19 bool registered,
const std::string& version,
const std::string& source,
unsigned long long login_id,
const std::size_t max_messages,
20 const std::chrono::seconds& time_period,
26 , registered_(registered)
28 , messages_since_flood_start_(0)
29 , MaxMessages(max_messages)
30 , TimePeriod(time_period)
32 , moderator_(moderator)
48 cfg_.set_attr(
"status",
"lobby");
51 cfg_.set_attr(
"status",
"playing");
54 cfg_.set_attr(
"status",
"observing");
57 cfg_.set_attr(
"status",
"unknown");
63 const std::string& location)
66 cfg_.set_attr(
"available",
"yes");
69 cfg_.set_attr(
"available",
"no");
71 cfg_.set_attr_dup(
"game_id", std::to_string(game_id).c_str());
72 cfg_.set_attr_dup(
"location", location.c_str());
77 cfg_.set_attr(
"registered", registered ?
"yes" :
"no");
78 registered_ = registered;
83 const auto now = std::chrono::steady_clock::now();
84 if (flood_start_ == std::chrono::steady_clock::time_point{}) {
89 ++messages_since_flood_start_;
91 if (now - flood_start_ > TimePeriod) {
92 messages_since_flood_start_ = 0;
94 }
else if (messages_since_flood_start_ >= MaxMessages) {
node & set_attr_int(const char *key, int value)
node & set_attr(const char *key, const char *value)
node & set_attr_dup(const char *key, const char *value)
void mark_available(const int game_id=0, const std::string &location="")
void set_status(STATUS status)
void mark_registered(bool registered=true)
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)
bool is_message_flooding()
static map_location::direction n