Civilization
Server.hpp
1 // Generated by dia2code
2 #ifndef SERVER__SERVER__H
3 #define SERVER__SERVER__H
4 
5 #include <vector>
6 #include <memory>
7 #include <mutex>
8 #include <boost/asio.hpp>
9 #include <string>
10 
11 namespace shared {
12  class Binary;
13  class Player;
14 };
15 namespace server {
16  class GameEngine;
17 }
18 
19 #include "shared/Binary.hpp"
20 #include "shared/Player.hpp"
21 #include "GameEngine.hpp"
22 
23 namespace server {
24 
26  class Server {
27  // Attributes
28  public:
29  std::vector<std::shared_ptr<GameEngine>> games;
30  std::mutex gamesMutex;
31  std::atomic<bool> running = true;
32  private:
33  shared::Binary binary;
34  // Operations
35  public:
36  void start (unsigned short port = 8080);
37  void handleClient (boost::asio::ip::tcp::socket socket);
38  std::shared_ptr<GameEngine> createNewGame (std::shared_ptr<shared::Player> player);
39  std::shared_ptr<GameEngine> getGameById (std::string gameId);
40  bool connectPlayerToGame (std::shared_ptr<shared::Player> player, std::shared_ptr<GameEngine> game);
41  void registerClientAnswer (const std::string & response, std::shared_ptr<shared::Player> player);
42  void processMessage (boost::asio::streambuf& receiveBuffer, std::shared_ptr<shared::Player> player, std::shared_ptr<GameEngine> game);
43  private:
44  void handleAccept (boost::asio::ip::tcp::acceptor & acceptor, boost::asio::ip::tcp::socket & socket);
45  void sendGameInfo (std::shared_ptr<GameEngine> game, std::shared_ptr<shared::Player> player);
46  // Setters and Getters
47  };
48 
49 };
50 
51 #endif
class Server -
Definition: Server.hpp:26
class Binary -
Definition: Binary.hpp:18