implemented SetPlayerLastGames db function

This commit is contained in:
Kai Philipp
2019-09-11 04:36:54 +02:00
parent ecf5996135
commit afcec9d39a
7 changed files with 50 additions and 17 deletions
+15
View File
@@ -93,6 +93,21 @@ ServerDBGeneric::SetGamePlayerPlace(unsigned /*requestId*/, DB_id /*playerId*/,
{
}
void
ServerDBGeneric::SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place)
{
}
void
ServerDBGeneric::SetPlayerLastGames(unsigned /*requestId*/, DB_id /*playerId*/, std::vector /*lastGames*/)
{
}
void
ServerDBGeneric::SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector lastGames)
{
}
void
ServerDBGeneric::EndGame(unsigned /*requestId*/)
{
+1
View File
@@ -57,6 +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);
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
View File
@@ -57,6 +57,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) = 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
View File
@@ -55,6 +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*/) {}
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*/) {}
+26
View File
@@ -230,6 +230,32 @@ ServerDBThread::SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned
m_semaphore.post();
}
void
ServerDBThread::SetPlayerLastGames(unsigned requestId, DB_id playerId, std::vector lastGames)
{
// The game id param is added later (during init of the async op), because it may be unknown.
string lastGamesFieldValue = "1,2,3";
list<string> params;
ostringstream paramStream;
paramStream << playerId;
params.push_back(paramStream.str());
paramStream.str("");
paramStream << lastGamesFieldValue;
params.push_back(paramStream.str());
// boost::shared_ptr<AsyncDBQuery> asyncQuery(
// new AsyncDBGamePlace(
// requestId,
// QUERY_PLAYER_LASTGAMES_PREPARE,
// params));
// {
// boost::mutex::scoped_lock lock(m_asyncQueueMutex);
// m_asyncQueue.push(asyncQuery);
// }
LOG_ERROR("reached ServerDBThread::SetPlayerLastGames() post query ");
m_semaphore.post();
}
void
ServerDBThread::EndGame(unsigned requestId)
{
+3
View File
@@ -42,6 +42,8 @@
#include <dbofficial/dbidmanager.h>
#include <core/thread.h>
//#include <vector>
struct DBConnectionData;
class AsyncDBQuery;
@@ -66,6 +68,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);
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);
+3 -17
View File
@@ -454,23 +454,6 @@ void
ServerGame::StoreLastGames(const PlayerDataList &playerDataList)
{
// Store players lastgames in database.
// RankingMap::const_iterator i = m_rankingMap.begin();
// RankingMap::const_iterator end = m_rankingMap.end();
// boost::shared_ptr<SessionData> tmpSession;
// while (i != end) {
// LOG_ERROR("iterating m_rankingMap ... userId " << (*i).second.dbid);
// tmpSession = GetSessionManager().GetSessionByUniquePlayerId((*i).second.dbid);
// if(tmpSession){
// tmpSession->GetPlayerData()->AddPlayerLastGame((long)time(NULL));
// LOG_ERROR("TimeStamp stored: " << tmpSession->GetPlayerData()->GetPlayerLastGames().back());
// std::vector<long> lastGames = tmpSession->GetPlayerData()->GetPlayerLastGames();
// LOG_ERROR("Ready for storing vector: " << lastGames.back());
// }else{
// LOG_ERROR("no tmpSession for userId " << (*i).second.dbid);
// }
// ++i;
// }
PlayerDataList::const_iterator i = playerDataList.begin();
PlayerDataList::const_iterator end = playerDataList.end();
while (i != end) {
@@ -480,6 +463,9 @@ ServerGame::StoreLastGames(const PlayerDataList &playerDataList)
LOG_ERROR("TimeStamp stored: " << tmpPlayer->GetPlayerLastGames().back());
std::vector<long> lastGames = tmpPlayer->GetPlayerLastGames();
LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetUniqueId() << " - lastGameTs " << lastGames.back());
if(tmpPlayer->GetUniqueId() != DB_ID_INVALID){
GetDatabase().SetPlayerLastGames(GetId(), tmpPlayer->GetUniqueId(), lastGames);
}
++i;
}
}