- added crc logging when crc mismatch detected
This commit is contained in:
parent
b08ac7ef9d
commit
d22c10ccda
|
@ -1715,6 +1715,7 @@ void Game::update() {
|
|||
if(index < world.getFactionCount()) {
|
||||
Faction *faction = world.getFaction(index);
|
||||
netIntf->setNetworkPlayerFactionCRC(index,faction->getCRC().getSum());
|
||||
faction->addCRC_DetailsForWorldFrame(world.getFrameCount());
|
||||
}
|
||||
else {
|
||||
netIntf->setNetworkPlayerFactionCRC(index,0);
|
||||
|
@ -2969,10 +2970,12 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
|
|||
faction->getControlType() == ctNetworkCpu ||
|
||||
faction->getControlType() == ctNetworkCpuUltra ||
|
||||
faction->getControlType() == ctNetworkCpuMega)) {
|
||||
//ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||
//if(aiInterfaces[i] == NULL && (slot == NULL || slot->isConnected() == false)) {
|
||||
|
||||
if(aiInterfaces[i] == NULL &&
|
||||
server->isClientConnected(faction->getStartLocationIndex()) == false) {
|
||||
|
||||
DumpCRCWorldLogIfRequired("_faction_" + intToStr(i));
|
||||
|
||||
faction->setFactionDisconnectHandled(true);
|
||||
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
@ -4860,6 +4863,14 @@ void Game::keyPress(SDL_KeyboardEvent c) {
|
|||
Stats Game::quitGame() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
NetworkRole role = networkManager.getNetworkRole();
|
||||
string suffix = "_client";
|
||||
if(role == nrServer) {
|
||||
suffix = "_server";
|
||||
}
|
||||
this->DumpCRCWorldLogIfRequired(suffix);
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
|
||||
world.DumpWorldToLog();
|
||||
}
|
||||
|
@ -4891,11 +4902,81 @@ Stats Game::quitGame() {
|
|||
return endStats;
|
||||
}
|
||||
|
||||
void Game::DumpCRCWorldLogIfRequired(string fileSuffix) {
|
||||
bool isNetworkGame = this->gameSettings.isNetworkGame();
|
||||
|
||||
printf("Check save world CRC to log. isNetworkGame = %d fileSuffix = %s\n",isNetworkGame,fileSuffix.c_str());
|
||||
|
||||
if(isNetworkGame == true) {
|
||||
GameSettings *settings = world.getGameSettingsPtr();
|
||||
if(settings != NULL && (settings->getFlagTypes1() & ft1_network_synch_checks) == ft1_network_synch_checks) {
|
||||
string debugCRCWorldLogFile = Config::getInstance().getString("DebugCRCWorldLogFile","debugCRCWorld.log");
|
||||
debugCRCWorldLogFile += fileSuffix;
|
||||
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
debugCRCWorldLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugCRCWorldLogFile;
|
||||
}
|
||||
else {
|
||||
string userData = Config::getInstance().getString("UserData_Root","");
|
||||
if(userData != "") {
|
||||
endPathWithSlash(userData);
|
||||
}
|
||||
debugCRCWorldLogFile = userData + debugCRCWorldLogFile;
|
||||
}
|
||||
|
||||
printf("Save to log debugCRCWorldLogFile = %s\n",debugCRCWorldLogFile.c_str());
|
||||
|
||||
#if defined(WIN32) && !defined(__MINGW32__)
|
||||
FILE *fp = _wfopen(utf8_decode(debugCRCWorldLogFile).c_str(), L"w");
|
||||
std::ofstream logFile(fp);
|
||||
#else
|
||||
std::ofstream logFile;
|
||||
logFile.open(debugCRCWorldLogFile.c_str(), ios_base::out | ios_base::trunc);
|
||||
#endif
|
||||
logFile << "World CRC debug information:" << std::endl;
|
||||
logFile << "============================" << std::endl;
|
||||
logFile << "Maximum framecount: " << world.getFaction(0)->getCRC_DetailsForWorldFrameCount() << std::endl;
|
||||
|
||||
for(unsigned int worldFrameIndex = 0; worldFrameIndex < world.getFaction(0)->getCRC_DetailsForWorldFrameCount(); ++worldFrameIndex) {
|
||||
//factions (and their related info)
|
||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||
logFile << "Faction detail for index: " << i << std::endl;
|
||||
logFile << "--------------------------" << std::endl;
|
||||
|
||||
std::pair<int,string> details = world.getFaction(i)->getCRC_DetailsForWorldFrameIndex(worldFrameIndex);
|
||||
|
||||
logFile << string("** world frame: ") << details.first << std::endl;
|
||||
logFile << details.second << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
logFile.close();
|
||||
#if defined(WIN32) && !defined(__MINGW32__)
|
||||
if(fp) {
|
||||
fclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::exitGameState(Program *program, Stats &endStats) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
Game *game = dynamic_cast<Game *>(program->getState());
|
||||
|
||||
//printf("game = %p\n",game);
|
||||
|
||||
if(game) {
|
||||
// NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
// NetworkRole role = networkManager.getNetworkRole();
|
||||
// string suffix = "_client";
|
||||
// if(role == nrServer) {
|
||||
// suffix = "_server";
|
||||
// }
|
||||
// game->DumpCRCWorldLogIfRequired(suffix);
|
||||
|
||||
game->setEndGameTeamWinnersAndLosers();
|
||||
game->endGame();
|
||||
}
|
||||
|
|
|
@ -327,6 +327,8 @@ public:
|
|||
|
||||
bool showTranslatedTechTree() const;
|
||||
|
||||
void DumpCRCWorldLogIfRequired(string fileSuffix="");
|
||||
|
||||
private:
|
||||
//render
|
||||
void render3d();
|
||||
|
|
|
@ -1972,12 +1972,14 @@ string Faction::getCacheStats() {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string Faction::toString() const {
|
||||
std::string Faction::toString(bool crcMode) const {
|
||||
std::string result = "FactionIndex = " + intToStr(this->index) + "\n";
|
||||
result += "teamIndex = " + intToStr(this->teamIndex) + "\n";
|
||||
result += "startLocationIndex = " + intToStr(this->startLocationIndex) + "\n";
|
||||
result += "thisFaction = " + intToStr(this->thisFaction) + "\n";
|
||||
result += "control = " + intToStr(this->control) + "\n";
|
||||
if(crcMode == false) {
|
||||
result += "thisFaction = " + intToStr(this->thisFaction) + "\n";
|
||||
result += "control = " + intToStr(this->control) + "\n";
|
||||
}
|
||||
|
||||
if(this->factionType != NULL) {
|
||||
result += this->factionType->toString() + "\n";
|
||||
|
@ -1987,12 +1989,12 @@ std::string Faction::toString() const {
|
|||
|
||||
result += "ResourceCount = " + intToStr(resources.size()) + "\n";
|
||||
for(int idx = 0; idx < resources.size(); idx ++) {
|
||||
result += "index = " + intToStr(idx) + " " + resources[idx].getDescription(false) + "\n";
|
||||
result += "index = " + intToStr(idx) + " " + resources[idx].toString() + "\n";
|
||||
}
|
||||
|
||||
result += "StoreCount = " + intToStr(store.size()) + "\n";
|
||||
for(int idx = 0; idx < store.size(); idx ++) {
|
||||
result += "index = " + intToStr(idx) + " " + store[idx].getDescription(false) + "\n";
|
||||
result += "index = " + intToStr(idx) + " " + store[idx].toString() + "\n";
|
||||
}
|
||||
|
||||
result += "Allies = " + intToStr(allies.size()) + "\n";
|
||||
|
@ -2002,7 +2004,7 @@ std::string Faction::toString() const {
|
|||
|
||||
result += "Units = " + intToStr(units.size()) + "\n";
|
||||
for(int idx = 0; idx < units.size(); idx ++) {
|
||||
result += units[idx]->toString() + "\n";
|
||||
result += units[idx]->toString(crcMode) + "\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -2297,4 +2299,49 @@ Checksum Faction::getCRC() {
|
|||
return crcForFaction;
|
||||
}
|
||||
|
||||
void Faction::addCRC_DetailsForWorldFrame(int worldFrameCount) {
|
||||
const int MAX_FRAME_CACHE = 5000;
|
||||
crcWorldFrameDetails[worldFrameCount] = this->toString(true);
|
||||
//if(worldFrameCount <= 0) printf("Adding world frame: %d log entries: %lld\n",worldFrameCount,(long long int)crcWorldFrameDetails.size());
|
||||
|
||||
if(crcWorldFrameDetails.size() > MAX_FRAME_CACHE) {
|
||||
printf("===> Removing older world frame log entries: %lld\n",(long long int)crcWorldFrameDetails.size());
|
||||
|
||||
for(std::map<int,string>::iterator iterMap = crcWorldFrameDetails.begin();
|
||||
crcWorldFrameDetails.size() - MAX_FRAME_CACHE > 0;) {
|
||||
crcWorldFrameDetails.erase(crcWorldFrameDetails.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string Faction::getCRC_DetailsForWorldFrame(int worldFrameCount) {
|
||||
if(crcWorldFrameDetails.empty()) {
|
||||
return "";
|
||||
}
|
||||
return crcWorldFrameDetails[worldFrameCount];
|
||||
}
|
||||
|
||||
std::pair<int,string> Faction::getCRC_DetailsForWorldFrameIndex(int worldFrameIndex) {
|
||||
if(crcWorldFrameDetails.empty()) {
|
||||
return make_pair<int,string>(0,"");
|
||||
}
|
||||
std::map<int,string>::iterator iterMap = crcWorldFrameDetails.begin();
|
||||
std::advance( iterMap, worldFrameIndex );
|
||||
return make_pair<int,string>(iterMap->first,iterMap->second);
|
||||
}
|
||||
|
||||
string Faction::getCRC_DetailsForWorldFrames() {
|
||||
string result = "";
|
||||
for(std::map<int,string>::iterator iterMap = crcWorldFrameDetails.begin();
|
||||
iterMap != crcWorldFrameDetails.end(); ++iterMap) {
|
||||
result += string("============================================================================\n");
|
||||
result += string("** world frame: ") + intToStr(iterMap->first) + string(" detail: ") + iterMap->second;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64 Faction:: getCRC_DetailsForWorldFrameCount() {
|
||||
return crcWorldFrameDetails.size();
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -169,6 +169,8 @@ private:
|
|||
|
||||
std::vector<string> worldSynchThreadedLogList;
|
||||
|
||||
std::map<int,string> crcWorldFrameDetails;
|
||||
|
||||
public:
|
||||
Faction();
|
||||
~Faction();
|
||||
|
@ -362,7 +364,7 @@ public:
|
|||
string getCacheStats();
|
||||
uint64 getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size);
|
||||
|
||||
std::string toString() const;
|
||||
std::string toString(bool crcMode=false) const;
|
||||
|
||||
void saveGame(XmlNode *rootNode);
|
||||
void loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *settings,World *world);
|
||||
|
@ -370,6 +372,11 @@ public:
|
|||
void clearCaches();
|
||||
|
||||
Checksum getCRC();
|
||||
void addCRC_DetailsForWorldFrame(int worldFrameCount);
|
||||
string getCRC_DetailsForWorldFrame(int worldFrameCount);
|
||||
std::pair<int,string> getCRC_DetailsForWorldFrameIndex(int worldFrameIndex);
|
||||
string getCRC_DetailsForWorldFrames();
|
||||
uint64 getCRC_DetailsForWorldFrameCount();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
|
|
@ -129,6 +129,17 @@ void Resource::loadGame(const XmlNode *rootNode, int index,const TechTree *techT
|
|||
}
|
||||
}
|
||||
|
||||
std::string Resource::toString() const {
|
||||
std::string result = "resource name = " + this->getDescription(false) + "\n";
|
||||
result += "amount = " + intToStr(this->amount) + "\n";
|
||||
result += "type = " + this->type->getName(false) + "\n";
|
||||
result += "type resources per patch = " + intToStr(type->getDefResPerPatch()) + "\n";
|
||||
result += "pos = " + this->pos.getString() + "\n";
|
||||
result += "balance = " + intToStr(this->balance) + "\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Checksum Resource::getCRC() {
|
||||
Checksum crcForResource;
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ public:
|
|||
void saveGame(XmlNode *rootNode) const;
|
||||
void loadGame(const XmlNode *rootNode, int index,const TechTree *techTree);
|
||||
|
||||
std::string toString() const;
|
||||
Checksum getCRC();
|
||||
};
|
||||
|
||||
|
|
|
@ -4039,7 +4039,7 @@ bool Unit::showTranslatedTechTree() const {
|
|||
return (this->game != NULL ? this->game->showTranslatedTechTree() : true);
|
||||
}
|
||||
|
||||
std::string Unit::toString() const {
|
||||
std::string Unit::toString(bool crcMode) const {
|
||||
std::string result = "";
|
||||
|
||||
result += "id = " + intToStr(this->id);
|
||||
|
@ -4051,8 +4051,10 @@ std::string Unit::toString() const {
|
|||
result += "\nFactionIndex = " + intToStr(this->faction->getIndex()) + "\n";
|
||||
result += "teamIndex = " + intToStr(this->faction->getTeam()) + "\n";
|
||||
result += "startLocationIndex = " + intToStr(this->faction->getStartLocationIndex()) + "\n";
|
||||
result += "thisFaction = " + intToStr(this->faction->getThisFaction()) + "\n";
|
||||
result += "control = " + intToStr(this->faction->getControlType()) + "\n";
|
||||
if(crcMode == false) {
|
||||
result += "thisFaction = " + intToStr(this->faction->getThisFaction()) + "\n";
|
||||
result += "control = " + intToStr(this->faction->getControlType()) + "\n";
|
||||
}
|
||||
if(this->faction->getType() != NULL) {
|
||||
result += "factionName = " + this->faction->getType()->getName(false) + "\n";
|
||||
}
|
||||
|
|
|
@ -731,7 +731,7 @@ public:
|
|||
void logSynchData(string file,int line,string source="");
|
||||
void logSynchDataThreaded(string file,int line,string source="");
|
||||
|
||||
std::string toString() const;
|
||||
std::string toString(bool crcMode=false) const;
|
||||
bool needToUpdate();
|
||||
float getProgressAsFloat() const;
|
||||
int64 getUpdateProgress();
|
||||
|
|
Loading…
Reference in New Issue