summaryrefslogtreecommitdiff
path: root/server/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/client.cpp')
-rw-r--r--server/client.cpp26
1 files changed, 23 insertions, 3 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_;
}