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 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Hands before raise | Game Speed |
|
||||
| Hands before raise | Reserved |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Start Cash |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
@@ -97,6 +97,7 @@ HEADERS += src/game.h \
|
||||
src/gui/qt/mainwindow/mycardspixmaplabel.h \
|
||||
src/gui/qt/mainwindow/startsplash/startsplash.h \
|
||||
src/gui/qt/guiwrapper.h \
|
||||
src/gui/qt/gamedatawrapper.h \
|
||||
src/gui/qt/aboutpokerth/aboutpokerthimpl.h \
|
||||
src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.h \
|
||||
src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h \
|
||||
@@ -169,6 +170,7 @@ SOURCES += src/game.cpp \
|
||||
src/net/common/netexception.cpp \
|
||||
src/net/common/receiverhelper.cpp \
|
||||
src/gui/qt/guiwrapper.cpp \
|
||||
src/gui/qt/gamedatawrapper.cpp \
|
||||
src/gui/qt/mainwindow/mainwindowimpl.cpp \
|
||||
src/gui/qt/mainwindow/mycardspixmaplabel.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
|
||||
+100
-98
@@ -1,98 +1,100 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2006 by FThauer FHammer *
|
||||
* f.thauer@web.de *
|
||||
* *
|
||||
* 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 "guiwrapper.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
GuiWrapper::GuiWrapper() : myLog(0), myW(0)
|
||||
{
|
||||
|
||||
|
||||
myW = new mainWindowImpl;
|
||||
myW->show();
|
||||
|
||||
myLog = new Log(myW);
|
||||
myConfig = new ConfigFile;
|
||||
|
||||
}
|
||||
|
||||
|
||||
GuiWrapper::~GuiWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiWrapper::setGame(Game *g) { myW->setGame(g); }
|
||||
void GuiWrapper::setHand(HandInterface *lh) { myW->setHand(lh); }
|
||||
void GuiWrapper::setSession(Session *s) { myW->setSession(s); }
|
||||
|
||||
void GuiWrapper::refreshSet() const { myW->refreshSet(); }
|
||||
void GuiWrapper::refreshCash() const { myW->refreshCash(); }
|
||||
void GuiWrapper::refreshAction(int playerID, int playerAction) const { myW->refreshAction(playerID, playerAction); }
|
||||
void GuiWrapper::refreshChangePlayer() const { myW->refreshChangePlayer(); }
|
||||
void GuiWrapper::refreshAll() const { myW->refreshAll(); }
|
||||
void GuiWrapper::refreshPot() const { myW->refreshPot(); }
|
||||
void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->refreshGroupbox(playerID, status); }
|
||||
void GuiWrapper::refreshPlayerName() const { myW->refreshPlayerName(); }
|
||||
|
||||
void GuiWrapper::dealHoleCards() const { myW->dealHoleCards(); }
|
||||
void GuiWrapper::dealFlopCards() const { myW->dealFlopCards0(); }
|
||||
void GuiWrapper::dealTurnCard() const { myW->dealTurnCards0(); }
|
||||
void GuiWrapper::dealRiverCard() const { myW->dealRiverCards0(); }
|
||||
|
||||
void GuiWrapper::highlightRoundLabel(string round) const { myW->highlightRoundLabel(round); }
|
||||
|
||||
|
||||
void GuiWrapper::nextPlayerAnimation() const { myW->nextPlayerAnimation(); }
|
||||
|
||||
void GuiWrapper::preflopAnimation1() const { myW->preflopAnimation1(); }
|
||||
void GuiWrapper::preflopAnimation2() const { myW->preflopAnimation2(); }
|
||||
|
||||
void GuiWrapper::flopAnimation1() const { myW->flopAnimation1(); }
|
||||
void GuiWrapper::flopAnimation2() const { myW->flopAnimation2(); }
|
||||
|
||||
void GuiWrapper::turnAnimation1() const { myW->turnAnimation1(); }
|
||||
void GuiWrapper::turnAnimation2() const { myW->turnAnimation2(); }
|
||||
|
||||
void GuiWrapper::riverAnimation1() const { myW->riverAnimation1(); }
|
||||
void GuiWrapper::riverAnimation2() const { myW->riverAnimation2(); }
|
||||
|
||||
void GuiWrapper::postRiverAnimation1() const { myW->postRiverAnimation1(); }
|
||||
void GuiWrapper::postRiverRunAnimation1() const { myW->postRiverRunAnimation1(); }
|
||||
|
||||
void GuiWrapper::flipHolecardsAllIn() const { myW->flipHolecardsAllIn(); }
|
||||
|
||||
void GuiWrapper::nextRoundCleanGui() const { myW->nextRoundCleanGui(); }
|
||||
|
||||
void GuiWrapper::meInAction() const { myW->meInAction(); }
|
||||
|
||||
void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->logPlayerActionMsg(playerName, action, setValue); }
|
||||
void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); }
|
||||
|
||||
void GuiWrapper::SignalNetClientConnect(int actionID) { myW->SignalNetClientConnect(actionID); }
|
||||
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->SignalNetClientGameInfo(actionID); }
|
||||
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->SignalNetClientError(errorID, osErrorID); }
|
||||
|
||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
||||
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->SignalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2006 by FThauer FHammer *
|
||||
* f.thauer@web.de *
|
||||
* *
|
||||
* 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 "guiwrapper.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
GuiWrapper::GuiWrapper() : myLog(0), myW(0)
|
||||
{
|
||||
|
||||
|
||||
myW = new mainWindowImpl;
|
||||
myW->show();
|
||||
|
||||
myLog = new Log(myW);
|
||||
myConfig = new ConfigFile;
|
||||
|
||||
}
|
||||
|
||||
|
||||
GuiWrapper::~GuiWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiWrapper::setGame(Game *g) { myW->setGame(g); }
|
||||
void GuiWrapper::setHand(HandInterface *lh) { myW->setHand(lh); }
|
||||
void GuiWrapper::setSession(Session *s) { myW->setSession(s); }
|
||||
|
||||
void GuiWrapper::refreshSet() const { myW->refreshSet(); }
|
||||
void GuiWrapper::refreshCash() const { myW->refreshCash(); }
|
||||
void GuiWrapper::refreshAction(int playerID, int playerAction) const { myW->refreshAction(playerID, playerAction); }
|
||||
void GuiWrapper::refreshChangePlayer() const { myW->refreshChangePlayer(); }
|
||||
void GuiWrapper::refreshAll() const { myW->refreshAll(); }
|
||||
void GuiWrapper::refreshPot() const { myW->refreshPot(); }
|
||||
void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->refreshGroupbox(playerID, status); }
|
||||
void GuiWrapper::refreshPlayerName() const { myW->refreshPlayerName(); }
|
||||
|
||||
void GuiWrapper::dealHoleCards() const { myW->dealHoleCards(); }
|
||||
void GuiWrapper::dealFlopCards() const { myW->dealFlopCards0(); }
|
||||
void GuiWrapper::dealTurnCard() const { myW->dealTurnCards0(); }
|
||||
void GuiWrapper::dealRiverCard() const { myW->dealRiverCards0(); }
|
||||
|
||||
void GuiWrapper::highlightRoundLabel(string round) const { myW->highlightRoundLabel(round); }
|
||||
|
||||
|
||||
void GuiWrapper::nextPlayerAnimation() const { myW->nextPlayerAnimation(); }
|
||||
|
||||
void GuiWrapper::preflopAnimation1() const { myW->preflopAnimation1(); }
|
||||
void GuiWrapper::preflopAnimation2() const { myW->preflopAnimation2(); }
|
||||
|
||||
void GuiWrapper::flopAnimation1() const { myW->flopAnimation1(); }
|
||||
void GuiWrapper::flopAnimation2() const { myW->flopAnimation2(); }
|
||||
|
||||
void GuiWrapper::turnAnimation1() const { myW->turnAnimation1(); }
|
||||
void GuiWrapper::turnAnimation2() const { myW->turnAnimation2(); }
|
||||
|
||||
void GuiWrapper::riverAnimation1() const { myW->riverAnimation1(); }
|
||||
void GuiWrapper::riverAnimation2() const { myW->riverAnimation2(); }
|
||||
|
||||
void GuiWrapper::postRiverAnimation1() const { myW->postRiverAnimation1(); }
|
||||
void GuiWrapper::postRiverRunAnimation1() const { myW->postRiverRunAnimation1(); }
|
||||
|
||||
void GuiWrapper::flipHolecardsAllIn() const { myW->flipHolecardsAllIn(); }
|
||||
|
||||
void GuiWrapper::nextRoundCleanGui() const { myW->nextRoundCleanGui(); }
|
||||
|
||||
void GuiWrapper::meInAction() const { myW->meInAction(); }
|
||||
|
||||
void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->logPlayerActionMsg(playerName, action, setValue); }
|
||||
void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); }
|
||||
|
||||
void GuiWrapper::SignalNetClientConnect(int actionID) { myW->SignalNetClientConnect(actionID); }
|
||||
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->SignalNetClientGameInfo(actionID); }
|
||||
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::SignalNetServerError(int errorID, int osErrorID) { }
|
||||
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->SignalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
||||
|
||||
|
||||
@@ -92,6 +92,8 @@ public:
|
||||
void SignalNetClientGameInfo(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
|
||||
void SignalNetClientGameStart(const GameData &gameData);
|
||||
|
||||
void SignalNetServerSuccess(int actionID);
|
||||
void SignalNetServerError(int errorID, int osErrorID);
|
||||
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||
|
||||
@@ -538,6 +538,7 @@ mainWindowImpl::mainWindowImpl(QMainWindow *parent)
|
||||
connect(this, SIGNAL(SignalNetClientGameInfo(int)), myWaitingForServerGameDialog, SLOT(refresh(int)));
|
||||
// Errors are handled globally, not within one dialog.
|
||||
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)));
|
||||
|
||||
@@ -2199,6 +2200,11 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
|
||||
myWaitingForServerGameDialog->reject();
|
||||
}
|
||||
|
||||
void mainWindowImpl::networkStart(GameDataWrapper gameData)
|
||||
{
|
||||
mySession->startGame(gameData.GetGameData());
|
||||
}
|
||||
|
||||
void mainWindowImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||
|
||||
// cout << event->key() << endl;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "handinterface.h"
|
||||
#include "game_defs.h"
|
||||
#include <gamedatawrapper.h>
|
||||
|
||||
class Session;
|
||||
class Game;
|
||||
@@ -93,6 +94,7 @@ signals:
|
||||
void SignalNetClientConnect(int actionID);
|
||||
void SignalNetClientGameInfo(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
void SignalNetClientGameStart(GameDataWrapper gameData);
|
||||
void SignalNetServerPlayerJoined(QString playerName);
|
||||
|
||||
public slots:
|
||||
@@ -189,6 +191,7 @@ public slots:
|
||||
void paintStartSplash();
|
||||
|
||||
void networkError(int, int);
|
||||
void networkStart(GameDataWrapper);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef _CLIENTCALLBACK_H_
|
||||
#define _CLIENTCALLBACK_H_
|
||||
|
||||
struct GameData;
|
||||
|
||||
class ClientCallback
|
||||
{
|
||||
public:
|
||||
@@ -29,6 +31,8 @@ public:
|
||||
virtual void SignalNetClientConnect(int actionID) = 0;
|
||||
virtual void SignalNetClientGameInfo(int actionID) = 0;
|
||||
virtual void SignalNetClientError(int errorID, int osErrorID) = 0;
|
||||
|
||||
virtual void SignalNetClientGameStart(const GameData &gameData) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,7 @@ class ClientState;
|
||||
class SenderThread;
|
||||
class ReceiverHelper;
|
||||
class ClientSenderCallback;
|
||||
struct GameData;
|
||||
|
||||
class ClientThread : public Thread
|
||||
{
|
||||
@@ -64,6 +65,9 @@ protected:
|
||||
SenderThread &GetSender();
|
||||
ReceiverHelper &GetReceiver();
|
||||
|
||||
const GameData &GetGameData() const;
|
||||
void SetGameData(const GameData &gameData);
|
||||
|
||||
ClientSenderCallback &GetSenderCallback();
|
||||
|
||||
private:
|
||||
@@ -72,9 +76,12 @@ private:
|
||||
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
||||
ClientState *m_curState;
|
||||
ClientCallback &m_callback;
|
||||
|
||||
std::auto_ptr<SenderThread> m_sender;
|
||||
std::auto_ptr<ReceiverHelper> m_receiver;
|
||||
|
||||
std::auto_ptr<GameData> m_gameData;
|
||||
|
||||
friend class ClientStateInit;
|
||||
friend class ClientStateStartResolve;
|
||||
friend class ClientStateResolving;
|
||||
|
||||
@@ -366,6 +366,11 @@ ClientStateWaitSession::Process(ClientThread &client)
|
||||
|
||||
if (tmpPacket.get() && tmpPacket->ToNetPacketJoinGameAck())
|
||||
{
|
||||
// Initialise game configuration.
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||
client.SetGameData(joinGameAckData.gameData);
|
||||
|
||||
client.SetState(ClientStateWaitGame::Instance());
|
||||
retVal = MSG_SOCK_SESSION_DONE;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <net/receiverhelper.h>
|
||||
#include <net/clientexception.h>
|
||||
#include <net/socket_msg.h>
|
||||
|
||||
#include <gamedata.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -57,6 +57,7 @@ ClientThread::ClientThread(ClientCallback &cb)
|
||||
m_senderCallback.reset(new ClientSenderCallback(*this));
|
||||
m_sender.reset(new SenderThread(GetSenderCallback()));
|
||||
m_receiver.reset(new ReceiverHelper);
|
||||
m_gameData.reset(new GameData);
|
||||
}
|
||||
|
||||
ClientThread::~ClientThread()
|
||||
@@ -103,6 +104,10 @@ ClientThread::Main()
|
||||
GetCallback().SignalNetClientConnect(msg);
|
||||
else
|
||||
GetCallback().SignalNetClientGameInfo(msg);
|
||||
|
||||
// Additionally signal the start of the game.
|
||||
if (msg == MSG_SOCK_GAME_START)
|
||||
GetCallback().SignalNetClientGameStart(GetGameData());
|
||||
}
|
||||
}
|
||||
} catch (const NetException &e)
|
||||
@@ -154,6 +159,20 @@ ClientThread::GetReceiver()
|
||||
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 &
|
||||
ClientThread::GetSenderCallback()
|
||||
{
|
||||
|
||||
@@ -78,7 +78,7 @@ struct NetPacketJoinGameAckData
|
||||
u_int16_t numberOfPlayers;
|
||||
u_int16_t smallBlind;
|
||||
u_int16_t handsBeforeRaise;
|
||||
u_int16_t gameSpeed;
|
||||
u_int16_t reserved;
|
||||
u_int32_t startCash;
|
||||
};
|
||||
|
||||
@@ -416,11 +416,10 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData)
|
||||
tmpData->sessionId = htonl(inData.sessionId);
|
||||
tmpData->playerId = htons(inData.playerId);
|
||||
tmpData->playerNumber = htons(inData.playerNumber);
|
||||
tmpData->numberOfPlayers = htons(inData.numberOfPlayers);
|
||||
tmpData->smallBlind = htons(inData.smallBlind);
|
||||
tmpData->handsBeforeRaise = htons(inData.handsBeforeRaise);
|
||||
tmpData->gameSpeed = htons(inData.gameSpeed);
|
||||
tmpData->startCash = htonl(inData.startCash);
|
||||
tmpData->numberOfPlayers = htons(inData.gameData.numberOfPlayers);
|
||||
tmpData->smallBlind = htons(inData.gameData.smallBlind);
|
||||
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
|
||||
tmpData->startCash = htonl(inData.gameData.startCash);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -429,14 +428,13 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const
|
||||
NetPacketJoinGameAckData *tmpData = (NetPacketJoinGameAckData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.sessionId = ntohl(tmpData->sessionId);
|
||||
outData.playerId = ntohs(tmpData->playerId);
|
||||
outData.playerNumber = ntohs(tmpData->playerNumber);
|
||||
outData.numberOfPlayers = ntohs(tmpData->numberOfPlayers);
|
||||
outData.smallBlind = ntohs(tmpData->smallBlind);
|
||||
outData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||
outData.gameSpeed = ntohs(tmpData->gameSpeed);
|
||||
outData.startCash = ntohl(tmpData->startCash);
|
||||
outData.sessionId = ntohl(tmpData->sessionId);
|
||||
outData.playerId = ntohs(tmpData->playerId);
|
||||
outData.playerNumber = ntohs(tmpData->playerNumber);
|
||||
outData.gameData.numberOfPlayers = ntohs(tmpData->numberOfPlayers);
|
||||
outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
|
||||
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||
outData.gameData.startCash = ntohl(tmpData->startCash);
|
||||
}
|
||||
|
||||
const NetPacketJoinGameAck *
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <net/senderthread.h>
|
||||
#include <net/netpacket.h>
|
||||
#include <net/socket_msg.h>
|
||||
#include <gamedata.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -43,6 +45,7 @@ ServerRecvStateInit::Instance()
|
||||
}
|
||||
|
||||
ServerRecvStateInit::ServerRecvStateInit()
|
||||
: m_curUniquePlayerId(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -76,16 +79,54 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
|
||||
const NetPacketJoinGame *tmpPacket = packet->ToNetPacketJoinGame();
|
||||
if (tmpPacket)
|
||||
{
|
||||
// TODO: check password
|
||||
NetPacketJoinGame::Data playerData;
|
||||
tmpPacket->GetData(playerData);
|
||||
server.GetCallback().SignalNetServerPlayerJoined(playerData.playerName);
|
||||
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
// TODO: set data.
|
||||
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
|
||||
server.GetSender().Send(answer, recvSock);
|
||||
session->SetState(SessionData::Established);
|
||||
NetPacketJoinGame::Data joinGameData;
|
||||
tmpPacket->GetData(joinGameData);
|
||||
// Check the server password.
|
||||
if (server.CheckPassword(joinGameData.password))
|
||||
{
|
||||
PlayerDataList &playerDataList = server.GetPlayerDataList();
|
||||
// Check whether this player is already connected.
|
||||
PlayerDataList::const_iterator player_i = playerDataList.begin();
|
||||
PlayerDataList::const_iterator player_end = playerDataList.end();
|
||||
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
|
||||
{
|
||||
|
||||
@@ -309,18 +309,24 @@ ServerRecvThread::GetReceiver()
|
||||
}
|
||||
|
||||
const GameData &
|
||||
ServerRecvThread::GetGameData()
|
||||
ServerRecvThread::GetGameData() const
|
||||
{
|
||||
assert(m_gameData.get());
|
||||
return *m_gameData;
|
||||
}
|
||||
|
||||
bool
|
||||
ServerRecvThread::CheckPassword(const std::string &password)
|
||||
ServerRecvThread::CheckPassword(const std::string &password) const
|
||||
{
|
||||
return (password == m_password);
|
||||
}
|
||||
|
||||
PlayerDataList &
|
||||
ServerRecvThread::GetPlayerDataList()
|
||||
{
|
||||
return m_playerDataList;
|
||||
}
|
||||
|
||||
ServerSenderCallback &
|
||||
ServerRecvThread::GetSenderCallback()
|
||||
{
|
||||
|
||||
+2
-5
@@ -22,6 +22,7 @@
|
||||
#define _NETPACKET_H_
|
||||
|
||||
#include <playerdata.h>
|
||||
#include <gamedata.h>
|
||||
#include <net/socket_helper.h>
|
||||
|
||||
#define MIN_PACKET_SIZE 4
|
||||
@@ -112,11 +113,7 @@ public:
|
||||
u_int32_t sessionId;
|
||||
u_int16_t playerId;
|
||||
u_int16_t playerNumber;
|
||||
u_int16_t numberOfPlayers;
|
||||
u_int16_t smallBlind;
|
||||
u_int16_t handsBeforeRaise;
|
||||
u_int16_t gameSpeed;
|
||||
u_int32_t startCash;
|
||||
GameData gameData;
|
||||
};
|
||||
|
||||
NetPacketJoinGameAck();
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#ifndef _SERVERRECVSTATE_H_
|
||||
#define _SERVERRECVSTATE_H_
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <net/connectdata.h>
|
||||
#include <playerdata.h>
|
||||
|
||||
#define SERVER_INITIAL_STATE ServerRecvStateInit
|
||||
#define SERVER_START_GAME_STATE ServerRecvStateStartGame
|
||||
@@ -61,6 +61,10 @@ protected:
|
||||
|
||||
// Protected constructor - this is a singleton.
|
||||
ServerRecvStateInit();
|
||||
|
||||
private:
|
||||
|
||||
unsigned m_curUniquePlayerId;
|
||||
};
|
||||
|
||||
// State: Start server game.
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <net/connectdata.h>
|
||||
#include <net/sessiondata.h>
|
||||
#include <net/servercallback.h>
|
||||
#include <playerdata.h>
|
||||
|
||||
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
||||
|
||||
@@ -82,8 +83,10 @@ protected:
|
||||
SenderThread &GetSender();
|
||||
ReceiverHelper &GetReceiver();
|
||||
|
||||
const GameData &GetGameData();
|
||||
bool CheckPassword(const std::string &password);
|
||||
const GameData &GetGameData() const;
|
||||
bool CheckPassword(const std::string &password) const;
|
||||
|
||||
PlayerDataList &GetPlayerDataList();
|
||||
|
||||
ServerSenderCallback &GetSenderCallback();
|
||||
|
||||
@@ -105,6 +108,7 @@ private:
|
||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||
std::auto_ptr<GameData> m_gameData;
|
||||
|
||||
PlayerDataList m_playerDataList;
|
||||
std::string m_password;
|
||||
|
||||
ServerCallback &m_callback;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
enum PlayerType
|
||||
@@ -60,6 +61,7 @@ private:
|
||||
};
|
||||
|
||||
typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList;
|
||||
typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user