17 _onPromoted(onPromoted)
28 if (line ==
"GRAPHIC") {
67 if (egg.parentPlayerId < 0)
76 std::uniform_int_distribution<int> dori(1, 4);
77 static std::mt19937 rng{std::random_device{}()};
78 auto orientation =
static_cast<Orientation>(dori(rng));
88 int playerId =
_world.
addPlayer(connectionId, teamName, egg->x, egg->y, orientation);
93 _clients.
send(connectionId, std::to_string(slotsLeft) +
"\n");
std::function< void(int connectionId, int playerId)> PromotedCallback
Owns every client socket and runs the poll() loop.
void send(int connectionId, const std::string &msg)
Queue msg to be sent to a client (flushed during poll()).
Connection & getConnection(int connectionId)
Access the underlying Connection (e.g. to set its type/playerId).
void disconnect(int connectionId)
Close a client and drop its connection.
void setType(ClientType type)
Single owner of game frequency and elapsed game time.
void addGui(int connectionId)
void send(int connectionId, const std::string &msg)
void onNewConnection(int connectionId)
New socket: send the "WELCOME" greeting.
const ServerConfig & _config
void onLine(int connectionId, const std::string &line)
The client's reply (its team name).
void _promoteToGui(int connectionId)
void _reject(int connectionId)
PromotedCallback _onPromoted
void _promoteToAi(int connectionId, const std::string &teamName)
HandshakeHandler(ClientManager &clients, World &world, GuiNotifier ¬ifier, const ServerConfig &config, const GameClock &clock, PromotedCallback onPromoted)
Pure game state - no networking, no scheduling.
const std::unordered_map< int, Player > & getPlayers() const
std::optional< Egg > popEggForTeam(const std::string &teamName)
Tile & at(int x, int y)
Access a tile by position. Map is toroidal, coordinates wrap.
int addPlayer(int connectionId, const std::string &teamName, int x, int y, Orientation orientation)
bool isGameEnded() const
True once a team has won. Game logic stops reacting to AI commands.
const std::unordered_map< int, Egg > & getEggs() const
int teamEggCount(const std::string &team) const
std::string msz(int x, int y)
Map size. Wire: msz X Y\n
std::string tna(const std::string &teamName)
Team name (one per team). Wire: tna NAME\n
std::string sgt(int freq)
Reply to "sgt": current time unit frequency. Wire: sgt F\n
std::string bct(int x, int y, const Resources &r)
Tile content (resources on it). Wire: bct X Y q q q q q q q\n
std::string sse(int eggId, const std::string &teamName, int x, int y)
std::string pnw(int id, int x, int y, Orientation o, int level, const std::string &team)
New player connected. Wire: pnw #N X Y O L NAME\n (L = level)
std::string enw(int eggId, int playerId, int x, int y)
Egg laid by a player. Wire: enw #E #N X Y\n (E = egg, N = parent)
Represents the configuration for the server application, described by:
std::vector< std::string > teamNames