Configuration is transferred. A new game should be started on client side, but signal/slot is not working yet. Oh well.
This commit is contained in:
@@ -62,7 +62,7 @@ Server Reply: Join Game ACK
|
|||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Number of Players | Small Blind |
|
| Number of Players | Small Blind |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Hands before raise | Game Speed |
|
| Hands before raise | Reserved |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Start Cash |
|
| Start Cash |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ HEADERS += src/game.h \
|
|||||||
src/gui/qt/mainwindow/mycardspixmaplabel.h \
|
src/gui/qt/mainwindow/mycardspixmaplabel.h \
|
||||||
src/gui/qt/mainwindow/startsplash/startsplash.h \
|
src/gui/qt/mainwindow/startsplash/startsplash.h \
|
||||||
src/gui/qt/guiwrapper.h \
|
src/gui/qt/guiwrapper.h \
|
||||||
|
src/gui/qt/gamedatawrapper.h \
|
||||||
src/gui/qt/aboutpokerth/aboutpokerthimpl.h \
|
src/gui/qt/aboutpokerth/aboutpokerthimpl.h \
|
||||||
src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.h \
|
src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.h \
|
||||||
src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h \
|
src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h \
|
||||||
@@ -169,6 +170,7 @@ SOURCES += src/game.cpp \
|
|||||||
src/net/common/netexception.cpp \
|
src/net/common/netexception.cpp \
|
||||||
src/net/common/receiverhelper.cpp \
|
src/net/common/receiverhelper.cpp \
|
||||||
src/gui/qt/guiwrapper.cpp \
|
src/gui/qt/guiwrapper.cpp \
|
||||||
|
src/gui/qt/gamedatawrapper.cpp \
|
||||||
src/gui/qt/mainwindow/mainwindowimpl.cpp \
|
src/gui/qt/mainwindow/mainwindowimpl.cpp \
|
||||||
src/gui/qt/mainwindow/mycardspixmaplabel.cpp \
|
src/gui/qt/mainwindow/mycardspixmaplabel.cpp \
|
||||||
src/gui/qt/mainwindow/startsplash/startsplash.cpp \
|
src/gui/qt/mainwindow/startsplash/startsplash.cpp \
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "gamedatawrapper.h"
|
||||||
|
|
||||||
|
GameDataWrapper::GameDataWrapper(const GameData &gameData)
|
||||||
|
: m_gameData(gameData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GameDataWrapper::GameDataWrapper(const GameDataWrapper &other)
|
||||||
|
: m_gameData(other.GetGameData())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const GameData&
|
||||||
|
GameDataWrapper::GetGameData() const
|
||||||
|
{
|
||||||
|
return m_gameData;
|
||||||
|
}
|
||||||
|
|
||||||
|
const GameDataWrapper &
|
||||||
|
GameDataWrapper::operator=(const GameDataWrapper &other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
m_gameData = other.GetGameData();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GAMEDATAWRAPPER_H
|
||||||
|
#define GAMEDATAWRAPPER_H
|
||||||
|
|
||||||
|
#include <gamedata.h>
|
||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
|
||||||
|
class GameDataWrapper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GameDataWrapper(const GameData &gameData);
|
||||||
|
GameDataWrapper(const GameDataWrapper &other);
|
||||||
|
|
||||||
|
const GameData &GetGameData() const;
|
||||||
|
|
||||||
|
const GameDataWrapper &operator=(const GameDataWrapper &other);
|
||||||
|
|
||||||
|
private:
|
||||||
|
GameData m_gameData;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -92,6 +92,8 @@ void GuiWrapper::SignalNetClientConnect(int actionID) { myW->SignalNetClientConn
|
|||||||
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->SignalNetClientGameInfo(actionID); }
|
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->SignalNetClientGameInfo(actionID); }
|
||||||
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->SignalNetClientError(errorID, osErrorID); }
|
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->SignalNetClientError(errorID, osErrorID); }
|
||||||
|
|
||||||
|
void GuiWrapper::SignalNetClientGameStart(const GameData &gameData) { myW->SignalNetClientGameStart(GameDataWrapper(gameData)); }
|
||||||
|
|
||||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
||||||
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->SignalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->SignalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ public:
|
|||||||
void SignalNetClientGameInfo(int actionID);
|
void SignalNetClientGameInfo(int actionID);
|
||||||
void SignalNetClientError(int errorID, int osErrorID);
|
void SignalNetClientError(int errorID, int osErrorID);
|
||||||
|
|
||||||
|
void SignalNetClientGameStart(const GameData &gameData);
|
||||||
|
|
||||||
void SignalNetServerSuccess(int actionID);
|
void SignalNetServerSuccess(int actionID);
|
||||||
void SignalNetServerError(int errorID, int osErrorID);
|
void SignalNetServerError(int errorID, int osErrorID);
|
||||||
void SignalNetServerPlayerJoined(const std::string &playerName);
|
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||||
|
|||||||
@@ -538,6 +538,7 @@ mainWindowImpl::mainWindowImpl(QMainWindow *parent)
|
|||||||
connect(this, SIGNAL(SignalNetClientGameInfo(int)), myWaitingForServerGameDialog, SLOT(refresh(int)));
|
connect(this, SIGNAL(SignalNetClientGameInfo(int)), myWaitingForServerGameDialog, SLOT(refresh(int)));
|
||||||
// Errors are handled globally, not within one dialog.
|
// Errors are handled globally, not within one dialog.
|
||||||
connect(this, SIGNAL(SignalNetClientError(int, int)), this, SLOT(networkError(int, int)));
|
connect(this, SIGNAL(SignalNetClientError(int, int)), this, SLOT(networkError(int, int)));
|
||||||
|
connect(this, SIGNAL(SignalNetClientGameStart(GameDataWrapper)), this, SLOT(networkStart(GameDataWrapper)));
|
||||||
|
|
||||||
connect(this, SIGNAL(SignalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
|
connect(this, SIGNAL(SignalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
|
||||||
|
|
||||||
@@ -2199,6 +2200,11 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
|
|||||||
myWaitingForServerGameDialog->reject();
|
myWaitingForServerGameDialog->reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mainWindowImpl::networkStart(GameDataWrapper gameData)
|
||||||
|
{
|
||||||
|
mySession->startGame(gameData.GetGameData());
|
||||||
|
}
|
||||||
|
|
||||||
void mainWindowImpl::keyPressEvent ( QKeyEvent * event ) {
|
void mainWindowImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||||
|
|
||||||
// cout << event->key() << endl;
|
// cout << event->key() << endl;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "handinterface.h"
|
#include "handinterface.h"
|
||||||
#include "game_defs.h"
|
#include "game_defs.h"
|
||||||
|
#include <gamedatawrapper.h>
|
||||||
|
|
||||||
class Session;
|
class Session;
|
||||||
class Game;
|
class Game;
|
||||||
@@ -93,6 +94,7 @@ signals:
|
|||||||
void SignalNetClientConnect(int actionID);
|
void SignalNetClientConnect(int actionID);
|
||||||
void SignalNetClientGameInfo(int actionID);
|
void SignalNetClientGameInfo(int actionID);
|
||||||
void SignalNetClientError(int errorID, int osErrorID);
|
void SignalNetClientError(int errorID, int osErrorID);
|
||||||
|
void SignalNetClientGameStart(GameDataWrapper gameData);
|
||||||
void SignalNetServerPlayerJoined(QString playerName);
|
void SignalNetServerPlayerJoined(QString playerName);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -189,6 +191,7 @@ public slots:
|
|||||||
void paintStartSplash();
|
void paintStartSplash();
|
||||||
|
|
||||||
void networkError(int, int);
|
void networkError(int, int);
|
||||||
|
void networkStart(GameDataWrapper);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef _CLIENTCALLBACK_H_
|
#ifndef _CLIENTCALLBACK_H_
|
||||||
#define _CLIENTCALLBACK_H_
|
#define _CLIENTCALLBACK_H_
|
||||||
|
|
||||||
|
struct GameData;
|
||||||
|
|
||||||
class ClientCallback
|
class ClientCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -29,6 +31,8 @@ public:
|
|||||||
virtual void SignalNetClientConnect(int actionID) = 0;
|
virtual void SignalNetClientConnect(int actionID) = 0;
|
||||||
virtual void SignalNetClientGameInfo(int actionID) = 0;
|
virtual void SignalNetClientGameInfo(int actionID) = 0;
|
||||||
virtual void SignalNetClientError(int errorID, int osErrorID) = 0;
|
virtual void SignalNetClientError(int errorID, int osErrorID) = 0;
|
||||||
|
|
||||||
|
virtual void SignalNetClientGameStart(const GameData &gameData) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class ClientState;
|
|||||||
class SenderThread;
|
class SenderThread;
|
||||||
class ReceiverHelper;
|
class ReceiverHelper;
|
||||||
class ClientSenderCallback;
|
class ClientSenderCallback;
|
||||||
|
struct GameData;
|
||||||
|
|
||||||
class ClientThread : public Thread
|
class ClientThread : public Thread
|
||||||
{
|
{
|
||||||
@@ -64,6 +65,9 @@ protected:
|
|||||||
SenderThread &GetSender();
|
SenderThread &GetSender();
|
||||||
ReceiverHelper &GetReceiver();
|
ReceiverHelper &GetReceiver();
|
||||||
|
|
||||||
|
const GameData &GetGameData() const;
|
||||||
|
void SetGameData(const GameData &gameData);
|
||||||
|
|
||||||
ClientSenderCallback &GetSenderCallback();
|
ClientSenderCallback &GetSenderCallback();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -72,9 +76,12 @@ private:
|
|||||||
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
||||||
ClientState *m_curState;
|
ClientState *m_curState;
|
||||||
ClientCallback &m_callback;
|
ClientCallback &m_callback;
|
||||||
|
|
||||||
std::auto_ptr<SenderThread> m_sender;
|
std::auto_ptr<SenderThread> m_sender;
|
||||||
std::auto_ptr<ReceiverHelper> m_receiver;
|
std::auto_ptr<ReceiverHelper> m_receiver;
|
||||||
|
|
||||||
|
std::auto_ptr<GameData> m_gameData;
|
||||||
|
|
||||||
friend class ClientStateInit;
|
friend class ClientStateInit;
|
||||||
friend class ClientStateStartResolve;
|
friend class ClientStateStartResolve;
|
||||||
friend class ClientStateResolving;
|
friend class ClientStateResolving;
|
||||||
|
|||||||
@@ -366,6 +366,11 @@ ClientStateWaitSession::Process(ClientThread &client)
|
|||||||
|
|
||||||
if (tmpPacket.get() && tmpPacket->ToNetPacketJoinGameAck())
|
if (tmpPacket.get() && tmpPacket->ToNetPacketJoinGameAck())
|
||||||
{
|
{
|
||||||
|
// Initialise game configuration.
|
||||||
|
NetPacketJoinGameAck::Data joinGameAckData;
|
||||||
|
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||||
|
client.SetGameData(joinGameAckData.gameData);
|
||||||
|
|
||||||
client.SetState(ClientStateWaitGame::Instance());
|
client.SetState(ClientStateWaitGame::Instance());
|
||||||
retVal = MSG_SOCK_SESSION_DONE;
|
retVal = MSG_SOCK_SESSION_DONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <net/receiverhelper.h>
|
#include <net/receiverhelper.h>
|
||||||
#include <net/clientexception.h>
|
#include <net/clientexception.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
|
#include <gamedata.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@@ -57,6 +57,7 @@ ClientThread::ClientThread(ClientCallback &cb)
|
|||||||
m_senderCallback.reset(new ClientSenderCallback(*this));
|
m_senderCallback.reset(new ClientSenderCallback(*this));
|
||||||
m_sender.reset(new SenderThread(GetSenderCallback()));
|
m_sender.reset(new SenderThread(GetSenderCallback()));
|
||||||
m_receiver.reset(new ReceiverHelper);
|
m_receiver.reset(new ReceiverHelper);
|
||||||
|
m_gameData.reset(new GameData);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientThread::~ClientThread()
|
ClientThread::~ClientThread()
|
||||||
@@ -103,6 +104,10 @@ ClientThread::Main()
|
|||||||
GetCallback().SignalNetClientConnect(msg);
|
GetCallback().SignalNetClientConnect(msg);
|
||||||
else
|
else
|
||||||
GetCallback().SignalNetClientGameInfo(msg);
|
GetCallback().SignalNetClientGameInfo(msg);
|
||||||
|
|
||||||
|
// Additionally signal the start of the game.
|
||||||
|
if (msg == MSG_SOCK_GAME_START)
|
||||||
|
GetCallback().SignalNetClientGameStart(GetGameData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const NetException &e)
|
} catch (const NetException &e)
|
||||||
@@ -154,6 +159,20 @@ ClientThread::GetReceiver()
|
|||||||
return *m_receiver;
|
return *m_receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GameData &
|
||||||
|
ClientThread::GetGameData() const
|
||||||
|
{
|
||||||
|
assert(m_gameData.get());
|
||||||
|
return *m_gameData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::SetGameData(const GameData &gameData)
|
||||||
|
{
|
||||||
|
assert(m_gameData.get());
|
||||||
|
*m_gameData = gameData;
|
||||||
|
}
|
||||||
|
|
||||||
ClientSenderCallback &
|
ClientSenderCallback &
|
||||||
ClientThread::GetSenderCallback()
|
ClientThread::GetSenderCallback()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ struct NetPacketJoinGameAckData
|
|||||||
u_int16_t numberOfPlayers;
|
u_int16_t numberOfPlayers;
|
||||||
u_int16_t smallBlind;
|
u_int16_t smallBlind;
|
||||||
u_int16_t handsBeforeRaise;
|
u_int16_t handsBeforeRaise;
|
||||||
u_int16_t gameSpeed;
|
u_int16_t reserved;
|
||||||
u_int32_t startCash;
|
u_int32_t startCash;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -416,11 +416,10 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData)
|
|||||||
tmpData->sessionId = htonl(inData.sessionId);
|
tmpData->sessionId = htonl(inData.sessionId);
|
||||||
tmpData->playerId = htons(inData.playerId);
|
tmpData->playerId = htons(inData.playerId);
|
||||||
tmpData->playerNumber = htons(inData.playerNumber);
|
tmpData->playerNumber = htons(inData.playerNumber);
|
||||||
tmpData->numberOfPlayers = htons(inData.numberOfPlayers);
|
tmpData->numberOfPlayers = htons(inData.gameData.numberOfPlayers);
|
||||||
tmpData->smallBlind = htons(inData.smallBlind);
|
tmpData->smallBlind = htons(inData.gameData.smallBlind);
|
||||||
tmpData->handsBeforeRaise = htons(inData.handsBeforeRaise);
|
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
|
||||||
tmpData->gameSpeed = htons(inData.gameSpeed);
|
tmpData->startCash = htonl(inData.gameData.startCash);
|
||||||
tmpData->startCash = htonl(inData.startCash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -429,14 +428,13 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const
|
|||||||
NetPacketJoinGameAckData *tmpData = (NetPacketJoinGameAckData *)GetRawData();
|
NetPacketJoinGameAckData *tmpData = (NetPacketJoinGameAckData *)GetRawData();
|
||||||
assert(tmpData);
|
assert(tmpData);
|
||||||
|
|
||||||
outData.sessionId = ntohl(tmpData->sessionId);
|
outData.sessionId = ntohl(tmpData->sessionId);
|
||||||
outData.playerId = ntohs(tmpData->playerId);
|
outData.playerId = ntohs(tmpData->playerId);
|
||||||
outData.playerNumber = ntohs(tmpData->playerNumber);
|
outData.playerNumber = ntohs(tmpData->playerNumber);
|
||||||
outData.numberOfPlayers = ntohs(tmpData->numberOfPlayers);
|
outData.gameData.numberOfPlayers = ntohs(tmpData->numberOfPlayers);
|
||||||
outData.smallBlind = ntohs(tmpData->smallBlind);
|
outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
|
||||||
outData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||||
outData.gameSpeed = ntohs(tmpData->gameSpeed);
|
outData.gameData.startCash = ntohl(tmpData->startCash);
|
||||||
outData.startCash = ntohl(tmpData->startCash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetPacketJoinGameAck *
|
const NetPacketJoinGameAck *
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include <net/senderthread.h>
|
#include <net/senderthread.h>
|
||||||
#include <net/netpacket.h>
|
#include <net/netpacket.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
|
#include <gamedata.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -43,6 +45,7 @@ ServerRecvStateInit::Instance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerRecvStateInit::ServerRecvStateInit()
|
ServerRecvStateInit::ServerRecvStateInit()
|
||||||
|
: m_curUniquePlayerId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,16 +79,54 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
|
|||||||
const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
|
const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
|
||||||
if (tmpPacket)
|
if (tmpPacket)
|
||||||
{
|
{
|
||||||
// TODO: check password
|
NetPacketJoinGame::Data joinGameData;
|
||||||
NetPacketJoinGame::Data playerData;
|
tmpPacket->GetData(joinGameData);
|
||||||
tmpPacket->GetData(playerData);
|
// Check the server password.
|
||||||
server.GetCallback().SignalNetServerPlayerJoined(playerData.playerName);
|
if (server.CheckPassword(joinGameData.password))
|
||||||
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
{
|
||||||
NetPacketJoinGameAck::Data joinGameAckData;
|
PlayerDataList &playerDataList = server.GetPlayerDataList();
|
||||||
// TODO: set data.
|
// Check whether this player is already connected.
|
||||||
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
|
PlayerDataList::const_iterator player_i = playerDataList.begin();
|
||||||
server.GetSender().Send(answer, recvSock);
|
PlayerDataList::const_iterator player_end = playerDataList.end();
|
||||||
session->SetState(SessionData::Established);
|
while (player_i != player_end)
|
||||||
|
{
|
||||||
|
if ((*player_i)->GetName() == joinGameData.playerName)
|
||||||
|
break;
|
||||||
|
++player_i;
|
||||||
|
}
|
||||||
|
if (player_i == player_end)
|
||||||
|
{
|
||||||
|
// Create player data object.
|
||||||
|
boost::shared_ptr<PlayerData> tmpPlayerData(new PlayerData(m_curUniquePlayerId++));
|
||||||
|
tmpPlayerData->SetName(joinGameData.playerName);
|
||||||
|
tmpPlayerData->SetPlayerType(joinGameData.ptype);
|
||||||
|
|
||||||
|
// Signal joining player to GUI.
|
||||||
|
server.GetCallback().SignalNetServerPlayerJoined(tmpPlayerData->GetName());
|
||||||
|
|
||||||
|
// Send ACK to client.
|
||||||
|
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
||||||
|
NetPacketJoinGameAck::Data joinGameAckData;
|
||||||
|
joinGameAckData.playerId = tmpPlayerData->GetUniqueId();
|
||||||
|
joinGameAckData.playerNumber = playerDataList.size();
|
||||||
|
joinGameAckData.sessionId = session->GetId(); // TODO: currently unused.
|
||||||
|
joinGameAckData.gameData = server.GetGameData();
|
||||||
|
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
|
||||||
|
server.GetSender().Send(answer, recvSock);
|
||||||
|
session->SetState(SessionData::Established);
|
||||||
|
|
||||||
|
// Store player data in list.
|
||||||
|
playerDataList.push_back(tmpPlayerData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO send error message, duplicate name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO send error message, invalid password
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -309,18 +309,24 @@ ServerRecvThread::GetReceiver()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const GameData &
|
const GameData &
|
||||||
ServerRecvThread::GetGameData()
|
ServerRecvThread::GetGameData() const
|
||||||
{
|
{
|
||||||
assert(m_gameData.get());
|
assert(m_gameData.get());
|
||||||
return *m_gameData;
|
return *m_gameData;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerRecvThread::CheckPassword(const std::string &password)
|
ServerRecvThread::CheckPassword(const std::string &password) const
|
||||||
{
|
{
|
||||||
return (password == m_password);
|
return (password == m_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerDataList &
|
||||||
|
ServerRecvThread::GetPlayerDataList()
|
||||||
|
{
|
||||||
|
return m_playerDataList;
|
||||||
|
}
|
||||||
|
|
||||||
ServerSenderCallback &
|
ServerSenderCallback &
|
||||||
ServerRecvThread::GetSenderCallback()
|
ServerRecvThread::GetSenderCallback()
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-5
@@ -22,6 +22,7 @@
|
|||||||
#define _NETPACKET_H_
|
#define _NETPACKET_H_
|
||||||
|
|
||||||
#include <playerdata.h>
|
#include <playerdata.h>
|
||||||
|
#include <gamedata.h>
|
||||||
#include <net/socket_helper.h>
|
#include <net/socket_helper.h>
|
||||||
|
|
||||||
#define MIN_PACKET_SIZE 4
|
#define MIN_PACKET_SIZE 4
|
||||||
@@ -112,11 +113,7 @@ public:
|
|||||||
u_int32_t sessionId;
|
u_int32_t sessionId;
|
||||||
u_int16_t playerId;
|
u_int16_t playerId;
|
||||||
u_int16_t playerNumber;
|
u_int16_t playerNumber;
|
||||||
u_int16_t numberOfPlayers;
|
GameData gameData;
|
||||||
u_int16_t smallBlind;
|
|
||||||
u_int16_t handsBeforeRaise;
|
|
||||||
u_int16_t gameSpeed;
|
|
||||||
u_int32_t startCash;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NetPacketJoinGameAck();
|
NetPacketJoinGameAck();
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
#ifndef _SERVERRECVSTATE_H_
|
#ifndef _SERVERRECVSTATE_H_
|
||||||
#define _SERVERRECVSTATE_H_
|
#define _SERVERRECVSTATE_H_
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
#include <net/connectdata.h>
|
#include <net/connectdata.h>
|
||||||
|
#include <playerdata.h>
|
||||||
|
|
||||||
#define SERVER_INITIAL_STATE ServerRecvStateInit
|
#define SERVER_INITIAL_STATE ServerRecvStateInit
|
||||||
#define SERVER_START_GAME_STATE ServerRecvStateStartGame
|
#define SERVER_START_GAME_STATE ServerRecvStateStartGame
|
||||||
@@ -61,6 +61,10 @@ protected:
|
|||||||
|
|
||||||
// Protected constructor - this is a singleton.
|
// Protected constructor - this is a singleton.
|
||||||
ServerRecvStateInit();
|
ServerRecvStateInit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned m_curUniquePlayerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// State: Start server game.
|
// State: Start server game.
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <net/connectdata.h>
|
#include <net/connectdata.h>
|
||||||
#include <net/sessiondata.h>
|
#include <net/sessiondata.h>
|
||||||
#include <net/servercallback.h>
|
#include <net/servercallback.h>
|
||||||
|
#include <playerdata.h>
|
||||||
|
|
||||||
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
||||||
|
|
||||||
@@ -82,8 +83,10 @@ protected:
|
|||||||
SenderThread &GetSender();
|
SenderThread &GetSender();
|
||||||
ReceiverHelper &GetReceiver();
|
ReceiverHelper &GetReceiver();
|
||||||
|
|
||||||
const GameData &GetGameData();
|
const GameData &GetGameData() const;
|
||||||
bool CheckPassword(const std::string &password);
|
bool CheckPassword(const std::string &password) const;
|
||||||
|
|
||||||
|
PlayerDataList &GetPlayerDataList();
|
||||||
|
|
||||||
ServerSenderCallback &GetSenderCallback();
|
ServerSenderCallback &GetSenderCallback();
|
||||||
|
|
||||||
@@ -105,6 +108,7 @@ private:
|
|||||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||||
std::auto_ptr<GameData> m_gameData;
|
std::auto_ptr<GameData> m_gameData;
|
||||||
|
|
||||||
|
PlayerDataList m_playerDataList;
|
||||||
std::string m_password;
|
std::string m_password;
|
||||||
|
|
||||||
ServerCallback &m_callback;
|
ServerCallback &m_callback;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
enum PlayerType
|
enum PlayerType
|
||||||
@@ -60,6 +61,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList;
|
typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList;
|
||||||
|
typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user