The Battle for Wesnoth  1.15.1+dev
player.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "server/simple_wml.hpp"
18 
19 #include <ctime>
20 #include <set>
21 
22 namespace wesnothd {
23 
24 class game;
25 
26 class player
27 {
28 public:
29  enum STATUS {
33  };
34 
35  player(const std::string& n, simple_wml::node& cfg, bool registered, const std::string& version,
36  const std::size_t max_messages=4, const std::size_t time_period=10,
37  const bool moderator=false);
38 
39  void set_status(STATUS status);
40 
41  // mark a player as member of the game 'game_id' or as located in the lobby
42  void mark_available(const int game_id=0, const std::string& location="");
43 
44  //Mark a player as registered if he has authorized
45  void mark_registered(bool registered =true);
46  bool registered() const {return registered_;}
47 
48 
49  const std::string& name() const { return name_; }
50  const std::string& version() const { return version_; }
51  const simple_wml::node* config_address() const { return &cfg_; }
52 
53  bool is_message_flooding();
54 
55  /**
56  * @return true iff the player is in a game
57  */
58  bool in_game() const { return get_game() != nullptr; }
59 
60  /**
61  * @return a pointer to the game the player is in, or nullptr if he/she is not
62  * in a game at the moment
63  */
64  const game* get_game() const;
65 
66  void set_game(game* g);
67 
68  void set_moderator(bool moderator) { moderator_ = moderator; }
69  bool is_moderator() const { return moderator_; }
70 
71 private:
72  const std::string name_;
73  std::string version_;
75 
77 
78  std::time_t flood_start_;
80  const std::size_t MaxMessages;
81  const std::time_t TimePeriod;
83  bool moderator_;
84 };
85 
86 } //namespace wesnothd
const simple_wml::node * config_address() const
Definition: player.hpp:51
void set_game(game *g)
const std::string & version() const
Definition: player.hpp:50
const std::string & name() const
Definition: player.hpp:49
player(const std::string &n, simple_wml::node &cfg, bool registered, const std::string &version, const std::size_t max_messages=4, const std::size_t time_period=10, const bool moderator=false)
Definition: player.cpp:18
const std::time_t TimePeriod
Definition: player.hpp:81
std::time_t flood_start_
Definition: player.hpp:78
bool is_moderator() const
Definition: player.hpp:69
void mark_available(const int game_id=0, const std::string &location="")
Definition: player.cpp:59
std::string version_
Definition: player.hpp:73
const game * get_game() const
simple_wml::node & cfg_
Definition: player.hpp:74
bool registered_
Definition: player.hpp:76
bool in_game() const
Definition: player.hpp:58
bool registered() const
Definition: player.hpp:46
void mark_registered(bool registered=true)
Definition: player.cpp:72
void set_moderator(bool moderator)
Definition: player.hpp:68
double g
Definition: astarsearch.cpp:64
STATUS status_
Definition: player.hpp:82
unsigned int messages_since_flood_start_
Definition: player.hpp:79
bool is_message_flooding()
Definition: player.cpp:78
void set_status(STATUS status)
Definition: player.cpp:39
Definition: ban.cpp:28
static map_location::DIRECTION n
const std::string name_
Definition: player.hpp:72
const std::size_t MaxMessages
Definition: player.hpp:80