- attempt #1 to support 'keeping' connected clients in the lobby when the map changes and slots would normally disconnect

This commit is contained in:
Mark Vejvoda 2011-09-01 21:54:31 +00:00
parent 4a5a7f010d
commit 0a2c929fea
5 changed files with 275 additions and 88 deletions

View File

@ -53,6 +53,7 @@ enum ControlType {
ctCpuUltra,
ctCpuMega,
ctNetwork,
ctNetworkUnassigned,
ctHuman,
ctNetworkCpuEasy,

View File

@ -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<mapInfo.players; ++i)
{
for(int i=0; i<mapInfo.players; ++i) {
ControlType ct= static_cast<ControlType>(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<ControlType>(listBoxControls[i].getSelectedItemIndex());
if(ct != ctClosed) {
if(ct == ctNetworkUnassigned) {
hasNetworkSlot = true;
break;
}
}
}
}
}
catch(const std::exception &ex) {
char szBuf[1024]="";

View File

@ -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<mapInfo.players; ++i)
{
for(int i=0; i<mapInfo.players; ++i) {
ControlType ct= static_cast<ControlType>(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<ControlType>(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; i<mapInfo.players; ++i){
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork){
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork ||
listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
if(serverInterface->getSlot(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);
}
}
}
}
}

View File

@ -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

View File

@ -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());