bug enclosing

This commit is contained in:
Kai Philipp
2019-09-13 15:42:35 +02:00
parent 2b15e8536c
commit cab243d978
12 changed files with 40 additions and 38 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ ServerDBGeneric::SetGamePlayerPlace(unsigned /*requestId*/, DB_id /*playerId*/,
} }
void void
ServerDBGeneric::SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector<long> /*lastGames*/, std::string /*playerIp*/) ServerDBGeneric::SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector<long> /*last_games*/, std::string /*playerIp*/)
{ {
} }
+2 -2
View File
@@ -46,8 +46,8 @@ struct DBPlayerData {
std::string secret; std::string secret;
std::string country; std::string country;
std::string last_login; std::string last_login;
std::string lastGames; std::string last_games;
std::string lastIp; std::string last_ip;
}; };
#endif #endif
+1 -1
View File
@@ -57,7 +57,7 @@ public:
virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName); virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName);
virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place); virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place);
virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> lastGames, std::string playerIp); virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> last_games, std::string playerIp);
virtual void EndGame(unsigned requestId); virtual void EndGame(unsigned requestId);
virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId); virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId);
+1 -1
View File
@@ -58,7 +58,7 @@ public:
virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName) = 0; virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName) = 0;
virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place) = 0; virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place) = 0;
virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> lastGames, std::string playerIp) = 0; virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> last_games, std::string playerIp) = 0;
virtual void EndGame(unsigned requestId) = 0; virtual void EndGame(unsigned requestId) = 0;
virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId) = 0; virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId) = 0;
+1 -1
View File
@@ -55,7 +55,7 @@ public:
virtual void AsyncCreateGame(unsigned /*requestId*/, const std::string &/*gameName*/) {} virtual void AsyncCreateGame(unsigned /*requestId*/, const std::string &/*gameName*/) {}
virtual void SetGamePlayerPlace(unsigned /*requestId*/, DB_id /*playerId*/, unsigned /*place*/) {} virtual void SetGamePlayerPlace(unsigned /*requestId*/, DB_id /*playerId*/, unsigned /*place*/) {}
virtual void SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector<long> /*lastGames*/, std::string /*playerIp*/) {} virtual void SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector<long> /*last_games*/, std::string /*playerIp*/) {}
virtual void EndGame(unsigned /*requestId*/) {} virtual void EndGame(unsigned /*requestId*/) {}
virtual void AsyncReportAvatar(unsigned /*requestId*/, unsigned /*replyId*/, DB_id /*reportedPlayerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/, DB_id * /*byPlayerId*/) {} virtual void AsyncReportAvatar(unsigned /*requestId*/, unsigned /*replyId*/, DB_id /*reportedPlayerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/, DB_id * /*byPlayerId*/) {}
+8 -6
View File
@@ -52,23 +52,25 @@ AsyncDBAuth::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/,
service.post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &cb, GetId())); service.post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &cb, GetId()));
} else { } else {
int blocked = result[0][2]; int blocked = result[0][2];
int active = result[0][5]; //int active = result[0][5];
if ((active != 1) || (blocked != 0)) { if (/*(active != 1) ||*/ (blocked != 0)) {
service.post(boost::bind(&ServerDBCallback::PlayerLoginBlocked, &cb, GetId())); service.post(boost::bind(&ServerDBCallback::PlayerLoginBlocked, &cb, GetId()));
} else { } else {
mysqlpp::String secret(result[0][1]); mysqlpp::String secret(result[0][1]);
mysqlpp::String country(result[0][3]); mysqlpp::String country(result[0][3]);
mysqlpp::String last_login(result[0][4]); mysqlpp::String last_login(result[0][4]);
mysqlpp::String lastGames(result[0][5]); mysqlpp::String last_games(result[0][5]);
mysqlpp::String lastIp(result[0][6]); mysqlpp::String last_ip(result[0][6]);
boost::shared_ptr<DBPlayerData> tmpData(new DBPlayerData); boost::shared_ptr<DBPlayerData> tmpData(new DBPlayerData);
tmpData->id = result[0][0]; tmpData->id = result[0][0];
secret.to_string(tmpData->secret); secret.to_string(tmpData->secret);
if (!country.is_null()) if (!country.is_null())
country.to_string(tmpData->country); country.to_string(tmpData->country);
last_login.to_string(tmpData->last_login); last_login.to_string(tmpData->last_login);
lastGames.to_string(tmpData->lastGames); if (!last_games.is_null())
lastIp.to_string(tmpData->lastIp); last_games.to_string(tmpData->last_games);
if (!last_ip.is_null())
last_ip.to_string(tmpData->last_ip);
service.post(boost::bind(&ServerDBCallback::PlayerLoginSuccess, &cb, GetId(), tmpData)); service.post(boost::bind(&ServerDBCallback::PlayerLoginSuccess, &cb, GetId(), tmpData));
} }
+4 -4
View File
@@ -235,16 +235,16 @@ ServerDBThread::SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned
} }
void void
ServerDBThread::SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> lastGames, std::string playerIp) ServerDBThread::SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> last_games, std::string playerIp)
{ {
LOG_ERROR("ServerDBThread::SetPlayerLastGames() entered."); LOG_ERROR("ServerDBThread::SetPlayerLastGames() entered.");
std::ostringstream oss; std::ostringstream oss;
std::copy(lastGames.begin(), lastGames.end(), std::ostream_iterator<int>(oss, ",")); std::copy(last_games.begin(), last_games.end(), std::ostream_iterator<int>(oss, ","));
std::string lastGamesFieldValue( oss.str() ); std::string last_gamesFieldValue( oss.str() );
list<string> params; list<string> params;
ostringstream paramStream; ostringstream paramStream;
params.push_back(lastGamesFieldValue); params.push_back(last_gamesFieldValue);
params.push_back(playerIp); params.push_back(playerIp);
paramStream << playerId; paramStream << playerId;
params.push_back(paramStream.str()); params.push_back(paramStream.str());
+1 -1
View File
@@ -67,7 +67,7 @@ public:
virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName); virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName);
virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place); virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place);
virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> lastGames, std::string playerIp); virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector<long> last_games, std::string playerIp);
virtual void EndGame(unsigned requestId); virtual void EndGame(unsigned requestId);
virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId); virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId);
+4 -4
View File
@@ -349,7 +349,7 @@ ServerGame::InternalStartGame()
GetDatabase().AsyncCreateGame(GetId(), GetName()); GetDatabase().AsyncCreateGame(GetId(), GetName());
InitRankingMap(playerData); InitRankingMap(playerData);
// @TODO: here to save lastGames with mysql per player // @TODO: here to save last_games with mysql per player
//if (GetGameData().gameType == GAME_TYPE_RANKING) //if (GetGameData().gameType == GAME_TYPE_RANKING)
if(true) if(true)
@@ -462,10 +462,10 @@ ServerGame::StoreLastGames(const PlayerDataList &playerDataList)
// tmpPlayer->GetUniqueId() // tmpPlayer->GetUniqueId()
tmpPlayer->AddPlayerLastGame((long)time(NULL)); tmpPlayer->AddPlayerLastGame((long)time(NULL));
LOG_ERROR("TimeStamp stored: " << tmpPlayer->GetPlayerLastGames().back()); LOG_ERROR("TimeStamp stored: " << tmpPlayer->GetPlayerLastGames().back());
std::vector<long> lastGames = tmpPlayer->GetPlayerLastGames(); std::vector<long> last_games = tmpPlayer->GetPlayerLastGames();
LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetDBId() << " - lastGameTs " << lastGames.back()); LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetDBId() << " - lastGameTs " << last_games.back());
if(tmpPlayer->GetDBId() != DB_ID_INVALID){ if(tmpPlayer->GetDBId() != DB_ID_INVALID){
GetDatabase().SetPlayerLastGames(GetId(), tmpPlayer->GetDBId(), lastGames, GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->GetUniqueId())->GetClientAddr()); GetDatabase().SetPlayerLastGames(GetId(), tmpPlayer->GetDBId(), last_games, GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->GetUniqueId())->GetClientAddr());
} }
++i; ++i;
} }
+6 -6
View File
@@ -1811,16 +1811,16 @@ ServerLobbyThread::UserValid(unsigned playerId, const DBPlayerData &dbPlayerData
if (tmpSession && tmpSession->GetPlayerData()) { if (tmpSession && tmpSession->GetPlayerData()) {
tmpSession->GetPlayerData()->SetDBId(dbPlayerData.id); tmpSession->GetPlayerData()->SetDBId(dbPlayerData.id);
tmpSession->GetPlayerData()->SetCountry(dbPlayerData.country); tmpSession->GetPlayerData()->SetCountry(dbPlayerData.country);
LOG_ERROR("lastGames from db = " << dbPlayerData.lastGames); LOG_ERROR("last_games from db = " << dbPlayerData.last_games);
// std::vector<long> lastGames; // std::vector<long> last_games;
// std::stringstream ss(dbPlayerData.lastGames); // std::stringstream ss(dbPlayerData.last_games);
// for (int i; ss >> i;) { // for (int i; ss >> i;) {
// lastGames.push_back(i); // last_games.push_back(i);
// if (ss.peek() == ',') // if (ss.peek() == ',')
// ss.ignore(); // ss.ignore();
// } // }
// tmpSession->GetPlayerData()->SetPlayerLastGames(lastGames); // tmpSession->GetPlayerData()->SetPlayerLastGames(last_games);
// LOG_ERROR("lastGames first from vector after db = " << tmpSession->GetPlayerData()->GetPlayerLastGames().front()); // LOG_ERROR("last_games first from vector after db = " << tmpSession->GetPlayerData()->GetPlayerLastGames().front());
this->AuthChallenge(tmpSession, dbPlayerData.secret); this->AuthChallenge(tmpSession, dbPlayerData.secret);
} }
} }
+6 -6
View File
@@ -247,10 +247,10 @@ PlayerData::operator<(const PlayerData &other) const
} }
void void
PlayerData::SetPlayerLastGames(std::vector<long> lastGames) PlayerData::SetPlayerLastGames(std::vector<long> last_games)
{ {
boost::mutex::scoped_lock lock(m_dataMutex); boost::mutex::scoped_lock lock(m_dataMutex);
m_lastGames = lastGames; m_last_games = last_games;
} }
void void
@@ -258,14 +258,14 @@ PlayerData::AddPlayerLastGame(long lastGame)
{ {
boost::mutex::scoped_lock lock(m_dataMutex); boost::mutex::scoped_lock lock(m_dataMutex);
m_lastGames.push_back(lastGame); m_last_games.push_back(lastGame);
} }
std::vector<long> std::vector<long>
PlayerData::GetPlayerLastGames() PlayerData::GetPlayerLastGames()
{ {
boost::mutex::scoped_lock lock(m_dataMutex); boost::mutex::scoped_lock lock(m_dataMutex);
return m_lastGames; return m_last_games;
} }
bool bool
@@ -282,11 +282,11 @@ PlayerData::IsPlayerAllowedToJoinCreateLimitRank()
int count = 0; int count = 0;
for(std::vector<long>::iterator timeStamp = m_lastGames.begin(); timeStamp != m_lastGames.end(); ++timeStamp) { for(std::vector<long>::iterator timeStamp = m_last_games.begin(); timeStamp != m_last_games.end(); ++timeStamp) {
if(*timeStamp > then) if(*timeStamp > then)
count++; count++;
else else
m_lastGames.erase(timeStamp); // erase overdued entries m_last_games.erase(timeStamp); // erase overdued entries
} }
if(count < SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES) if(count < SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES)
+4 -4
View File
@@ -116,9 +116,9 @@ public:
int GetStartCash() const; int GetStartCash() const;
void SetStartCash(int cash); void SetStartCash(int cash);
// @TODO: lastGames here // @TODO: last_games here
void AddPlayerLastGame(long lastGames); void AddPlayerLastGame(long last_games);
void SetPlayerLastGames(std::vector<long> lastGames); void SetPlayerLastGames(std::vector<long> last_games);
std::vector<long> GetPlayerLastGames(); std::vector<long> GetPlayerLastGames();
bool IsPlayerAllowedToJoinCreateLimitRank(); bool IsPlayerAllowedToJoinCreateLimitRank();
@@ -141,7 +141,7 @@ private:
bool m_isGameAdmin; bool m_isGameAdmin;
boost::shared_ptr<AvatarFile> m_netAvatarFile; boost::shared_ptr<AvatarFile> m_netAvatarFile;
std::vector<long> m_lastGames; std::vector<long> m_last_games;
mutable boost::mutex m_dataMutex; mutable boost::mutex m_dataMutex;
}; };