summaryrefslogtreecommitdiff
path: root/server/client.h
blob: 4ba36d7a9c56d6334fbf5f245d1a9727c26c335a (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 CLIENT_H
#define CLIENT_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 Client : public boost::enable_shared_from_this<Client> {
	public:
		typedef boost::shared_ptr<Client> p;
		
		static p create(Connection::p c, boost::function<void (Client::p)> f);
	
	private:
		Connection::p connection;
		
		boost::asio::deadline_timer timer;
		
		std::string nick_;
		
		Client(Connection::p c);
		
		//! Start communicating.
		void start(boost::function<void (Client::p)> f);
		
		//! Handle Login-message.
		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);
		
		//! Handle Action-message.
		void handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions expected_actions);
		
	public:
		//! Return client's nick.
		std::string nick();
		
		//! Notify client of a game start.
		void game_start(boost::function<void ()> callback, std::vector<std::string> players);
		
		//! Notify client of a round start.
		void round_start();
		
		typedef Message::RoundState::Player PlayerState;
		
		//! Send round state.
		void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a);
		
		//! Send round end.
		void round_end(boost::function<void ()> callback);
		
		//! Get action. Upon connection error, last element of expected_actions will be provided.
		void get_action(boost::function<void (Action)> callback, Actions expected_actions);
};

typedef std::vector<Client> Clients;

#endif