limit rank games per time unit implemented
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
* as that of the covered work. *
|
||||
*****************************************************************************/
|
||||
#include <playerdata.h>
|
||||
#include <ctime>
|
||||
#include <core/loghelper.h> // @TODO: remove in productive
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -242,3 +244,59 @@ PlayerData::operator<(const PlayerData &other) const
|
||||
return m_number < other.GetNumber();
|
||||
}
|
||||
|
||||
void
|
||||
PlayerData::SetPlayerLastGames(std::vector<long> last_games)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
m_last_games.clear();
|
||||
m_last_games = last_games;
|
||||
}
|
||||
|
||||
void
|
||||
PlayerData::AddPlayerLastGame(long lastGame)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
|
||||
m_last_games.push_back(lastGame);
|
||||
}
|
||||
|
||||
std::vector<long>
|
||||
PlayerData::GetPlayerLastGames()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
return m_last_games;
|
||||
}
|
||||
|
||||
bool
|
||||
PlayerData::IsPlayerAllowedToJoinCreateLimitRank(std::string num, std::string period)
|
||||
{
|
||||
bool retVal = false;
|
||||
LOG_ERROR("checking IsPlayerAllowedToJoinCreateLimitRank() ");
|
||||
LOG_ERROR("num = " << num << " period " << period);
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
|
||||
long then = (long)time(NULL) - (long)(stoi(period) * 60);
|
||||
|
||||
int count = 0;
|
||||
int i=0;
|
||||
for(std::vector<long>::iterator timeStamp = m_last_games.begin(); timeStamp != m_last_games.end(); ++timeStamp) {
|
||||
LOG_ERROR("timeStamp " << *timeStamp);
|
||||
time_t ts = (time_t)*timeStamp;
|
||||
LOG_ERROR("comparing ts " << (long)ts << " with " << then);
|
||||
if((long)ts > then){
|
||||
LOG_ERROR("counting timeStamp in time " << ctime(&ts));
|
||||
count++;
|
||||
}else{
|
||||
LOG_ERROR("erasing overdued timestamp " << ctime(&ts));
|
||||
timeStamp = m_last_games.erase(timeStamp); // erase overdued entries
|
||||
if( timeStamp == m_last_games.end())
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(count < stoi(num))
|
||||
retVal = true;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user