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