summaryrefslogtreecommitdiff
path: root/server/player.h
blob: af2772116c513d2a77fd53e4e47a4efb994defd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef PLAYER_H
#define PLAYER_H

#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/function.hpp>
#include <boost/asio.hpp>

#include "connection.h"

class Player : public boost::enable_shared_from_this<Player> {
	public:
		typedef boost::shared_ptr<Player> p;
		
		static p create(Connection::p c, boost::function<void (Player::p)> f);
	
	private:
		Connection::p connection;
		
		boost::asio::deadline_timer timer;
		
		boost::function<void (Player::p)> lobby_callback;
		boost::function<void ()> ready_callback;
		boost::function<void (Action)> action_callback;
		
		std::string nick_;
		
		Player(Connection::p c, boost::function<void (Player::p)> f);
		
		//! Start communicating.
		void start();
		
		//! Handle Login-message.
		void handle_login(Message::p msg);
		
		//! Handle Ready-message.
		void handle_ready(Message::p msg);
		
		//! Handle Action-message.
		void handle_action(Message::p msg);
		
	public:
		//! The ID of the player
		int id;
	
		//! Return player's nick.
		std::string nick();
		
		//! Notify client of a game start.
		void game_start(boost::function<void ()> callback, std::vector<Player::p> players);
		
		//! Notify client of a round start.
		void round_start();
		
		//! Send round state.
		void round_state(State state);
		
		//! Get action.
		void get_action(boost::function<void (Action)> callback);
};

#endif