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 "clientriver.h"
|
||||
|
||||
#include <configfile.h>
|
||||
|
||||
|
||||
ClientEngineFactory::ClientEngineFactory(ConfigFile *c)
|
||||
: myConfig(c)
|
||||
ClientEngineFactory::ClientEngineFactory()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -34,7 +34,7 @@ class ConfigFile;
|
||||
class ClientEngineFactory : public EngineFactory
|
||||
{
|
||||
public:
|
||||
ClientEngineFactory(ConfigFile*);
|
||||
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);
|
||||
@@ -44,9 +44,6 @@ public:
|
||||
FlopInterface* createFlop(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);
|
||||
|
||||
private:
|
||||
ConfigFile *myConfig;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+3
-2
@@ -29,13 +29,14 @@
|
||||
using namespace std;
|
||||
|
||||
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),
|
||||
startQuantityPlayers(gameData.numberOfPlayers),
|
||||
startCash(gameData.startCash), startSmallBlind(gameData.smallBlind),
|
||||
startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise),
|
||||
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";
|
||||
int i;
|
||||
|
||||
+4
-1
@@ -33,11 +33,14 @@ class PlayerInterface;
|
||||
class BoardInterface;
|
||||
class EngineFactory;
|
||||
struct GameData;
|
||||
struct StartData;
|
||||
|
||||
class Game {
|
||||
|
||||
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();
|
||||
|
||||
|
||||
+6
-1
@@ -26,12 +26,17 @@
|
||||
struct GameData
|
||||
{
|
||||
GameData() : numberOfPlayers(0), startCash(0), smallBlind(0),
|
||||
handsBeforeRaise(1), guiSpeed(4), startDealerPos(0) {}
|
||||
handsBeforeRaise(1), guiSpeed(4) {}
|
||||
int numberOfPlayers;
|
||||
int startCash;
|
||||
int smallBlind;
|
||||
int handsBeforeRaise;
|
||||
int guiSpeed;
|
||||
};
|
||||
|
||||
struct StartData
|
||||
{
|
||||
StartData() : startDealerPos(0) {}
|
||||
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::SignalNetClientPlayerJoined(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(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::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
void SignalNetClientPlayerJoined(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 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::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::SignalNetClientGameStart(const GameData &gameData) { myW->signalNetClientGameStart(); }
|
||||
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
|
||||
|
||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
void SignalNetClientPlayerJoined(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 SignalNetServerError(int errorID, int osErrorID);
|
||||
|
||||
@@ -597,7 +597,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
||||
|
||||
// Errors are handled globally, not within one dialog.
|
||||
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(signalNetServerPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
|
||||
@@ -656,11 +656,12 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
|
||||
gameData.guiSpeed = myConfig->readConfigInt("GameSpeed");
|
||||
}
|
||||
// Set dealer pos.
|
||||
StartData startData;
|
||||
Tools myTool;
|
||||
myTool.getRandNumber(0, gameData.numberOfPlayers-1, 1, &gameData.startDealerPos, 0);
|
||||
myTool.getRandNumber(0, gameData.numberOfPlayers-1, 1, &startData.startDealerPos, 0);
|
||||
|
||||
//Start Game!!!
|
||||
mySession->startLocalGame(gameData);
|
||||
mySession->startLocalGame(gameData, startData);
|
||||
}
|
||||
|
||||
|
||||
@@ -1182,11 +1183,11 @@ void mainWindowImpl::dealHoleCards() {
|
||||
|
||||
// Karten der Gegner austeilen
|
||||
int i, j;
|
||||
HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand();
|
||||
Game *currentGame = mySession->getCurrentGame();
|
||||
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++) {
|
||||
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
|
||||
if(currentGame->getPlayerArray()[i]->getMyActiveStatus()) {
|
||||
if (debugMode) {
|
||||
tempCardsPixmapArray[j].load(":/cards/resources/graphics/cards/"+QString::number(tempCardsIntArray[j], 10)+".png");
|
||||
holeCardsArray[i][j]->setPixmap(tempCardsPixmapArray[j],FALSE);
|
||||
@@ -1204,10 +1205,10 @@ void mainWindowImpl::dealHoleCards() {
|
||||
}
|
||||
// eigenen Karten austeilen
|
||||
|
||||
currentHand->getPlayerArray()[0]->getMyCards(tempCardsIntArray);
|
||||
currentGame->getPlayerArray()[0]->getMyCards(tempCardsIntArray);
|
||||
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");
|
||||
holeCardsArray[0][i]->setPixmap(tempCardsPixmapArray[i], FALSE);
|
||||
@@ -2413,11 +2414,9 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
|
||||
myWaitingForServerGameDialog->reject();
|
||||
}
|
||||
|
||||
void mainWindowImpl::networkStart()
|
||||
void mainWindowImpl::networkStart(boost::shared_ptr<Game> game)
|
||||
{
|
||||
// QMutexLocker lock(&myClientDataMutex);
|
||||
// assert(!myClientPlayerDataList.empty());
|
||||
// mySession->startClientGame(myClientGameData, myClientPlayerDataList);
|
||||
mySession->startClientGame(game);
|
||||
}
|
||||
|
||||
void mainWindowImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
class Log;
|
||||
class ConfigFile;
|
||||
class Session;
|
||||
class Game;
|
||||
|
||||
class GuiInterface;
|
||||
class BoardInterface;
|
||||
@@ -108,7 +109,7 @@ signals:
|
||||
void signalNetClientError(int errorID, int osErrorID);
|
||||
void signalNetClientPlayerJoined(QString playerName);
|
||||
void signalNetClientPlayerLeft(QString playerName);
|
||||
void signalNetClientGameStart();
|
||||
void signalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
void signalNetServerPlayerJoined(QString playerName);
|
||||
void signalNetServerPlayerLeft(QString playerName);
|
||||
|
||||
@@ -231,7 +232,7 @@ public slots:
|
||||
void paintStartSplash();
|
||||
|
||||
void networkError(int, int);
|
||||
void networkStart();
|
||||
void networkStart(boost::shared_ptr<Game> game);
|
||||
|
||||
void closeEvent(QCloseEvent*);
|
||||
|
||||
|
||||
@@ -22,8 +22,9 @@
|
||||
#define _CLIENTCALLBACK_H_
|
||||
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
struct GameData;
|
||||
class Game;
|
||||
|
||||
class ClientCallback
|
||||
{
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
virtual void SignalNetClientGameInfo(int actionID) = 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 SignalNetClientPlayerLeft(const std::string &playerName) = 0;
|
||||
};
|
||||
|
||||
@@ -191,6 +191,24 @@ protected:
|
||||
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).
|
||||
class ClientStateFinal : public ClientState
|
||||
{
|
||||
|
||||
+24
-8
@@ -22,22 +22,23 @@
|
||||
#define _CLIENTTHREAD_H_
|
||||
|
||||
#include <core/thread.h>
|
||||
#include <map>
|
||||
#include <guiinterface.h>
|
||||
#include <playerdata.h>
|
||||
#include <gamedata.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <net/clientcallback.h>
|
||||
|
||||
class ClientContext;
|
||||
class ClientState;
|
||||
class SenderThread;
|
||||
class ReceiverHelper;
|
||||
class ClientSenderCallback;
|
||||
struct GameData;
|
||||
class Game;
|
||||
|
||||
class ClientThread : public Thread
|
||||
{
|
||||
public:
|
||||
ClientThread(ClientCallback &gui);
|
||||
ClientThread(GuiInterface &gui);
|
||||
virtual ~ClientThread();
|
||||
|
||||
// Set the parameters. Does not do any error checking.
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
const std::string &playerName);
|
||||
|
||||
ClientCallback &GetCallback();
|
||||
GuiInterface &GetGui();
|
||||
|
||||
protected:
|
||||
typedef std::map<unsigned, std::string> PlayerMap;
|
||||
@@ -69,23 +71,36 @@ protected:
|
||||
|
||||
const GameData &GetGameData() const;
|
||||
void SetGameData(const GameData &gameData);
|
||||
const StartData &GetStartData() const;
|
||||
void SetStartData(const StartData &startData);
|
||||
|
||||
boost::shared_ptr<Game> GetGame();
|
||||
|
||||
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:
|
||||
|
||||
std::auto_ptr<ClientContext> m_context;
|
||||
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
||||
ClientState *m_curState;
|
||||
ClientCallback &m_callback;
|
||||
GuiInterface &m_gui;
|
||||
|
||||
std::auto_ptr<SenderThread> m_sender;
|
||||
std::auto_ptr<ReceiverHelper> m_receiver;
|
||||
|
||||
std::auto_ptr<GameData> m_gameData;
|
||||
PlayerMap m_playerMap;
|
||||
GameData m_gameData;
|
||||
StartData m_startData;
|
||||
PlayerDataList m_playerDataList;
|
||||
|
||||
boost::shared_ptr<Game> m_game;
|
||||
|
||||
unsigned m_curGameId;
|
||||
|
||||
friend class ClientStateInit;
|
||||
friend class ClientStateStartResolve;
|
||||
@@ -95,6 +110,7 @@ friend class ClientStateConnecting;
|
||||
friend class ClientStateStartSession;
|
||||
friend class ClientStateWaitSession;
|
||||
friend class ClientStateWaitGame;
|
||||
friend class ClientStateWaitHand;
|
||||
friend class ClientStateFinal;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <net/socket_helper.h>
|
||||
#include <net/socket_msg.h>
|
||||
|
||||
#include <game.h>
|
||||
#include <playerinterface.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define CLIENT_WAIT_TIMEOUT_MSEC 50
|
||||
@@ -374,7 +377,14 @@ ClientStateWaitSession::Process(ClientThread &client)
|
||||
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||
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());
|
||||
retVal = MSG_SOCK_SESSION_DONE;
|
||||
@@ -422,23 +432,32 @@ ClientStateWaitGame::Process(ClientThread &client)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayerJoined())
|
||||
{
|
||||
NetPacketPlayerJoined::Data playerData;
|
||||
tmpPacket->ToNetPacketPlayerJoined()->GetData(playerData);
|
||||
client.GetCallback().SignalNetClientPlayerJoined(playerData.playerName);
|
||||
client.GetPlayerMap()[playerData.playerId] = playerData.playerName;
|
||||
// Another player joined the network game.
|
||||
NetPacketPlayerJoined::Data netPlayerData;
|
||||
tmpPacket->ToNetPacketPlayerJoined()->GetData(netPlayerData);
|
||||
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(netPlayerData.playerId, netPlayerData.playerNumber, netPlayerData.ptype));
|
||||
playerData->SetName(netPlayerData.playerName);
|
||||
client.AddPlayerData(playerData);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayerLeft())
|
||||
{
|
||||
// TODO hacked.
|
||||
NetPacketPlayerLeft::Data playerData;
|
||||
tmpPacket->ToNetPacketPlayerLeft()->GetData(playerData);
|
||||
client.GetCallback().SignalNetClientPlayerLeft(client.GetPlayerMap()[playerData.playerId]);
|
||||
client.GetPlayerMap().erase(playerData.playerId);
|
||||
// Another player left the network game.
|
||||
NetPacketPlayerLeft::Data netPlayerData;
|
||||
tmpPacket->ToNetPacketPlayerLeft()->GetData(netPlayerData);
|
||||
client.RemovePlayerData(netPlayerData.playerId);
|
||||
}
|
||||
}
|
||||
// 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::Instance()
|
||||
{
|
||||
@@ -466,21 +528,7 @@ ClientStateFinal::~ClientStateFinal()
|
||||
int
|
||||
ClientStateFinal::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())
|
||||
{
|
||||
// TODO
|
||||
NetPacketHandStart::Data tmpData;
|
||||
tmpPacket->ToNetPacketHandStart()->GetData(tmpData);
|
||||
int z = 1;
|
||||
}
|
||||
}
|
||||
Thread::Msleep(10);
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
#include <net/receiverhelper.h>
|
||||
#include <net/clientexception.h>
|
||||
#include <net/socket_msg.h>
|
||||
#include <gamedata.h>
|
||||
#include <clientenginefactory.h>
|
||||
#include <game.h>
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
@@ -50,14 +52,13 @@ private:
|
||||
};
|
||||
|
||||
|
||||
ClientThread::ClientThread(ClientCallback &cb)
|
||||
: m_curState(NULL), m_callback(cb)
|
||||
ClientThread::ClientThread(GuiInterface &gui)
|
||||
: m_curState(NULL), m_gui(gui), m_curGameId(0)
|
||||
{
|
||||
m_context.reset(new ClientContext);
|
||||
m_senderCallback.reset(new ClientSenderCallback(*this));
|
||||
m_sender.reset(new SenderThread(GetSenderCallback()));
|
||||
m_receiver.reset(new ReceiverHelper);
|
||||
m_gameData.reset(new GameData);
|
||||
}
|
||||
|
||||
ClientThread::~ClientThread()
|
||||
@@ -83,7 +84,13 @@ ClientThread::Init(
|
||||
ClientCallback &
|
||||
ClientThread::GetCallback()
|
||||
{
|
||||
return m_callback;
|
||||
return m_gui;
|
||||
}
|
||||
|
||||
GuiInterface &
|
||||
ClientThread::GetGui()
|
||||
{
|
||||
return m_gui;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -107,7 +114,13 @@ ClientThread::Main()
|
||||
|
||||
// Additionally signal the start of the game.
|
||||
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)
|
||||
@@ -162,15 +175,31 @@ ClientThread::GetReceiver()
|
||||
const GameData &
|
||||
ClientThread::GetGameData() const
|
||||
{
|
||||
assert(m_gameData.get());
|
||||
return *m_gameData;
|
||||
return m_gameData;
|
||||
}
|
||||
|
||||
void
|
||||
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 &
|
||||
@@ -180,9 +209,44 @@ ClientThread::GetSenderCallback()
|
||||
return *m_senderCallback;
|
||||
}
|
||||
|
||||
ClientThread::PlayerMap &
|
||||
ClientThread::GetPlayerMap()
|
||||
void
|
||||
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();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->startDealerPos = htons(inData.startDealerPos);
|
||||
tmpData->startDealerPos = htons(inData.startData.startDealerPos);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -770,7 +770,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const
|
||||
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.startDealerPos = ntohs(tmpData->startDealerPos);
|
||||
outData.startData.startDealerPos = ntohs(tmpData->startDealerPos);
|
||||
}
|
||||
|
||||
const NetPacketGameStart *
|
||||
|
||||
@@ -224,16 +224,18 @@ ServerRecvStateStartGame::HandleNewConnection(ServerRecvThread &server, boost::s
|
||||
int
|
||||
ServerRecvStateStartGame::Process(ServerRecvThread &server)
|
||||
{
|
||||
GameData &gameData = server.GetGameData();
|
||||
|
||||
// Set dealer pos.
|
||||
Tools myTool;
|
||||
myTool.getRandNumber(0, gameData.numberOfPlayers-1, 1, &gameData.startDealerPos, 0);
|
||||
{
|
||||
// Set dealer pos.
|
||||
StartData startData;
|
||||
Tools myTool;
|
||||
myTool.getRandNumber(0, server.GetGameData().numberOfPlayers-1, 1, &startData.startDealerPos, 0);
|
||||
server.SetStartData(startData);
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
|
||||
|
||||
NetPacketGameStart::Data gameStartData;
|
||||
gameStartData.startDealerPos = gameData.startDealerPos;
|
||||
gameStartData.startData = server.GetStartData();
|
||||
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
|
||||
|
||||
server.SendToAllPlayers(answer);
|
||||
|
||||
@@ -58,7 +58,6 @@ ServerRecvThread::ServerRecvThread(GuiInterface &gui, ConfigFile *playerConfig)
|
||||
m_senderCallback.reset(new ServerSenderCallback(*this));
|
||||
m_sender.reset(new SenderThread(GetSenderCallback()));
|
||||
m_receiver.reset(new ReceiverHelper);
|
||||
m_gameData.reset(new GameData);
|
||||
}
|
||||
|
||||
ServerRecvThread::~ServerRecvThread()
|
||||
@@ -71,7 +70,7 @@ void
|
||||
ServerRecvThread::Init(const string &pwd, const GameData &gameData)
|
||||
{
|
||||
m_password = pwd;
|
||||
*m_gameData = gameData;
|
||||
m_gameData = gameData;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -252,7 +251,7 @@ ServerRecvThread::InternalStartGame()
|
||||
// EngineFactory 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());
|
||||
}
|
||||
|
||||
@@ -498,11 +497,22 @@ ServerRecvThread::GetGame()
|
||||
return *m_game;
|
||||
}
|
||||
|
||||
GameData &
|
||||
const GameData &
|
||||
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
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ class NetPacketGameStart : public NetPacket
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
u_int16_t startDealerPos;
|
||||
StartData startData;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <net/connectdata.h>
|
||||
#include <net/sessiondata.h>
|
||||
#include <gui/guiinterface.h>
|
||||
#include <gamedata.h>
|
||||
|
||||
#include <deque>
|
||||
#include <map>
|
||||
@@ -121,7 +122,9 @@ protected:
|
||||
ReceiverHelper &GetReceiver();
|
||||
|
||||
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;
|
||||
|
||||
ServerSenderCallback &GetSenderCallback();
|
||||
@@ -145,7 +148,8 @@ private:
|
||||
std::auto_ptr<SenderThread> m_sender;
|
||||
|
||||
std::auto_ptr<Game> m_game;
|
||||
std::auto_ptr<GameData> m_gameData;
|
||||
GameData m_gameData;
|
||||
StartData m_startData;
|
||||
unsigned m_curGameId;
|
||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class SessionData;
|
||||
enum PlayerType
|
||||
{
|
||||
PLAYER_TYPE_COMPUTER,
|
||||
PLAYER_TYPE_HUMAN
|
||||
PLAYER_TYPE_HUMAN,
|
||||
};
|
||||
|
||||
class PlayerData
|
||||
|
||||
+6
-3
@@ -60,6 +60,7 @@
|
||||
using namespace std;
|
||||
|
||||
class GuiWrapper;
|
||||
class Game;
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
@@ -83,11 +84,13 @@ int main( int argc, char **argv )
|
||||
|
||||
QString locale = QLocale::system().name();
|
||||
|
||||
QTranslator translator;
|
||||
translator.load(QString(":/translations/resources/translations/pokerth_") + locale);
|
||||
a.installTranslator(&translator);
|
||||
QTranslator translator;
|
||||
translator.load(QString(":/translations/resources/translations/pokerth_") + locale);
|
||||
a.installTranslator(&translator);
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
qRegisterMetaType<boost::shared_ptr<Game> >("boost::shared_ptr<Game>");
|
||||
|
||||
boost::shared_ptr<GuiInterface> myGuiInterface(new GuiWrapper(myConfig));
|
||||
{
|
||||
boost::shared_ptr<Session> session(new Session(myGuiInterface.get(), myConfig));
|
||||
|
||||
+11
-28
@@ -32,7 +32,7 @@
|
||||
using namespace std;
|
||||
|
||||
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();
|
||||
terminateNetworkServer();
|
||||
deleteGame();
|
||||
delete myConfig;
|
||||
myConfig = 0;
|
||||
}
|
||||
|
||||
|
||||
void Session::startLocalGame(const GameData &gameData) {
|
||||
|
||||
deleteGame();
|
||||
myGui->initGui(gameData.guiSpeed);
|
||||
void Session::startLocalGame(const GameData &gameData, const StartData &startData) {
|
||||
|
||||
currentGame.reset();
|
||||
currentGameID++;
|
||||
|
||||
myGui->initGui(gameData.guiSpeed);
|
||||
|
||||
PlayerDataList playerDataList;
|
||||
for(int i=0; i<gameData.numberOfPlayers; i++) {
|
||||
|
||||
@@ -78,7 +77,7 @@ void Session::startLocalGame(const GameData &gameData) {
|
||||
// EngineFactory 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
|
||||
currentGame->initHand();
|
||||
@@ -86,34 +85,18 @@ void Session::startLocalGame(const GameData &gameData) {
|
||||
// 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++;
|
||||
|
||||
// EngineFactory erstellen
|
||||
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory(myConfig)); // LocalEngine erstellen
|
||||
|
||||
currentGame = new Game(myGui, factory, playerDataList, gameData, currentGameID);
|
||||
|
||||
//// SPIEL-SCHLEIFE
|
||||
currentGame->initHand();
|
||||
currentGame->startHand();
|
||||
// SPIEL-SCHLEIFE
|
||||
}
|
||||
|
||||
void Session::deleteGame() {
|
||||
|
||||
delete currentGame;
|
||||
currentGame = 0;
|
||||
|
||||
// TODO: use server gui speed.
|
||||
myGui->initGui(5);
|
||||
currentGame = game;
|
||||
}
|
||||
|
||||
Game *Session::getCurrentGame()
|
||||
{
|
||||
return currentGame;
|
||||
return currentGame.get();
|
||||
}
|
||||
|
||||
GuiInterface *Session::getGui()
|
||||
|
||||
+4
-4
@@ -23,6 +23,7 @@
|
||||
#include "playerdata.h"
|
||||
#include "game_defs.h"
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class GuiInterface;
|
||||
class Game;
|
||||
@@ -37,9 +38,8 @@ public:
|
||||
|
||||
~Session();
|
||||
|
||||
void startLocalGame(const GameData &gameData);
|
||||
void startClientGame(const GameData &gameData, const PlayerDataList &playerDataList);
|
||||
void deleteGame();
|
||||
void startLocalGame(const GameData &gameData, const StartData &startData);
|
||||
void startClientGame(boost::shared_ptr<Game> game);
|
||||
|
||||
Game *getCurrentGame();
|
||||
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
ClientThread *myNetClient;
|
||||
ServerThread *myNetServer;
|
||||
|
||||
Game *currentGame;
|
||||
boost::shared_ptr<Game> currentGame;
|
||||
GuiInterface *myGui;
|
||||
ConfigFile *myConfig;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user