player.cpp

Go to the documentation of this file.
00001 /* $Id: player.cpp 24730 2008-03-17 05:11:14Z dave $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
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 // keep 'available' and game name ('location') for backward compatibility
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 }

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs