diff options
Diffstat (limited to 'server/player.cpp')
-rw-r--r-- | server/player.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/server/player.cpp b/server/player.cpp index b1d8467..d8baaf8 100644 --- a/server/player.cpp +++ b/server/player.cpp @@ -49,16 +49,18 @@ void Player::handle_ready(Message::p msg, boost::function<void ()> ready_callbac ready_callback(); } -void Player::handle_action(Message::p msg, boost::function<void (Action)> action_callback) { +void Player::handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions possible_actions) { if(msg->type != Message::Types::RoundAction) { return; } Message::RoundAction::p action_msg = dynamic_pointer_cast<Message::RoundAction>(msg); - //action_msg->action.player = id; - if(action_callback != 0) { + // Check if the action is valid. + if(possible_actions.contains(action_msg->action)) { action_callback(action_msg->action); + } else { + action_callback(possible_actions[0]); } } @@ -91,8 +93,8 @@ void Player::round_end() { connection->send(make_shared<Message::RoundEnd>()); } -void Player::get_action(boost::function<void (Action)> callback) { - connection->recv(boost::bind(&Player::handle_action, shared_from_this(), _1, callback)); +void Player::get_action(boost::function<void (Action)> callback, Actions expected_actions) { + connection->recv(boost::bind(&Player::handle_action, shared_from_this(), _1, callback, expected_actions)); } void Player::kill_action() { |