summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorAtle Hellvik Havsø <atle@havso.net>2010-12-14 23:28:19 +0100
committerAtle Hellvik Havsø <atle@havso.net>2010-12-14 23:28:19 +0100
commitb28b3c5b8ddb6d73c1e7745d15ea328326a544f9 (patch)
tree4f6d2ffa1a0e41200f7606fbe233151226b2a01d /server
parentd4e406b161376f8f7d195fbc5851c5d6751a01af (diff)
Made server send GameEnd.
Diffstat (limited to 'server')
-rw-r--r--server/client.cpp14
-rw-r--r--server/client.h6
-rw-r--r--server/game.cpp44
-rw-r--r--server/game.h3
4 files changed, 55 insertions, 12 deletions
diff --git a/server/client.cpp b/server/client.cpp
index 345e3a3..3573128 100644
--- a/server/client.cpp
+++ b/server/client.cpp
@@ -152,6 +152,14 @@ void Client::get_action(boost::function<void (Action)> callback, Actions expecte
connection->recv(boost::bind(&Client::handle_action, shared_from_this(), _1, callback, expected_actions));
}
+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));
+ }
+}
+
unsigned int ClientDumb::id() {
return 0;
}
@@ -173,9 +181,13 @@ void ClientDumb::round_state(const PlayerState& pl_d, const PlayerState& pl_r, c
}
void ClientDumb::round_end(Message::RoundEnd::p msg, boost::function<void ()> callback) {
- callback();
+ if(callback) callback();
}
void ClientDumb::get_action(boost::function<void (Action)> callback, Actions expected_actions) {
callback(expected_actions.back());
}
+
+void ClientDumb::game_end(Message::GameEnd::p msg, boost::function<void ()> callback) {
+ callback();
+}
diff --git a/server/client.h b/server/client.h
index 752a6a4..e6cfcc7 100644
--- a/server/client.h
+++ b/server/client.h
@@ -35,6 +35,8 @@ class ClientBase {
//! Get action. Upon connection error, last element of expected_actions will be provided.
virtual void get_action(boost::function<void (Action)> callback, Actions expected_actions) = 0;
+ virtual void game_end(Message::GameEnd::p msg, boost::function<void ()> callback) = 0;
+
};
//! Class implementing ClientBase for real clients.
@@ -102,6 +104,8 @@ class Client : public ClientBase, public boost::enable_shared_from_this<Client>
//! Reconnect a player.
virtual void reconnect(Connection::p c);
+
+ virtual void game_end(Message::GameEnd::p msg, boost::function<void ()> callback);
};
typedef std::vector<Client> Clients;
@@ -121,6 +125,8 @@ class ClientDumb : public ClientBase {
virtual void round_end(Message::RoundEnd::p msg, boost::function<void ()> callback);
virtual void get_action(boost::function<void (Action)> callback, Actions expected_actions);
+
+ virtual void game_end(Message::GameEnd::p msg, boost::function<void ()> callback);
};
#endif
diff --git a/server/game.cpp b/server/game.cpp
index e9b1369..4816490 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -326,12 +326,6 @@ void Game::handle_action_discard(Action action, int player) {
}
void Game::round_end(Endcondition end) {
-
- round_num++;
-
- if(!round_num) {
- round_wind++;
- }
Message::RoundEnd::p msg[4] = make_shared<Message::RoundEnd>();
@@ -409,12 +403,40 @@ void Game::round_end(Endcondition end) {
msg[count_player]->game_end = false;
if(count_player == 3) break;
}
- awaiting_players = 4;
- players[0].client->round_end(msg[0], boost::bind(&Game::handle_ready, shared_from_this()));
- players[1].client->round_end(msg[1], boost::bind(&Game::handle_ready, shared_from_this()));
- players[2].client->round_end(msg[2], boost::bind(&Game::handle_ready, shared_from_this()));
- players[3].client->round_end(msg[3], boost::bind(&Game::handle_ready, shared_from_this()));
+ round_num++;
+
+ if(!round_num) {
+ round_wind++;
+ //Do a 4-round game for now
+ for(int i = 0; i < 4; ++i) {
+ msg[i]->game_end = true;
+ players[i].client->round_end(msg[i], 0);
+ }
+ game_end();
+ } else {
+ awaiting_players = 4;
+ players[0].client->round_end(msg[0], boost::bind(&Game::handle_ready, shared_from_this()));
+ players[1].client->round_end(msg[1], boost::bind(&Game::handle_ready, shared_from_this()));
+ players[2].client->round_end(msg[2], boost::bind(&Game::handle_ready, shared_from_this()));
+ players[3].client->round_end(msg[3], boost::bind(&Game::handle_ready, shared_from_this()));
+ }
// Ferdig? game_end()
}
+
+void Game::game_end() {
+ Message::GameEnd::p msg = make_shared<Message::GameEnd>();
+ for(int i = 0; i < 4; i++) {
+ msg->scores[i].score = players[i].score;
+ msg->scores[i].won = players[i].score - 25000;
+ }
+
+ awaiting_players = 4;
+ players[0].client->game_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+ players[1].client->game_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+ players[2].client->game_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+ players[3].client->game_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+
+
+}
diff --git a/server/game.h b/server/game.h
index 9d795a4..874a525 100644
--- a/server/game.h
+++ b/server/game.h
@@ -67,6 +67,9 @@ class Game : public boost::enable_shared_from_this<Game> {
//! End the round.
void round_end(Endcondition end);
+
+ //! End the game
+ void game_end();
};
#endif