diff options
-rw-r--r-- | server/client.cpp | 18 | ||||
-rw-r--r-- | server/client.h | 16 | ||||
-rw-r--r-- | server/lobby.cpp | 17 |
3 files changed, 45 insertions, 6 deletions
diff --git a/server/client.cpp b/server/client.cpp index 0d0b0ba..329da82 100644 --- a/server/client.cpp +++ b/server/client.cpp @@ -12,6 +12,16 @@ Client::Client(Connection::p c) : connection(c), timer(c->socket.get_io_service( } +void Client::disconnect() { + //delete connection; + //connection = NULL; + //We need to make this player dumb? +} + +void Client::reconnect(Connection::p c) { + connection = c; +} + void Client::start(boost::function<void (Client::p)> f) { // Send Hello. connection->send(make_shared<Message::Hello>("aotenjoud git")); @@ -84,6 +94,10 @@ void Client::lobby_status(const std::vector<std::string>& game_modes, boost::fun connection->recv(boost::bind(&Client::handle_lobby, shared_from_this(), _1, callback)); } +unsigned int Client::id() { + return id_; +} + std::string Client::nick() { return nick_; } @@ -121,6 +135,10 @@ void Client::get_action(boost::function<void (Action)> callback, Actions expecte connection->recv(boost::bind(&Client::handle_action, shared_from_this(), _1, callback, expected_actions)); } +unsigned int ClientDumb::id() { + return 0; +} + std::string ClientDumb::nick() { return "CPU"; } diff --git a/server/client.h b/server/client.h index 3455056..676264e 100644 --- a/server/client.h +++ b/server/client.h @@ -16,6 +16,9 @@ class ClientBase { virtual ~ClientBase() {} + //! Return client's id. + virtual unsigned int id() = 0; + //! Return client's nick. virtual std::string nick() = 0; @@ -48,6 +51,8 @@ class Client : public ClientBase, public boost::enable_shared_from_this<Client> boost::asio::deadline_timer timer; + unsigned int id_; + std::string nick_; Client(Connection::p c); @@ -71,6 +76,9 @@ class Client : public ClientBase, public boost::enable_shared_from_this<Client> //! Inform client of lobby status (available game modes). void lobby_status(const std::vector<std::string>& game_modes, boost::function<void (int)> callback); + //! Return client's id. + virtual unsigned int id(); + //! Return client's nick. virtual std::string nick(); @@ -88,12 +96,20 @@ class Client : public ClientBase, public boost::enable_shared_from_this<Client> //! Get action. Upon connection error, last element of expected_actions will be provided. virtual void get_action(boost::function<void (Action)> callback, Actions expected_actions); + + //! Dis-connect a player. + virtual void disconnect(); + + //! Re-connect a player. + virtual void reconnect(Connection::p c); }; typedef std::vector<Client> Clients; class ClientDumb : public ClientBase { public: + virtual unsigned int id(); + virtual std::string nick(); virtual void game_start(boost::function<void ()> callback, std::vector<std::string> players); diff --git a/server/lobby.cpp b/server/lobby.cpp index 620b2fd..7939977 100644 --- a/server/lobby.cpp +++ b/server/lobby.cpp @@ -17,12 +17,17 @@ void Lobby::handle_connect(Connection::p connection) { void Lobby::handle_login(Client::p client) { std::cout << "Client " << client->nick() << " entered the lobby." << std::endl; - std::vector<std::string> game_modes; - - game_modes.push_back("1p test mode"); - game_modes.push_back("4p test mode"); - - client->lobby_status(game_modes, boost::bind(&Lobby::handle_action, this, client, _1)); + if(0) {//client->id != 0 + //We check if player is in an ongoing game? + + } else { + std::vector<std::string> game_modes; + + game_modes.push_back("1p test mode"); + game_modes.push_back("4p test mode"); + + client->lobby_status(game_modes, boost::bind(&Lobby::handle_action, this, client, _1)); + } } void Lobby::handle_action(Client::p client, int game_mode) { |