From 99960dd1580e32423bda5b53ad9c39ebb6b1dbd9 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 1 Dec 2010 14:03:29 +0100 Subject: Added lobby support to Client. --- server/client.cpp | 26 +++++++++++++++++++++++--- server/client.h | 8 +++++++- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/client.cpp b/server/client.cpp index af2c55d..0d2fe24 100644 --- a/server/client.cpp +++ b/server/client.cpp @@ -20,7 +20,7 @@ void Client::start(boost::function f) { connection->recv(boost::bind(&Client::handle_login, shared_from_this(), _1, f)); } -void Client::handle_login(Message::p msg, boost::function lobby_callback) { +void Client::handle_login(Message::p msg, boost::function login_callback) { if(msg->type != Message::Types::Login) { return; } @@ -30,7 +30,7 @@ void Client::handle_login(Message::p msg, boost::function lobb // Check if nick is invalid. if(login_msg->nick.size() == 0) { connection->send(make_shared(false)); - connection->recv(boost::bind(&Client::handle_login, shared_from_this(), _1, lobby_callback)); + connection->recv(boost::bind(&Client::handle_login, shared_from_this(), _1, login_callback)); return; } @@ -38,7 +38,17 @@ void Client::handle_login(Message::p msg, boost::function lobb nick_ = login_msg->nick; - lobby_callback(shared_from_this()); + login_callback(shared_from_this()); +} + +void Client::handle_lobby(Message::p msg, boost::function lobby_callback) { + if(msg->type != Message::Types::LobbyAction) { + return; + } + + Message::LobbyAction::p lobby_msg = dynamic_pointer_cast(msg); + + lobby_callback(lobby_msg->index); } void Client::handle_ready(Message::p msg, boost::function ready_callback) { @@ -64,6 +74,16 @@ void Client::handle_action(Message::p msg, boost::function action } } +void Client::lobby_status(const std::vector& game_modes, boost::function callback) { + Message::LobbyStatus::p msg = make_shared(); + + msg->game_modes = game_modes; + + connection->send(msg); + + connection->recv(boost::bind(&Client::handle_lobby, shared_from_this(), _1, callback)); +} + std::string Client::nick() { return nick_; } diff --git a/server/client.h b/server/client.h index 4ba36d7..cbb588f 100644 --- a/server/client.h +++ b/server/client.h @@ -28,7 +28,10 @@ class Client : public boost::enable_shared_from_this { void start(boost::function f); //! Handle Login-message. - void handle_login(Message::p msg, boost::function lobby_callback); + void handle_login(Message::p msg, boost::function login_callback); + + //! Handle LobbyAction-message. + void handle_lobby(Message::p msg, boost::function lobby_callback); //! Handle Ready-message. void handle_ready(Message::p msg, boost::function ready_callback); @@ -37,6 +40,9 @@ class Client : public boost::enable_shared_from_this { void handle_action(Message::p msg, boost::function action_callback, Actions expected_actions); public: + //! Inform client of lobby status (available game modes). + void lobby_status(const std::vector& game_modes, boost::function callback); + //! Return client's nick. std::string nick(); -- cgit v1.2.3