summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/client.cpp26
-rw-r--r--server/client.h8
2 files changed, 30 insertions, 4 deletions
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<void (Client::p)> f) {
connection->recv(boost::bind(&Client::handle_login, shared_from_this(), _1, f));
}
-void Client::handle_login(Message::p msg, boost::function<void (Client::p)> lobby_callback) {
+void Client::handle_login(Message::p msg, boost::function<void (Client::p)> login_callback) {
if(msg->type != Message::Types::Login) {
return;
}
@@ -30,7 +30,7 @@ void Client::handle_login(Message::p msg, boost::function<void (Client::p)> lobb
// Check if nick is invalid.
if(login_msg->nick.size() == 0) {
connection->send(make_shared<Message::LoginResponse>(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<void (Client::p)> lobb
nick_ = login_msg->nick;
- lobby_callback(shared_from_this());
+ login_callback(shared_from_this());
+}
+
+void Client::handle_lobby(Message::p msg, boost::function<void (int)> lobby_callback) {
+ if(msg->type != Message::Types::LobbyAction) {
+ return;
+ }
+
+ Message::LobbyAction::p lobby_msg = dynamic_pointer_cast<Message::LobbyAction>(msg);
+
+ lobby_callback(lobby_msg->index);
}
void Client::handle_ready(Message::p msg, boost::function<void ()> ready_callback) {
@@ -64,6 +74,16 @@ void Client::handle_action(Message::p msg, boost::function<void (Action)> action
}
}
+void Client::lobby_status(const std::vector<std::string>& game_modes, boost::function<void (int)> callback) {
+ Message::LobbyStatus::p msg = make_shared<Message::LobbyStatus>();
+
+ 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<Client> {
void start(boost::function<void (Client::p)> f);
//! Handle Login-message.
- void handle_login(Message::p msg, boost::function<void (Client::p)> lobby_callback);
+ void handle_login(Message::p msg, boost::function<void (Client::p)> login_callback);
+
+ //! Handle LobbyAction-message.
+ void handle_lobby(Message::p msg, boost::function<void (int)> lobby_callback);
//! Handle Ready-message.
void handle_ready(Message::p msg, boost::function<void ()> ready_callback);
@@ -37,6 +40,9 @@ class Client : public boost::enable_shared_from_this<Client> {
void handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions expected_actions);
public:
+ //! 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 nick.
std::string nick();