R-Type  2
Doom but in better
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <thread>
4#include <chrono>
5#include <memory>
6#include <array>
7#include <asio.hpp>
8
9#include "game_manager.hpp"
10#include "client_manager.hpp"
11#include "message.hpp"
12#include "message_codec.hpp"
13
18class Server : public std::enable_shared_from_this<Server> {
19 public:
25 Server(asio::io_context &io, unsigned short port);
26
31 GameManager &getGameManager() { return gameManager_; }
32
38 void sendToClient(uint32_t clientId, const Message &msg);
39
40 private:
44 void doReceive();
45
50 void handleMessage(std::size_t bytesReceived);
51
52 asio::ip::udp::socket socket_;
53 asio::ip::udp::endpoint remoteEndpoint_;
54
55 std::array<char, 2048> recvBuffer_;
56
57 ClientManager clientManager_;
58 GameManager gameManager_;
59};
Tracks (ip::udp::endpoint)->clientId and allows lookup in reverse.
Manages multiple Game instances and routes messages/events.
The main UDP server that accepts client messages and updates the game logic.
Definition server.hpp:18
GameManager & getGameManager()
Accessor for the GameManager that manages multiple games.
Definition server.hpp:31
Server(asio::io_context &io, unsigned short port)
Constructs the Server, binding a UDP socket to the specified port.
Definition server.cpp:4
void sendToClient(uint32_t clientId, const Message &msg)
Sends a Message to a specific client by ID (uses clientManager to find endpoint).
Definition server.cpp:80
Minimal network message with a 4-byte header (type + length) and a payload.
Definition message.hpp:9