From cab243d9784c6136529a013b666c687f177439e1 Mon Sep 17 00:00:00 2001 From: Kai Philipp Date: Fri, 13 Sep 2019 15:42:35 +0200 Subject: [PATCH] bug enclosing --- src/db/common/serverdbgeneric.cpp | 2 +- src/db/dbdefs.h | 4 ++-- src/db/serverdbgeneric.h | 2 +- src/db/serverdbinterface.h | 2 +- src/db/serverdbnoaction.h | 2 +- src/dbofficial/asyncdbauth.cpp | 14 ++++++++------ src/dbofficial/serverdbthread.cpp | 10 +++++----- src/dbofficial/serverdbthread.h | 2 +- src/net/common/servergame.cpp | 8 ++++---- src/net/common/serverlobbythread.cpp | 12 ++++++------ src/playerdata.cpp | 12 ++++++------ src/playerdata.h | 8 ++++---- 12 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/db/common/serverdbgeneric.cpp b/src/db/common/serverdbgeneric.cpp index 5eab83a7..4872cc5b 100644 --- a/src/db/common/serverdbgeneric.cpp +++ b/src/db/common/serverdbgeneric.cpp @@ -94,7 +94,7 @@ ServerDBGeneric::SetGamePlayerPlace(unsigned /*requestId*/, DB_id /*playerId*/, } void -ServerDBGeneric::SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector /*lastGames*/, std::string /*playerIp*/) +ServerDBGeneric::SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector /*last_games*/, std::string /*playerIp*/) { } diff --git a/src/db/dbdefs.h b/src/db/dbdefs.h index c664ce7b..5847d6d3 100644 --- a/src/db/dbdefs.h +++ b/src/db/dbdefs.h @@ -46,8 +46,8 @@ struct DBPlayerData { std::string secret; std::string country; std::string last_login; - std::string lastGames; - std::string lastIp; + std::string last_games; + std::string last_ip; }; #endif diff --git a/src/db/serverdbgeneric.h b/src/db/serverdbgeneric.h index c79a0290..b24bfd00 100644 --- a/src/db/serverdbgeneric.h +++ b/src/db/serverdbgeneric.h @@ -57,7 +57,7 @@ public: virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName); virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place); - virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector lastGames, std::string playerIp); + virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector last_games, std::string playerIp); 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); diff --git a/src/db/serverdbinterface.h b/src/db/serverdbinterface.h index 3d5d5288..00e20379 100644 --- a/src/db/serverdbinterface.h +++ b/src/db/serverdbinterface.h @@ -58,7 +58,7 @@ public: virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName) = 0; virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place) = 0; - virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector lastGames, std::string playerIp) = 0; + virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector last_games, std::string playerIp) = 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; diff --git a/src/db/serverdbnoaction.h b/src/db/serverdbnoaction.h index 7bcf0366..28b62733 100644 --- a/src/db/serverdbnoaction.h +++ b/src/db/serverdbnoaction.h @@ -55,7 +55,7 @@ public: virtual void AsyncCreateGame(unsigned /*requestId*/, const std::string &/*gameName*/) {} virtual void SetGamePlayerPlace(unsigned /*requestId*/, DB_id /*playerId*/, unsigned /*place*/) {} - virtual void SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector /*lastGames*/, std::string /*playerIp*/) {} + virtual void SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector /*last_games*/, std::string /*playerIp*/) {} 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*/) {} diff --git a/src/dbofficial/asyncdbauth.cpp b/src/dbofficial/asyncdbauth.cpp index 0fe4f6ae..91f07aea 100644 --- a/src/dbofficial/asyncdbauth.cpp +++ b/src/dbofficial/asyncdbauth.cpp @@ -52,23 +52,25 @@ AsyncDBAuth::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, service.post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &cb, GetId())); } else { int blocked = result[0][2]; - int active = result[0][5]; - if ((active != 1) || (blocked != 0)) { + //int active = result[0][5]; + if (/*(active != 1) ||*/ (blocked != 0)) { service.post(boost::bind(&ServerDBCallback::PlayerLoginBlocked, &cb, GetId())); } else { mysqlpp::String secret(result[0][1]); mysqlpp::String country(result[0][3]); mysqlpp::String last_login(result[0][4]); - mysqlpp::String lastGames(result[0][5]); - mysqlpp::String lastIp(result[0][6]); + mysqlpp::String last_games(result[0][5]); + mysqlpp::String last_ip(result[0][6]); boost::shared_ptr tmpData(new DBPlayerData); tmpData->id = result[0][0]; secret.to_string(tmpData->secret); if (!country.is_null()) country.to_string(tmpData->country); last_login.to_string(tmpData->last_login); - lastGames.to_string(tmpData->lastGames); - lastIp.to_string(tmpData->lastIp); + if (!last_games.is_null()) + 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)); } diff --git a/src/dbofficial/serverdbthread.cpp b/src/dbofficial/serverdbthread.cpp index 179c0c1d..f18ea68d 100644 --- a/src/dbofficial/serverdbthread.cpp +++ b/src/dbofficial/serverdbthread.cpp @@ -235,16 +235,16 @@ ServerDBThread::SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned } void -ServerDBThread::SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector lastGames, std::string playerIp) +ServerDBThread::SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector last_games, std::string playerIp) { LOG_ERROR("ServerDBThread::SetPlayerLastGames() entered."); std::ostringstream oss; - std::copy(lastGames.begin(), lastGames.end(), std::ostream_iterator(oss, ",")); - std::string lastGamesFieldValue( oss.str() ); + std::copy(last_games.begin(), last_games.end(), std::ostream_iterator(oss, ",")); + std::string last_gamesFieldValue( oss.str() ); list params; ostringstream paramStream; - params.push_back(lastGamesFieldValue); + params.push_back(last_gamesFieldValue); params.push_back(playerIp); paramStream << playerId; params.push_back(paramStream.str()); @@ -463,7 +463,7 @@ ServerDBThread::EstablishDBConnection() */ prepareNick << "PREPARE " QUERY_NICK_PREPARE " FROM " << mysqlpp::quote - << "SELECT " DB_TABLE_PLAYER_COL_ID ", AES_DECRYPT(" DB_TABLE_PLAYER_COL_PASSWORD ", ?), " DB_TABLE_PLAYER_COL_VALID ", TRIM(" DB_TABLE_PLAYER_COL_COUNTRY "), " DB_TABLE_PLAYER_COL_LASTLOGIN ", " DB_TABLE_PLAYER_COL_LASTGAMES ", " DB_TABLE_PLAYER_COL_LASTIP " FROM " DB_TABLE_PLAYER " WHERE " DB_TABLE_PLAYER_COL_USERNAME " = ?"; + << "SELECT " DB_TABLE_PLAYER_COL_ID ", AES_DECRYPT(" DB_TABLE_PLAYER_COL_PASSWORD ", ?), " DB_TABLE_PLAYER_COL_VALID ", TRIM(" DB_TABLE_PLAYER_COL_COUNTRY "), " DB_TABLE_PLAYER_COL_LASTLOGIN ", " DB_TABLE_PLAYER_COL_LASTGAMES ", " DB_TABLE_PLAYER_COL_LASTIP " FROM " DB_TABLE_PLAYER " WHERE " DB_TABLE_PLAYER_COL_USERNAME " = ?"; mysqlpp::Query prepareAvatarBlacklist = m_connData->conn.query(); prepareAvatarBlacklist diff --git a/src/dbofficial/serverdbthread.h b/src/dbofficial/serverdbthread.h index 159abc22..03722d1a 100644 --- a/src/dbofficial/serverdbthread.h +++ b/src/dbofficial/serverdbthread.h @@ -67,7 +67,7 @@ public: virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName); virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place); - virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector lastGames, std::string playerIp); + virtual void SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector last_games, std::string playerIp); 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); diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index e9f193a2..37dd2c39 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -349,7 +349,7 @@ ServerGame::InternalStartGame() GetDatabase().AsyncCreateGame(GetId(), GetName()); 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(true) @@ -462,10 +462,10 @@ ServerGame::StoreLastGames(const PlayerDataList &playerDataList) // tmpPlayer->GetUniqueId() tmpPlayer->AddPlayerLastGame((long)time(NULL)); LOG_ERROR("TimeStamp stored: " << tmpPlayer->GetPlayerLastGames().back()); - std::vector lastGames = tmpPlayer->GetPlayerLastGames(); - LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetDBId() << " - lastGameTs " << lastGames.back()); + std::vector last_games = tmpPlayer->GetPlayerLastGames(); + LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetDBId() << " - lastGameTs " << last_games.back()); 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; } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index cdeb6ef1..7df6babf 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1811,16 +1811,16 @@ ServerLobbyThread::UserValid(unsigned playerId, const DBPlayerData &dbPlayerData if (tmpSession && tmpSession->GetPlayerData()) { tmpSession->GetPlayerData()->SetDBId(dbPlayerData.id); tmpSession->GetPlayerData()->SetCountry(dbPlayerData.country); -LOG_ERROR("lastGames from db = " << dbPlayerData.lastGames); -// std::vector lastGames; -// std::stringstream ss(dbPlayerData.lastGames); +LOG_ERROR("last_games from db = " << dbPlayerData.last_games); +// std::vector last_games; +// std::stringstream ss(dbPlayerData.last_games); // for (int i; ss >> i;) { -// lastGames.push_back(i); +// last_games.push_back(i); // if (ss.peek() == ',') // ss.ignore(); // } -// tmpSession->GetPlayerData()->SetPlayerLastGames(lastGames); -// LOG_ERROR("lastGames first from vector after db = " << tmpSession->GetPlayerData()->GetPlayerLastGames().front()); +// tmpSession->GetPlayerData()->SetPlayerLastGames(last_games); +// LOG_ERROR("last_games first from vector after db = " << tmpSession->GetPlayerData()->GetPlayerLastGames().front()); this->AuthChallenge(tmpSession, dbPlayerData.secret); } } diff --git a/src/playerdata.cpp b/src/playerdata.cpp index b4d10c4d..9fb6d8cc 100644 --- a/src/playerdata.cpp +++ b/src/playerdata.cpp @@ -247,10 +247,10 @@ PlayerData::operator<(const PlayerData &other) const } void -PlayerData::SetPlayerLastGames(std::vector lastGames) +PlayerData::SetPlayerLastGames(std::vector last_games) { boost::mutex::scoped_lock lock(m_dataMutex); - m_lastGames = lastGames; + m_last_games = last_games; } void @@ -258,14 +258,14 @@ PlayerData::AddPlayerLastGame(long lastGame) { boost::mutex::scoped_lock lock(m_dataMutex); - m_lastGames.push_back(lastGame); + m_last_games.push_back(lastGame); } std::vector PlayerData::GetPlayerLastGames() { boost::mutex::scoped_lock lock(m_dataMutex); - return m_lastGames; + return m_last_games; } bool @@ -282,11 +282,11 @@ PlayerData::IsPlayerAllowedToJoinCreateLimitRank() int count = 0; - for(std::vector::iterator timeStamp = m_lastGames.begin(); timeStamp != m_lastGames.end(); ++timeStamp) { + for(std::vector::iterator timeStamp = m_last_games.begin(); timeStamp != m_last_games.end(); ++timeStamp) { if(*timeStamp > then) count++; else - m_lastGames.erase(timeStamp); // erase overdued entries + m_last_games.erase(timeStamp); // erase overdued entries } if(count < SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES) diff --git a/src/playerdata.h b/src/playerdata.h index 12204f9f..cf47e353 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -116,9 +116,9 @@ public: int GetStartCash() const; void SetStartCash(int cash); - // @TODO: lastGames here - void AddPlayerLastGame(long lastGames); - void SetPlayerLastGames(std::vector lastGames); + // @TODO: last_games here + void AddPlayerLastGame(long last_games); + void SetPlayerLastGames(std::vector last_games); std::vector GetPlayerLastGames(); bool IsPlayerAllowedToJoinCreateLimitRank(); @@ -141,7 +141,7 @@ private: bool m_isGameAdmin; boost::shared_ptr m_netAvatarFile; - std::vector m_lastGames; + std::vector m_last_games; mutable boost::mutex m_dataMutex; };