Added new packet type as end of game notification. Now displaying dialogs at end of game, to start a new game. Server errors are displayed.
This commit is contained in:
@@ -335,6 +335,16 @@ Server Notification: End Of Hand Hide Cards
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
Server Notification: End Of Game
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Message Type = 17 | Message Length = 8 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Winner Player Id | Reserved |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
Client Request: Send Chat Text
|
||||
|
||||
|
||||
@@ -1,117 +1,119 @@
|
||||
/***************************************************************************
|
||||
* 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 <session.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
ServerGuiWrapper::ServerGuiWrapper(ConfigFile *config, ClientCallback *clientcb, ServerCallback *servercb)
|
||||
: myConfig(config), myClientcb(clientcb), myServercb(servercb)
|
||||
{
|
||||
}
|
||||
|
||||
ServerGuiWrapper::~ServerGuiWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
void ServerGuiWrapper::initGui(int speed) {}
|
||||
|
||||
Session &ServerGuiWrapper::getSession()
|
||||
{
|
||||
assert(mySession.get());
|
||||
return *mySession;
|
||||
}
|
||||
|
||||
void ServerGuiWrapper::setSession(boost::shared_ptr<Session> session)
|
||||
{
|
||||
mySession = session;
|
||||
}
|
||||
|
||||
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::refreshButton() const {}
|
||||
void ServerGuiWrapper::refreshGameLabels(GameState state) const {}
|
||||
|
||||
void ServerGuiWrapper::waitForGuiUpdateDone() const {}
|
||||
|
||||
void ServerGuiWrapper::dealHoleCards() {}
|
||||
void ServerGuiWrapper::dealFlopCards() {}
|
||||
void ServerGuiWrapper::dealTurnCard() {}
|
||||
void ServerGuiWrapper::dealRiverCard() {}
|
||||
|
||||
void ServerGuiWrapper::nextPlayerAnimation() {}
|
||||
|
||||
void ServerGuiWrapper::preflopAnimation1() {}
|
||||
void ServerGuiWrapper::preflopAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::flopAnimation1() {}
|
||||
void ServerGuiWrapper::flopAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::turnAnimation1() {}
|
||||
void ServerGuiWrapper::turnAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::riverAnimation1() {}
|
||||
void ServerGuiWrapper::riverAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::postRiverAnimation1() {}
|
||||
void ServerGuiWrapper::postRiverRunAnimation1() {}
|
||||
|
||||
void ServerGuiWrapper::flipHolecardsAllIn() {}
|
||||
|
||||
void ServerGuiWrapper::nextRoundCleanGui() {}
|
||||
|
||||
void ServerGuiWrapper::meInAction() {}
|
||||
void ServerGuiWrapper::disableMyButtons() {}
|
||||
void ServerGuiWrapper::startTimeoutAnimation(int playerId, int timeoutSec) {}
|
||||
void ServerGuiWrapper::stopTimeoutAnimation(int playerId) {}
|
||||
|
||||
void ServerGuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) {}
|
||||
void ServerGuiWrapper::logNewGameHandMsg(int gameID, int handID) {}
|
||||
void ServerGuiWrapper::logPlayerWinsMsg(int playerID, int pot) {}
|
||||
void ServerGuiWrapper::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4, int card5) {}
|
||||
void ServerGuiWrapper::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt, std::string showHas) {}
|
||||
|
||||
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(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
|
||||
void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); }
|
||||
|
||||
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); }
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* 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 <session.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
ServerGuiWrapper::ServerGuiWrapper(ConfigFile *config, ClientCallback *clientcb, ServerCallback *servercb)
|
||||
: myConfig(config), myClientcb(clientcb), myServercb(servercb)
|
||||
{
|
||||
}
|
||||
|
||||
ServerGuiWrapper::~ServerGuiWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
void ServerGuiWrapper::initGui(int speed) {}
|
||||
|
||||
Session &ServerGuiWrapper::getSession()
|
||||
{
|
||||
assert(mySession.get());
|
||||
return *mySession;
|
||||
}
|
||||
|
||||
void ServerGuiWrapper::setSession(boost::shared_ptr<Session> session)
|
||||
{
|
||||
mySession = session;
|
||||
}
|
||||
|
||||
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::refreshButton() const {}
|
||||
void ServerGuiWrapper::refreshGameLabels(GameState state) const {}
|
||||
|
||||
void ServerGuiWrapper::waitForGuiUpdateDone() const {}
|
||||
|
||||
void ServerGuiWrapper::dealHoleCards() {}
|
||||
void ServerGuiWrapper::dealFlopCards() {}
|
||||
void ServerGuiWrapper::dealTurnCard() {}
|
||||
void ServerGuiWrapper::dealRiverCard() {}
|
||||
|
||||
void ServerGuiWrapper::nextPlayerAnimation() {}
|
||||
|
||||
void ServerGuiWrapper::preflopAnimation1() {}
|
||||
void ServerGuiWrapper::preflopAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::flopAnimation1() {}
|
||||
void ServerGuiWrapper::flopAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::turnAnimation1() {}
|
||||
void ServerGuiWrapper::turnAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::riverAnimation1() {}
|
||||
void ServerGuiWrapper::riverAnimation2() {}
|
||||
|
||||
void ServerGuiWrapper::postRiverAnimation1() {}
|
||||
void ServerGuiWrapper::postRiverRunAnimation1() {}
|
||||
|
||||
void ServerGuiWrapper::flipHolecardsAllIn() {}
|
||||
|
||||
void ServerGuiWrapper::nextRoundCleanGui() {}
|
||||
|
||||
void ServerGuiWrapper::meInAction() {}
|
||||
void ServerGuiWrapper::disableMyButtons() {}
|
||||
void ServerGuiWrapper::startTimeoutAnimation(int playerId, int timeoutSec) {}
|
||||
void ServerGuiWrapper::stopTimeoutAnimation(int playerId) {}
|
||||
|
||||
void ServerGuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) {}
|
||||
void ServerGuiWrapper::logNewGameHandMsg(int gameID, int handID) {}
|
||||
void ServerGuiWrapper::logPlayerWinsMsg(int playerID, int pot) {}
|
||||
void ServerGuiWrapper::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4, int card5) {}
|
||||
void ServerGuiWrapper::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt, std::string showHas) {}
|
||||
|
||||
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(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
|
||||
void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); }
|
||||
void ServerGuiWrapper::SignalNetClientWaitDialog() { if (myClientcb) myClientcb->SignalNetClientWaitDialog(); }
|
||||
|
||||
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); }
|
||||
void ServerGuiWrapper::SignalNetServerStartDialog() { if (myServercb) myServercb->SignalNetServerStartDialog(); }
|
||||
|
||||
\
|
||||
@@ -91,6 +91,7 @@ public:
|
||||
void SignalNetClientPlayerJoined(const std::string &playerName);
|
||||
void SignalNetClientPlayerLeft(const std::string &playerName);
|
||||
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
|
||||
void SignalNetClientWaitDialog();
|
||||
|
||||
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
@@ -98,6 +99,7 @@ public:
|
||||
void SignalNetServerError(int errorID, int osErrorID);
|
||||
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||
void SignalNetServerPlayerLeft(const std::string &playerName);
|
||||
void SignalNetServerStartDialog();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->si
|
||||
void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { myW->signalNetClientPlayerLeft(QString::fromUtf8(playerName.c_str())); }
|
||||
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
|
||||
void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
|
||||
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowClientWaitDialog(); }
|
||||
|
||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
|
||||
@@ -120,5 +121,5 @@ void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName)
|
||||
myW->signalNetServerPlayerLeft(tmpName);
|
||||
myLog->signalLogPlayerLeftMsg(tmpName);
|
||||
}
|
||||
|
||||
void GuiWrapper::SignalNetServerStartDialog() { myW->signalShowServerStartDialog(); }
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
Session &getSession();
|
||||
void setSession(boost::shared_ptr<Session> session);
|
||||
|
||||
void showServerStartDialog();
|
||||
void showClientWaitDialog();
|
||||
|
||||
void refreshSet() const;
|
||||
void refreshCash() const;
|
||||
void refreshAction(int =-1, int =-1) const;
|
||||
@@ -98,6 +101,7 @@ public:
|
||||
void SignalNetClientPlayerJoined(const std::string &playerName);
|
||||
void SignalNetClientPlayerLeft(const std::string &playerName);
|
||||
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
|
||||
void SignalNetClientWaitDialog();
|
||||
|
||||
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
@@ -105,6 +109,7 @@ public:
|
||||
void SignalNetServerError(int errorID, int osErrorID);
|
||||
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||
void SignalNetServerPlayerLeft(const std::string &playerName);
|
||||
void SignalNetServerStartDialog();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -573,6 +573,9 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
||||
//Nachrichten Thread-Save
|
||||
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
|
||||
|
||||
connect(this, SIGNAL(signalShowServerStartDialog()), this, SLOT(showServerStartDialog()));
|
||||
connect(this, SIGNAL(signalShowClientWaitDialog()), this, SLOT(showClientWaitDialog()));
|
||||
|
||||
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
|
||||
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
|
||||
connect(this, SIGNAL(signalRefreshAction(int, int)), this, SLOT(refreshAction(int, int)));
|
||||
@@ -733,21 +736,8 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
|
||||
mySession->startNetworkClientForLocalServer();
|
||||
|
||||
myStartNetworkGameDialog->setMaxPlayerNumber(gameData.numberOfPlayers);
|
||||
myStartNetworkGameDialog->exec();
|
||||
|
||||
|
||||
|
||||
if (myStartNetworkGameDialog->result() == QDialog::Accepted ) {
|
||||
|
||||
//some gui modifications
|
||||
networkGameModification();
|
||||
myServerGuiInterface->getSession().initiateNetworkServerGame();
|
||||
|
||||
}
|
||||
else {
|
||||
mySession->terminateNetworkClient();
|
||||
myServerGuiInterface->getSession().terminateNetworkServer();
|
||||
}
|
||||
showServerStartDialog();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -779,15 +769,7 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
|
||||
actionJoin_network_Game->trigger(); // re-trigger
|
||||
}
|
||||
else {
|
||||
myWaitingForServerGameDialog->exec();
|
||||
|
||||
if (myWaitingForServerGameDialog->result() == QDialog::Rejected) {
|
||||
mySession->terminateNetworkClient();
|
||||
}
|
||||
else {
|
||||
//some gui modifications
|
||||
networkGameModification();
|
||||
}
|
||||
showClientWaitDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -890,6 +872,39 @@ void mainWindowImpl::initGui(int speed)
|
||||
setSpeeds();
|
||||
}
|
||||
|
||||
void mainWindowImpl::showServerStartDialog()
|
||||
{
|
||||
myStartNetworkGameDialog->exec();
|
||||
|
||||
if (myStartNetworkGameDialog->result() == QDialog::Accepted ) {
|
||||
|
||||
//some gui modifications
|
||||
networkGameModification();
|
||||
myServerGuiInterface->getSession().initiateNetworkServerGame();
|
||||
|
||||
}
|
||||
else {
|
||||
mySession->terminateNetworkClient();
|
||||
myServerGuiInterface->getSession().terminateNetworkServer();
|
||||
}
|
||||
}
|
||||
|
||||
void mainWindowImpl::showClientWaitDialog()
|
||||
{
|
||||
if (!myServerGuiInterface.get() || !myServerGuiInterface->getSession().isNetworkServerRunning())
|
||||
{
|
||||
myWaitingForServerGameDialog->exec();
|
||||
|
||||
if (myWaitingForServerGameDialog->result() == QDialog::Accepted) {
|
||||
//some gui modifications
|
||||
networkGameModification();
|
||||
}
|
||||
else {
|
||||
mySession->terminateNetworkClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Session &mainWindowImpl::getSession() { assert(mySession.get()); return *mySession; }
|
||||
void mainWindowImpl::setSession(boost::shared_ptr<Session> session) { mySession = session; }
|
||||
|
||||
@@ -2344,7 +2359,7 @@ void mainWindowImpl::breakButtonClicked() {
|
||||
int width = tempMetrics.width(tr("Stop"));
|
||||
pushButton_break->setMinimumSize(width+10,20);
|
||||
|
||||
pushButton_break->setText(tr("Stop"));
|
||||
pushButton_break->setText(tr("Stop"));
|
||||
startNewHand();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,9 @@ public:
|
||||
signals:
|
||||
void signalInitGui(int speed);
|
||||
|
||||
void signalShowServerStartDialog();
|
||||
void signalShowClientWaitDialog();
|
||||
|
||||
void signalRefreshSet();
|
||||
void signalRefreshCash();
|
||||
void signalRefreshAction(int =-1, int=-1);
|
||||
@@ -129,6 +132,9 @@ public slots:
|
||||
|
||||
void initGui(int speed);
|
||||
|
||||
void showServerStartDialog();
|
||||
void showClientWaitDialog();
|
||||
|
||||
//refresh-Funktionen
|
||||
void refreshSet();
|
||||
void refreshCash();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
***************************************************************************/
|
||||
#include "waitforservertostartgamedialogimpl.h"
|
||||
#include "session.h"
|
||||
#include <net/socket_msg.h>
|
||||
// #include "configfile.h"
|
||||
|
||||
waitForServerToStartGameDialogImpl::waitForServerToStartGameDialogImpl(QWidget *parent)
|
||||
@@ -33,7 +34,10 @@ waitForServerToStartGameDialogImpl::waitForServerToStartGameDialogImpl(QWidget *
|
||||
|
||||
void waitForServerToStartGameDialogImpl::refresh(int actionID) {
|
||||
|
||||
QTimer::singleShot(1000, this, SLOT(accept()));
|
||||
if (actionID == MSG_NET_GAME_CLIENT_START)
|
||||
{
|
||||
QTimer::singleShot(500, this, SLOT(accept()));
|
||||
}
|
||||
}
|
||||
|
||||
void waitForServerToStartGameDialogImpl::cancel() {
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
virtual void SignalNetClientPlayerLeft(const std::string &playerName) = 0;
|
||||
|
||||
virtual void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg) = 0;
|
||||
virtual void SignalNetClientWaitDialog() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -568,6 +568,12 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND_START;
|
||||
}
|
||||
else if (packet->ToNetPacketEndOfGame())
|
||||
{
|
||||
client.GetCallback().SignalNetClientWaitDialog();
|
||||
client.SetState(ClientStateWaitGame::Instance());
|
||||
retVal = MSG_NET_GAME_CLIENT_END;
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
}
|
||||
@@ -831,7 +837,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
|
||||
// Wait for next Hand.
|
||||
client.SetState(ClientStateWaitHand::Instance());
|
||||
retVal = MSG_NET_GAME_SERVER_HAND_END;
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND_END;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ using namespace std;
|
||||
#define NET_TYPE_ALL_IN_SHOW_CARDS 0x000E
|
||||
#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x000F
|
||||
#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x0010
|
||||
#define NET_TYPE_END_OF_GAME 0x0011
|
||||
|
||||
#define NET_TYPE_SEND_CHAT_TEXT 0x0200
|
||||
#define NET_TYPE_CHAT_TEXT 0x0201
|
||||
@@ -244,6 +245,13 @@ struct GCC_PACKED NetPacketEndOfHandHideCardsData
|
||||
u_int32_t playerMoney;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketEndOfGameData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t winnerPlayerId;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketSendChatTextData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
@@ -340,6 +348,9 @@ NetPacket::Create(char *data, unsigned &dataSize)
|
||||
case NET_TYPE_END_OF_HAND_HIDE_CARDS:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketEndOfHandHideCards);
|
||||
break;
|
||||
case NET_TYPE_END_OF_GAME:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketEndOfGame);
|
||||
break;
|
||||
case NET_TYPE_SEND_CHAT_TEXT:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketSendChatText);
|
||||
break;
|
||||
@@ -526,6 +537,12 @@ NetPacket::ToNetPacketEndOfHandHideCards() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketEndOfGame *
|
||||
NetPacket::ToNetPacketEndOfGame() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketSendChatText *
|
||||
NetPacket::ToNetPacketSendChatText() const
|
||||
{
|
||||
@@ -1873,6 +1890,67 @@ NetPacketEndOfHandHideCards::Check(const NetPacketHeader* data) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketEndOfGame::NetPacketEndOfGame()
|
||||
: NetPacket(NET_TYPE_END_OF_GAME, sizeof(NetPacketEndOfGameData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketEndOfGame::~NetPacketEndOfGame()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketEndOfGame::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketEndOfGame);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketEndOfGame::SetData(const NetPacketEndOfGame::Data &inData)
|
||||
{
|
||||
NetPacketEndOfGameData *tmpData = (NetPacketEndOfGameData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->winnerPlayerId = htons(inData.winnerPlayerId);
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketEndOfGame::GetData(NetPacketEndOfGame::Data &outData) const
|
||||
{
|
||||
NetPacketEndOfGameData *tmpData = (NetPacketEndOfGameData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.winnerPlayerId = ntohs(tmpData->winnerPlayerId);
|
||||
}
|
||||
|
||||
const NetPacketEndOfGame *
|
||||
NetPacketEndOfGame::ToNetPacketEndOfGame() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketEndOfGame::Check(const NetPacketHeader* data) const
|
||||
{
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen != sizeof(NetPacketEndOfGameData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketSendChatText::NetPacketSendChatText()
|
||||
: NetPacket(NET_TYPE_SEND_CHAT_TEXT, sizeof(NetPacketSendChatTextData))
|
||||
{
|
||||
|
||||
@@ -34,6 +34,7 @@ using namespace std;
|
||||
|
||||
#define SERVER_WAIT_TIMEOUT_MSEC 50
|
||||
#define SERVER_DELAY_NEXT_HAND_SEC 10
|
||||
#define SERVER_DELAY_NEXT_GAME_SEC 10
|
||||
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5
|
||||
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2
|
||||
#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2
|
||||
@@ -642,11 +643,16 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
||||
if (curGame.getCurrentHand()->getPlayerArray()[i]->getMyCash() > 0)
|
||||
playersPositiveCashCounter++;
|
||||
}
|
||||
assert(playersPositiveCashCounter);
|
||||
if (playersPositiveCashCounter == 1)
|
||||
server.SetState(ServerRecvStateFinal::Instance()); // TODO
|
||||
{
|
||||
// View a dialog for a new game - delayed.
|
||||
server.SetState(ServerRecvStateNextGameDelay::Instance());
|
||||
retVal = MSG_NET_GAME_SERVER_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
server.SetState(ServerRecvStateNextHand::Instance());
|
||||
server.SetState(ServerRecvStateNextHandDelay::Instance());
|
||||
retVal = MSG_NET_GAME_SERVER_HAND_END;
|
||||
}
|
||||
}
|
||||
@@ -922,10 +928,9 @@ ServerRecvStateShowCardsDelay::Process(ServerRecvThread &server)
|
||||
{
|
||||
int retVal = ServerRecvStateReceiving::Process(server);
|
||||
|
||||
Game &curGame = server.GetGame();
|
||||
|
||||
if (GetTimer().elapsed().seconds() >= SERVER_SHOW_CARDS_DELAY_SEC)
|
||||
{
|
||||
Game &curGame = server.GetGame();
|
||||
SendNewRoundCards(server, curGame, curGame.getCurrentHand()->getActualRound());
|
||||
|
||||
server.SetState(ServerRecvStateDealCardsDelay::Instance());
|
||||
@@ -943,23 +948,23 @@ ServerRecvStateShowCardsDelay::InternalProcess(ServerRecvThread &server, Session
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateNextHand &
|
||||
ServerRecvStateNextHand::Instance()
|
||||
ServerRecvStateNextHandDelay &
|
||||
ServerRecvStateNextHandDelay::Instance()
|
||||
{
|
||||
static ServerRecvStateNextHand state;
|
||||
static ServerRecvStateNextHandDelay state;
|
||||
return state;
|
||||
}
|
||||
|
||||
ServerRecvStateNextHand::ServerRecvStateNextHand()
|
||||
ServerRecvStateNextHandDelay::ServerRecvStateNextHandDelay()
|
||||
{
|
||||
}
|
||||
|
||||
ServerRecvStateNextHand::~ServerRecvStateNextHand()
|
||||
ServerRecvStateNextHandDelay::~ServerRecvStateNextHandDelay()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateNextHand::Process(ServerRecvThread &server)
|
||||
ServerRecvStateNextHandDelay::Process(ServerRecvThread &server)
|
||||
{
|
||||
int retVal = ServerRecvStateReceiving::Process(server);
|
||||
|
||||
@@ -970,7 +975,65 @@ ServerRecvStateNextHand::Process(ServerRecvThread &server)
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateNextHand::InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
ServerRecvStateNextHandDelay::InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateNextGameDelay &
|
||||
ServerRecvStateNextGameDelay::Instance()
|
||||
{
|
||||
static ServerRecvStateNextGameDelay state;
|
||||
return state;
|
||||
}
|
||||
|
||||
ServerRecvStateNextGameDelay::ServerRecvStateNextGameDelay()
|
||||
{
|
||||
}
|
||||
|
||||
ServerRecvStateNextGameDelay::~ServerRecvStateNextGameDelay()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateNextGameDelay::Process(ServerRecvThread &server)
|
||||
{
|
||||
int retVal = ServerRecvStateReceiving::Process(server);
|
||||
|
||||
if (GetTimer().elapsed().seconds() >= SERVER_DELAY_NEXT_GAME_SEC)
|
||||
{
|
||||
Game &curGame = server.GetGame();
|
||||
// The game has ended. Notify all clients.
|
||||
PlayerInterface *winnerPlayer = NULL;
|
||||
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++)
|
||||
{
|
||||
winnerPlayer = curGame.getCurrentHand()->getPlayerArray()[i];
|
||||
if (winnerPlayer->getMyCash() > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket> endGame(new NetPacketEndOfGame);
|
||||
NetPacketEndOfGame::Data endGameData;
|
||||
endGameData.winnerPlayerId = winnerPlayer->getMyUniqueID();
|
||||
static_cast<NetPacketEndOfGame *>(endGame.get())->SetData(endGameData);
|
||||
|
||||
server.SendToAllPlayers(endGame);
|
||||
|
||||
// Switch back to the GUI, wait for the start of a new game.
|
||||
// Luckily, the names are still in the GUI dialog.
|
||||
// We just need to show the proper dialog, and people can
|
||||
// join or leave as usual.
|
||||
server.GetCallback().SignalNetServerStartDialog();
|
||||
server.SetState(ServerRecvStateInit::Instance());
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateNextGameDelay::InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ ServerRecvThread::Main()
|
||||
// Close sessions.
|
||||
CloseSessionLoop();
|
||||
}
|
||||
} catch (const NetException &)
|
||||
} catch (const NetException &e)
|
||||
{
|
||||
// TODO
|
||||
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
|
||||
}
|
||||
GetSender().SignalTermination();
|
||||
GetSender().Join(SENDER_THREAD_TERMINATE_TIMEOUT);
|
||||
|
||||
+25
-1
@@ -56,6 +56,7 @@ class NetPacketDealRiverCard;
|
||||
class NetPacketAllInShowCards;
|
||||
class NetPacketEndOfHandShowCards;
|
||||
class NetPacketEndOfHandHideCards;
|
||||
class NetPacketEndOfGame;
|
||||
class NetPacketSendChatText;
|
||||
class NetPacketChatText;
|
||||
class NetPacketError;
|
||||
@@ -93,6 +94,7 @@ public:
|
||||
virtual const NetPacketAllInShowCards *ToNetPacketAllInShowCards() const;
|
||||
virtual const NetPacketEndOfHandShowCards *ToNetPacketEndOfHandShowCards() const;
|
||||
virtual const NetPacketEndOfHandHideCards *ToNetPacketEndOfHandHideCards() const;
|
||||
virtual const NetPacketEndOfGame *ToNetPacketEndOfGame() const;
|
||||
virtual const NetPacketSendChatText *ToNetPacketSendChatText() const;
|
||||
virtual const NetPacketChatText *ToNetPacketChatText() const;
|
||||
virtual const NetPacketError *ToNetPacketError() const;
|
||||
@@ -216,7 +218,6 @@ public:
|
||||
struct Data
|
||||
{
|
||||
StartData startData;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
NetPacketGameStart();
|
||||
@@ -520,6 +521,29 @@ protected:
|
||||
virtual void Check(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketEndOfGame : public NetPacket
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
u_int16_t winnerPlayerId;
|
||||
};
|
||||
|
||||
NetPacketEndOfGame();
|
||||
virtual ~NetPacketEndOfGame();
|
||||
|
||||
virtual boost::shared_ptr<NetPacket> Clone() const;
|
||||
|
||||
void SetData(const Data &inData);
|
||||
void GetData(Data &outData) const;
|
||||
|
||||
virtual const NetPacketEndOfGame *ToNetPacketEndOfGame() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Check(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketSendChatText : public NetPacket
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -33,6 +33,8 @@ public:
|
||||
|
||||
virtual void SignalNetServerPlayerJoined(const std::string &playerName) = 0;
|
||||
virtual void SignalNetServerPlayerLeft(const std::string &playerName) = 0;
|
||||
|
||||
virtual void SignalNetServerStartDialog() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -253,13 +253,13 @@ protected:
|
||||
};
|
||||
|
||||
// State: Delay before next hand.
|
||||
class ServerRecvStateNextHand : public ServerRecvStateReceiving, public ServerRecvStateRunning, public ServerRecvStateTimer
|
||||
class ServerRecvStateNextHandDelay : public ServerRecvStateReceiving, public ServerRecvStateRunning, public ServerRecvStateTimer
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
static ServerRecvStateNextHand &Instance();
|
||||
static ServerRecvStateNextHandDelay &Instance();
|
||||
|
||||
virtual ~ServerRecvStateNextHand();
|
||||
virtual ~ServerRecvStateNextHandDelay();
|
||||
|
||||
// Overwrite default processing
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
@@ -267,11 +267,30 @@ public:
|
||||
protected:
|
||||
|
||||
// Protected constructor - this is a singleton.
|
||||
ServerRecvStateNextHand();
|
||||
ServerRecvStateNextHandDelay();
|
||||
|
||||
virtual int InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet);
|
||||
};
|
||||
|
||||
// State: Delay before next hand.
|
||||
class ServerRecvStateNextGameDelay : public ServerRecvStateReceiving, public ServerRecvStateRunning, public ServerRecvStateTimer
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
static ServerRecvStateNextGameDelay &Instance();
|
||||
|
||||
virtual ~ServerRecvStateNextGameDelay();
|
||||
|
||||
// Overwrite default processing
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
protected:
|
||||
|
||||
// Protected constructor - this is a singleton.
|
||||
ServerRecvStateNextGameDelay();
|
||||
|
||||
virtual int InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet);
|
||||
};
|
||||
|
||||
// State: Final.
|
||||
class ServerRecvStateFinal : public ServerRecvStateReceiving, public ServerRecvStateRunning
|
||||
|
||||
@@ -173,7 +173,8 @@ friend class ServerRecvStateStartRound;
|
||||
friend class ServerRecvStateWaitPlayerAction;
|
||||
friend class ServerRecvStateShowCardsDelay;
|
||||
friend class ServerRecvStateDealCardsDelay;
|
||||
friend class ServerRecvStateNextHand;
|
||||
friend class ServerRecvStateNextHandDelay;
|
||||
friend class ServerRecvStateNextGameDelay;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -69,14 +69,17 @@
|
||||
|
||||
// The following messages are game messages.
|
||||
#define MSG_NET_GAME_CLIENT_START 5
|
||||
#define MSG_NET_GAME_SERVER_START 6
|
||||
#define MSG_NET_GAME_CLIENT_HAND_START 7
|
||||
#define MSG_NET_GAME_CLIENT_HAND_END 8
|
||||
#define MSG_NET_GAME_SERVER_HAND_START 9
|
||||
#define MSG_NET_GAME_SERVER_HAND_END 10
|
||||
#define MSG_NET_GAME_SERVER_ROUND 11
|
||||
#define MSG_NET_GAME_SERVER_ACTION 12
|
||||
#define MSG_NET_GAME_SERVER_CARDS_DELAY 13
|
||||
#define MSG_NET_GAME_CLIENT_END 9
|
||||
|
||||
#define MSG_NET_GAME_SERVER_START 10
|
||||
#define MSG_NET_GAME_SERVER_HAND_START 11
|
||||
#define MSG_NET_GAME_SERVER_HAND_END 12
|
||||
#define MSG_NET_GAME_SERVER_ROUND 13
|
||||
#define MSG_NET_GAME_SERVER_ACTION 14
|
||||
#define MSG_NET_GAME_SERVER_CARDS_DELAY 15
|
||||
#define MSG_NET_GAME_SERVER_END 16
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -227,3 +227,9 @@ bool Session::isNetworkClientRunning() const
|
||||
return myNetClient != NULL;
|
||||
}
|
||||
|
||||
bool Session::isNetworkServerRunning() const
|
||||
{
|
||||
// This, and every place which calls this, is a HACK.
|
||||
// TODO
|
||||
return myNetServer != NULL;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
void kickPlayer(const std::string &playerName);
|
||||
|
||||
bool isNetworkClientRunning() const; // TODO hack
|
||||
bool isNetworkServerRunning() const; // TODO hack
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user