Added console server app. First try. Depends on qt for locale-specific stuff. Cannot start a game yet, only join is possible. Cannot run multiple games yet.
Not yet as service/daemon, because testing is easier with a simple console app.
This commit is contained in:
+12
-10
@@ -33,11 +33,11 @@ Client Request: Join Game
|
|||||||
| +-------------------------------+
|
| +-------------------------------+
|
||||||
/ | padding |
|
/ | padding |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
Additional values for major version = 1:
|
Additional values for major version = 2:
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Password Length | Player Flags |
|
| Password Length | Name Length |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Name Length | Reserved |
|
|| Reserved |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| |
|
| |
|
||||||
\ Password (UTF-8) /
|
\ Password (UTF-8) /
|
||||||
@@ -49,12 +49,9 @@ Additional values for major version = 1:
|
|||||||
| +-------------------------------+
|
| +-------------------------------+
|
||||||
/ | padding |
|
/ | padding |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
[Future versions will include the name of the game, to support
|
[Future versions will include an id of the game, to support
|
||||||
multiple games per server.]
|
multiple games per server.]
|
||||||
|
|
||||||
Player Flags:
|
|
||||||
0x01 set: Player is human
|
|
||||||
|
|
||||||
|
|
||||||
Server Reply: Join Game ACK
|
Server Reply: Join Game ACK
|
||||||
|
|
||||||
@@ -65,11 +62,13 @@ Server Reply: Join Game ACK
|
|||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Your Session ID |
|
| Your Session ID |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Your Player ID | Max Number of Players |
|
| Your Player ID | Your Player Flags |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Small Blind | Hands before raise |
|
| Max Number of Players | Small Blind |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Proposed GUI Speed | Player Action Timeout |
|
| Hands before raise | Proposed GUI Speed |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Player Action Timeout | Reserved |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Start Money |
|
| Start Money |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
@@ -80,6 +79,9 @@ Proposed GUI Speed:
|
|||||||
1-11
|
1-11
|
||||||
Player Action Timeout:
|
Player Action Timeout:
|
||||||
# seconds
|
# seconds
|
||||||
|
Player Flags:
|
||||||
|
0x01 set: Player is human
|
||||||
|
0x02 set: Player is admin for this game
|
||||||
|
|
||||||
|
|
||||||
Server Notification: Player Joined
|
Server Notification: Player Joined
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
# QMake pro-file for the PokerTH dedicated server
|
||||||
|
|
||||||
|
INSTALLS += TARGET
|
||||||
|
TARGET.files += bin/*
|
||||||
|
TARGET.path = /usr/bin/
|
||||||
|
|
||||||
|
INCLUDEPATH += . \
|
||||||
|
src \
|
||||||
|
src/engine \
|
||||||
|
src/gui \
|
||||||
|
src/gui/qt \
|
||||||
|
src/gui/qt/qttools \
|
||||||
|
src/gui/qt/qttools/qthelper \
|
||||||
|
src/net \
|
||||||
|
src/engine/local_engine \
|
||||||
|
src/engine/network_engine \
|
||||||
|
src/config \
|
||||||
|
src/core/tinyxml \
|
||||||
|
src/core \
|
||||||
|
|
||||||
|
DEPENDPATH += . \
|
||||||
|
src \
|
||||||
|
src/config \
|
||||||
|
src/core \
|
||||||
|
src/engine \
|
||||||
|
src/gui \
|
||||||
|
src/gui/qt \
|
||||||
|
src/gui/generic \
|
||||||
|
src/net \
|
||||||
|
src/core/common \
|
||||||
|
src/core/tinyxml \
|
||||||
|
src/engine/local_engine \
|
||||||
|
src/engine/network_engine \
|
||||||
|
src/net/common \
|
||||||
|
# Input
|
||||||
|
HEADERS += src/game.h \
|
||||||
|
src/session.h \
|
||||||
|
src/playerdata.h \
|
||||||
|
src/gamedata.h \
|
||||||
|
src/config/configfile.h \
|
||||||
|
src/core/rand.h \
|
||||||
|
src/core/thread.h \
|
||||||
|
src/engine/boardinterface.h \
|
||||||
|
src/engine/enginefactory.h \
|
||||||
|
src/engine/flopinterface.h \
|
||||||
|
src/engine/handinterface.h \
|
||||||
|
src/engine/playerinterface.h \
|
||||||
|
src/engine/preflopinterface.h \
|
||||||
|
src/engine/riverinterface.h \
|
||||||
|
src/engine/turninterface.h \
|
||||||
|
src/gui/guiinterface.h \
|
||||||
|
src/net/clientcallback.h \
|
||||||
|
src/net/clientcontext.h \
|
||||||
|
src/net/clientexception.h \
|
||||||
|
src/net/clientstate.h \
|
||||||
|
src/net/clientthread.h \
|
||||||
|
src/net/genericsocket.h \
|
||||||
|
src/net/netpacket.h \
|
||||||
|
src/net/resolverthread.h \
|
||||||
|
src/net/senderthread.h \
|
||||||
|
src/net/serverthread.h \
|
||||||
|
src/net/socket_helper.h \
|
||||||
|
src/net/socket_msg.h \
|
||||||
|
src/net/socket_startup.h \
|
||||||
|
src/core/tinyxml/tinystr.h \
|
||||||
|
src/core/tinyxml/tinyxml.h \
|
||||||
|
src/engine/local_engine/cardsvalue.h \
|
||||||
|
src/engine/local_engine/localboard.h \
|
||||||
|
src/engine/local_engine/localenginefactory.h \
|
||||||
|
src/engine/local_engine/localflop.h \
|
||||||
|
src/engine/local_engine/localhand.h \
|
||||||
|
src/engine/local_engine/localplayer.h \
|
||||||
|
src/engine/local_engine/localpreflop.h \
|
||||||
|
src/engine/local_engine/localriver.h \
|
||||||
|
src/engine/local_engine/localturn.h \
|
||||||
|
src/engine/local_engine/tools.h \
|
||||||
|
src/engine/network_engine/clientboard.h \
|
||||||
|
src/engine/network_engine/clientenginefactory.h \
|
||||||
|
src/engine/network_engine/clientflop.h \
|
||||||
|
src/engine/network_engine/clienthand.h \
|
||||||
|
src/engine/network_engine/clientplayer.h \
|
||||||
|
src/engine/network_engine/clientpreflop.h \
|
||||||
|
src/engine/network_engine/clientriver.h \
|
||||||
|
src/engine/network_engine/clientturn.h \
|
||||||
|
src/gui/qttoolsinterface.h \
|
||||||
|
src/gui/qt/qttools/qttoolswrapper.h \
|
||||||
|
src/gui/qt/qttools/qthelper/qthelper.h \
|
||||||
|
src/gui/generic/serverguiwrapper.h
|
||||||
|
SOURCES += src/game.cpp \
|
||||||
|
src/pokerth_server.cpp \
|
||||||
|
src/session.cpp \
|
||||||
|
src/playerdata.cpp \
|
||||||
|
src/config/configfile.cpp \
|
||||||
|
src/engine/boardinterface.cpp \
|
||||||
|
src/engine/enginefactory.cpp \
|
||||||
|
src/engine/flopinterface.cpp \
|
||||||
|
src/engine/handinterface.cpp \
|
||||||
|
src/engine/playerinterface.cpp \
|
||||||
|
src/engine/preflopinterface.cpp \
|
||||||
|
src/engine/riverinterface.cpp \
|
||||||
|
src/engine/turninterface.cpp \
|
||||||
|
src/gui/guiinterface.cpp \
|
||||||
|
src/core/common/thread.cpp \
|
||||||
|
src/core/tinyxml/tinystr.cpp \
|
||||||
|
src/core/tinyxml/tinyxml.cpp \
|
||||||
|
src/core/tinyxml/tinyxmlerror.cpp \
|
||||||
|
src/core/tinyxml/tinyxmlparser.cpp \
|
||||||
|
src/engine/local_engine/cardsvalue.cpp \
|
||||||
|
src/engine/local_engine/localboard.cpp \
|
||||||
|
src/engine/local_engine/localenginefactory.cpp \
|
||||||
|
src/engine/local_engine/localflop.cpp \
|
||||||
|
src/engine/local_engine/localhand.cpp \
|
||||||
|
src/engine/local_engine/localplayer.cpp \
|
||||||
|
src/engine/local_engine/localpreflop.cpp \
|
||||||
|
src/engine/local_engine/localriver.cpp \
|
||||||
|
src/engine/local_engine/localturn.cpp \
|
||||||
|
src/engine/local_engine/tools.cpp \
|
||||||
|
src/engine/network_engine/clientboard.cpp \
|
||||||
|
src/engine/network_engine/clientenginefactory.cpp \
|
||||||
|
src/engine/network_engine/clientflop.cpp \
|
||||||
|
src/engine/network_engine/clienthand.cpp \
|
||||||
|
src/engine/network_engine/clientplayer.cpp \
|
||||||
|
src/engine/network_engine/clientpreflop.cpp \
|
||||||
|
src/engine/network_engine/clientriver.cpp \
|
||||||
|
src/engine/network_engine/clientturn.cpp \
|
||||||
|
src/net/common/connectdata.cpp \
|
||||||
|
src/net/common/clientcallback.cpp \
|
||||||
|
src/net/common/clientcontext.cpp \
|
||||||
|
src/net/common/clientstate.cpp \
|
||||||
|
src/net/common/clientthread.cpp \
|
||||||
|
src/net/common/netpacket.cpp \
|
||||||
|
src/net/common/resolverthread.cpp \
|
||||||
|
src/net/common/senderthread.cpp \
|
||||||
|
src/net/common/sendercallback.cpp \
|
||||||
|
src/net/common/serverthread.cpp \
|
||||||
|
src/net/common/servercontext.cpp \
|
||||||
|
src/net/common/serverexception.cpp \
|
||||||
|
src/net/common/serverrecvthread.cpp \
|
||||||
|
src/net/common/serverrecvstate.cpp \
|
||||||
|
src/net/common/servercallback.cpp \
|
||||||
|
src/net/common/sessiondata.cpp \
|
||||||
|
src/net/common/socket_startup_cmn.cpp \
|
||||||
|
src/net/common/socket_helper_cmn.cpp \
|
||||||
|
src/net/common/clientexception.cpp \
|
||||||
|
src/net/common/netcontext.cpp \
|
||||||
|
src/net/common/netexception.cpp \
|
||||||
|
src/net/common/receiverhelper.cpp \
|
||||||
|
src/gui/qttoolsinterface.cpp \
|
||||||
|
src/gui/qt/qttools/qttoolswrapper.cpp \
|
||||||
|
src/gui/qt/qttools/qthelper/qthelper.cpp \
|
||||||
|
src/gui/generic/serverguiwrapper.cpp
|
||||||
|
CODECFORSRC = UTF-8
|
||||||
|
|
||||||
|
TEMPLATE = vcapp
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
win32{
|
||||||
|
DEPENDPATH += src/net/win32/ src/core/win32
|
||||||
|
SOURCES += src/core/win32/rand.cpp \
|
||||||
|
src/net/win32/socket_helper.cpp \
|
||||||
|
src/net/win32/socket_startup.cpp
|
||||||
|
INCLUDEPATH += ../boost/
|
||||||
|
LIBPATH += ../boost/stage/lib
|
||||||
|
LIBS += gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ole32.lib uuid.lib user32.lib msimg32.lib shell32.lib kernel32.lib ws2_32.lib advapi32.lib
|
||||||
|
}
|
||||||
|
!win32{
|
||||||
|
DEPENDPATH += src/net/linux/ src/core/linux
|
||||||
|
SOURCES += src/core/linux/rand.cpp \
|
||||||
|
src/net/linux/socket_helper.cpp \
|
||||||
|
src/net/linux/socket_startup.cpp
|
||||||
|
}
|
||||||
|
|
||||||
|
unix:!mac{
|
||||||
|
exists( /usr/lib/libboost_thread-mt.so ) {
|
||||||
|
message("Found libboost_thread-mt")
|
||||||
|
LIBS += -lboost_thread-mt
|
||||||
|
}
|
||||||
|
exists( /usr/lib/libboost_thread.so ) {
|
||||||
|
message("Found libboost_thread")
|
||||||
|
LIBS += -lboost_thread
|
||||||
|
}
|
||||||
|
LIBS += -lcrypto
|
||||||
|
## My release static libs
|
||||||
|
#LIBS += -lcrypto
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG += qt console release
|
||||||
|
#CONFIG += qt console warn_on debug
|
||||||
|
UI_DIR = uics/server
|
||||||
|
TARGET = bin/pokerth_server
|
||||||
|
MOC_DIR = mocs/server
|
||||||
|
OBJECTS_DIR = obj/server
|
||||||
|
QT +=
|
||||||
|
# QMAKE_CXXFLAGS_DEBUG += -g
|
||||||
@@ -86,14 +86,24 @@ Thread::Join(unsigned msecTimeout)
|
|||||||
if (!IsRunning())
|
if (!IsRunning())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Calculate time after timeout
|
bool tmpIsTerminated;
|
||||||
boost::xtime t;
|
if (msecTimeout == THREAD_WAIT_INFINITE)
|
||||||
boost::xtime_get(&t, boost::TIME_UTC);
|
{
|
||||||
ADD_MSEC_TO_XTIME(t, msecTimeout);
|
// Wait infinitely.
|
||||||
|
boost::timed_mutex::scoped_lock lock(m_isTerminatedMutex);
|
||||||
|
tmpIsTerminated = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Calculate time after timeout
|
||||||
|
boost::xtime t;
|
||||||
|
boost::xtime_get(&t, boost::TIME_UTC);
|
||||||
|
ADD_MSEC_TO_XTIME(t, msecTimeout);
|
||||||
|
|
||||||
// Wait for the termination of the application code.
|
// Wait for the termination of the application code.
|
||||||
boost::timed_mutex::scoped_timed_lock lock(m_isTerminatedMutex, t);
|
boost::timed_mutex::scoped_timed_lock lock(m_isTerminatedMutex, t);
|
||||||
bool tmpIsTerminated = lock.locked();
|
tmpIsTerminated = lock.locked();
|
||||||
|
}
|
||||||
|
|
||||||
if (tmpIsTerminated)
|
if (tmpIsTerminated)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#define NANOSECONDS_PER_SECOND 1000000000
|
#define NANOSECONDS_PER_SECOND 1000000000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define THREAD_WAIT_INFINITE 0xFFFFFFFF
|
||||||
|
|
||||||
class Thread
|
class Thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -347,7 +347,6 @@ ClientStateStartSession::Process(ClientThread &client)
|
|||||||
NetPacketJoinGame::Data initData;
|
NetPacketJoinGame::Data initData;
|
||||||
initData.password = context.GetPassword();
|
initData.password = context.GetPassword();
|
||||||
initData.playerName = context.GetPlayerName();
|
initData.playerName = context.GetPlayerName();
|
||||||
initData.ptype = PLAYER_TYPE_HUMAN; // TODO
|
|
||||||
|
|
||||||
boost::shared_ptr<NetPacket> packet(new NetPacketJoinGame);
|
boost::shared_ptr<NetPacket> packet(new NetPacketJoinGame);
|
||||||
((NetPacketJoinGame *)packet.get())->SetData(initData);
|
((NetPacketJoinGame *)packet.get())->SetData(initData);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ using namespace std;
|
|||||||
#define NET_TYPE_ERROR 0x0400
|
#define NET_TYPE_ERROR 0x0400
|
||||||
|
|
||||||
#define NET_PLAYER_FLAG_HUMAN 0x01
|
#define NET_PLAYER_FLAG_HUMAN 0x01
|
||||||
|
#define NET_PLAYER_FLAG_ADMIN 0x02
|
||||||
|
|
||||||
#define NET_ERR_JOIN_GAME_VERSION_NOT_SUPPORTED 0x0001
|
#define NET_ERR_JOIN_GAME_VERSION_NOT_SUPPORTED 0x0001
|
||||||
#define NET_ERR_JOIN_GAME_SERVER_FULL 0x0002
|
#define NET_ERR_JOIN_GAME_SERVER_FULL 0x0002
|
||||||
@@ -83,9 +84,8 @@ struct GCC_PACKED NetPacketJoinGameData
|
|||||||
u_int16_t requestedVersionMajor;
|
u_int16_t requestedVersionMajor;
|
||||||
u_int16_t requestedVersionMinor;
|
u_int16_t requestedVersionMinor;
|
||||||
u_int16_t passwordLength;
|
u_int16_t passwordLength;
|
||||||
u_int16_t playerFlags;
|
|
||||||
u_int16_t playerNameLength;
|
u_int16_t playerNameLength;
|
||||||
u_int16_t reserved;
|
u_int32_t reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GCC_PACKED NetPacketJoinGameAckData
|
struct GCC_PACKED NetPacketJoinGameAckData
|
||||||
@@ -93,11 +93,13 @@ struct GCC_PACKED NetPacketJoinGameAckData
|
|||||||
NetPacketHeader head;
|
NetPacketHeader head;
|
||||||
u_int32_t sessionId;
|
u_int32_t sessionId;
|
||||||
u_int16_t playerId;
|
u_int16_t playerId;
|
||||||
|
u_int16_t playerFlags;
|
||||||
u_int16_t maxNumberOfPlayers;
|
u_int16_t maxNumberOfPlayers;
|
||||||
u_int16_t smallBlind;
|
u_int16_t smallBlind;
|
||||||
u_int16_t handsBeforeRaise;
|
u_int16_t handsBeforeRaise;
|
||||||
u_int16_t proposedGuiSpeed;
|
u_int16_t proposedGuiSpeed;
|
||||||
u_int16_t playerActionTimeout;
|
u_int16_t playerActionTimeout;
|
||||||
|
u_int16_t reserved;
|
||||||
u_int32_t startMoney;
|
u_int32_t startMoney;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -670,7 +672,6 @@ NetPacketJoinGame::SetData(const NetPacketJoinGame::Data &inData)
|
|||||||
|
|
||||||
// Set the data.
|
// Set the data.
|
||||||
tmpData->passwordLength = htons(passwordLen);
|
tmpData->passwordLength = htons(passwordLen);
|
||||||
tmpData->playerFlags = htons((inData.ptype == PLAYER_TYPE_HUMAN) ? NET_PLAYER_FLAG_HUMAN : 0);
|
|
||||||
tmpData->playerNameLength = htons(playerNameLen);
|
tmpData->playerNameLength = htons(playerNameLen);
|
||||||
char *passwordPtr = (char *)tmpData + sizeof(NetPacketJoinGameData);
|
char *passwordPtr = (char *)tmpData + sizeof(NetPacketJoinGameData);
|
||||||
memcpy(passwordPtr, inData.password.c_str(), passwordLen);
|
memcpy(passwordPtr, inData.password.c_str(), passwordLen);
|
||||||
@@ -689,8 +690,6 @@ NetPacketJoinGame::GetData(NetPacketJoinGame::Data &outData) const
|
|||||||
outData.versionMajor = ntohs(tmpData->requestedVersionMajor);
|
outData.versionMajor = ntohs(tmpData->requestedVersionMajor);
|
||||||
outData.versionMinor = ntohs(tmpData->requestedVersionMinor);
|
outData.versionMinor = ntohs(tmpData->requestedVersionMinor);
|
||||||
|
|
||||||
outData.ptype = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_HUMAN) ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
|
||||||
|
|
||||||
u_int16_t passwordLen = ntohs(tmpData->passwordLength);
|
u_int16_t passwordLen = ntohs(tmpData->passwordLength);
|
||||||
char *passwordPtr = (char *)tmpData + sizeof(NetPacketJoinGameData);
|
char *passwordPtr = (char *)tmpData + sizeof(NetPacketJoinGameData);
|
||||||
outData.password = string(passwordPtr, passwordLen);
|
outData.password = string(passwordPtr, passwordLen);
|
||||||
@@ -766,8 +765,15 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData)
|
|||||||
{
|
{
|
||||||
NetPacketJoinGameAckData *tmpData = (NetPacketJoinGameAckData *)GetRawData();
|
NetPacketJoinGameAckData *tmpData = (NetPacketJoinGameAckData *)GetRawData();
|
||||||
|
|
||||||
|
u_int16_t tmpPlayerFlags = 0;
|
||||||
|
if (inData.ptype == PLAYER_TYPE_HUMAN)
|
||||||
|
tmpPlayerFlags |= NET_PLAYER_FLAG_HUMAN;
|
||||||
|
if (inData.prights == PLAYER_RIGHTS_ADMIN)
|
||||||
|
tmpPlayerFlags |= NET_PLAYER_FLAG_ADMIN;
|
||||||
|
|
||||||
tmpData->sessionId = htonl(inData.sessionId);
|
tmpData->sessionId = htonl(inData.sessionId);
|
||||||
tmpData->playerId = htons(inData.yourPlayerUniqueId);
|
tmpData->playerId = htons(inData.yourPlayerUniqueId);
|
||||||
|
tmpData->playerFlags = htons(tmpPlayerFlags);
|
||||||
tmpData->maxNumberOfPlayers = htons(inData.gameData.maxNumberOfPlayers);
|
tmpData->maxNumberOfPlayers = htons(inData.gameData.maxNumberOfPlayers);
|
||||||
tmpData->smallBlind = htons(inData.gameData.smallBlind);
|
tmpData->smallBlind = htons(inData.gameData.smallBlind);
|
||||||
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
|
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
|
||||||
@@ -786,6 +792,8 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const
|
|||||||
|
|
||||||
outData.sessionId = ntohl(tmpData->sessionId);
|
outData.sessionId = ntohl(tmpData->sessionId);
|
||||||
outData.yourPlayerUniqueId = ntohs(tmpData->playerId);
|
outData.yourPlayerUniqueId = ntohs(tmpData->playerId);
|
||||||
|
outData.ptype = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_HUMAN) ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
||||||
|
outData.prights = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_ADMIN) ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL;
|
||||||
outData.gameData.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers);
|
outData.gameData.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers);
|
||||||
outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
|
outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
|
||||||
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||||
@@ -858,8 +866,14 @@ NetPacketPlayerJoined::SetData(const NetPacketPlayerJoined::Data &inData)
|
|||||||
|
|
||||||
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)GetRawData();
|
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)GetRawData();
|
||||||
|
|
||||||
|
u_int16_t tmpPlayerFlags = 0;
|
||||||
|
if (inData.ptype == PLAYER_TYPE_HUMAN)
|
||||||
|
tmpPlayerFlags |= NET_PLAYER_FLAG_HUMAN;
|
||||||
|
if (inData.prights == PLAYER_RIGHTS_ADMIN)
|
||||||
|
tmpPlayerFlags |= NET_PLAYER_FLAG_ADMIN;
|
||||||
|
|
||||||
// Set the data.
|
// Set the data.
|
||||||
tmpData->playerFlags = htons((inData.ptype == PLAYER_TYPE_HUMAN) ? NET_PLAYER_FLAG_HUMAN : 0);
|
tmpData->playerFlags = htons(tmpPlayerFlags);
|
||||||
tmpData->playerId = htons(inData.playerId);
|
tmpData->playerId = htons(inData.playerId);
|
||||||
tmpData->playerNameLength = htons(playerNameLen);
|
tmpData->playerNameLength = htons(playerNameLen);
|
||||||
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
||||||
@@ -876,6 +890,7 @@ NetPacketPlayerJoined::GetData(NetPacketPlayerJoined::Data &outData) const
|
|||||||
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)GetRawData();
|
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)GetRawData();
|
||||||
|
|
||||||
outData.ptype = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_HUMAN) ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
outData.ptype = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_HUMAN) ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
|
||||||
|
outData.prights = (ntohs(tmpData->playerFlags) & NET_PLAYER_FLAG_ADMIN) ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL;
|
||||||
outData.playerId = ntohs(tmpData->playerId);
|
outData.playerId = ntohs(tmpData->playerId);
|
||||||
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
||||||
outData.playerName = string(namePtr, ntohs(tmpData->playerNameLength));
|
outData.playerName = string(namePtr, ntohs(tmpData->playerNameLength));
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ ServerRecvStateInit::InternalProcess(ServerRecvThread &server, SessionWrapper se
|
|||||||
|
|
||||||
// Create player data object.
|
// Create player data object.
|
||||||
boost::shared_ptr<PlayerData> tmpPlayerData(
|
boost::shared_ptr<PlayerData> tmpPlayerData(
|
||||||
new PlayerData(m_curUniquePlayerId++, 0, joinGameData.ptype));
|
new PlayerData(m_curUniquePlayerId++, 0, PLAYER_TYPE_HUMAN));
|
||||||
tmpPlayerData->SetName(joinGameData.playerName);
|
tmpPlayerData->SetName(joinGameData.playerName);
|
||||||
tmpPlayerData->SetNetSessionData(session.sessionData);
|
tmpPlayerData->SetNetSessionData(session.sessionData);
|
||||||
|
|
||||||
|
|||||||
+9
-7
@@ -120,7 +120,6 @@ public:
|
|||||||
{
|
{
|
||||||
int versionMajor;
|
int versionMajor;
|
||||||
int versionMinor;
|
int versionMinor;
|
||||||
PlayerType ptype;
|
|
||||||
std::string playerName;
|
std::string playerName;
|
||||||
std::string password;
|
std::string password;
|
||||||
};
|
};
|
||||||
@@ -145,9 +144,11 @@ class NetPacketJoinGameAck : public NetPacket
|
|||||||
public:
|
public:
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
u_int32_t sessionId;
|
u_int32_t sessionId;
|
||||||
u_int16_t yourPlayerUniqueId;
|
u_int16_t yourPlayerUniqueId;
|
||||||
GameData gameData;
|
PlayerType ptype;
|
||||||
|
PlayerRights prights;
|
||||||
|
GameData gameData;
|
||||||
};
|
};
|
||||||
|
|
||||||
NetPacketJoinGameAck();
|
NetPacketJoinGameAck();
|
||||||
@@ -170,9 +171,10 @@ class NetPacketPlayerJoined : public NetPacket
|
|||||||
public:
|
public:
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
u_int16_t playerId;
|
u_int16_t playerId;
|
||||||
PlayerType ptype;
|
PlayerType ptype;
|
||||||
std::string playerName;
|
PlayerRights prights;
|
||||||
|
std::string playerName;
|
||||||
};
|
};
|
||||||
|
|
||||||
NetPacketPlayerJoined();
|
NetPacketPlayerJoined();
|
||||||
|
|||||||
+7
-1
@@ -31,7 +31,13 @@ class SessionData;
|
|||||||
enum PlayerType
|
enum PlayerType
|
||||||
{
|
{
|
||||||
PLAYER_TYPE_COMPUTER,
|
PLAYER_TYPE_COMPUTER,
|
||||||
PLAYER_TYPE_HUMAN,
|
PLAYER_TYPE_HUMAN
|
||||||
|
};
|
||||||
|
|
||||||
|
enum PlayerRights
|
||||||
|
{
|
||||||
|
PLAYER_RIGHTS_NORMAL,
|
||||||
|
PLAYER_RIGHTS_ADMIN
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerData
|
class PlayerData
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 <iostream>
|
||||||
|
|
||||||
|
#include "session.h"
|
||||||
|
#include "configfile.h"
|
||||||
|
#include <gui/generic/serverguiwrapper.h>
|
||||||
|
#include <net/socket_startup.h>
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <crtdbg.h>
|
||||||
|
|
||||||
|
#define ENABLE_LEAK_CHECK() \
|
||||||
|
{ \
|
||||||
|
int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); \
|
||||||
|
tmpFlag |= _CRTDBG_LEAK_CHECK_DF; \
|
||||||
|
_CrtSetDbgFlag(tmpFlag); \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENABLE_LEAK_CHECK
|
||||||
|
#define ENABLE_LEAK_CHECK()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
volatile int g_pokerthTerminate = 0;
|
||||||
|
|
||||||
|
void
|
||||||
|
TerminateHandler(int signal)
|
||||||
|
{
|
||||||
|
g_pokerthTerminate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
ENABLE_LEAK_CHECK();
|
||||||
|
|
||||||
|
//_CrtSetBreakAlloc(164);
|
||||||
|
|
||||||
|
signal(SIGTERM, TerminateHandler);
|
||||||
|
signal(SIGINT, TerminateHandler);
|
||||||
|
|
||||||
|
//create defaultconfig
|
||||||
|
ConfigFile *myConfig = new ConfigFile(argc, argv);
|
||||||
|
|
||||||
|
socket_startup();
|
||||||
|
|
||||||
|
// Create pseudo Gui Wrapper for the server.
|
||||||
|
boost::shared_ptr<GuiInterface> myServerGuiInterface(new ServerGuiWrapper(myConfig, NULL, NULL));
|
||||||
|
{
|
||||||
|
boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig));
|
||||||
|
myServerGuiInterface->setSession(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameData gameData;
|
||||||
|
gameData.maxNumberOfPlayers = myConfig->readConfigInt("NetNumberOfPlayers");
|
||||||
|
gameData.startMoney = myConfig->readConfigInt("NetStartCash");
|
||||||
|
gameData.smallBlind = myConfig->readConfigInt("NetSmallBlind");
|
||||||
|
gameData.handsBeforeRaise = myConfig->readConfigInt("NetHandsBeforeRaiseSmallBlind");
|
||||||
|
gameData.guiSpeed = 4;
|
||||||
|
gameData.playerActionTimeoutSec = myConfig->readConfigInt("NetTimeOutPlayerAction");
|
||||||
|
|
||||||
|
myServerGuiInterface->getSession().startNetworkServer(gameData);
|
||||||
|
while (!g_pokerthTerminate)
|
||||||
|
{
|
||||||
|
myServerGuiInterface->getSession().waitForNetworkServer(100);
|
||||||
|
}
|
||||||
|
myServerGuiInterface->getSession().terminateNetworkServer();
|
||||||
|
|
||||||
|
socket_cleanup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -196,6 +196,17 @@ void Session::terminateNetworkServer()
|
|||||||
myNetServer = 0;
|
myNetServer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::waitForNetworkServer(unsigned timeoutMsec)
|
||||||
|
{
|
||||||
|
if (!myNetServer)
|
||||||
|
return; // already terminated
|
||||||
|
if (myNetServer->Join(timeoutMsec))
|
||||||
|
{
|
||||||
|
delete myNetServer;
|
||||||
|
myNetServer = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Session::sendClientPlayerAction()
|
void Session::sendClientPlayerAction()
|
||||||
{
|
{
|
||||||
if (!myNetClient)
|
if (!myNetClient)
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
void startNetworkServer(const GameData &gameData);
|
void startNetworkServer(const GameData &gameData);
|
||||||
void initiateNetworkServerGame();
|
void initiateNetworkServerGame();
|
||||||
void terminateNetworkServer();
|
void terminateNetworkServer();
|
||||||
|
void waitForNetworkServer(unsigned timeoutMsec);
|
||||||
|
|
||||||
void sendClientPlayerAction();
|
void sendClientPlayerAction();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user