Added more guards and debug info related to network play

This commit is contained in:
Mark Vejvoda
2010-04-29 07:59:44 +00:00
parent 805015fd83
commit 4f147b2d89
9 changed files with 140 additions and 92 deletions

Binary file not shown.

View File

@@ -128,8 +128,8 @@ void GraphicListBox::setItems(const vector<string> &items){
setSelectedItemIndex(0); setSelectedItemIndex(0);
} }
void GraphicListBox::setSelectedItemIndex(int index){ void GraphicListBox::setSelectedItemIndex(int index, bool errorOnMissing){
assert(index>=0 && index<items.size()); if(errorOnMissing == true) assert(index>=0 && index<items.size());
selectedItemIndex= index; selectedItemIndex= index;
setText(getSelectedItem()); setText(getSelectedItem());
} }
@@ -140,13 +140,15 @@ void GraphicListBox::setEditable(bool editable){
GraphicComponent::setEditable(editable); GraphicComponent::setEditable(editable);
} }
void GraphicListBox::setSelectedItem(string item){ void GraphicListBox::setSelectedItem(string item, bool errorOnMissing){
vector<string>::iterator iter; vector<string>::iterator iter;
iter= find(items.begin(), items.end(), item); iter= find(items.begin(), items.end(), item);
if(iter==items.end()){ if(iter==items.end()) {
throw runtime_error("Value not found on list box: "+item); if(errorOnMissing == true) {
throw runtime_error("Value not found on list box: "+item);
}
} }
else { else {
setSelectedItemIndex(iter-items.begin()); setSelectedItemIndex(iter-items.begin());

View File

@@ -142,8 +142,8 @@ public:
void pushBackItem(string item); void pushBackItem(string item);
void setItems(const vector<string> &items); void setItems(const vector<string> &items);
void setSelectedItemIndex(int index); void setSelectedItemIndex(int index, bool errorOnMissing=true);
void setSelectedItem(string item); void setSelectedItem(string item, bool errorOnMissing=true);
void setEditable(bool editable); void setEditable(bool editable);
virtual bool mouseMove(int x, int y); virtual bool mouseMove(int x, int y);

View File

@@ -464,6 +464,7 @@ void MenuStateConnectedGame::update()
if(clientInterface->isConnected()) if(clientInterface->isConnected())
{ {
if(clientInterface->getGameSettingsReceived()){ if(clientInterface->getGameSettingsReceived()){
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
vector<string> maps,tilesets,techtree; vector<string> maps,tilesets,techtree;
const GameSettings *gameSettings=clientInterface->getGameSettings(); const GameSettings *gameSettings=clientInterface->getGameSettings();
@@ -477,20 +478,25 @@ void MenuStateConnectedGame::update()
listBoxTechTree.setItems(techtree); listBoxTechTree.setItems(techtree);
// factions // factions
if(currentFactionName!=gameSettings->getTech()) bool hasFactions = true;
if(currentFactionName != gameSettings->getTech())
{ {
currentFactionName=gameSettings->getTech(); currentFactionName = gameSettings->getTech();
loadFactions(gameSettings); hasFactions = loadFactions(gameSettings);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] hasFactions = %d\n",__FILE__,__FUNCTION__,__LINE__,hasFactions);
// map // map
maps.push_back(formatString(gameSettings->getMap())); maps.push_back(formatString(gameSettings->getMap()));
listBoxMap.setItems(maps); listBoxMap.setItems(maps);
if(currentMap!=gameSettings->getMap()) if(currentMap != gameSettings->getMap())
{// load the setup again {// load the setup again
currentMap=gameSettings->getMap(); currentMap = gameSettings->getMap();
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// FogOfWar // FogOfWar
if(gameSettings->getFogOfWar()){ if(gameSettings->getFogOfWar()){
listBoxFogOfWar.setSelectedItemIndex(0); listBoxFogOfWar.setSelectedItemIndex(0);
@@ -499,7 +505,9 @@ void MenuStateConnectedGame::update()
{ {
listBoxFogOfWar.setSelectedItemIndex(1); listBoxFogOfWar.setSelectedItemIndex(1);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Control // Control
for(int i=0; i<GameConstants::maxPlayers; ++i){ for(int i=0; i<GameConstants::maxPlayers; ++i){
listBoxControls[i].setSelectedItemIndex(ctClosed); listBoxControls[i].setSelectedItemIndex(ctClosed);
@@ -507,25 +515,30 @@ void MenuStateConnectedGame::update()
listBoxTeams[i].setEditable(false); listBoxTeams[i].setEditable(false);
} }
for(int i=0; i<gameSettings->getFactionCount(); ++i){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
int slot=gameSettings->getStartLocationIndex(i);
listBoxControls[slot].setSelectedItemIndex(gameSettings->getFactionControl(i));
listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i));
listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)));
if(gameSettings->getFactionControl(i) == ctNetwork ){ if(hasFactions == true) {
labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i)); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i=0; i<gameSettings->getFactionCount(); ++i){
int slot=gameSettings->getStartLocationIndex(i);
listBoxControls[slot].setSelectedItemIndex(gameSettings->getFactionControl(i),errorOnMissingData);
listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData);
listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData);
if(gameSettings->getFactionControl(i) == ctNetwork ){
labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i));
}
if(gameSettings->getFactionControl(i) == ctNetwork && gameSettings->getThisFactionIndex() == i){
// set my current slot to ctHuman
listBoxControls[slot].setSelectedItemIndex(ctHuman);
listBoxFactions[slot].setEditable(true);
listBoxTeams[slot].setEditable(true);
}
settingsReceivedFromServer=true;
} }
if(gameSettings->getFactionControl(i) == ctNetwork && gameSettings->getThisFactionIndex() == i){
// set my current slot to ctHuman
listBoxControls[slot].setSelectedItemIndex(ctHuman);
listBoxFactions[slot].setEditable(true);
listBoxTeams[slot].setEditable(true);
}
settingsReceivedFromServer=true;
} }
} }
//update lobby //update lobby
@@ -566,7 +579,7 @@ void MenuStateConnectedGame::update()
} }
void MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
vector<string> results; vector<string> results;
@@ -584,24 +597,32 @@ void MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){
} }
if(results.size() == 0) { if(results.size() == 0) {
throw runtime_error("(2)There are no factions for the tech tree [" + gameSettings->getTech() + "]"); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
factionFiles= results;
for(int i= 0; i<results.size(); ++i){
results[i]= formatString(results[i]);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"Tech [%s] has faction [%s]\n",gameSettings->getTech().c_str(),results[i].c_str()); NetworkManager &networkManager= NetworkManager::getInstance();
} ClientInterface* clientInterface= networkManager.getClientInterface();
for(int i=0; i<GameConstants::maxPlayers; ++i){ if(clientInterface->getAllowGameDataSynchCheck() == false) {
listBoxFactions[i].setItems(results); throw runtime_error("(2)There are no factions for the tech tree [" + gameSettings->getTech() + "]");
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
else {
factionFiles= results;
for(int i= 0; i<results.size(); ++i){
results[i]= formatString(results[i]);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"Tech [%s] has faction [%s]\n",gameSettings->getTech().c_str(),results[i].c_str());
}
for(int i=0; i<GameConstants::maxPlayers; ++i){
listBoxFactions[i].setItems(results);
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return (results.size() > 0);
} }
// ============ PRIVATE =========================== // ============ PRIVATE ===========================
bool MenuStateConnectedGame::hasNetworkGameSettings() bool MenuStateConnectedGame::hasNetworkGameSettings()
@@ -639,6 +660,8 @@ void MenuStateConnectedGame::reloadFactions(){
Config &config = Config::getInstance(); Config &config = Config::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
vector<string> techPaths = config.getPathListForType(ptTechs); vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) { for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx]; string &techPath = techPaths[idx];
@@ -649,6 +672,8 @@ void MenuStateConnectedGame::reloadFactions(){
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(results.size() == 0) { if(results.size() == 0) {
throw runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]"); throw runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
} }
@@ -658,11 +683,15 @@ void MenuStateConnectedGame::reloadFactions(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"Tech [%s] has faction [%s]\n",techTreeFiles[listBoxTechTree.getSelectedItemIndex()].c_str(),results[i].c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"Tech [%s] has faction [%s]\n",techTreeFiles[listBoxTechTree.getSelectedItemIndex()].c_str(),results[i].c_str());
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i=0; i<GameConstants::maxPlayers; ++i){ for(int i=0; i<GameConstants::maxPlayers; ++i){
listBoxFactions[i].setItems(results); listBoxFactions[i].setItems(results);
listBoxFactions[i].setSelectedItemIndex(i % results.size()); listBoxFactions[i].setSelectedItemIndex(i % results.size());
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }

View File

@@ -78,7 +78,7 @@ private:
bool hasNetworkGameSettings(); bool hasNetworkGameSettings();
void reloadFactions(); void reloadFactions();
void loadFactions(const GameSettings *gameSettings); bool loadFactions(const GameSettings *gameSettings);
}; };
}}//end namespace }}//end namespace

View File

@@ -181,58 +181,70 @@ void ClientInterface::updateLobby()
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__);
Config &config = Config::getInstance(); int32 tilesetCRC = 0;
string scenarioDir = ""; int32 techCRC = 0;
if(gameSettings.getScenarioDir() != "") { int32 mapCRC = 0;
scenarioDir = gameSettings.getScenarioDir();
if(EndsWith(scenarioDir, ".xml") == true) {
scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4);
scenarioDir = scenarioDir.erase(scenarioDir.size() - gameSettings.getScenario().size(), gameSettings.getScenario().size() + 1);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getScenarioDir().c_str(),gameSettings.getScenario().c_str(),scenarioDir.c_str()); try {
} Config &config = Config::getInstance();
string scenarioDir = "";
if(gameSettings.getScenarioDir() != "") {
scenarioDir = gameSettings.getScenarioDir();
if(EndsWith(scenarioDir, ".xml") == true) {
scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4);
scenarioDir = scenarioDir.erase(scenarioDir.size() - gameSettings.getScenario().size(), gameSettings.getScenario().size() + 1);
}
// check the checksum's SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getScenarioDir().c_str(),gameSettings.getScenario().c_str(),scenarioDir.c_str());
//int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_tilesets) + "/" + networkMessageSynchNetworkGameData.getTileset() + "/*", ".xml", NULL); }
int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTileset() + string("/*"), ".xml", NULL);
this->setNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC())); // check the checksum's
if(this->getNetworkGameDataSynchCheckOkTile() == false) //int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_tilesets) + "/" + networkMessageSynchNetworkGameData.getTileset() + "/*", ".xml", NULL);
{ tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTileset() + string("/*"), ".xml", NULL);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] tilesetCRC mismatch, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTileset() = [%s]\n",
__FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC(),networkMessageSynchNetworkGameData.getTileset().c_str()); this->setNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC()));
} //if(this->getNetworkGameDataSynchCheckOkTile() == false)
//{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] tilesetCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTileset() = [%s]\n",__FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC(),networkMessageSynchNetworkGameData.getTileset().c_str());
//}
//tech, load before map because of resources //tech, load before map because of resources
//int32 techCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_techs) + "/" + networkMessageSynchNetworkGameData.getTech() + "/*", ".xml", NULL); //int32 techCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_techs) + "/" + networkMessageSynchNetworkGameData.getTech() + "/*", ".xml", NULL);
int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTech() + string("/*"), ".xml", NULL); techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTech() + string("/*"), ".xml", NULL);
this->setNetworkGameDataSynchCheckOkTech((techCRC == networkMessageSynchNetworkGameData.getTechCRC())); this->setNetworkGameDataSynchCheckOkTech((techCRC == networkMessageSynchNetworkGameData.getTechCRC()));
if(this->getNetworkGameDataSynchCheckOkTech() == false) //if(this->getNetworkGameDataSynchCheckOkTech() == false)
{ //{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC mismatch, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTech() = [%s]\n", SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTech() = [%s]\n",__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameData.getTechCRC(),networkMessageSynchNetworkGameData.getTech().c_str());
__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameData.getTechCRC(),networkMessageSynchNetworkGameData.getTech().c_str()); //}
}
//map //map
Checksum checksum; Checksum checksum;
string file = Map::getMapPath(networkMessageSynchNetworkGameData.getMap(),scenarioDir); string file = Map::getMapPath(networkMessageSynchNetworkGameData.getMap(),scenarioDir, false);
checksum.addFile(file); if(file != "") {
int32 mapCRC = checksum.getSum(); checksum.addFile(file);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),mapCRC); mapCRC = checksum.getSum();
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),mapCRC);
this->setNetworkGameDataSynchCheckOkMap((mapCRC == networkMessageSynchNetworkGameData.getMapCRC())); this->setNetworkGameDataSynchCheckOkMap((mapCRC == networkMessageSynchNetworkGameData.getMapCRC()));
if(this->getNetworkGameDataSynchCheckOkMap() == false) //if(this->getNetworkGameDataSynchCheckOkMap() == false)
{ //{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC mismatch, local = %d, remote = %d, file = [%s]\n", SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC info, local = %d, remote = %d, file = [%s]\n",__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC(),file.c_str());
__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC(),file.c_str()); //}
} }
NetworkMessageSynchNetworkGameDataStatus sendNetworkMessageSynchNetworkGameDataStatus(mapCRC,tilesetCRC,techCRC); catch(const runtime_error &ex) {
sendMessage(&sendNetworkMessageSynchNetworkGameDataStatus); string sErr = ex.what();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] error during processing, sErr = [%s]\n",__FILE__,__FUNCTION__,sErr.c_str());
DisplayErrorMessage(sErr);
}
NetworkMessageSynchNetworkGameDataStatus sendNetworkMessageSynchNetworkGameDataStatus(mapCRC,tilesetCRC,techCRC);
sendMessage(&sendNetworkMessageSynchNetworkGameDataStatus);
} }
} }
break; break;

View File

@@ -618,7 +618,7 @@ void Map::computeCellColors(){
} }
// static // static
string Map::getMapPath(const string &mapName, string scenarioDir) { string Map::getMapPath(const string &mapName, string scenarioDir, bool errorOnNotFound) {
Config &config = Config::getInstance(); Config &config = Config::getInstance();
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir); vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
@@ -635,7 +635,11 @@ string Map::getMapPath(const string &mapName, string scenarioDir) {
} }
} }
throw runtime_error("Map [" + mapName + "] not found, scenarioDir [" + scenarioDir + "]"); if(errorOnNotFound == true) {
throw runtime_error("Map [" + mapName + "] not found, scenarioDir [" + scenarioDir + "]");
}
return "";
} }
// ===================================================== // =====================================================

View File

@@ -224,7 +224,7 @@ public:
//static //static
static Vec2i toSurfCoords(Vec2i unitPos) {return unitPos/cellScale;} static Vec2i toSurfCoords(Vec2i unitPos) {return unitPos/cellScale;}
static Vec2i toUnitCoords(Vec2i surfPos) {return surfPos*cellScale;} static Vec2i toUnitCoords(Vec2i surfPos) {return surfPos*cellScale;}
static string getMapPath(const string &mapName, string scenarioDir=""); static string getMapPath(const string &mapName, string scenarioDir="", bool errorOnNotFound=true);
private: private:
//compute //compute

View File

@@ -52,11 +52,12 @@ void Checksum::addString(const string &value){
} }
void Checksum::addFile(const string &path){ void Checksum::addFile(const string &path){
fileList[path] = 0; if(path != "") {
fileList[path] = 0;
}
} }
void Checksum::addFileToSum(const string &path){ void Checksum::addFileToSum(const string &path){
FILE* file= fopen(path.c_str(), "rb"); FILE* file= fopen(path.c_str(), "rb");
if(file!=NULL){ if(file!=NULL){