diff --git a/src/db/common/serverdbgeneric.cpp b/src/db/common/serverdbgeneric.cpp index 86483a71..c15ef614 100644 --- a/src/db/common/serverdbgeneric.cpp +++ b/src/db/common/serverdbgeneric.cpp @@ -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*/) { diff --git a/src/db/serverdbgeneric.h b/src/db/serverdbgeneric.h index 1a111cc1..fc987fc4 100644 --- a/src/db/serverdbgeneric.h +++ b/src/db/serverdbgeneric.h @@ -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); diff --git a/src/db/serverdbinterface.h b/src/db/serverdbinterface.h index 622f5aaa..ec4d1ca6 100644 --- a/src/db/serverdbinterface.h +++ b/src/db/serverdbinterface.h @@ -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; diff --git a/src/db/serverdbnoaction.h b/src/db/serverdbnoaction.h index d3f2f4da..e8864774 100644 --- a/src/db/serverdbnoaction.h +++ b/src/db/serverdbnoaction.h @@ -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*/) {} diff --git a/src/dbofficial/serverdbthread.cpp b/src/dbofficial/serverdbthread.cpp index 1ae5e786..d765b41a 100644 --- a/src/dbofficial/serverdbthread.cpp +++ b/src/dbofficial/serverdbthread.cpp @@ -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 params; + ostringstream paramStream; + paramStream << playerId; + params.push_back(paramStream.str()); + paramStream.str(""); + paramStream << lastGamesFieldValue; + params.push_back(paramStream.str()); + // boost::shared_ptr 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) { diff --git a/src/dbofficial/serverdbthread.h b/src/dbofficial/serverdbthread.h index 274b247e..e75d815f 100644 --- a/src/dbofficial/serverdbthread.h +++ b/src/dbofficial/serverdbthread.h @@ -42,6 +42,8 @@ #include #include +//#include + 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); diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index ea551ebd..d3606e6c 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -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 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 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 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; } }