- 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, ctCpuUltra,
ctCpuMega, ctCpuMega,
ctNetwork, ctNetwork,
ctNetworkUnassigned,
ctHuman, ctHuman,
ctNetworkCpuEasy, ctNetworkCpuEasy,

View File

@ -368,6 +368,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
controlItems.push_back(lang.get("CpuUltra")); controlItems.push_back(lang.get("CpuUltra"));
controlItems.push_back(lang.get("CpuMega")); controlItems.push_back(lang.get("CpuMega"));
controlItems.push_back(lang.get("Network")); controlItems.push_back(lang.get("Network"));
controlItems.push_back(lang.get("NetworkUnassigned"));
controlItems.push_back(lang.get("Human")); controlItems.push_back(lang.get("Human"));
for(int i=0; i<45; ++i){ 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() if((listBoxControls[i].getSelectedItemIndex() == ctNetwork) && (labelNetStatus[i].getText()
== GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)){ == 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()); soundRenderer.playFx(coreData.getClickSoundA());
clientInterface->setGameSettingsReceived(false); clientInterface->setGameSettingsReceived(false);
settingsReceivedFromServer= false; settingsReceivedFromServer= false;
@ -922,6 +925,17 @@ void MenuStateConnectedGame::render() {
renderer.renderListBox(&listBoxPlayerStatus); renderer.renderListBox(&listBoxPlayerStatus);
for(int i = 0; i < GameConstants::maxPlayers; ++i) { 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) { if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
renderer.renderLabel(&labelPlayerStatus[i]); renderer.renderLabel(&labelPlayerStatus[i]);
} }
@ -957,13 +971,15 @@ void MenuStateConnectedGame::render() {
(labelNetStatus[i].getText() == GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)) { (labelNetStatus[i].getText() == GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME)) {
renderer.renderButton(&grabSlotButton[i]); renderer.renderButton(&grabSlotButton[i]);
} }
else if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) || else if(listBoxControls[i].getSelectedItemIndex() == ctNetwork ||
(listBoxControls[i].getSelectedItemIndex()==ctHuman)){ listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned ||
listBoxControls[i].getSelectedItemIndex() == ctHuman){
renderer.renderLabel(&labelNetStatus[i]); renderer.renderLabel(&labelNetStatus[i]);
} }
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) || if(listBoxControls[i].getSelectedItemIndex() == ctNetwork ||
(listBoxControls[i].getSelectedItemIndex()==ctHuman)){ listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned ||
listBoxControls[i].getSelectedItemIndex() == ctHuman){
if(labelNetStatus[i].getText() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { if(labelNetStatus[i].getText() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
renderer.renderLabel(&labelPlayerNames[i]); renderer.renderLabel(&labelPlayerNames[i]);
} }
@ -1805,6 +1821,7 @@ void MenuStateConnectedGame::update() {
int slot = gameSettings->getStartLocationIndex(i); int slot = gameSettings->getStartLocationIndex(i);
if( gameSettings->getFactionControl(i) == ctNetwork || if( gameSettings->getFactionControl(i) == ctNetwork ||
//gameSettings->getFactionControl(i) == ctNetworkUnassigned ||
gameSettings->getFactionControl(i) == ctHuman) { gameSettings->getFactionControl(i) == ctHuman) {
switch(gameSettings->getNetworkPlayerStatuses(i)) { switch(gameSettings->getNetworkPlayerStatuses(i)) {
case npst_BeRightBack: case npst_BeRightBack:
@ -1830,7 +1847,8 @@ void MenuStateConnectedGame::update() {
listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData); listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData);
//listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData); //listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData);
listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),false); 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)); labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i));
if( gameSettings->getThisFactionIndex() != i && if( gameSettings->getThisFactionIndex() != i &&
gameSettings->getNetworkPlayerName(i) != "" && gameSettings->getNetworkPlayerName(i) != "" &&
@ -1840,7 +1858,7 @@ void MenuStateConnectedGame::update() {
} }
ControlType ct= gameSettings->getFactionControl(i); 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].setEnabled(false);
listBoxRMultiplier[slot].setVisible(false); listBoxRMultiplier[slot].setVisible(false);
} else { } else {
@ -1848,8 +1866,9 @@ void MenuStateConnectedGame::update() {
listBoxRMultiplier[slot].setVisible(true); listBoxRMultiplier[slot].setVisible(true);
} }
if(gameSettings->getFactionControl(i) == ctNetwork && if((gameSettings->getFactionControl(i) == ctNetwork ||
gameSettings->getThisFactionIndex() == i){ gameSettings->getFactionControl(i) == ctNetworkUnassigned) &&
gameSettings->getThisFactionIndex() == i) {
// set my current slot to ctHuman // set my current slot to ctHuman
listBoxControls[slot].setSelectedItemIndex(ctHuman); listBoxControls[slot].setSelectedItemIndex(ctHuman);
listBoxFactions[slot].setEditable(true); listBoxFactions[slot].setEditable(true);
@ -2078,18 +2097,26 @@ bool MenuStateConnectedGame::hasNetworkGameSettings()
bool hasNetworkSlot = false; bool hasNetworkSlot = false;
try { 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()); ControlType ct= static_cast<ControlType>(listBoxControls[i].getSelectedItemIndex());
if(ct != ctClosed) if(ct != ctClosed) {
{ if(ct == ctNetwork || ct == ctNetworkUnassigned) {
if(ct == ctNetwork)
{
hasNetworkSlot = true; hasNetworkSlot = true;
break; 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) { catch(const std::exception &ex) {
char szBuf[1024]=""; 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("CpuUltra"));
controlItems.push_back(lang.get("CpuMega")); controlItems.push_back(lang.get("CpuMega"));
controlItems.push_back(lang.get("Network")); controlItems.push_back(lang.get("Network"));
controlItems.push_back(lang.get("NetworkUnassigned"));
controlItems.push_back(lang.get("Human")); controlItems.push_back(lang.get("Human"));
for(int i=0; i<45; ++i){ for(int i=0; i<45; ++i){
@ -1371,11 +1372,23 @@ void MenuStateCustomGame::render() {
renderer.renderButton(&buttonClearBlockedPlayers); renderer.renderButton(&buttonClearBlockedPlayers);
} }
for(int i = 0; i < GameConstants::maxPlayers; ++i) { 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 && if( hasNetworkGameSettings() == true &&
listBoxControls[i].getSelectedItemIndex() != ctClosed) { listBoxControls[i].getSelectedItemIndex() != ctClosed) {
renderer.renderLabel(&labelPlayerStatus[i]); renderer.renderLabel(&labelPlayerStatus[i]);
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
if( serverInterface != NULL && if( serverInterface != NULL &&
serverInterface->getSlot(i) != 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() { void MenuStateCustomGame::update() {
Chrono chrono; Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@ -1562,70 +1661,74 @@ void MenuStateCustomGame::update() {
// handle setting changes from clients // handle setting changes from clients
SwitchSetupRequest ** switchSetupRequests = serverInterface->getSwitchSetupRequests(); SwitchSetupRequest ** switchSetupRequests = serverInterface->getSwitchSetupRequests();
for(int i= 0; i< mapInfo.players; ++i) { //!!!
if(switchSetupRequests[i] != NULL) { switchSetupForSlots(switchSetupRequests, serverInterface, 0, mapInfo.players, false);
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, mapInfo.players, GameConstants::maxPlayers, true);
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { // for(int i= 0; i< mapInfo.players; ++i) {
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] != 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(switchSetupRequests[i]->getToFactionIndex() != -1) { //
int newFactionIdx = switchSetupRequests[i]->getToFactionIndex(); // 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());
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex()); //
int switchFactionIdx = switchSetupRequests[i]->getCurrentFactionIndex(); // if(switchSetupRequests[i]->getToFactionIndex() != -1) {
if(serverInterface->switchSlot(switchFactionIdx,newFactionIdx)) { // int newFactionIdx = switchSetupRequests[i]->getToFactionIndex();
try { //
if(switchSetupRequests[i]->getSelectedFactionName() != "") { // //printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex());
listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); // int switchFactionIdx = switchSetupRequests[i]->getCurrentFactionIndex();
} // if(serverInterface->switchSlot(switchFactionIdx,newFactionIdx)) {
if(switchSetupRequests[i]->getToTeam() != -1) { // try {
listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); // if(switchSetupRequests[i]->getSelectedFactionName() != "") {
} // listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
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()); // if(switchSetupRequests[i]->getToTeam() != -1) {
labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName()); // listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
} // }
} // if(switchSetupRequests[i]->getNetworkPlayerName() != "") {
catch(const runtime_error &e) { // 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());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); // labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName());
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()); // }
} // }
} // catch(const runtime_error &e) {
} // SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
else { // 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());
try { // }
if(switchSetupRequests[i]->getSelectedFactionName() != "") { // }
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName()); // }
} // else {
if(switchSetupRequests[i]->getToTeam() != -1) { // try {
listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam()); // if(switchSetupRequests[i]->getSelectedFactionName() != "") {
} // listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
// }
if((switchSetupRequests[i]->getSwitchFlags() & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) { // if(switchSetupRequests[i]->getToTeam() != -1) {
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()); // listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
// }
if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { //
labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName()); // 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());
else { //
labelPlayerNames[i].setText(""); // if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
} // labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName());
//SetActivePlayerNameEditor(); // }
//switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName); // else {
} // labelPlayerNames[i].setText("");
} // }
catch(const runtime_error &e) { // //SetActivePlayerNameEditor();
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); // //switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName);
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()); // }
} // }
} // 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; // }
} // }
} //
// 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) 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(); 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; hasOneNetworkSlotOpen=true;
if(serverInterface->getSlot(i) != NULL && if(serverInterface->getSlot(i) != NULL &&
@ -1967,7 +2070,7 @@ void MenuStateCustomGame::publishToMasterserver() {
slotCountUsed++; slotCountUsed++;
} }
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned)
{ {
slotCountHumans++; slotCountHumans++;
if(serverInterface->getSlot(i) != NULL && if(serverInterface->getSlot(i) != NULL &&
@ -2250,7 +2353,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setStartLocationIndex(slotIndex, i); gameSettings->setStartLocationIndex(slotIndex, i);
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
if(serverInterface->getSlot(i) != NULL && if(serverInterface->getSlot(i) != NULL &&
serverInterface->getSlot(i)->isConnected()) { serverInterface->getSlot(i)->isConnected()) {
@ -2628,16 +2731,26 @@ bool MenuStateCustomGame::hasNetworkGameSettings() {
bool hasNetworkSlot = false; bool hasNetworkSlot = false;
try { 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()); ControlType ct= static_cast<ControlType>(listBoxControls[i].getSelectedItemIndex());
if(ct != ctClosed) { if(ct != ctClosed) {
if(ct == ctNetwork) { if(ct == ctNetwork || ct == ctNetworkUnassigned) {
hasNetworkSlot = true; hasNetworkSlot = true;
break; 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) { catch(const std::exception &ex) {
char szBuf[4096]=""; char szBuf[4096]="";
@ -2675,7 +2788,19 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa
fclose(f); fclose(f);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
for(int i = 0; i < GameConstants::maxPlayers; ++i) { 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); labelPlayers[i].setVisible(i+1 <= mapInfo->players);
labelPlayerNames[i].setVisible(i+1 <= mapInfo->players); labelPlayerNames[i].setVisible(i+1 <= mapInfo->players);
listBoxControls[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) { 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) { catch(const std::exception &ex) {
@ -2800,9 +2930,12 @@ void MenuStateCustomGame::closeUnusedSlots(){
try { try {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
for(int i= 0; i<mapInfo.players; ++i){ 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 || if(serverInterface->getSlot(i) == NULL ||
serverInterface->getSlot(i)->isConnected() == false) { serverInterface->getSlot(i)->isConnected() == false) {
//printf("Closed A [%d] [%s]\n",i,labelPlayerNames[i].getText().c_str());
listBoxControls[i].setSelectedItemIndex(ctClosed); listBoxControls[i].setSelectedItemIndex(ctClosed);
} }
} }
@ -2857,7 +2990,18 @@ void MenuStateCustomGame::updateNetworkSlots() {
} }
if(serverInterface->getSlot(i) != NULL && if(serverInterface->getSlot(i) != NULL &&
listBoxControls[i].getSelectedItemIndex() != ctNetwork) { 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 { namespace Glest { namespace Game {
class SwitchSetupRequest;
class ServerInterface;
// =============================== // ===============================
// class MenuStateCustomGame // class MenuStateCustomGame
// =============================== // ===============================
@ -209,6 +212,11 @@ private:
int32 getNetworkPlayerStatus(); int32 getNetworkPlayerStatus();
void setupUIFromGameSettings(const GameSettings &gameSettings); void setupUIFromGameSettings(const GameSettings &gameSettings);
void switchSetupForSlots(SwitchSetupRequest **switchSetupRequests,
ServerInterface *& serverInterface, int startIndex, int endIndex,
bool onlyNetworkUnassigned);
}; };
}}//end namespace }}//end namespace

View File

@ -708,9 +708,13 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
case nmtSwitchSetupRequest: 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(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) { if(gotIntro == true) {
//printf("Got nmtSwitchSetupRequest B\n");
SwitchSetupRequest switchSetupRequest; SwitchSetupRequest switchSetupRequest;
if(receiveMessage(&switchSetupRequest)) { if(receiveMessage(&switchSetupRequest)) {
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
@ -726,6 +730,9 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
this->name = switchSetupRequest.getNetworkPlayerName(); this->name = switchSetupRequest.getNetworkPlayerName();
this->playerLanguage = switchSetupRequest.getNetworkPlayerLanguage(); 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::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()); 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());