From b140aca7ab3ce6d312bc147a82dcf016af72eafd Mon Sep 17 00:00:00 2001 From: Ole Daniel Evensen Date: Mon, 6 Dec 2010 19:30:28 +0100 Subject: some preliminary code and structure for dis-connection and re-connection. --- server/client.cpp | 18 ++++++++++++++++++ server/client.h | 16 ++++++++++++++++ server/lobby.cpp | 17 +++++++++++------ 3 files changed, 45 insertions(+), 6 deletions(-) (limited to 'server') 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 f) { // Send Hello. connection->send(make_shared("aotenjoud git")); @@ -84,6 +94,10 @@ void Client::lobby_status(const std::vector& 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 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 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 //! Inform client of lobby status (available game modes). void lobby_status(const std::vector& game_modes, boost::function 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 //! Get action. Upon connection error, last element of expected_actions will be provided. virtual void get_action(boost::function callback, Actions expected_actions); + + //! Dis-connect a player. + virtual void disconnect(); + + //! Re-connect a player. + virtual void reconnect(Connection::p c); }; typedef std::vector Clients; class ClientDumb : public ClientBase { public: + virtual unsigned int id(); + virtual std::string nick(); virtual void game_start(boost::function callback, std::vector 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 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 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) { -- cgit v1.2.3