summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOle Daniel Evensen <ole_daniel_evensen@hotmail.com>2010-12-15 20:29:08 +0100
committerOle Daniel Evensen <ole_daniel_evensen@hotmail.com>2010-12-15 20:29:08 +0100
commit1c4c2c7abd9bd8ed7a32455749082056079ae85c (patch)
treeaae5ce349328fde4c913709581e5f4225e02c35d
parent5dd443319b5ab67feba2a213186091b587456743 (diff)
Some tests in client to fall back to dumb behaviour if connection is gone.
-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();
}
}