summaryrefslogtreecommitdiff
path: root/server/player.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-11-25 03:01:43 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-11-25 03:01:43 +0100
commit4282a9d069b3bedc8888a4e6202f2b066233d4ec (patch)
tree8e0646804a7b33883be5867833e7b02004ddca1c /server/player.cpp
parentd5aae396856ee801eb2e2420b786fda2f13cf391 (diff)
Rename Player to Client, to better reflect what it represents.
A Player should be specific to a game, while a Client may participate in several.
Diffstat (limited to 'server/player.cpp')
-rw-r--r--server/player.cpp102
1 files changed, 0 insertions, 102 deletions
diff --git a/server/player.cpp b/server/player.cpp
deleted file mode 100644
index d8baaf8..0000000
--- a/server/player.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "player.h"
-
-#include <boost/bind.hpp>
-
-Player::p Player::create(Connection::p c, boost::function<void (Player::p)> f) {
- Player::p p(new Player(c));
- p->start(f);
- return p;
-}
-
-Player::Player(Connection::p c) : connection(c), timer(c->socket.get_io_service()) {
-
-}
-
-void Player::start(boost::function<void (Player::p)> f) {
- // Send Hello.
- connection->send(make_shared<Message::Hello>("aotenjoud git"));
-
- // Wait for Login.
- connection->recv(boost::bind(&Player::handle_login, shared_from_this(), _1, f));
-}
-
-void Player::handle_login(Message::p msg, boost::function<void (Player::p)> lobby_callback) {
- if(msg->type != Message::Types::Login) {
- return;
- }
-
- Message::Login::p login_msg = dynamic_pointer_cast<Message::Login>(msg);
-
- // Check if nick is invalid.
- if(login_msg->nick.size() == 0) {
- connection->send(make_shared<Message::LoginResponse>(false));
- connection->recv(boost::bind(&Player::handle_login, shared_from_this(), _1, lobby_callback));
- return;
- }
-
- connection->send(make_shared<Message::LoginResponse>(true));
-
- nick_ = login_msg->nick;
-
- lobby_callback(shared_from_this());
-}
-
-void Player::handle_ready(Message::p msg, boost::function<void ()> ready_callback) {
- if(msg->type != Message::Types::Ready) {
- return;
- }
-
- ready_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);
-
- // Check if the action is valid.
- if(possible_actions.contains(action_msg->action)) {
- action_callback(action_msg->action);
- } else {
- action_callback(possible_actions[0]);
- }
-}
-
-std::string Player::nick() {
- return nick_;
-}
-
-void Player::game_start(boost::function<void ()> callback, std::vector<Player::p> players) {
- Message::GameStart::p msg = make_shared<Message::GameStart>();
-
- for(std::vector<Player::p>::iterator i = players.begin(); i != players.end(); i++) {
- msg->players.push_back((*i)->nick());
- }
- msg->player_id = id;
-
- connection->send(msg);
-
- connection->recv(boost::bind(&Player::handle_ready, shared_from_this(), _1, callback));
-}
-
-void Player::round_start() {
- connection->send(make_shared<Message::RoundStart>());
-}
-
-void Player::round_state(State state) {
- connection->send(make_shared<Message::RoundState>(state));
-}
-
-void Player::round_end() {
- connection->send(make_shared<Message::RoundEnd>());
-}
-
-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() {
-
-}