2007-10-18 17:40:12 +00:00
|
|
|
/***************************************************************************
|
2009-05-30 22:20:40 +00:00
|
|
|
* Copyright (C) 2007-2009 by Lothar May *
|
2007-10-18 17:40:12 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation; either version 2 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 General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <net/servergamestate.h>
|
|
|
|
|
#include <net/servergamethread.h>
|
|
|
|
|
#include <net/serverlobbythread.h>
|
|
|
|
|
#include <net/receiverhelper.h>
|
2009-05-10 22:21:20 +00:00
|
|
|
#include <net/senderhelper.h>
|
2007-10-18 17:40:12 +00:00
|
|
|
#include <net/netpacket.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
2007-10-18 20:36:49 +00:00
|
|
|
#include <net/serverexception.h>
|
2007-10-18 17:40:12 +00:00
|
|
|
#include <gamedata.h>
|
|
|
|
|
#include <game.h>
|
|
|
|
|
#include <playerinterface.h>
|
|
|
|
|
#include <handinterface.h>
|
|
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2008-04-24 22:35:59 +00:00
|
|
|
//#define SERVER_TEST
|
2007-10-29 09:18:34 +00:00
|
|
|
|
|
|
|
|
#ifdef SERVER_TEST
|
|
|
|
|
#define SERVER_DELAY_NEXT_HAND_SEC 0
|
|
|
|
|
#define SERVER_DELAY_NEXT_GAME_SEC 0
|
|
|
|
|
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 0
|
|
|
|
|
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 0
|
|
|
|
|
#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 0
|
|
|
|
|
#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 0
|
|
|
|
|
#define SERVER_SHOW_CARDS_DELAY_SEC 0
|
|
|
|
|
#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 0
|
|
|
|
|
#define SERVER_COMPUTER_ACTION_DELAY_SEC 0
|
|
|
|
|
#else
|
|
|
|
|
#define SERVER_DELAY_NEXT_HAND_SEC 10
|
|
|
|
|
#define SERVER_DELAY_NEXT_GAME_SEC 10
|
|
|
|
|
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5
|
|
|
|
|
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2
|
|
|
|
|
#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2
|
|
|
|
|
#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 2
|
|
|
|
|
#define SERVER_SHOW_CARDS_DELAY_SEC 2
|
|
|
|
|
#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2
|
|
|
|
|
#define SERVER_COMPUTER_ACTION_DELAY_SEC 2
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-12-06 00:18:36 +00:00
|
|
|
#define SERVER_START_GAME_TIMEOUT_SEC 10
|
2008-03-06 20:44:37 +00:00
|
|
|
#define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60
|
2008-03-09 23:32:45 +00:00
|
|
|
#define SERVER_GAME_ADMIN_TIMEOUT_SEC 300 // 5 min, MUST be > SERVER_GAME_ADMIN_WARNING_REMAINING_SEC
|
2008-11-16 22:57:11 +00:00
|
|
|
#define SERVER_VOTE_KICK_TIMEOUT_SEC 30
|
2009-05-30 22:20:40 +00:00
|
|
|
#define SERVER_LOOP_DELAY_MSEC 20
|
2008-03-06 20:44:37 +00:00
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
// Helper functions
|
|
|
|
|
// TODO: these are hacks.
|
|
|
|
|
|
|
|
|
|
static void SendPlayerAction(ServerGameThread &server, boost::shared_ptr<PlayerInterface> player)
|
|
|
|
|
{
|
2007-11-10 22:18:31 +00:00
|
|
|
if (!player.get())
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
|
|
|
|
NetPacketPlayersActionDone::Data actionDoneData;
|
|
|
|
|
actionDoneData.gameState = server.GetCurRound();
|
|
|
|
|
actionDoneData.playerId = player->getMyUniqueID();
|
|
|
|
|
actionDoneData.playerAction = static_cast<PlayerAction>(player->getMyAction());
|
|
|
|
|
actionDoneData.totalPlayerBet = player->getMySet();
|
|
|
|
|
actionDoneData.playerMoney = player->getMyCash();
|
|
|
|
|
actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet();
|
2007-11-18 00:06:14 +00:00
|
|
|
actionDoneData.minimumRaise = server.GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise();
|
2007-10-18 17:40:12 +00:00
|
|
|
static_cast<NetPacketPlayersActionDone *>(notifyActionDone.get())->SetData(actionDoneData);
|
|
|
|
|
server.SendToAllPlayers(notifyActionDone, SessionData::Game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SendNewRoundCards(ServerGameThread &server, Game &curGame, int state)
|
|
|
|
|
{
|
|
|
|
|
// TODO: no switch needed here if game states are polymorphic
|
|
|
|
|
switch(state) {
|
|
|
|
|
case GAME_STATE_PREFLOP: {
|
|
|
|
|
// nothing to do
|
|
|
|
|
} break;
|
|
|
|
|
case GAME_STATE_FLOP: {
|
|
|
|
|
// deal flop cards
|
|
|
|
|
int cards[5];
|
|
|
|
|
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealFlopCards);
|
|
|
|
|
NetPacketDealFlopCards::Data notifyCardsData;
|
|
|
|
|
for (int num = 0; num < 3; num++)
|
|
|
|
|
notifyCardsData.flopCards[num] = static_cast<u_int16_t>(cards[num]);
|
|
|
|
|
static_cast<NetPacketDealFlopCards *>(notifyCards.get())->SetData(notifyCardsData);
|
|
|
|
|
server.SendToAllPlayers(notifyCards, SessionData::Game);
|
|
|
|
|
} break;
|
|
|
|
|
case GAME_STATE_TURN: {
|
|
|
|
|
// deal turn card
|
|
|
|
|
int cards[5];
|
|
|
|
|
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealTurnCard);
|
|
|
|
|
NetPacketDealTurnCard::Data notifyCardsData;
|
|
|
|
|
notifyCardsData.turnCard = static_cast<u_int16_t>(cards[3]);
|
|
|
|
|
static_cast<NetPacketDealTurnCard *>(notifyCards.get())->SetData(notifyCardsData);
|
|
|
|
|
server.SendToAllPlayers(notifyCards, SessionData::Game);
|
|
|
|
|
} break;
|
|
|
|
|
case GAME_STATE_RIVER: {
|
|
|
|
|
// deal river card
|
|
|
|
|
int cards[5];
|
|
|
|
|
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealRiverCard);
|
|
|
|
|
NetPacketDealRiverCard::Data notifyCardsData;
|
|
|
|
|
notifyCardsData.riverCard = static_cast<u_int16_t>(cards[4]);
|
|
|
|
|
static_cast<NetPacketDealRiverCard *>(notifyCards.get())->SetData(notifyCardsData);
|
|
|
|
|
server.SendToAllPlayers(notifyCards, SessionData::Game);
|
|
|
|
|
} break;
|
|
|
|
|
default: {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
static void StartNewHand(ServerGameThread &server)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
// Initialize hand.
|
|
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
curGame.initHand();
|
|
|
|
|
|
|
|
|
|
// HACK: Skip GUI notification run
|
|
|
|
|
curGame.getCurrentHand()->getFlop()->skipFirstRunGui();
|
|
|
|
|
curGame.getCurrentHand()->getTurn()->skipFirstRunGui();
|
|
|
|
|
curGame.getCurrentHand()->getRiver()->skipFirstRunGui();
|
|
|
|
|
|
|
|
|
|
// Consider all players, even inactive.
|
|
|
|
|
PlayerListIterator i = curGame.getSeatsList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getSeatsList()->end();
|
|
|
|
|
|
|
|
|
|
// Send cards to all players.
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
// also send to inactive players, but not to disconnected players.
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
|
|
|
|
if (tmpPlayer->getNetSessionData().get())
|
|
|
|
|
{
|
|
|
|
|
int cards[2];
|
|
|
|
|
tmpPlayer->getMyCards(cards);
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyCards(new NetPacketHandStart);
|
|
|
|
|
NetPacketHandStart::Data handStartData;
|
|
|
|
|
handStartData.yourCards[0] = static_cast<unsigned>(cards[0]);
|
|
|
|
|
handStartData.yourCards[1] = static_cast<unsigned>(cards[1]);
|
|
|
|
|
handStartData.smallBlind = curGame.getCurrentHand()->getSmallBlind();
|
|
|
|
|
static_cast<NetPacketHandStart *>(notifyCards.get())->SetData(handStartData);
|
|
|
|
|
|
2009-01-07 21:52:16 +00:00
|
|
|
tmpPlayer->getNetSessionData()->GetSender().Send(tmpPlayer->getNetSessionData(), notifyCards);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start hand.
|
|
|
|
|
curGame.startHand();
|
|
|
|
|
|
|
|
|
|
// Auto small blind / big blind at the beginning of hand.
|
|
|
|
|
i = curGame.getActivePlayerList()->begin();
|
|
|
|
|
end = curGame.getActivePlayerList()->end();
|
|
|
|
|
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
|
|
|
|
if (tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> notifySmallBlind(new NetPacketPlayersActionDone);
|
|
|
|
|
NetPacketPlayersActionDone::Data actionDoneData;
|
|
|
|
|
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
|
|
|
|
|
actionDoneData.playerId = tmpPlayer->getMyUniqueID();
|
|
|
|
|
actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction();
|
|
|
|
|
actionDoneData.totalPlayerBet = tmpPlayer->getMySet();
|
|
|
|
|
actionDoneData.playerMoney = tmpPlayer->getMyCash();
|
|
|
|
|
actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet();
|
2007-11-18 00:21:04 +00:00
|
|
|
actionDoneData.minimumRaise = server.GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise();
|
2007-10-18 17:40:12 +00:00
|
|
|
static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
|
|
|
|
|
server.SendToAllPlayers(notifySmallBlind, SessionData::Game);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = curGame.getActivePlayerList()->begin();
|
|
|
|
|
end = curGame.getActivePlayerList()->end();
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
|
|
|
|
if (tmpPlayer->getMyButton() == BUTTON_BIG_BLIND)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyBigBlind(new NetPacketPlayersActionDone);
|
|
|
|
|
NetPacketPlayersActionDone::Data actionDoneData;
|
|
|
|
|
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
|
|
|
|
|
actionDoneData.playerId = tmpPlayer->getMyUniqueID();
|
|
|
|
|
actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction();
|
|
|
|
|
actionDoneData.totalPlayerBet = tmpPlayer->getMySet();
|
|
|
|
|
actionDoneData.playerMoney = tmpPlayer->getMyCash();
|
|
|
|
|
actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet();
|
2007-11-18 00:21:04 +00:00
|
|
|
actionDoneData.minimumRaise = server.GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise();
|
2007-10-18 17:40:12 +00:00
|
|
|
static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
|
|
|
|
|
server.SendToAllPlayers(notifyBigBlind, SessionData::Game);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
2009-05-30 22:20:40 +00:00
|
|
|
}
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
static void PerformPlayerAction(ServerGameThread &server, boost::shared_ptr<PlayerInterface> player, PlayerAction action, int bet)
|
|
|
|
|
{
|
|
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
if (!player.get())
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
|
|
|
|
|
player->setMyAction(action);
|
|
|
|
|
// Only change the player bet if action is not fold/check
|
|
|
|
|
if (action != PLAYER_ACTION_FOLD && action != PLAYER_ACTION_CHECK)
|
|
|
|
|
{
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
player->setMySet(bet);
|
|
|
|
|
|
|
|
|
|
// update minimumRaise
|
|
|
|
|
switch(action) {
|
|
|
|
|
case PLAYER_ACTION_BET: {
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(bet);
|
|
|
|
|
} break;
|
|
|
|
|
case PLAYER_ACTION_RAISE: {
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet());
|
|
|
|
|
} break;
|
|
|
|
|
case PLAYER_ACTION_ALLIN: {
|
|
|
|
|
if(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() > curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise()) {
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet());
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
default: {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update highestSet
|
|
|
|
|
if (player->getMySet() > curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet())
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->setHighestSet(player->getMySet());
|
|
|
|
|
// Update total sets.
|
|
|
|
|
curGame.getCurrentHand()->getBoard()->collectSets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SendPlayerAction(server, player);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
ServerGameState::~ServerGameState()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AbstractServerGameStateReceiving::AbstractServerGameStateReceiving(ServerGameThread &serverGame)
|
|
|
|
|
: ServerGameState(serverGame)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractServerGameStateReceiving::~AbstractServerGameStateReceiving()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2009-05-30 22:20:40 +00:00
|
|
|
AbstractServerGameStateReceiving::ProcessPacket(SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
|
|
|
|
{
|
|
|
|
|
// This is the receive loop for the server.
|
|
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
|
|
|
|
|
if (packet->IsClientActivity())
|
|
|
|
|
session.sessionData->ResetActivityTimer();
|
|
|
|
|
if (packet->ToNetPacketRetrievePlayerInfo())
|
|
|
|
|
{
|
|
|
|
|
// Delegate to Lobby.
|
|
|
|
|
GetServerGame().GetLobbyThread().HandleGameRetrievePlayerInfo(session, *packet->ToNetPacketRetrievePlayerInfo());
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketRetrieveAvatar())
|
|
|
|
|
{
|
|
|
|
|
// Delegate to Lobby.
|
|
|
|
|
GetServerGame().GetLobbyThread().HandleGameRetrieveAvatar(session, *packet->ToNetPacketRetrieveAvatar());
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketLeaveCurrentGame())
|
|
|
|
|
{
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_ON_REQUEST);
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketKickPlayer())
|
|
|
|
|
{
|
|
|
|
|
// Only admins are allowed to kick, and only in the lobby.
|
|
|
|
|
// After leaving the lobby, a vote needs to be initiated to kick.
|
|
|
|
|
if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN && !GetServerGame().IsRunning())
|
|
|
|
|
{
|
|
|
|
|
NetPacketKickPlayer::Data kickPlayerData;
|
|
|
|
|
packet->ToNetPacketKickPlayer()->GetData(kickPlayerData);
|
|
|
|
|
|
|
|
|
|
GetServerGame().InternalKickPlayer(kickPlayerData.playerId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketAskKickPlayer())
|
|
|
|
|
{
|
|
|
|
|
if (session.playerData)
|
|
|
|
|
{
|
|
|
|
|
NetPacketAskKickPlayer::Data askKickData;
|
|
|
|
|
packet->ToNetPacketAskKickPlayer()->GetData(askKickData);
|
|
|
|
|
|
|
|
|
|
GetServerGame().InternalAskVoteKick(session, askKickData.playerId, SERVER_VOTE_KICK_TIMEOUT_SEC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketVoteKickPlayer())
|
|
|
|
|
{
|
|
|
|
|
if (session.playerData)
|
|
|
|
|
{
|
|
|
|
|
NetPacketVoteKickPlayer::Data voteData;
|
|
|
|
|
packet->ToNetPacketVoteKickPlayer()->GetData(voteData);
|
|
|
|
|
|
|
|
|
|
GetServerGame().InternalVoteKick(session, voteData.petitionId, voteData.vote);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Chat text is always allowed.
|
|
|
|
|
else if (packet->ToNetPacketSendChatText())
|
|
|
|
|
{
|
|
|
|
|
if (session.playerData) // Only forward if this player is known.
|
|
|
|
|
{
|
|
|
|
|
// Forward chat text to all players.
|
|
|
|
|
// TODO: Some limitation needed.
|
|
|
|
|
NetPacketSendChatText::Data inChatData;
|
|
|
|
|
packet->ToNetPacketSendChatText()->GetData(inChatData);
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> outChat(new NetPacketChatText);
|
|
|
|
|
NetPacketChatText::Data outChatData;
|
|
|
|
|
outChatData.playerId = session.playerData->GetUniqueId();
|
|
|
|
|
outChatData.text = inChatData.text;
|
|
|
|
|
static_cast<NetPacketChatText *>(outChat.get())->SetData(outChatData);
|
|
|
|
|
GetServerGame().SendToAllPlayers(outChat, SessionData::Game);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketUnsubscribeGameList())
|
|
|
|
|
{
|
|
|
|
|
// We can do this directly in this thread.
|
|
|
|
|
session.sessionData->ResetWantsLobbyMsg();
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketResubscribeGameList())
|
|
|
|
|
{
|
|
|
|
|
// This needs to be performed in the lobby thread,
|
|
|
|
|
// because a new game list needs to be sent.
|
|
|
|
|
if (!session.sessionData->WantsLobbyMsg())
|
|
|
|
|
GetServerGame().GetLobbyThread().ResubscribeLobbyMsg(session);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Packet processing in subclass.
|
|
|
|
|
retVal = InternalProcessPacket(session, packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ServerGameStateInit::ServerGameStateInit(ServerGameThread &serverGame)
|
|
|
|
|
: AbstractServerGameStateReceiving(serverGame), m_timerRegistered(false)
|
|
|
|
|
{
|
|
|
|
|
RegisterAdminTimers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerGameStateInit::~ServerGameStateInit()
|
|
|
|
|
{
|
|
|
|
|
UnregisterAdminTimers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateInit::NotifyGameAdminChanged()
|
|
|
|
|
{
|
|
|
|
|
RegisterAdminTimers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateInit::HandleNewSession(SessionWrapper session)
|
|
|
|
|
{
|
|
|
|
|
if (session.sessionData.get() && session.playerData.get())
|
|
|
|
|
{
|
|
|
|
|
size_t curNumPlayers = GetServerGame().GetCurNumberOfPlayers();
|
|
|
|
|
|
|
|
|
|
// Check the number of players.
|
|
|
|
|
if (curNumPlayers >= (size_t)GetServerGame().GetGameData().maxNumberOfPlayers)
|
|
|
|
|
{
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL);
|
|
|
|
|
}
|
|
|
|
|
// Check whether the client supports the current game.
|
|
|
|
|
else if ((size_t)GetServerGame().GetGameData().maxNumberOfPlayers > session.sessionData->GetMaxNumPlayers())
|
|
|
|
|
{
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (session.playerData->GetUniqueId() == GetServerGame().GetAdminPlayerId())
|
|
|
|
|
{
|
|
|
|
|
// This is the admin player.
|
|
|
|
|
session.playerData->SetRights(PLAYER_RIGHTS_ADMIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send ack to client.
|
|
|
|
|
boost::shared_ptr<NetPacket> joinGameAck(new NetPacketJoinGameAck);
|
|
|
|
|
NetPacketJoinGameAck::Data joinGameAckData;
|
|
|
|
|
joinGameAckData.gameId = GetServerGame().GetId();
|
|
|
|
|
joinGameAckData.prights = session.playerData->GetRights();
|
|
|
|
|
joinGameAckData.gameData = GetServerGame().GetGameData();
|
|
|
|
|
static_cast<NetPacketJoinGameAck *>(joinGameAck.get())->SetData(joinGameAckData);
|
|
|
|
|
session.sessionData->GetSender().Send(session.sessionData, joinGameAck);
|
|
|
|
|
|
|
|
|
|
// Send notifications for connected players to client.
|
|
|
|
|
PlayerDataList tmpPlayerList = GetServerGame().GetFullPlayerDataList();
|
|
|
|
|
PlayerDataList::iterator player_i = tmpPlayerList.begin();
|
|
|
|
|
PlayerDataList::iterator player_end = tmpPlayerList.end();
|
|
|
|
|
while (player_i != player_end)
|
|
|
|
|
{
|
|
|
|
|
session.sessionData->GetSender().Send(session.sessionData, CreateNetPacketPlayerJoined(*(*player_i)));
|
|
|
|
|
++player_i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send "Player Joined" to other fully connected clients.
|
|
|
|
|
GetServerGame().SendToAllPlayers(CreateNetPacketPlayerJoined(*session.playerData), SessionData::Game);
|
|
|
|
|
|
|
|
|
|
// Accept session.
|
|
|
|
|
GetServerGame().GetSessionManager().AddSession(session);
|
|
|
|
|
|
|
|
|
|
// Notify lobby.
|
|
|
|
|
GetServerGame().GetLobbyThread().NotifyPlayerJoinedGame(GetServerGame().GetId(), session.playerData->GetUniqueId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateInit::RegisterAdminTimers()
|
|
|
|
|
{
|
|
|
|
|
if (m_timerRegistered)
|
|
|
|
|
UnregisterAdminTimers();
|
|
|
|
|
|
|
|
|
|
m_adminWarningTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC) * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateInit::TimerAdminWarning, this));
|
|
|
|
|
m_adminTimeoutTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_GAME_ADMIN_TIMEOUT_SEC * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateInit::TimerAdminTimeout, this));
|
|
|
|
|
m_timerRegistered = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateInit::UnregisterAdminTimers()
|
|
|
|
|
{
|
|
|
|
|
if (m_timerRegistered)
|
|
|
|
|
{
|
|
|
|
|
GetServerGame().GetLobbyThread().GetTimerManager().UnregisterTimer(m_adminWarningTimerId);
|
|
|
|
|
GetServerGame().GetLobbyThread().GetTimerManager().UnregisterTimer(m_adminTimeoutTimerId);
|
|
|
|
|
m_timerRegistered = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateInit::TimerAdminWarning()
|
|
|
|
|
{
|
|
|
|
|
// Find game admin.
|
|
|
|
|
SessionWrapper session = GetServerGame().GetSessionManager().GetSessionByUniquePlayerId(GetServerGame().GetAdminPlayerId());
|
|
|
|
|
if (session.sessionData.get())
|
|
|
|
|
{
|
|
|
|
|
// Send him a warning.
|
|
|
|
|
boost::shared_ptr<NetPacket> warning(new NetPacketTimeoutWarning);
|
|
|
|
|
NetPacketTimeoutWarning::Data warningData;
|
|
|
|
|
warningData.timeoutReason = NETWORK_TIMEOUT_GAME_ADMIN_IDLE;
|
|
|
|
|
warningData.remainingSeconds = SERVER_GAME_ADMIN_WARNING_REMAINING_SEC;
|
|
|
|
|
static_cast<NetPacketTimeoutWarning *>(warning.get())->SetData(warningData);
|
|
|
|
|
session.sessionData->GetSender().Send(session.sessionData, warning);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateInit::TimerAdminTimeout()
|
|
|
|
|
{
|
|
|
|
|
// Find game admin.
|
|
|
|
|
SessionWrapper session = GetServerGame().GetSessionManager().GetSessionByUniquePlayerId(GetServerGame().GetAdminPlayerId());
|
|
|
|
|
if (session.sessionData.get())
|
|
|
|
|
{
|
|
|
|
|
// Remove him from the game.
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_TIMEOUT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ServerGameStateInit::InternalProcessPacket(SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
2009-05-30 22:20:40 +00:00
|
|
|
|
|
|
|
|
if (packet->ToNetPacketStartEvent())
|
|
|
|
|
{
|
|
|
|
|
// Only admins are allowed to start the game.
|
|
|
|
|
if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN)
|
|
|
|
|
{
|
|
|
|
|
NetPacketStartEvent::Data startData;
|
|
|
|
|
packet->ToNetPacketStartEvent()->GetData(startData);
|
|
|
|
|
|
|
|
|
|
// Fill up with computer players.
|
|
|
|
|
GetServerGame().ResetComputerPlayerList();
|
|
|
|
|
|
|
|
|
|
if (startData.fillUpWithCpuPlayers)
|
|
|
|
|
{
|
|
|
|
|
int remainingSlots = GetServerGame().GetGameData().maxNumberOfPlayers - GetServerGame().GetCurNumberOfPlayers();
|
|
|
|
|
for (int i = 1; i <= remainingSlots; i++)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayerData(
|
|
|
|
|
new PlayerData(GetServerGame().GetLobbyThread().GetNextUniquePlayerId(), 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL));
|
|
|
|
|
|
|
|
|
|
ostringstream name;
|
|
|
|
|
name << SERVER_COMPUTER_PLAYER_NAME << i;
|
|
|
|
|
tmpPlayerData->SetName(name.str());
|
|
|
|
|
GetServerGame().AddComputerPlayer(tmpPlayerData);
|
|
|
|
|
|
|
|
|
|
// Send "Player Joined" to other fully connected clients.
|
|
|
|
|
GetServerGame().SendToAllPlayers(CreateNetPacketPlayerJoined(*tmpPlayerData), SessionData::Game);
|
|
|
|
|
|
|
|
|
|
// Notify lobby.
|
|
|
|
|
GetServerGame().GetLobbyThread().NotifyPlayerJoinedGame(GetServerGame().GetId(), tmpPlayerData->GetUniqueId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Wait for all players to confirm start of game.
|
|
|
|
|
GetServerGame().SendToAllPlayers(boost::shared_ptr<NetPacket>(packet->Clone()), SessionData::Game);
|
|
|
|
|
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new ServerGameStateStartGame(GetServerGame())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketResetTimeout())
|
|
|
|
|
{
|
|
|
|
|
if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN)
|
|
|
|
|
{
|
|
|
|
|
RegisterAdminTimers();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GetServerGame().SessionError(session, ERR_SOCK_INVALID_PACKET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
ServerGameStateInit::CreateNetPacketPlayerJoined(const PlayerData &playerData)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> thisPlayerJoined(new NetPacketPlayerJoined);
|
|
|
|
|
NetPacketPlayerJoined::Data thisPlayerJoinedData;
|
|
|
|
|
thisPlayerJoinedData.playerId = playerData.GetUniqueId();
|
|
|
|
|
thisPlayerJoinedData.prights = playerData.GetRights();
|
|
|
|
|
static_cast<NetPacketPlayerJoined *>(thisPlayerJoined.get())->SetData(thisPlayerJoinedData);
|
|
|
|
|
return thisPlayerJoined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ServerGameStateStartGame::ServerGameStateStartGame(ServerGameThread &serverGame)
|
|
|
|
|
: AbstractServerGameStateReceiving(serverGame)
|
|
|
|
|
{
|
|
|
|
|
m_timeoutTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_START_GAME_TIMEOUT_SEC * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateStartGame::TimerTimeout, this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerGameStateStartGame::~ServerGameStateStartGame()
|
|
|
|
|
{
|
|
|
|
|
// The Id might be invalid, but this is not a problem.
|
|
|
|
|
GetServerGame().GetLobbyThread().GetTimerManager().UnregisterTimer(m_timeoutTimerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateStartGame::HandleNewSession(SessionWrapper session)
|
|
|
|
|
{
|
|
|
|
|
// Do not accept new sessions in this state.
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ServerGameStateStartGame::InternalProcessPacket(SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
|
|
|
|
{
|
|
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
|
|
|
|
|
if (packet->ToNetPacketStartEventAck())
|
|
|
|
|
{
|
|
|
|
|
session.sessionData->SetReadyFlag();
|
|
|
|
|
if (GetServerGame().GetSessionManager().CountReadySessions() == GetServerGame().GetSessionManager().GetRawSessionCount())
|
|
|
|
|
{
|
|
|
|
|
// Everyone is ready.
|
|
|
|
|
GetServerGame().GetSessionManager().ResetAllReadyFlags();
|
|
|
|
|
DoStart();
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new SERVER_START_GAME_STATE(GetServerGame())));
|
|
|
|
|
retVal = MSG_SOCK_INIT_DONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateStartGame::TimerTimeout()
|
|
|
|
|
{
|
|
|
|
|
// On timeout: start anyway.
|
|
|
|
|
GetServerGame().GetSessionManager().ResetAllReadyFlags();
|
|
|
|
|
// TODO report successful start! -> new callback?!
|
|
|
|
|
//retVal = MSG_SOCK_INIT_DONE;
|
|
|
|
|
DoStart();
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new SERVER_START_GAME_STATE(GetServerGame())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateStartGame::DoStart()
|
|
|
|
|
{
|
|
|
|
|
PlayerDataList tmpPlayerList = GetServerGame().GetFullPlayerDataList();
|
|
|
|
|
if (tmpPlayerList.size() <= 1)
|
|
|
|
|
{
|
|
|
|
|
if (!tmpPlayerList.empty())
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(tmpPlayerList.front());
|
|
|
|
|
SessionWrapper tmpSession = GetServerGame().GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->GetUniqueId());
|
|
|
|
|
if (tmpSession.sessionData.get())
|
|
|
|
|
GetServerGame().MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_START_FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GetServerGame().InternalStartGame();
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
|
|
|
|
|
|
|
|
|
|
NetPacketGameStart::Data gameStartData;
|
|
|
|
|
gameStartData.startData = GetServerGame().GetStartData();
|
|
|
|
|
|
|
|
|
|
// Send player order to clients.
|
|
|
|
|
// Assume player list is sorted by number.
|
|
|
|
|
PlayerDataList::iterator player_i = tmpPlayerList.begin();
|
|
|
|
|
PlayerDataList::iterator player_end = tmpPlayerList.end();
|
|
|
|
|
while (player_i != player_end)
|
|
|
|
|
{
|
|
|
|
|
NetPacketGameStart::PlayerSlot tmpPlayerSlot;
|
|
|
|
|
tmpPlayerSlot.playerId = (*player_i)->GetUniqueId();
|
|
|
|
|
gameStartData.playerSlots.push_back(tmpPlayerSlot);
|
|
|
|
|
|
|
|
|
|
++player_i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
|
|
|
|
|
GetServerGame().SendToAllPlayers(answer, SessionData::Game);
|
|
|
|
|
|
|
|
|
|
// Start the first hand.
|
|
|
|
|
StartNewHand(GetServerGame());
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new ServerGameStateHand(GetServerGame())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
ServerGameStateHand::ServerGameStateHand(ServerGameThread &serverGame)
|
|
|
|
|
: AbstractServerGameStateReceiving(serverGame)
|
|
|
|
|
{
|
|
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_LOOP_DELAY_MSEC,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerLoop, this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerGameStateHand::~ServerGameStateHand()
|
|
|
|
|
{
|
|
|
|
|
// The Id might be invalid, but this is not a problem.
|
|
|
|
|
GetServerGame().GetLobbyThread().GetTimerManager().UnregisterTimer(m_loopTimerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateHand::HandleNewSession(SessionWrapper session)
|
|
|
|
|
{
|
|
|
|
|
// Do not accept new sessions in this state.
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ServerGameStateHand::InternalProcessPacket(SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
|
|
|
|
{
|
|
|
|
|
// TODO: maybe reject packet.
|
|
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateHand::TimerLoop()
|
|
|
|
|
{
|
|
|
|
|
bool newTimerSet = false;
|
|
|
|
|
Game &curGame = GetServerGame().GetGame();
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
// Main game loop.
|
|
|
|
|
int curRound = curGame.getCurrentHand()->getCurrentRound();
|
|
|
|
|
curGame.getCurrentHand()->switchRounds();
|
|
|
|
|
if (!curGame.getCurrentHand()->getAllInCondition())
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->run();
|
|
|
|
|
int newRound = curGame.getCurrentHand()->getCurrentRound();
|
|
|
|
|
|
|
|
|
|
// If round changes, deal cards if needed.
|
|
|
|
|
if (newRound != curRound && newRound != GAME_STATE_POST_RIVER)
|
|
|
|
|
{
|
2007-11-10 22:18:31 +00:00
|
|
|
if (newRound <= curRound)
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_GAME_ROUND, 0);
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
// Retrieve non-fold players. If only one player is left, no cards are shown.
|
|
|
|
|
list<boost::shared_ptr<PlayerInterface> > nonFoldPlayers = *curGame.getActivePlayerList();
|
|
|
|
|
nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD);
|
|
|
|
|
|
|
|
|
|
if (curGame.getCurrentHand()->getAllInCondition()
|
|
|
|
|
&& !curGame.getCurrentHand()->getCardsShown()
|
|
|
|
|
&& nonFoldPlayers.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
// Send cards of all active players to all players (all in).
|
|
|
|
|
boost::shared_ptr<NetPacket> allIn(new NetPacketAllInShowCards);
|
|
|
|
|
NetPacketAllInShowCards::Data allInData;
|
|
|
|
|
|
|
|
|
|
PlayerListConstIterator i = nonFoldPlayers.begin();
|
|
|
|
|
PlayerListConstIterator end = nonFoldPlayers.end();
|
|
|
|
|
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
NetPacketAllInShowCards::PlayerCards tmpPlayerCards;
|
|
|
|
|
tmpPlayerCards.playerId = (*i)->getMyUniqueID();
|
|
|
|
|
|
|
|
|
|
int tmpCards[2];
|
|
|
|
|
(*i)->getMyCards(tmpCards);
|
|
|
|
|
tmpPlayerCards.cards[0] = static_cast<u_int16_t>(tmpCards[0]);
|
|
|
|
|
tmpPlayerCards.cards[1] = static_cast<u_int16_t>(tmpCards[1]);
|
|
|
|
|
|
|
|
|
|
allInData.playerCards.push_back(tmpPlayerCards);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
static_cast<NetPacketAllInShowCards *>(allIn.get())->SetData(allInData);
|
2009-05-30 22:20:40 +00:00
|
|
|
GetServerGame().SendToAllPlayers(allIn, SessionData::Game);
|
2007-10-18 17:40:12 +00:00
|
|
|
curGame.getCurrentHand()->setCardsShown(true);
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_SHOW_CARDS_DELAY_SEC * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerLoop, this));
|
|
|
|
|
newTimerSet = true;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
SendNewRoundCards(GetServerGame(), curGame, newRound);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
GetDealCardsDelaySec() * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerLoop, this));
|
|
|
|
|
newTimerSet = true;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (newRound != GAME_STATE_POST_RIVER) // continue hand
|
|
|
|
|
{
|
2007-11-10 22:18:31 +00:00
|
|
|
if (curGame.getCurrentHand()->getAllInCondition())
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INTERNAL_GAME_ERROR, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
// Retrieve current player.
|
|
|
|
|
boost::shared_ptr<PlayerInterface> curPlayer = curGame.getCurrentPlayer();
|
|
|
|
|
if (!curPlayer.get())
|
2007-10-18 20:36:49 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
if (!curPlayer->getMyActiveStatus())
|
2007-10-18 20:36:49 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_PLAYER_NOT_ACTIVE, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> notification(new NetPacketPlayersTurn);
|
|
|
|
|
NetPacketPlayersTurn::Data playersTurnData;
|
|
|
|
|
playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getCurrentRound();
|
|
|
|
|
playersTurnData.playerId = curPlayer->getMyUniqueID();
|
|
|
|
|
static_cast<NetPacketPlayersTurn *>(notification.get())->SetData(playersTurnData);
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
GetServerGame().SendToAllPlayers(notification, SessionData::Game);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
// If the player is computer controlled, let the engine act.
|
|
|
|
|
if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER)
|
|
|
|
|
{
|
|
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_COMPUTER_ACTION_DELAY_SEC * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerComputerAction, this));
|
|
|
|
|
newTimerSet = true;
|
|
|
|
|
}
|
|
|
|
|
// If the player we are waiting for left, continue without him.
|
|
|
|
|
else if (!GetServerGame().GetSessionManager().IsPlayerConnected(curPlayer->getMyName()))
|
|
|
|
|
{
|
|
|
|
|
PerformPlayerAction(GetServerGame(), curPlayer, PLAYER_ACTION_FOLD, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//wrong!!!
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new ServerGameStateWaitPlayerAction(GetServerGame())));
|
|
|
|
|
}
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
else // hand is over
|
|
|
|
|
{
|
|
|
|
|
// Engine will find out who won.
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun();
|
|
|
|
|
|
|
|
|
|
// Retrieve non-fold players. If only one player is left, no cards are shown.
|
|
|
|
|
list<boost::shared_ptr<PlayerInterface> > nonFoldPlayers = *curGame.getActivePlayerList();
|
|
|
|
|
nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD);
|
|
|
|
|
|
|
|
|
|
if (nonFoldPlayers.size() == 1)
|
|
|
|
|
{
|
|
|
|
|
// End of Hand, but keep cards hidden.
|
|
|
|
|
boost::shared_ptr<PlayerInterface> player = nonFoldPlayers.front();
|
|
|
|
|
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandHideCards);
|
|
|
|
|
NetPacketEndOfHandHideCards::Data endHandData;
|
|
|
|
|
endHandData.playerId = player->getMyUniqueID();
|
2007-10-29 22:37:42 +00:00
|
|
|
endHandData.moneyWon = player->getLastMoneyWon();
|
2007-10-18 17:40:12 +00:00
|
|
|
endHandData.playerMoney = player->getMyCash();
|
|
|
|
|
static_cast<NetPacketEndOfHandHideCards *>(endHand.get())->SetData(endHandData);
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
GetServerGame().SendToAllPlayers(endHand, SessionData::Game);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// End of Hand - show cards of active players.
|
|
|
|
|
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandShowCards);
|
|
|
|
|
NetPacketEndOfHandShowCards::Data endHandData;
|
|
|
|
|
|
|
|
|
|
PlayerListConstIterator i = nonFoldPlayers.begin();
|
|
|
|
|
PlayerListConstIterator end = nonFoldPlayers.end();
|
|
|
|
|
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult;
|
|
|
|
|
tmpPlayerResult.playerId = (*i)->getMyUniqueID();
|
|
|
|
|
|
|
|
|
|
int tmpCards[2];
|
|
|
|
|
int bestHandPos[5];
|
|
|
|
|
(*i)->getMyCards(tmpCards);
|
|
|
|
|
tmpPlayerResult.cards[0] = static_cast<u_int16_t>(tmpCards[0]);
|
|
|
|
|
tmpPlayerResult.cards[1] = static_cast<u_int16_t>(tmpCards[1]);
|
|
|
|
|
|
|
|
|
|
(*i)->getMyBestHandPosition(bestHandPos);
|
|
|
|
|
for (int num = 0; num < 5; num++)
|
|
|
|
|
tmpPlayerResult.bestHandPos[num] = bestHandPos[num];
|
|
|
|
|
|
|
|
|
|
tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt();
|
2007-10-29 22:37:42 +00:00
|
|
|
tmpPlayerResult.moneyWon = (*i)->getLastMoneyWon();
|
2007-10-18 17:40:12 +00:00
|
|
|
tmpPlayerResult.playerMoney = (*i)->getMyCash();
|
|
|
|
|
|
|
|
|
|
endHandData.playerResults.push_back(tmpPlayerResult);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
static_cast<NetPacketEndOfHandShowCards *>(endHand.get())->SetData(endHandData);
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
GetServerGame().SendToAllPlayers(endHand, SessionData::Game);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove disconnected players. This is the one and only place to do this.
|
2009-05-30 22:20:40 +00:00
|
|
|
GetServerGame().RemoveDisconnectedPlayers();
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
// Start next hand - if enough players are left.
|
|
|
|
|
list<boost::shared_ptr<PlayerInterface> > playersWithCash = *curGame.getActivePlayerList();
|
|
|
|
|
playersWithCash.remove_if(boost::bind(&PlayerInterface::getMyCash, _1) < 1);
|
|
|
|
|
|
|
|
|
|
if (playersWithCash.empty())
|
|
|
|
|
{
|
|
|
|
|
// No more players left - restart.
|
2009-05-30 22:20:40 +00:00
|
|
|
//wrong!!!
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new SERVER_INITIAL_STATE(GetServerGame())));
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
else if (playersWithCash.size() == 1)
|
|
|
|
|
{
|
|
|
|
|
// View a dialog for a new game - delayed.
|
2009-05-30 22:20:40 +00:00
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_DELAY_NEXT_GAME_SEC * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerNextGame, this));
|
|
|
|
|
newTimerSet = true;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
SERVER_DELAY_NEXT_HAND_SEC * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerNextHand, this));
|
|
|
|
|
newTimerSet = true;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-30 22:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateHand::TimerShowCards()
|
|
|
|
|
{
|
|
|
|
|
Game &curGame = GetServerGame().GetGame();
|
|
|
|
|
SendNewRoundCards(GetServerGame(), curGame, curGame.getCurrentHand()->getCurrentRound());
|
|
|
|
|
|
|
|
|
|
m_loopTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
GetDealCardsDelaySec() * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateHand::TimerLoop, this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateHand::TimerComputerAction()
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = GetServerGame().GetGame().getCurrentPlayer();
|
|
|
|
|
|
|
|
|
|
tmpPlayer->action();
|
|
|
|
|
SendPlayerAction(GetServerGame(), tmpPlayer);
|
|
|
|
|
TimerLoop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateHand::TimerNextHand()
|
|
|
|
|
{
|
|
|
|
|
StartNewHand(GetServerGame());
|
|
|
|
|
TimerLoop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerGameStateHand::TimerNextGame()
|
|
|
|
|
{
|
|
|
|
|
Game &curGame = GetServerGame().GetGame();
|
|
|
|
|
// The game has ended. Notify all clients.
|
|
|
|
|
boost::shared_ptr<PlayerInterface> winnerPlayer;
|
|
|
|
|
PlayerListIterator i = curGame.getActivePlayerList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getActivePlayerList()->end();
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
winnerPlayer = *i;
|
|
|
|
|
if (winnerPlayer->getMyCash() > 0)
|
|
|
|
|
break;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> endGame(new NetPacketEndOfGame);
|
|
|
|
|
NetPacketEndOfGame::Data endGameData;
|
|
|
|
|
endGameData.winnerPlayerId = winnerPlayer->getMyUniqueID();
|
|
|
|
|
static_cast<NetPacketEndOfGame *>(endGame.get())->SetData(endGameData);
|
|
|
|
|
|
|
|
|
|
GetServerGame().SendToAllPlayers(endGame, SessionData::Game);
|
|
|
|
|
|
|
|
|
|
// Wait for the start of a new game.
|
|
|
|
|
GetServerGame().ResetComputerPlayerList();
|
|
|
|
|
GetServerGame().ResetGame();
|
|
|
|
|
GetServerGame().GetLobbyThread().NotifyReopeningGame(GetServerGame().GetId());
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new ServerGameStateInit(GetServerGame())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ServerGameStateHand::GetDealCardsDelaySec()
|
|
|
|
|
{
|
|
|
|
|
Game &curGame = GetServerGame().GetGame();
|
|
|
|
|
int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0;
|
|
|
|
|
int delay = 0;
|
|
|
|
|
|
|
|
|
|
switch(curGame.getCurrentHand()->getCurrentRound())
|
|
|
|
|
{
|
|
|
|
|
case GAME_STATE_FLOP:
|
|
|
|
|
delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC;
|
|
|
|
|
break;
|
|
|
|
|
case GAME_STATE_TURN:
|
|
|
|
|
delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay;
|
|
|
|
|
break;
|
|
|
|
|
case GAME_STATE_RIVER:
|
|
|
|
|
delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return delay;
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
ServerGameStateWaitPlayerAction::ServerGameStateWaitPlayerAction(ServerGameThread &serverGame)
|
|
|
|
|
: AbstractServerGameStateReceiving(serverGame)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
#ifdef SERVER_TEST
|
|
|
|
|
int timeoutSec = 0;
|
|
|
|
|
#else
|
|
|
|
|
int timeoutSec = GetServerGame().GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
|
|
|
|
|
#endif
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
m_timeoutTimerId = GetServerGame().GetLobbyThread().GetTimerManager().RegisterTimer(
|
|
|
|
|
timeoutSec * 1000,
|
|
|
|
|
boost::bind(&ServerGameStateWaitPlayerAction::TimerTimeout, this));
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerGameStateWaitPlayerAction::~ServerGameStateWaitPlayerAction()
|
|
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
// The Id might be invalid, but this is not a problem.
|
|
|
|
|
GetServerGame().GetLobbyThread().GetTimerManager().UnregisterTimer(m_timeoutTimerId);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
void
|
|
|
|
|
ServerGameStateWaitPlayerAction::HandleNewSession(SessionWrapper session)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
// Do not accept new sessions in this state.
|
|
|
|
|
GetServerGame().MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2009-05-30 22:20:40 +00:00
|
|
|
ServerGameStateWaitPlayerAction::InternalProcessPacket(SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
|
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
|
|
|
|
|
if (packet->ToNetPacketPlayersAction())
|
|
|
|
|
{
|
|
|
|
|
NetPacketPlayersAction::Data actionData;
|
|
|
|
|
packet->ToNetPacketPlayersAction()->GetData(actionData);
|
|
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
Game &curGame = GetServerGame().GetGame();
|
2007-10-18 17:40:12 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId());
|
|
|
|
|
if (!tmpPlayer.get())
|
2007-10-18 20:36:49 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
|
|
|
|
// Check whether this is the correct round.
|
|
|
|
|
PlayerActionCode code = ACTION_CODE_VALID;
|
|
|
|
|
if (curGame.getCurrentHand()->getCurrentRound() != actionData.gameState)
|
|
|
|
|
code = ACTION_CODE_INVALID_STATE;
|
|
|
|
|
|
|
|
|
|
// Check whether this is the correct player.
|
2009-05-30 22:20:40 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> curPlayer = GetServerGame().GetGame().getCurrentPlayer();
|
2007-10-18 17:40:12 +00:00
|
|
|
if (code == ACTION_CODE_VALID
|
|
|
|
|
&& (curPlayer->getMyUniqueID() != tmpPlayer->getMyUniqueID()))
|
|
|
|
|
{
|
|
|
|
|
code = ACTION_CODE_NOT_YOUR_TURN;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-25 21:11:05 +00:00
|
|
|
// If the client omitted some values, fill them in.
|
|
|
|
|
if (actionData.playerAction == PLAYER_ACTION_CALL && actionData.playerBet == 0)
|
|
|
|
|
{
|
|
|
|
|
if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() >= tmpPlayer->getMySet() + tmpPlayer->getMyCash())
|
|
|
|
|
actionData.playerAction = PLAYER_ACTION_ALLIN;
|
|
|
|
|
else
|
|
|
|
|
actionData.playerBet = curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() - tmpPlayer->getMySet();
|
|
|
|
|
}
|
|
|
|
|
if (actionData.playerAction == PLAYER_ACTION_ALLIN && actionData.playerBet == 0)
|
|
|
|
|
actionData.playerBet = tmpPlayer->getMyCash();
|
|
|
|
|
|
2007-10-18 17:40:12 +00:00
|
|
|
// Check whether the action is valid.
|
|
|
|
|
if (code == ACTION_CODE_VALID
|
|
|
|
|
&& (tmpPlayer->checkMyAction(
|
|
|
|
|
actionData.playerAction,
|
|
|
|
|
actionData.playerBet,
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet(),
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(),
|
|
|
|
|
curGame.getCurrentHand()->getSmallBlind()) != 0))
|
|
|
|
|
{
|
|
|
|
|
code = ACTION_CODE_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (code == ACTION_CODE_VALID)
|
|
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
PerformPlayerAction(GetServerGame(), tmpPlayer, actionData.playerAction, actionData.playerBet);
|
|
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new ServerGameStateHand(GetServerGame())));
|
2007-10-18 17:40:12 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_ACTION;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Send reject message.
|
|
|
|
|
boost::shared_ptr<NetPacket> reject(new NetPacketPlayersActionRejected);
|
|
|
|
|
NetPacketPlayersActionRejected::Data rejectData;
|
|
|
|
|
rejectData.gameState = actionData.gameState;
|
|
|
|
|
rejectData.playerAction = actionData.playerAction;
|
|
|
|
|
rejectData.playerBet = actionData.playerBet;
|
|
|
|
|
rejectData.rejectionReason = code;
|
|
|
|
|
static_cast<NetPacketPlayersActionRejected *>(reject.get())->SetData(rejectData);
|
2009-01-07 21:52:16 +00:00
|
|
|
session.sessionData->GetSender().Send(session.sessionData, reject);
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-30 22:20:40 +00:00
|
|
|
ServerGameStateWaitPlayerAction::TimerTimeout()
|
2007-10-18 17:40:12 +00:00
|
|
|
{
|
2009-05-30 22:20:40 +00:00
|
|
|
Game &curGame = GetServerGame().GetGame();
|
|
|
|
|
// Retrieve current player.
|
|
|
|
|
boost::shared_ptr<PlayerInterface> curPlayer = curGame.getCurrentPlayer();
|
|
|
|
|
if (!curPlayer.get())
|
2007-11-10 22:18:31 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
// Player did not act fast enough. Act for him.
|
|
|
|
|
if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() == curPlayer->getMySet())
|
|
|
|
|
PerformPlayerAction(GetServerGame(), curPlayer, PLAYER_ACTION_CHECK, 0);
|
|
|
|
|
else
|
|
|
|
|
PerformPlayerAction(GetServerGame(), curPlayer, PLAYER_ACTION_FOLD, 0);
|
2007-10-18 17:40:12 +00:00
|
|
|
|
2009-05-30 22:20:40 +00:00
|
|
|
GetServerGame().SetState(boost::shared_ptr<ServerGameState>(new ServerGameStateHand(GetServerGame())));
|
2007-10-18 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|