Client engine factory needs to be free of configuration file (configuration provided by server). Separated specific start data from general game data. Sending client game object to GUI after creation. Client thread now manages player and game data.
This commit is contained in:
@@ -26,11 +26,8 @@
|
|||||||
#include "clientturn.h"
|
#include "clientturn.h"
|
||||||
#include "clientriver.h"
|
#include "clientriver.h"
|
||||||
|
|
||||||
#include <configfile.h>
|
|
||||||
|
|
||||||
|
ClientEngineFactory::ClientEngineFactory()
|
||||||
ClientEngineFactory::ClientEngineFactory(ConfigFile *c)
|
|
||||||
: myConfig(c)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +49,7 @@ BoardInterface* ClientEngineFactory::createBoard()
|
|||||||
|
|
||||||
PlayerInterface* ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
|
PlayerInterface* ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
|
||||||
{
|
{
|
||||||
return new ClientPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB);
|
return new ClientPlayer(NULL, b, id, uniqueId, type, name, avatar, sC, aS, mB);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreflopInterface* ClientEngineFactory::createPreflop(HandInterface* hi, int id, int aP, int dP, int sB)
|
PreflopInterface* ClientEngineFactory::createPreflop(HandInterface* hi, int id, int aP, int dP, int sB)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class ConfigFile;
|
|||||||
class ClientEngineFactory : public EngineFactory
|
class ClientEngineFactory : public EngineFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClientEngineFactory(ConfigFile*);
|
ClientEngineFactory();
|
||||||
~ClientEngineFactory();
|
~ClientEngineFactory();
|
||||||
|
|
||||||
HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC);
|
HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC);
|
||||||
@@ -44,9 +44,6 @@ public:
|
|||||||
FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB);
|
FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB);
|
||||||
TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB);
|
TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB);
|
||||||
RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB);
|
RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB);
|
||||||
|
|
||||||
private:
|
|
||||||
ConfigFile *myConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+3
-2
@@ -29,13 +29,14 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
|
Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
|
||||||
const PlayerDataList &playerDataList, const GameData &gameData, int gameId)
|
const PlayerDataList &playerDataList, const GameData &gameData,
|
||||||
|
const StartData &startData, int gameId)
|
||||||
: myGui(gui), myFactory(factory), actualHand(0), actualBoard(0),
|
: myGui(gui), myFactory(factory), actualHand(0), actualBoard(0),
|
||||||
startQuantityPlayers(gameData.numberOfPlayers),
|
startQuantityPlayers(gameData.numberOfPlayers),
|
||||||
startCash(gameData.startCash), startSmallBlind(gameData.smallBlind),
|
startCash(gameData.startCash), startSmallBlind(gameData.smallBlind),
|
||||||
startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise),
|
startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise),
|
||||||
myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers),
|
myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers),
|
||||||
actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(gameData.startDealerPos)
|
actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(startData.startDealerPos)
|
||||||
{
|
{
|
||||||
// cout << "Create Game Object" << "\n";
|
// cout << "Create Game Object" << "\n";
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
+4
-1
@@ -33,11 +33,14 @@ class PlayerInterface;
|
|||||||
class BoardInterface;
|
class BoardInterface;
|
||||||
class EngineFactory;
|
class EngineFactory;
|
||||||
struct GameData;
|
struct GameData;
|
||||||
|
struct StartData;
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Game(GuiInterface *gui, boost::shared_ptr<EngineFactory> factory, const PlayerDataList &playerDataList, const GameData &gameData, int gameId);
|
Game(GuiInterface *gui, boost::shared_ptr<EngineFactory> factory,
|
||||||
|
const PlayerDataList &playerDataList, const GameData &gameData,
|
||||||
|
const StartData &startData, int gameId);
|
||||||
|
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -26,12 +26,17 @@
|
|||||||
struct GameData
|
struct GameData
|
||||||
{
|
{
|
||||||
GameData() : numberOfPlayers(0), startCash(0), smallBlind(0),
|
GameData() : numberOfPlayers(0), startCash(0), smallBlind(0),
|
||||||
handsBeforeRaise(1), guiSpeed(4), startDealerPos(0) {}
|
handsBeforeRaise(1), guiSpeed(4) {}
|
||||||
int numberOfPlayers;
|
int numberOfPlayers;
|
||||||
int startCash;
|
int startCash;
|
||||||
int smallBlind;
|
int smallBlind;
|
||||||
int handsBeforeRaise;
|
int handsBeforeRaise;
|
||||||
int guiSpeed;
|
int guiSpeed;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StartData
|
||||||
|
{
|
||||||
|
StartData() : startDealerPos(0) {}
|
||||||
int startDealerPos;
|
int startDealerPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) m
|
|||||||
void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); }
|
void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); }
|
||||||
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName); }
|
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName); }
|
||||||
void ServerGuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerName); }
|
void ServerGuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerName); }
|
||||||
void ServerGuiWrapper::SignalNetClientGameStart(const GameData &gameData) { if (myClientcb) myClientcb->SignalNetClientGameStart(gameData); }
|
void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
|
||||||
|
|
||||||
void ServerGuiWrapper::SignalNetServerSuccess(int actionID) { if (myServercb) myServercb->SignalNetServerSuccess(actionID); }
|
void ServerGuiWrapper::SignalNetServerSuccess(int actionID) { if (myServercb) myServercb->SignalNetServerSuccess(actionID); }
|
||||||
void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
|
void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public:
|
|||||||
void SignalNetClientPlayerJoined(const std::string &playerName);
|
void SignalNetClientPlayerJoined(const std::string &playerName);
|
||||||
void SignalNetClientPlayerLeft(const std::string &playerName);
|
void SignalNetClientPlayerLeft(const std::string &playerName);
|
||||||
|
|
||||||
void SignalNetClientGameStart(const GameData &gameData);
|
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||||
|
|
||||||
void SignalNetServerSuccess(int actionID);
|
void SignalNetServerSuccess(int actionID);
|
||||||
void SignalNetServerError(int errorID, int osErrorID);
|
void SignalNetServerError(int errorID, int osErrorID);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGam
|
|||||||
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); }
|
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); }
|
||||||
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
||||||
void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { myW->signalNetClientPlayerLeft(QString::fromUtf8(playerName.c_str())); }
|
void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { myW->signalNetClientPlayerLeft(QString::fromUtf8(playerName.c_str())); }
|
||||||
void GuiWrapper::SignalNetClientGameStart(const GameData &gameData) { myW->signalNetClientGameStart(); }
|
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
|
||||||
|
|
||||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public:
|
|||||||
void SignalNetClientPlayerJoined(const std::string &playerName);
|
void SignalNetClientPlayerJoined(const std::string &playerName);
|
||||||
void SignalNetClientPlayerLeft(const std::string &playerName);
|
void SignalNetClientPlayerLeft(const std::string &playerName);
|
||||||
|
|
||||||
void SignalNetClientGameStart(const GameData &gameData);
|
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||||
|
|
||||||
void SignalNetServerSuccess(int actionID);
|
void SignalNetServerSuccess(int actionID);
|
||||||
void SignalNetServerError(int errorID, int osErrorID);
|
void SignalNetServerError(int errorID, int osErrorID);
|
||||||
|
|||||||
@@ -597,7 +597,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
|||||||
|
|
||||||
// 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()), this, SLOT(networkStart()));
|
connect(this, SIGNAL(signalNetClientGameStart(boost::shared_ptr<Game>)), this, SLOT(networkStart(boost::shared_ptr<Game>)));
|
||||||
|
|
||||||
connect(this, SIGNAL(signalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
|
connect(this, SIGNAL(signalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
|
||||||
connect(this, SIGNAL(signalNetServerPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
|
connect(this, SIGNAL(signalNetServerPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
|
||||||
@@ -656,11 +656,12 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
|
|||||||
gameData.guiSpeed = myConfig->readConfigInt("GameSpeed");
|
gameData.guiSpeed = myConfig->readConfigInt("GameSpeed");
|
||||||
}
|
}
|
||||||
// Set dealer pos.
|
// Set dealer pos.
|
||||||
|
StartData startData;
|
||||||
Tools myTool;
|
Tools myTool;
|
||||||
myTool.getRandNumber(0, gameData.numberOfPlayers-1, 1, &gameData.startDealerPos, 0);
|
myTool.getRandNumber(0, gameData.numberOfPlayers-1, 1, &startData.startDealerPos, 0);
|
||||||
|
|
||||||
//Start Game!!!
|
//Start Game!!!
|
||||||
mySession->startLocalGame(gameData);
|
mySession->startLocalGame(gameData, startData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1182,11 +1183,11 @@ void mainWindowImpl::dealHoleCards() {
|
|||||||
|
|
||||||
// Karten der Gegner austeilen
|
// Karten der Gegner austeilen
|
||||||
int i, j;
|
int i, j;
|
||||||
HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand();
|
Game *currentGame = mySession->getCurrentGame();
|
||||||
for(i=1; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
for(i=1; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
||||||
currentHand->getPlayerArray()[i]->getMyCards(tempCardsIntArray);
|
currentGame->getPlayerArray()[i]->getMyCards(tempCardsIntArray);
|
||||||
for(j=0; j<2; j++) {
|
for(j=0; j<2; j++) {
|
||||||
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
|
if(currentGame->getPlayerArray()[i]->getMyActiveStatus()) {
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
tempCardsPixmapArray[j].load(":/cards/resources/graphics/cards/"+QString::number(tempCardsIntArray[j], 10)+".png");
|
tempCardsPixmapArray[j].load(":/cards/resources/graphics/cards/"+QString::number(tempCardsIntArray[j], 10)+".png");
|
||||||
holeCardsArray[i][j]->setPixmap(tempCardsPixmapArray[j],FALSE);
|
holeCardsArray[i][j]->setPixmap(tempCardsPixmapArray[j],FALSE);
|
||||||
@@ -1204,10 +1205,10 @@ void mainWindowImpl::dealHoleCards() {
|
|||||||
}
|
}
|
||||||
// eigenen Karten austeilen
|
// eigenen Karten austeilen
|
||||||
|
|
||||||
currentHand->getPlayerArray()[0]->getMyCards(tempCardsIntArray);
|
currentGame->getPlayerArray()[0]->getMyCards(tempCardsIntArray);
|
||||||
for(i=0; i<2; i++) {
|
for(i=0; i<2; i++) {
|
||||||
|
|
||||||
if(currentHand->getPlayerArray()[0]->getMyActiveStatus()) {
|
if(currentGame->getPlayerArray()[0]->getMyActiveStatus()) {
|
||||||
|
|
||||||
tempCardsPixmapArray[i].load(":/cards/resources/graphics/cards/"+QString::number(tempCardsIntArray[i], 10)+".png");
|
tempCardsPixmapArray[i].load(":/cards/resources/graphics/cards/"+QString::number(tempCardsIntArray[i], 10)+".png");
|
||||||
holeCardsArray[0][i]->setPixmap(tempCardsPixmapArray[i], FALSE);
|
holeCardsArray[0][i]->setPixmap(tempCardsPixmapArray[i], FALSE);
|
||||||
@@ -2413,11 +2414,9 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
|
|||||||
myWaitingForServerGameDialog->reject();
|
myWaitingForServerGameDialog->reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindowImpl::networkStart()
|
void mainWindowImpl::networkStart(boost::shared_ptr<Game> game)
|
||||||
{
|
{
|
||||||
// QMutexLocker lock(&myClientDataMutex);
|
mySession->startClientGame(game);
|
||||||
// assert(!myClientPlayerDataList.empty());
|
|
||||||
// mySession->startClientGame(myClientGameData, myClientPlayerDataList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindowImpl::keyPressEvent ( QKeyEvent * event ) {
|
void mainWindowImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
class Log;
|
class Log;
|
||||||
class ConfigFile;
|
class ConfigFile;
|
||||||
class Session;
|
class Session;
|
||||||
|
class Game;
|
||||||
|
|
||||||
class GuiInterface;
|
class GuiInterface;
|
||||||
class BoardInterface;
|
class BoardInterface;
|
||||||
@@ -108,7 +109,7 @@ signals:
|
|||||||
void signalNetClientError(int errorID, int osErrorID);
|
void signalNetClientError(int errorID, int osErrorID);
|
||||||
void signalNetClientPlayerJoined(QString playerName);
|
void signalNetClientPlayerJoined(QString playerName);
|
||||||
void signalNetClientPlayerLeft(QString playerName);
|
void signalNetClientPlayerLeft(QString playerName);
|
||||||
void signalNetClientGameStart();
|
void signalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||||
void signalNetServerPlayerJoined(QString playerName);
|
void signalNetServerPlayerJoined(QString playerName);
|
||||||
void signalNetServerPlayerLeft(QString playerName);
|
void signalNetServerPlayerLeft(QString playerName);
|
||||||
|
|
||||||
@@ -231,7 +232,7 @@ public slots:
|
|||||||
void paintStartSplash();
|
void paintStartSplash();
|
||||||
|
|
||||||
void networkError(int, int);
|
void networkError(int, int);
|
||||||
void networkStart();
|
void networkStart(boost::shared_ptr<Game> game);
|
||||||
|
|
||||||
void closeEvent(QCloseEvent*);
|
void closeEvent(QCloseEvent*);
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,9 @@
|
|||||||
#define _CLIENTCALLBACK_H_
|
#define _CLIENTCALLBACK_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
struct GameData;
|
class Game;
|
||||||
|
|
||||||
class ClientCallback
|
class ClientCallback
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,7 @@ public:
|
|||||||
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;
|
virtual void SignalNetClientGameStart(boost::shared_ptr<Game> game) = 0;
|
||||||
virtual void SignalNetClientPlayerJoined(const std::string &playerName) = 0;
|
virtual void SignalNetClientPlayerJoined(const std::string &playerName) = 0;
|
||||||
virtual void SignalNetClientPlayerLeft(const std::string &playerName) = 0;
|
virtual void SignalNetClientPlayerLeft(const std::string &playerName) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -191,6 +191,24 @@ protected:
|
|||||||
ClientStateWaitGame();
|
ClientStateWaitGame();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// State: Wait for start of the next hand.
|
||||||
|
class ClientStateWaitHand : public ClientState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Access the state singleton.
|
||||||
|
static ClientStateWaitHand &Instance();
|
||||||
|
|
||||||
|
virtual ~ClientStateWaitHand();
|
||||||
|
|
||||||
|
// select on socket.
|
||||||
|
virtual int Process(ClientThread &client);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected constructor - this is a singleton.
|
||||||
|
ClientStateWaitHand();
|
||||||
|
};
|
||||||
|
|
||||||
// State: Final (TODO).
|
// State: Final (TODO).
|
||||||
class ClientStateFinal : public ClientState
|
class ClientStateFinal : public ClientState
|
||||||
{
|
{
|
||||||
|
|||||||
+24
-8
@@ -22,22 +22,23 @@
|
|||||||
#define _CLIENTTHREAD_H_
|
#define _CLIENTTHREAD_H_
|
||||||
|
|
||||||
#include <core/thread.h>
|
#include <core/thread.h>
|
||||||
#include <map>
|
#include <guiinterface.h>
|
||||||
|
#include <playerdata.h>
|
||||||
|
#include <gamedata.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <net/clientcallback.h>
|
|
||||||
|
|
||||||
class ClientContext;
|
class ClientContext;
|
||||||
class ClientState;
|
class ClientState;
|
||||||
class SenderThread;
|
class SenderThread;
|
||||||
class ReceiverHelper;
|
class ReceiverHelper;
|
||||||
class ClientSenderCallback;
|
class ClientSenderCallback;
|
||||||
struct GameData;
|
class Game;
|
||||||
|
|
||||||
class ClientThread : public Thread
|
class ClientThread : public Thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClientThread(ClientCallback &gui);
|
ClientThread(GuiInterface &gui);
|
||||||
virtual ~ClientThread();
|
virtual ~ClientThread();
|
||||||
|
|
||||||
// Set the parameters. Does not do any error checking.
|
// Set the parameters. Does not do any error checking.
|
||||||
@@ -51,6 +52,7 @@ public:
|
|||||||
const std::string &playerName);
|
const std::string &playerName);
|
||||||
|
|
||||||
ClientCallback &GetCallback();
|
ClientCallback &GetCallback();
|
||||||
|
GuiInterface &GetGui();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map<unsigned, std::string> PlayerMap;
|
typedef std::map<unsigned, std::string> PlayerMap;
|
||||||
@@ -69,23 +71,36 @@ protected:
|
|||||||
|
|
||||||
const GameData &GetGameData() const;
|
const GameData &GetGameData() const;
|
||||||
void SetGameData(const GameData &gameData);
|
void SetGameData(const GameData &gameData);
|
||||||
|
const StartData &GetStartData() const;
|
||||||
|
void SetStartData(const StartData &startData);
|
||||||
|
|
||||||
|
boost::shared_ptr<Game> GetGame();
|
||||||
|
|
||||||
ClientSenderCallback &GetSenderCallback();
|
ClientSenderCallback &GetSenderCallback();
|
||||||
|
|
||||||
PlayerMap &GetPlayerMap();
|
void AddPlayerData(boost::shared_ptr<PlayerData> playerData);
|
||||||
|
void RemovePlayerData(unsigned playerId);
|
||||||
|
const PlayerDataList &GetPlayerDataList() const;
|
||||||
|
|
||||||
|
int m_myPlayerNum; // TODO: Hack
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::auto_ptr<ClientContext> m_context;
|
std::auto_ptr<ClientContext> m_context;
|
||||||
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
||||||
ClientState *m_curState;
|
ClientState *m_curState;
|
||||||
ClientCallback &m_callback;
|
GuiInterface &m_gui;
|
||||||
|
|
||||||
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;
|
GameData m_gameData;
|
||||||
PlayerMap m_playerMap;
|
StartData m_startData;
|
||||||
|
PlayerDataList m_playerDataList;
|
||||||
|
|
||||||
|
boost::shared_ptr<Game> m_game;
|
||||||
|
|
||||||
|
unsigned m_curGameId;
|
||||||
|
|
||||||
friend class ClientStateInit;
|
friend class ClientStateInit;
|
||||||
friend class ClientStateStartResolve;
|
friend class ClientStateStartResolve;
|
||||||
@@ -95,6 +110,7 @@ friend class ClientStateConnecting;
|
|||||||
friend class ClientStateStartSession;
|
friend class ClientStateStartSession;
|
||||||
friend class ClientStateWaitSession;
|
friend class ClientStateWaitSession;
|
||||||
friend class ClientStateWaitGame;
|
friend class ClientStateWaitGame;
|
||||||
|
friend class ClientStateWaitHand;
|
||||||
friend class ClientStateFinal;
|
friend class ClientStateFinal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@
|
|||||||
#include <net/socket_helper.h>
|
#include <net/socket_helper.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
|
|
||||||
|
#include <game.h>
|
||||||
|
#include <playerinterface.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define CLIENT_WAIT_TIMEOUT_MSEC 50
|
#define CLIENT_WAIT_TIMEOUT_MSEC 50
|
||||||
@@ -374,7 +377,14 @@ ClientStateWaitSession::Process(ClientThread &client)
|
|||||||
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||||
client.SetGameData(joinGameAckData.gameData);
|
client.SetGameData(joinGameAckData.gameData);
|
||||||
|
|
||||||
client.GetCallback().SignalNetClientPlayerJoined(context.GetPlayerName());
|
// TODO: Hack
|
||||||
|
client.m_myPlayerNum = joinGameAckData.playerNumber;
|
||||||
|
|
||||||
|
// TODO: Type Human is fixed here.
|
||||||
|
boost::shared_ptr<PlayerData> playerData(
|
||||||
|
new PlayerData(joinGameAckData.playerId, joinGameAckData.playerNumber, PLAYER_TYPE_HUMAN));
|
||||||
|
playerData->SetName(context.GetPlayerName());
|
||||||
|
client.AddPlayerData(playerData);
|
||||||
|
|
||||||
client.SetState(ClientStateWaitGame::Instance());
|
client.SetState(ClientStateWaitGame::Instance());
|
||||||
retVal = MSG_SOCK_SESSION_DONE;
|
retVal = MSG_SOCK_SESSION_DONE;
|
||||||
@@ -422,23 +432,32 @@ ClientStateWaitGame::Process(ClientThread &client)
|
|||||||
{
|
{
|
||||||
if (tmpPacket->ToNetPacketGameStart())
|
if (tmpPacket->ToNetPacketGameStart())
|
||||||
{
|
{
|
||||||
client.SetState(ClientStateFinal::Instance());
|
// Start the network game as client.
|
||||||
|
NetPacketGameStart::Data gameStartData;
|
||||||
|
tmpPacket->ToNetPacketGameStart()->GetData(gameStartData);
|
||||||
|
|
||||||
|
client.SetStartData(gameStartData.startData);
|
||||||
|
|
||||||
|
client.SetState(ClientStateWaitHand::Instance());
|
||||||
retVal = MSG_NET_GAME_CLIENT_START;
|
retVal = MSG_NET_GAME_CLIENT_START;
|
||||||
}
|
}
|
||||||
else if (tmpPacket->ToNetPacketPlayerJoined())
|
else if (tmpPacket->ToNetPacketPlayerJoined())
|
||||||
{
|
{
|
||||||
NetPacketPlayerJoined::Data playerData;
|
// Another player joined the network game.
|
||||||
tmpPacket->ToNetPacketPlayerJoined()->GetData(playerData);
|
NetPacketPlayerJoined::Data netPlayerData;
|
||||||
client.GetCallback().SignalNetClientPlayerJoined(playerData.playerName);
|
tmpPacket->ToNetPacketPlayerJoined()->GetData(netPlayerData);
|
||||||
client.GetPlayerMap()[playerData.playerId] = playerData.playerName;
|
|
||||||
|
boost::shared_ptr<PlayerData> playerData(
|
||||||
|
new PlayerData(netPlayerData.playerId, netPlayerData.playerNumber, netPlayerData.ptype));
|
||||||
|
playerData->SetName(netPlayerData.playerName);
|
||||||
|
client.AddPlayerData(playerData);
|
||||||
}
|
}
|
||||||
else if (tmpPacket->ToNetPacketPlayerLeft())
|
else if (tmpPacket->ToNetPacketPlayerLeft())
|
||||||
{
|
{
|
||||||
// TODO hacked.
|
// Another player left the network game.
|
||||||
NetPacketPlayerLeft::Data playerData;
|
NetPacketPlayerLeft::Data netPlayerData;
|
||||||
tmpPacket->ToNetPacketPlayerLeft()->GetData(playerData);
|
tmpPacket->ToNetPacketPlayerLeft()->GetData(netPlayerData);
|
||||||
client.GetCallback().SignalNetClientPlayerLeft(client.GetPlayerMap()[playerData.playerId]);
|
client.RemovePlayerData(netPlayerData.playerId);
|
||||||
client.GetPlayerMap().erase(playerData.playerId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: handle error packet
|
// TODO: handle error packet
|
||||||
@@ -448,6 +467,49 @@ ClientStateWaitGame::Process(ClientThread &client)
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ClientStateWaitHand &
|
||||||
|
ClientStateWaitHand::Instance()
|
||||||
|
{
|
||||||
|
static ClientStateWaitHand state;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientStateWaitHand::ClientStateWaitHand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientStateWaitHand::~ClientStateWaitHand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ClientStateWaitHand::Process(ClientThread &client)
|
||||||
|
{
|
||||||
|
ClientContext &context = client.GetContext();
|
||||||
|
|
||||||
|
// delegate to receiver helper class
|
||||||
|
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||||
|
|
||||||
|
if (tmpPacket.get())
|
||||||
|
{
|
||||||
|
if (tmpPacket->ToNetPacketHandStart())
|
||||||
|
{
|
||||||
|
NetPacketHandStart::Data tmpData;
|
||||||
|
tmpPacket->ToNetPacketHandStart()->GetData(tmpData);
|
||||||
|
// TODO: Hack
|
||||||
|
int myCards[2];
|
||||||
|
myCards[0] = (int)tmpData.yourCards[0];
|
||||||
|
myCards[1] = (int)tmpData.yourCards[1];
|
||||||
|
client.GetGame()->getPlayerArray()[client.m_myPlayerNum]->setMyCards(myCards);
|
||||||
|
client.GetGui().dealHoleCards();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MSG_SOCK_INTERNAL_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
ClientStateFinal &
|
ClientStateFinal &
|
||||||
ClientStateFinal::Instance()
|
ClientStateFinal::Instance()
|
||||||
{
|
{
|
||||||
@@ -466,21 +528,7 @@ ClientStateFinal::~ClientStateFinal()
|
|||||||
int
|
int
|
||||||
ClientStateFinal::Process(ClientThread &client)
|
ClientStateFinal::Process(ClientThread &client)
|
||||||
{
|
{
|
||||||
ClientContext &context = client.GetContext();
|
Thread::Msleep(10);
|
||||||
|
|
||||||
// delegate to receiver helper class
|
|
||||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
|
||||||
|
|
||||||
if (tmpPacket.get())
|
|
||||||
{
|
|
||||||
if (tmpPacket->ToNetPacketHandStart())
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
NetPacketHandStart::Data tmpData;
|
|
||||||
tmpPacket->ToNetPacketHandStart()->GetData(tmpData);
|
|
||||||
int z = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MSG_SOCK_INTERNAL_PENDING;
|
return MSG_SOCK_INTERNAL_PENDING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,10 @@
|
|||||||
#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 <clientenginefactory.h>
|
||||||
|
#include <game.h>
|
||||||
|
|
||||||
|
#include <boost/lambda/lambda.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -50,14 +52,13 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ClientThread::ClientThread(ClientCallback &cb)
|
ClientThread::ClientThread(GuiInterface &gui)
|
||||||
: m_curState(NULL), m_callback(cb)
|
: m_curState(NULL), m_gui(gui), m_curGameId(0)
|
||||||
{
|
{
|
||||||
m_context.reset(new ClientContext);
|
m_context.reset(new ClientContext);
|
||||||
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()
|
||||||
@@ -83,7 +84,13 @@ ClientThread::Init(
|
|||||||
ClientCallback &
|
ClientCallback &
|
||||||
ClientThread::GetCallback()
|
ClientThread::GetCallback()
|
||||||
{
|
{
|
||||||
return m_callback;
|
return m_gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiInterface &
|
||||||
|
ClientThread::GetGui()
|
||||||
|
{
|
||||||
|
return m_gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -107,7 +114,13 @@ ClientThread::Main()
|
|||||||
|
|
||||||
// Additionally signal the start of the game.
|
// Additionally signal the start of the game.
|
||||||
if (msg == MSG_NET_GAME_CLIENT_START)
|
if (msg == MSG_NET_GAME_CLIENT_START)
|
||||||
GetCallback().SignalNetClientGameStart(GetGameData());
|
{
|
||||||
|
// EngineFactory erstellen
|
||||||
|
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen
|
||||||
|
|
||||||
|
m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++));
|
||||||
|
GetCallback().SignalNetClientGameStart(m_game);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const NetException &e)
|
} catch (const NetException &e)
|
||||||
@@ -162,15 +175,31 @@ ClientThread::GetReceiver()
|
|||||||
const GameData &
|
const GameData &
|
||||||
ClientThread::GetGameData() const
|
ClientThread::GetGameData() const
|
||||||
{
|
{
|
||||||
assert(m_gameData.get());
|
return m_gameData;
|
||||||
return *m_gameData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientThread::SetGameData(const GameData &gameData)
|
ClientThread::SetGameData(const GameData &gameData)
|
||||||
{
|
{
|
||||||
assert(m_gameData.get());
|
m_gameData = gameData;
|
||||||
*m_gameData = gameData;
|
}
|
||||||
|
|
||||||
|
const StartData &
|
||||||
|
ClientThread::GetStartData() const
|
||||||
|
{
|
||||||
|
return m_startData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::SetStartData(const StartData &startData)
|
||||||
|
{
|
||||||
|
m_startData = startData;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<Game>
|
||||||
|
ClientThread::GetGame()
|
||||||
|
{
|
||||||
|
return m_game;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientSenderCallback &
|
ClientSenderCallback &
|
||||||
@@ -180,9 +209,44 @@ ClientThread::GetSenderCallback()
|
|||||||
return *m_senderCallback;
|
return *m_senderCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientThread::PlayerMap &
|
void
|
||||||
ClientThread::GetPlayerMap()
|
ClientThread::AddPlayerData(boost::shared_ptr<PlayerData> playerData)
|
||||||
{
|
{
|
||||||
return m_playerMap;
|
if (playerData.get() && !playerData->GetName().empty())
|
||||||
|
{
|
||||||
|
m_playerDataList.push_back(playerData);
|
||||||
|
// Sort the list by player number.
|
||||||
|
m_playerDataList.sort(*boost::lambda::_1 < *boost::lambda::_2);
|
||||||
|
|
||||||
|
GetCallback().SignalNetClientPlayerJoined(playerData->GetName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::RemovePlayerData(unsigned playerId)
|
||||||
|
{
|
||||||
|
string playerName;
|
||||||
|
|
||||||
|
PlayerDataList::iterator i = m_playerDataList.begin();
|
||||||
|
PlayerDataList::iterator end = m_playerDataList.end();
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
if ((*i)->GetUniqueId() == playerId)
|
||||||
|
{
|
||||||
|
playerName = (*i)->GetName();
|
||||||
|
m_playerDataList.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!playerName.empty())
|
||||||
|
GetCallback().SignalNetClientPlayerLeft(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerDataList &
|
||||||
|
ClientThread::GetPlayerDataList() const
|
||||||
|
{
|
||||||
|
return m_playerDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -761,7 +761,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData)
|
|||||||
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
||||||
assert(tmpData);
|
assert(tmpData);
|
||||||
|
|
||||||
tmpData->startDealerPos = htons(inData.startDealerPos);
|
tmpData->startDealerPos = htons(inData.startData.startDealerPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -770,7 +770,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const
|
|||||||
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
||||||
assert(tmpData);
|
assert(tmpData);
|
||||||
|
|
||||||
outData.startDealerPos = ntohs(tmpData->startDealerPos);
|
outData.startData.startDealerPos = ntohs(tmpData->startDealerPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetPacketGameStart *
|
const NetPacketGameStart *
|
||||||
|
|||||||
@@ -224,16 +224,18 @@ ServerRecvStateStartGame::HandleNewConnection(ServerRecvThread &server, boost::s
|
|||||||
int
|
int
|
||||||
ServerRecvStateStartGame::Process(ServerRecvThread &server)
|
ServerRecvStateStartGame::Process(ServerRecvThread &server)
|
||||||
{
|
{
|
||||||
GameData &gameData = server.GetGameData();
|
{
|
||||||
|
// Set dealer pos.
|
||||||
// Set dealer pos.
|
StartData startData;
|
||||||
Tools myTool;
|
Tools myTool;
|
||||||
myTool.getRandNumber(0, gameData.numberOfPlayers-1, 1, &gameData.startDealerPos, 0);
|
myTool.getRandNumber(0, server.GetGameData().numberOfPlayers-1, 1, &startData.startDealerPos, 0);
|
||||||
|
server.SetStartData(startData);
|
||||||
|
}
|
||||||
|
|
||||||
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
|
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
|
||||||
|
|
||||||
NetPacketGameStart::Data gameStartData;
|
NetPacketGameStart::Data gameStartData;
|
||||||
gameStartData.startDealerPos = gameData.startDealerPos;
|
gameStartData.startData = server.GetStartData();
|
||||||
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
|
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
|
||||||
|
|
||||||
server.SendToAllPlayers(answer);
|
server.SendToAllPlayers(answer);
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ ServerRecvThread::ServerRecvThread(GuiInterface &gui, ConfigFile *playerConfig)
|
|||||||
m_senderCallback.reset(new ServerSenderCallback(*this));
|
m_senderCallback.reset(new ServerSenderCallback(*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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerRecvThread::~ServerRecvThread()
|
ServerRecvThread::~ServerRecvThread()
|
||||||
@@ -71,7 +70,7 @@ void
|
|||||||
ServerRecvThread::Init(const string &pwd, const GameData &gameData)
|
ServerRecvThread::Init(const string &pwd, const GameData &gameData)
|
||||||
{
|
{
|
||||||
m_password = pwd;
|
m_password = pwd;
|
||||||
*m_gameData = gameData;
|
m_gameData = gameData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -252,7 +251,7 @@ ServerRecvThread::InternalStartGame()
|
|||||||
// EngineFactory erstellen
|
// EngineFactory erstellen
|
||||||
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen
|
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen
|
||||||
|
|
||||||
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), m_curGameId++));
|
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), m_curGameId++));
|
||||||
SetState(SERVER_START_GAME_STATE::Instance());
|
SetState(SERVER_START_GAME_STATE::Instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,11 +497,22 @@ ServerRecvThread::GetGame()
|
|||||||
return *m_game;
|
return *m_game;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameData &
|
const GameData &
|
||||||
ServerRecvThread::GetGameData() const
|
ServerRecvThread::GetGameData() const
|
||||||
{
|
{
|
||||||
assert(m_gameData.get());
|
return m_gameData;
|
||||||
return *m_gameData;
|
}
|
||||||
|
|
||||||
|
const StartData &
|
||||||
|
ServerRecvThread::GetStartData() const
|
||||||
|
{
|
||||||
|
return m_startData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerRecvThread::SetStartData(const StartData &startData)
|
||||||
|
{
|
||||||
|
m_startData = startData;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
+1
-1
@@ -194,7 +194,7 @@ class NetPacketGameStart : public NetPacket
|
|||||||
public:
|
public:
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
u_int16_t startDealerPos;
|
StartData startData;
|
||||||
u_int16_t reserved;
|
u_int16_t reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <net/connectdata.h>
|
#include <net/connectdata.h>
|
||||||
#include <net/sessiondata.h>
|
#include <net/sessiondata.h>
|
||||||
#include <gui/guiinterface.h>
|
#include <gui/guiinterface.h>
|
||||||
|
#include <gamedata.h>
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -121,7 +122,9 @@ protected:
|
|||||||
ReceiverHelper &GetReceiver();
|
ReceiverHelper &GetReceiver();
|
||||||
|
|
||||||
Game &GetGame();
|
Game &GetGame();
|
||||||
GameData &GetGameData() const;
|
const GameData &GetGameData() const;
|
||||||
|
const StartData &GetStartData() const;
|
||||||
|
void SetStartData(const StartData &startData);
|
||||||
bool CheckPassword(const std::string &password) const;
|
bool CheckPassword(const std::string &password) const;
|
||||||
|
|
||||||
ServerSenderCallback &GetSenderCallback();
|
ServerSenderCallback &GetSenderCallback();
|
||||||
@@ -145,7 +148,8 @@ private:
|
|||||||
std::auto_ptr<SenderThread> m_sender;
|
std::auto_ptr<SenderThread> m_sender;
|
||||||
|
|
||||||
std::auto_ptr<Game> m_game;
|
std::auto_ptr<Game> m_game;
|
||||||
std::auto_ptr<GameData> m_gameData;
|
GameData m_gameData;
|
||||||
|
StartData m_startData;
|
||||||
unsigned m_curGameId;
|
unsigned m_curGameId;
|
||||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ class SessionData;
|
|||||||
enum PlayerType
|
enum PlayerType
|
||||||
{
|
{
|
||||||
PLAYER_TYPE_COMPUTER,
|
PLAYER_TYPE_COMPUTER,
|
||||||
PLAYER_TYPE_HUMAN
|
PLAYER_TYPE_HUMAN,
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerData
|
class PlayerData
|
||||||
|
|||||||
+6
-3
@@ -60,6 +60,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class GuiWrapper;
|
class GuiWrapper;
|
||||||
|
class Game;
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
@@ -83,11 +84,13 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
QString locale = QLocale::system().name();
|
QString locale = QLocale::system().name();
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
translator.load(QString(":/translations/resources/translations/pokerth_") + locale);
|
translator.load(QString(":/translations/resources/translations/pokerth_") + locale);
|
||||||
a.installTranslator(&translator);
|
a.installTranslator(&translator);
|
||||||
///////////////////////////////////////////////////
|
///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
qRegisterMetaType<boost::shared_ptr<Game> >("boost::shared_ptr<Game>");
|
||||||
|
|
||||||
boost::shared_ptr<GuiInterface> myGuiInterface(new GuiWrapper(myConfig));
|
boost::shared_ptr<GuiInterface> myGuiInterface(new GuiWrapper(myConfig));
|
||||||
{
|
{
|
||||||
boost::shared_ptr<Session> session(new Session(myGuiInterface.get(), myConfig));
|
boost::shared_ptr<Session> session(new Session(myGuiInterface.get(), myConfig));
|
||||||
|
|||||||
+11
-28
@@ -32,7 +32,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Session::Session(GuiInterface *g, ConfigFile *c)
|
Session::Session(GuiInterface *g, ConfigFile *c)
|
||||||
: currentGameID(0), myNetClient(0), myNetServer(0), currentGame(0), myGui(g), myConfig(c)
|
: currentGameID(0), myNetClient(0), myNetServer(0), myGui(g), myConfig(c)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -42,19 +42,18 @@ Session::~Session()
|
|||||||
{
|
{
|
||||||
terminateNetworkClient();
|
terminateNetworkClient();
|
||||||
terminateNetworkServer();
|
terminateNetworkServer();
|
||||||
deleteGame();
|
|
||||||
delete myConfig;
|
delete myConfig;
|
||||||
myConfig = 0;
|
myConfig = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Session::startLocalGame(const GameData &gameData) {
|
void Session::startLocalGame(const GameData &gameData, const StartData &startData) {
|
||||||
|
|
||||||
deleteGame();
|
|
||||||
myGui->initGui(gameData.guiSpeed);
|
|
||||||
|
|
||||||
|
currentGame.reset();
|
||||||
currentGameID++;
|
currentGameID++;
|
||||||
|
|
||||||
|
myGui->initGui(gameData.guiSpeed);
|
||||||
|
|
||||||
PlayerDataList playerDataList;
|
PlayerDataList playerDataList;
|
||||||
for(int i=0; i<gameData.numberOfPlayers; i++) {
|
for(int i=0; i<gameData.numberOfPlayers; i++) {
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ void Session::startLocalGame(const GameData &gameData) {
|
|||||||
// EngineFactory erstellen
|
// EngineFactory erstellen
|
||||||
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(myConfig)); // LocalEngine erstellen
|
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(myConfig)); // LocalEngine erstellen
|
||||||
|
|
||||||
currentGame = new Game(myGui, factory, playerDataList, gameData, currentGameID);
|
currentGame.reset(new Game(myGui, factory, playerDataList, gameData, startData, currentGameID));
|
||||||
|
|
||||||
//// SPIEL-SCHLEIFE
|
//// SPIEL-SCHLEIFE
|
||||||
currentGame->initHand();
|
currentGame->initHand();
|
||||||
@@ -86,34 +85,18 @@ void Session::startLocalGame(const GameData &gameData) {
|
|||||||
// SPIEL-SCHLEIFE
|
// SPIEL-SCHLEIFE
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::startClientGame(const GameData &gameData, const PlayerDataList &playerDataList)
|
void Session::startClientGame(boost::shared_ptr<Game> game)
|
||||||
{
|
{
|
||||||
deleteGame();
|
|
||||||
myGui->initGui(gameData.guiSpeed);
|
|
||||||
|
|
||||||
currentGameID++;
|
currentGameID++;
|
||||||
|
|
||||||
// EngineFactory erstellen
|
// TODO: use server gui speed.
|
||||||
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory(myConfig)); // LocalEngine erstellen
|
myGui->initGui(5);
|
||||||
|
currentGame = game;
|
||||||
currentGame = new Game(myGui, factory, playerDataList, gameData, currentGameID);
|
|
||||||
|
|
||||||
//// SPIEL-SCHLEIFE
|
|
||||||
currentGame->initHand();
|
|
||||||
currentGame->startHand();
|
|
||||||
// SPIEL-SCHLEIFE
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::deleteGame() {
|
|
||||||
|
|
||||||
delete currentGame;
|
|
||||||
currentGame = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Game *Session::getCurrentGame()
|
Game *Session::getCurrentGame()
|
||||||
{
|
{
|
||||||
return currentGame;
|
return currentGame.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiInterface *Session::getGui()
|
GuiInterface *Session::getGui()
|
||||||
|
|||||||
+4
-4
@@ -23,6 +23,7 @@
|
|||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
#include "game_defs.h"
|
#include "game_defs.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
class GuiInterface;
|
class GuiInterface;
|
||||||
class Game;
|
class Game;
|
||||||
@@ -37,9 +38,8 @@ public:
|
|||||||
|
|
||||||
~Session();
|
~Session();
|
||||||
|
|
||||||
void startLocalGame(const GameData &gameData);
|
void startLocalGame(const GameData &gameData, const StartData &startData);
|
||||||
void startClientGame(const GameData &gameData, const PlayerDataList &playerDataList);
|
void startClientGame(boost::shared_ptr<Game> game);
|
||||||
void deleteGame();
|
|
||||||
|
|
||||||
Game *getCurrentGame();
|
Game *getCurrentGame();
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ private:
|
|||||||
ClientThread *myNetClient;
|
ClientThread *myNetClient;
|
||||||
ServerThread *myNetServer;
|
ServerThread *myNetServer;
|
||||||
|
|
||||||
Game *currentGame;
|
boost::shared_ptr<Game> currentGame;
|
||||||
GuiInterface *myGui;
|
GuiInterface *myGui;
|
||||||
ConfigFile *myConfig;
|
ConfigFile *myConfig;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user