It is now possible to start the network game with a player number below the maximum player count.

This commit is contained in:
lotodore
2007-06-11 19:46:18 +00:00
parent 07dc39d107
commit 0d4e38705d
11 changed files with 40 additions and 23 deletions
+2 -2
View File
@@ -61,7 +61,7 @@ Server Reply: Join Game ACK
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Your Player ID | Your Player Number | | Your Player ID | Your Player Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Number of Players | Small Blind | | Max Number of Players | Small Blind |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Hands before raise | Proposed GUI Speed | | Hands before raise | Proposed GUI Speed |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -116,7 +116,7 @@ Server Notification: Game Start
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message Type = 5 | Message Length = 8 | | 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 [ Dealer Pos can be different for each game, therefore it is not
+2 -2
View File
@@ -32,10 +32,10 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
const PlayerDataList &playerDataList, const GameData &gameData, const PlayerDataList &playerDataList, const GameData &gameData,
const StartData &startData, int gameId) const StartData &startData, int gameId)
: myFactory(factory), myGui(gui), actualHand(0), actualBoard(0), : myFactory(factory), myGui(gui), actualHand(0), actualBoard(0),
startQuantityPlayers(gameData.numberOfPlayers), startQuantityPlayers(startData.numberOfPlayers),
startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind), startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind),
startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise),
myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers), myGameID(gameId), actualQuantityPlayers(startData.numberOfPlayers),
actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0)
{ {
// cout << "Create Game Object" << "\n"; // cout << "Create Game Object" << "\n";
+4 -3
View File
@@ -25,9 +25,9 @@
struct GameData struct GameData
{ {
GameData() : numberOfPlayers(0), startMoney(0), smallBlind(0), GameData() : maxNumberOfPlayers(0), startMoney(0), smallBlind(0),
handsBeforeRaise(1), guiSpeed(4), playerActionTimeoutSec(20) {} handsBeforeRaise(1), guiSpeed(4), playerActionTimeoutSec(20) {}
int numberOfPlayers; int maxNumberOfPlayers;
int startMoney; int startMoney;
int smallBlind; int smallBlind;
int handsBeforeRaise; int handsBeforeRaise;
@@ -37,8 +37,9 @@ struct GameData
struct StartData struct StartData
{ {
StartData() : startDealerPlayerId(0) {} StartData() : startDealerPlayerId(0), numberOfPlayers(0) {}
unsigned startDealerPlayerId; unsigned startDealerPlayerId;
int numberOfPlayers;
}; };
#endif #endif
+11 -5
View File
@@ -666,7 +666,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
GameData gameData; GameData gameData;
if(v) { if(v) {
// Set Game Data // Set Game Data
gameData.numberOfPlayers = v->spinBox_quantityPlayers->value(); gameData.maxNumberOfPlayers = v->spinBox_quantityPlayers->value();
gameData.startMoney = v->spinBox_startCash->value(); gameData.startMoney = v->spinBox_startCash->value();
gameData.smallBlind = v->spinBox_smallBlind->value(); gameData.smallBlind = v->spinBox_smallBlind->value();
gameData.handsBeforeRaise = v->spinBox_handsBeforeRaiseSmallBlind->value(); gameData.handsBeforeRaise = v->spinBox_handsBeforeRaiseSmallBlind->value();
@@ -676,7 +676,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
// start with default values // start with default values
else { else {
// Set Game Data // Set Game Data
gameData.numberOfPlayers = myConfig->readConfigInt("NumberOfPlayers"); gameData.maxNumberOfPlayers = myConfig->readConfigInt("NumberOfPlayers");
gameData.startMoney = myConfig->readConfigInt("StartCash"); gameData.startMoney = myConfig->readConfigInt("StartCash");
gameData.smallBlind = myConfig->readConfigInt("SmallBlind"); gameData.smallBlind = myConfig->readConfigInt("SmallBlind");
gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind"); gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind");
@@ -686,7 +686,8 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
// Set dealer pos. // Set dealer pos.
StartData startData; StartData startData;
int tmpDealerPos = 0; 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<unsigned>(tmpDealerPos); startData.startDealerPlayerId = static_cast<unsigned>(tmpDealerPos);
//some gui modifications //some gui modifications
@@ -720,7 +721,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
myServerGuiInterface->getSession().terminateNetworkServer(); myServerGuiInterface->getSession().terminateNetworkServer();
GameData gameData; GameData gameData;
gameData.numberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); gameData.maxNumberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value();
gameData.startMoney = myCreateNetworkGameDialog->spinBox_startCash->value(); gameData.startMoney = myCreateNetworkGameDialog->spinBox_startCash->value();
gameData.smallBlind = myCreateNetworkGameDialog->spinBox_smallBlind->value(); gameData.smallBlind = myCreateNetworkGameDialog->spinBox_smallBlind->value();
gameData.handsBeforeRaise = myCreateNetworkGameDialog->spinBox_handsBeforeRaiseSmallBlind->value(); gameData.handsBeforeRaise = myCreateNetworkGameDialog->spinBox_handsBeforeRaiseSmallBlind->value();
@@ -735,7 +736,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
myServerGuiInterface->getSession().startNetworkServer(gameData); myServerGuiInterface->getSession().startNetworkServer(gameData);
mySession->startNetworkClientForLocalServer(); mySession->startNetworkClientForLocalServer();
myStartNetworkGameDialog->setMaxPlayerNumber(gameData.numberOfPlayers); myStartNetworkGameDialog->setMaxPlayerNumber(gameData.maxNumberOfPlayers);
showServerStartDialog(); showServerStartDialog();
} }
@@ -2513,6 +2514,11 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
tr("You were kicked from the server."), tr("You were kicked from the server."),
QMessageBox::Close); } QMessageBox::Close); }
break; 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"), default: { QMessageBox::warning(this, tr("Network Error"),
tr("An internal error occured."), tr("An internal error occured."),
QMessageBox::Close); } QMessageBox::Close); }
@@ -32,6 +32,7 @@ startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFi
connect( treeWidget, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( playerSelected(QTreeWidgetItem*, int) ) ); connect( treeWidget, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( playerSelected(QTreeWidgetItem*, int) ) );
pushButton_Kick->setEnabled(FALSE); pushButton_Kick->setEnabled(FALSE);
pushButton_startGame->setEnabled(FALSE);
} }
void startNetworkGameDialogImpl::startGame() { void startNetworkGameDialogImpl::startGame() {
@@ -88,8 +89,10 @@ void startNetworkGameDialogImpl::kickPlayer() {
void startNetworkGameDialogImpl::checkPlayerQuantity() { void startNetworkGameDialogImpl::checkPlayerQuantity() {
if(treeWidget->topLevelItemCount() == maxPlayerNumber) pushButton_startGame->setEnabled(TRUE); if (treeWidget->topLevelItemCount() >= 2)
else pushButton_startGame->setDisabled(TRUE); pushButton_startGame->setEnabled(TRUE);
else
pushButton_startGame->setEnabled(FALSE);
} }
+3 -1
View File
@@ -160,6 +160,8 @@ ClientThread::Main()
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen
MapPlayerDataList(); 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++)); m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++));
// Initialize GUI speed. // Initialize GUI speed.
GetGui().initGui(GetGameData().guiSpeed); GetGui().initGui(GetGameData().guiSpeed);
@@ -315,7 +317,7 @@ ClientThread::MapPlayerDataList()
if (numberDiff >= 0) if (numberDiff >= 0)
tmpData->SetNumber(numberDiff); tmpData->SetNumber(numberDiff);
else else
tmpData->SetNumber(GetGameData().numberOfPlayers + numberDiff); tmpData->SetNumber(GetStartData().numberOfPlayers + numberDiff);
mappedList.push_back(tmpData); mappedList.push_back(tmpData);
++i; ++i;
} }
+6 -4
View File
@@ -94,7 +94,7 @@ struct GCC_PACKED NetPacketJoinGameAckData
u_int32_t sessionId; u_int32_t sessionId;
u_int16_t playerId; u_int16_t playerId;
u_int16_t playerNumber; u_int16_t playerNumber;
u_int16_t numberOfPlayers; 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;
@@ -130,7 +130,7 @@ struct GCC_PACKED NetPacketGameStartData
{ {
NetPacketHeader head; NetPacketHeader head;
u_int16_t startDealerPlayerId; u_int16_t startDealerPlayerId;
u_int16_t reserved; u_int16_t numberOfPlayers;
}; };
struct GCC_PACKED NetPacketHandStartData struct GCC_PACKED NetPacketHandStartData
@@ -737,7 +737,7 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData)
tmpData->sessionId = htonl(inData.sessionId); tmpData->sessionId = htonl(inData.sessionId);
tmpData->playerId = htons(inData.yourPlayerUniqueId); tmpData->playerId = htons(inData.yourPlayerUniqueId);
tmpData->playerNumber = htons(inData.yourPlayerNum); tmpData->playerNumber = htons(inData.yourPlayerNum);
tmpData->numberOfPlayers = htons(inData.gameData.numberOfPlayers); 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);
tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed); tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed);
@@ -754,7 +754,7 @@ 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.yourPlayerNum = ntohs(tmpData->playerNumber); 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.smallBlind = ntohs(tmpData->smallBlind);
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise); outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed); outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed);
@@ -973,6 +973,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData)
assert(tmpData); assert(tmpData);
tmpData->startDealerPlayerId = htons(inData.startData.startDealerPlayerId); tmpData->startDealerPlayerId = htons(inData.startData.startDealerPlayerId);
tmpData->numberOfPlayers = htons(inData.startData.numberOfPlayers);
} }
void void
@@ -982,6 +983,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const
assert(tmpData); assert(tmpData);
outData.startData.startDealerPlayerId = ntohs(tmpData->startDealerPlayerId); outData.startData.startDealerPlayerId = ntohs(tmpData->startDealerPlayerId);
outData.startData.numberOfPlayers = ntohs(tmpData->numberOfPlayers);
} }
const NetPacketGameStart * const NetPacketGameStart *
+1 -1
View File
@@ -261,7 +261,7 @@ ServerRecvStateInit::InternalProcess(ServerRecvThread &server, SessionWrapper se
size_t curNumPlayers = server.GetCurNumberOfPlayers(); size_t curNumPlayers = server.GetCurNumberOfPlayers();
// Check the number of players. // 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); server.SessionError(session, ERR_NET_SERVER_FULL);
return retVal; return retVal;
+4 -2
View File
@@ -261,10 +261,12 @@ ServerRecvThread::InternalStartGame()
// Create EngineFactory // Create EngineFactory
boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen boost::shared_ptr<EngineFactory> factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen
// Set dealer pos. // Set start data.
StartData startData; StartData startData;
startData.numberOfPlayers = playerData.size();
int tmpDealerPos = 0; 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 // The Player Id is not continuous. Therefore, the start dealer position
// needs to be converted to a player Id, and cannot be directly generated // needs to be converted to a player Id, and cannot be directly generated
// as player Id. // as player Id.
+1
View File
@@ -54,6 +54,7 @@
#define ERR_NET_UNKNOWN_PLAYER_ID 111 #define ERR_NET_UNKNOWN_PLAYER_ID 111
#define ERR_NET_INVALID_ROUND 112 #define ERR_NET_INVALID_ROUND 112
#define ERR_NET_PLAYER_KICKED 113 #define ERR_NET_PLAYER_KICKED 113
#define ERR_NET_INVALID_PLAYER_COUNT 114
// This is an internal message which is not reported. // This is an internal message which is not reported.
#define MSG_SOCK_INTERNAL_PENDING 0 #define MSG_SOCK_INTERNAL_PENDING 0
+1 -1
View File
@@ -57,7 +57,7 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
myGui->initGui(gameData.guiSpeed); myGui->initGui(gameData.guiSpeed);
PlayerDataList playerDataList; PlayerDataList playerDataList;
for(int i=0; i<gameData.numberOfPlayers; i++) { for(int i = 0; i < startData.numberOfPlayers; i++) {
//Namen und Avatarpfad abfragen //Namen und Avatarpfad abfragen
ostringstream myName; ostringstream myName;