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

View File

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

View File

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

View File

@ -181,58 +181,70 @@ void ClientInterface::updateLobby()
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got NetworkMessageSynchNetworkGameData\n",__FILE__,__FUNCTION__);
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);
}
int32 tilesetCRC = 0;
int32 techCRC = 0;
int32 mapCRC = 0;
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
//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);
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());
}
this->setNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC()));
if(this->getNetworkGameDataSynchCheckOkTile() == false)
{
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());
}
// check the checksum's
//int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_tilesets) + "/" + networkMessageSynchNetworkGameData.getTileset() + "/*", ".xml", NULL);
tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTileset() + string("/*"), ".xml", NULL);
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
//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);
//tech, load before map because of resources
//int32 techCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_techs) + "/" + networkMessageSynchNetworkGameData.getTech() + "/*", ".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)
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC mismatch, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTech() = [%s]\n",
__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameData.getTechCRC(),networkMessageSynchNetworkGameData.getTech().c_str());
}
//if(this->getNetworkGameDataSynchCheckOkTech() == false)
//{
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());
//}
//map
Checksum checksum;
string file = Map::getMapPath(networkMessageSynchNetworkGameData.getMap(),scenarioDir);
checksum.addFile(file);
int32 mapCRC = checksum.getSum();
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),mapCRC);
//map
Checksum checksum;
string file = Map::getMapPath(networkMessageSynchNetworkGameData.getMap(),scenarioDir, false);
if(file != "") {
checksum.addFile(file);
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)
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC mismatch, local = %d, remote = %d, file = [%s]\n",
__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC(),file.c_str());
}
NetworkMessageSynchNetworkGameDataStatus sendNetworkMessageSynchNetworkGameDataStatus(mapCRC,tilesetCRC,techCRC);
sendMessage(&sendNetworkMessageSynchNetworkGameDataStatus);
//if(this->getNetworkGameDataSynchCheckOkMap() == false)
//{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC info, local = %d, remote = %d, file = [%s]\n",__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC(),file.c_str());
//}
}
catch(const runtime_error &ex) {
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;

View File

@ -618,7 +618,7 @@ void Map::computeCellColors(){
}
// static
string Map::getMapPath(const string &mapName, string scenarioDir) {
string Map::getMapPath(const string &mapName, string scenarioDir, bool errorOnNotFound) {
Config &config = Config::getInstance();
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 Vec2i toSurfCoords(Vec2i unitPos) {return unitPos/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:
//compute

View File

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