Chat messages are now working.
This commit is contained in:
+106
-91
@@ -357,6 +357,43 @@ ClientStateStartSession::Process(ClientThread &client)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AbstractClientStateReceiving::AbstractClientStateReceiving()
|
||||
{
|
||||
}
|
||||
|
||||
AbstractClientStateReceiving::~AbstractClientStateReceiving()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
AbstractClientStateReceiving::Process(ClientThread &client)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
|
||||
// delegate to receiver helper class
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(client.GetContext().GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
{
|
||||
if (tmpPacket->ToNetPacketChatText())
|
||||
{
|
||||
// Chat message - display it in the GUI.
|
||||
NetPacketChatText::Data chatData;
|
||||
tmpPacket->ToNetPacketChatText()->GetData(chatData);
|
||||
|
||||
boost::shared_ptr<PlayerData> tmpPlayer = client.GetPlayerDataByUniqueId(chatData.playerId);
|
||||
if (tmpPlayer.get())
|
||||
client.GetCallback().SignalNetClientChatMsg(tmpPlayer->GetName(), chatData.text);
|
||||
}
|
||||
else
|
||||
retVal = InternalProcess(client, tmpPacket);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ClientStateWaitSession &
|
||||
ClientStateWaitSession::Instance()
|
||||
{
|
||||
@@ -373,43 +410,36 @@ ClientStateWaitSession::~ClientStateWaitSession()
|
||||
}
|
||||
|
||||
int
|
||||
ClientStateWaitSession::Process(ClientThread &client)
|
||||
ClientStateWaitSession::InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// delegate to receiver helper class
|
||||
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
if (packet->ToNetPacketJoinGameAck())
|
||||
{
|
||||
if (tmpPacket->ToNetPacketJoinGameAck())
|
||||
{
|
||||
// Everything is fine - we joined the game.
|
||||
// Initialize game configuration.
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||
client.SetGameData(joinGameAckData.gameData);
|
||||
client.SetGuiPlayerNum(joinGameAckData.yourPlayerNum);
|
||||
// Everything is fine - we joined the game.
|
||||
// Initialize game configuration.
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
packet->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||
client.SetGameData(joinGameAckData.gameData);
|
||||
client.SetGuiPlayerNum(joinGameAckData.yourPlayerNum);
|
||||
|
||||
// TODO: Type Human is fixed here.
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(joinGameAckData.yourPlayerUniqueId, joinGameAckData.yourPlayerNum, PLAYER_TYPE_HUMAN));
|
||||
playerData->SetName(context.GetPlayerName());
|
||||
client.AddPlayerData(playerData);
|
||||
// TODO: Type Human is fixed here.
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(joinGameAckData.yourPlayerUniqueId, joinGameAckData.yourPlayerNum, PLAYER_TYPE_HUMAN));
|
||||
playerData->SetName(context.GetPlayerName());
|
||||
client.AddPlayerData(playerData);
|
||||
|
||||
client.SetState(ClientStateWaitGame::Instance());
|
||||
retVal = MSG_SOCK_SESSION_DONE;
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketError())
|
||||
{
|
||||
// Server reported an error.
|
||||
NetPacketError::Data errorData;
|
||||
tmpPacket->ToNetPacketError()->GetData(errorData);
|
||||
// Show the error.
|
||||
throw ClientException(errorData.errorCode, 0);
|
||||
}
|
||||
client.SetState(ClientStateWaitGame::Instance());
|
||||
retVal = MSG_SOCK_SESSION_DONE;
|
||||
}
|
||||
else if (packet->ToNetPacketError())
|
||||
{
|
||||
// Server reported an error.
|
||||
NetPacketError::Data errorData;
|
||||
packet->ToNetPacketError()->GetData(errorData);
|
||||
// Show the error.
|
||||
throw ClientException(errorData.errorCode, 0);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
@@ -433,45 +463,39 @@ ClientStateWaitGame::~ClientStateWaitGame()
|
||||
}
|
||||
|
||||
int
|
||||
ClientStateWaitGame::Process(ClientThread &client)
|
||||
ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// delegate to receiver helper class
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
if (packet->ToNetPacketGameStart())
|
||||
{
|
||||
if (tmpPacket->ToNetPacketGameStart())
|
||||
{
|
||||
// Start the network game as client.
|
||||
NetPacketGameStart::Data gameStartData;
|
||||
tmpPacket->ToNetPacketGameStart()->GetData(gameStartData);
|
||||
// Start the network game as client.
|
||||
NetPacketGameStart::Data gameStartData;
|
||||
packet->ToNetPacketGameStart()->GetData(gameStartData);
|
||||
|
||||
client.SetStartData(gameStartData.startData);
|
||||
client.SetStartData(gameStartData.startData);
|
||||
|
||||
client.SetState(ClientStateWaitHand::Instance());
|
||||
retVal = MSG_NET_GAME_CLIENT_START;
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayerJoined())
|
||||
{
|
||||
// Another player joined the network game.
|
||||
NetPacketPlayerJoined::Data netPlayerData;
|
||||
tmpPacket->ToNetPacketPlayerJoined()->GetData(netPlayerData);
|
||||
client.SetState(ClientStateWaitHand::Instance());
|
||||
retVal = MSG_NET_GAME_CLIENT_START;
|
||||
}
|
||||
else if (packet->ToNetPacketPlayerJoined())
|
||||
{
|
||||
// Another player joined the network game.
|
||||
NetPacketPlayerJoined::Data netPlayerData;
|
||||
packet->ToNetPacketPlayerJoined()->GetData(netPlayerData);
|
||||
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(netPlayerData.playerId, netPlayerData.playerNumber, netPlayerData.ptype));
|
||||
playerData->SetName(netPlayerData.playerName);
|
||||
client.AddPlayerData(playerData);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayerLeft())
|
||||
{
|
||||
// Another player left the network game.
|
||||
NetPacketPlayerLeft::Data netPlayerData;
|
||||
tmpPacket->ToNetPacketPlayerLeft()->GetData(netPlayerData);
|
||||
client.RemovePlayerData(netPlayerData.playerId);
|
||||
}
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(netPlayerData.playerId, netPlayerData.playerNumber, netPlayerData.ptype));
|
||||
playerData->SetName(netPlayerData.playerName);
|
||||
client.AddPlayerData(playerData);
|
||||
}
|
||||
else if (packet->ToNetPacketPlayerLeft())
|
||||
{
|
||||
// Another player left the network game.
|
||||
NetPacketPlayerLeft::Data netPlayerData;
|
||||
packet->ToNetPacketPlayerLeft()->GetData(netPlayerData);
|
||||
client.RemovePlayerData(netPlayerData.playerId);
|
||||
}
|
||||
// TODO: handle error packet
|
||||
|
||||
@@ -496,33 +520,27 @@ ClientStateWaitHand::~ClientStateWaitHand()
|
||||
}
|
||||
|
||||
int
|
||||
ClientStateWaitHand::Process(ClientThread &client)
|
||||
ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// Delegate to receiver helper class.
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
if (packet->ToNetPacketHandStart())
|
||||
{
|
||||
if (tmpPacket->ToNetPacketHandStart())
|
||||
{
|
||||
// Hand was started.
|
||||
// These are the cards. Good luck.
|
||||
NetPacketHandStart::Data tmpData;
|
||||
tmpPacket->ToNetPacketHandStart()->GetData(tmpData);
|
||||
int myCards[2];
|
||||
myCards[0] = (int)tmpData.yourCards[0];
|
||||
myCards[1] = (int)tmpData.yourCards[1];
|
||||
client.GetGame()->getPlayerArray()[0]->setMyCards(myCards);
|
||||
client.GetGame()->initHand();
|
||||
client.GetGame()->startHand();
|
||||
client.GetGui().dealHoleCards();
|
||||
client.SetState(ClientStateRunHand::Instance());
|
||||
// Hand was started.
|
||||
// These are the cards. Good luck.
|
||||
NetPacketHandStart::Data tmpData;
|
||||
packet->ToNetPacketHandStart()->GetData(tmpData);
|
||||
int myCards[2];
|
||||
myCards[0] = (int)tmpData.yourCards[0];
|
||||
myCards[1] = (int)tmpData.yourCards[1];
|
||||
client.GetGame()->getPlayerArray()[0]->setMyCards(myCards);
|
||||
client.GetGame()->initHand();
|
||||
client.GetGame()->startHand();
|
||||
client.GetGui().dealHoleCards();
|
||||
client.SetState(ClientStateRunHand::Instance());
|
||||
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND;
|
||||
}
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND;
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
@@ -546,20 +564,17 @@ ClientStateRunHand::~ClientStateRunHand()
|
||||
}
|
||||
|
||||
int
|
||||
ClientStateRunHand::Process(ClientThread &client)
|
||||
ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// Delegate to receiver helper class.
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
if (packet.get())
|
||||
{
|
||||
boost::shared_ptr<Game> curGame = client.GetGame();
|
||||
if (tmpPacket->ToNetPacketPlayersActionDone())
|
||||
if (packet->ToNetPacketPlayersActionDone())
|
||||
{
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
tmpPacket->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
|
||||
packet->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
|
||||
@@ -587,10 +602,10 @@ ClientStateRunHand::Process(ClientThread &client)
|
||||
client.GetGui().refreshAction();
|
||||
client.GetGui().refreshCash();
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayersTurn())
|
||||
else if (packet->ToNetPacketPlayersTurn())
|
||||
{
|
||||
NetPacketPlayersTurn::Data turnData;
|
||||
tmpPacket->ToNetPacketPlayersTurn()->GetData(turnData);
|
||||
packet->ToNetPacketPlayersTurn()->GetData(turnData);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
|
||||
|
||||
@@ -96,6 +96,19 @@ ClientThread::SendPlayerAction()
|
||||
GetSender().Send(GetContext().GetSocket(), action);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::SendChatMessage(const std::string &msg)
|
||||
{
|
||||
// Warning: This function is called in the context of the GUI thread.
|
||||
// Create a network packet containing the chat message.
|
||||
boost::shared_ptr<NetPacket> chat(new NetPacketSendChatText);
|
||||
NetPacketSendChatText::Data chatData;
|
||||
chatData.text = msg;
|
||||
static_cast<NetPacketSendChatText *>(chat.get())->SetData(chatData);
|
||||
// The sender is thread-safe, so just dump the packet.
|
||||
GetSender().Send(GetContext().GetSocket(), chat);
|
||||
}
|
||||
|
||||
ClientCallback &
|
||||
ClientThread::GetCallback()
|
||||
{
|
||||
@@ -133,7 +146,8 @@ ClientThread::Main()
|
||||
// EngineFactory erstellen
|
||||
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen
|
||||
|
||||
m_game.reset(new Game(&m_gui, factory, GetMappedPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++));
|
||||
MapPlayerDataList();
|
||||
m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++));
|
||||
GetCallback().SignalNetClientGameStart(m_game);
|
||||
}
|
||||
}
|
||||
@@ -268,8 +282,8 @@ ClientThread::RemovePlayerData(unsigned playerId)
|
||||
GetCallback().SignalNetClientPlayerLeft(playerName);
|
||||
}
|
||||
|
||||
PlayerDataList
|
||||
ClientThread::GetMappedPlayerDataList() const
|
||||
void
|
||||
ClientThread::MapPlayerDataList()
|
||||
{
|
||||
PlayerDataList mappedList;
|
||||
|
||||
@@ -293,6 +307,33 @@ ClientThread::GetMappedPlayerDataList() const
|
||||
// Sort the list by player number.
|
||||
mappedList.sort(*boost::lambda::_1 < *boost::lambda::_2);
|
||||
|
||||
return mappedList;
|
||||
m_playerDataList = mappedList;
|
||||
SetGuiPlayerNum(0);
|
||||
}
|
||||
|
||||
const PlayerDataList &
|
||||
ClientThread::GetPlayerDataList() const
|
||||
{
|
||||
return m_playerDataList;
|
||||
}
|
||||
|
||||
boost::shared_ptr<PlayerData>
|
||||
ClientThread::GetPlayerDataByUniqueId(unsigned id)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpPlayer;
|
||||
|
||||
PlayerDataList::const_iterator i = m_playerDataList.begin();
|
||||
PlayerDataList::const_iterator end = m_playerDataList.end();
|
||||
|
||||
while (i != end)
|
||||
{
|
||||
if ((*i)->GetUniqueId() == id)
|
||||
{
|
||||
tmpPlayer = *i;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return tmpPlayer;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ using namespace std;
|
||||
#define NET_TYPE_PLAYERS_ACTION 0x0008
|
||||
#define NET_TYPE_PLAYERS_ACTION_DONE 0x0009
|
||||
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x000A
|
||||
#define NET_TYPE_SEND_CHAT_TEXT 0x000B
|
||||
#define NET_TYPE_CHAT_TEXT 0x000C
|
||||
|
||||
#define NET_TYPE_ERROR 0x0400
|
||||
|
||||
@@ -75,7 +77,6 @@ struct GCC_PACKED NetPacketJoinGameData
|
||||
u_int16_t playerFlags;
|
||||
u_int16_t playerNameLength;
|
||||
u_int16_t reserved;
|
||||
char password[1];
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketJoinGameAckData
|
||||
@@ -105,7 +106,6 @@ struct GCC_PACKED NetPacketPlayerJoinedData
|
||||
u_int16_t playerNumber;
|
||||
u_int16_t playerFlags;
|
||||
u_int16_t playerNameLength;
|
||||
char playerName[1];
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketPlayerLeftData
|
||||
@@ -166,6 +166,21 @@ struct GCC_PACKED NetPacketPlayersActionRejectedData
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketSendChatTextData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t textLength;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketChatTextData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t textLength;
|
||||
u_int16_t playerId;
|
||||
char text[1];
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketErrorData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
@@ -229,6 +244,12 @@ NetPacket::Create(char *data, unsigned &dataSize)
|
||||
case NET_TYPE_PLAYERS_ACTION_REJECTED:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketPlayersActionRejected);
|
||||
break;
|
||||
case NET_TYPE_SEND_CHAT_TEXT:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketSendChatText);
|
||||
break;
|
||||
case NET_TYPE_CHAT_TEXT:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketChatText);
|
||||
break;
|
||||
case NET_TYPE_ERROR:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketError);
|
||||
break;
|
||||
@@ -373,6 +394,18 @@ NetPacket::ToNetPacketPlayersActionRejected() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketSendChatText *
|
||||
NetPacket::ToNetPacketSendChatText() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketChatText *
|
||||
NetPacket::ToNetPacketChatText() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketError *
|
||||
NetPacket::ToNetPacketError() const
|
||||
{
|
||||
@@ -461,8 +494,9 @@ NetPacketJoinGame::SetData(const NetPacketJoinGame::Data &inData)
|
||||
tmpData->passwordLength = htons(passwordLen);
|
||||
tmpData->playerFlags = htons((inData.ptype == PLAYER_TYPE_HUMAN) ? NET_PLAYER_FLAG_HUMAN : 0);
|
||||
tmpData->playerNameLength = htons(playerNameLen);
|
||||
memcpy(tmpData->password, inData.password.c_str(), passwordLen);
|
||||
memcpy(tmpData->password + ADD_PADDING(passwordLen), inData.playerName.c_str(), playerNameLen);
|
||||
char *passwordPtr = (char *)tmpData + sizeof(NetPacketJoinGameData);
|
||||
memcpy(passwordPtr, inData.password.c_str(), passwordLen);
|
||||
memcpy(passwordPtr + ADD_PADDING(passwordLen), inData.playerName.c_str(), playerNameLen);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -478,8 +512,9 @@ NetPacketJoinGame::GetData(NetPacketJoinGame::Data &outData) const
|
||||
outData.ptype = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_HUMAN) ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
||||
|
||||
u_int16_t passwordLen = ntohs(tmpData->passwordLength);
|
||||
outData.password = string(tmpData->password, passwordLen);
|
||||
outData.playerName = string(tmpData->password + ADD_PADDING(passwordLen), ntohs(tmpData->playerNameLength));
|
||||
char *passwordPtr = (char *)tmpData + sizeof(NetPacketJoinGameData);
|
||||
outData.password = string(passwordPtr, passwordLen);
|
||||
outData.playerName = string(passwordPtr + ADD_PADDING(passwordLen), ntohs(tmpData->playerNameLength));
|
||||
}
|
||||
|
||||
const NetPacketJoinGame *
|
||||
@@ -640,7 +675,8 @@ NetPacketPlayerJoined::SetData(const NetPacketPlayerJoined::Data &inData)
|
||||
tmpData->playerId = htons(inData.playerId);
|
||||
tmpData->playerNumber = htons(inData.playerNumber);
|
||||
tmpData->playerNameLength = htons(playerNameLen);
|
||||
memcpy(tmpData->playerName, inData.playerName.c_str(), playerNameLen);
|
||||
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
||||
memcpy(namePtr, inData.playerName.c_str(), playerNameLen);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -653,7 +689,8 @@ NetPacketPlayerJoined::GetData(NetPacketPlayerJoined::Data &outData) const
|
||||
outData.ptype = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_HUMAN) ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
||||
outData.playerId = ntohs(tmpData->playerId);
|
||||
outData.playerNumber = ntohs(tmpData->playerNumber);
|
||||
outData.playerName = string(tmpData->playerName, ntohs(tmpData->playerNameLength));
|
||||
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
||||
outData.playerName = string(namePtr, ntohs(tmpData->playerNameLength));
|
||||
}
|
||||
|
||||
const NetPacketPlayerJoined *
|
||||
@@ -1196,6 +1233,189 @@ NetPacketPlayersActionRejected::Check(const NetPacketHeader* data) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketSendChatText::NetPacketSendChatText()
|
||||
: NetPacket(NET_TYPE_SEND_CHAT_TEXT, sizeof(NetPacketSendChatTextData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketSendChatText::~NetPacketSendChatText()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketSendChatText::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketSendChatText);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketSendChatText::SetData(const NetPacketSendChatText::Data &inData)
|
||||
{
|
||||
u_int16_t textLen = (u_int16_t)inData.text.length();
|
||||
|
||||
if (!textLen || textLen > MAX_CHAT_TEXT_SIZE)
|
||||
throw NetException(ERR_NET_INVALID_CHAT_TEXT, 0);
|
||||
|
||||
// Resize the packet so that the data fits in.
|
||||
Resize((u_int16_t)
|
||||
(sizeof(NetPacketSendChatTextData) + ADD_PADDING(textLen)));
|
||||
|
||||
NetPacketSendChatTextData *tmpData = (NetPacketSendChatTextData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
// Set the data.
|
||||
tmpData->textLength = htons(textLen);
|
||||
char *textPtr = (char *)tmpData + sizeof(NetPacketSendChatTextData);
|
||||
memcpy(textPtr, inData.text.c_str(), textLen);
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketSendChatText::GetData(NetPacketSendChatText::Data &outData) const
|
||||
{
|
||||
// We assume that the data is valid. Validity has already been checked.
|
||||
NetPacketSendChatTextData *tmpData = (NetPacketSendChatTextData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
char *textPtr = (char *)tmpData + sizeof(NetPacketSendChatTextData);
|
||||
outData.text = string(textPtr, ntohs(tmpData->textLength));
|
||||
}
|
||||
|
||||
const NetPacketSendChatText *
|
||||
NetPacketSendChatText::ToNetPacketSendChatText() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketSendChatText::Check(const NetPacketHeader* data) const
|
||||
{
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketSendChatTextData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
NetPacketSendChatTextData *tmpData = (NetPacketSendChatTextData *)data;
|
||||
int textLength = ntohs(tmpData->textLength);
|
||||
// Generous checking - larger packets are allowed.
|
||||
if (dataLen <
|
||||
sizeof(NetPacketSendChatTextData)
|
||||
+ ADD_PADDING(textLength))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
// Check string sizes.
|
||||
if (!textLength
|
||||
|| textLength > MAX_CHAT_TEXT_SIZE)
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketChatText::NetPacketChatText()
|
||||
: NetPacket(NET_TYPE_CHAT_TEXT, sizeof(NetPacketChatTextData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketChatText::~NetPacketChatText()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketChatText::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketChatText);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketChatText::SetData(const NetPacketChatText::Data &inData)
|
||||
{
|
||||
u_int16_t textLen = (u_int16_t)inData.text.length();
|
||||
|
||||
if (!textLen || textLen > MAX_CHAT_TEXT_SIZE)
|
||||
throw NetException(ERR_NET_INVALID_CHAT_TEXT, 0);
|
||||
|
||||
// Resize the packet so that the data fits in.
|
||||
Resize((u_int16_t)
|
||||
(sizeof(NetPacketChatTextData) + ADD_PADDING(textLen)));
|
||||
|
||||
NetPacketChatTextData *tmpData = (NetPacketChatTextData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
// Set the data.
|
||||
tmpData->playerId = htons(inData.playerId);
|
||||
tmpData->textLength = htons(textLen);
|
||||
char *textPtr = (char *)tmpData + sizeof(NetPacketChatTextData);
|
||||
memcpy(textPtr, inData.text.c_str(), textLen);
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketChatText::GetData(NetPacketChatText::Data &outData) const
|
||||
{
|
||||
// We assume that the data is valid. Validity has already been checked.
|
||||
NetPacketChatTextData *tmpData = (NetPacketChatTextData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.playerId = ntohs(tmpData->playerId);
|
||||
char *textPtr = (char *)tmpData + sizeof(NetPacketChatTextData);
|
||||
outData.text = string(textPtr, ntohs(tmpData->textLength));
|
||||
}
|
||||
|
||||
const NetPacketChatText *
|
||||
NetPacketChatText::ToNetPacketChatText() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketChatText::Check(const NetPacketHeader* data) const
|
||||
{
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketChatTextData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
NetPacketChatTextData *tmpData = (NetPacketChatTextData *)data;
|
||||
int textLength = ntohs(tmpData->textLength);
|
||||
// Generous checking - larger packets are allowed.
|
||||
if (dataLen <
|
||||
sizeof(NetPacketChatTextData)
|
||||
+ ADD_PADDING(textLength))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
// Check string sizes.
|
||||
if (!textLength
|
||||
|| textLength > MAX_CHAT_TEXT_SIZE)
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketError::NetPacketError()
|
||||
: NetPacket(NET_TYPE_ERROR, sizeof(NetPacketErrorData))
|
||||
{
|
||||
|
||||
+200
-173
@@ -41,6 +41,66 @@ ServerRecvState::~ServerRecvState()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateReceiving::ServerRecvStateReceiving()
|
||||
{
|
||||
}
|
||||
|
||||
ServerRecvStateReceiving::~ServerRecvStateReceiving()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateReceiving::Process(ServerRecvThread &server)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
SOCKET recvSock = server.Select();
|
||||
|
||||
if (recvSock != INVALID_SOCKET)
|
||||
{
|
||||
SessionWrapper session = server.GetSession(recvSock);
|
||||
boost::shared_ptr<NetPacket> packet;
|
||||
try
|
||||
{
|
||||
packet = server.GetReceiver().Recv(recvSock);
|
||||
} catch (const NetException &)
|
||||
{
|
||||
if (session.sessionData.get())
|
||||
{
|
||||
// TODO: Deactivate player.
|
||||
server.CloseSessionDelayed(session);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore if no session / no packet.
|
||||
if (packet.get() && session.sessionData.get())
|
||||
{
|
||||
if (packet->ToNetPacketSendChatText()) // Chat text is always allowed.
|
||||
{
|
||||
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);
|
||||
server.SendToAllPlayers(outChat);
|
||||
}
|
||||
}
|
||||
else
|
||||
retVal = InternalProcess(server, session, packet); // Let other class handle this.
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateInit &
|
||||
ServerRecvStateInit::Instance()
|
||||
{
|
||||
@@ -71,137 +131,116 @@ ServerRecvStateInit::HandleNewConnection(ServerRecvThread &server, boost::shared
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateInit::Process(ServerRecvThread &server)
|
||||
ServerRecvStateInit::InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
int retVal = MSG_SOCK_INIT_DONE;
|
||||
SOCKET recvSock = server.Select();
|
||||
|
||||
if (recvSock != INVALID_SOCKET)
|
||||
// Session should be in initial state.
|
||||
if (session.sessionData->GetState() != SessionData::Init)
|
||||
{
|
||||
SessionWrapper session = server.GetSession(recvSock);
|
||||
boost::shared_ptr<NetPacket> packet;
|
||||
try
|
||||
{
|
||||
packet = server.GetReceiver().Recv(recvSock);
|
||||
} catch (const NetException &)
|
||||
{
|
||||
if (session.sessionData.get())
|
||||
{
|
||||
server.CloseSessionDelayed(session);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore if no session / no packet.
|
||||
if (packet.get() && session.sessionData.get())
|
||||
{
|
||||
// Session should be in initial state.
|
||||
if (session.sessionData->GetState() != SessionData::Init)
|
||||
{
|
||||
server.SessionError(session, ERR_SOCK_INVALID_STATE);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Only accept join game packets.
|
||||
const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
|
||||
if (!tmpPacket)
|
||||
{
|
||||
server.SessionError(session, ERR_SOCK_INVALID_PACKET);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
NetPacketJoinGame::Data joinGameData;
|
||||
tmpPacket->GetData(joinGameData);
|
||||
|
||||
// Check the protocol version.
|
||||
if (joinGameData.versionMajor != NET_VERSION_MAJOR)
|
||||
{
|
||||
server.SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
size_t curNumPlayers = server.GetCurNumberOfPlayers();
|
||||
|
||||
// Check the number of players.
|
||||
if (curNumPlayers >= (size_t)server.GetGameData().numberOfPlayers)
|
||||
{
|
||||
server.SessionError(session, ERR_NET_SERVER_FULL);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Check the server password.
|
||||
if (!server.CheckPassword(joinGameData.password))
|
||||
{
|
||||
server.SessionError(session, ERR_NET_INVALID_PASSWORD);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Check whether the player name is correct.
|
||||
// Paranoia check, this is also done in netpacket.
|
||||
if (joinGameData.playerName.empty() || joinGameData.playerName.size() > MAX_NAME_SIZE)
|
||||
{
|
||||
server.SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Check whether this player is already connected.
|
||||
if (server.IsPlayerConnected(joinGameData.playerName))
|
||||
{
|
||||
server.SessionError(session, ERR_NET_PLAYER_NAME_IN_USE);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Create player data object.
|
||||
boost::shared_ptr<PlayerData> tmpPlayerData(
|
||||
new PlayerData(m_curUniquePlayerId++, server.GetNextPlayerNumber(), joinGameData.ptype));
|
||||
tmpPlayerData->SetName(joinGameData.playerName);
|
||||
tmpPlayerData->SetNetSessionData(session.sessionData);
|
||||
|
||||
// Send ACK to client.
|
||||
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
joinGameAckData.sessionId = session.sessionData->GetId(); // TODO: currently unused.
|
||||
joinGameAckData.yourPlayerUniqueId = tmpPlayerData->GetUniqueId();
|
||||
joinGameAckData.yourPlayerNum = tmpPlayerData->GetNumber();
|
||||
joinGameAckData.gameData = server.GetGameData();
|
||||
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
|
||||
server.GetSender().Send(recvSock, answer);
|
||||
|
||||
// Send notifications for connected players to client.
|
||||
PlayerDataList tmpPlayerList = server.GetPlayerDataList();
|
||||
PlayerDataList::iterator player_i = tmpPlayerList.begin();
|
||||
PlayerDataList::iterator player_end = tmpPlayerList.end();
|
||||
while (player_i != player_end)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> otherPlayerJoined(new NetPacketPlayerJoined);
|
||||
NetPacketPlayerJoined::Data otherPlayerJoinedData;
|
||||
otherPlayerJoinedData.playerId = (*player_i)->GetUniqueId();
|
||||
otherPlayerJoinedData.playerName = (*player_i)->GetName();
|
||||
otherPlayerJoinedData.playerNumber = (*player_i)->GetNumber();
|
||||
otherPlayerJoinedData.ptype = (*player_i)->GetType();
|
||||
static_cast<NetPacketPlayerJoined *>(otherPlayerJoined.get())->SetData(otherPlayerJoinedData);
|
||||
server.GetSender().Send(session.sessionData->GetSocket(), otherPlayerJoined);
|
||||
|
||||
++player_i;
|
||||
}
|
||||
|
||||
// Send "Player Joined" to other fully connected clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerJoined(new NetPacketPlayerJoined);
|
||||
NetPacketPlayerJoined::Data thisPlayerJoinedData;
|
||||
thisPlayerJoinedData.playerId = tmpPlayerData->GetUniqueId();
|
||||
thisPlayerJoinedData.playerName = tmpPlayerData->GetName();
|
||||
thisPlayerJoinedData.playerNumber = tmpPlayerData->GetNumber();
|
||||
thisPlayerJoinedData.ptype = tmpPlayerData->GetType();
|
||||
static_cast<NetPacketPlayerJoined *>(thisPlayerJoined.get())->SetData(thisPlayerJoinedData);
|
||||
server.SendToAllPlayers(thisPlayerJoined);
|
||||
|
||||
// Set player data for session.
|
||||
server.SetSessionPlayerData(session.sessionData, tmpPlayerData);
|
||||
|
||||
// Session is now established.
|
||||
session.sessionData->SetState(SessionData::Established);
|
||||
}
|
||||
server.SessionError(session, ERR_SOCK_INVALID_STATE);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Only accept join game packets.
|
||||
const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
|
||||
if (!tmpPacket)
|
||||
{
|
||||
server.SessionError(session, ERR_SOCK_INVALID_PACKET);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
NetPacketJoinGame::Data joinGameData;
|
||||
tmpPacket->GetData(joinGameData);
|
||||
|
||||
// Check the protocol version.
|
||||
if (joinGameData.versionMajor != NET_VERSION_MAJOR)
|
||||
{
|
||||
server.SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
size_t curNumPlayers = server.GetCurNumberOfPlayers();
|
||||
|
||||
// Check the number of players.
|
||||
if (curNumPlayers >= (size_t)server.GetGameData().numberOfPlayers)
|
||||
{
|
||||
server.SessionError(session, ERR_NET_SERVER_FULL);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Check the server password.
|
||||
if (!server.CheckPassword(joinGameData.password))
|
||||
{
|
||||
server.SessionError(session, ERR_NET_INVALID_PASSWORD);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Check whether the player name is correct.
|
||||
// Paranoia check, this is also done in netpacket.
|
||||
if (joinGameData.playerName.empty() || joinGameData.playerName.size() > MAX_NAME_SIZE)
|
||||
{
|
||||
server.SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Check whether this player is already connected.
|
||||
if (server.IsPlayerConnected(joinGameData.playerName))
|
||||
{
|
||||
server.SessionError(session, ERR_NET_PLAYER_NAME_IN_USE);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Create player data object.
|
||||
boost::shared_ptr<PlayerData> tmpPlayerData(
|
||||
new PlayerData(m_curUniquePlayerId++, server.GetNextPlayerNumber(), joinGameData.ptype));
|
||||
tmpPlayerData->SetName(joinGameData.playerName);
|
||||
tmpPlayerData->SetNetSessionData(session.sessionData);
|
||||
|
||||
// Send ACK to client.
|
||||
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
joinGameAckData.sessionId = session.sessionData->GetId(); // TODO: currently unused.
|
||||
joinGameAckData.yourPlayerUniqueId = tmpPlayerData->GetUniqueId();
|
||||
joinGameAckData.yourPlayerNum = tmpPlayerData->GetNumber();
|
||||
joinGameAckData.gameData = server.GetGameData();
|
||||
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
|
||||
server.GetSender().Send(session.sessionData->GetSocket(), answer);
|
||||
|
||||
// Send notifications for connected players to client.
|
||||
PlayerDataList tmpPlayerList = server.GetPlayerDataList();
|
||||
PlayerDataList::iterator player_i = tmpPlayerList.begin();
|
||||
PlayerDataList::iterator player_end = tmpPlayerList.end();
|
||||
while (player_i != player_end)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> otherPlayerJoined(new NetPacketPlayerJoined);
|
||||
NetPacketPlayerJoined::Data otherPlayerJoinedData;
|
||||
otherPlayerJoinedData.playerId = (*player_i)->GetUniqueId();
|
||||
otherPlayerJoinedData.playerName = (*player_i)->GetName();
|
||||
otherPlayerJoinedData.playerNumber = (*player_i)->GetNumber();
|
||||
otherPlayerJoinedData.ptype = (*player_i)->GetType();
|
||||
static_cast<NetPacketPlayerJoined *>(otherPlayerJoined.get())->SetData(otherPlayerJoinedData);
|
||||
server.GetSender().Send(session.sessionData->GetSocket(), otherPlayerJoined);
|
||||
|
||||
++player_i;
|
||||
}
|
||||
|
||||
// Send "Player Joined" to other fully connected clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerJoined(new NetPacketPlayerJoined);
|
||||
NetPacketPlayerJoined::Data thisPlayerJoinedData;
|
||||
thisPlayerJoinedData.playerId = tmpPlayerData->GetUniqueId();
|
||||
thisPlayerJoinedData.playerName = tmpPlayerData->GetName();
|
||||
thisPlayerJoinedData.playerNumber = tmpPlayerData->GetNumber();
|
||||
thisPlayerJoinedData.ptype = tmpPlayerData->GetType();
|
||||
static_cast<NetPacketPlayerJoined *>(thisPlayerJoined.get())->SetData(thisPlayerJoinedData);
|
||||
server.SendToAllPlayers(thisPlayerJoined);
|
||||
|
||||
// Set player data for session.
|
||||
server.SetSessionPlayerData(session.sessionData, tmpPlayerData);
|
||||
|
||||
// Session is now established.
|
||||
session.sessionData->SetState(SessionData::Established);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -463,62 +502,50 @@ ServerRecvStateWaitPlayerAction::~ServerRecvStateWaitPlayerAction()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateWaitPlayerAction::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// C++ really sucks concerning multiple inheritance *sigh*.
|
||||
// So this is a copy & paste from ServerRecvStateRunning.
|
||||
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateWaitPlayerAction::Process(ServerRecvThread &server)
|
||||
ServerRecvStateWaitPlayerAction::InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
SOCKET recvSock = server.Select();
|
||||
|
||||
if (recvSock != INVALID_SOCKET)
|
||||
if (packet->ToNetPacketPlayersAction())
|
||||
{
|
||||
SessionWrapper session = server.GetSession(recvSock);
|
||||
boost::shared_ptr<NetPacket> packet;
|
||||
try
|
||||
{
|
||||
packet = server.GetReceiver().Recv(recvSock);
|
||||
} catch (const NetException &)
|
||||
{
|
||||
if (session.sessionData.get())
|
||||
{
|
||||
server.CloseSessionDelayed(session);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
NetPacketPlayersAction::Data actionData;
|
||||
packet->ToNetPacketPlayersAction()->GetData(actionData);
|
||||
|
||||
Game &curGame = server.GetGame();
|
||||
PlayerInterface *tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId());
|
||||
assert(tmpPlayer); // TODO throw exception
|
||||
|
||||
// Ignore if no session / no packet.
|
||||
if (packet.get() && session.sessionData.get())
|
||||
{
|
||||
if (packet->ToNetPacketPlayersAction())
|
||||
{
|
||||
NetPacketPlayersAction::Data actionData;
|
||||
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);
|
||||
|
||||
tmpPlayer->setMyAction(actionData.playerAction);
|
||||
tmpPlayer->setMySet(actionData.playerBet);
|
||||
if (tmpPlayer->getMySet() > GetHighestSet(curGame))
|
||||
SetHighestSet(curGame, tmpPlayer->getMySet());
|
||||
|
||||
if (tmpPlayer->getMySet() > GetHighestSet(curGame))
|
||||
SetHighestSet(curGame, tmpPlayer->getMySet());
|
||||
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
actionDoneData.gameState = static_cast<GameState>(curGame.getCurrentHand()->getActualRound());
|
||||
actionDoneData.playerId = session.playerData->GetUniqueId();
|
||||
actionDoneData.playerAction = actionData.playerAction;
|
||||
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);
|
||||
|
||||
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
actionDoneData.gameState = static_cast<GameState>(curGame.getCurrentHand()->getActualRound());
|
||||
actionDoneData.playerId = session.playerData->GetUniqueId();
|
||||
actionDoneData.playerAction = actionData.playerAction;
|
||||
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;
|
||||
}
|
||||
}
|
||||
server.SetState(ServerRecvStateStartRound::Instance());
|
||||
retVal = MSG_NET_GAME_SERVER_ACTION;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
||||
Reference in New Issue
Block a user