summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/client.cpp8
-rw-r--r--server/client.h6
-rw-r--r--server/game.cpp27
3 files changed, 27 insertions, 14 deletions
diff --git a/server/client.cpp b/server/client.cpp
index 2155359..345e3a3 100644
--- a/server/client.cpp
+++ b/server/client.cpp
@@ -139,11 +139,7 @@ void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const
connection->send(make_shared<Message::RoundState>(pl_d, pl_r, pl_u, pl_l, g, a));
}
-void Client::round_end(boost::function<void ()> callback) {
- Message::RoundEnd::p msg = make_shared<Message::RoundEnd>();
-
- msg->game_end = false;
-
+void Client::round_end(Message::RoundEnd::p msg, boost::function<void ()> callback) {
connection->send(msg);
// Check if we're waiting for ready.
@@ -176,7 +172,7 @@ void ClientDumb::round_state(const PlayerState& pl_d, const PlayerState& pl_r, c
}
-void ClientDumb::round_end(boost::function<void ()> callback) {
+void ClientDumb::round_end(Message::RoundEnd::p msg, boost::function<void ()> callback) {
callback();
}
diff --git a/server/client.h b/server/client.h
index 82968b4..752a6a4 100644
--- a/server/client.h
+++ b/server/client.h
@@ -30,7 +30,7 @@ class ClientBase {
virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) = 0;
//! Send round end.
- virtual void round_end(boost::function<void ()> callback) = 0;
+ virtual void round_end(Message::RoundEnd::p msg, boost::function<void ()> callback) = 0;
//! 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;
@@ -95,7 +95,7 @@ class Client : public ClientBase, public boost::enable_shared_from_this<Client>
virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a);
//! Send round end.
- virtual void round_end(boost::function<void ()> callback);
+ virtual void round_end(Message::RoundEnd::p msg, boost::function<void ()> callback);
//! 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);
@@ -118,7 +118,7 @@ class ClientDumb : public ClientBase {
virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a);
- virtual void round_end(boost::function<void ()> callback);
+ virtual void round_end(Message::RoundEnd::p msg, boost::function<void ()> callback);
virtual void get_action(boost::function<void (Action)> callback, Actions expected_actions);
};
diff --git a/server/game.cpp b/server/game.cpp
index a41b90c..6b0b275 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -326,20 +326,37 @@ void Game::handle_action_discard(Action action, int player) {
}
void Game::round_end() {
- // Flere runder? round_start()
+ Message::RoundEnd::p msg = make_shared<Message::RoundEnd>();
+ // Did anybody win?
+ for(int i = 0; i < 4; i++) {
+ if(players[current_player + i].won) {
+ Player& player = players[current_player + i];
+
+ msg->hand = player.hand;
+
+ msg->yakus = player.won_han;
+
+ msg->total_han = player.won_value.han();
+ msg->total_fu = player.won_value.fu_rounded();
+ msg->won = player.won_value.ron_east();
+
+ break;
+ }
+ }
round_num++;
if(!round_num) {
round_wind++;
}
+ msg->game_end = false;
awaiting_players = 4;
- players[0].client->round_end(boost::bind(&Game::handle_ready, shared_from_this()));
- players[1].client->round_end(boost::bind(&Game::handle_ready, shared_from_this()));
- players[2].client->round_end(boost::bind(&Game::handle_ready, shared_from_this()));
- players[3].client->round_end(boost::bind(&Game::handle_ready, shared_from_this()));
+ players[0].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+ players[1].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+ players[2].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
+ players[3].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this()));
// Ferdig? game_end()