2007-02-18 11:26:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2007 by Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* 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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
#include <net/servergamestate.h>
|
|
|
|
|
#include <net/servergamethread.h>
|
2007-09-02 16:36:52 +00:00
|
|
|
#include <net/serverlobbythread.h>
|
2007-03-20 02:20:50 +00:00
|
|
|
#include <net/receiverhelper.h>
|
|
|
|
|
#include <net/senderthread.h>
|
|
|
|
|
#include <net/netpacket.h>
|
2007-03-13 23:27:17 +00:00
|
|
|
#include <net/socket_msg.h>
|
2007-05-05 21:14:23 +00:00
|
|
|
#include <net/netexception.h>
|
2007-04-27 21:35:18 +00:00
|
|
|
#include <gamedata.h>
|
2007-05-13 22:25:59 +00:00
|
|
|
#include <game.h>
|
|
|
|
|
#include <playerinterface.h>
|
2007-05-14 12:40:42 +00:00
|
|
|
#include <handinterface.h>
|
2007-02-18 11:26:57 +00:00
|
|
|
|
2007-08-11 20:27:36 +00:00
|
|
|
#include <sstream>
|
2007-08-11 20:24:08 +00:00
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2007-06-07 14:06:22 +00:00
|
|
|
#define SERVER_WAIT_TIMEOUT_MSEC 50
|
|
|
|
|
#define SERVER_DELAY_NEXT_HAND_SEC 10
|
2007-06-10 23:28:25 +00:00
|
|
|
#define SERVER_DELAY_NEXT_GAME_SEC 10
|
2007-06-07 14:06:22 +00:00
|
|
|
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5
|
|
|
|
|
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2
|
|
|
|
|
#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2
|
2007-06-10 21:45:31 +00:00
|
|
|
#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 2
|
2007-06-07 14:06:22 +00:00
|
|
|
#define SERVER_SHOW_CARDS_DELAY_SEC 2
|
2007-06-08 22:14:05 +00:00
|
|
|
#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2
|
2007-08-11 20:24:08 +00:00
|
|
|
#define SERVER_COMPUTER_ACTION_DELAY_SEC 2
|
|
|
|
|
|
|
|
|
|
#define SERVER_COMPUTER_PLAYER_NAME "Computer"
|
2007-03-13 23:27:17 +00:00
|
|
|
|
2007-06-03 14:57:33 +00:00
|
|
|
// Helper functions
|
2007-06-07 14:06:22 +00:00
|
|
|
// TODO: these are hacks.
|
2007-06-03 14:57:33 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
static void SendPlayerAction(ServerGameThread &server, boost::shared_ptr<PlayerInterface> player)
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
|
|
|
|
assert(player);
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
|
|
|
|
NetPacketPlayersActionDone::Data actionDoneData;
|
2007-08-20 15:30:22 +00:00
|
|
|
actionDoneData.gameState = server.GetCurRound();
|
2007-08-11 20:24:08 +00:00
|
|
|
actionDoneData.playerId = player->getMyUniqueID();
|
|
|
|
|
actionDoneData.playerAction = static_cast<PlayerAction>(player->getMyAction());
|
|
|
|
|
actionDoneData.totalPlayerBet = player->getMySet();
|
|
|
|
|
actionDoneData.playerMoney = player->getMyCash();
|
|
|
|
|
static_cast<NetPacketPlayersActionDone *>(notifyActionDone.get())->SetData(actionDoneData);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notifyActionDone, SessionData::Game);
|
2007-08-11 20:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
static void SendNewRoundCards(ServerGameThread &server, Game &curGame, int state)
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
|
|
|
|
// 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);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notifyCards, SessionData::Game);
|
2007-06-07 14:06:22 +00:00
|
|
|
} 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);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notifyCards, SessionData::Game);
|
2007-06-07 14:06:22 +00:00
|
|
|
} 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);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notifyCards, SessionData::Game);
|
2007-06-07 14:06:22 +00:00
|
|
|
} break;
|
|
|
|
|
default: {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-03 14:57:33 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-13 23:27:17 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameState::~ServerGameState()
|
2007-02-18 11:26:57 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateReceiving::AbstractServerGameStateReceiving()
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateReceiving::~AbstractServerGameStateReceiving()
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateReceiving::Process(ServerGameThread &server)
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
// This is the receive loop for the server.
|
2007-05-25 16:03:12 +00:00
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
2007-08-20 15:30:22 +00:00
|
|
|
SessionWrapper session = server.GetSessionManager().Select(RECV_TIMEOUT_MSEC);
|
2007-05-25 16:03:12 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
if (session.sessionData.get())
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> packet;
|
|
|
|
|
try
|
|
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
// Receive the packet.
|
2007-09-03 16:35:45 +00:00
|
|
|
packet = server.GetReceiver().Recv(session.sessionData->GetSocket(), session.sessionData->GetReceiveBuffer());
|
2007-05-25 16:03:12 +00:00
|
|
|
} catch (const NetException &)
|
|
|
|
|
{
|
2007-09-29 14:05:41 +00:00
|
|
|
server.ErrorRemoveSession(session);
|
2007-08-11 10:02:04 +00:00
|
|
|
return retVal;
|
2007-05-25 16:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-11 10:02:04 +00:00
|
|
|
// Process packet if one was received.
|
|
|
|
|
if (packet.get())
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
2007-08-26 22:41:37 +00:00
|
|
|
if (packet->ToNetPacketRetrievePlayerInfo())
|
|
|
|
|
{
|
2007-09-29 14:05:41 +00:00
|
|
|
// Delegate to Lobby.
|
|
|
|
|
server.GetLobbyThread().HandleGameRetrievePlayerInfo(session, *packet->ToNetPacketRetrievePlayerInfo());
|
2007-08-26 22:41:37 +00:00
|
|
|
}
|
2007-09-06 19:09:05 +00:00
|
|
|
else if (packet->ToNetPacketLeaveCurrentGame())
|
|
|
|
|
{
|
|
|
|
|
server.MoveSessionToLobby(session, NTF_NET_REMOVED_ON_REQUEST);
|
|
|
|
|
}
|
2007-08-11 10:02:04 +00:00
|
|
|
// Chat text is always allowed.
|
2007-08-26 22:41:37 +00:00
|
|
|
else if (packet->ToNetPacketSendChatText())
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
|
|
|
|
if (session.playerData.get()) // 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);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(outChat, SessionData::Game);
|
2007-05-25 16:03:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2007-08-11 10:02:04 +00:00
|
|
|
{
|
|
|
|
|
// Packet processing in subclass.
|
|
|
|
|
retVal = InternalProcess(server, session, packet);
|
|
|
|
|
}
|
2007-05-25 16:03:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateTimer::AbstractServerGameStateTimer()
|
2007-06-08 20:19:21 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateTimer::~AbstractServerGameStateTimer()
|
2007-06-08 20:19:21 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateTimer::Init()
|
2007-06-08 20:19:21 +00:00
|
|
|
{
|
|
|
|
|
m_timer.reset();
|
|
|
|
|
m_timer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateInit> ServerGameStateInit::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateInit &
|
|
|
|
|
ServerGameStateInit::Instance()
|
2007-02-18 11:26:57 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateInit);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-02-18 11:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateInit::ServerGameStateInit()
|
2007-03-13 23:27:17 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateInit::~ServerGameStateInit()
|
2007-03-13 23:27:17 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 22:55:39 +00:00
|
|
|
void
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateInit::HandleNewSession(ServerGameThread &server, SessionWrapper session)
|
2007-03-13 23:27:17 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
if (session.sessionData.get() && session.playerData.get())
|
2007-03-20 02:20:50 +00:00
|
|
|
{
|
2007-08-02 20:52:13 +00:00
|
|
|
size_t curNumPlayers = server.GetCurNumberOfPlayers();
|
|
|
|
|
|
|
|
|
|
// Check the number of players.
|
|
|
|
|
if (curNumPlayers >= (size_t)server.GetGameData().maxNumberOfPlayers)
|
|
|
|
|
{
|
2007-09-06 19:09:05 +00:00
|
|
|
server.MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL);
|
2007-08-02 20:52:13 +00:00
|
|
|
}
|
2007-08-20 15:30:22 +00:00
|
|
|
else
|
2007-08-02 20:52:13 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
if (curNumPlayers == 0)
|
|
|
|
|
{
|
|
|
|
|
// First player is admin.
|
|
|
|
|
session.playerData->SetRights(PLAYER_RIGHTS_ADMIN);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 22:55:39 +00:00
|
|
|
// Send ack to client.
|
|
|
|
|
boost::shared_ptr<NetPacket> joinGameAck(new NetPacketJoinGameAck);
|
|
|
|
|
NetPacketJoinGameAck::Data joinGameAckData;
|
|
|
|
|
joinGameAckData.gameId = server.GetId();
|
|
|
|
|
joinGameAckData.prights = session.playerData->GetRights();
|
|
|
|
|
joinGameAckData.gameData = server.GetGameData();
|
|
|
|
|
static_cast<NetPacketJoinGameAck *>(joinGameAck.get())->SetData(joinGameAckData);
|
|
|
|
|
server.GetSender().Send(session.sessionData->GetSocket(), joinGameAck);
|
|
|
|
|
|
|
|
|
|
// Send notifications for connected players to client.
|
2007-09-02 20:59:16 +00:00
|
|
|
PlayerDataList tmpPlayerList = server.GetFullPlayerDataList();
|
2007-08-20 22:55:39 +00:00
|
|
|
PlayerDataList::iterator player_i = tmpPlayerList.begin();
|
|
|
|
|
PlayerDataList::iterator player_end = tmpPlayerList.end();
|
|
|
|
|
while (player_i != player_end)
|
|
|
|
|
{
|
|
|
|
|
server.GetSender().Send(session.sessionData->GetSocket(), CreateNetPacketPlayerJoined(*(*player_i)));
|
|
|
|
|
++player_i;
|
2007-08-20 15:30:22 +00:00
|
|
|
}
|
2007-08-20 22:55:39 +00:00
|
|
|
|
|
|
|
|
// Send "Player Joined" to other fully connected clients.
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(CreateNetPacketPlayerJoined(*session.playerData), SessionData::Game);
|
2007-08-20 22:55:39 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
// Accept session.
|
|
|
|
|
server.GetSessionManager().AddSession(session);
|
2007-09-02 16:36:52 +00:00
|
|
|
|
|
|
|
|
// Notify lobby.
|
|
|
|
|
server.GetLobbyThread().NotifyPlayerJoinedGame(server.GetId(), session.playerData->GetUniqueId());
|
2007-08-02 20:52:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-08-20 15:30:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ServerGameStateInit::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
|
|
|
|
{
|
|
|
|
|
int retVal = MSG_SOCK_INIT_DONE;
|
|
|
|
|
|
|
|
|
|
if (packet->ToNetPacketStartEvent())
|
2007-08-02 20:52:13 +00:00
|
|
|
{
|
2007-09-05 19:14:34 +00:00
|
|
|
NetPacketStartEvent::Data startData;
|
|
|
|
|
packet->ToNetPacketStartEvent()->GetData(startData);
|
|
|
|
|
|
2007-08-11 21:21:41 +00:00
|
|
|
server.ResetComputerPlayerList();
|
2007-09-05 19:14:34 +00:00
|
|
|
|
|
|
|
|
if (startData.fillUpWithCpuPlayers)
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
2007-09-05 19:14:34 +00:00
|
|
|
int remainingSlots = server.GetGameData().maxNumberOfPlayers - server.GetCurNumberOfPlayers();
|
|
|
|
|
for (int i = 1; i <= remainingSlots; i++)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayerData(
|
|
|
|
|
new PlayerData(server.GetLobbyThread().GetNextUniquePlayerId(), 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL));
|
2007-08-06 21:38:09 +00:00
|
|
|
|
2007-09-05 19:14:34 +00:00
|
|
|
ostringstream name;
|
|
|
|
|
name << SERVER_COMPUTER_PLAYER_NAME << i;
|
|
|
|
|
tmpPlayerData->SetName(name.str());
|
|
|
|
|
server.AddComputerPlayer(tmpPlayerData);
|
2007-08-06 21:38:09 +00:00
|
|
|
|
2007-09-05 19:14:34 +00:00
|
|
|
// Send "Player Joined" to other fully connected clients.
|
|
|
|
|
server.SendToAllPlayers(CreateNetPacketPlayerJoined(*tmpPlayerData), SessionData::Game);
|
|
|
|
|
}
|
2007-09-02 20:59:16 +00:00
|
|
|
}
|
2007-08-06 21:38:09 +00:00
|
|
|
|
2007-08-02 20:52:13 +00:00
|
|
|
server.InternalStartGame();
|
|
|
|
|
server.SetState(SERVER_START_GAME_STATE::Instance());
|
|
|
|
|
}
|
|
|
|
|
else if (packet->ToNetPacketKickPlayer())
|
|
|
|
|
{
|
|
|
|
|
NetPacketKickPlayer::Data kickPlayerData;
|
|
|
|
|
packet->ToNetPacketKickPlayer()->GetData(kickPlayerData);
|
|
|
|
|
|
|
|
|
|
server.InternalKickPlayer(kickPlayerData.playerId);
|
|
|
|
|
}
|
|
|
|
|
else
|
2007-05-25 16:03:12 +00:00
|
|
|
{
|
|
|
|
|
server.SessionError(session, ERR_SOCK_INVALID_PACKET);
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-28 13:07:06 +00:00
|
|
|
return retVal;
|
2007-03-20 02:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-11 20:24:08 +00:00
|
|
|
boost::shared_ptr<NetPacket>
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateInit::CreateNetPacketPlayerJoined(const PlayerData &playerData)
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 02:20:50 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateRunning::AbstractServerGameStateRunning()
|
2007-05-24 20:26:23 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateRunning::~AbstractServerGameStateRunning()
|
2007-05-24 20:26:23 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 22:55:39 +00:00
|
|
|
void
|
2007-08-20 15:30:22 +00:00
|
|
|
AbstractServerGameStateRunning::HandleNewSession(ServerGameThread &server, SessionWrapper session)
|
2007-05-24 20:26:23 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
// Do not accept new sessions in this state.
|
2007-09-06 19:09:05 +00:00
|
|
|
server.MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING);
|
2007-05-24 20:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateStartGame> ServerGameStateStartGame::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartGame &
|
|
|
|
|
ServerGameStateStartGame::Instance()
|
2007-03-20 02:20:50 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateStartGame);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-03-20 02:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartGame::ServerGameStateStartGame()
|
2007-03-20 02:20:50 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartGame::~ServerGameStateStartGame()
|
2007-03-20 02:20:50 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartGame::Process(ServerGameThread &server)
|
2007-03-20 02:20:50 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
|
|
|
|
|
|
2007-05-18 17:13:27 +00:00
|
|
|
NetPacketGameStart::Data gameStartData;
|
2007-05-20 00:16:29 +00:00
|
|
|
gameStartData.startData = server.GetStartData();
|
2007-07-24 14:55:14 +00:00
|
|
|
|
2007-08-11 10:02:04 +00:00
|
|
|
// Send player order to clients.
|
|
|
|
|
// Assume player list is sorted by number.
|
2007-09-02 20:59:16 +00:00
|
|
|
PlayerDataList tmpPlayerList = server.GetFullPlayerDataList();
|
2007-07-24 14:55:14 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-18 17:13:27 +00:00
|
|
|
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
|
|
|
|
|
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(answer, SessionData::Game);
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartHand::Instance());
|
2007-05-13 22:25:59 +00:00
|
|
|
|
|
|
|
|
return MSG_NET_GAME_SERVER_START;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateStartHand> ServerGameStateStartHand::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartHand &
|
|
|
|
|
ServerGameStateStartHand::Instance()
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateStartHand);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-05-13 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartHand::ServerGameStateStartHand()
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartHand::~ServerGameStateStartHand()
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartHand::Process(ServerGameThread &server)
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> answer(new NetPacketHandStart);
|
|
|
|
|
|
2007-05-14 12:40:42 +00:00
|
|
|
// Initialize hand.
|
2007-05-13 22:25:59 +00:00
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
curGame.initHand();
|
2007-05-25 19:53:07 +00:00
|
|
|
|
2007-05-26 17:06:03 +00:00
|
|
|
// HACK: Skip GUI notification run
|
|
|
|
|
curGame.getCurrentHand()->getFlop()->resetFirstRun();
|
|
|
|
|
curGame.getCurrentHand()->getTurn()->resetFirstRun();
|
|
|
|
|
curGame.getCurrentHand()->getRiver()->resetFirstRun();
|
|
|
|
|
|
2007-09-27 14:17:07 +00:00
|
|
|
// Consider all players, even inactive.
|
|
|
|
|
PlayerListIterator i = curGame.getSeatsList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getSeatsList()->end();
|
2007-05-13 22:25:59 +00:00
|
|
|
|
2007-05-14 12:40:42 +00:00
|
|
|
// Send cards to all players.
|
2007-09-27 14:17:07 +00:00
|
|
|
while (i != end)
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
2007-06-15 20:56:31 +00:00
|
|
|
// also send to inactive players, but not to disconnected players.
|
2007-09-27 14:17:07 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
|
|
|
|
if (tmpPlayer->getNetSessionData().get())
|
2007-06-15 20:56:31 +00:00
|
|
|
{
|
|
|
|
|
int cards[2];
|
2007-09-27 14:17:07 +00:00
|
|
|
tmpPlayer->getMyCards(cards);
|
2007-06-15 20:56:31 +00:00
|
|
|
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]);
|
|
|
|
|
static_cast<NetPacketHandStart *>(notifyCards.get())->SetData(handStartData);
|
2007-05-13 22:25:59 +00:00
|
|
|
|
2007-09-27 14:17:07 +00:00
|
|
|
server.GetSender().Send(tmpPlayer->getNetSessionData()->GetSocket(), notifyCards);
|
2007-06-15 20:56:31 +00:00
|
|
|
}
|
2007-09-27 14:17:07 +00:00
|
|
|
++i;
|
2007-05-13 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-23 22:31:56 +00:00
|
|
|
// Start hand.
|
|
|
|
|
curGame.startHand();
|
|
|
|
|
|
2007-05-23 08:57:34 +00:00
|
|
|
// Auto small blind / big blind at the beginning of hand.
|
2007-09-27 14:17:07 +00:00
|
|
|
i = curGame.getActivePlayerList()->begin();
|
|
|
|
|
end = curGame.getActivePlayerList()->end();
|
|
|
|
|
|
|
|
|
|
while (i != end)
|
2007-05-21 22:16:32 +00:00
|
|
|
{
|
2007-09-27 14:17:07 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
|
|
|
|
if (tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND)
|
2007-05-22 23:27:21 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> notifySmallBlind(new NetPacketPlayersActionDone);
|
|
|
|
|
NetPacketPlayersActionDone::Data actionDoneData;
|
|
|
|
|
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
|
2007-09-27 14:17:07 +00:00
|
|
|
actionDoneData.playerId = tmpPlayer->getMyUniqueID();
|
|
|
|
|
actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction();
|
|
|
|
|
actionDoneData.totalPlayerBet = tmpPlayer->getMySet();
|
|
|
|
|
actionDoneData.playerMoney = tmpPlayer->getMyCash();
|
2007-05-22 23:27:21 +00:00
|
|
|
static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notifySmallBlind, SessionData::Game);
|
2007-05-22 23:27:21 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2007-09-27 14:17:07 +00:00
|
|
|
++i;
|
2007-05-21 22:16:32 +00:00
|
|
|
}
|
2007-09-27 14:17:07 +00:00
|
|
|
|
|
|
|
|
i = curGame.getActivePlayerList()->begin();
|
|
|
|
|
end = curGame.getActivePlayerList()->end();
|
|
|
|
|
while (i != end)
|
2007-05-21 22:16:32 +00:00
|
|
|
{
|
2007-09-27 14:17:07 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
|
|
|
|
if (tmpPlayer->getMyButton() == BUTTON_BIG_BLIND)
|
2007-05-22 23:27:21 +00:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> notifyBigBlind(new NetPacketPlayersActionDone);
|
|
|
|
|
NetPacketPlayersActionDone::Data actionDoneData;
|
|
|
|
|
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
|
2007-09-27 14:17:07 +00:00
|
|
|
actionDoneData.playerId = tmpPlayer->getMyUniqueID();
|
|
|
|
|
actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction();
|
|
|
|
|
actionDoneData.totalPlayerBet = tmpPlayer->getMySet();
|
|
|
|
|
actionDoneData.playerMoney = tmpPlayer->getMyCash();
|
2007-05-22 23:27:21 +00:00
|
|
|
static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notifyBigBlind, SessionData::Game);
|
2007-05-22 23:27:21 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2007-09-27 14:17:07 +00:00
|
|
|
++i;
|
2007-05-21 22:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartRound::Instance());
|
2007-05-13 22:25:59 +00:00
|
|
|
|
2007-05-26 17:06:03 +00:00
|
|
|
return MSG_NET_GAME_SERVER_HAND_START;
|
2007-05-13 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateStartRound> ServerGameStateStartRound::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartRound &
|
|
|
|
|
ServerGameStateStartRound::Instance()
|
2007-05-14 12:40:42 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateStartRound);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-05-14 12:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartRound::ServerGameStateStartRound()
|
2007-05-14 12:40:42 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartRound::~ServerGameStateStartRound()
|
2007-05-14 12:40:42 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateStartRound::Process(ServerGameThread &server)
|
2007-05-14 12:40:42 +00:00
|
|
|
{
|
2007-05-26 17:06:03 +00:00
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
2007-05-14 12:40:42 +00:00
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
|
2007-06-05 21:28:47 +00:00
|
|
|
// Main game loop.
|
|
|
|
|
int curRound = curGame.getCurrentHand()->getActualRound();
|
|
|
|
|
curGame.getCurrentHand()->switchRounds();
|
2007-08-22 23:00:51 +00:00
|
|
|
if (!curGame.getCurrentHand()->getAllInCondition())
|
2007-08-07 20:37:34 +00:00
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->run();
|
2007-05-15 20:37:37 +00:00
|
|
|
int newRound = curGame.getCurrentHand()->getActualRound();
|
2007-06-05 21:28:47 +00:00
|
|
|
|
|
|
|
|
// If round changes, deal cards if needed.
|
2007-08-11 21:21:41 +00:00
|
|
|
if (newRound != curRound && newRound != GAME_STATE_POST_RIVER)
|
2007-05-15 20:37:37 +00:00
|
|
|
{
|
2007-06-05 21:28:47 +00:00
|
|
|
assert(newRound > curRound);
|
2007-09-27 14:17:07 +00:00
|
|
|
// Retrieve non-fold players. If only one player is left, no cards are shown.
|
|
|
|
|
PlayerList runningPlayers = curGame.getRunningPlayerList();
|
2007-06-06 21:16:52 +00:00
|
|
|
|
|
|
|
|
if (curGame.getCurrentHand()->getAllInCondition()
|
2007-06-07 14:06:22 +00:00
|
|
|
&& !curGame.getCurrentHand()->getCardsShown()
|
2007-09-27 14:17:07 +00:00
|
|
|
&& runningPlayers->size() > 1)
|
2007-06-06 21:16:52 +00:00
|
|
|
{
|
2007-06-07 14:06:22 +00:00
|
|
|
// Send cards of all active players to all players (all in).
|
|
|
|
|
boost::shared_ptr<NetPacket> allIn(new NetPacketAllInShowCards);
|
|
|
|
|
NetPacketAllInShowCards::Data allInData;
|
|
|
|
|
|
2007-09-27 14:17:07 +00:00
|
|
|
PlayerListConstIterator i = runningPlayers->begin();
|
|
|
|
|
PlayerListConstIterator end = runningPlayers->end();
|
2007-06-07 14:06:22 +00:00
|
|
|
|
|
|
|
|
while (i != end)
|
2007-06-06 21:16:52 +00:00
|
|
|
{
|
2007-06-07 14:06:22 +00:00
|
|
|
NetPacketAllInShowCards::PlayerCards tmpPlayerCards;
|
|
|
|
|
tmpPlayerCards.playerId = (*i)->getMyUniqueID();
|
2007-06-06 21:16:52 +00:00
|
|
|
|
2007-06-07 14:06:22 +00:00
|
|
|
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]);
|
2007-06-06 21:16:52 +00:00
|
|
|
|
2007-06-07 14:06:22 +00:00
|
|
|
allInData.playerCards.push_back(tmpPlayerCards);
|
|
|
|
|
++i;
|
2007-06-06 21:16:52 +00:00
|
|
|
}
|
2007-06-07 14:06:22 +00:00
|
|
|
static_cast<NetPacketAllInShowCards *>(allIn.get())->SetData(allInData);
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(allIn, SessionData::Game);
|
2007-06-07 14:06:22 +00:00
|
|
|
curGame.getCurrentHand()->setCardsShown(true);
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateShowCardsDelay::Instance());
|
2007-06-07 14:06:22 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
2007-06-06 21:16:52 +00:00
|
|
|
}
|
2007-06-07 14:06:22 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SendNewRoundCards(server, curGame, newRound);
|
2007-06-06 21:16:52 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateDealCardsDelay::Instance());
|
2007-06-07 14:06:22 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
|
|
|
|
}
|
2007-05-26 17:06:03 +00:00
|
|
|
}
|
2007-06-05 21:28:47 +00:00
|
|
|
else
|
2007-05-26 17:06:03 +00:00
|
|
|
{
|
2007-06-05 21:28:47 +00:00
|
|
|
if (newRound != GAME_STATE_POST_RIVER) // continue hand
|
|
|
|
|
{
|
2007-06-06 21:16:52 +00:00
|
|
|
assert (!curGame.getCurrentHand()->getAllInCondition()); // this would be an error.
|
2007-06-05 21:28:47 +00:00
|
|
|
|
2007-06-06 21:16:52 +00:00
|
|
|
// Retrieve current player.
|
2007-08-11 10:02:04 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> curPlayer = curGame.getCurrentPlayer();
|
|
|
|
|
assert(curPlayer.get()); // TODO throw exception
|
2007-06-06 21:16:52 +00:00
|
|
|
assert(curPlayer->getMyActiveStatus()); // TODO throw exception
|
2007-06-05 21:28:47 +00:00
|
|
|
|
2007-06-06 21:16:52 +00:00
|
|
|
boost::shared_ptr<NetPacket> notification(new NetPacketPlayersTurn);
|
|
|
|
|
NetPacketPlayersTurn::Data playersTurnData;
|
|
|
|
|
playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound();
|
|
|
|
|
playersTurnData.playerId = curPlayer->getMyUniqueID();
|
|
|
|
|
static_cast<NetPacketPlayersTurn *>(notification.get())->SetData(playersTurnData);
|
2007-06-05 21:28:47 +00:00
|
|
|
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(notification, SessionData::Game);
|
2007-06-05 21:28:47 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateWaitPlayerAction::Instance());
|
2007-06-06 21:16:52 +00:00
|
|
|
|
|
|
|
|
retVal = MSG_NET_GAME_SERVER_ROUND;
|
2007-05-27 13:24:52 +00:00
|
|
|
}
|
2007-06-05 21:28:47 +00:00
|
|
|
else // hand is over
|
2007-05-27 13:24:52 +00:00
|
|
|
{
|
2007-08-12 19:09:06 +00:00
|
|
|
// Engine will find out who won.
|
2007-08-22 23:00:51 +00:00
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun();
|
2007-08-12 19:09:06 +00:00
|
|
|
|
2007-09-27 14:17:07 +00:00
|
|
|
// Retrieve non-fold players. If only one player is left, no cards are shown.
|
|
|
|
|
PlayerList runningPlayers = curGame.getRunningPlayerList();
|
|
|
|
|
// if (runningPlayers.empty()) TODO throw exception
|
2007-05-26 17:06:03 +00:00
|
|
|
|
2007-09-27 14:17:07 +00:00
|
|
|
if (runningPlayers->size() == 1)
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
|
|
|
|
// End of Hand, but keep cards hidden.
|
2007-09-27 14:17:07 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> player = runningPlayers->front();
|
2007-06-05 21:28:47 +00:00
|
|
|
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandHideCards);
|
|
|
|
|
NetPacketEndOfHandHideCards::Data endHandData;
|
|
|
|
|
endHandData.playerId = player->getMyUniqueID();
|
|
|
|
|
endHandData.moneyWon = 0; // TODO
|
|
|
|
|
endHandData.playerMoney = player->getMyCash();
|
|
|
|
|
static_cast<NetPacketEndOfHandHideCards *>(endHand.get())->SetData(endHandData);
|
|
|
|
|
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(endHand, SessionData::Game);
|
2007-06-05 21:28:47 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// End of Hand - show cards of active players.
|
|
|
|
|
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandShowCards);
|
|
|
|
|
NetPacketEndOfHandShowCards::Data endHandData;
|
|
|
|
|
|
2007-09-27 14:17:07 +00:00
|
|
|
PlayerListConstIterator i = runningPlayers->begin();
|
|
|
|
|
PlayerListConstIterator end = runningPlayers->end();
|
2007-06-05 21:28:47 +00:00
|
|
|
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult;
|
|
|
|
|
tmpPlayerResult.playerId = (*i)->getMyUniqueID();
|
|
|
|
|
|
|
|
|
|
int tmpCards[2];
|
2007-06-11 17:48:22 +00:00
|
|
|
int bestHandPos[5];
|
2007-06-05 21:28:47 +00:00
|
|
|
(*i)->getMyCards(tmpCards);
|
|
|
|
|
tmpPlayerResult.cards[0] = static_cast<u_int16_t>(tmpCards[0]);
|
|
|
|
|
tmpPlayerResult.cards[1] = static_cast<u_int16_t>(tmpCards[1]);
|
|
|
|
|
|
2007-06-11 17:48:22 +00:00
|
|
|
(*i)->getMyBestHandPosition(bestHandPos);
|
2007-06-05 21:28:47 +00:00
|
|
|
for (int num = 0; num < 5; num++)
|
2007-06-11 17:48:22 +00:00
|
|
|
tmpPlayerResult.bestHandPos[num] = bestHandPos[num];
|
2007-06-05 21:28:47 +00:00
|
|
|
|
|
|
|
|
tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt();
|
|
|
|
|
tmpPlayerResult.moneyWon = 0; // TODO
|
|
|
|
|
tmpPlayerResult.playerMoney = (*i)->getMyCash();
|
|
|
|
|
|
|
|
|
|
endHandData.playerResults.push_back(tmpPlayerResult);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
static_cast<NetPacketEndOfHandShowCards *>(endHand.get())->SetData(endHandData);
|
|
|
|
|
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(endHand, SessionData::Game);
|
2007-06-05 21:28:47 +00:00
|
|
|
}
|
2007-06-15 10:38:41 +00:00
|
|
|
|
|
|
|
|
// Remove disconnected players. This is the one and only place to do this.
|
|
|
|
|
server.RemoveDisconnectedPlayers();
|
|
|
|
|
|
2007-06-05 21:28:47 +00:00
|
|
|
// Start next hand - if enough players are left.
|
|
|
|
|
int playersPositiveCashCounter = 0;
|
2007-09-27 14:17:07 +00:00
|
|
|
|
|
|
|
|
PlayerListIterator i = curGame.getSeatsList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getSeatsList()->end();
|
|
|
|
|
|
|
|
|
|
while (i != end)
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
2007-09-27 14:17:07 +00:00
|
|
|
if ((*i)->getMyCash() > 0)
|
2007-06-05 21:28:47 +00:00
|
|
|
playersPositiveCashCounter++;
|
2007-09-27 14:17:07 +00:00
|
|
|
++i;
|
2007-06-05 21:28:47 +00:00
|
|
|
}
|
2007-08-21 17:27:13 +00:00
|
|
|
if (!playersPositiveCashCounter)
|
|
|
|
|
{
|
|
|
|
|
// No more players left - restart.
|
|
|
|
|
server.SetState(SERVER_INITIAL_STATE::Instance());
|
|
|
|
|
retVal = MSG_NET_GAME_SERVER_END;
|
|
|
|
|
}
|
|
|
|
|
else if (playersPositiveCashCounter == 1)
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
|
|
|
|
// View a dialog for a new game - delayed.
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateNextGameDelay::Instance());
|
2007-06-10 23:28:25 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_END;
|
|
|
|
|
}
|
2007-06-05 21:28:47 +00:00
|
|
|
else
|
|
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateNextHandDelay::Instance());
|
2007-06-05 21:28:47 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_HAND_END;
|
|
|
|
|
}
|
2007-05-27 13:24:52 +00:00
|
|
|
}
|
2007-05-26 17:06:03 +00:00
|
|
|
}
|
|
|
|
|
return retVal;
|
2007-05-14 12:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-23 22:31:56 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateWaitPlayerAction> ServerGameStateWaitPlayerAction::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateWaitPlayerAction &
|
|
|
|
|
ServerGameStateWaitPlayerAction::Instance()
|
2007-05-23 22:31:56 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateWaitPlayerAction);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-05-23 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateWaitPlayerAction::ServerGameStateWaitPlayerAction()
|
2007-05-23 22:31:56 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateWaitPlayerAction::~ServerGameStateWaitPlayerAction()
|
2007-05-23 22:31:56 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-03 14:57:33 +00:00
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateWaitPlayerAction::Process(ServerGameThread &server)
|
2007-06-03 14:57:33 +00:00
|
|
|
{
|
|
|
|
|
int retVal;
|
|
|
|
|
|
2007-08-11 10:02:04 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = server.GetGame().getCurrentPlayer();
|
2007-08-10 23:52:31 +00:00
|
|
|
assert(tmpPlayer.get());
|
2007-06-15 10:38:41 +00:00
|
|
|
assert(!tmpPlayer->getMyName().empty());
|
2007-08-06 21:38:09 +00:00
|
|
|
|
|
|
|
|
// If the player is computer controlled, let the engine act.
|
|
|
|
|
if (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER)
|
|
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateComputerAction::Instance());
|
2007-08-11 20:24:08 +00:00
|
|
|
retVal = MSG_SOCK_INTERNAL_PENDING;
|
2007-08-06 21:38:09 +00:00
|
|
|
}
|
|
|
|
|
// If the player we are waiting for left, continue without him.
|
2007-08-20 15:30:22 +00:00
|
|
|
else if (!server.GetSessionManager().IsPlayerConnected(tmpPlayer->getMyName()))
|
2007-06-03 14:57:33 +00:00
|
|
|
{
|
|
|
|
|
PerformPlayerAction(server, tmpPlayer, PLAYER_ACTION_FOLD, 0);
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartRound::Instance());
|
2007-06-03 14:57:33 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_ACTION;
|
|
|
|
|
}
|
2007-06-14 20:29:59 +00:00
|
|
|
else if (GetTimer().elapsed().total_seconds() >= server.GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC)
|
2007-06-08 22:14:05 +00:00
|
|
|
{
|
|
|
|
|
// Player did not act fast enough. Act for him.
|
2007-08-07 21:17:11 +00:00
|
|
|
if (server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet() == tmpPlayer->getMySet())
|
2007-06-10 10:11:00 +00:00
|
|
|
PerformPlayerAction(server, tmpPlayer, PLAYER_ACTION_CHECK, 0);
|
|
|
|
|
else
|
|
|
|
|
PerformPlayerAction(server, tmpPlayer, PLAYER_ACTION_FOLD, 0);
|
2007-06-08 22:14:05 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartRound::Instance());
|
2007-06-08 22:14:05 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_ACTION;
|
|
|
|
|
}
|
2007-06-03 14:57:33 +00:00
|
|
|
else
|
2007-08-20 15:30:22 +00:00
|
|
|
retVal = AbstractServerGameStateReceiving::Process(server);
|
2007-06-03 14:57:33 +00:00
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-23 22:31:56 +00:00
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateWaitPlayerAction::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-05-23 22:31:56 +00:00
|
|
|
{
|
2007-05-24 20:26:23 +00:00
|
|
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
2007-05-23 22:31:56 +00:00
|
|
|
|
2007-05-25 16:03:12 +00:00
|
|
|
if (packet->ToNetPacketPlayersAction())
|
2007-05-23 22:31:56 +00:00
|
|
|
{
|
2007-05-25 16:03:12 +00:00
|
|
|
NetPacketPlayersAction::Data actionData;
|
|
|
|
|
packet->ToNetPacketPlayersAction()->GetData(actionData);
|
|
|
|
|
|
|
|
|
|
Game &curGame = server.GetGame();
|
2007-08-10 23:40:38 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId());
|
2007-08-10 23:52:31 +00:00
|
|
|
assert(tmpPlayer.get()); // TODO throw exception
|
2007-06-03 14:57:33 +00:00
|
|
|
// TODO: check whether this is the correct player
|
|
|
|
|
// TODO: check game state
|
2007-05-23 22:31:56 +00:00
|
|
|
|
2007-06-03 14:57:33 +00:00
|
|
|
PerformPlayerAction(server, tmpPlayer, actionData.playerAction, actionData.playerBet);
|
2007-05-24 23:38:40 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartRound::Instance());
|
2007-05-25 16:03:12 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_ACTION;
|
2007-05-23 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-24 20:26:23 +00:00
|
|
|
return retVal;
|
2007-05-23 22:31:56 +00:00
|
|
|
}
|
2007-05-15 20:37:37 +00:00
|
|
|
|
2007-06-03 14:57:33 +00:00
|
|
|
void
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateWaitPlayerAction::PerformPlayerAction(ServerGameThread &server, boost::shared_ptr<PlayerInterface> player, PlayerAction action, int bet)
|
2007-06-03 14:57:33 +00:00
|
|
|
{
|
|
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
assert(player);
|
|
|
|
|
player->setMyAction(action);
|
|
|
|
|
// Only change the player bet if action is not fold/check
|
|
|
|
|
if (action != PLAYER_ACTION_FOLD && action != PLAYER_ACTION_CHECK)
|
|
|
|
|
{
|
|
|
|
|
player->setMySet(bet);
|
|
|
|
|
|
2007-08-07 21:17:11 +00:00
|
|
|
if (player->getMySet() > curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet())
|
|
|
|
|
curGame.getCurrentHand()->getCurrentBeRo()->setHighestSet(player->getMySet());
|
2007-06-07 15:09:51 +00:00
|
|
|
// Update total sets.
|
|
|
|
|
curGame.getCurrentHand()->getBoard()->collectSets();
|
2007-06-03 14:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-06 21:38:09 +00:00
|
|
|
SendPlayerAction(server, player);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-11 20:24:08 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-08-06 21:38:09 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateComputerAction> ServerGameStateComputerAction::Ptr;
|
2007-08-11 20:24:08 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateComputerAction &
|
|
|
|
|
ServerGameStateComputerAction::Instance()
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
|
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateComputerAction);
|
2007-08-11 20:24:08 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateComputerAction::ServerGameStateComputerAction()
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateComputerAction::~ServerGameStateComputerAction()
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateComputerAction::Process(ServerGameThread &server)
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
int retVal = AbstractServerGameStateReceiving::Process(server);
|
2007-08-11 20:24:08 +00:00
|
|
|
|
|
|
|
|
if (GetTimer().elapsed().total_seconds() >= SERVER_COMPUTER_ACTION_DELAY_SEC)
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer = server.GetGame().getCurrentPlayer();
|
|
|
|
|
|
|
|
|
|
tmpPlayer->action();
|
|
|
|
|
SendPlayerAction(server, tmpPlayer);
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartRound::Instance());
|
2007-08-11 20:24:08 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_ACTION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateComputerAction::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-08-11 20:24:08 +00:00
|
|
|
{
|
|
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
2007-06-03 14:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-14 12:40:42 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateDealCardsDelay> ServerGameStateDealCardsDelay::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateDealCardsDelay &
|
|
|
|
|
ServerGameStateDealCardsDelay::Instance()
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateDealCardsDelay);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-06-05 21:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateDealCardsDelay::ServerGameStateDealCardsDelay()
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateDealCardsDelay::~ServerGameStateDealCardsDelay()
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateDealCardsDelay::Process(ServerGameThread &server)
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
int retVal = AbstractServerGameStateReceiving::Process(server);
|
2007-06-05 21:28:47 +00:00
|
|
|
|
|
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
|
2007-06-07 14:06:22 +00:00
|
|
|
int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0;
|
2007-06-08 20:19:21 +00:00
|
|
|
int delay = 0;
|
2007-06-05 21:28:47 +00:00
|
|
|
|
|
|
|
|
switch(curGame.getCurrentHand()->getActualRound())
|
|
|
|
|
{
|
|
|
|
|
case GAME_STATE_FLOP:
|
2007-06-10 21:45:31 +00:00
|
|
|
delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC;
|
2007-06-05 21:28:47 +00:00
|
|
|
break;
|
|
|
|
|
case GAME_STATE_TURN:
|
2007-06-10 21:45:31 +00:00
|
|
|
delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay;
|
2007-06-05 21:28:47 +00:00
|
|
|
break;
|
|
|
|
|
case GAME_STATE_RIVER:
|
2007-06-08 20:19:21 +00:00
|
|
|
delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC;
|
2007-06-05 21:28:47 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2007-06-14 20:29:59 +00:00
|
|
|
if (!delay || GetTimer().elapsed().total_seconds() >= delay)
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartRound::Instance());
|
2007-06-08 20:19:21 +00:00
|
|
|
|
2007-06-05 21:28:47 +00:00
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateDealCardsDelay::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-06-05 21:28:47 +00:00
|
|
|
{
|
|
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateShowCardsDelay> ServerGameStateShowCardsDelay::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateShowCardsDelay &
|
|
|
|
|
ServerGameStateShowCardsDelay::Instance()
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateShowCardsDelay);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-06-07 14:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateShowCardsDelay::ServerGameStateShowCardsDelay()
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateShowCardsDelay::~ServerGameStateShowCardsDelay()
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateShowCardsDelay::Process(ServerGameThread &server)
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
int retVal = AbstractServerGameStateReceiving::Process(server);
|
2007-06-07 14:06:22 +00:00
|
|
|
|
2007-06-14 20:29:59 +00:00
|
|
|
if (GetTimer().elapsed().total_seconds() >= SERVER_SHOW_CARDS_DELAY_SEC)
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
2007-06-10 23:28:25 +00:00
|
|
|
Game &curGame = server.GetGame();
|
2007-06-07 14:06:22 +00:00
|
|
|
SendNewRoundCards(server, curGame, curGame.getCurrentHand()->getActualRound());
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateDealCardsDelay::Instance());
|
2007-06-07 14:06:22 +00:00
|
|
|
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateShowCardsDelay::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-06-07 14:06:22 +00:00
|
|
|
{
|
|
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateNextHandDelay> ServerGameStateNextHandDelay::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextHandDelay &
|
|
|
|
|
ServerGameStateNextHandDelay::Instance()
|
2007-05-26 17:06:03 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateNextHandDelay);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-05-26 17:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextHandDelay::ServerGameStateNextHandDelay()
|
2007-05-26 17:06:03 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextHandDelay::~ServerGameStateNextHandDelay()
|
2007-05-26 17:06:03 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextHandDelay::Process(ServerGameThread &server)
|
2007-05-26 17:06:03 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
int retVal = AbstractServerGameStateReceiving::Process(server);
|
2007-06-02 16:35:41 +00:00
|
|
|
|
2007-06-14 20:29:59 +00:00
|
|
|
if (GetTimer().elapsed().total_seconds() >= SERVER_DELAY_NEXT_HAND_SEC)
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateStartHand::Instance());
|
2007-05-26 17:06:03 +00:00
|
|
|
|
2007-06-02 16:35:41 +00:00
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextHandDelay::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
|
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateNextGameDelay> ServerGameStateNextGameDelay::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextGameDelay &
|
|
|
|
|
ServerGameStateNextGameDelay::Instance()
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateNextGameDelay);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-06-10 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextGameDelay::ServerGameStateNextGameDelay()
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextGameDelay::~ServerGameStateNextGameDelay()
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextGameDelay::Process(ServerGameThread &server)
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
2007-08-20 15:30:22 +00:00
|
|
|
int retVal = AbstractServerGameStateReceiving::Process(server);
|
2007-06-10 23:28:25 +00:00
|
|
|
|
2007-06-14 20:29:59 +00:00
|
|
|
if (GetTimer().elapsed().total_seconds() >= SERVER_DELAY_NEXT_GAME_SEC)
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
|
|
|
|
Game &curGame = server.GetGame();
|
|
|
|
|
// The game has ended. Notify all clients.
|
2007-08-10 23:40:38 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> winnerPlayer;
|
2007-09-27 14:17:07 +00:00
|
|
|
PlayerListIterator i = curGame.getActivePlayerList()->begin();
|
|
|
|
|
PlayerListIterator end = curGame.getActivePlayerList()->end();
|
|
|
|
|
while (i != end)
|
2007-06-10 23:28:25 +00:00
|
|
|
{
|
2007-09-27 14:17:07 +00:00
|
|
|
winnerPlayer = *i;
|
2007-06-10 23:28:25 +00:00
|
|
|
if (winnerPlayer->getMyCash() > 0)
|
|
|
|
|
break;
|
2007-09-27 14:17:07 +00:00
|
|
|
++i;
|
2007-06-10 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket> endGame(new NetPacketEndOfGame);
|
|
|
|
|
NetPacketEndOfGame::Data endGameData;
|
|
|
|
|
endGameData.winnerPlayerId = winnerPlayer->getMyUniqueID();
|
|
|
|
|
static_cast<NetPacketEndOfGame *>(endGame.get())->SetData(endGameData);
|
|
|
|
|
|
2007-08-21 13:18:18 +00:00
|
|
|
server.SendToAllPlayers(endGame, SessionData::Game);
|
2007-06-10 23:28:25 +00:00
|
|
|
|
2007-08-02 20:52:13 +00:00
|
|
|
// Wait for the start of a new game.
|
2007-08-20 15:30:22 +00:00
|
|
|
server.SetState(ServerGameStateInit::Instance());
|
2007-06-10 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateNextGameDelay::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-06-02 16:35:41 +00:00
|
|
|
{
|
2007-05-26 17:06:03 +00:00
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
boost::thread_specific_ptr<ServerGameStateFinal> ServerGameStateFinal::Ptr;
|
2007-08-11 10:02:04 +00:00
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateFinal &
|
|
|
|
|
ServerGameStateFinal::Instance()
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
2007-08-11 10:02:04 +00:00
|
|
|
if (!Ptr.get())
|
2007-08-20 15:30:22 +00:00
|
|
|
Ptr.reset(new ServerGameStateFinal);
|
2007-08-11 10:02:04 +00:00
|
|
|
|
|
|
|
|
return *Ptr;
|
2007-05-13 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateFinal::ServerGameStateFinal()
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateFinal::~ServerGameStateFinal()
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2007-08-20 15:30:22 +00:00
|
|
|
ServerGameStateFinal::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
2007-05-13 22:25:59 +00:00
|
|
|
{
|
2007-03-20 11:56:30 +00:00
|
|
|
return MSG_SOCK_INTERNAL_PENDING;
|
2007-03-13 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|