summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/client.cpp (renamed from server/player.cpp)40
-rw-r--r--server/client.h (renamed from server/player.h)24
-rw-r--r--server/connection.h2
-rw-r--r--server/game.cpp4
-rw-r--r--server/game.h8
-rw-r--r--server/lobby.cpp10
-rw-r--r--server/lobby.h6
-rw-r--r--server/standard.h1
8 files changed, 47 insertions, 48 deletions
diff --git a/server/player.cpp b/server/client.cpp
index d8baaf8..533f6ee 100644
--- a/server/player.cpp
+++ b/server/client.cpp
@@ -1,26 +1,26 @@
-#include "player.h"
+#include "client.h"
#include <boost/bind.hpp>
-Player::p Player::create(Connection::p c, boost::function<void (Player::p)> f) {
- Player::p p(new Player(c));
+Client::p Client::create(Connection::p c, boost::function<void (Client::p)> f) {
+ Client::p p(new Client(c));
p->start(f);
return p;
}
-Player::Player(Connection::p c) : connection(c), timer(c->socket.get_io_service()) {
+Client::Client(Connection::p c) : connection(c), timer(c->socket.get_io_service()) {
}
-void Player::start(boost::function<void (Player::p)> f) {
+void Client::start(boost::function<void (Client::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));
+ connection->recv(boost::bind(&Client::handle_login, shared_from_this(), _1, f));
}
-void Player::handle_login(Message::p msg, boost::function<void (Player::p)> lobby_callback) {
+void Client::handle_login(Message::p msg, boost::function<void (Client::p)> lobby_callback) {
if(msg->type != Message::Types::Login) {
return;
}
@@ -30,7 +30,7 @@ void Player::handle_login(Message::p msg, boost::function<void (Player::p)> lobb
// 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));
+ connection->recv(boost::bind(&Client::handle_login, shared_from_this(), _1, lobby_callback));
return;
}
@@ -41,7 +41,7 @@ void Player::handle_login(Message::p msg, boost::function<void (Player::p)> lobb
lobby_callback(shared_from_this());
}
-void Player::handle_ready(Message::p msg, boost::function<void ()> ready_callback) {
+void Client::handle_ready(Message::p msg, boost::function<void ()> ready_callback) {
if(msg->type != Message::Types::Ready) {
return;
}
@@ -49,7 +49,7 @@ 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, Actions possible_actions) {
+void Client::handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions possible_actions) {
if(msg->type != Message::Types::RoundAction) {
return;
}
@@ -64,39 +64,39 @@ void Player::handle_action(Message::p msg, boost::function<void (Action)> action
}
}
-std::string Player::nick() {
+std::string Client::nick() {
return nick_;
}
-void Player::game_start(boost::function<void ()> callback, std::vector<Player::p> players) {
+void Client::game_start(boost::function<void ()> callback, std::vector<Client::p> players) {
Message::GameStart::p msg = make_shared<Message::GameStart>();
- for(std::vector<Player::p>::iterator i = players.begin(); i != players.end(); i++) {
+ for(std::vector<Client::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));
+ connection->recv(boost::bind(&Client::handle_ready, shared_from_this(), _1, callback));
}
-void Player::round_start() {
+void Client::round_start() {
connection->send(make_shared<Message::RoundStart>());
}
-void Player::round_state(State state) {
+void Client::round_state(State state) {
connection->send(make_shared<Message::RoundState>(state));
}
-void Player::round_end() {
+void Client::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 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));
}
-void Player::kill_action() {
+void Client::kill_action() {
}
diff --git a/server/player.h b/server/client.h
index 25eddd3..ad5df64 100644
--- a/server/player.h
+++ b/server/client.h
@@ -1,5 +1,5 @@
-#ifndef PLAYER_H
-#define PLAYER_H
+#ifndef CLIENT_H
+#define CLIENT_H
#include <string>
#include <boost/shared_ptr.hpp>
@@ -9,11 +9,11 @@
#include "connection.h"
-class Player : public boost::enable_shared_from_this<Player> {
+class Client : public boost::enable_shared_from_this<Client> {
public:
- typedef boost::shared_ptr<Player> p;
+ typedef boost::shared_ptr<Client> p;
- static p create(Connection::p c, boost::function<void (Player::p)> f);
+ static p create(Connection::p c, boost::function<void (Client::p)> f);
private:
Connection::p connection;
@@ -22,13 +22,13 @@ class Player : public boost::enable_shared_from_this<Player> {
std::string nick_;
- Player(Connection::p c);
+ Client(Connection::p c);
//! Start communicating.
- void start(boost::function<void (Player::p)> f);
+ void start(boost::function<void (Client::p)> f);
//! Handle Login-message.
- void handle_login(Message::p msg, boost::function<void (Player::p)> lobby_callback);
+ void handle_login(Message::p msg, boost::function<void (Client::p)> lobby_callback);
//! Handle Ready-message.
void handle_ready(Message::p msg, boost::function<void ()> ready_callback);
@@ -37,14 +37,14 @@ class Player : public boost::enable_shared_from_this<Player> {
void handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions expected_actions);
public:
- //! The ID of the player
+ //! The ID of the client
int id;
- //! Return player's nick.
+ //! Return client's nick.
std::string nick();
//! Notify client of a game start.
- void game_start(boost::function<void ()> callback, std::vector<Player::p> players);
+ void game_start(boost::function<void ()> callback, std::vector<Client::p> players);
//! Notify client of a round start.
void round_start();
@@ -61,6 +61,6 @@ class Player : public boost::enable_shared_from_this<Player> {
void kill_action();
};
-typedef std::vector<Player> Players;
+typedef std::vector<Client> Clients;
#endif
diff --git a/server/connection.h b/server/connection.h
index 0f16022..248817b 100644
--- a/server/connection.h
+++ b/server/connection.h
@@ -10,7 +10,7 @@
class Connection : public ConnectionBase, public boost::enable_shared_from_this<Connection> {
private:
friend class TCPServer;
- friend class Player;
+ friend class Client;
boost::asio::ip::tcp::socket socket;
diff --git a/server/game.cpp b/server/game.cpp
index 4d102a7..07373ac 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -11,7 +11,7 @@
#include "../common/set.h"
-Game::p Game::create(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4) {
+Game::p Game::create(Client::p player_1, Client::p player_2, Client::p player_3, Client::p player_4) {
Game::p p(new Game(player_1, player_2, player_3, player_4));
p->start();
return p;
@@ -22,7 +22,7 @@ Game::~Game() {
delete ruleset;
}
-Game::Game(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4) {
+Game::Game(Client::p player_1, Client::p player_2, Client::p player_3, Client::p player_4) {
players.push_back(player_1);
players.push_back(player_2);
players.push_back(player_3);
diff --git a/server/game.h b/server/game.h
index f0f1564..2574dc3 100644
--- a/server/game.h
+++ b/server/game.h
@@ -7,7 +7,7 @@
#include <vector>
#include "wall.h"
-#include "player.h"
+#include "client.h"
#include "../common/action.h"
#include "gamevariant.h"
@@ -17,16 +17,16 @@ class Game : public boost::enable_shared_from_this<Game> {
public:
typedef boost::shared_ptr<Game> p;
- static p create(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4);
+ static p create(Client::p player_1, Client::p player_2, Client::p player_3, Client::p player_4);
~Game();
private:
- std::vector<Player::p> players;
+ std::vector<Client::p> players;
int waiting_players;
- Game(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4);
+ Game(Client::p player_1, Client::p player_2, Client::p player_3, Client::p player_4);
GameVariant *ruleset;
diff --git a/server/lobby.cpp b/server/lobby.cpp
index 748d70f..79c207b 100644
--- a/server/lobby.cpp
+++ b/server/lobby.cpp
@@ -8,20 +8,20 @@
void Lobby::handle_connect(Connection::p connection) {
// Create player.
- Player::create(connection, boost::bind(&Lobby::handle_action, this, _1));
+ Client::create(connection, boost::bind(&Lobby::handle_action, this, _1));
// Get another connection.
server.get_connection(boost::bind(&Lobby::handle_connect, this, _1));
}
-void Lobby::handle_action(Player::p player) {
- std::cout << "Player " << player->nick() << " entered the lobby." << std::endl;
+void Lobby::handle_action(Client::p client) {
+ std::cout << "Client " << client->nick() << " entered the lobby." << std::endl;
if(waiting.size() >= 3) {
- Game::create(waiting[0], waiting[1], waiting[2], player);
+ Game::create(waiting[0], waiting[1], waiting[2], client);
waiting.clear();
} else {
- waiting.push_back(player);
+ waiting.push_back(client);
}
}
diff --git a/server/lobby.h b/server/lobby.h
index 6f5572e..0e25975 100644
--- a/server/lobby.h
+++ b/server/lobby.h
@@ -6,20 +6,20 @@
#include <vector>
#include "tcpserver.h"
-#include "player.h"
+#include "client.h"
class Lobby {
private:
boost::asio::io_service io_service;
TCPServer server;
- std::vector<Player::p> waiting;
+ std::vector<Client::p> waiting;
//! Handle new connection.
void handle_connect(Connection::p connection);
//! Handle action.
- void handle_action(Player::p player);
+ void handle_action(Client::p client);
public:
Lobby();
diff --git a/server/standard.h b/server/standard.h
index 4e5e4fb..9ad73ec 100644
--- a/server/standard.h
+++ b/server/standard.h
@@ -2,7 +2,6 @@
#define STANDARD_H
#include "gamevariant.h"
-#include "player.h"
#include "wall.h"
#include "../common/set.h"