From 0a2c929fea35d9eef5b563eb37a056f9dcbf477c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 1 Sep 2011 21:54:31 +0000 Subject: [PATCH] - attempt #1 to support 'keeping' connected clients in the lobby when the map changes and slots would normally disconnect --- source/glest_game/game/game_constants.h | 1 + .../menu/menu_state_connected_game.cpp | 57 +++- .../menu/menu_state_custom_game.cpp | 290 +++++++++++++----- .../glest_game/menu/menu_state_custom_game.h | 8 + source/glest_game/network/connection_slot.cpp | 7 + 5 files changed, 275 insertions(+), 88 deletions(-) diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index c6cc2f0c..54ee5f1a 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -53,6 +53,7 @@ enum ControlType { ctCpuUltra, ctCpuMega, ctNetwork, + ctNetworkUnassigned, ctHuman, ctNetworkCpuEasy, diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 196cbe90..e3249303 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -368,6 +368,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM controlItems.push_back(lang.get("CpuUltra")); controlItems.push_back(lang.get("CpuMega")); controlItems.push_back(lang.get("Network")); + controlItems.push_back(lang.get("NetworkUnassigned")); controlItems.push_back(lang.get("Human")); for(int i=0; i<45; ++i){ @@ -749,7 +750,9 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ } if((listBoxControls[i].getSelectedItemIndex() == ctNetwork) && (labelNetStatus[i].getText() == GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)){ - if(grabSlotButton[i].mouseClick(x, y)){ + if(grabSlotButton[i].mouseClick(x, y)) { + //printf("Send slot switch request for slot = %d, myCurrentIndex = %d\n",i,myCurrentIndex); + soundRenderer.playFx(coreData.getClickSoundA()); clientInterface->setGameSettingsReceived(false); settingsReceivedFromServer= false; @@ -922,6 +925,17 @@ void MenuStateConnectedGame::render() { renderer.renderListBox(&listBoxPlayerStatus); for(int i = 0; i < GameConstants::maxPlayers; ++i) { + if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { + //printf("Player #%d [%s] control = %d\n",i,labelPlayerNames[i].getText().c_str(),listBoxControls[i].getSelectedItemIndex()); + + labelPlayers[i].setVisible(true); + labelPlayerNames[i].setVisible(true); + listBoxControls[i].setVisible(true); + listBoxFactions[i].setVisible(true); + listBoxTeams[i].setVisible(true); + labelNetStatus[i].setVisible(true); + } + if(listBoxControls[i].getSelectedItemIndex() != ctClosed) { renderer.renderLabel(&labelPlayerStatus[i]); } @@ -957,13 +971,15 @@ void MenuStateConnectedGame::render() { (labelNetStatus[i].getText() == GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)) { renderer.renderButton(&grabSlotButton[i]); } - else if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) || - (listBoxControls[i].getSelectedItemIndex()==ctHuman)){ + else if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || + listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned || + listBoxControls[i].getSelectedItemIndex() == ctHuman){ renderer.renderLabel(&labelNetStatus[i]); } - if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) || - (listBoxControls[i].getSelectedItemIndex()==ctHuman)){ + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || + listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned || + listBoxControls[i].getSelectedItemIndex() == ctHuman){ if(labelNetStatus[i].getText() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { renderer.renderLabel(&labelPlayerNames[i]); } @@ -1805,6 +1821,7 @@ void MenuStateConnectedGame::update() { int slot = gameSettings->getStartLocationIndex(i); if( gameSettings->getFactionControl(i) == ctNetwork || + //gameSettings->getFactionControl(i) == ctNetworkUnassigned || gameSettings->getFactionControl(i) == ctHuman) { switch(gameSettings->getNetworkPlayerStatuses(i)) { case npst_BeRightBack: @@ -1830,7 +1847,8 @@ void MenuStateConnectedGame::update() { listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData); //listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData); listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),false); - if(gameSettings->getFactionControl(i) == ctNetwork ){ + if( gameSettings->getFactionControl(i) == ctNetwork) { + //gameSettings->getFactionControl(i) == ctNetworkUnassigned) { labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i)); if( gameSettings->getThisFactionIndex() != i && gameSettings->getNetworkPlayerName(i) != "" && @@ -1840,7 +1858,7 @@ void MenuStateConnectedGame::update() { } ControlType ct= gameSettings->getFactionControl(i); - if (ct == ctHuman || ct == ctNetwork || ct == ctClosed) { + if (ct == ctHuman || ct == ctNetwork || ct == ctNetworkUnassigned || ct == ctClosed) { listBoxRMultiplier[slot].setEnabled(false); listBoxRMultiplier[slot].setVisible(false); } else { @@ -1848,8 +1866,9 @@ void MenuStateConnectedGame::update() { listBoxRMultiplier[slot].setVisible(true); } - if(gameSettings->getFactionControl(i) == ctNetwork && - gameSettings->getThisFactionIndex() == i){ + if((gameSettings->getFactionControl(i) == ctNetwork || + gameSettings->getFactionControl(i) == ctNetworkUnassigned) && + gameSettings->getThisFactionIndex() == i) { // set my current slot to ctHuman listBoxControls[slot].setSelectedItemIndex(ctHuman); listBoxFactions[slot].setEditable(true); @@ -2078,18 +2097,26 @@ bool MenuStateConnectedGame::hasNetworkGameSettings() bool hasNetworkSlot = false; try { - for(int i=0; i(listBoxControls[i].getSelectedItemIndex()); - if(ct != ctClosed) - { - if(ct == ctNetwork) - { + if(ct != ctClosed) { + if(ct == ctNetwork || ct == ctNetworkUnassigned) { hasNetworkSlot = true; break; } } } + if(hasNetworkSlot == false) { + for(int i=0; i < GameConstants::maxPlayers; ++i) { + ControlType ct= static_cast(listBoxControls[i].getSelectedItemIndex()); + if(ct != ctClosed) { + if(ct == ctNetworkUnassigned) { + hasNetworkSlot = true; + break; + } + } + } + } } catch(const std::exception &ex) { char szBuf[1024]=""; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 9cb7f9b6..7933f90a 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -452,6 +452,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b controlItems.push_back(lang.get("CpuUltra")); controlItems.push_back(lang.get("CpuMega")); controlItems.push_back(lang.get("Network")); + controlItems.push_back(lang.get("NetworkUnassigned")); controlItems.push_back(lang.get("Human")); for(int i=0; i<45; ++i){ @@ -1371,11 +1372,23 @@ void MenuStateCustomGame::render() { renderer.renderButton(&buttonClearBlockedPlayers); } for(int i = 0; i < GameConstants::maxPlayers; ++i) { + if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { + //printf("Player #%d [%s] control = %d\n",i,labelPlayerNames[i].getText().c_str(),listBoxControls[i].getSelectedItemIndex()); + + labelPlayers[i].setVisible(true); + labelPlayerNames[i].setVisible(true); + listBoxControls[i].setVisible(true); + listBoxFactions[i].setVisible(true); + listBoxTeams[i].setVisible(true); + labelNetStatus[i].setVisible(true); + } + if( hasNetworkGameSettings() == true && listBoxControls[i].getSelectedItemIndex() != ctClosed) { + renderer.renderLabel(&labelPlayerStatus[i]); - if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); if( serverInterface != NULL && serverInterface->getSlot(i) != NULL && @@ -1494,6 +1507,92 @@ void MenuStateCustomGame::render() { } } +void MenuStateCustomGame::switchSetupForSlots(SwitchSetupRequest **switchSetupRequests, + ServerInterface *& serverInterface, int startIndex, int endIndex, bool onlyNetworkUnassigned) { + for(int i= startIndex; i < endIndex; ++i) { + if(switchSetupRequests[i] != NULL) { + //printf("Switch slot = %d\n",i); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getSwitchFlags()); + + if(onlyNetworkUnassigned == true && listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { + continue; + } + + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getToFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getToFactionIndex()); + + if(switchSetupRequests[i]->getToFactionIndex() != -1) { + int newFactionIdx = switchSetupRequests[i]->getToFactionIndex(); + + //printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex()); + int switchFactionIdx = switchSetupRequests[i]->getCurrentFactionIndex(); + if(serverInterface->switchSlot(switchFactionIdx,newFactionIdx)) { + try { + if(switchSetupRequests[i]->getSelectedFactionName() != "") { + listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); + } + if(switchSetupRequests[i]->getToTeam() != -1) { + listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); + } + if(switchSetupRequests[i]->getNetworkPlayerName() != "") { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[newFactionIdx].getText().c_str(),switchSetupRequests[i]->getNetworkPlayerName().c_str()); + labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName()); + } + + if(listBoxControls[switchFactionIdx].getSelectedItemIndex() == ctNetworkUnassigned) { + serverInterface->removeSlot(i); + listBoxControls[switchFactionIdx].setSelectedItemIndex(ctClosed); + + labelPlayers[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players); + labelPlayerNames[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players); + listBoxControls[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players); + listBoxFactions[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players); + listBoxTeams[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players); + labelNetStatus[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players); + } + } + catch(const runtime_error &e) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); + } + } + } + else { + try { + if(switchSetupRequests[i]->getSelectedFactionName() != "") { + listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); + } + if(switchSetupRequests[i]->getToTeam() != -1) { + listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); + } + + if((switchSetupRequests[i]->getSwitchFlags() & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, switchSetupRequests[i]->getSwitchFlags() = %d, switchSetupRequests[i]->getNetworkPlayerName() [%s], labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,switchSetupRequests[i]->getSwitchFlags(),switchSetupRequests[i]->getNetworkPlayerName().c_str(),labelPlayerNames[i].getText().c_str()); + + if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { + labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName()); + } + else { + labelPlayerNames[i].setText(""); + } + //SetActivePlayerNameEditor(); + //switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName); + } + } + catch(const runtime_error &e) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); + } + } + } + + delete switchSetupRequests[i]; + switchSetupRequests[i]=NULL; + } + } +} + void MenuStateCustomGame::update() { Chrono chrono; if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); @@ -1562,70 +1661,74 @@ void MenuStateCustomGame::update() { // handle setting changes from clients SwitchSetupRequest ** switchSetupRequests = serverInterface->getSwitchSetupRequests(); - for(int i= 0; i< mapInfo.players; ++i) { - if(switchSetupRequests[i] != NULL) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getSwitchFlags()); + //!!! + switchSetupForSlots(switchSetupRequests, serverInterface, 0, mapInfo.players, false); + switchSetupForSlots(switchSetupRequests, serverInterface, mapInfo.players, GameConstants::maxPlayers, true); - if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getToFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getToFactionIndex()); - - if(switchSetupRequests[i]->getToFactionIndex() != -1) { - int newFactionIdx = switchSetupRequests[i]->getToFactionIndex(); - - //printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex()); - int switchFactionIdx = switchSetupRequests[i]->getCurrentFactionIndex(); - if(serverInterface->switchSlot(switchFactionIdx,newFactionIdx)) { - try { - if(switchSetupRequests[i]->getSelectedFactionName() != "") { - listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); - } - if(switchSetupRequests[i]->getToTeam() != -1) { - listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); - } - if(switchSetupRequests[i]->getNetworkPlayerName() != "") { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[newFactionIdx].getText().c_str(),switchSetupRequests[i]->getNetworkPlayerName().c_str()); - labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName()); - } - } - catch(const runtime_error &e) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - } - } - } - else { - try { - if(switchSetupRequests[i]->getSelectedFactionName() != "") { - listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); - } - if(switchSetupRequests[i]->getToTeam() != -1) { - listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); - } - - if((switchSetupRequests[i]->getSwitchFlags() & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, switchSetupRequests[i]->getSwitchFlags() = %d, switchSetupRequests[i]->getNetworkPlayerName() [%s], labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,switchSetupRequests[i]->getSwitchFlags(),switchSetupRequests[i]->getNetworkPlayerName().c_str(),labelPlayerNames[i].getText().c_str()); - - if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { - labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName()); - } - else { - labelPlayerNames[i].setText(""); - } - //SetActivePlayerNameEditor(); - //switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName); - } - } - catch(const runtime_error &e) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - } - } - } - - delete switchSetupRequests[i]; - switchSetupRequests[i]=NULL; - } - } +// for(int i= 0; i< mapInfo.players; ++i) { +// if(switchSetupRequests[i] != NULL) { +// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getSwitchFlags()); +// +// if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { +// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getToFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getToFactionIndex()); +// +// if(switchSetupRequests[i]->getToFactionIndex() != -1) { +// int newFactionIdx = switchSetupRequests[i]->getToFactionIndex(); +// +// //printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex()); +// int switchFactionIdx = switchSetupRequests[i]->getCurrentFactionIndex(); +// if(serverInterface->switchSlot(switchFactionIdx,newFactionIdx)) { +// try { +// if(switchSetupRequests[i]->getSelectedFactionName() != "") { +// listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); +// } +// if(switchSetupRequests[i]->getToTeam() != -1) { +// listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); +// } +// if(switchSetupRequests[i]->getNetworkPlayerName() != "") { +// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[newFactionIdx].getText().c_str(),switchSetupRequests[i]->getNetworkPlayerName().c_str()); +// labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName()); +// } +// } +// catch(const runtime_error &e) { +// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); +// } +// } +// } +// else { +// try { +// if(switchSetupRequests[i]->getSelectedFactionName() != "") { +// listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); +// } +// if(switchSetupRequests[i]->getToTeam() != -1) { +// listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); +// } +// +// if((switchSetupRequests[i]->getSwitchFlags() & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) { +// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, switchSetupRequests[i]->getSwitchFlags() = %d, switchSetupRequests[i]->getNetworkPlayerName() [%s], labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,switchSetupRequests[i]->getSwitchFlags(),switchSetupRequests[i]->getNetworkPlayerName().c_str(),labelPlayerNames[i].getText().c_str()); +// +// if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { +// labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName()); +// } +// else { +// labelPlayerNames[i].setText(""); +// } +// //SetActivePlayerNameEditor(); +// //switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName); +// } +// } +// catch(const runtime_error &e) { +// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); +// } +// } +// } +// +// delete switchSetupRequests[i]; +// switchSetupRequests[i]=NULL; +// } +// } if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); @@ -1668,7 +1771,7 @@ void MenuStateCustomGame::update() { } } - if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { hasOneNetworkSlotOpen=true; if(serverInterface->getSlot(i) != NULL && @@ -1967,7 +2070,7 @@ void MenuStateCustomGame::publishToMasterserver() { slotCountUsed++; } - if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { slotCountHumans++; if(serverInterface->getSlot(i) != NULL && @@ -2250,7 +2353,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { gameSettings->setStartLocationIndex(slotIndex, i); - if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { if(serverInterface->getSlot(i) != NULL && serverInterface->getSlot(i)->isConnected()) { @@ -2628,16 +2731,26 @@ bool MenuStateCustomGame::hasNetworkGameSettings() { bool hasNetworkSlot = false; try { - for(int i=0; i(listBoxControls[i].getSelectedItemIndex()); if(ct != ctClosed) { - if(ct == ctNetwork) { + if(ct == ctNetwork || ct == ctNetworkUnassigned) { hasNetworkSlot = true; break; } } } + if(hasNetworkSlot == false) { + for(int i=0; i < GameConstants::maxPlayers; ++i) { + ControlType ct= static_cast(listBoxControls[i].getSelectedItemIndex()); + if(ct != ctClosed) { + if(ct == ctNetworkUnassigned) { + hasNetworkSlot = true; + break; + } + } + } + } } catch(const std::exception &ex) { char szBuf[4096]=""; @@ -2675,7 +2788,19 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa fclose(f); + ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); for(int i = 0; i < GameConstants::maxPlayers; ++i) { + if(serverInterface->getSlot(i) != NULL && + (listBoxControls[i].getSelectedItemIndex() == ctNetwork || + listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned)) { + if(serverInterface->getSlot(i)->isConnected() == true) { + if(i+1 > mapInfo->players && + listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { + listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned); + } + } + } + labelPlayers[i].setVisible(i+1 <= mapInfo->players); labelPlayerNames[i].setVisible(i+1 <= mapInfo->players); listBoxControls[i].setVisible(i+1 <= mapInfo->players); @@ -2785,7 +2910,12 @@ void MenuStateCustomGame::updateControlers() { } for(int i= mapInfo.players; i < GameConstants::maxPlayers; ++i) { - listBoxControls[i].setSelectedItemIndex(ctClosed); + if( listBoxControls[i].getSelectedItemIndex() != ctNetwork && + listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { + //printf("Closed A [%d] [%s]\n",i,labelPlayerNames[i].getText().c_str()); + + listBoxControls[i].setSelectedItemIndex(ctClosed); + } } } catch(const std::exception &ex) { @@ -2800,9 +2930,12 @@ void MenuStateCustomGame::closeUnusedSlots(){ try { ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); for(int i= 0; igetSlot(i) == NULL || serverInterface->getSlot(i)->isConnected() == false) { + //printf("Closed A [%d] [%s]\n",i,labelPlayerNames[i].getText().c_str()); + listBoxControls[i].setSelectedItemIndex(ctClosed); } } @@ -2857,7 +2990,18 @@ void MenuStateCustomGame::updateNetworkSlots() { } if(serverInterface->getSlot(i) != NULL && listBoxControls[i].getSelectedItemIndex() != ctNetwork) { - serverInterface->removeSlot(i); + if(serverInterface->getSlot(i)->isConnected() == true) { + if(listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { + listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned); + } + } + else { + serverInterface->removeSlot(i); + + if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { + listBoxControls[i].setSelectedItemIndex(ctClosed); + } + } } } } diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index bebb38a4..c28f23cb 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -22,6 +22,9 @@ using namespace Shared::Map; namespace Glest { namespace Game { +class SwitchSetupRequest; +class ServerInterface; + // =============================== // class MenuStateCustomGame // =============================== @@ -209,6 +212,11 @@ private: int32 getNetworkPlayerStatus(); void setupUIFromGameSettings(const GameSettings &gameSettings); + + void switchSetupForSlots(SwitchSetupRequest **switchSetupRequests, + ServerInterface *& serverInterface, int startIndex, int endIndex, + bool onlyNetworkUnassigned); + }; }}//end namespace diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 8485e52b..315f9cff 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -708,9 +708,13 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { case nmtSwitchSetupRequest: { + //printf("Got nmtSwitchSetupRequest A\n"); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtSwitchSetupRequest gotIntro = %d\n",__FILE__,__FUNCTION__,__LINE__,gotIntro); if(gotIntro == true) { + //printf("Got nmtSwitchSetupRequest B\n"); + SwitchSetupRequest switchSetupRequest; if(receiveMessage(&switchSetupRequest)) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); @@ -726,6 +730,9 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { this->name = switchSetupRequest.getNetworkPlayerName(); this->playerLanguage = switchSetupRequest.getNetworkPlayerLanguage(); + //printf("Got nmtSwitchSetupRequest C\n"); + //printf("In [%s::%s Line %d] networkPlayerName [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getSwitchSetupRequests()[factionIdx]->getNetworkPlayerName().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] networkPlayerName [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getSwitchSetupRequests()[factionIdx]->getNetworkPlayerName().c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] factionIdx = %d, switchSetupRequest.getNetworkPlayerName() [%s] switchSetupRequest.getNetworkPlayerStatus() = %d, switchSetupRequest.getSwitchFlags() = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdx,switchSetupRequest.getNetworkPlayerName().c_str(),switchSetupRequest.getNetworkPlayerStatus(),switchSetupRequest.getSwitchFlags());