limit rank games per time unit implemented
This commit is contained in:
@@ -293,11 +293,13 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
|
||||
PlayerDataList
|
||||
ServerGame::InternalStartGame()
|
||||
{
|
||||
LOG_ERROR("InternalStartGame() entered.");
|
||||
// Initialize the game.
|
||||
PlayerDataList playerData(GetFullPlayerDataList());
|
||||
|
||||
if (playerData.size() >= 2) {
|
||||
// Set DB Backend.
|
||||
// @TODO: check for wec or bbc game with bbcbot as creator
|
||||
if (GetGameData().gameType == GAME_TYPE_RANKING)
|
||||
m_database = GetLobbyThread().GetDatabase();
|
||||
else
|
||||
@@ -346,6 +348,12 @@ ServerGame::InternalStartGame()
|
||||
|
||||
GetDatabase().AsyncCreateGame(GetId(), GetName());
|
||||
InitRankingMap(playerData);
|
||||
|
||||
// @TODO: here to save last_games with mysql per player
|
||||
|
||||
if (GetGameData().gameType == GAME_TYPE_RANKING)
|
||||
StoreLastGames(playerData);
|
||||
|
||||
}
|
||||
return playerData;
|
||||
}
|
||||
@@ -442,6 +450,26 @@ ServerGame::StoreAndResetRanking()
|
||||
m_rankingMap.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::StoreLastGames(const PlayerDataList &playerDataList)
|
||||
{
|
||||
// Store players lastgames in database.
|
||||
PlayerDataList::const_iterator i = playerDataList.begin();
|
||||
PlayerDataList::const_iterator end = playerDataList.end();
|
||||
while (i != end) {
|
||||
boost::shared_ptr<PlayerData> tmpPlayer(*i);
|
||||
// tmpPlayer->GetUniqueId()
|
||||
tmpPlayer->AddPlayerLastGame((long)time(NULL));
|
||||
LOG_ERROR("TimeStamp stored: " << tmpPlayer->GetPlayerLastGames().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(), last_games, GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->GetUniqueId())->GetClientAddr());
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::RemoveAutoLeavePlayers()
|
||||
{
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <gsasl.h>
|
||||
#include <ctime>
|
||||
|
||||
#define SERVER_MAX_NUM_LOBBY_SESSIONS 512 // Maximum number of idle users in lobby.
|
||||
#define SERVER_MAX_NUM_TOTAL_SESSIONS 2000 // Total maximum of sessions, fitting a 2048 handle limit
|
||||
@@ -304,6 +305,7 @@ ServerLobbyThread::AddConnection(boost::shared_ptr<SessionData> sessionData)
|
||||
m_sessionManager.AddSession(sessionData);
|
||||
|
||||
LOG_VERBOSE("Accepted connection - session #" << sessionData->GetId() << ".");
|
||||
LOG_ERROR("Accepted connection - session #" << sessionData->GetId() << ".");
|
||||
|
||||
sessionData->StartTimerInitTimeout(SERVER_INIT_SESSION_TIMEOUT_SEC);
|
||||
sessionData->StartTimerGlobalTimeout(SERVER_SESSION_FORCED_TIMEOUT_SEC);
|
||||
@@ -1347,7 +1349,7 @@ ServerLobbyThread::HandleNetPacketRetrieveAvatar(boost::shared_ptr<SessionData>
|
||||
void
|
||||
ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr<SessionData> session, const JoinNewGameMessage &newGame)
|
||||
{
|
||||
LOG_VERBOSE("Creating new game, initiated by session #" << session->GetId() << ".");
|
||||
LOG_ERROR("Creating new game, initiated by session #" << session->GetId() << ".");
|
||||
|
||||
string password;
|
||||
if (newGame.has_password())
|
||||
@@ -1377,6 +1379,10 @@ ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr<SessionData> sess
|
||||
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN);
|
||||
} else if (!ServerGame::CheckSettings(tmpData, password, GetServerMode())) {
|
||||
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_INVALID_SETTINGS);
|
||||
} else if (!session->GetPlayerData()->IsPlayerAllowedToJoinCreateLimitRank(m_serverConfig.readConfigString("ServerLimitRankNum"), m_serverConfig.readConfigString("ServerLimitRankPeriod"))
|
||||
&& tmpData.gameType == GAME_TYPE_RANKING ) {
|
||||
LOG_ERROR("not allowed due to ranklimit");
|
||||
SendJoinGameFailed(session, gameId, NTF_NET_JOIN_IP_BLOCKED);
|
||||
} else {
|
||||
boost::shared_ptr<ServerGame> game(
|
||||
new ServerGame(
|
||||
@@ -1418,6 +1424,7 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr<SessionData> sessio
|
||||
MoveSessionToGame(game, session, joinGame.autoleave(), true);
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("JoinGame pre validation");
|
||||
// As guest, you are only allowed to join normal games.
|
||||
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST
|
||||
&& tmpData.gameType != GAME_TYPE_NORMAL) {
|
||||
@@ -1427,14 +1434,14 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr<SessionData> sessio
|
||||
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_NOT_INVITED);
|
||||
} else if (!game->CheckPassword(password)) {
|
||||
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_INVALID_PASSWORD);
|
||||
} else if (tmpData.gameType == GAME_TYPE_RANKING
|
||||
&& !joinGame.spectateonly()
|
||||
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR
|
||||
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6
|
||||
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4
|
||||
&& game->IsClientAddressConnected(session->GetClientAddr())) {
|
||||
} else if (tmpData.gameType == GAME_TYPE_RANKING && !session->GetPlayerData()->IsPlayerAllowedToJoinCreateLimitRank(m_serverConfig.readConfigString("ServerLimitRankNum"), m_serverConfig.readConfigString("ServerLimitRankPeriod"))) {
|
||||
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED);
|
||||
} else if (tmpData.gameType == GAME_TYPE_RANKING && !joinGame.spectateonly()
|
||||
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR
|
||||
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6
|
||||
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4
|
||||
&& game->IsClientAddressConnected(session->GetClientAddr())) {
|
||||
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED);
|
||||
|
||||
} else {
|
||||
MoveSessionToGame(game, session, joinGame.autoleave(), false);
|
||||
}
|
||||
@@ -1803,6 +1810,18 @@ ServerLobbyThread::UserValid(unsigned playerId, const DBPlayerData &dbPlayerData
|
||||
if (tmpSession && tmpSession->GetPlayerData()) {
|
||||
tmpSession->GetPlayerData()->SetDBId(dbPlayerData.id);
|
||||
tmpSession->GetPlayerData()->SetCountry(dbPlayerData.country);
|
||||
if(dbPlayerData.last_games.length() > 0){
|
||||
LOG_ERROR("last_games from db = " << dbPlayerData.last_games);
|
||||
vector<string> last_games;
|
||||
boost::split(last_games, dbPlayerData.last_games, boost::is_any_of(","));
|
||||
for (unsigned int i = 0; i < last_games.size(); i++){
|
||||
if(last_games[i].length() > 0)
|
||||
tmpSession->GetPlayerData()->AddPlayerLastGame(stol(last_games[i]));
|
||||
}
|
||||
LOG_ERROR("last_games last from vector after db = " << tmpSession->GetPlayerData()->GetPlayerLastGames().back());
|
||||
}else{
|
||||
LOG_ERROR("no lastGames from db");
|
||||
}
|
||||
this->AuthChallenge(tmpSession, dbPlayerData.secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include <net/serverexception.h>
|
||||
#include <net/socket_msg.h>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define SERVER_MAX_GUEST_USERS_LOBBY 50 // LG: Maximum number of guests users in lobby allowed
|
||||
|
||||
@@ -148,6 +148,7 @@ protected:
|
||||
void SetPlayerPlace(unsigned playerId, int place);
|
||||
void ReplaceRankingPlayer(unsigned oldPlayerId, unsigned newPlayerId);
|
||||
void StoreAndResetRanking();
|
||||
void StoreLastGames(const PlayerDataList &playerDataList);
|
||||
void RemoveAutoLeavePlayers();
|
||||
void InternalEndGame();
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef unsigned SessionId;
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <net/socket_helper.h>
|
||||
#include <net/sessiondatacallback.h>
|
||||
|
||||
@@ -65,6 +65,8 @@ public:
|
||||
bool IsPlayerConnected(unsigned uniqueId) const;
|
||||
bool IsClientAddressConnected(const std::string &clientAddress) const;
|
||||
bool IsGuestAllowedToConnect(const std::string &clientAddress) const;
|
||||
bool IsPlayerAllowedToJoinCreateLimitRank(const std::string &playerName) const;
|
||||
bool IsPlayerAllowedToJoinCreateLimitRank(unsigned uniqueId) const;
|
||||
|
||||
void ForEach(boost::function<void (boost::shared_ptr<SessionData>)> func);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user