Added packet type to start a "Hand". Added generic gui for the server.

This commit is contained in:
lotodore
2007-05-13 17:50:48 +00:00
parent cdd34fe820
commit 37bf6e4eb9
12 changed files with 521 additions and 75 deletions
+35 -35
View File
@@ -1,40 +1,40 @@
/***************************************************************************
* 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. *
***************************************************************************/
#ifndef GAME_DEFS_H
#define GAME_DEFS_H
#define MAX_NUMBER_OF_PLAYERS 7
/***************************************************************************
* 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. *
***************************************************************************/
#ifndef GAME_DEFS_H
#define GAME_DEFS_H
#define MAX_NUMBER_OF_PLAYERS 7
enum GameState {
GAME_STATE_PREFLOP = 0,
GAME_STATE_FLOP,
GAME_STATE_TURN,
GAME_STATE_RIVER };
enum PlayerAction {
PLAYER_ACTION_NONE = 0,
PLAYER_ACTION_FOLD,
PLAYER_ACTION_CHECK,
PLAYER_ACTION_CALL,
PLAYER_ACTION_BET,
PLAYER_ACTION_RAISE,
PLAYER_ACTION_ALLIN };
#endif
enum PlayerAction {
PLAYER_ACTION_NONE = 0,
PLAYER_ACTION_FOLD,
PLAYER_ACTION_CHECK,
PLAYER_ACTION_CALL,
PLAYER_ACTION_BET,
PLAYER_ACTION_RAISE,
PLAYER_ACTION_ALLIN };
#endif
+53
View File
@@ -0,0 +1,53 @@
/***************************************************************************
* 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 "genericservergui.h"
using namespace std;
GenericServerGui::GenericServerGui(ConfigFile *config)
: myConfig(config)
{
}
GenericServerGui::~GenericServerGui()
{
}
void GenericServerGui::initGui(int speed)
{
}
Session &GenericServerGui::getSession()
{
return *mySession;
}
void GenericServerGui::setSession(boost::shared_ptr<Session> session)
{
mySession = session;
}
void GenericServerGui::waitForNetworkAction(GameState state, unsigned uniquePlayerId)
{
}
+48
View File
@@ -0,0 +1,48 @@
/***************************************************************************
* 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 GENERICSERVERGUI_H
#define GENERICSERVERGUI_H
#include <game_defs.h>
#include <boost/shared_ptr.hpp>
class Session;
class ConfigFile;
class GenericServerGui
{
public:
GenericServerGui(ConfigFile *config);
~GenericServerGui();
void initGui(int speed);
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
private:
boost::shared_ptr<Session> mySession;
ConfigFile *myConfig;
};
#endif
+122
View File
@@ -0,0 +1,122 @@
/***************************************************************************
* 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 "serverguiwrapper.h"
#include "genericservergui.h"
using namespace std;
ServerGuiWrapper::ServerGuiWrapper(ConfigFile *config, ClientCallback *clientcb, ServerCallback *servercb)
: myClientcb(clientcb), myServercb(servercb)
{
myGui.reset(new GenericServerGui(config));
}
ServerGuiWrapper::~ServerGuiWrapper()
{
}
void ServerGuiWrapper::initGui(int speed) {}
Session &ServerGuiWrapper::getSession()
{
return myGui->getSession();
}
void ServerGuiWrapper::setSession(boost::shared_ptr<Session> session)
{
myGui->setSession(session);
}
bool
ServerGuiWrapper::isNetworkServer() const
{
/* TODO hack */
return true;
}
void
ServerGuiWrapper::waitForNetworkAction(GameState state, unsigned uniquePlayerId)
{
/* TODO hack */
}
void ServerGuiWrapper::refreshSet() const {}
void ServerGuiWrapper::refreshCash() const {}
void ServerGuiWrapper::refreshAction(int playerID, int playerAction) const {}
void ServerGuiWrapper::refreshChangePlayer() const {}
void ServerGuiWrapper::refreshAll() const {}
void ServerGuiWrapper::refreshPot() const {}
void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {}
void ServerGuiWrapper::refreshPlayerName() const {}
void ServerGuiWrapper::dealHoleCards() const {}
void ServerGuiWrapper::dealFlopCards() const {}
void ServerGuiWrapper::dealTurnCard() const {}
void ServerGuiWrapper::dealRiverCard() const {}
void ServerGuiWrapper::highlightRoundLabel(string round) const {}
void ServerGuiWrapper::nextPlayerAnimation() const {}
void ServerGuiWrapper::preflopAnimation1() const {}
void ServerGuiWrapper::preflopAnimation2() const {}
void ServerGuiWrapper::flopAnimation1() const {}
void ServerGuiWrapper::flopAnimation2() const {}
void ServerGuiWrapper::turnAnimation1() const {}
void ServerGuiWrapper::turnAnimation2() const {}
void ServerGuiWrapper::riverAnimation1() const {}
void ServerGuiWrapper::riverAnimation2() const {}
void ServerGuiWrapper::postRiverAnimation1() const {}
void ServerGuiWrapper::postRiverRunAnimation1() const {}
void ServerGuiWrapper::flipHolecardsAllIn() const {}
void ServerGuiWrapper::nextRoundCleanGui() const {}
void ServerGuiWrapper::meInAction() const {}
void ServerGuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) {}
void ServerGuiWrapper::logNewGameHandMsg(int gameID, int handID) {}
void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); }
void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); }
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::SignalNetServerSuccess(int actionID) { if (myServercb) myServercb->SignalNetServerSuccess(actionID); }
void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
void ServerGuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerJoined(playerName); }
void ServerGuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerLeft(playerName); }
+103
View File
@@ -0,0 +1,103 @@
/***************************************************************************
* 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 SERVERGUIWRAPPER_H
#define SERVERGUIWRAPPER_H
#include <guiinterface.h>
class ConfigFile;
class GenericServerGui;
class ServerGuiWrapper : public GuiInterface
{
public:
ServerGuiWrapper(ConfigFile *config, ClientCallback *clientcb, ServerCallback *servercb);
~ServerGuiWrapper();
void initGui(int speed);
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
bool isNetworkServer() const;
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
void refreshSet() const;
void refreshCash() const;
void refreshAction(int =-1, int =-1) const;
void refreshChangePlayer() const;
void refreshPot() const;
void refreshGroupbox(int =-1, int =-1) const;
void refreshAll() const;
void refreshPlayerName() const;
void dealHoleCards() const;
void dealFlopCards() const;
void dealTurnCard() const;
void dealRiverCard() const;
void highlightRoundLabel(std::string round) const;
void nextPlayerAnimation() const;
void preflopAnimation1() const;
void preflopAnimation2() const;
void flopAnimation1() const;
void flopAnimation2() const;
void turnAnimation1() const;
void turnAnimation2() const;
void riverAnimation1() const;
void riverAnimation2() const;
void postRiverAnimation1() const;
void postRiverRunAnimation1() const;
void flipHolecardsAllIn() const;
void nextRoundCleanGui() const;
void meInAction() const;
void logPlayerActionMsg(std::string playerName, int action, int setValue) ;
void logNewGameHandMsg(int gameID, int handID) ;
void SignalNetClientConnect(int actionID);
void SignalNetClientGameInfo(int actionID);
void SignalNetClientError(int errorID, int osErrorID);
void SignalNetClientPlayerJoined(const std::string &playerName);
void SignalNetClientPlayerLeft(const std::string &playerName);
void SignalNetClientGameStart(const GameData &gameData);
void SignalNetServerSuccess(int actionID);
void SignalNetServerError(int errorID, int osErrorID);
void SignalNetServerPlayerJoined(const std::string &playerName);
void SignalNetServerPlayerLeft(const std::string &playerName);
private:
boost::shared_ptr<GenericServerGui> myGui;
ClientCallback *myClientcb;
ServerCallback *myServercb;
};
#endif
+3 -1
View File
@@ -20,7 +20,9 @@
#include "guiwrapper.h"
#include "session.h"
#include "log.h"
#include "mainwindowimpl.h"
#include "configfile.h"
using namespace std;
+5 -7
View File
@@ -22,15 +22,13 @@
#include <guiinterface.h>
#include "log.h"
#include "mainwindowimpl.h"
#include "connecttoserverdialogimpl.h"
#include "configfile.h"
#include <string>
#include <iostream>
class Session;
class mainWindowImpl;
class Log;
class ConfigFile;
class GuiWrapper : public GuiInterface
{
@@ -102,8 +100,8 @@ public:
void SignalNetServerPlayerJoined(const std::string &playerName);
void SignalNetServerPlayerLeft(const std::string &playerName);
private:
private:
Log *myLog;
mainWindowImpl *myW;
ConfigFile *myConfig;
+85 -8
View File
@@ -32,9 +32,10 @@ using namespace std;
#define NET_TYPE_PLAYER_JOINED 0x0003
#define NET_TYPE_PLAYER_LEFT 0x0004
#define NET_TYPE_GAME_START 0x0005
#define NET_TYPE_PLAYERS_TURN 0x0006
#define NET_TYPE_PLAYERS_ACTION 0x0007
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x0008
#define NET_TYPE_HAND_START 0x0006
#define NET_TYPE_PLAYERS_TURN 0x0007
#define NET_TYPE_PLAYERS_ACTION 0x0008
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x0009
#define NET_TYPE_ERROR 0x0400
@@ -112,6 +113,12 @@ struct NetPacketPlayerLeftData
};
struct NetPacketGameStartData
{
NetPacketHeader head;
u_int32_t reserved;
};
struct NetPacketHandStartData
{
NetPacketHeader head;
u_int16_t yourCards[2];
@@ -192,6 +199,9 @@ NetPacket::Create(char *data, unsigned &dataSize)
case NET_TYPE_GAME_START:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameStart);
break;
case NET_TYPE_HAND_START:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketHandStart);
break;
case NET_TYPE_PLAYERS_TURN:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketPlayersTurn);
break;
@@ -315,6 +325,12 @@ NetPacket::ToNetPacketGameStart() const
return NULL;
}
const NetPacketHandStart *
NetPacket::ToNetPacketHandStart() const
{
return NULL;
}
const NetPacketPlayersTurn *
NetPacket::ToNetPacketPlayersTurn() const
{
@@ -744,8 +760,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData)
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
assert(tmpData);
tmpData->yourCards[0] = htons(inData.yourCards[0]);
tmpData->yourCards[1] = htons(inData.yourCards[1]);
tmpData->reserved = htonl(inData.reserved);
}
void
@@ -754,8 +769,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
assert(tmpData);
outData.yourCards[0] = ntohs(tmpData->yourCards[0]);
outData.yourCards[1] = ntohs(tmpData->yourCards[1]);
outData.reserved = ntohl(tmpData->reserved);
}
const NetPacketGameStart *
@@ -774,8 +788,71 @@ NetPacketGameStart::Check(const NetPacketHeader* data) const
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
}
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
//-----------------------------------------------------------------------------
NetPacketHandStart::NetPacketHandStart()
: NetPacket(NET_TYPE_GAME_START, sizeof(NetPacketGameStartData))
{
}
NetPacketHandStart::~NetPacketHandStart()
{
}
boost::shared_ptr<NetPacket>
NetPacketHandStart::Clone() const
{
boost::shared_ptr<NetPacket> newPacket(new NetPacketHandStart);
try
{
newPacket->SetRawData(GetRawData());
} catch (const NetException &)
{
// Need to return the new packet anyway.
}
return newPacket;
}
void
NetPacketHandStart::SetData(const NetPacketHandStart::Data &inData)
{
NetPacketHandStartData *tmpData = (NetPacketHandStartData *)GetRawData();
assert(tmpData);
tmpData->yourCards[0] = htons(inData.yourCards[0]);
tmpData->yourCards[1] = htons(inData.yourCards[1]);
}
void
NetPacketHandStart::GetData(NetPacketHandStart::Data &outData) const
{
NetPacketHandStartData *tmpData = (NetPacketHandStartData *)GetRawData();
assert(tmpData);
outData.yourCards[0] = ntohs(tmpData->yourCards[0]);
outData.yourCards[1] = ntohs(tmpData->yourCards[1]);
}
const NetPacketHandStart *
NetPacketHandStart::ToNetPacketHandStart() const
{
return this;
}
void
NetPacketHandStart::Check(const NetPacketHeader* data) const
{
assert(data);
u_int16_t dataLen = ntohs(data->length);
if (dataLen < sizeof(NetPacketHandStartData))
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
NetPacketHandStartData *tmpData = (NetPacketHandStartData *)GetRawData();
if (ntohs(tmpData->yourCards[0]) > 51 || ntohs(tmpData->yourCards[1]) > 51)
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
+26 -1
View File
@@ -42,6 +42,7 @@ class NetPacketJoinGameAck;
class NetPacketPlayerJoined;
class NetPacketPlayerLeft;
class NetPacketGameStart;
class NetPacketHandStart;
class NetPacketPlayersTurn;
class NetPacketPlayersAction;
class NetPacketPlayersActionRejected;
@@ -69,6 +70,7 @@ public:
virtual const NetPacketPlayerJoined *ToNetPacketPlayerJoined() const;
virtual const NetPacketPlayerLeft *ToNetPacketPlayerLeft() const;
virtual const NetPacketGameStart *ToNetPacketGameStart() const;
virtual const NetPacketHandStart *ToNetPacketHandStart() const;
virtual const NetPacketPlayersTurn *ToNetPacketPlayersTurn() const;
virtual const NetPacketPlayersAction *ToNetPacketPlayersAction() const;
virtual const NetPacketPlayersActionRejected *ToNetPacketPlayersActionRejected() const;
@@ -192,7 +194,7 @@ class NetPacketGameStart : public NetPacket
public:
struct Data
{
u_int16_t yourCards[2];
u_int32_t reserved;
};
NetPacketGameStart();
@@ -210,6 +212,29 @@ protected:
virtual void Check(const NetPacketHeader* data) const;
};
class NetPacketHandStart : public NetPacket
{
public:
struct Data
{
u_int16_t yourCards[2];
};
NetPacketHandStart();
virtual ~NetPacketHandStart();
virtual boost::shared_ptr<NetPacket> Clone() const;
void SetData(const Data &inData);
void GetData(Data &outData) const;
virtual const NetPacketHandStart *ToNetPacketHandStart() const;
protected:
virtual void Check(const NetPacketHeader* data) const;
};
class NetPacketPlayersTurn : public NetPacket
{
public:
+3
View File
@@ -33,6 +33,9 @@
#include "configfile.h"
#include <net/socket_startup.h>
#include <QtGui>
#include <QtCore>
#include <cstdlib>
#include <ctime>