2011-07-02 14:45:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 14:45:12 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-02 14:45:12 +00:00
|
|
|
*****************************************************************************/
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <playerdata.h>
|
2019-09-10 20:47:10 +02:00
|
|
|
#include <ctime>
|
2019-09-14 17:37:02 +02:00
|
|
|
#include <core/loghelper.h> // @TODO: remove in productive
|
2019-09-10 20:47:10 +02:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2010-03-26 21:41:35 +00:00
|
|
|
PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin)
|
2011-12-27 09:05:50 +00:00
|
|
|
: m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_startCash(-1), m_type(type), m_rights(rights), m_isGameAdmin(isGameAdmin)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerData::PlayerData(const PlayerData &other)
|
2011-09-28 20:20:08 +00:00
|
|
|
: m_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_startCash(other.GetStartCash()),
|
|
|
|
|
m_guid(other.GetGuid()), m_oldGuid(other.GetOldGuid()), m_name(other.GetName()), m_password(), m_country(other.GetCountry()),
|
|
|
|
|
m_avatarFile(other.GetAvatarFile()), m_avatarMD5(other.GetAvatarMD5()), m_type(other.GetType()), m_rights(other.GetRights()),
|
|
|
|
|
m_isGameAdmin(other.IsGameAdmin()), m_netAvatarFile(), m_dataMutex()
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerData::~PlayerData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string
|
|
|
|
|
PlayerData::GetName() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-11 09:20:17 +00:00
|
|
|
PlayerData::SetName(const string &name)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-01 16:20:57 +00:00
|
|
|
std::string
|
|
|
|
|
PlayerData::GetCountry() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_country;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetCountry(const std::string &country)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_country = country;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
string
|
|
|
|
|
PlayerData::GetAvatarFile() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_avatarFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetAvatarFile(const std::string &avatarFile)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_avatarFile = avatarFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MD5Buf
|
|
|
|
|
PlayerData::GetAvatarMD5() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_avatarMD5;
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetAvatarMD5(const MD5Buf &avatarMD5)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_avatarMD5 = avatarMD5;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
boost::shared_ptr<AvatarFile>
|
|
|
|
|
PlayerData::GetNetAvatarFile() const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
return m_netAvatarFile;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-08-02 15:11:40 +00:00
|
|
|
PlayerData::SetNetAvatarFile(boost::shared_ptr<AvatarFile> AvatarFile)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2009-08-02 15:11:40 +00:00
|
|
|
m_netAvatarFile = AvatarFile;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerType
|
|
|
|
|
PlayerData::GetType() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetType(PlayerType type)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_type = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerRights
|
|
|
|
|
PlayerData::GetRights() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_rights;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 16:22:51 +01:00
|
|
|
void
|
|
|
|
|
PlayerData::SetRights(PlayerRights rights)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_rights = rights;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 21:41:35 +00:00
|
|
|
bool
|
|
|
|
|
PlayerData::IsGameAdmin() const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
2010-03-26 21:41:35 +00:00
|
|
|
return m_isGameAdmin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetGameAdmin(bool isAdmin)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_isGameAdmin = isAdmin;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
PlayerData::GetUniqueId() const
|
|
|
|
|
{
|
|
|
|
|
// const value - no mutex needed.
|
|
|
|
|
return m_uniqueId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
PlayerData::GetNumber() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetNumber(int number)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_number = number;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-28 17:14:03 +00:00
|
|
|
std::string
|
|
|
|
|
PlayerData::GetGuid() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_guid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetGuid(const std::string &guid)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_guid = guid;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:41:56 +00:00
|
|
|
std::string
|
|
|
|
|
PlayerData::GetOldGuid() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_oldGuid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetOldGuid(const std::string &guid)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_oldGuid = guid;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-24 21:49:11 +00:00
|
|
|
DB_id
|
|
|
|
|
PlayerData::GetDBId() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_dbId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetDBId(DB_id id)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_dbId = id;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 20:20:08 +00:00
|
|
|
int
|
|
|
|
|
PlayerData::GetStartCash() const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_startCash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::SetStartCash(int cash)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
m_startCash = cash;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
bool
|
|
|
|
|
PlayerData::operator<(const PlayerData &other) const
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
return m_number < other.GetNumber();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 20:47:10 +02:00
|
|
|
void
|
2019-09-13 15:42:35 +02:00
|
|
|
PlayerData::SetPlayerLastGames(std::vector<long> last_games)
|
2019-09-10 20:47:10 +02:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
2019-09-13 18:38:02 +02:00
|
|
|
m_last_games.clear();
|
2019-09-15 17:41:25 +02:00
|
|
|
m_last_games = last_games;
|
2019-09-10 20:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlayerData::AddPlayerLastGame(long lastGame)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
|
2019-09-13 15:42:35 +02:00
|
|
|
m_last_games.push_back(lastGame);
|
2019-09-10 20:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<long>
|
|
|
|
|
PlayerData::GetPlayerLastGames()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
2019-09-13 15:42:35 +02:00
|
|
|
return m_last_games;
|
2019-09-10 20:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2019-09-15 19:47:17 +02:00
|
|
|
PlayerData::IsPlayerAllowedToJoinCreateLimitRank(std::string num, std::string period)
|
2019-09-10 20:47:10 +02:00
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
2019-09-14 17:35:33 +02:00
|
|
|
LOG_ERROR("checking IsPlayerAllowedToJoinCreateLimitRank() ");
|
2019-09-15 19:47:17 +02:00
|
|
|
LOG_ERROR("num = " << num << " period " << period);
|
2019-09-10 20:47:10 +02:00
|
|
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
|
|
|
|
2019-09-15 17:36:03 +02:00
|
|
|
long then = (long)time(NULL) - (long)(stoi(period) * 10);
|
2019-09-10 20:47:10 +02:00
|
|
|
|
|
|
|
|
int count = 0;
|
2019-09-14 17:43:32 +02:00
|
|
|
int i=0;
|
2019-09-13 15:42:35 +02:00
|
|
|
for(std::vector<long>::iterator timeStamp = m_last_games.begin(); timeStamp != m_last_games.end(); ++timeStamp) {
|
2019-09-14 17:50:48 +02:00
|
|
|
LOG_ERROR("timeStamp " << *timeStamp);
|
2019-09-15 19:38:04 +02:00
|
|
|
time_t ts = (time_t)*timeStamp;
|
2019-09-15 19:44:57 +02:00
|
|
|
LOG_ERROR("comparing ts " << (long)ts << " with " << then);
|
|
|
|
|
if((long)ts > then){
|
2019-09-15 19:38:51 +02:00
|
|
|
LOG_ERROR("counting timeStamp in time " << ctime(&ts));
|
2019-09-10 20:47:10 +02:00
|
|
|
count++;
|
2019-09-14 17:48:08 +02:00
|
|
|
}else{
|
2019-09-15 19:38:51 +02:00
|
|
|
LOG_ERROR("erasing overdued timestamp " << ctime(&ts));
|
2019-09-14 21:51:38 +02:00
|
|
|
timeStamp = m_last_games.erase(timeStamp); // erase overdued entries
|
2019-09-14 21:54:47 +02:00
|
|
|
if( timeStamp == m_last_games.end())
|
|
|
|
|
break;
|
2019-09-14 17:48:08 +02:00
|
|
|
}
|
2019-09-14 17:43:32 +02:00
|
|
|
i++;
|
2019-09-10 20:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-15 17:36:03 +02:00
|
|
|
if(count < stoi(num))
|
2019-09-10 20:47:10 +02:00
|
|
|
retVal = true;
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|