summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/client.cpp58
1 files changed, 39 insertions, 19 deletions
diff --git a/server/client.cpp b/server/client.cpp
index 3573128..afec605 100644
--- a/server/client.cpp
+++ b/server/client.cpp
@@ -122,41 +122,61 @@ std::string Client::nick() {
}
void Client::game_start(boost::function<void ()> callback, std::vector<std::string> players) {
- Message::GameStart::p msg = make_shared<Message::GameStart>();
-
- msg->players = players;
-
- connection->send(msg);
-
- connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
+ if(connection) {
+ Message::GameStart::p msg = make_shared<Message::GameStart>();
+
+ msg->players = players;
+
+ connection->send(msg);
+
+ connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
+ } else {
+ callback();
+ }
}
void Client::round_start() {
- connection->send(make_shared<Message::RoundStart>());
+ if(connection) {
+ connection->send(make_shared<Message::RoundStart>());
+ }
}
void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) {
- connection->send(make_shared<Message::RoundState>(pl_d, pl_r, pl_u, pl_l, g, a));
+ if(connection) {
+ connection->send(make_shared<Message::RoundState>(pl_d, pl_r, pl_u, pl_l, g, a));
+ }
}
void Client::round_end(Message::RoundEnd::p msg, boost::function<void ()> callback) {
- connection->send(msg);
-
- // Check if we're waiting for ready.
- if(callback) {
- connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
+ if(connection) {
+ connection->send(msg);
+
+ // Check if we're waiting for ready.
+ if(callback) {
+ connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
+ }
+ } else {
+ if(callback){callback();}
}
}
void Client::get_action(boost::function<void (Action)> callback, Actions expected_actions) {
- connection->recv(boost::bind(&Client::handle_action, shared_from_this(), _1, callback, expected_actions));
+ if(connection) {
+ connection->recv(boost::bind(&Client::handle_action, shared_from_this(), _1, callback, expected_actions));
+ } else {
+ callback(expected_actions.back());
+ }
}
void Client::game_end(Message::GameEnd::p msg, boost::function<void ()> callback) {
- connection->send(msg);
-
- if(callback) {
- connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
+ if(connection) {
+ connection->send(msg);
+
+ if(callback) {
+ connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
+ }
+ } else {
+ callback();
}
}