- Server can handle multiple clients simultaneously. - Client can see other players in the game. - Server broadcasts the game state to all clients. - Client receives the game state and renders the other players. - Server assigns a unique ID to each player. - Client receives its player ID form the server. - Server handles client disconnections.. Kinda... Server is ignoring SIGPIPE signal. - Server and client signals are non-blocking. - Moved player objects off the stack and onto the heap.
18 lines
433 B
C++
18 lines
433 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include "bettola/network/socket.h"
|
|
#include "player.h"
|
|
|
|
class Game {
|
|
public:
|
|
Player* add_player(BettolaLib::Network::Socket* socket);
|
|
void remove_player(unsigned int player_id);
|
|
void update_player_pos(unsigned int player_id, float x, float y);
|
|
void broadcast_game_state(void);
|
|
Player* get_player_by_socket(BettolaLib::Network::Socket* socket);
|
|
|
|
private:
|
|
std::vector<Player*> _players;
|
|
};
|