diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index e90cf6c7..83133625 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -61,7 +61,7 @@ Server Reply: Join Game ACK +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Your Player ID | Your Player Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Number of Players | Small Blind | + | Max Number of Players | Small Blind | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Hands before raise | Proposed GUI Speed | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -116,7 +116,7 @@ Server Notification: Game Start +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Message Type = 5 | Message Length = 8 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Start Dealer Player Id | Reserved | + | Start Dealer Player Id | Number of Players | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ [ Dealer Pos can be different for each game, therefore it is not diff --git a/src/game.cpp b/src/game.cpp index 4bb07b4d..3a56058a 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -32,10 +32,10 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, const PlayerDataList &playerDataList, const GameData &gameData, const StartData &startData, int gameId) : myFactory(factory), myGui(gui), actualHand(0), actualBoard(0), - startQuantityPlayers(gameData.numberOfPlayers), + startQuantityPlayers(startData.numberOfPlayers), startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), - myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers), + myGameID(gameId), actualQuantityPlayers(startData.numberOfPlayers), actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) { // cout << "Create Game Object" << "\n"; diff --git a/src/gamedata.h b/src/gamedata.h index af72e8de..9f86beda 100644 --- a/src/gamedata.h +++ b/src/gamedata.h @@ -25,9 +25,9 @@ struct GameData { - GameData() : numberOfPlayers(0), startMoney(0), smallBlind(0), + GameData() : maxNumberOfPlayers(0), startMoney(0), smallBlind(0), handsBeforeRaise(1), guiSpeed(4), playerActionTimeoutSec(20) {} - int numberOfPlayers; + int maxNumberOfPlayers; int startMoney; int smallBlind; int handsBeforeRaise; @@ -37,8 +37,9 @@ struct GameData struct StartData { - StartData() : startDealerPlayerId(0) {} + StartData() : startDealerPlayerId(0), numberOfPlayers(0) {} unsigned startDealerPlayerId; + int numberOfPlayers; }; #endif diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index c0006fe4..1d2178ed 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -666,7 +666,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { GameData gameData; if(v) { // Set Game Data - gameData.numberOfPlayers = v->spinBox_quantityPlayers->value(); + gameData.maxNumberOfPlayers = v->spinBox_quantityPlayers->value(); gameData.startMoney = v->spinBox_startCash->value(); gameData.smallBlind = v->spinBox_smallBlind->value(); gameData.handsBeforeRaise = v->spinBox_handsBeforeRaiseSmallBlind->value(); @@ -676,7 +676,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { // start with default values else { // Set Game Data - gameData.numberOfPlayers = myConfig->readConfigInt("NumberOfPlayers"); + gameData.maxNumberOfPlayers = myConfig->readConfigInt("NumberOfPlayers"); gameData.startMoney = myConfig->readConfigInt("StartCash"); gameData.smallBlind = myConfig->readConfigInt("SmallBlind"); gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind"); @@ -686,7 +686,8 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { // Set dealer pos. StartData startData; int tmpDealerPos = 0; - Tools::getRandNumber(0, gameData.numberOfPlayers-1, 1, &tmpDealerPos, 0); + startData.numberOfPlayers = gameData.maxNumberOfPlayers; + Tools::getRandNumber(0, startData.numberOfPlayers-1, 1, &tmpDealerPos, 0); startData.startDealerPlayerId = static_cast(tmpDealerPos); //some gui modifications @@ -720,7 +721,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() { myServerGuiInterface->getSession().terminateNetworkServer(); GameData gameData; - gameData.numberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); + gameData.maxNumberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); gameData.startMoney = myCreateNetworkGameDialog->spinBox_startCash->value(); gameData.smallBlind = myCreateNetworkGameDialog->spinBox_smallBlind->value(); gameData.handsBeforeRaise = myCreateNetworkGameDialog->spinBox_handsBeforeRaiseSmallBlind->value(); @@ -735,7 +736,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() { myServerGuiInterface->getSession().startNetworkServer(gameData); mySession->startNetworkClientForLocalServer(); - myStartNetworkGameDialog->setMaxPlayerNumber(gameData.numberOfPlayers); + myStartNetworkGameDialog->setMaxPlayerNumber(gameData.maxNumberOfPlayers); showServerStartDialog(); } @@ -2513,6 +2514,11 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) { tr("You were kicked from the server."), QMessageBox::Close); } break; + case ERR_NET_INVALID_PLAYER_COUNT: + { QMessageBox::warning(this, tr("Network Error"), + tr("The client player count is invalid."), + QMessageBox::Close); } + break; default: { QMessageBox::warning(this, tr("Network Error"), tr("An internal error occured."), QMessageBox::Close); } diff --git a/src/gui/qt/startnetworkgamedialog/startnetworkgamedialogimpl.cpp b/src/gui/qt/startnetworkgamedialog/startnetworkgamedialogimpl.cpp index 53eeb495..e43acea8 100644 --- a/src/gui/qt/startnetworkgamedialog/startnetworkgamedialogimpl.cpp +++ b/src/gui/qt/startnetworkgamedialog/startnetworkgamedialogimpl.cpp @@ -32,6 +32,7 @@ startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFi connect( treeWidget, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( playerSelected(QTreeWidgetItem*, int) ) ); pushButton_Kick->setEnabled(FALSE); + pushButton_startGame->setEnabled(FALSE); } void startNetworkGameDialogImpl::startGame() { @@ -88,8 +89,10 @@ void startNetworkGameDialogImpl::kickPlayer() { void startNetworkGameDialogImpl::checkPlayerQuantity() { - if(treeWidget->topLevelItemCount() == maxPlayerNumber) pushButton_startGame->setEnabled(TRUE); - else pushButton_startGame->setDisabled(TRUE); + if (treeWidget->topLevelItemCount() >= 2) + pushButton_startGame->setEnabled(TRUE); + else + pushButton_startGame->setEnabled(FALSE); } diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 743df548..66ec3bd5 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -160,6 +160,8 @@ ClientThread::Main() boost::shared_ptr factory(new ClientEngineFactory); // LocalEngine erstellen MapPlayerDataList(); + if (GetPlayerDataList().size() != GetStartData().numberOfPlayers) + throw NetException(ERR_NET_INVALID_PLAYER_COUNT, 0); m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++)); // Initialize GUI speed. GetGui().initGui(GetGameData().guiSpeed); @@ -315,7 +317,7 @@ ClientThread::MapPlayerDataList() if (numberDiff >= 0) tmpData->SetNumber(numberDiff); else - tmpData->SetNumber(GetGameData().numberOfPlayers + numberDiff); + tmpData->SetNumber(GetStartData().numberOfPlayers + numberDiff); mappedList.push_back(tmpData); ++i; } diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index ba1a65e4..a50429ae 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -94,7 +94,7 @@ struct GCC_PACKED NetPacketJoinGameAckData u_int32_t sessionId; u_int16_t playerId; u_int16_t playerNumber; - u_int16_t numberOfPlayers; + u_int16_t maxNumberOfPlayers; u_int16_t smallBlind; u_int16_t handsBeforeRaise; u_int16_t proposedGuiSpeed; @@ -130,7 +130,7 @@ struct GCC_PACKED NetPacketGameStartData { NetPacketHeader head; u_int16_t startDealerPlayerId; - u_int16_t reserved; + u_int16_t numberOfPlayers; }; struct GCC_PACKED NetPacketHandStartData @@ -737,7 +737,7 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData) tmpData->sessionId = htonl(inData.sessionId); tmpData->playerId = htons(inData.yourPlayerUniqueId); tmpData->playerNumber = htons(inData.yourPlayerNum); - tmpData->numberOfPlayers = htons(inData.gameData.numberOfPlayers); + tmpData->maxNumberOfPlayers = htons(inData.gameData.maxNumberOfPlayers); tmpData->smallBlind = htons(inData.gameData.smallBlind); tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise); tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed); @@ -754,7 +754,7 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const outData.sessionId = ntohl(tmpData->sessionId); outData.yourPlayerUniqueId = ntohs(tmpData->playerId); outData.yourPlayerNum = ntohs(tmpData->playerNumber); - outData.gameData.numberOfPlayers = ntohs(tmpData->numberOfPlayers); + outData.gameData.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers); outData.gameData.smallBlind = ntohs(tmpData->smallBlind); outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise); outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed); @@ -973,6 +973,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData) assert(tmpData); tmpData->startDealerPlayerId = htons(inData.startData.startDealerPlayerId); + tmpData->numberOfPlayers = htons(inData.startData.numberOfPlayers); } void @@ -982,6 +983,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const assert(tmpData); outData.startData.startDealerPlayerId = ntohs(tmpData->startDealerPlayerId); + outData.startData.numberOfPlayers = ntohs(tmpData->numberOfPlayers); } const NetPacketGameStart * diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index db9fcfc4..0a1b3168 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -261,7 +261,7 @@ ServerRecvStateInit::InternalProcess(ServerRecvThread &server, SessionWrapper se size_t curNumPlayers = server.GetCurNumberOfPlayers(); // Check the number of players. - if (curNumPlayers >= (size_t)server.GetGameData().numberOfPlayers) + if (curNumPlayers >= (size_t)server.GetGameData().maxNumberOfPlayers) { server.SessionError(session, ERR_NET_SERVER_FULL); return retVal; diff --git a/src/net/common/serverrecvthread.cpp b/src/net/common/serverrecvthread.cpp index 36814de7..826dbc84 100644 --- a/src/net/common/serverrecvthread.cpp +++ b/src/net/common/serverrecvthread.cpp @@ -261,10 +261,12 @@ ServerRecvThread::InternalStartGame() // Create EngineFactory boost::shared_ptr factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen - // Set dealer pos. + // Set start data. StartData startData; + startData.numberOfPlayers = playerData.size(); + int tmpDealerPos = 0; - Tools::getRandNumber(0, GetGameData().numberOfPlayers-1, 1, &tmpDealerPos, 0); + Tools::getRandNumber(0, startData.numberOfPlayers-1, 1, &tmpDealerPos, 0); // The Player Id is not continuous. Therefore, the start dealer position // needs to be converted to a player Id, and cannot be directly generated // as player Id. diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index 39b4e6f3..e5d43790 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -54,6 +54,7 @@ #define ERR_NET_UNKNOWN_PLAYER_ID 111 #define ERR_NET_INVALID_ROUND 112 #define ERR_NET_PLAYER_KICKED 113 +#define ERR_NET_INVALID_PLAYER_COUNT 114 // This is an internal message which is not reported. #define MSG_SOCK_INTERNAL_PENDING 0 diff --git a/src/session.cpp b/src/session.cpp index ea9cbe9a..5c8c3ca4 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -57,7 +57,7 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat myGui->initGui(gameData.guiSpeed); PlayerDataList playerDataList; - for(int i=0; i