From a360b4734870a4195426a0088fb9eed33e321421 Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Mon, 14 Oct 2024 23:01:04 -0400
Subject: [PATCH 01/11] fix: add newline berfore EOF in Spawned.hpp
---
.github/workflows/cpp_norm_checker.yml | 3 ---
.../Engine/EntityComponentSystem/Components/Common/Spawned.hpp | 2 +-
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/.github/workflows/cpp_norm_checker.yml b/.github/workflows/cpp_norm_checker.yml
index dc1e4dce..07fa08f4 100644
--- a/.github/workflows/cpp_norm_checker.yml
+++ b/.github/workflows/cpp_norm_checker.yml
@@ -4,9 +4,6 @@ on:
push:
branches:
- '*'
- pull_request:
- branches:
- - '*'
jobs:
build:
diff --git a/Flakkari/Engine/EntityComponentSystem/Components/Common/Spawned.hpp b/Flakkari/Engine/EntityComponentSystem/Components/Common/Spawned.hpp
index 3fc4fdf9..28804655 100644
--- a/Flakkari/Engine/EntityComponentSystem/Components/Common/Spawned.hpp
+++ b/Flakkari/Engine/EntityComponentSystem/Components/Common/Spawned.hpp
@@ -38,4 +38,4 @@ struct Spawned {
PACKED_END
} // namespace Flakkari::Engine::ECS::Components::Common
-#endif /* !SPAWNED_HPP_ */
\ No newline at end of file
+#endif /* !SPAWNED_HPP_ */
From dd2dc6ce69eece3d487569e8b0af89ed08f11dd2 Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Sun, 27 Oct 2024 20:59:01 -0400
Subject: [PATCH 02/11] fix: Update byte type in Buffer.hpp and Header.hpp
---
.github/workflows/commit_norm_check.yml | 8 +++-----
Flakkari/Network/Buffer.hpp | 3 +--
Flakkari/Protocol/Header.hpp | 1 -
3 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/commit_norm_check.yml b/.github/workflows/commit_norm_check.yml
index cbbba3a8..12b87e4b 100644
--- a/.github/workflows/commit_norm_check.yml
+++ b/.github/workflows/commit_norm_check.yml
@@ -4,9 +4,6 @@ on:
push:
branches:
- '*'
- pull_request:
- branches:
- - '*'
jobs:
verify-commit-name:
@@ -19,14 +16,15 @@ jobs:
- name: Commit Norm Checker
run: |
commit_msg=$(git log --format=%B -n 1 ${{ github.sha }})
- keyword_regex="^([a-z]+\([0-9A-Za-z_.-]+\)|^[a-z]+): "
+ keyword_regex="^([a-z]+\([0-9A-Za-z_.-]+\)|^[a-z]+): [0-9a-z_.-]+"
if [[ ! $commit_msg =~ $keyword_regex ]]; then
if [[ $commit_msg =~ ^Merge\ .* ]]; then
echo "Skipping merge commit"
else
echo $commit_msg
- echo "Commit message does not match expected format. Please use the following format: \"keyword(scope): comment\""
+ echo "Commit message does not match Angular convention."
exit 1
fi
fi
+ shell: bash
diff --git a/Flakkari/Network/Buffer.hpp b/Flakkari/Network/Buffer.hpp
index 8fc8c053..4660294c 100644
--- a/Flakkari/Network/Buffer.hpp
+++ b/Flakkari/Network/Buffer.hpp
@@ -22,8 +22,7 @@
#include
#include
-using byte = unsigned char;
-using byte_t = byte;
+using byte = std::uint8_t;
namespace Flakkari::Network {
diff --git a/Flakkari/Protocol/Header.hpp b/Flakkari/Protocol/Header.hpp
index 53a3fb79..9f86438d 100644
--- a/Flakkari/Protocol/Header.hpp
+++ b/Flakkari/Protocol/Header.hpp
@@ -28,7 +28,6 @@
namespace Flakkari::Protocol {
-using byte = byte_t; // 8 bits (max: 255)
using ushort = unsigned short; // 16 bits (max: 65535)
using uint = unsigned int; // 32 bits (max: 4294967295)
using ulong = unsigned long; // 64 bits (max: 18446744073709551615)
From bcab62ec72ddf2671bb71d11f5b76d895e8e559c Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Sun, 27 Oct 2024 20:59:25 -0400
Subject: [PATCH 03/11] fix: Update notes in README.md
Update the notes in the README.md file to use the [!NOTE] syntax for better readability and consistency.
---
README.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 8a06d0e4..f5f886c9 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@
Flakkari is a UDP server created for the R-Type Epitech project.
-> **Note**:
+> [!NOTE]
> The project is still under development and may not be stable.
@@ -76,12 +76,12 @@ $> cd build
(build)$> ./r-type_server
```
-> **Note**:
+> [!NOTE]
> - the server load Games from the `./Games` directory, so if you want to add a game,
> you have to put it in this directory before running.
> If the server is already running, use the `addGame ` command to load it.
-> **Note**:
+> [!NOTE]
> - some input commands need administrator privileges to execute.
> `export FLAKKARI_PASSWORD=` to set the password for the server
> to run with administrator privileges.
@@ -99,7 +99,7 @@ other build commands:
(build)$> sudo dpkg -i r-type_server--Linux.deb
```
-> **Note**:
+> [!NOTE]
> - the install target will install the server executable in the /usr/local/bin directory,
> the network library in the /usr/local/lib directory and
> the header files in the /usr/local/include directory.
From 3eaefbc4eb8a0131af1cfab0f68cb31214004093 Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Mon, 28 Oct 2024 02:06:11 -0400
Subject: [PATCH 04/11] fix: fixing Windows build error and a few other bugs
---
.gitignore | 1 -
CMakeLists.txt | 4 +
.../EntityComponentSystem/Systems/Systems.cpp | 18 +--
Flakkari/Engine/Math/Vector.hpp | 12 +-
Flakkari/Logger/Logger.hpp | 17 ++-
Flakkari/Network/Address.cpp | 32 ++++-
Flakkari/Network/Address.hpp | 4 +-
Flakkari/Network/IOMultiplexer.cpp | 83 +++++++++++-
Flakkari/Network/IOMultiplexer.hpp | 122 +++++++++++++++---
Flakkari/Network/Network.cpp | 31 +++++
Flakkari/Network/Network.hpp | 39 ++++++
Flakkari/Network/Socket.cpp | 76 ++++-------
Flakkari/Network/Socket.hpp | 29 ++---
Flakkari/Protocol/Header.hpp | 6 +-
Flakkari/Protocol/Packet.hpp | 8 +-
Flakkari/Protocol/PacketFactory.hpp | 36 +++---
Flakkari/Server/Client/ClientManager.hpp | 2 +-
Flakkari/Server/Game/Game.cpp | 48 +++----
Flakkari/Server/Game/GameManager.cpp | 18 ++-
Flakkari/Server/Game/GameManager.hpp | 4 +
Flakkari/Server/Internals/CommandManager.cpp | 17 ++-
Flakkari/Server/UDPServer.cpp | 25 ++--
Flakkari/Server/UDPServer.hpp | 16 ++-
Flakkari/core.cpp | 6 +-
README.md | 10 +-
docs/examples/TCPServer.cpp | 29 ++++-
docs/examples/UDPClient.hpp | 22 +++-
docs/examples/UDPServer.hpp | 25 +++-
28 files changed, 526 insertions(+), 214 deletions(-)
create mode 100644 Flakkari/Network/Network.cpp
create mode 100644 Flakkari/Network/Network.hpp
diff --git a/.gitignore b/.gitignore
index 3f9d9528..00d5ff95 100644
--- a/.gitignore
+++ b/.gitignore
@@ -567,7 +567,6 @@ _deps
*.exe
*.out
*.app
-flakkari
r-type_server
docs/Flakkari/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d6a19d64..acbff0ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,7 @@ set(SOURCES
Flakkari/Logger/Logger.cpp
+ Flakkari/Network/Network.cpp
Flakkari/Network/Address.cpp
Flakkari/Network/Buffer.cpp
Flakkari/Network/Socket.cpp
@@ -33,6 +34,7 @@ set(SOURCES
set(HEADERS
Flakkari/Logger/Logger.hpp
+ Flakkari/Network/Network.hpp
Flakkari/Network/Packed.hpp
Flakkari/Network/Address.hpp
Flakkari/Network/Buffer.hpp
@@ -75,6 +77,7 @@ set(HEADER_LIB_LOGGER
)
set(HEADER_LIB_NETWORK
+ Flakkari/Network/Network.hpp
Flakkari/Network/Packed.hpp
Flakkari/Network/Address.hpp
Flakkari/Network/Buffer.hpp
@@ -108,6 +111,7 @@ FetchContent_MakeAvailable(nlohmann_json)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
+set(FLAKKARI_GAME_DIR ${CMAKE_SOURCE_DIR}/Games)
# Compiler Standards:
set(CMAKE_CXX_STANDARD 20)
diff --git a/Flakkari/Engine/EntityComponentSystem/Systems/Systems.cpp b/Flakkari/Engine/EntityComponentSystem/Systems/Systems.cpp
index 38a0d2d4..54e574d2 100644
--- a/Flakkari/Engine/EntityComponentSystem/Systems/Systems.cpp
+++ b/Flakkari/Engine/EntityComponentSystem/Systems/Systems.cpp
@@ -24,13 +24,13 @@ void position(Registry &r, float deltaTime)
auto& vel = velocities[i];
if (pos.has_value() && vel.has_value()) {
- float magnitude = std::sqrt(vel->velocity.dx * vel->velocity.dx + vel->velocity.dy * vel->velocity.dy);
+ float magnitude = std::sqrt(vel->velocity.vec.x * vel->velocity.vec.x + vel->velocity.vec.y * vel->velocity.vec.y);
if (magnitude > 0.0f) {
- vel->velocity.dx /= magnitude;
- vel->velocity.dy /= magnitude;
+ vel->velocity.vec.x /= magnitude;
+ vel->velocity.vec.y /= magnitude;
}
- pos->position.x += vel->velocity.dx * vel->acceleration.x * deltaTime;
- pos->position.y += vel->velocity.dy * vel->acceleration.y * deltaTime;
+ pos->position.vec.x += vel->velocity.vec.x * vel->acceleration.vec.x * deltaTime;
+ pos->position.vec.y += vel->velocity.vec.y * vel->acceleration.vec.y * deltaTime;
}
}
}
@@ -51,22 +51,22 @@ void update_control(Registry &r)
if (net->events.size() < int(Protocol::EventId::MOVE_UP))
continue;
if (net->events[int(Protocol::EventId::MOVE_UP)] == int(Protocol::EventState::PRESSED))
- vel->velocity.dy = -1;
+ vel->velocity.vec.y = -1;
if (net->events.size() < int(Protocol::EventId::MOVE_DOWN))
continue;
if (net->events[int(Protocol::EventId::MOVE_DOWN)] == int(Protocol::EventState::PRESSED))
- vel->velocity.dy = 1;
+ vel->velocity.vec.y = 1;
if (net->events.size() < int(Protocol::EventId::MOVE_LEFT))
continue;
if (net->events[int(Protocol::EventId::MOVE_LEFT)] == int(Protocol::EventState::PRESSED))
- vel->velocity.dx = -1;
+ vel->velocity.vec.x = -1;
if (net->events.size() < int(Protocol::EventId::MOVE_RIGHT))
continue;
if (net->events[int(Protocol::EventId::MOVE_RIGHT)] == int(Protocol::EventState::PRESSED))
- vel->velocity.dx = 1;
+ vel->velocity.vec.x = 1;
}
}
diff --git a/Flakkari/Engine/Math/Vector.hpp b/Flakkari/Engine/Math/Vector.hpp
index 4f5dd54f..ce934ea6 100644
--- a/Flakkari/Engine/Math/Vector.hpp
+++ b/Flakkari/Engine/Math/Vector.hpp
@@ -36,25 +36,19 @@ PACKED_START
Type y;
Type z;
Type w;
- };
+ } vec;
struct {
Type r;
Type g;
Type b;
Type a;
- };
+ } color;
struct {
Type width;
Type height;
Type depth;
Type time;
- };
- struct {
- Type dx;
- Type dy;
- Type dz;
- Type _;
- };
+ } dimension;
Type v[4];
};
diff --git a/Flakkari/Logger/Logger.hpp b/Flakkari/Logger/Logger.hpp
index 0566d6cd..24d38e46 100644
--- a/Flakkari/Logger/Logger.hpp
+++ b/Flakkari/Logger/Logger.hpp
@@ -28,9 +28,24 @@
#define FLAKKARI_LOG_ERROR(message) FLAKKARI_LOG(LOG_ERROR, message)
#define FLAKKARI_LOG_FATAL(message) FLAKKARI_LOG(LOG_FATAL, message)
-#define STD_ERROR std::string(::strerror(errno))
+#ifdef _WIN32
+ #define STD_ERROR \
+ []() -> std::string { \
+ char buffer[256]; \
+ strerror_s(buffer, sizeof(buffer), errno); \
+ return std::string(buffer); \
+ }()
+
+ #define SPECIAL_ERROR std::to_string(WSAGetLastError())
+#else
+ #define STD_ERROR std::string(::strerror(errno))
+ #define SPECIAL_ERROR STD_ERROR
+#endif
#if _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define _WINSOCK_DEPRECATED_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
#include
#define COLOR_RESET 7
diff --git a/Flakkari/Network/Address.cpp b/Flakkari/Network/Address.cpp
index 50e13f8f..98e07af4 100644
--- a/Flakkari/Network/Address.cpp
+++ b/Flakkari/Network/Address.cpp
@@ -14,13 +14,27 @@ namespace Flakkari::Network {
Address::Address(address_t &address, port_t port, SocketType socket_type, IpType ip_type)
: _socket_type(socket_type), _ip_type(ip_type)
{
- struct hostent *host = nullptr;
- addrinfo hints;
+ addrinfo hints{};
+
hints.ai_family = (ip_type == IpType::IPv4) ? AF_INET : AF_INET6;
hints.ai_socktype = (socket_type == SocketType::TCP) ? SOCK_STREAM : SOCK_DGRAM;
hints.ai_protocol = (socket_type == SocketType::TCP) ? IPPROTO_TCP : IPPROTO_UDP;
hints.ai_flags = (AI_PASSIVE | AI_V4MAPPED | AI_ALL);
+#ifdef _WIN32
+ addrinfo *result = nullptr;
+ if (getaddrinfo(address.c_str(), std::to_string(port).c_str(), &hints, &result) != 0) {
+ FLAKKARI_LOG_ERROR("getaddrinfo() failed for " + address);
+ return;
+ }
+
+ _addrInfo = std::shared_ptr(result, [](addrinfo *addrInfo) {
+ if (addrInfo != nullptr)
+ freeaddrinfo(addrInfo);
+ });
+#else
+ struct hostent *host = nullptr;
+
if ((host = gethostbyname(address.c_str())) == nullptr) {
FLAKKARI_LOG_ERROR("gethostbyname() failed for " + address);
return;
@@ -36,6 +50,7 @@ Address::Address(address_t &address, port_t port, SocketType socket_type, IpType
if (addrInfo != nullptr)
freeaddrinfo(addrInfo);
});
+#endif
}
Address::Address(port_t port, SocketType socket_type, IpType ip_type)
@@ -91,7 +106,16 @@ Address::Address(const sockaddr_storage &clientAddr, SocketType socket_type, IpT
hints.ai_flags = (AI_PASSIVE | AI_V4MAPPED | AI_ALL);
addrinfo *result = nullptr;
+#if defined(_WIN32)
+ char name[INET6_ADDRSTRLEN];
+
+ if (clientAddr.ss_family == AF_INET)
+ inet_ntop(AF_INET, &(((sockaddr_in *)&clientAddr)->sin_addr), name, INET_ADDRSTRLEN);
+ else
+ inet_ntop(AF_INET6, &(((sockaddr_in6 *)&clientAddr)->sin6_addr), name, INET6_ADDRSTRLEN);
+#else
const char *name = inet_ntoa(((sockaddr_in *)&clientAddr)->sin_addr);
+#endif
const std::string serviceStr = std::to_string(ntohs(((sockaddr_in *)&clientAddr)->sin_port));
const char *service = serviceStr.c_str();
@@ -113,7 +137,7 @@ std::optional Address::toString() const
return {};
char host[NI_MAXHOST];
char service[NI_MAXSERV];
- if (getnameinfo(_addrInfo->ai_addr, _addrInfo->ai_addrlen, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICSERV) != 0) {
+ if (getnameinfo(_addrInfo->ai_addr, (int)_addrInfo->ai_addrlen, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICSERV) != 0) {
FLAKKARI_LOG_ERROR("getnameinfo() failed");
return {};
}
@@ -125,7 +149,7 @@ std::optional Address::getIp() const
if (_addrInfo == nullptr)
return {};
char host[NI_MAXHOST];
- if (getnameinfo(_addrInfo->ai_addr, _addrInfo->ai_addrlen, host, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST) != 0) {
+ if (getnameinfo(_addrInfo->ai_addr, (int)_addrInfo->ai_addrlen, host, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST) != 0) {
FLAKKARI_LOG_ERROR("getnameinfo() failed");
return {};
}
diff --git a/Flakkari/Network/Address.hpp b/Flakkari/Network/Address.hpp
index 0d81b5cc..585a0701 100644
--- a/Flakkari/Network/Address.hpp
+++ b/Flakkari/Network/Address.hpp
@@ -19,7 +19,9 @@
#include
#include
#else
-#include
+#define WIN32_LEAN_AND_MEAN
+#define _WINSOCK_DEPRECATED_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
#include
#pragma comment(lib, "Ws2_32.lib")
diff --git a/Flakkari/Network/IOMultiplexer.cpp b/Flakkari/Network/IOMultiplexer.cpp
index 7f6a65af..16bf2282 100644
--- a/Flakkari/Network/IOMultiplexer.cpp
+++ b/Flakkari/Network/IOMultiplexer.cpp
@@ -64,9 +64,7 @@ int PSELECT::wait()
FD_ZERO(&_fds);
for (auto &fd : _sockets)
FD_SET(fd, &_fds);
- #if defined(_WIN32)
- return ::select(_maxFd + 1, &_fds, nullptr, nullptr, (const timeval *)&_timeout);
- #elif defined(__APPLE__)
+ #if defined(__APPLE__)
return ::select(_maxFd + 1, &_fds, nullptr, nullptr, (struct timeval *)&_timeout);
#else
return ::pselect(_maxFd + 1, &_fds, nullptr, nullptr, &_timeout, nullptr);
@@ -82,6 +80,11 @@ bool PSELECT::isReady(FileDescriptor socket)
return FD_ISSET(socket, &_fds);
}
+bool PSELECT::skipableError()
+{
+ return errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK;
+}
+
#endif
#if defined(_PPOLL_)
@@ -181,4 +184,78 @@ bool PPOLL::isReady(FileDescriptor socket)
#endif
+#if defined(_WSA_)
+
+WSA::WSA(long int seconds, long int microseconds)
+{
+ _timeoutInMs = seconds * 1000 + microseconds / 1000; // Convert to milliseconds
+ _hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Create a manual-reset event
+ if (_hEvent == NULL)
+ throw std::runtime_error("Failed to create event.");
+}
+
+WSA::~WSA()
+{
+ for (auto& socket : _sockets)
+ WSAEventSelect(socket, NULL, 0);
+
+ CloseHandle(_hEvent);
+}
+
+void WSA::addSocket(FileDescriptor socket)
+{
+ if (socket == -1)
+ throw std::runtime_error("Socket is -1");
+
+ if (_events.find(socket) != _events.end())
+ throw std::runtime_error("Socket already added.");
+
+ _events[socket] = _hEvent;
+ WSAEventSelect(socket, _hEvent, FD_READ | FD_ACCEPT);
+ _sockets.push_back(socket);
+}
+
+void WSA::removeSocket(FileDescriptor socket)
+{
+ if (socket == -1)
+ throw std::runtime_error("Socket is -1");
+
+ auto it = std::remove(_sockets.begin(), _sockets.end(), socket);
+ if (it != _sockets.end()) {
+ WSAEventSelect(socket, NULL, 0);
+ _sockets.erase(it, _sockets.end());
+ _events.erase(socket);
+ }
+}
+
+int WSA::wait()
+{
+ DWORD waitResult = WSAWaitForMultipleEvents(1, &_hEvent, FALSE, _timeoutInMs, FALSE);
+ if (waitResult == WAIT_FAILED)
+ return -1;
+ else if (waitResult == WAIT_TIMEOUT)
+ return 0;
+
+ WSAResetEvent(_hEvent);
+
+ return static_cast(_sockets.size());
+}
+
+bool WSA::isReady(FileDescriptor socket)
+{
+ if (socket == -1)
+ throw std::runtime_error("Socket is -1");
+
+ DWORD result = WSAEnumNetworkEvents(socket, _events[socket], nullptr);
+ return (result == 0);
+}
+
+bool WSA::skipableError()
+{
+ int error = WSAGetLastError();
+ return error == WSAEINTR || error == WSAEWOULDBLOCK || error == WSAEINPROGRESS;
+}
+
+#endif
+
} // namespace Flakkari::Network
diff --git a/Flakkari/Network/IOMultiplexer.hpp b/Flakkari/Network/IOMultiplexer.hpp
index c8d0f6f5..a2108cd7 100644
--- a/Flakkari/Network/IOMultiplexer.hpp
+++ b/Flakkari/Network/IOMultiplexer.hpp
@@ -18,10 +18,10 @@
// if im on windows, define all compatible IOMultiplexer
#ifdef _WIN32
- #define _PSELECT_
#define _EPOLL_
#define _KQUEUE_
#define _IO_URING_
+ #define _WSA_
#else
#define _PSELECT_
#define _PPOLL_
@@ -30,26 +30,14 @@
#include "Socket.hpp"
#include
+#include
namespace Flakkari::Network {
#if defined(_PSELECT_)
-#if defined(_WIN32)
- #include
- #include
- #include
- #include
-
- #pragma comment(lib, "Ws2_32.lib")
-#elif defined(__APPLE__)
- #include
- #include
- #include
-#else
- #include
- #include
- #include
-#endif
+#include
+#include
+#include
/**
* @brief PSELECT is a class that represents a PSELECT
@@ -122,6 +110,14 @@ class PSELECT {
*/
[[nodiscard]] bool isReady(FileDescriptor socket);
+ /**
+ * @brief Check if the error is skipable
+ *
+ * @return true If the error is skipable
+ * @return false If the error is not skipable
+ */
+ [[nodiscard]] bool skipableError();
+
protected:
private:
fd_set _fds;
@@ -133,11 +129,7 @@ class PSELECT {
#if defined(_PPOLL_)
#if defined(_WIN32)
- #include
- #include
- #include
#include
- #pragma comment(lib, "Ws2_32.lib")
#elif defined(__APPLE__)
#include
#else
@@ -246,6 +238,94 @@ class PPOLL {
};
#endif
+#if defined(_WSA_)
+
+/**
+ * @brief WSA is a class that represents a WSA
+ *
+ * @class WSA
+ * @implements IOMultiplexer
+ * @see IOMultiplexer
+ *
+ * @example "WSA example":
+ * @code
+ * auto socket = std::make_shared(12345, Address::IpType::IPv4, Address::SocketType::UDP);
+ * socket->bind();
+ *
+ * auto io = std::make_unique();
+ * io->addSocket(socket->getSocket());
+ *
+ * while (true) {
+ * int result = io->wait();
+ * if (result > 0) {
+ * for (auto &fd : *io) {
+ * if (io->isReady(fd)) {
+ * // do something
+ * }
+ * }
+ * }
+ * }
+ * @endcode
+ */
+class WSA {
+ public:
+ using FileDescriptor = SOCKET;
+
+ public:
+ WSA(long int seconds = 1, long int microseconds = 0);
+ ~WSA();
+
+ /**
+ * @brief Add a socket to the WSA list
+ *
+ * @param socket The socket to add to the list
+ */
+ void addSocket(FileDescriptor socket);
+
+ /**
+ * @brief Remove a socket from the WSA list
+ *
+ * @param socket The socket to remove from the list
+ */
+ void removeSocket(FileDescriptor socket);
+
+ /**
+ * @brief Wait for an event to happen on a socket or timeout
+ *
+ * @return int The number of events that happened or -1 if an error occured or 0 if the timeout expired (EINTR)
+ * @see WSAWaitForMultipleEvents
+ */
+ int wait();
+
+ std::vector::iterator begin() { return _sockets.begin(); }
+ std::vector::iterator end() { return _sockets.end(); }
+
+ /**
+ * @brief Check if a socket is ready to read from
+ *
+ * @param socket The socket to check
+ * @return true If the socket is ready
+ * @return false If the socket is not ready
+ */
+ [[nodiscard]] bool isReady(FileDescriptor socket);
+
+ /**
+ * @brief Check if the error is skipable
+ *
+ * @return true If the error is skipable
+ * @return false If the error is not skipable
+ */
+ [[nodiscard]] bool skipableError();
+
+ protected:
+ private:
+ std::vector _sockets;
+ std::unordered_map _events;
+ HANDLE _hEvent;
+ long int _timeoutInMs;
+};
+#endif
+
} // namespace Flakkari::Network
#endif /* !IOMULTIPLEXER_HPP_ */
diff --git a/Flakkari/Network/Network.cpp b/Flakkari/Network/Network.cpp
new file mode 100644
index 00000000..8c04be84
--- /dev/null
+++ b/Flakkari/Network/Network.cpp
@@ -0,0 +1,31 @@
+/*
+** EPITECH PROJECT, 2023
+** Title: Flakkari
+** Author: MasterLaplace
+** Created: 2024-10-27
+** File description:
+** Network
+*/
+
+#include "Network.hpp"
+
+namespace Flakkari::Network {
+
+void initNetwork()
+{
+#ifdef _WIN32
+ WSADATA WSAData;
+
+ if (::WSAStartup(MAKEWORD(2, 2), &WSAData) != NO_ERROR)
+ FLAKKARI_LOG_FATAL("WSAStartup failed");
+#endif
+}
+
+void cleanupNetwork()
+{
+#ifdef _WIN32
+ ::WSACleanup();
+#endif
+}
+
+} // namespace Flakkari::Network
diff --git a/Flakkari/Network/Network.hpp b/Flakkari/Network/Network.hpp
new file mode 100644
index 00000000..cc6f0365
--- /dev/null
+++ b/Flakkari/Network/Network.hpp
@@ -0,0 +1,39 @@
+/**************************************************************************
+ * Flakkari Library v0.2.0
+ *
+ * Flakkari Library is a C++ Library for Network.
+ * @file Network.hpp
+ * @brief This file contains the Network functions. It is used to initialize
+ * and cleanup the network. It is only used by Windows.
+ *
+ * Flakkari Library is under MIT License.
+ * https://opensource.org/licenses/MIT
+ * © 2023 @MasterLaplace
+ * @version 0.2.0
+ * @date 2024-10-27
+ **************************************************************************/
+
+#ifndef NETWORK_HPP_
+#define NETWORK_HPP_
+
+#include "Socket.hpp"
+
+namespace Flakkari::Network {
+
+/**
+ * @brief Initialize the network.
+ * This function is only used by Windows.
+ *
+ */
+void initNetwork();
+
+/**
+ * @brief Cleanup the network.
+ * This function is only used by Windows.
+ *
+ */
+void cleanupNetwork();
+
+} // namespace Flakkari::Network
+
+#endif /* !NETWORK_HPP_ */
diff --git a/Flakkari/Network/Socket.cpp b/Flakkari/Network/Socket.cpp
index 484d202b..ccbc2169 100644
--- a/Flakkari/Network/Socket.cpp
+++ b/Flakkari/Network/Socket.cpp
@@ -11,16 +11,10 @@
namespace Flakkari::Network {
-Socket::Socket(std::shared_ptr address)
- : _socket(INVALID_SOCKET), _address(address)
+void Socket::create(std::shared_ptr address)
{
- #ifdef _WIN32
- WSADATA WSAData;
- if (::WSAStartup(MAKEWORD(2, 2), &WSAData) != 0) {
- FLAKKARI_LOG_FATAL("WSAStartup failed");
- return;
- }
- #endif
+ _address = address;
+ _socket = INVALID_SOCKET;
auto &addr = _address->getAddrInfo();
@@ -46,20 +40,17 @@ Socket::Socket(std::shared_ptr address)
#endif
}
-Socket::Socket(socket_t socket, std::shared_ptr address)
- : _socket(socket), _address(address)
+void Socket::create(socket_t socket, std::shared_ptr address)
{
- #ifdef _WIN32
- WSADATA WSAData;
- if (::WSAStartup(MAKEWORD(2, 2), &WSAData) != 0) {
- FLAKKARI_LOG_FATAL("WSAStartup failed");
- return;
- }
- #endif
+ _socket = socket;
+ _address = address;
#if _WIN32
u_long mode = 1;
- int result = ::ioctlsocket(_socket, FIONBIO, &mode);
+ if (::ioctlsocket(_socket, FIONBIO, &mode) != NO_ERROR) {
+ FLAKKARI_LOG_FATAL("Failed to set socket to non-blocking, error: " + STD_ERROR);
+ return;
+ }
#elif __APPLE__
int optval = 1;
::setsockopt(_socket, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
@@ -71,16 +62,10 @@ Socket::Socket(socket_t socket, std::shared_ptr address)
#endif
}
-Socket::Socket(Address address)
- : _socket(INVALID_SOCKET), _address(std::make_shared(address))
+void Socket::create(Address address)
{
- #ifdef _WIN32
- WSADATA WSAData;
- if (::WSAStartup(MAKEWORD(2, 2), &WSAData) != 0) {
- FLAKKARI_LOG_FATAL("WSAStartup failed");
- return;
- }
- #endif
+ _address = std::make_shared(address);
+ _socket = INVALID_SOCKET;
auto &addr = _address->getAddrInfo();
@@ -106,16 +91,10 @@ Socket::Socket(Address address)
#endif
}
-Socket::Socket(ip_t ip, port_t port, Address::IpType ip_type, Address::SocketType socket_type)
- : _socket(INVALID_SOCKET), _address(std::make_shared(ip, port, socket_type, ip_type))
+void Socket::create(ip_t address, port_t port, Address::IpType ip_type, Address::SocketType socket_type)
{
- #ifdef _WIN32
- WSADATA WSAData;
- if (::WSAStartup(MAKEWORD(2, 2), &WSAData) != 0) {
- FLAKKARI_LOG_FATAL("WSAStartup failed");
- return;
- }
- #endif
+ _address = std::make_shared(address, port, socket_type, ip_type);
+ _socket = INVALID_SOCKET;
auto &addr = _address->getAddrInfo();
@@ -144,9 +123,6 @@ Socket::Socket(ip_t ip, port_t port, Address::IpType ip_type, Address::SocketTyp
Socket::~Socket()
{
this->close();
- #ifdef _WIN32
- ::WSACleanup();
- #endif
}
void Socket::bind()
@@ -156,7 +132,7 @@ void Socket::bind()
if (addr == nullptr)
return FLAKKARI_LOG_ERROR("Address is nullptr"), void();
- if (::bind(_socket, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
+ if (::bind(_socket, addr->ai_addr, (int)addr->ai_addrlen) == SOCKET_ERROR) {
FLAKKARI_LOG_FATAL("Failed to bind socket, error: " + STD_ERROR);
return;
}
@@ -177,7 +153,7 @@ void Socket::connect()
if (addr == nullptr)
return FLAKKARI_LOG_ERROR("Address is nullptr"), void();
- if (::connect(_socket, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
+ if (::connect(_socket, addr->ai_addr, (int)addr->ai_addrlen) == SOCKET_ERROR) {
FLAKKARI_LOG_FATAL("Failed to connect socket, error: " + STD_ERROR);
return;
}
@@ -232,13 +208,15 @@ std::shared_ptr Socket::accept()
? Address::IpType::IPv6 : Address::IpType::None;
auto clientAddress = std::make_shared(clientAddr, _address->getSocketType(), _ip_type);
- return std::make_shared(clientSocket, clientAddress);
+ auto client = std::make_shared();
+ client->create(clientSocket, clientAddress);
+ return client;
}
void Socket::send(const Buffer &data, int flags)
{
#ifdef _WIN32
- if (::send(_socket, (const char *)data.getData(), data.getSize(), flags) == SOCKET_ERROR) {
+ if (::send(_socket, (const char *)data.getData(), (int)data.getSize(), flags) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to send \"" + std::string(data.begin(), data.end()) + "\" to socket(" + std::to_string(_socket) + "), error: " + STD_ERROR);
return;
}
@@ -253,7 +231,7 @@ void Socket::send(const Buffer &data, int flags)
void Socket::send(const Buffer &data, size_t size, int flags)
{
#ifdef _WIN32
- if (::send(_socket, (const char *)data.getData(), size, flags) == SOCKET_ERROR) {
+ if (::send(_socket, (const char *)data.getData(), (int)size, flags) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to send \"" + std::string(data.begin(), data.end()) + "\" to socket(" + std::to_string(_socket) + "), error: " + STD_ERROR);
return;
}
@@ -274,7 +252,7 @@ void Socket::sendTo(const std::shared_ptr &address, const Buffer &data,
return FLAKKARI_LOG_ERROR("Address is nullptr"), void();
#ifdef _WIN32
- if (::sendto(_socket, (const char *)data.getData(), data.getSize(), flags, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
+ if (::sendto(_socket, (const char *)data.getData(), (int)data.getSize(), flags, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to send \"" + std::string(data.begin(), data.end()) + "\" to \"" + address->toString().value_or("No address") + "\", error: " + STD_ERROR);
return;
}
@@ -294,7 +272,7 @@ void Socket::sendTo(const std::shared_ptr &address, const byte *data, c
return FLAKKARI_LOG_ERROR("Address is nullptr"), void();
#if _WIN32
- if (::sendto(_socket, (const char *)data, size, flags, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
+ if (::sendto(_socket, (const char *)data, (int)size, flags, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to send \""+ std::string(data, data + size) +"\" to \""+ address->toString().value_or("No address") +"\", error: "+ STD_ERROR);
return;
}
@@ -310,7 +288,7 @@ std::optional Socket::receive(size_t size, int flags)
{
Buffer data(size, 0);
- if (::recv(_socket, (char*)&data[0], size, flags) == SOCKET_ERROR) {
+ if (::recv(_socket, (char*)&data[0], (int)size, flags) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to receive data from socket(" + std::to_string(_socket) + "), error: " + STD_ERROR);
return {};
}
@@ -334,7 +312,7 @@ std::optional, Buffer>> Socket::receiveFrom(s
sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
- if (::recvfrom(_socket, (char*)data.data(), size, flags, (sockaddr*)&addr, &addrlen) == SOCKET_ERROR) {
+ if (::recvfrom(_socket, (char*)data.data(), (int)size, flags, (sockaddr*)&addr, &addrlen) == SOCKET_ERROR) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
return {};
FLAKKARI_LOG_ERROR("Failed to receive data from \"" + _address->toString().value_or("No address") + "\", error: " + STD_ERROR);
diff --git a/Flakkari/Network/Socket.hpp b/Flakkari/Network/Socket.hpp
index 7a862ae5..bea6ea73 100644
--- a/Flakkari/Network/Socket.hpp
+++ b/Flakkari/Network/Socket.hpp
@@ -25,13 +25,6 @@
#include
#ifdef _WIN32
- #include
- #include
- #include
-
- #pragma comment(lib, "ws2_32.lib")
- #pragma comment(lib, "Mswsock.lib")
-
typedef SOCKET SOCKET;
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR (-1)
@@ -75,7 +68,8 @@ namespace Flakkari::Network {
* @example "Socket class for a UDP server":
* @code
* // Create a socket
- * auto socket = std::make_shared(12345, Address::IpType::IPv4, Address::SocketType::UDP);
+ * auto socket = std::make_shared();
+ * socket->create(12345, Address::IpType::IPv4, Address::SocketType::UDP);
* // Bind the socket
* socket->bind();
* // Send data to a client
@@ -88,7 +82,8 @@ namespace Flakkari::Network {
* @example "Socket class for a TCP server":
* @code
* // Create a socket
- * auto socket = std::make_shared(12345, Address::IpType::IPv4, Address::SocketType::TCP);
+ * auto socket = std::make_shared();
+ * socket->create(12345, Address::IpType::IPv4, Address::SocketType::TCP);
* // Bind the socket
* socket->bind();
* // Listen for incoming connections
@@ -104,7 +99,8 @@ namespace Flakkari::Network {
* @example "Socket class for a UDP client":
* @code
* // Create a socket
- * auto socket = std::make_shared(12345, Address::IpType::IPv4, Address::SocketType::UDP);
+ * auto socket = std::make_shared();
+ * socket->create(12345, Address::IpType::IPv4, Address::SocketType::UDP);
* // Send data to the server
* socket->sendTo("Hello World!", socket->getAddress());
* // Receive data from the server
@@ -115,7 +111,8 @@ namespace Flakkari::Network {
* @example "Socket class for a TCP client":
* @code
* // Create a socket
- * auto socket = std::make_shared(12345, Address::IpType::IPv4, Address::SocketType::TCP);
+ * auto socket = std::make_shared();
+ * socket->create(12345, Address::IpType::IPv4, Address::SocketType::TCP);
* // Connect to a server
* socket->connect();
* // Send data to the server
@@ -131,14 +128,16 @@ class Socket {
using socket_t = SOCKET;
public:
- Socket(std::shared_ptr address);
- Socket(socket_t socket, std::shared_ptr address);
- Socket(Address address);
- Socket(ip_t address, port_t port, Address::IpType ip_type, Address::SocketType socket_type);
+ Socket() = default;
Socket(const Socket &) = default;
Socket(Socket &&) = default;
~Socket();
+ void create(std::shared_ptr address);
+ void create(socket_t socket, std::shared_ptr address);
+ void create(Address address);
+ void create(ip_t address, port_t port, Address::IpType ip_type, Address::SocketType socket_type);
+
bool operator==(const Socket &other) const { return _socket == other._socket; }
bool operator==(const int &socket) const { return _socket == socket; }
diff --git a/Flakkari/Protocol/Header.hpp b/Flakkari/Protocol/Header.hpp
index 9f86438d..73ae0468 100644
--- a/Flakkari/Protocol/Header.hpp
+++ b/Flakkari/Protocol/Header.hpp
@@ -54,7 +54,7 @@ inline namespace V_0 {
MEDIUM = 1,
HIGH = 2,
CRITICAL = 3,
- MAX_PRIORITY
+ MAX_PRIORITY = 4
};
PACKED_START
@@ -65,8 +65,8 @@ inline namespace V_0 {
ApiVersion _apiVersion : 4 = ApiVersion::V_0;
Id _commandId;
ushort _contentLength = 0;
- uint _sequenceNumber = std::chrono::duration_cast(
- std::chrono::system_clock::now().time_since_epoch()).count();
+ uint _sequenceNumber = static_cast(std::chrono::duration_cast(
+ std::chrono::system_clock::now().time_since_epoch()).count());
};
PACKED_END
diff --git a/Flakkari/Protocol/Packet.hpp b/Flakkari/Protocol/Packet.hpp
index 6609eeba..13c866fa 100644
--- a/Flakkari/Protocol/Packet.hpp
+++ b/Flakkari/Protocol/Packet.hpp
@@ -26,6 +26,8 @@
#include "Components.hpp"
#include "Events.hpp"
+#include
+
namespace Flakkari::Protocol {
inline namespace V_0 {
@@ -100,7 +102,7 @@ inline namespace V_0 {
const byte *dataBytes = reinterpret_cast(&data);
packet.payload.insert(packet.payload.end(), dataBytes, dataBytes + sizeof(data));
- packet.header._contentLength += packet.payload.size() + sizeof(data);
+ packet.header._contentLength += (ushort)packet.payload.size() + (ushort)sizeof(data);
return packet;
}
@@ -136,7 +138,7 @@ inline namespace V_0 {
const byte *dataBytes = reinterpret_cast(&intValue);
payload.insert(payload.end(), dataBytes, dataBytes + sizeof(intValue));
payload += str;
- header._contentLength += payload.size() + sizeof(intValue);
+ header._contentLength += (ushort)payload.size() + (ushort)sizeof(intValue);
}
std::string extractString()
@@ -147,7 +149,7 @@ inline namespace V_0 {
payload.erase(payload.begin(), payload.begin() + sizeof(intValue));
str = std::string((const char*)payload.data(), intValue);
payload.erase(payload.begin(), payload.begin() + intValue);
- header._contentLength -= sizeof(intValue) + intValue;
+ header._contentLength -= (ushort)sizeof(intValue) + (ushort)intValue;
return str;
}
diff --git a/Flakkari/Protocol/PacketFactory.hpp b/Flakkari/Protocol/PacketFactory.hpp
index 68805890..b2b02d8d 100644
--- a/Flakkari/Protocol/PacketFactory.hpp
+++ b/Flakkari/Protocol/PacketFactory.hpp
@@ -109,21 +109,21 @@ class PacketFactory {
if (transform.has_value()) {
packet << Protocol::ComponentId::TRANSFORM;
- packet << transform->position.x;
- packet << transform->position.y;
+ packet << transform->position.vec.x;
+ packet << transform->position.vec.y;
packet << transform->rotation;
- packet << transform->scale.x;
- packet << transform->scale.y;
+ packet << transform->scale.vec.x;
+ packet << transform->scale.vec.y;
}
auto movable = registry.getComponents()[entity];
if (movable.has_value()) {
packet << Protocol::ComponentId::MOVABLE;
- packet << movable->velocity.x;
- packet << movable->velocity.y;
- packet << movable->acceleration.x;
- packet << movable->acceleration.y;
+ packet << movable->velocity.vec.x;
+ packet << movable->velocity.vec.y;
+ packet << movable->acceleration.vec.x;
+ packet << movable->acceleration.vec.y;
}
auto control = registry.getComponents()[entity];
@@ -141,8 +141,8 @@ class PacketFactory {
if (collider.has_value()) {
packet << Protocol::ComponentId::COLLIDER;
- packet << collider->_size.x;
- packet << collider->_size.y;
+ packet << collider->_size.vec.x;
+ packet << collider->_size.vec.y;
}
auto rigidbody = registry.getComponents()[entity];
@@ -282,15 +282,15 @@ class PacketFactory {
Engine::ECS::Components::_2D::Movable vel
) {
packet << entity;
- packet << pos.position.x;
- packet << pos.position.y;
+ packet << pos.position.vec.x;
+ packet << pos.position.vec.y;
packet << pos.rotation;
- packet << pos.scale.x;
- packet << pos.scale.y;
- packet << vel.velocity.x;
- packet << vel.velocity.y;
- packet << vel.acceleration.x;
- packet << vel.acceleration.y;
+ packet << pos.scale.vec.x;
+ packet << pos.scale.vec.y;
+ packet << vel.velocity.vec.x;
+ packet << vel.velocity.vec.y;
+ packet << vel.acceleration.vec.x;
+ packet << vel.acceleration.vec.y;
}
};
diff --git a/Flakkari/Server/Client/ClientManager.hpp b/Flakkari/Server/Client/ClientManager.hpp
index 0d1d3eb5..cc2a2e1d 100644
--- a/Flakkari/Server/Client/ClientManager.hpp
+++ b/Flakkari/Server/Client/ClientManager.hpp
@@ -16,7 +16,7 @@
#ifndef CLIENTMANAGER_HPP_
#define CLIENTMANAGER_HPP_
-#include "Network/Socket.hpp"
+#include "Network/Network.hpp"
#include "Network/Serializer.hpp"
#include "Client.hpp"
diff --git a/Flakkari/Server/Game/Game.cpp b/Flakkari/Server/Game/Game.cpp
index 91684b90..363ea496 100644
--- a/Flakkari/Server/Game/Game.cpp
+++ b/Flakkari/Server/Game/Game.cpp
@@ -251,23 +251,23 @@ void Game::sendUpdatePosition (
Protocol::Packet packet;
packet.header._commandId = Protocol::CommandId::REQ_ENTITY_MOVED;
packet << player->getEntity();
- packet << pos.position.x;
- packet << pos.position.y;
+ packet << pos.position.vec.x;
+ packet << pos.position.vec.y;
packet << pos.rotation;
- packet << pos.scale.x;
- packet << pos.scale.y;
- packet << vel.velocity.x;
- packet << vel.velocity.y;
- packet << vel.acceleration.x;
- packet << vel.acceleration.y;
+ packet << pos.scale.vec.x;
+ packet << pos.scale.vec.y;
+ packet << vel.velocity.vec.x;
+ packet << vel.velocity.vec.y;
+ packet << vel.acceleration.vec.x;
+ packet << vel.acceleration.vec.y;
FLAKKARI_LOG_LOG(
"packet size: " + std::to_string(packet.size()) + " bytes\n"
"packet sent: getEntity())
- + ", Pos: (" + std::to_string(pos.position.x) + ", " + std::to_string(pos.position.y) + ")"
- + ", Vel: (" + std::to_string(vel.velocity.x) + ", " + std::to_string(vel.velocity.y) + ")"
- + ", Acc: (" + std::to_string(vel.acceleration.x) + ", " + std::to_string(vel.acceleration.y) + ")"
+ + ", Pos: (" + std::to_string(pos.position.vec.x) + ", " + std::to_string(pos.position.vec.y) + ")"
+ + ", Vel: (" + std::to_string(vel.velocity.vec.x) + ", " + std::to_string(vel.velocity.vec.y) + ")"
+ + ", Acc: (" + std::to_string(vel.acceleration.vec.x) + ", " + std::to_string(vel.acceleration.vec.y) + ")"
+ ">"
);
sendOnSameScene(player->getSceneName(), packet.serialize());
@@ -295,9 +295,9 @@ void Game::handleEvent(std::shared_ptr player, Protocol::Packetvelocity.dy = -1;
+ vel->velocity.vec.y = -1;
if (event.state == Protocol::EventState::RELEASED)
- vel->velocity.dy = 0;
+ vel->velocity.vec.y = 0;
sendUpdatePosition(player, pos.value(), vel.value());
return;
}
@@ -309,9 +309,9 @@ void Game::handleEvent(std::shared_ptr player, Protocol::Packetvelocity.dy = 1;
+ vel->velocity.vec.y = 1;
if (event.state == Protocol::EventState::RELEASED)
- vel->velocity.dy = 0;
+ vel->velocity.vec.y = 0;
sendUpdatePosition(player, pos.value(), vel.value());
return;
}
@@ -323,9 +323,9 @@ void Game::handleEvent(std::shared_ptr player, Protocol::Packetvelocity.dx = -1;
+ vel->velocity.vec.x = -1;
if (event.state == Protocol::EventState::RELEASED)
- vel->velocity.dx = 0;
+ vel->velocity.vec.x = 0;
sendUpdatePosition(player, pos.value(), vel.value());
return;
}
@@ -337,9 +337,9 @@ void Game::handleEvent(std::shared_ptr player, Protocol::Packetvelocity.dx = 1;
+ vel->velocity.vec.x = 1;
if (event.state == Protocol::EventState::RELEASED)
- vel->velocity.dx = 0;
+ vel->velocity.vec.x = 0;
sendUpdatePosition(player, pos.value(), vel.value());
return;
}
@@ -351,12 +351,12 @@ void Game::handleEvent(std::shared_ptr player, Protocol::Packet packet;
- packet.header._commandId = Protocol::CommandId::REQ_ENTITY_SHOOT;
- packet.injectString(player->getSceneName());
- packet << player->getEntity();
+ Protocol::Packet shootPacket;
+ shootPacket.header._commandId = Protocol::CommandId::REQ_ENTITY_SHOOT;
+ shootPacket.injectString(player->getSceneName());
+ shootPacket << player->getEntity();
// create a bullet with player as parent
- sendOnSameScene(player->getSceneName(), packet.serialize());
+ sendOnSameScene(player->getSceneName(), shootPacket.serialize());
}
return;
}
diff --git a/Flakkari/Server/Game/GameManager.cpp b/Flakkari/Server/Game/GameManager.cpp
index 73bc9eba..c7bd7bb3 100644
--- a/Flakkari/Server/Game/GameManager.cpp
+++ b/Flakkari/Server/Game/GameManager.cpp
@@ -24,10 +24,16 @@ GameManager::GameManager()
#if !defined(_WIN32) && !defined(_WIN64) && !defined( MSVC) && !defined(_MSC_VER)
_game_dir = std::getenv("FLAKKARI_GAME_DIR");
#else
- errno_t err = _dupenv_s(&_game_dir.data(), &_game_dir.size(), "FLAKKARI_GAME_DIR");
+ char *gameDir = nullptr;
+ size_t len = 0;
+ errno_t err = _dupenv_s(&gameDir, &len, "FLAKKARI_GAME_DIR");
+ if (err == 0 && gameDir != nullptr) {
+ _game_dir = gameDir;
+ free(gameDir);
+ }
#endif
- if (_game_dir.empty())
- FLAKKARI_LOG_FATAL("No game directory set: please set \"FLAKKARI_GAME_DIR\" environment variable");
+if (_game_dir.empty())
+ FLAKKARI_LOG_FATAL("No game directory set: please set \"FLAKKARI_GAME_DIR\" environment variable");
for (const auto & entry : std::filesystem::directory_iterator(_game_dir))
{
@@ -222,13 +228,13 @@ void GameManager::removeClientFromGame(std::string gameName, std::shared_ptraddPlayer(client)) {
+ auto waitingClient = waitingQueue.front();
+ if (instance->addPlayer(waitingClient)) {
waitingQueue.pop();
return;
}
FLAKKARI_LOG_WARNING("could not add client \""+ STR_ADDRESS +"\" to game \"" + gameName + "\"");
- if (client->isConnected())
+ if (waitingClient->isConnected())
waitingQueue.pop();
}
return;
diff --git a/Flakkari/Server/Game/GameManager.hpp b/Flakkari/Server/Game/GameManager.hpp
index e163ce7a..4e0ec855 100644
--- a/Flakkari/Server/Game/GameManager.hpp
+++ b/Flakkari/Server/Game/GameManager.hpp
@@ -26,6 +26,10 @@
#include "Game.hpp"
#include "Logger/Logger.hpp"
+#ifdef _WIN32
+ #undef max
+#endif
+
namespace Flakkari {
class GameManager {
diff --git a/Flakkari/Server/Internals/CommandManager.cpp b/Flakkari/Server/Internals/CommandManager.cpp
index 5bc4046f..f2dd568d 100644
--- a/Flakkari/Server/Internals/CommandManager.cpp
+++ b/Flakkari/Server/Internals/CommandManager.cpp
@@ -65,17 +65,10 @@ bool CommandManager::handlePasswordCommand(const std::string &input)
_unlocked = true;
FLAKKARI_LOG_INFO("Command manager unlocked");
return true;
- } else {
- FLAKKARI_LOG_WARNING("Wrong password");
- return true;
}
- if (input == "lock" && _unlocked) {
- _unlocked = false;
- FLAKKARI_LOG_INFO("Command manager locked");
- return true;
- }
- return false;
+ FLAKKARI_LOG_WARNING("Wrong password");
+ return true;
}
bool CommandManager::handleAdminCommand(const std::string &input)
@@ -110,6 +103,12 @@ bool CommandManager::handleAdminCommand(const std::string &input)
throw std::runtime_error("exit");
}
+ if (input == "lock" && _unlocked) {
+ _unlocked = false;
+ FLAKKARI_LOG_INFO("Command manager locked");
+ return true;
+ }
+
return false;
}
diff --git a/Flakkari/Server/UDPServer.cpp b/Flakkari/Server/UDPServer.cpp
index 26cbcd89..3694bd97 100644
--- a/Flakkari/Server/UDPServer.cpp
+++ b/Flakkari/Server/UDPServer.cpp
@@ -12,18 +12,18 @@
using namespace Flakkari;
-UDPServer::UDPServer(std::string ip, std::size_t port) :
- _socket(std::make_shared(
- ip, port,
- Network::Address::IpType::IPv4,
- Network::Address::SocketType::UDP
- ))
+UDPServer::UDPServer(std::string ip, unsigned short port)
{
+ Network::initNetwork();
+
+ _socket = std::make_shared();
+ _socket->create(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP);
+
FLAKKARI_LOG_INFO(std::string(*_socket));
_socket->bind();
- _io = std::make_unique(1);
- _io->addSocket(_socket->getSocket());
+ _io = std::make_unique(1);
+ _io->addSocket((int)_socket->getSocket());
_io->addSocket(STDIN_FILENO);
ClientManager::setSocket(_socket);
@@ -31,6 +31,7 @@ UDPServer::UDPServer(std::string ip, std::size_t port) :
}
UDPServer::~UDPServer() {
+ Network::cleanupNetwork();
FLAKKARI_LOG_INFO("UDPServer is now stopped");
}
@@ -38,7 +39,7 @@ bool UDPServer::handleTimeout(int event)
{
if (event != 0)
return false;
- FLAKKARI_LOG_DEBUG("ppoll timed out");
+ FLAKKARI_LOG_DEBUG(XSTR(IO_SELECTED)" timed out");
ClientManager::checkInactiveClients();
return true;
}
@@ -68,9 +69,9 @@ void UDPServer::run()
int result = _io->wait();
if (result == -1) {
- if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
+ if (_io->skipableError())
GOTO_LOOP;
- throw std::runtime_error("Failed to poll sockets, error: " + STD_ERROR);
+ throw std::runtime_error("Failed to poll sockets, error: " + SPECIAL_ERROR);
}
if (handleTimeout(result))
@@ -79,7 +80,7 @@ void UDPServer::run()
for (auto &fd : *_io) {
if (!_io->isReady(fd))
continue;
- if (handleInput(fd))
+ if (handleInput((int)fd))
continue;
handlePacket();
}
diff --git a/Flakkari/Server/UDPServer.hpp b/Flakkari/Server/UDPServer.hpp
index 65a978cf..0910565c 100644
--- a/Flakkari/Server/UDPServer.hpp
+++ b/Flakkari/Server/UDPServer.hpp
@@ -27,6 +27,18 @@ namespace Flakkari {
#define INIT_LOOP loop:
#define GOTO_LOOP goto loop;
+#ifndef STDIN_FILENO
+ #define STDIN_FILENO 0
+#endif
+
+#ifdef _PSELECT_
+ #define IO_SELECTED Network::PSELECT
+#elif defined(_WSA_)
+ #define IO_SELECTED Network::WSA
+#endif
+
+#define STR(x) #x
+#define XSTR(x) STR(x)
/**
* @brief UDP Server class that handles incoming packets and clients
@@ -53,7 +65,7 @@ class UDPServer {
* @param ip The ip to bind the server to (default: localhost)
* @param port The port to bind the server to (default: 8080)
*/
- UDPServer(std::string ip = "localhost", std::size_t port = 8080);
+ UDPServer(std::string ip = "localhost", unsigned short port = 8080);
~UDPServer();
/**
@@ -91,7 +103,7 @@ class UDPServer {
private:
std::shared_ptr _socket;
- std::unique_ptr _io;
+ std::unique_ptr _io;
};
} /* namespace Flakkari */
diff --git a/Flakkari/core.cpp b/Flakkari/core.cpp
index 39735c7d..3104436a 100644
--- a/Flakkari/core.cpp
+++ b/Flakkari/core.cpp
@@ -9,10 +9,10 @@
int main(int ac, const char *av[])
{
- if (ac != 2)
- return FLAKKARI_LOG_ERROR("Usage: ./r-type_server "), 84;
+ if (ac != 3)
+ return FLAKKARI_LOG_ERROR("Usage: ./r-type_server "), 84;
try {
- Flakkari::UDPServer server(av[1], 8080);
+ Flakkari::UDPServer server(av[1], static_cast(std::stoi(av[2])));
server.run();
} catch (const std::exception &e) {
if (std::string(e.what()) != "exit")
diff --git a/README.md b/README.md
index f5f886c9..5d8ab268 100644
--- a/README.md
+++ b/README.md
@@ -72,13 +72,19 @@ $> cd build
# Or configure the project with Ninja
(build)$> cmake -G Ninja .. && cmake --build .
+# Set the FLAKKARI_GAME_DIR environment variable
+(build)$> export FLAKKARI_GAME_DIR=
+
+# for windows
+(build)$> set FLAKKARI_GAME_DIR=
+
# Run the server executable
(build)$> ./r-type_server
```
> [!NOTE]
-> - the server load Games from the `./Games` directory, so if you want to add a game,
-> you have to put it in this directory before running.
+> - the server load Games from the `FLAKKARI_GAME_DIR` environment variable,
+> so if you want to add a game, you have to put it in this directory before running.
> If the server is already running, use the `addGame ` command to load it.
> [!NOTE]
diff --git a/docs/examples/TCPServer.cpp b/docs/examples/TCPServer.cpp
index f30acdf0..a84208db 100644
--- a/docs/examples/TCPServer.cpp
+++ b/docs/examples/TCPServer.cpp
@@ -20,23 +20,38 @@
#define TCPSERVER_HPP_
#include "Network/IOMultiplexer.hpp"
+#include "Network/Network.hpp"
+
+#ifndef STDIN_FILENO
+ #define STDIN_FILENO 0
+#endif
+
+#ifdef _PSELECT_
+ #define IO_SELECTED Network::PSELECT
+#elif defined(_WSA_)
+ #define IO_SELECTED Network::WSA
+#endif
namespace Flakkari {
class TCPServer {
public:
TCPServer(std::string ip = "localhost", std::size_t port = 8080) :
- _socket(Network::Socket(ip, port, Network::Address::IpType::IPv6, Network::Address::SocketType::TCP))
+ _io(std::make_unique())
{
+ Network::initNetwork();
+
+ _socket.create(ip, port, Network::Address::IpType::IPv6, Network::Address::SocketType::TCP);
std::cout << _socket << std::endl;
_socket.bind();
_socket.listen();
- _io = std::make_unique();
_io->addSocket(_socket.getSocket());
_io->addSocket(STDIN_FILENO);
}
- ~TCPServer() = default;
+ ~TCPServer() {
+ Network::cleanupNetwork();
+ }
int run() {
while (true)
@@ -53,10 +68,10 @@ class TCPServer {
for (auto &fd : *_io) {
if (_io->isReady(fd)) {
auto packet = _socket.receive();
- std::cout << (*packet.value().first.get());
+ std::cout << packet.value().data();
std::cout << " : ";
- std::cout << packet.value().second << std::endl;
- _socket.send(packet.value().first, packet.value().second);
+ std::cout << packet.value().size() << std::endl;
+ _socket.send(packet.value());
}
}
}
@@ -66,7 +81,7 @@ class TCPServer {
protected:
private:
Network::Socket _socket;
- std::unique_ptr _io;
+ std::unique_ptr _io;
};
} /* namespace Flakkari */
diff --git a/docs/examples/UDPClient.hpp b/docs/examples/UDPClient.hpp
index 0ab6ae03..dea9d6d3 100644
--- a/docs/examples/UDPClient.hpp
+++ b/docs/examples/UDPClient.hpp
@@ -19,20 +19,30 @@
#define UDPCLIENT_HPP_
#include "Network/IOMultiplexer.hpp"
+#include "Network/Network.hpp"
+
+#ifdef _PSELECT_
+ #define IO_SELECTED Network::PSELECT
+#elif defined(_WSA_)
+ #define IO_SELECTED Network::WSA
+#endif
namespace Flakkari {
class UDPClient {
public:
- UDPClient(std::string ip = "localhost", std::size_t port = 8080) :
- _socket(Network::Socket(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP))
+ UDPClient(std::string ip = "localhost", unsigned short port = 8080) :
+ _io(std::make_unique())
{
- std::cout << _socket << std::endl;
+ Network::initNetwork();
- _io = std::make_unique();
+ _socket.create(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP);
+ std::cout << _socket << std::endl;
_io->addSocket(_socket.getSocket());
}
- ~UDPClient() = default;
+ ~UDPClient() {
+ Network::cleanupNetwork();
+ }
int run() {
while (true)
@@ -65,7 +75,7 @@ class UDPClient {
protected:
private:
Network::Socket _socket;
- std::unique_ptr _io;
+ std::unique_ptr _io;
};
} /* namespace Flakkari */
diff --git a/docs/examples/UDPServer.hpp b/docs/examples/UDPServer.hpp
index 7deee7de..7143707e 100644
--- a/docs/examples/UDPServer.hpp
+++ b/docs/examples/UDPServer.hpp
@@ -20,22 +20,37 @@
#define UDPSERVER_HPP_
#include "Network/IOMultiplexer.hpp"
+#include "Network/Network.hpp"
+
+#ifndef STDIN_FILENO
+ #define STDIN_FILENO 0
+#endif
+
+#ifdef _PSELECT_
+ #define IO_SELECTED Network::PSELECT
+#elif defined(_WSA_)
+ #define IO_SELECTED Network::WSA
+#endif
namespace Flakkari {
class UDPServer {
public:
- UDPServer(std::string ip = "localhost", std::size_t port = 8080) :
- _socket(Network::Socket(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP))
+ UDPServer(std::string ip, unsigned short port) :
+ _io(std::make_unique())
{
+ Network::initNetwork();
+
+ _socket.create(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP);
std::cout << _socket << std::endl;
_socket.bind();
- _io = std::make_unique();
_io->addSocket(_socket.getSocket());
_io->addSocket(STDIN_FILENO);
}
- ~UDPServer() = default;
+ ~UDPServer() {
+ Network::cleanupNetwork();
+ }
int run() {
while (true)
@@ -65,7 +80,7 @@ class UDPServer {
protected:
private:
Network::Socket _socket;
- std::unique_ptr _io;
+ std::unique_ptr _io;
};
} /* namespace Flakkari */
From cb0ce7ab4b3533ef36f77d4f0c4c9d19a35fb2b1 Mon Sep 17 00:00:00 2001
From: Marrbol
Date: Mon, 28 Oct 2024 07:56:17 +0100
Subject: [PATCH 05/11] fix: simplify entity template loading logic
This commit simplifies the logic for loading entity templates in the Game class. Instead of iterating through the template items and component items separately, it now directly matches the template key with the component key. This improves readability and reduces unnecessary iterations.
Refactor the loadEntityFromTemplate function in Game.cpp to use the template key and component key directly for loading components and registering the Template component.
---
Flakkari/Server/Game/Game.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Flakkari/Server/Game/Game.cpp b/Flakkari/Server/Game/Game.cpp
index 363ea496..e23f55f3 100644
--- a/Flakkari/Server/Game/Game.cpp
+++ b/Flakkari/Server/Game/Game.cpp
@@ -168,11 +168,11 @@ void Game::loadEntityFromTemplate (
for (auto &componentInfo : entity.begin().value().items()) {
for (auto &templateInfo : templates.items()) {
- if (templateInfo.value().begin().key() != componentInfo.value())
+ if (templateInfo.key() != componentInfo.key())
continue;
- loadComponents(registry, templateInfo.value().begin().value(), newEntity);
+ loadComponents(registry, templateInfo.value(), newEntity);
registry.registerComponent();
- registry.add_component(newEntity, templateInfo.value().begin().key());
+ registry.add_component(newEntity, templateInfo.key());
}
}
}
From 2dfbea973edde158a9d6b7bd9e7d7f8a9406a19a Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Mon, 28 Oct 2024 06:55:16 -0400
Subject: [PATCH 06/11] refactor: network initialization and cleanup functions
This commit refactors the network initialization and cleanup functions in the Flakkari library. The functions `initNetwork()` and `cleanupNetwork()` have been renamed to `init()` and `cleanup()` respectively. This change improves the clarity and consistency of the codebase.
The affected files are:
- Flakkari/Network/Network.cpp
- Flakkari/Network/Network.hpp
- Flakkari/Server/UDPServer.cpp
- Flakkari/Server/UDPServer.hpp
- docs/examples/TCPServer.cpp
- docs/examples/UDPClient.hpp
- docs/examples/UDPServer.hpp
---
Flakkari/Network/IOMultiplexer.hpp | 6 ++++++
Flakkari/Network/Network.cpp | 4 ++--
Flakkari/Network/Network.hpp | 4 ++--
Flakkari/Network/Socket.cpp | 4 ++--
Flakkari/Server/UDPServer.cpp | 4 ++--
Flakkari/Server/UDPServer.hpp | 6 ------
docs/examples/TCPServer.cpp | 10 ++--------
docs/examples/UDPClient.hpp | 10 ++--------
docs/examples/UDPServer.hpp | 10 ++--------
9 files changed, 20 insertions(+), 38 deletions(-)
diff --git a/Flakkari/Network/IOMultiplexer.hpp b/Flakkari/Network/IOMultiplexer.hpp
index a2108cd7..bf19af0d 100644
--- a/Flakkari/Network/IOMultiplexer.hpp
+++ b/Flakkari/Network/IOMultiplexer.hpp
@@ -326,6 +326,12 @@ class WSA {
};
#endif
+#ifdef _PSELECT_
+ #define IO_SELECTED Network::PSELECT
+#elif defined(_WSA_)
+ #define IO_SELECTED Network::WSA
+#endif
+
} // namespace Flakkari::Network
#endif /* !IOMULTIPLEXER_HPP_ */
diff --git a/Flakkari/Network/Network.cpp b/Flakkari/Network/Network.cpp
index 8c04be84..509186a6 100644
--- a/Flakkari/Network/Network.cpp
+++ b/Flakkari/Network/Network.cpp
@@ -11,7 +11,7 @@
namespace Flakkari::Network {
-void initNetwork()
+void init()
{
#ifdef _WIN32
WSADATA WSAData;
@@ -21,7 +21,7 @@ void initNetwork()
#endif
}
-void cleanupNetwork()
+void cleanup()
{
#ifdef _WIN32
::WSACleanup();
diff --git a/Flakkari/Network/Network.hpp b/Flakkari/Network/Network.hpp
index cc6f0365..8ec242f0 100644
--- a/Flakkari/Network/Network.hpp
+++ b/Flakkari/Network/Network.hpp
@@ -25,14 +25,14 @@ namespace Flakkari::Network {
* This function is only used by Windows.
*
*/
-void initNetwork();
+void init();
/**
* @brief Cleanup the network.
* This function is only used by Windows.
*
*/
-void cleanupNetwork();
+void cleanup();
} // namespace Flakkari::Network
diff --git a/Flakkari/Network/Socket.cpp b/Flakkari/Network/Socket.cpp
index ccbc2169..d66a56fc 100644
--- a/Flakkari/Network/Socket.cpp
+++ b/Flakkari/Network/Socket.cpp
@@ -252,7 +252,7 @@ void Socket::sendTo(const std::shared_ptr &address, const Buffer &data,
return FLAKKARI_LOG_ERROR("Address is nullptr"), void();
#ifdef _WIN32
- if (::sendto(_socket, (const char *)data.getData(), (int)data.getSize(), flags, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
+ if (::sendto(_socket, (const char *)data.getData(), (int)data.getSize(), flags, addr->ai_addr, (int)addr->ai_addrlen) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to send \"" + std::string(data.begin(), data.end()) + "\" to \"" + address->toString().value_or("No address") + "\", error: " + STD_ERROR);
return;
}
@@ -272,7 +272,7 @@ void Socket::sendTo(const std::shared_ptr &address, const byte *data, c
return FLAKKARI_LOG_ERROR("Address is nullptr"), void();
#if _WIN32
- if (::sendto(_socket, (const char *)data, (int)size, flags, addr->ai_addr, addr->ai_addrlen) == SOCKET_ERROR) {
+ if (::sendto(_socket, (const char *)data, (int)size, flags, addr->ai_addr, (int)addr->ai_addrlen) == SOCKET_ERROR) {
FLAKKARI_LOG_ERROR("Failed to send \""+ std::string(data, data + size) +"\" to \""+ address->toString().value_or("No address") +"\", error: "+ STD_ERROR);
return;
}
diff --git a/Flakkari/Server/UDPServer.cpp b/Flakkari/Server/UDPServer.cpp
index 3694bd97..2c47b383 100644
--- a/Flakkari/Server/UDPServer.cpp
+++ b/Flakkari/Server/UDPServer.cpp
@@ -14,7 +14,7 @@ using namespace Flakkari;
UDPServer::UDPServer(std::string ip, unsigned short port)
{
- Network::initNetwork();
+ Network::init();
_socket = std::make_shared();
_socket->create(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP);
@@ -31,7 +31,7 @@ UDPServer::UDPServer(std::string ip, unsigned short port)
}
UDPServer::~UDPServer() {
- Network::cleanupNetwork();
+ Network::cleanup();
FLAKKARI_LOG_INFO("UDPServer is now stopped");
}
diff --git a/Flakkari/Server/UDPServer.hpp b/Flakkari/Server/UDPServer.hpp
index 0910565c..932f38a9 100644
--- a/Flakkari/Server/UDPServer.hpp
+++ b/Flakkari/Server/UDPServer.hpp
@@ -31,12 +31,6 @@ namespace Flakkari {
#define STDIN_FILENO 0
#endif
-#ifdef _PSELECT_
- #define IO_SELECTED Network::PSELECT
-#elif defined(_WSA_)
- #define IO_SELECTED Network::WSA
-#endif
-
#define STR(x) #x
#define XSTR(x) STR(x)
diff --git a/docs/examples/TCPServer.cpp b/docs/examples/TCPServer.cpp
index a84208db..0cdd6b99 100644
--- a/docs/examples/TCPServer.cpp
+++ b/docs/examples/TCPServer.cpp
@@ -26,12 +26,6 @@
#define STDIN_FILENO 0
#endif
-#ifdef _PSELECT_
- #define IO_SELECTED Network::PSELECT
-#elif defined(_WSA_)
- #define IO_SELECTED Network::WSA
-#endif
-
namespace Flakkari {
class TCPServer {
@@ -39,7 +33,7 @@ class TCPServer {
TCPServer(std::string ip = "localhost", std::size_t port = 8080) :
_io(std::make_unique())
{
- Network::initNetwork();
+ Network::init();
_socket.create(ip, port, Network::Address::IpType::IPv6, Network::Address::SocketType::TCP);
std::cout << _socket << std::endl;
@@ -50,7 +44,7 @@ class TCPServer {
_io->addSocket(STDIN_FILENO);
}
~TCPServer() {
- Network::cleanupNetwork();
+ Network::cleanup();
}
int run() {
diff --git a/docs/examples/UDPClient.hpp b/docs/examples/UDPClient.hpp
index dea9d6d3..b4f17b87 100644
--- a/docs/examples/UDPClient.hpp
+++ b/docs/examples/UDPClient.hpp
@@ -21,12 +21,6 @@
#include "Network/IOMultiplexer.hpp"
#include "Network/Network.hpp"
-#ifdef _PSELECT_
- #define IO_SELECTED Network::PSELECT
-#elif defined(_WSA_)
- #define IO_SELECTED Network::WSA
-#endif
-
namespace Flakkari {
class UDPClient {
@@ -34,14 +28,14 @@ class UDPClient {
UDPClient(std::string ip = "localhost", unsigned short port = 8080) :
_io(std::make_unique())
{
- Network::initNetwork();
+ Network::init();
_socket.create(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP);
std::cout << _socket << std::endl;
_io->addSocket(_socket.getSocket());
}
~UDPClient() {
- Network::cleanupNetwork();
+ Network::cleanup();
}
int run() {
diff --git a/docs/examples/UDPServer.hpp b/docs/examples/UDPServer.hpp
index 7143707e..ed504931 100644
--- a/docs/examples/UDPServer.hpp
+++ b/docs/examples/UDPServer.hpp
@@ -26,12 +26,6 @@
#define STDIN_FILENO 0
#endif
-#ifdef _PSELECT_
- #define IO_SELECTED Network::PSELECT
-#elif defined(_WSA_)
- #define IO_SELECTED Network::WSA
-#endif
-
namespace Flakkari {
class UDPServer {
@@ -39,7 +33,7 @@ class UDPServer {
UDPServer(std::string ip, unsigned short port) :
_io(std::make_unique())
{
- Network::initNetwork();
+ Network::init();
_socket.create(ip, port, Network::Address::IpType::IPv4, Network::Address::SocketType::UDP);
std::cout << _socket << std::endl;
@@ -49,7 +43,7 @@ class UDPServer {
_io->addSocket(STDIN_FILENO);
}
~UDPServer() {
- Network::cleanupNetwork();
+ Network::cleanup();
}
int run() {
From 4853d131d7302a06d9362641a1d59b2e8a006437 Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Wed, 6 Nov 2024 22:55:46 -0500
Subject: [PATCH 07/11] refactor: update version incrementing script to update
related files
---
Scripts/increment_version.py | 67 +++++++++++++++++++++++++++++++++---
1 file changed, 62 insertions(+), 5 deletions(-)
diff --git a/Scripts/increment_version.py b/Scripts/increment_version.py
index 9c8e64a3..86b086e2 100644
--- a/Scripts/increment_version.py
+++ b/Scripts/increment_version.py
@@ -6,17 +6,53 @@
# Created on: 2023-10-12
import re
+import os
+import sys
-def increment_version(current_version: str):
+major = 0
+minor = 0
+patch = 0
+
+def increment_version(current_version: str) -> str:
match = re.search(r'v(\d+\.\d+\.\d+)', current_version)
if match:
current_version_number = match.group(1)
major, minor, patch = map(int, current_version_number.split('.'))
- return f"Flakkari v{major}.{minor}.{patch + 1}"
+ if sys.argv[1] == "major":
+ return f"{major + 1}.0.0"
+ elif sys.argv[1] == "minor":
+ return f"{major}.{minor + 1}.0"
+ elif sys.argv[1] == "patch":
+ return f"{major}.{minor}.{patch + 1}"
+ else:
+ raise ValueError(f"Invalid version increment: {sys.argv[1]}")
+
+ raise ValueError(f"Invalid version format: {current_version}")
+
+def increment_doxyfile_version(new_version: str):
+ with open("Doxyfile.cfg", "r") as f:
+ content = f.read()
+
+ content = re.sub(r'PROJECT_NUMBER\s+=\s+\d+\.\d+\.\d+', f'PROJECT_NUMBER = {new_version}', content)
+
+ with open("Doxyfile.cfg", "w") as f:
+ f.write(content)
+
+def increment_config_in_version(path: str, new_version: str):
+ major, minor, patch = map(int, new_version.split('.'))
- return current_version
+ with open(path, "r") as f:
+ content = f.read()
-if __name__ == "__main__":
+ content = re.sub(r'(\d+\.\d+\.\d+)', f"{major}.{minor}.{patch}", content)
+ content = re.sub(r'#define FLAKKARI_VERSION_MAJOR \d+', f'#define FLAKKARI_VERSION_MAJOR {major}', content)
+ content = re.sub(r'#define FLAKKARI_VERSION_MINOR \d+', f'#define FLAKKARI_VERSION_MINOR {minor}', content)
+ content = re.sub(r'#define FLAKKARI_VERSION_PATCH \d+', f'#define FLAKKARI_VERSION_PATCH {patch}', content)
+
+ with open(path, "w") as f:
+ f.write(content)
+
+if __name__ == "__main__" and len(sys.argv) == 2:
# Read the current version from the VERSION file
with open("VERSION", "r") as version_file:
current_version = version_file.read().strip()
@@ -25,4 +61,25 @@ def increment_version(current_version: str):
# Update the VERSION file with the new version
with open("VERSION", "w") as version_file:
- version_file.write(new_version)
+ version_file.write( f"Flakkari v{new_version}\n")
+
+ print(f"Updating version {current_version} -> {new_version} in VERSION")
+
+ increment_doxyfile_version(new_version)
+
+ print(f"Updating version {current_version} -> {new_version} in Doxyfile.cfg")
+
+ # loop in all the files recursively and update the version
+ for root, dirs, files in os.walk("./Flakkari/"):
+ for file in files:
+ if file.endswith(".cpp") or file.endswith(".h") or file.endswith(".md") or file.endswith(".hpp"):
+ print(f"Updating version {current_version} -> {new_version} in {file}")
+ match = re.search(r'(\d+\.\d+\.\d+)', current_version)
+ if match:
+ current_version_number = match.group(1)
+ with open(os.path.join(root, file), "r") as f:
+ content = f.read()
+ with open(os.path.join(root, file), "w") as f:
+ f.write(content.replace(current_version_number, new_version))
+ if file.endswith(".h.in"):
+ increment_config_in_version(os.path.join(root, file), new_version)
From dc866ec468bbebaeeca0b2d654d3ed03b49ead0e Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Wed, 6 Nov 2024 23:58:13 -0500
Subject: [PATCH 08/11] refactor: enhance version incrementing script with
detailed documentation and additional functionality
---
Scripts/increment_version.py | 137 ++++++++++++++++++++++++++++-------
1 file changed, 112 insertions(+), 25 deletions(-)
diff --git a/Scripts/increment_version.py b/Scripts/increment_version.py
index 86b086e2..7a616bb2 100644
--- a/Scripts/increment_version.py
+++ b/Scripts/increment_version.py
@@ -9,11 +9,22 @@
import os
import sys
-major = 0
-minor = 0
-patch = 0
-
def increment_version(current_version: str) -> str:
+ """
+ Increment the given version string based on the command line argument.
+
+ The function expects the version string to be in the format 'v..'.
+ It increments the version based on the first command line argument, which can be "major", "minor", or "patch".
+
+ Args:
+ current_version (str): The current version string in the format 'v..'.
+
+ Returns:
+ str: The incremented version string.
+
+ Raises:
+ ValueError: If the version format is invalid or if the increment type is invalid.
+ """
match = re.search(r'v(\d+\.\d+\.\d+)', current_version)
if match:
current_version_number = match.group(1)
@@ -29,16 +40,57 @@ def increment_version(current_version: str) -> str:
raise ValueError(f"Invalid version format: {current_version}")
-def increment_doxyfile_version(new_version: str):
+def increment_doxyfile_version(new_version: str) -> None:
+ """
+ Updates the version number in the Doxyfile.cfg file for the Flakkari-Server project.
+
+ Args:
+ new_version (str): The new version number to set in the format 'major.minor.patch'.
+
+ Returns:
+ None
+ """
with open("Doxyfile.cfg", "r") as f:
content = f.read()
content = re.sub(r'PROJECT_NUMBER\s+=\s+\d+\.\d+\.\d+', f'PROJECT_NUMBER = {new_version}', content)
- with open("Doxyfile.cfg", "w") as f:
+ with open("Doxyfile.cfg", "w", newline='\n') as f:
+ f.write(content)
+
+def increment_cmakelists_version(new_version: str) -> None:
+ """
+ Updates the version number in the CMakeLists.txt file for the Flakkari-Server project.
+
+ Args:
+ new_version (str): The new version number to set in the format 'major.minor.patch'.
+
+ Returns:
+ None
+ """
+ with open("CMakeLists.txt", "r") as f:
+ content = f.read()
+
+ content = re.sub(r'project\(Flakkari-Server VERSION \d+\.\d+\.\d+', f'project(Flakkari-Server VERSION {new_version}', content)
+
+ with open("CMakeLists.txt", "w", newline='\n') as f:
f.write(content)
-def increment_config_in_version(path: str, new_version: str):
+def increment_config_in_version(path: str, new_version: str) -> None:
+ """
+ Updates the version information in the specified configuration file.
+
+ This function reads the content of the file at the given path, updates the version
+ information to the new version provided, and writes the updated content back to the file.
+ The version information is expected to be in the format 'major.minor.patch'.
+
+ Args:
+ path (str): The path to the configuration file to be updated.
+ new_version (str): The new version string in the format 'major.minor.patch'.
+
+ Returns:
+ None
+ """
major, minor, patch = map(int, new_version.split('.'))
with open(path, "r") as f:
@@ -49,28 +101,25 @@ def increment_config_in_version(path: str, new_version: str):
content = re.sub(r'#define FLAKKARI_VERSION_MINOR \d+', f'#define FLAKKARI_VERSION_MINOR {minor}', content)
content = re.sub(r'#define FLAKKARI_VERSION_PATCH \d+', f'#define FLAKKARI_VERSION_PATCH {patch}', content)
- with open(path, "w") as f:
+ with open(path, "w", newline='\n') as f:
f.write(content)
-if __name__ == "__main__" and len(sys.argv) == 2:
- # Read the current version from the VERSION file
- with open("VERSION", "r") as version_file:
- current_version = version_file.read().strip()
+def loop_in_files(path: str, current_version: str, new_version: str) -> None:
+ """
+ Recursively updates the version number in specified file types within a given directory.
- new_version = increment_version(current_version)
+ Args:
+ path (str): The root directory path to start the search.
+ current_version (str): The current version number to be replaced.
+ new_version (str): The new version number to replace the current version.
- # Update the VERSION file with the new version
- with open("VERSION", "w") as version_file:
- version_file.write( f"Flakkari v{new_version}\n")
+ Returns:
+ None
- print(f"Updating version {current_version} -> {new_version} in VERSION")
-
- increment_doxyfile_version(new_version)
-
- print(f"Updating version {current_version} -> {new_version} in Doxyfile.cfg")
-
- # loop in all the files recursively and update the version
- for root, dirs, files in os.walk("./Flakkari/"):
+ This function searches for files with extensions .cpp, .h, .md, .hpp, and .h.in within the given directory
+ and its subdirectories. It updates the version number in these files from the current version to the new version.
+ """
+ for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(".cpp") or file.endswith(".h") or file.endswith(".md") or file.endswith(".hpp"):
print(f"Updating version {current_version} -> {new_version} in {file}")
@@ -79,7 +128,45 @@ def increment_config_in_version(path: str, new_version: str):
current_version_number = match.group(1)
with open(os.path.join(root, file), "r") as f:
content = f.read()
- with open(os.path.join(root, file), "w") as f:
+ with open(os.path.join(root, file), "w", newline='\n') as f:
f.write(content.replace(current_version_number, new_version))
+
if file.endswith(".h.in"):
+ print(f"Updating version {current_version} -> {new_version} in {file}")
increment_config_in_version(os.path.join(root, file), new_version)
+
+def main():
+ """
+ Main function to increment the version of the project.
+
+ This function performs the following steps:
+ 1. Reads the current version from the VERSION file.
+ 2. Increments the version using the `increment_version` function.
+ 3. Updates the VERSION file with the new version.
+ 4. Updates the version in the Doxyfile.cfg file.
+ 5. Updates the version in the CMakeLists.txt file.
+ 6. Recursively updates the version in all relevant files within the ./Flakkari/ directory.
+
+ Raises:
+ FileNotFoundError: If the VERSION file does not exist.
+ IOError: If there is an error reading or writing to the VERSION file.
+ """
+ with open("VERSION", "r") as version_file:
+ current_version = version_file.read().strip()
+
+ new_version = increment_version(current_version)
+
+ print(f"Updating version {current_version} -> {new_version} in VERSION")
+ with open("VERSION", "w", newline='\n') as version_file:
+ version_file.write(f"Flakkari v{new_version}\n")
+
+ print(f"Updating version {current_version} -> {new_version} in Doxyfile.cfg")
+ increment_doxyfile_version(new_version)
+
+ print(f"Updating version {current_version} -> {new_version} in CMakeLists.txt")
+ increment_cmakelists_version(new_version)
+
+ loop_in_files("./Flakkari/", current_version, new_version)
+
+if __name__ == "__main__" and len(sys.argv) == 2:
+ main()
From 48a94250a6647cbbef5c7100ebed9f1581746cd0 Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Thu, 7 Nov 2024 00:10:13 -0500
Subject: [PATCH 09/11] refactor: rename project and update CMake configuration
for Flakkari server
---
CMakeLists.txt | 29 +++++++++++++++--------------
CONTRIBUTING.md | 4 +++-
Doxyfile.cfg | 2 +-
README.md | 17 +++++++++++------
4 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index acbff0ae..c21b45dd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
# Flakkari/CMakeLists.txt
-cmake_minimum_required(VERSION 3.22.0)
+cmake_minimum_required(VERSION 3.2...3.22)
-project(R-Type_Server)
+project(Flakkari-Server VERSION 0.2.0 LANGUAGES CXX)
# Add all your source and headers files:
set(SOURCES
@@ -112,32 +112,33 @@ set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(FLAKKARI_GAME_DIR ${CMAKE_SOURCE_DIR}/Games)
+message(STATUS "FLAKKARI_GAME_DIR: ${FLAKKARI_GAME_DIR}")
# Compiler Standards:
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Compiler Warnings:
-if(MSVC)
+if (MSVC)
add_compile_options(/W4)
-elseif(WIN32)
+elseif (WIN32)
add_compile_options(-Wall -Wextra)
else()
add_compile_options(-Wall -Wextra)
endif()
# Create the executable
-add_executable(r-type_server ${SOURCES} ${HEADERS})
+add_executable(flakkari ${SOURCES} ${HEADERS})
# Include Directories:
-target_include_directories(r-type_server PRIVATE ${CMAKE_SOURCE_DIR}/Flakkari)
+target_include_directories(flakkari PRIVATE ${CMAKE_SOURCE_DIR}/Flakkari)
# Link Libraries:
-target_link_libraries(r-type_server PRIVATE nlohmann_json::nlohmann_json)
+target_link_libraries(flakkari PRIVATE nlohmann_json::nlohmann_json)
# Documentation: sudo apt-get install graphviz
find_package(Doxygen)
-if(DOXYGEN_FOUND)
+if (DOXYGEN_FOUND)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile.cfg
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@@ -154,14 +155,14 @@ set(PROJECT_VERSION_PATCH 0)
configure_file(${CMAKE_SOURCE_DIR}/Flakkari/config.h.in ${CMAKE_BINARY_DIR}/config.h)
# Install Targets:
-install(TARGETS r-type_server DESTINATION bin)
+install(TARGETS flakkari DESTINATION bin)
install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/Flakkari)
install(FILES ${HEADER_LIB_LOGGER} DESTINATION include/Flakkari/Logger)
install(FILES ${HEADER_LIB_NETWORK} DESTINATION include/Flakkari/Network)
install(FILES ${HEADER_LIB_PROTOCOL} DESTINATION include/Flakkari/Protocol)
# Packaging:
-set(CPACK_PACKAGE_NAME "r-type_server")
+set(CPACK_PACKAGE_NAME "flakkari")
set(CPACK_PACKAGE_VENDOR "R-Type")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "R-Type Server")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
@@ -185,14 +186,14 @@ set(SOURCES_LIB_NETWORK
Flakkari/Network/Socket.cpp
Flakkari/Network/IOMultiplexer.cpp
)
-add_library(r-type_server_network SHARED ${SOURCES_LIB_NETWORK} ${HEADER_LIB_NETWORK} ${HEADER_LIB_LOGGER})
+add_library(flakkari_network SHARED ${SOURCES_LIB_NETWORK} ${HEADER_LIB_NETWORK} ${HEADER_LIB_LOGGER})
# Include Directories:
-target_include_directories(r-type_server_network PRIVATE ${CMAKE_SOURCE_DIR}/Flakkari)
+target_include_directories(flakkari_network PRIVATE ${CMAKE_SOURCE_DIR}/Flakkari)
# Link Libraries:
-target_link_libraries(r-type_server_network PRIVATE nlohmann_json::nlohmann_json)
+target_link_libraries(flakkari_network PRIVATE nlohmann_json::nlohmann_json)
# Install dynamic library:
-install(TARGETS r-type_server_network DESTINATION lib)
+install(TARGETS flakkari_network DESTINATION lib)
install(FILES ${HEADER_LIB_NETWORK} DESTINATION include/Flakkari/Network)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index f7151bec..46665e0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -39,7 +39,9 @@ See the [Table of Contents](#table-of-contents) for different ways to help and d
Here, you can provide a brief overview of what the Flakkari project is about and why contributions are important.
-v0.2.0 of the project is currently under development. You can find the latest release [here](https://github.com/MasterLaplace/Flakkari/releases/latest/) and the changelog [here](CHANGELOG.md).
+Flakkari is a Epitech/Laval Student project. It is a simple game server written in C++. The project is designed to be a lightweight and easy-to-use server that can be used for various purposes. The server is also part of the Laplace-Project, a collection of libraries that provide a set of tools for developing games, os, applications, and more.
+The project is open-source and welcomes contributions from the community. If you're interested in helping out, you can find more information on how to contribute below.
+Flakkari is currently under development. You can find the latest release [here](https://github.com/MasterLaplace/Flakkari/releases/latest/) and the changelog [here](CHANGELOG.md).
----
diff --git a/Doxyfile.cfg b/Doxyfile.cfg
index 92ab9734..69ff9f83 100644
--- a/Doxyfile.cfg
+++ b/Doxyfile.cfg
@@ -48,7 +48,7 @@ PROJECT_NAME = "Flakkari"
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER =
+PROJECT_NUMBER = 0.2.0
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/README.md b/README.md
index 5d8ab268..43f40b1a 100644
--- a/README.md
+++ b/README.md
@@ -11,12 +11,13 @@
-🌐 Supported Platforms
+
🌐 Supported Platforms
+ :
|
|
+ >
+
-📡 Supported Protocol
-
-
+
📡 Supported Protocol
+ :
+
+ |
+
+
From 3b789bebe43faffc42f206a05bb8e3bae52af956 Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Thu, 7 Nov 2024 00:11:37 -0500
Subject: [PATCH 10/11] feat: add GitHub Actions workflow to bump patch version
and create release
---
.github/workflows/create_patch.yml | 60 ++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
create mode 100644 .github/workflows/create_patch.yml
diff --git a/.github/workflows/create_patch.yml b/.github/workflows/create_patch.yml
new file mode 100644
index 00000000..f1a40e4d
--- /dev/null
+++ b/.github/workflows/create_patch.yml
@@ -0,0 +1,60 @@
+name: Bump Patch Version
+
+on:
+ pull_request:
+ types: [closed]
+ branches:
+ - master
+ - main
+
+permissions:
+ contents: write
+
+jobs:
+ create_release:
+ name: Bump version and create release
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Install Python
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.8'
+
+ - name: Run Version Bump Script
+ run: |
+ python3 Scripts/increment_version.py patch
+
+ - name: Set up SSH
+ uses: webfactory/ssh-agent@v0.9.0
+ with:
+ ssh-private-key: ${{ secrets.GIT_SSH_PRIVATE_KEY }}
+
+ - name: Set up Git
+ run: |
+ git config --global user.name "github-actions[bot]"
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
+
+ - name: Push changes
+ run: |
+ git add .
+ git commit -m "chore: bump the Flakkari patch version" || true
+ git push || true
+
+ - name: Bump version and push tag
+ id: tag_version
+ uses: mathieudutour/github-tag-action@v6.2
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ default_bump: patch
+
+ - name: Create a GitHub release
+ uses: ncipollo/release-action@v1.14.0
+ with:
+ tag: ${{ steps.tag_version.outputs.new_tag }}
+ name: Flakkari ${{ steps.tag_version.outputs.new_tag }}
+ body: ${{ steps.tag_version.outputs.changelog }}
+ draft: false
+ prerelease: false
+ generateReleaseNotes: true
From 715e4cc76984e46ea31e116fbb36cf76a374a3cc Mon Sep 17 00:00:00 2001
From: MasterLaplace
Date: Thu, 7 Nov 2024 00:15:01 -0500
Subject: [PATCH 11/11] feat: add workflow to bump minor version and create
release; refactor patch release workflow
---
.github/workflows/create_minor.yml | 57 ++++++++++++++++++++++++++++
.github/workflows/create_patch.yml | 2 +-
.github/workflows/create_release.yml | 24 ------------
3 files changed, 58 insertions(+), 25 deletions(-)
create mode 100644 .github/workflows/create_minor.yml
delete mode 100644 .github/workflows/create_release.yml
diff --git a/.github/workflows/create_minor.yml b/.github/workflows/create_minor.yml
new file mode 100644
index 00000000..b7f9040c
--- /dev/null
+++ b/.github/workflows/create_minor.yml
@@ -0,0 +1,57 @@
+name: Bump Minor Version and Create Release
+
+on:
+ milestone:
+ types: closed
+
+permissions:
+ contents: write
+
+jobs:
+ create_minor_release:
+ name: Bump version and create release
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Install Python
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.8'
+
+ - name: Run Version Bump Script
+ run: |
+ python3 Scripts/increment_version.py minor
+
+ - name: Set up SSH
+ uses: webfactory/ssh-agent@v0.9.0
+ with:
+ ssh-private-key: ${{ secrets.GIT_SSH_PRIVATE_KEY }}
+
+ - name: Set up Git
+ run: |
+ git config --global user.name "github-actions[bot]"
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
+
+ - name: Push changes
+ run: |
+ git add .
+ git commit -m "chore: bump the Flakkari minor version" || true
+ git push || true
+
+ - name: Bump version and push tag
+ id: tag_version
+ uses: mathieudutour/github-tag-action@v6.2
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ default_bump: minor
+
+ - name: Create a GitHub release
+ uses: ncipollo/release-action@v1.14.0
+ with:
+ tag: ${{ steps.tag_version.outputs.new_tag }}
+ name: Flakkari ${{ steps.tag_version.outputs.new_tag }}
+ body: ${{ steps.tag_version.outputs.changelog }}
+ draft: false
+ prerelease: false
+ generateReleaseNotes: true
diff --git a/.github/workflows/create_patch.yml b/.github/workflows/create_patch.yml
index f1a40e4d..9a8b818a 100644
--- a/.github/workflows/create_patch.yml
+++ b/.github/workflows/create_patch.yml
@@ -11,7 +11,7 @@ permissions:
contents: write
jobs:
- create_release:
+ create_patch_release:
name: Bump version and create release
runs-on: ubuntu-latest
steps:
diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml
deleted file mode 100644
index ff4df94d..00000000
--- a/.github/workflows/create_release.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-name: Create Release on Tag
-
-on:
- push:
- tags:
- - 'v*.*.0'
-
-jobs:
- build:
- name: Create Release
- runs-on: ubuntu-latest
- steps:
- - name: Checkout code
- uses: actions/checkout@v4
- - name: Create Release
- id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- tag_name: ${{ github.ref }}
- release_name: Flakkari ${{ github.ref }}
- draft: false
- prerelease: false