00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "../global.hpp"
00016
00017 #include "player.hpp"
00018
00019 player::player(const std::string& n, simple_wml::node& cfg, const size_t max_messages, const size_t time_period)
00020 : name_(n), cfg_(cfg), flood_start_(0), messages_since_flood_start_(0),
00021 MaxMessages(max_messages), TimePeriod(time_period)
00022 {
00023 cfg_.set_attr_dup("name", n.c_str());
00024 mark_available();
00025 }
00026
00027
00028 void player::mark_available(const int game_id, const std::string location)
00029 {
00030 cfg_.set_attr("available", (game_id == 0) ? "yes" : "no");
00031 cfg_.set_attr_dup("game_id", lexical_cast<std::string>(game_id).c_str());
00032 cfg_.set_attr_dup("location", location.c_str());
00033 }
00034
00035 bool player::is_message_flooding() {
00036 const time_t now = time(NULL);
00037 if (flood_start_ == 0) {
00038 flood_start_ = now;
00039 return false;
00040 }
00041
00042 ++messages_since_flood_start_;
00043
00044 if (now - flood_start_ > TimePeriod) {
00045 messages_since_flood_start_ = 0;
00046 flood_start_ = now;
00047 } else if (messages_since_flood_start_ == MaxMessages) {
00048 return true;
00049 }
00050
00051 return false;
00052 }