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
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 country;
std::string last_login;
std::string lastGames;
std::string lastIp;
std::string last_games;
std::string last_ip;
};
#endif
+1 -1
View File
@@ -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<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 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 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 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 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 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()));
} 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<DBPlayerData> 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));
}
+5 -5
View File
@@ -235,16 +235,16 @@ ServerDBThread::SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned
}
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.");
std::ostringstream oss;
std::copy(lastGames.begin(), lastGames.end(), std::ostream_iterator<int>(oss, ","));
std::string lastGamesFieldValue( oss.str() );
std::copy(last_games.begin(), last_games.end(), std::ostream_iterator<int>(oss, ","));
std::string last_gamesFieldValue( oss.str() );
list<string> 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
+1 -1
View File
@@ -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<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 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());
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<long> lastGames = tmpPlayer->GetPlayerLastGames();
LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetDBId() << " - lastGameTs " << lastGames.back());
std::vector<long> 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;
}
+6 -6
View File
@@ -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<long> lastGames;
// std::stringstream ss(dbPlayerData.lastGames);
LOG_ERROR("last_games from db = " << dbPlayerData.last_games);
// std::vector<long> 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);
}
}
+6 -6
View File
@@ -247,10 +247,10 @@ PlayerData::operator<(const PlayerData &other) const
}
void
PlayerData::SetPlayerLastGames(std::vector<long> lastGames)
PlayerData::SetPlayerLastGames(std::vector<long> 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<long>
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<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)
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)
+4 -4
View File
@@ -116,9 +116,9 @@ public:
int GetStartCash() const;
void SetStartCash(int cash);
// @TODO: lastGames here
void AddPlayerLastGame(long lastGames);
void SetPlayerLastGames(std::vector<long> lastGames);
// @TODO: last_games here
void AddPlayerLastGame(long last_games);
void SetPlayerLastGames(std::vector<long> last_games);
std::vector<long> GetPlayerLastGames();
bool IsPlayerAllowedToJoinCreateLimitRank();
@@ -141,7 +141,7 @@ private:
bool m_isGameAdmin;
boost::shared_ptr<AvatarFile> m_netAvatarFile;
std::vector<long> m_lastGames;
std::vector<long> m_last_games;
mutable boost::mutex m_dataMutex;
};