lastgames from sessiondata to playerdata
This commit is contained in:
+1
-1
@@ -18,4 +18,4 @@ uics/
|
|||||||
make.sh
|
make.sh
|
||||||
gitpush_serverstuff_stable
|
gitpush_serverstuff_stable
|
||||||
pokerth_server
|
pokerth_server
|
||||||
|
.vscode/
|
||||||
|
|||||||
@@ -349,6 +349,8 @@ ServerGame::InternalStartGame()
|
|||||||
if(true)
|
if(true)
|
||||||
StoreLastGames();
|
StoreLastGames();
|
||||||
|
|
||||||
|
// @TODO: StoreWECData() ;)
|
||||||
|
|
||||||
|
|
||||||
GetDatabase().AsyncCreateGame(GetId(), GetName());
|
GetDatabase().AsyncCreateGame(GetId(), GetName());
|
||||||
InitRankingMap(playerData);
|
InitRankingMap(playerData);
|
||||||
|
|||||||
@@ -1439,8 +1439,8 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr<SessionData> sessio
|
|||||||
// SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED);
|
// SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED);
|
||||||
} else {
|
} else {
|
||||||
// @FIXME: debug only - final position is gamestart
|
// @FIXME: debug only - final position is gamestart
|
||||||
session->AddPlayerLastGame((long)time(NULL));
|
session->GetPlayerData()->AddPlayerLastGame((long)time(NULL));
|
||||||
LOG_ERROR("TimeStamp stored: " << *session->GetPlayerLastGames().end());
|
LOG_ERROR("TimeStamp stored: " << *session->GetPlayerData()->GetPlayerLastGames().end());
|
||||||
MoveSessionToGame(game, session, joinGame.autoleave(), false);
|
MoveSessionToGame(game, session, joinGame.autoleave(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,6 @@
|
|||||||
#include <net/websocketdata.h>
|
#include <net/websocketdata.h>
|
||||||
#include <gsasl.h>
|
#include <gsasl.h>
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
|
|
||||||
@@ -49,9 +47,6 @@ using namespace std::chrono;
|
|||||||
using namespace boost::chrono;
|
using namespace boost::chrono;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5
|
|
||||||
#define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60
|
|
||||||
|
|
||||||
SessionData::SessionData(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService)
|
SessionData::SessionData(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService)
|
||||||
: m_socket(sock), m_id(id), m_state(SessionData::Init), m_readyFlag(false), m_wantsLobbyMsg(true),
|
: m_socket(sock), m_id(id), m_state(SessionData::Init), m_readyFlag(false), m_wantsLobbyMsg(true),
|
||||||
m_activityTimeoutSec(0), m_activityWarningRemainingSec(0), m_initTimeoutTimer(ioService), m_globalTimeoutTimer(ioService),
|
m_activityTimeoutSec(0), m_activityWarningRemainingSec(0), m_initTimeoutTimer(ioService), m_globalTimeoutTimer(ioService),
|
||||||
@@ -403,60 +398,6 @@ SessionData::GetPlayerData()
|
|||||||
return m_playerData;
|
return m_playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SessionData::SetPlayerLastGames(std::vector<long> lastGames)
|
|
||||||
{
|
|
||||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
||||||
m_lastGames = lastGames;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SessionData::AddPlayerLastGame(long lastGame)
|
|
||||||
{
|
|
||||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
||||||
|
|
||||||
m_lastGames.push_back(lastGame);
|
|
||||||
|
|
||||||
// @TODO: remove overdued entries
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<long>
|
|
||||||
SessionData::GetPlayerLastGames()
|
|
||||||
{
|
|
||||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
||||||
return m_lastGames;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
SessionData::IsPlayerAllowedToJoinLimitRank()
|
|
||||||
{
|
|
||||||
bool retVal = false;
|
|
||||||
|
|
||||||
// #define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5
|
|
||||||
// #define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60
|
|
||||||
|
|
||||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
|
||||||
|
|
||||||
// @TODO: iterate m_lastGames
|
|
||||||
long then = (long)time(NULL) - (long)(SERVER_ALLOWED_RANKING_GAMES_MINUTES * 10);
|
|
||||||
|
|
||||||
long num = (long)SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES;
|
|
||||||
|
|
||||||
long count = 0;
|
|
||||||
|
|
||||||
for(std::vector<long>::iterator timeStamp = m_lastGames.begin(); timeStamp != m_lastGames.end(); ++timeStamp) {
|
|
||||||
if(*timeStamp > then)
|
|
||||||
count++;
|
|
||||||
else
|
|
||||||
m_lastGames.erase(timeStamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count < num)
|
|
||||||
retVal = true;
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
string
|
string
|
||||||
SessionData::GetRemoteIPAddressFromSocket() const
|
SessionData::GetRemoteIPAddressFromSocket() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -127,11 +127,6 @@ public:
|
|||||||
void SetPlayerData(boost::shared_ptr<PlayerData> player);
|
void SetPlayerData(boost::shared_ptr<PlayerData> player);
|
||||||
boost::shared_ptr<PlayerData> GetPlayerData();
|
boost::shared_ptr<PlayerData> GetPlayerData();
|
||||||
|
|
||||||
void AddPlayerLastGame(long lastGames);
|
|
||||||
void SetPlayerLastGames(std::vector<long> lastGames);
|
|
||||||
std::vector<long> GetPlayerLastGames();
|
|
||||||
bool IsPlayerAllowedToJoinLimitRank();
|
|
||||||
|
|
||||||
std::string GetRemoteIPAddressFromSocket() const;
|
std::string GetRemoteIPAddressFromSocket() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -165,8 +160,6 @@ private:
|
|||||||
std::string m_password;
|
std::string m_password;
|
||||||
boost::shared_ptr<PlayerData> m_playerData;
|
boost::shared_ptr<PlayerData> m_playerData;
|
||||||
|
|
||||||
std::vector<long> m_lastGames;
|
|
||||||
|
|
||||||
mutable boost::mutex m_dataMutex;
|
mutable boost::mutex m_dataMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
* as that of the covered work. *
|
* as that of the covered work. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#include <playerdata.h>
|
#include <playerdata.h>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
#define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5
|
||||||
|
#define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -242,3 +246,51 @@ PlayerData::operator<(const PlayerData &other) const
|
|||||||
return m_number < other.GetNumber();
|
return m_number < other.GetNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayerData::SetPlayerLastGames(std::vector<long> lastGames)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||||
|
m_lastGames = lastGames;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayerData::AddPlayerLastGame(long lastGame)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||||
|
|
||||||
|
m_lastGames.push_back(lastGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<long>
|
||||||
|
PlayerData::GetPlayerLastGames()
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||||
|
return m_lastGames;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlayerData::IsPlayerAllowedToJoinLimitRank()
|
||||||
|
{
|
||||||
|
bool retVal = false;
|
||||||
|
|
||||||
|
// #define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5
|
||||||
|
// #define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||||
|
|
||||||
|
long then = (long)time(NULL) - (long)(SERVER_ALLOWED_RANKING_GAMES_MINUTES * 10);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for(std::vector<long>::iterator timeStamp = m_lastGames.begin(); timeStamp != m_lastGames.end(); ++timeStamp) {
|
||||||
|
if(*timeStamp > then)
|
||||||
|
count++;
|
||||||
|
else
|
||||||
|
m_lastGames.erase(timeStamp); // erase overdued entries
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count < SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES)
|
||||||
|
retVal = true;
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ public:
|
|||||||
int GetStartCash() const;
|
int GetStartCash() const;
|
||||||
void SetStartCash(int cash);
|
void SetStartCash(int cash);
|
||||||
|
|
||||||
|
// @TODO: lastGames here
|
||||||
|
void AddPlayerLastGame(long lastGames);
|
||||||
|
void SetPlayerLastGames(std::vector<long> lastGames);
|
||||||
|
std::vector<long> GetPlayerLastGames();
|
||||||
|
bool IsPlayerAllowedToJoinLimitRank();
|
||||||
|
|
||||||
bool operator<(const PlayerData &other) const;
|
bool operator<(const PlayerData &other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -135,6 +141,8 @@ private:
|
|||||||
bool m_isGameAdmin;
|
bool m_isGameAdmin;
|
||||||
boost::shared_ptr<AvatarFile> m_netAvatarFile;
|
boost::shared_ptr<AvatarFile> m_netAvatarFile;
|
||||||
|
|
||||||
|
std::vector<long> m_lastGames;
|
||||||
|
|
||||||
mutable boost::mutex m_dataMutex;
|
mutable boost::mutex m_dataMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user