2011-07-02 14:38:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 14:38:06 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-02 14:38:06 +00:00
|
|
|
*****************************************************************************/
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-08-02 15:11:40 +00:00
|
|
|
#include <boost/asio.hpp>
|
|
|
|
|
#include <boost/bind.hpp>
|
2010-10-22 19:42:48 +00:00
|
|
|
#include <algorithm>
|
2009-08-02 15:11:40 +00:00
|
|
|
|
2009-05-31 19:45:20 +00:00
|
|
|
#include <net/servergame.h>
|
2007-10-18 17:40:12 +00:00
|
|
|
#include <net/servergamestate.h>
|
|
|
|
|
#include <net/serverlobbythread.h>
|
|
|
|
|
#include <net/serverexception.h>
|
2009-05-10 22:21:20 +00:00
|
|
|
#include <net/senderhelper.h>
|
2007-10-18 17:40:12 +00:00
|
|
|
#include <net/socket_msg.h>
|
2007-10-29 18:49:28 +00:00
|
|
|
#include <core/loghelper.h>
|
2009-10-03 20:19:51 +00:00
|
|
|
#include <db/serverdbinterface.h>
|
2010-08-07 23:06:59 +00:00
|
|
|
#include <db/serverdbnoaction.h>
|
2007-10-18 17:40:12 +00:00
|
|
|
#include <game.h>
|
|
|
|
|
#include <localenginefactory.h>
|
|
|
|
|
#include <tools.h>
|
2010-09-11 21:37:27 +00:00
|
|
|
#include <configfile.h>
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2008-12-06 21:10:46 +00:00
|
|
|
|
|
|
|
|
#define SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC 500
|
2008-12-07 11:48:01 +00:00
|
|
|
#define SERVER_KICK_TIMEOUT_ADD_DELAY_SEC 2
|
2008-12-06 21:10:46 +00:00
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2014-03-29 16:13:53 +01:00
|
|
|
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
#else
|
|
|
|
|
using namespace boost::chrono;
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-08-29 16:51:41 +00:00
|
|
|
static bool LessThanPlayerHandStartMoney(const boost::shared_ptr<PlayerInterface> p1, const boost::shared_ptr<PlayerInterface> p2)
|
|
|
|
|
{
|
|
|
|
|
return p1->getMyRoundStartCash() < p2->getMyRoundStartCash();
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2012-04-08 14:36:14 +00:00
|
|
|
ServerGame::ServerGame(boost::shared_ptr<ServerLobbyThread> lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData,
|
2014-07-27 18:09:19 +02:00
|
|
|
unsigned adminPlayerId, unsigned creatorPlayerDBId, GuiInterface &gui, ConfigFile &playerConfig, const ServerMode mode)
|
2011-02-11 20:02:08 +00:00
|
|
|
: m_adminPlayerId(adminPlayerId), m_lobbyThread(lobbyThread), m_gui(gui),
|
2014-12-28 01:03:06 +01:00
|
|
|
m_serverDelayTime(mode), m_gameData(gameData), m_curState(NULL), m_id(id), m_name(name),
|
2012-04-08 14:36:14 +00:00
|
|
|
m_password(pwd), m_creatorPlayerDBId(creatorPlayerDBId), m_playerConfig(playerConfig),
|
|
|
|
|
m_gameNum(1), m_curPetitionId(1), m_voteKickTimer(lobbyThread->GetIOService()),
|
2012-04-09 10:22:24 +00:00
|
|
|
m_stateTimer1(lobbyThread->GetIOService()), m_stateTimer2(lobbyThread->GetIOService()),
|
2014-12-28 01:03:06 +01:00
|
|
|
m_isNameReported(false)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2008-03-19 23:39:59 +00:00
|
|
|
LOG_VERBOSE("Game object " << GetId() << " created.");
|
2009-06-07 23:25:13 +00:00
|
|
|
}
|
2009-05-30 22:20:40 +00:00
|
|
|
|
2009-06-07 23:25:13 +00:00
|
|
|
ServerGame::~ServerGame()
|
|
|
|
|
{
|
|
|
|
|
LOG_VERBOSE("Game object " << GetId() << " destructed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGame::Init()
|
|
|
|
|
{
|
2009-05-31 13:17:02 +00:00
|
|
|
SetState(SERVER_INITIAL_STATE::Instance());
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-07 23:25:13 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::Exit()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-06-12 15:48:34 +00:00
|
|
|
m_voteKickTimer.cancel();
|
2009-06-15 22:34:07 +00:00
|
|
|
SetState(ServerGameStateFinal::Instance());
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u_int32_t
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetId() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetName() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 14:36:14 +00:00
|
|
|
unsigned
|
|
|
|
|
ServerGame::GetCreatorDBId() const
|
|
|
|
|
{
|
|
|
|
|
return m_creatorPlayerDBId;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
void
|
2013-06-16 10:43:13 +02:00
|
|
|
ServerGame::AddSession(boost::shared_ptr<SessionData> session, bool spectateOnly)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2013-06-16 10:43:13 +02:00
|
|
|
if (session) {
|
|
|
|
|
if (spectateOnly) {
|
|
|
|
|
GetState().HandleNewSpectator(shared_from_this(), session);
|
|
|
|
|
} else {
|
|
|
|
|
GetState().HandleNewPlayer(shared_from_this(), session);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:01:40 +00:00
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::RemovePlayer(unsigned playerId, unsigned errorCode)
|
2007-11-16 15:01:40 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId);
|
2009-05-31 19:11:59 +00:00
|
|
|
// Only kick if the player was found.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (tmpSession)
|
2009-05-31 19:11:59 +00:00
|
|
|
SessionError(tmpSession, errorCode);
|
2007-11-16 15:01:40 +00:00
|
|
|
}
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2012-01-08 13:02:29 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::MutePlayer(unsigned playerId, bool mute)
|
|
|
|
|
{
|
|
|
|
|
if (m_game) {
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
|
|
|
|
|
if (tmpPlayer) {
|
|
|
|
|
tmpPlayer->setIsMuted(mute);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-11 19:37:51 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::MarkPlayerAsInactive(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
if (m_game) {
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
|
|
|
|
|
if (tmpPlayer) {
|
|
|
|
|
tmpPlayer->setIsSessionActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGame::MarkPlayerAsKicked(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
// Mark the player as kicked in the engine.
|
|
|
|
|
if (m_game) {
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
|
|
|
|
|
if (tmpPlayer) {
|
|
|
|
|
// Player was kicked, so he is not allowed to rejoin.
|
|
|
|
|
tmpPlayer->setIsKicked(true);
|
|
|
|
|
tmpPlayer->setMyGuid("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
void
|
2014-12-28 01:03:06 +01:00
|
|
|
ServerGame::HandleGameMsg(boost::shared_ptr<SessionData> session, const GameMessage &gameMsg)
|
2009-05-30 22:20:40 +00:00
|
|
|
{
|
2014-12-28 01:03:06 +01:00
|
|
|
GetState().HandleGameMsg(shared_from_this(), session, gameMsg);
|
2009-05-30 22:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
GameState
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetCurRound() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return static_cast<GameState>(GetGame().getCurrentHand()->getCurrentRound());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-06-29 16:23:10 +02:00
|
|
|
ServerGame::SendToAllPlayers(boost::shared_ptr<NetPacket> packet, int state)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-06-07 08:51:43 +00:00
|
|
|
GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), packet, state);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-17 21:11:12 +00:00
|
|
|
void
|
2013-06-29 16:23:10 +02:00
|
|
|
ServerGame::SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SessionId except, int state)
|
2010-07-17 21:11:12 +00:00
|
|
|
{
|
|
|
|
|
GetSessionManager().SendToAllButOneSessions(GetLobbyThread().GetSender(), packet, except, state);
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::RemoveAllSessions()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
// Clean up ALL sessions which are left.
|
2011-12-11 14:54:17 +00:00
|
|
|
GetSessionManager().ForEach(&SessionData::Close);
|
2009-07-12 09:13:49 +00:00
|
|
|
GetSessionManager().Clear();
|
|
|
|
|
SetState(ServerGameStateFinal::Instance());
|
2007-11-16 15:01:40 +00:00
|
|
|
}
|
2007-11-16 00:58:23 +00:00
|
|
|
|
2013-10-05 12:49:21 +02:00
|
|
|
void
|
|
|
|
|
ServerGame::MoveSpectatorsToLobby()
|
|
|
|
|
{
|
|
|
|
|
PlayerIdList spectatorList = GetSpectatorIdList();
|
|
|
|
|
PlayerIdList::const_iterator i = spectatorList.begin();
|
|
|
|
|
PlayerIdList::const_iterator end = spectatorList.end();
|
|
|
|
|
while (i != end) {
|
|
|
|
|
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(*i);
|
|
|
|
|
// Only remove if the spectator was found.
|
|
|
|
|
if (tmpSession)
|
|
|
|
|
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_GAME_CLOSED);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-06 00:18:36 +00:00
|
|
|
void
|
2009-06-12 15:48:34 +00:00
|
|
|
ServerGame::TimerVoteKick(const boost::system::error_code &ec)
|
2008-12-06 21:10:46 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!ec && m_curState != &ServerGameStateFinal::Instance()) {
|
2009-06-12 15:48:34 +00:00
|
|
|
// Check whether someone should be kicked, or whether a vote kick should be aborted.
|
|
|
|
|
// Only one vote kick can be active at a time.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_voteKickData) {
|
2009-06-12 15:48:34 +00:00
|
|
|
// Prepare some values.
|
|
|
|
|
const PlayerIdList playerIds(GetPlayerIdList());
|
|
|
|
|
int votesRequiredToKick = m_voteKickData->numVotesToKick - m_voteKickData->numVotesInFavourOfKicking;
|
|
|
|
|
int playersAllowedToVote = 0;
|
|
|
|
|
// We need to count the number of players which are still allowed to vote.
|
|
|
|
|
PlayerIdList::const_iterator player_i = playerIds.begin();
|
|
|
|
|
PlayerIdList::const_iterator player_end = playerIds.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (player_i != player_end) {
|
2009-06-12 15:48:34 +00:00
|
|
|
if (find(m_voteKickData->votedPlayerIds.begin(), m_voteKickData->votedPlayerIds.end(), *player_i) == m_voteKickData->votedPlayerIds.end())
|
|
|
|
|
playersAllowedToVote++;
|
|
|
|
|
++player_i;
|
|
|
|
|
}
|
|
|
|
|
bool abortPetition = false;
|
|
|
|
|
bool doKick = false;
|
|
|
|
|
EndPetitionReason reason;
|
2008-12-06 21:10:46 +00:00
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
// 1. Enough votes to kick the player.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_voteKickData->numVotesInFavourOfKicking >= m_voteKickData->numVotesToKick) {
|
2009-06-12 15:48:34 +00:00
|
|
|
reason = PETITION_END_ENOUGH_VOTES;
|
|
|
|
|
abortPetition = true;
|
|
|
|
|
doKick = true;
|
|
|
|
|
}
|
|
|
|
|
// 2. Several players left the game, so a kick is no longer possible.
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (votesRequiredToKick > playersAllowedToVote) {
|
2009-06-12 15:48:34 +00:00
|
|
|
reason = PETITION_END_NOT_ENOUGH_PLAYERS;
|
|
|
|
|
abortPetition = true;
|
|
|
|
|
}
|
|
|
|
|
// 3. The kick has become invalid because the player to be kicked left.
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (!IsValidPlayer(m_voteKickData->kickPlayerId)) {
|
2009-06-12 15:48:34 +00:00
|
|
|
reason = PETITION_END_PLAYER_LEFT;
|
|
|
|
|
abortPetition = true;
|
|
|
|
|
}
|
|
|
|
|
// 4. A kick request timed out (because not everyone voted).
|
2011-02-11 20:02:08 +00:00
|
|
|
else if (m_voteKickData->voteTimer.elapsed().total_seconds() >= m_voteKickData->timeLimitSec) {
|
2009-06-12 15:48:34 +00:00
|
|
|
reason = PETITION_END_TIMEOUT;
|
|
|
|
|
abortPetition = true;
|
|
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (abortPetition) {
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_EndKickPetitionMessage);
|
|
|
|
|
EndKickPetitionMessage *netEndPetition = netManage->mutable_endkickpetitionmessage();
|
2012-09-18 15:57:58 +02:00
|
|
|
netEndPetition->set_petitionid(m_voteKickData->petitionId);
|
|
|
|
|
netEndPetition->set_numvotesagainstkicking(m_voteKickData->numVotesAgainstKicking);
|
|
|
|
|
netEndPetition->set_numvotesinfavourofkicking(m_voteKickData->numVotesInFavourOfKicking);
|
|
|
|
|
netEndPetition->set_resultplayerkicked(doKick);
|
|
|
|
|
netEndPetition->set_petitionendreason(static_cast<EndKickPetitionMessage::PetitionEndReason>(reason));
|
2009-08-02 15:11:40 +00:00
|
|
|
SendToAllPlayers(packet, SessionData::Game);
|
2008-12-07 11:04:42 +00:00
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
// Perform kick.
|
|
|
|
|
if (doKick)
|
2011-12-16 22:39:24 +00:00
|
|
|
KickPlayer(m_voteKickData->kickPlayerId);
|
2009-06-12 15:48:34 +00:00
|
|
|
// This petition has ended.
|
|
|
|
|
m_voteKickData.reset();
|
|
|
|
|
}
|
2010-10-19 13:13:39 +00:00
|
|
|
m_voteKickTimer.expires_from_now(
|
2014-03-29 16:13:53 +01:00
|
|
|
milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
|
2010-10-19 13:13:39 +00:00
|
|
|
m_voteKickTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error));
|
2008-12-06 21:10:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-06 00:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-22 19:42:48 +00:00
|
|
|
PlayerDataList
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::InternalStartGame()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
// Initialize the game.
|
2010-10-22 19:42:48 +00:00
|
|
|
PlayerDataList playerData(GetFullPlayerDataList());
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (playerData.size() >= 2) {
|
2010-10-22 19:42:48 +00:00
|
|
|
// Set DB Backend.
|
|
|
|
|
if (GetGameData().gameType == GAME_TYPE_RANKING)
|
|
|
|
|
m_database = GetLobbyThread().GetDatabase();
|
|
|
|
|
else
|
|
|
|
|
m_database.reset(new ServerDBNoAction);
|
|
|
|
|
|
|
|
|
|
// Randomize player list.
|
|
|
|
|
// Note: This does not use a cryptographically strong
|
|
|
|
|
// random number generator.
|
|
|
|
|
vector<boost::shared_ptr<PlayerData> > tmpData(playerData.begin(), playerData.end());
|
|
|
|
|
random_shuffle(tmpData.begin(), tmpData.end());
|
|
|
|
|
copy(tmpData.begin(), tmpData.end(), playerData.begin());
|
|
|
|
|
|
|
|
|
|
// Set order of players.
|
|
|
|
|
AssignPlayerNumbers(playerData);
|
|
|
|
|
|
|
|
|
|
// Create EngineFactory
|
2011-01-03 18:41:28 +00:00
|
|
|
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(&m_playerConfig)); // LocalEngine erstellen
|
2010-10-22 19:42:48 +00:00
|
|
|
|
|
|
|
|
// Set start data.
|
|
|
|
|
StartData startData;
|
2011-04-10 10:04:42 +00:00
|
|
|
startData.numberOfPlayers = (int)playerData.size();
|
2010-10-22 19:42:48 +00:00
|
|
|
|
|
|
|
|
int tmpDealerPos = 0;
|
2011-10-11 15:15:22 +00:00
|
|
|
Tools::GetRand(0, startData.numberOfPlayers-1, 1, &tmpDealerPos);
|
2010-10-22 19:42:48 +00:00
|
|
|
// The Player Id is not continuous. Therefore, the start dealer position
|
|
|
|
|
// needs to be converted to a player Id, and cannot be directly generated
|
|
|
|
|
// as player Id.
|
|
|
|
|
PlayerDataList::const_iterator player_i = playerData.begin();
|
|
|
|
|
PlayerDataList::const_iterator player_end = playerData.end();
|
|
|
|
|
|
|
|
|
|
int tmpPos = 0;
|
2011-02-11 20:02:08 +00:00
|
|
|
while (player_i != player_end) {
|
2010-10-22 19:42:48 +00:00
|
|
|
startData.startDealerPlayerId = static_cast<unsigned>((*player_i)->GetUniqueId());
|
|
|
|
|
if (tmpPos == tmpDealerPos)
|
|
|
|
|
break;
|
|
|
|
|
++tmpPos;
|
|
|
|
|
++player_i;
|
|
|
|
|
}
|
|
|
|
|
if (player_i == player_end)
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_DEALER_NOT_FOUND, 0);
|
|
|
|
|
|
|
|
|
|
SetStartData(startData);
|
|
|
|
|
|
|
|
|
|
GuiInterface &gui = GetGui();
|
2012-01-02 21:04:49 +00:00
|
|
|
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum(), NULL));
|
2010-10-22 19:42:48 +00:00
|
|
|
|
|
|
|
|
GetDatabase().AsyncCreateGame(GetId(), GetName());
|
|
|
|
|
InitRankingMap(playerData);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
2010-10-22 19:42:48 +00:00
|
|
|
return playerData;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-08-08 10:23:40 +00:00
|
|
|
ServerGame::InitRankingMap(const PlayerDataList &playerDataList)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2010-08-08 10:23:40 +00:00
|
|
|
PlayerDataList::const_iterator i = playerDataList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = playerDataList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2010-08-08 10:23:40 +00:00
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(*i);
|
|
|
|
|
RankingData tmpData(tmpPlayer->GetDBId());
|
|
|
|
|
m_rankingMap[tmpPlayer->GetUniqueId()] = tmpData;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 14:34:02 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::UpdateRankingMap()
|
|
|
|
|
{
|
|
|
|
|
list<boost::shared_ptr<PlayerInterface> > activePlayers = *m_game->getActivePlayerList();
|
2010-08-29 16:51:41 +00:00
|
|
|
int currentRank = static_cast<int>(activePlayers.size());
|
2010-08-28 14:34:02 +00:00
|
|
|
list<boost::shared_ptr<PlayerInterface> > tmpRemovedPlayers;
|
|
|
|
|
PlayerListIterator active_i = activePlayers.begin();
|
|
|
|
|
PlayerListIterator active_end = activePlayers.end();
|
2010-08-29 16:51:41 +00:00
|
|
|
PlayerListIterator next_active_i = active_i;
|
2011-02-11 20:02:08 +00:00
|
|
|
while(active_i != active_end) {
|
2010-08-29 16:51:41 +00:00
|
|
|
++next_active_i;
|
2011-02-11 20:02:08 +00:00
|
|
|
if ((*active_i)->getMyCash() < 1) {
|
2010-08-28 14:34:02 +00:00
|
|
|
tmpRemovedPlayers.push_back(*active_i);
|
|
|
|
|
activePlayers.erase(active_i);
|
|
|
|
|
}
|
2010-08-29 16:51:41 +00:00
|
|
|
active_i = next_active_i;
|
2010-08-28 14:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!tmpRemovedPlayers.empty()) {
|
2010-08-29 16:51:41 +00:00
|
|
|
tmpRemovedPlayers.sort(LessThanPlayerHandStartMoney);
|
2010-08-28 14:34:02 +00:00
|
|
|
PlayerListConstIterator removed_i = tmpRemovedPlayers.begin();
|
|
|
|
|
PlayerListConstIterator removed_end = tmpRemovedPlayers.end();
|
2010-08-30 09:16:57 +00:00
|
|
|
PlayerListConstIterator next_removed_i = removed_i;
|
2010-08-29 16:51:41 +00:00
|
|
|
int currentRankCounter = 0;
|
2011-02-11 20:02:08 +00:00
|
|
|
while (removed_i != removed_end) {
|
2010-08-29 16:51:41 +00:00
|
|
|
++next_removed_i;
|
|
|
|
|
|
2010-08-28 14:34:02 +00:00
|
|
|
SetPlayerPlace((*removed_i)->getMyUniqueID(), currentRank);
|
2010-08-29 16:51:41 +00:00
|
|
|
++currentRankCounter;
|
2011-02-11 20:02:08 +00:00
|
|
|
if (next_removed_i != removed_end && (*removed_i)->getMyRoundStartCash() < (*next_removed_i)->getMyRoundStartCash()) {
|
2010-08-29 16:51:41 +00:00
|
|
|
currentRank -= currentRankCounter;
|
|
|
|
|
currentRankCounter = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removed_i = next_removed_i;
|
2010-08-28 14:34:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Last player is winner.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (activePlayers.size() == 1) {
|
2010-08-28 14:34:02 +00:00
|
|
|
SetPlayerPlace((*(activePlayers.begin()))->getMyUniqueID(), 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-08 10:23:40 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::SetPlayerPlace(unsigned playerId, int place)
|
|
|
|
|
{
|
|
|
|
|
RankingMap::iterator pos = m_rankingMap.find(playerId);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (pos != m_rankingMap.end()) {
|
2010-08-08 10:23:40 +00:00
|
|
|
(*pos).second.place = place;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-27 20:44:16 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::ReplaceRankingPlayer(unsigned oldPlayerId, unsigned newPlayerId)
|
|
|
|
|
{
|
|
|
|
|
RankingMap::iterator pos = m_rankingMap.find(oldPlayerId);
|
|
|
|
|
if (pos != m_rankingMap.end()) {
|
|
|
|
|
RankingData tmpData((*pos).second);
|
|
|
|
|
m_rankingMap[newPlayerId] = tmpData;
|
|
|
|
|
m_rankingMap.erase(pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-08 10:23:40 +00:00
|
|
|
void
|
2011-02-06 13:17:07 +00:00
|
|
|
ServerGame::StoreAndResetRanking()
|
2010-08-08 10:23:40 +00:00
|
|
|
{
|
|
|
|
|
// Store players in database.
|
2011-03-20 22:38:03 +00:00
|
|
|
RankingMap::const_iterator i = m_rankingMap.begin();
|
|
|
|
|
RankingMap::const_iterator end = m_rankingMap.end();
|
|
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i).second.dbid != DB_ID_INVALID) {
|
|
|
|
|
GetDatabase().SetGamePlayerPlace(GetId(), (*i).second.dbid, (*i).second.place);
|
2010-08-08 10:23:40 +00:00
|
|
|
}
|
2011-03-20 22:38:03 +00:00
|
|
|
++i;
|
2010-08-08 10:23:40 +00:00
|
|
|
}
|
2011-03-20 22:38:03 +00:00
|
|
|
GetDatabase().EndGame(GetId());
|
2010-08-08 10:23:40 +00:00
|
|
|
m_rankingMap.clear();
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-06 13:17:07 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::RemoveAutoLeavePlayers()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_autoLeavePlayerListMutex);
|
|
|
|
|
PlayerIdList::const_iterator i = m_autoLeavePlayerList.begin();
|
|
|
|
|
PlayerIdList::const_iterator end = m_autoLeavePlayerList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(*i);
|
2011-02-06 13:17:07 +00:00
|
|
|
// Only remove if the player was found.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (tmpSession)
|
2011-02-06 13:17:07 +00:00
|
|
|
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_ON_REQUEST);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
m_autoLeavePlayerList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGame::InternalEndGame()
|
|
|
|
|
{
|
|
|
|
|
StoreAndResetRanking();
|
|
|
|
|
m_game.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 19:10:07 +00:00
|
|
|
void
|
2011-12-16 22:39:24 +00:00
|
|
|
ServerGame::KickPlayer(unsigned playerId)
|
2011-11-13 19:10:07 +00:00
|
|
|
{
|
|
|
|
|
MarkPlayerAsKicked(playerId);
|
2011-11-13 15:36:01 +00:00
|
|
|
|
|
|
|
|
// Kick the network session from this game.
|
2011-11-13 14:28:54 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession(GetSessionManager().GetSessionByUniquePlayerId(playerId));
|
2007-11-10 21:23:22 +00:00
|
|
|
// Only kick if the player was found.
|
2011-11-13 14:28:54 +00:00
|
|
|
if (tmpSession) {
|
2007-11-10 21:23:22 +00:00
|
|
|
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED);
|
2011-11-13 14:28:54 +00:00
|
|
|
}
|
2008-12-23 01:34:32 +00:00
|
|
|
// KICKING COMPUTER PLAYERS IS BUGGY AND OCCASIONALLY CAUSES A CRASH
|
|
|
|
|
// Disabled for now.
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// boost::shared_ptr<PlayerData> tmpData(RemoveComputerPlayer(playerId));
|
|
|
|
|
// if (tmpData)
|
|
|
|
|
// RemovePlayerData(tmpData, NTF_NET_REMOVED_KICKED);
|
|
|
|
|
//}
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-06 00:18:36 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerGame::InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, unsigned timeoutSec)
|
2008-11-16 22:57:11 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (IsRunning() && byWhom->GetPlayerData()) {
|
2008-12-08 22:17:14 +00:00
|
|
|
// Retrieve only the number of human players.
|
2009-08-15 14:08:48 +00:00
|
|
|
size_t numPlayers = GetSessionManager().GetPlayerIdList(SessionData::Game).size();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (numPlayers > 2) {
|
2008-12-12 22:38:35 +00:00
|
|
|
// Check whether the player to be kicked exists.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (IsValidPlayer(playerIdWho)) {
|
2008-12-12 22:38:35 +00:00
|
|
|
// Lock the vote kick data.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!m_voteKickData) {
|
2008-12-12 22:38:35 +00:00
|
|
|
// Initiate a vote kick.
|
2011-03-10 20:55:46 +00:00
|
|
|
unsigned playerIdByWhom = byWhom->GetPlayerData()->GetUniqueId();
|
2008-12-12 22:38:35 +00:00
|
|
|
m_voteKickData.reset(new VoteKickData);
|
|
|
|
|
m_voteKickData->petitionId = m_curPetitionId++;
|
|
|
|
|
m_voteKickData->kickPlayerId = playerIdWho;
|
|
|
|
|
m_voteKickData->numVotesToKick = static_cast<int>(ceil(numPlayers / 3. * 2.));
|
|
|
|
|
m_voteKickData->timeLimitSec = timeoutSec + SERVER_KICK_TIMEOUT_ADD_DELAY_SEC;
|
|
|
|
|
// Consider first vote.
|
|
|
|
|
m_voteKickData->numVotesInFavourOfKicking = 1;
|
|
|
|
|
m_voteKickData->votedPlayerIds.push_back(playerIdByWhom);
|
2008-12-06 00:18:36 +00:00
|
|
|
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_StartKickPetitionMessage);
|
|
|
|
|
StartKickPetitionMessage *netStartPetition = netManage->mutable_startkickpetitionmessage();
|
2012-09-18 15:57:58 +02:00
|
|
|
netStartPetition->set_petitionid(m_voteKickData->petitionId);
|
|
|
|
|
netStartPetition->set_proposingplayerid(playerIdByWhom);
|
|
|
|
|
netStartPetition->set_kickplayerid(m_voteKickData->kickPlayerId);
|
|
|
|
|
netStartPetition->set_kicktimeoutsec(timeoutSec);
|
|
|
|
|
netStartPetition->set_numvotesneededtokick(m_voteKickData->numVotesToKick);
|
2009-08-02 15:11:40 +00:00
|
|
|
SendToAllPlayers(packet, SessionData::Game);
|
2010-10-19 13:13:39 +00:00
|
|
|
|
|
|
|
|
m_voteKickTimer.expires_from_now(
|
2014-03-29 16:13:53 +01:00
|
|
|
milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
|
2010-10-19 13:13:39 +00:00
|
|
|
m_voteKickTimer.async_wait(
|
|
|
|
|
boost::bind(
|
|
|
|
|
&ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error));
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2008-12-12 22:38:35 +00:00
|
|
|
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_OTHER_IN_PROGRESS);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2008-12-12 22:38:35 +00:00
|
|
|
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_INVALID_PLAYER_ID);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2008-12-06 00:18:36 +00:00
|
|
|
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_TOO_FEW_PLAYERS);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2008-12-06 00:18:36 +00:00
|
|
|
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_INVALID_STATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerGame::InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason)
|
2008-12-06 00:18:36 +00:00
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_AskKickDeniedMessage);
|
|
|
|
|
AskKickDeniedMessage *netKickDenied = netManage->mutable_askkickdeniedmessage();
|
2012-09-18 15:57:58 +02:00
|
|
|
netKickDenied->set_playerid(playerIdWho);
|
|
|
|
|
netKickDenied->set_kickdeniedreason(static_cast<AskKickDeniedMessage::KickDeniedReason>(reason));
|
2011-03-10 20:55:46 +00:00
|
|
|
GetLobbyThread().GetSender().Send(byWhom, packet);
|
2008-11-16 22:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-25 22:18:17 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerGame::InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, KickVote vote)
|
2008-11-25 22:18:17 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (IsRunning() && byWhom->GetPlayerData()) {
|
2008-12-07 11:04:42 +00:00
|
|
|
// Check whether this is the valid petition id.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_voteKickData && m_voteKickData->petitionId == petitionId) {
|
2008-12-07 11:04:42 +00:00
|
|
|
// Check whether the player already voted.
|
2011-03-10 20:55:46 +00:00
|
|
|
unsigned playerId = byWhom->GetPlayerData()->GetUniqueId();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (find(m_voteKickData->votedPlayerIds.begin(), m_voteKickData->votedPlayerIds.end(), playerId) == m_voteKickData->votedPlayerIds.end()) {
|
2008-12-07 11:04:42 +00:00
|
|
|
m_voteKickData->votedPlayerIds.push_back(playerId);
|
|
|
|
|
if (vote == KICK_VOTE_IN_FAVOUR)
|
|
|
|
|
m_voteKickData->numVotesInFavourOfKicking++;
|
|
|
|
|
else
|
|
|
|
|
m_voteKickData->numVotesAgainstKicking++;
|
2008-12-07 12:22:35 +00:00
|
|
|
// Send update notification.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_KickPetitionUpdateMessage);
|
|
|
|
|
KickPetitionUpdateMessage *netKickUpdate = netManage->mutable_kickpetitionupdatemessage();
|
2012-09-18 15:57:58 +02:00
|
|
|
netKickUpdate->set_petitionid(m_voteKickData->petitionId);
|
|
|
|
|
netKickUpdate->set_numvotesagainstkicking(m_voteKickData->numVotesAgainstKicking);
|
|
|
|
|
netKickUpdate->set_numvotesinfavourofkicking(m_voteKickData->numVotesInFavourOfKicking);
|
|
|
|
|
netKickUpdate->set_numvotesneededtokick(m_voteKickData->numVotesToKick);
|
2009-08-02 15:11:40 +00:00
|
|
|
SendToAllPlayers(packet, SessionData::Game);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2008-12-07 11:04:42 +00:00
|
|
|
InternalDenyVoteKick(byWhom, petitionId, VOTE_DENIED_ALREADY_VOTED);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2008-12-07 11:04:42 +00:00
|
|
|
InternalDenyVoteKick(byWhom, petitionId, VOTE_DENIED_INVALID_PETITION);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else
|
2009-08-02 15:11:40 +00:00
|
|
|
InternalDenyVoteKick(byWhom, petitionId, VOTE_DENIED_INVALID_PETITION);
|
2008-12-07 11:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerGame::InternalDenyVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, DenyVoteReason reason)
|
2008-12-07 11:04:42 +00:00
|
|
|
{
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_VoteKickReplyMessage);
|
|
|
|
|
VoteKickReplyMessage *netVoteReply = netManage->mutable_votekickreplymessage();
|
2012-09-18 15:57:58 +02:00
|
|
|
netVoteReply->set_petitionid(petitionId);
|
|
|
|
|
switch(reason) {
|
2012-12-21 01:01:01 +01:00
|
|
|
case VOTE_DENIED_ALREADY_VOTED :
|
|
|
|
|
netVoteReply->set_votekickreplytype(VoteKickReplyMessage::voteKickDeniedAlreadyVoted);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
netVoteReply->set_votekickreplytype(VoteKickReplyMessage::voteKickDeniedInvalid);
|
|
|
|
|
break;
|
2012-09-18 15:57:58 +02:00
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
GetLobbyThread().GetSender().Send(byWhom, packet);
|
2008-11-25 22:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
PlayerDataList
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetFullPlayerDataList() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
PlayerDataList playerList(GetSessionManager().GetPlayerDataList());
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
copy(m_computerPlayerList.begin(), m_computerPlayerList.end(), back_inserter(playerList));
|
|
|
|
|
|
|
|
|
|
return playerList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerData>
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetPlayerDataByUniqueId(unsigned playerId) const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer;
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> session = GetSessionManager().GetSessionByUniquePlayerId(playerId);
|
2011-09-11 17:41:56 +00:00
|
|
|
if (session) {
|
|
|
|
|
tmpPlayer = session->GetPlayerData();
|
|
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!tmpPlayer) {
|
2007-10-18 17:40:12 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
PlayerDataList::const_iterator i = m_computerPlayerList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = m_computerPlayerList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i)->GetUniqueId() == playerId) {
|
2007-10-18 17:40:12 +00:00
|
|
|
tmpPlayer = *i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerIdList
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetPlayerIdList() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-08-15 14:08:48 +00:00
|
|
|
PlayerIdList idList(GetSessionManager().GetPlayerIdList(SessionData::Game));
|
2007-10-18 17:40:12 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
PlayerDataList::const_iterator i = m_computerPlayerList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = m_computerPlayerList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2007-10-18 17:40:12 +00:00
|
|
|
idList.push_back((*i)->GetUniqueId());
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return idList;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-29 16:23:10 +02:00
|
|
|
PlayerIdList
|
|
|
|
|
ServerGame::GetSpectatorIdList() const
|
|
|
|
|
{
|
2013-09-01 18:09:15 +02:00
|
|
|
return GetSessionManager().GetPlayerIdList(SessionData::Spectating | SessionData::SpectatorWaiting);
|
2013-06-29 16:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
bool
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::IsPlayerConnected(const std::string &name) const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return GetSessionManager().IsPlayerConnected(name);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 18:03:08 +00:00
|
|
|
bool
|
|
|
|
|
ServerGame::IsPlayerConnected(unsigned playerId) const
|
|
|
|
|
{
|
|
|
|
|
return GetSessionManager().IsPlayerConnected(playerId);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-02 19:50:49 +00:00
|
|
|
bool
|
|
|
|
|
ServerGame::IsClientAddressConnected(const std::string &clientAddress) const
|
|
|
|
|
{
|
|
|
|
|
return GetSessionManager().IsClientAddressConnected(clientAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-28 17:14:03 +00:00
|
|
|
boost::shared_ptr<PlayerInterface>
|
|
|
|
|
ServerGame::GetPlayerInterfaceFromGame(const std::string &playerName)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer;
|
2011-10-03 08:03:58 +00:00
|
|
|
if (m_game) {
|
2011-08-28 17:14:03 +00:00
|
|
|
tmpPlayer = m_game->getPlayerByName(playerName);
|
|
|
|
|
}
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-08 13:02:29 +00:00
|
|
|
boost::shared_ptr<PlayerInterface>
|
|
|
|
|
ServerGame::GetPlayerInterfaceFromGame(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer;
|
|
|
|
|
if (m_game) {
|
|
|
|
|
tmpPlayer = m_game->getPlayerByUniqueId(playerId);
|
|
|
|
|
}
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
bool
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::IsRunning() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_game.get() != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetAdminPlayerId() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_adminPlayerId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::SetAdminPlayerId(unsigned playerId)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
m_adminPlayerId = playerId;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:10:37 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::AddPlayerInvitation(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_playerInvitationListMutex);
|
|
|
|
|
m_playerInvitationList.push_back(playerId);
|
2010-03-30 18:03:08 +00:00
|
|
|
m_playerInvitationList.sort();
|
|
|
|
|
m_playerInvitationList.unique();
|
2010-03-30 17:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGame::RemovePlayerInvitation(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_playerInvitationListMutex);
|
|
|
|
|
m_playerInvitationList.remove(playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ServerGame::IsPlayerInvited(unsigned playerId) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
boost::mutex::scoped_lock lock(m_playerInvitationListMutex);
|
|
|
|
|
PlayerIdList::const_iterator pos = find(m_playerInvitationList.begin(), m_playerInvitationList.end(), playerId);
|
|
|
|
|
if (pos != m_playerInvitationList.end())
|
|
|
|
|
retVal = true;
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-25 21:54:26 +00:00
|
|
|
void
|
2011-02-06 13:17:07 +00:00
|
|
|
ServerGame::SetPlayerAutoLeaveOnFinish(unsigned playerId)
|
2010-12-25 21:54:26 +00:00
|
|
|
{
|
2011-02-06 13:17:07 +00:00
|
|
|
boost::mutex::scoped_lock lock(m_autoLeavePlayerListMutex);
|
|
|
|
|
m_autoLeavePlayerList.push_back(playerId);
|
2010-12-25 21:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 20:38:18 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::AddRejoinPlayer(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_rejoinPlayerListMutex);
|
|
|
|
|
m_rejoinPlayerList.push_back(playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerIdList
|
|
|
|
|
ServerGame::GetAndResetRejoinPlayers()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_rejoinPlayerListMutex);
|
|
|
|
|
PlayerIdList tmpList(m_rejoinPlayerList);
|
|
|
|
|
m_rejoinPlayerList.clear();
|
|
|
|
|
return tmpList;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:56:41 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::AddReactivatePlayer(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_reactivatePlayerListMutex);
|
|
|
|
|
m_reactivatePlayerList.push_back(playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerIdList
|
|
|
|
|
ServerGame::GetAndResetReactivatePlayers()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_reactivatePlayerListMutex);
|
|
|
|
|
PlayerIdList tmpList(m_reactivatePlayerList);
|
|
|
|
|
m_reactivatePlayerList.clear();
|
|
|
|
|
return tmpList;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-29 16:23:10 +02:00
|
|
|
void
|
|
|
|
|
ServerGame::AddNewSpectator(unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_newSpectatorListMutex);
|
|
|
|
|
m_newSpectatorList.push_back(playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerIdList
|
|
|
|
|
ServerGame::GetAndResetNewSpectators()
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_newSpectatorListMutex);
|
|
|
|
|
PlayerIdList tmpList(m_newSpectatorList);
|
|
|
|
|
m_newSpectatorList.clear();
|
|
|
|
|
return tmpList;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-09 10:22:24 +00:00
|
|
|
void
|
|
|
|
|
ServerGame::SetNameReported()
|
|
|
|
|
{
|
|
|
|
|
m_isNameReported = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ServerGame::IsNameReported() const
|
|
|
|
|
{
|
|
|
|
|
return m_isNameReported;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
m_computerPlayerList.push_back(player);
|
|
|
|
|
}
|
|
|
|
|
GetLobbyThread().AddComputerPlayer(player);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-08 23:06:11 +00:00
|
|
|
boost::shared_ptr<PlayerData>
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::RemoveComputerPlayer(unsigned playerId)
|
2008-12-08 23:06:11 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer;
|
|
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
PlayerDataList::iterator i = m_computerPlayerList.begin();
|
|
|
|
|
PlayerDataList::iterator end = m_computerPlayerList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
|
|
|
|
if ((*i)->GetUniqueId() == playerId) {
|
2008-12-08 23:06:11 +00:00
|
|
|
tmpPlayer = *i;
|
|
|
|
|
m_computerPlayerList.erase(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
GetLobbyThread().RemoveComputerPlayer(tmpPlayer);
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::IsComputerPlayerActive(unsigned playerId) const
|
2008-12-08 23:06:11 +00:00
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
PlayerDataList::const_iterator i = m_computerPlayerList.begin();
|
|
|
|
|
PlayerDataList::const_iterator end = m_computerPlayerList.end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2008-12-08 23:06:11 +00:00
|
|
|
if ((*i)->GetUniqueId() == playerId)
|
|
|
|
|
retVal = true;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::ResetComputerPlayerList()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
|
|
|
|
|
|
|
|
|
PlayerDataList::iterator i = m_computerPlayerList.begin();
|
|
|
|
|
PlayerDataList::iterator end = m_computerPlayerList.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2007-10-18 17:40:12 +00:00
|
|
|
GetLobbyThread().RemoveComputerPlayer(*i);
|
2013-08-11 13:25:26 +02:00
|
|
|
RemovePlayerData(*i, NTF_NET_REMOVED_ON_REQUEST, false);
|
2007-10-18 17:40:12 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_computerPlayerList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-12-11 14:54:17 +00:00
|
|
|
ServerGame::RemoveSession(boost::shared_ptr<SessionData> session, int reason)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!session)
|
2007-11-10 22:18:31 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (GetSessionManager().RemoveSession(session->GetId())) {
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayerData = session->GetPlayerData();
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpPlayerData && !tmpPlayerData->GetName().empty()) {
|
2013-08-11 13:25:26 +02:00
|
|
|
RemovePlayerData(tmpPlayerData, reason, session->GetState() == SessionData::Spectating || session->GetState() == SessionData::SpectatorWaiting);
|
2010-09-26 06:58:49 +00:00
|
|
|
}
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-08-11 13:25:26 +02:00
|
|
|
ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason, bool spectateOnly)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2011-02-11 20:02:08 +00:00
|
|
|
if (player->IsGameAdmin()) {
|
2007-10-18 17:40:12 +00:00
|
|
|
// Find new admin for the game
|
|
|
|
|
PlayerDataList playerList(GetSessionManager().GetPlayerDataList());
|
2011-02-11 20:02:08 +00:00
|
|
|
if (!playerList.empty()) {
|
2007-10-18 17:40:12 +00:00
|
|
|
boost::shared_ptr<PlayerData> newAdmin = playerList.front();
|
|
|
|
|
SetAdminPlayerId(newAdmin->GetUniqueId());
|
2010-03-26 21:41:35 +00:00
|
|
|
newAdmin->SetGameAdmin(true);
|
2008-03-06 20:44:37 +00:00
|
|
|
// Notify game state on admin change
|
2009-06-12 15:48:34 +00:00
|
|
|
GetState().NotifyGameAdminChanged(shared_from_this());
|
2007-10-18 17:40:12 +00:00
|
|
|
// Send "Game Admin Changed" to clients.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> adminChanged(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
adminChanged->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = adminChanged->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_GameAdminChangedMessage);
|
|
|
|
|
GameAdminChangedMessage *netGameAdmin = netManage->mutable_gameadminchangedmessage();
|
2012-09-18 15:57:58 +02:00
|
|
|
netGameAdmin->set_newadminplayerid(newAdmin->GetUniqueId()); // Choose next player as admin.
|
2009-06-07 08:51:43 +00:00
|
|
|
GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), adminChanged, SessionData::Game);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
GetLobbyThread().NotifyGameAdminChanged(GetId(), newAdmin->GetUniqueId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Reset player rights.
|
2010-03-26 21:41:35 +00:00
|
|
|
player->SetGameAdmin(false);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
// Send "Player Left" to clients.
|
2012-09-18 15:57:58 +02:00
|
|
|
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacket);
|
2014-12-28 01:03:06 +01:00
|
|
|
thisPlayerLeft->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
|
|
|
|
|
GameMessage *netGame = thisPlayerLeft->GetMsg()->mutable_gamemessage();
|
|
|
|
|
netGame->set_gameid(GetId());
|
|
|
|
|
netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
|
|
|
|
|
GameManagementMessage *netManage = netGame->mutable_gamemanagementmessage();
|
|
|
|
|
|
2013-08-11 13:25:26 +02:00
|
|
|
GamePlayerLeftMessage::GamePlayerLeftReason netReason = GamePlayerLeftMessage::leftError;
|
2011-02-11 20:02:08 +00:00
|
|
|
switch (reason) {
|
|
|
|
|
case NTF_NET_REMOVED_ON_REQUEST :
|
2013-08-11 13:25:26 +02:00
|
|
|
netReason = GamePlayerLeftMessage::leftOnRequest;
|
2011-02-11 20:02:08 +00:00
|
|
|
break;
|
|
|
|
|
case NTF_NET_REMOVED_KICKED :
|
2013-08-11 13:25:26 +02:00
|
|
|
netReason = GamePlayerLeftMessage::leftKicked;
|
2011-02-11 20:02:08 +00:00
|
|
|
break;
|
2009-08-02 15:11:40 +00:00
|
|
|
}
|
2013-08-11 13:25:26 +02:00
|
|
|
|
|
|
|
|
if (spectateOnly) {
|
2014-12-28 01:03:06 +01:00
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_GameSpectatorLeftMessage);
|
|
|
|
|
GameSpectatorLeftMessage *netPlayerLeft = netManage->mutable_gamespectatorleftmessage();
|
2013-08-11 13:25:26 +02:00
|
|
|
netPlayerLeft->set_playerid(player->GetUniqueId());
|
|
|
|
|
netPlayerLeft->set_gamespectatorleftreason(netReason);
|
|
|
|
|
} else {
|
2014-12-28 01:03:06 +01:00
|
|
|
netManage->set_messagetype(GameManagementMessage::Type_GamePlayerLeftMessage);
|
|
|
|
|
GamePlayerLeftMessage *netPlayerLeft = netManage->mutable_gameplayerleftmessage();
|
2013-08-11 13:25:26 +02:00
|
|
|
netPlayerLeft->set_playerid(player->GetUniqueId());
|
|
|
|
|
netPlayerLeft->set_gameplayerleftreason(netReason);
|
|
|
|
|
}
|
2013-09-01 18:09:15 +02:00
|
|
|
GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), thisPlayerLeft, SessionData::Game | SessionData::Spectating | SessionData::SpectatorWaiting);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2010-09-04 20:08:40 +00:00
|
|
|
GetState().NotifySessionRemoved(shared_from_this());
|
2013-08-11 13:25:26 +02:00
|
|
|
if (spectateOnly) {
|
|
|
|
|
GetLobbyThread().NotifySpectatorLeftGame(GetId(), player->GetUniqueId());
|
|
|
|
|
} else {
|
|
|
|
|
GetLobbyThread().NotifyPlayerLeftGame(GetId(), player->GetUniqueId());
|
|
|
|
|
}
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerGame::SessionError(boost::shared_ptr<SessionData> session, int errorCode)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!session)
|
2007-11-10 22:18:31 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
2011-12-11 14:54:17 +00:00
|
|
|
RemoveSession(session, NTF_NET_INTERNAL);
|
2007-10-18 17:40:12 +00:00
|
|
|
GetLobbyThread().SessionError(session, errorCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
ServerGame::MoveSessionToLobby(boost::shared_ptr<SessionData> session, int reason)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2011-12-11 14:54:17 +00:00
|
|
|
RemoveSession(session, reason);
|
2008-04-02 21:41:39 +00:00
|
|
|
// Reset ready flag - just in case it is set, player may leave at any time.
|
2011-03-10 20:55:46 +00:00
|
|
|
session->ResetReadyFlag();
|
2011-03-10 21:53:25 +00:00
|
|
|
GetLobbyThread().ReAddSession(session, reason, GetId());
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::RemoveDisconnectedPlayers()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
// This should only be called between hands.
|
2011-02-11 20:02:08 +00:00
|
|
|
if (m_game) {
|
2011-02-08 16:41:46 +00:00
|
|
|
PlayerList tmpList(m_game->getSeatsList());
|
|
|
|
|
PlayerListIterator i = tmpList->begin();
|
|
|
|
|
PlayerListIterator end = tmpList->end();
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2007-10-18 17:40:12 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
2008-12-08 23:06:11 +00:00
|
|
|
if ((tmpPlayer->getMyType() == PLAYER_TYPE_HUMAN && !GetSessionManager().IsPlayerConnected(tmpPlayer->getMyUniqueID()))
|
2011-02-11 20:02:08 +00:00
|
|
|
|| (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER && !IsComputerPlayerActive(tmpPlayer->getMyUniqueID()))) {
|
2007-10-18 17:40:12 +00:00
|
|
|
// Setting player cash to 0 will deactivate the player.
|
2011-11-13 14:28:54 +00:00
|
|
|
// The player should only be deactivated if rejoin is not possible.
|
|
|
|
|
if (tmpPlayer->isKicked() || tmpPlayer->getMyGuid().empty()) {
|
|
|
|
|
tmpPlayer->setMyCash(0);
|
2011-12-11 19:37:51 +00:00
|
|
|
tmpPlayer->setMyGuid("");
|
2011-11-13 14:28:54 +00:00
|
|
|
}
|
2011-12-11 19:37:51 +00:00
|
|
|
tmpPlayer->setIsSessionActive(false);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 10:04:42 +00:00
|
|
|
int
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetCurNumberOfPlayers() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2011-04-10 10:04:42 +00:00
|
|
|
return (int)GetFullPlayerDataList().size();
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-22 19:42:48 +00:00
|
|
|
ServerGame::AssignPlayerNumbers(PlayerDataList &playerList)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
int playerNumber = 0;
|
|
|
|
|
|
|
|
|
|
PlayerDataList::iterator player_i = playerList.begin();
|
|
|
|
|
PlayerDataList::iterator player_end = playerList.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (player_i != player_end) {
|
2007-10-18 17:40:12 +00:00
|
|
|
(*player_i)->SetNumber(playerNumber);
|
|
|
|
|
++playerNumber;
|
|
|
|
|
++player_i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-12 22:38:35 +00:00
|
|
|
bool
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::IsValidPlayer(unsigned playerId) const
|
2008-12-12 22:38:35 +00:00
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
const PlayerIdList list(GetPlayerIdList());
|
|
|
|
|
if (find(list.begin(), list.end(), playerId) != list.end())
|
|
|
|
|
retVal = true;
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
SessionManager &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetSessionManager()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_sessionManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SessionManager &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetSessionManager() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_sessionManager;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-27 18:09:19 +02:00
|
|
|
const ServerDelayTime
|
|
|
|
|
ServerGame::GetServerDelayTime() const
|
|
|
|
|
{
|
|
|
|
|
return m_serverDelayTime;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-07 23:06:59 +00:00
|
|
|
ServerDBInterface &
|
|
|
|
|
ServerGame::GetDatabase()
|
|
|
|
|
{
|
|
|
|
|
assert(m_database);
|
|
|
|
|
return *m_database;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
ServerLobbyThread &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetLobbyThread()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-06-12 15:48:34 +00:00
|
|
|
assert(m_lobbyThread);
|
|
|
|
|
return *m_lobbyThread;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerCallback &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetCallback()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerGameState &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetState()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
assert(m_curState);
|
|
|
|
|
return *m_curState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::SetState(ServerGameState &newState)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-05-31 13:47:10 +00:00
|
|
|
if (m_curState)
|
2009-06-12 15:48:34 +00:00
|
|
|
m_curState->Exit(shared_from_this());
|
2009-05-31 13:17:02 +00:00
|
|
|
m_curState = &newState;
|
2009-06-12 15:48:34 +00:00
|
|
|
m_curState->Enter(shared_from_this());
|
2009-05-31 13:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-29 16:13:53 +01:00
|
|
|
boost::asio::steady_timer &
|
2010-09-04 20:08:40 +00:00
|
|
|
ServerGame::GetStateTimer1()
|
2009-05-31 13:17:02 +00:00
|
|
|
{
|
2010-09-04 20:08:40 +00:00
|
|
|
return m_stateTimer1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 16:13:53 +01:00
|
|
|
boost::asio::steady_timer &
|
2010-09-04 20:08:40 +00:00
|
|
|
ServerGame::GetStateTimer2()
|
|
|
|
|
{
|
|
|
|
|
return m_stateTimer2;
|
2008-03-06 20:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
Game &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetGame()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
assert(m_game.get());
|
|
|
|
|
return *m_game;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Game &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetGame() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
assert(m_game.get());
|
|
|
|
|
return *m_game;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const GameData &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetGameData() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_gameData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StartData &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetStartData() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_startData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::SetStartData(const StartData &startData)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
m_startData = startData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::IsPasswordProtected() const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return !m_password.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::CheckPassword(const string &password) const
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return (password == m_password);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-01 20:15:49 +00:00
|
|
|
bool
|
2011-02-06 10:37:40 +00:00
|
|
|
ServerGame::CheckSettings(const GameData &data, const string &password, ServerMode mode)
|
2010-08-01 20:15:49 +00:00
|
|
|
{
|
|
|
|
|
bool retVal = true;
|
2014-07-11 18:15:40 +02:00
|
|
|
if (mode != SERVER_MODE_LAN && mode != SERVER_MODE_LAN_LOCAL) {
|
2011-02-11 20:02:08 +00:00
|
|
|
if (data.playerActionTimeoutSec < 5) {
|
2011-02-06 10:37:40 +00:00
|
|
|
retVal = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
if (data.gameType == GAME_TYPE_RANKING) {
|
2010-08-01 20:15:49 +00:00
|
|
|
if ((data.startMoney != RANKING_GAME_START_CASH)
|
2011-02-11 20:02:08 +00:00
|
|
|
|| (data.maxNumberOfPlayers != RANKING_GAME_NUMBER_OF_PLAYERS)
|
|
|
|
|
|| (data.firstSmallBlind != RANKING_GAME_START_SBLIND)
|
|
|
|
|
|| (data.raiseIntervalMode != RAISE_ON_HANDNUMBER)
|
|
|
|
|
|| (data.raiseMode != DOUBLE_BLINDS)
|
|
|
|
|
|| (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND)
|
2013-10-27 00:41:13 +02:00
|
|
|
|| (!password.empty())
|
|
|
|
|
|| (!data.allowSpectators)) {
|
2010-08-01 20:15:49 +00:00
|
|
|
retVal = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
GuiInterface &
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetGui()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame::GetNextGameNum()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
return m_gameNum++;
|
|
|
|
|
}
|
|
|
|
|
|