Network: First round seems to work fine now. Pot/sets not yet displayed correctly.
This commit is contained in:
@@ -498,16 +498,18 @@ ClientStateWaitHand::~ClientStateWaitHand()
|
||||
int
|
||||
ClientStateWaitHand::Process(ClientThread &client)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// delegate to receiver helper class
|
||||
// Delegate to receiver helper class.
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
{
|
||||
// TODO: Hack
|
||||
if (tmpPacket->ToNetPacketHandStart())
|
||||
{
|
||||
// Hand was started.
|
||||
// These are the cards. Good luck.
|
||||
NetPacketHandStart::Data tmpData;
|
||||
tmpPacket->ToNetPacketHandStart()->GetData(tmpData);
|
||||
int myCards[2];
|
||||
@@ -517,12 +519,48 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
client.GetGame()->initHand();
|
||||
client.GetGame()->startHand();
|
||||
client.GetGui().dealHoleCards();
|
||||
client.SetState(ClientStateRunHand::Instance());
|
||||
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND;
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayersActionDone())
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ClientStateRunHand &
|
||||
ClientStateRunHand::Instance()
|
||||
{
|
||||
static ClientStateRunHand state;
|
||||
return state;
|
||||
}
|
||||
|
||||
ClientStateRunHand::ClientStateRunHand()
|
||||
{
|
||||
}
|
||||
|
||||
ClientStateRunHand::~ClientStateRunHand()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ClientStateRunHand::Process(ClientThread &client)
|
||||
{
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// Delegate to receiver helper class.
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
{
|
||||
boost::shared_ptr<Game> curGame = client.GetGame();
|
||||
if (tmpPacket->ToNetPacketPlayersActionDone())
|
||||
{
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
tmpPacket->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
|
||||
PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(actionDoneData.playerId);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
|
||||
if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND)
|
||||
@@ -531,10 +569,10 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
tmpPlayer->setMyButton(BUTTON_BIG_BLIND);
|
||||
|
||||
tmpPlayer->setMyAction(actionDoneData.playerAction);
|
||||
tmpPlayer->setMySet(actionDoneData.playerBet);
|
||||
//assert(tmpPlayer->getMyCash() == actionDoneData.curPlayerMoney); // TODO: throw exception
|
||||
client.GetGame()->getCurrentHand()->getBoard()->setPot(actionDoneData.potSize);
|
||||
client.GetGame()->getCurrentHand()->getBoard()->setSets(actionDoneData.curHandBets);
|
||||
tmpPlayer->setMySetAbsolute(actionDoneData.totalPlayerBet);
|
||||
tmpPlayer->setMyCash(actionDoneData.playerMoney);
|
||||
curGame->getCurrentHand()->getBoard()->setPot(actionDoneData.potSize);
|
||||
curGame->getCurrentHand()->getBoard()->setSets(actionDoneData.curHandBets);
|
||||
client.GetGui().refreshSet();
|
||||
client.GetGui().refreshPot();
|
||||
client.GetGui().refreshAction();
|
||||
@@ -543,13 +581,36 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
{
|
||||
NetPacketPlayersTurn::Data turnData;
|
||||
tmpPacket->ToNetPacketPlayersTurn()->GetData(turnData);
|
||||
PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(turnData.playerId);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
|
||||
if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
|
||||
{
|
||||
client.GetGui().meInAction();
|
||||
// Set round.
|
||||
curGame->getCurrentHand()->setActualRound(turnData.gameState);
|
||||
|
||||
// Next player's turn.
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(turnData.gameState) {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
curGame->getCurrentHand()->getPreflop()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
case GAME_STATE_FLOP: {
|
||||
curGame->getCurrentHand()->getFlop()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
case GAME_STATE_TURN: {
|
||||
curGame->getCurrentHand()->getTurn()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
case GAME_STATE_RIVER: {
|
||||
curGame->getCurrentHand()->getRiver()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
default: {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
client.GetGui().nextPlayerAnimation();
|
||||
|
||||
if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
|
||||
client.GetGui().meInAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,14 +84,15 @@ ClientThread::Init(
|
||||
void
|
||||
ClientThread::SendPlayerAction()
|
||||
{
|
||||
// TODO: ugly hack
|
||||
|
||||
// Warning: This function is called in the context of the GUI thread.
|
||||
// Create a network packet containing the current player action.
|
||||
boost::shared_ptr<NetPacket> action(new NetPacketPlayersAction);
|
||||
NetPacketPlayersAction::Data actionData;
|
||||
actionData.gameState = (GameState)GetGame()->getCurrentHand()->getActualRound();
|
||||
actionData.playerAction = (PlayerAction)GetGame()->getPlayerArray()[0]->getMyAction();
|
||||
actionData.playerBet = GetGame()->getPlayerArray()[0]->getMySet();
|
||||
actionData.gameState = static_cast<GameState>(GetGame()->getCurrentHand()->getActualRound());
|
||||
actionData.playerAction = static_cast<PlayerAction>(GetGame()->getPlayerArray()[0]->getMyAction());
|
||||
actionData.playerBet = GetGame()->getPlayerArray()[0]->getMyLastRelativeSet();
|
||||
static_cast<NetPacketPlayersAction *>(action.get())->SetData(actionData);
|
||||
// The sender is thread-safe, so just dump the packet.
|
||||
GetSender().Send(GetContext().GetSocket(), action);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,8 +150,8 @@ struct GCC_PACKED NetPacketPlayersActionDoneData
|
||||
u_int16_t playerId;
|
||||
u_int16_t playerAction;
|
||||
u_int16_t reserved;
|
||||
u_int32_t playerBet;
|
||||
u_int32_t curPlayerMoney;
|
||||
u_int32_t totalPlayerBet;
|
||||
u_int32_t playerMoney;
|
||||
u_int32_t potSize;
|
||||
u_int32_t curHandBets;
|
||||
};
|
||||
@@ -1064,8 +1064,8 @@ NetPacketPlayersActionDone::SetData(const NetPacketPlayersActionDone::Data &inDa
|
||||
tmpData->gameState = htons(inData.gameState);
|
||||
tmpData->playerId = htons(inData.playerId);
|
||||
tmpData->playerAction = htons(inData.playerAction);
|
||||
tmpData->playerBet = htonl(inData.playerBet);
|
||||
tmpData->curPlayerMoney = htonl(inData.curPlayerMoney);
|
||||
tmpData->totalPlayerBet = htonl(inData.totalPlayerBet);
|
||||
tmpData->playerMoney = htonl(inData.playerMoney);
|
||||
tmpData->potSize = htonl(inData.potSize);
|
||||
tmpData->curHandBets = htonl(inData.curHandBets);
|
||||
}
|
||||
@@ -1079,8 +1079,8 @@ NetPacketPlayersActionDone::GetData(NetPacketPlayersActionDone::Data &outData) c
|
||||
outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState));
|
||||
outData.playerId = ntohs(tmpData->playerId);
|
||||
outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction));
|
||||
outData.playerBet = ntohl(tmpData->playerBet);
|
||||
outData.curPlayerMoney = ntohl(tmpData->curPlayerMoney);
|
||||
outData.totalPlayerBet = ntohl(tmpData->totalPlayerBet);
|
||||
outData.playerMoney = ntohl(tmpData->playerMoney);
|
||||
outData.potSize = ntohl(tmpData->potSize);
|
||||
outData.curHandBets = ntohl(tmpData->curHandBets);
|
||||
}
|
||||
|
||||
@@ -207,6 +207,23 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateRunning::ServerRecvStateRunning()
|
||||
{
|
||||
}
|
||||
|
||||
ServerRecvStateRunning::~ServerRecvStateRunning()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateRunning::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateStartGame &
|
||||
ServerRecvStateStartGame::Instance()
|
||||
{
|
||||
@@ -222,13 +239,6 @@ ServerRecvStateStartGame::~ServerRecvStateStartGame()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartGame::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartGame::Process(ServerRecvThread &server)
|
||||
{
|
||||
@@ -261,13 +271,6 @@ ServerRecvStateStartHand::~ServerRecvStateStartHand()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartHand::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
{
|
||||
@@ -307,8 +310,8 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
|
||||
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
||||
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
||||
actionDoneData.playerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.curPlayerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.totalPlayerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.playerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot();
|
||||
actionDoneData.curHandBets = playerArray[i]->getMySet(); // first bet only
|
||||
static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
|
||||
@@ -325,8 +328,8 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
|
||||
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
||||
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
||||
actionDoneData.playerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.curPlayerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.totalPlayerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.playerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot();
|
||||
actionDoneData.curHandBets = curGame.getCurrentHand()->getBoard()->getSets();
|
||||
static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
|
||||
@@ -357,13 +360,6 @@ ServerRecvStateStartRound::~ServerRecvStateStartRound()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartRound::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
||||
{
|
||||
@@ -402,19 +398,19 @@ ServerRecvStateStartRound::GameRun(Game &curGame, int state)
|
||||
{
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(state) {
|
||||
case 0: {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
// Preflop starten
|
||||
curGame.getCurrentHand()->getPreflop()->preflopRun();
|
||||
} break;
|
||||
case 1: {
|
||||
case GAME_STATE_FLOP: {
|
||||
// Flop starten
|
||||
curGame.getCurrentHand()->getFlop()->flopRun();
|
||||
} break;
|
||||
case 2: {
|
||||
case GAME_STATE_TURN: {
|
||||
// Turn starten
|
||||
curGame.getCurrentHand()->getTurn()->turnRun();
|
||||
} break;
|
||||
case 3: {
|
||||
case GAME_STATE_RIVER: {
|
||||
// River starten
|
||||
curGame.getCurrentHand()->getRiver()->riverRun();
|
||||
} break;
|
||||
@@ -430,16 +426,16 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame)
|
||||
int curPlayerNum = 0;
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(curGame.getCurrentHand()->getActualRound()) {
|
||||
case 0: {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getPreflop()->getPlayersTurn();
|
||||
} break;
|
||||
case 1: {
|
||||
case GAME_STATE_FLOP: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getFlop()->getPlayersTurn();
|
||||
} break;
|
||||
case 2: {
|
||||
case GAME_STATE_TURN: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getTurn()->getPlayersTurn();
|
||||
} break;
|
||||
case 3: {
|
||||
case GAME_STATE_RIVER: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getRiver()->getPlayersTurn();
|
||||
} break;
|
||||
default: {
|
||||
@@ -467,17 +463,10 @@ ServerRecvStateWaitPlayerAction::~ServerRecvStateWaitPlayerAction()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateWaitPlayerAction::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateWaitPlayerAction::Process(ServerRecvThread &server)
|
||||
{
|
||||
int retVal = MSG_SOCK_INIT_DONE;
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
SOCKET recvSock = server.Select();
|
||||
|
||||
if (recvSock != INVALID_SOCKET)
|
||||
@@ -505,23 +494,31 @@ ServerRecvStateWaitPlayerAction::Process(ServerRecvThread &server)
|
||||
packet->ToNetPacketPlayersAction()->GetData(actionData);
|
||||
|
||||
Game &curGame = server.GetGame();
|
||||
PlayerInterface *tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId());
|
||||
assert(tmpPlayer); // TODO throw exception
|
||||
|
||||
tmpPlayer->setMyAction(actionData.playerAction);
|
||||
tmpPlayer->setMySet(actionData.playerBet);
|
||||
|
||||
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
actionDoneData.gameState = GAME_STATE_PREFLOP; // TODO
|
||||
actionDoneData.gameState = static_cast<GameState>(curGame.getCurrentHand()->getActualRound());
|
||||
actionDoneData.playerId = session.playerData->GetUniqueId();
|
||||
actionDoneData.playerAction = actionData.playerAction;
|
||||
actionDoneData.playerBet = actionData.playerBet;
|
||||
actionDoneData.curPlayerMoney = 0;
|
||||
actionDoneData.totalPlayerBet = tmpPlayer->getMySet();
|
||||
actionDoneData.playerMoney = tmpPlayer->getMyCash();
|
||||
actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot();
|
||||
actionDoneData.curHandBets = curGame.getCurrentHand()->getBoard()->getSets();
|
||||
static_cast<NetPacketPlayersActionDone *>(notifyActionDone.get())->SetData(actionDoneData);
|
||||
server.SendToAllPlayers(notifyActionDone);
|
||||
|
||||
server.SetState(ServerRecvStateStartRound::Instance());
|
||||
retVal = MSG_NET_GAME_SERVER_ACTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -541,13 +538,6 @@ ServerRecvStateFinal::~ServerRecvStateFinal()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateFinal::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateFinal::Process(ServerRecvThread &server)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user