/
player.hpp
86 lines (63 loc) · 2.09 KB
/
player.hpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "simple_wml.hpp"
#include <ctime>
#include <set>
namespace wesnothd {
class game;
class player
{
public:
enum STATUS {
LOBBY,
PLAYING,
OBSERVING
};
player(const std::string& n, simple_wml::node& cfg, bool registered, const std::string& version,
const size_t max_messages=4, const size_t time_period=10,
const bool moderator=false);
void set_status(STATUS status);
// mark a player as member of the game 'game_id' or as located in the lobby
void mark_available(const int game_id=0, const std::string& location="");
//Mark a player as registered if he has authorized
void mark_registered(bool registered =true);
bool registered() const {return registered_;}
const std::string& name() const { return name_; }
const std::string& version() const { return version_; }
const simple_wml::node* config_address() const { return &cfg_; }
bool is_message_flooding();
/**
* @return true iff the player is in a game
*/
bool in_game() const { return get_game() != nullptr; }
/**
* @return a pointer to the game the player is in, or nullptr if he/she is not
* in a game at the moment
*/
const game* get_game() const;
void set_game(game* g);
void set_moderator(bool moderator) { moderator_ = moderator; }
bool is_moderator() const { return moderator_; }
private:
const std::string name_;
std::string version_;
simple_wml::node& cfg_;
bool registered_;
time_t flood_start_;
unsigned int messages_since_flood_start_;
const size_t MaxMessages;
const time_t TimePeriod;
STATUS status_;
bool moderator_;
};
} //namespace wesnothd