Ticket #3339: t3339_command_line_option_ooslog_unique_v1.patch

File t3339_command_line_option_ooslog_unique_v1.patch, 2.8 KB (added by elexis, 9 years ago)

Adds the command line switch, updates readme.txt. Add true || to the cit->second != expected check in line 647 of NetTurnManager to trigger an out of sync error, even as the only client on a server.

  • binaries/system/readme.txt

     
    5151-writableRoot       store runtime game data in root data directory
    5252                      (only use if you have write permissions on that directory)
    5353-ooslog             dumps simulation state in binary and ASCII representations each turn,
    5454                      files created in sim_log within the game's log folder. NOTE: game will
    5555                      run much slower with this option!
     56-ooslog-unique      adds unix timestamp and process id to the filename of the out of sync log
     57                     to prevent the file from being overwritten by another process.
    5658-serializationtest  checks simulation state each turn for serialization errors; on test
    5759                      failure, error is displayed and logs created in oos_log within the
    5860                      game's log folder. NOTE: game will run much slower with this option!
    5961
    6062Windows-specific:
  • source/network/NetTurnManager.cpp

     
    2424#include "network/NetMessage.h"
    2525
    2626#include "gui/GUIManager.h"
    2727#include "maths/MathUtil.h"
    2828#include "ps/CLogger.h"
     29#include "ps/GameSetup/CmdLineArgs.h"
    2930#include "ps/Profile.h"
    3031#include "ps/Pyrogenesis.h"
    3132#include "ps/Replay.h"
    3233#include "ps/SavedGame.h"
    3334#include "scriptinterface/ScriptInterface.h"
    3435#include "simulation2/Simulation2.h"
    3536
     37#include<iostream>
     38#include<ctime>
     39
    3640#include <sstream>
    3741#include <fstream>
    3842#include <iomanip>
    3943
     44#if MSC_VERSION
     45#include <process.h>
     46#define getpid _getpid // use the non-deprecated function name
     47#endif
     48
    4049static const int DEFAULT_TURN_LENGTH_MP = 500;
    4150static const int DEFAULT_TURN_LENGTH_SP = 200;
    4251
    4352static const int COMMAND_DELAY = 2;
    4453
     
    228237
    229238    bool quick = !TurnNeedsFullHash(turn);
    230239    std::string hash;
    231240    ENSURE(m_Simulation2.ComputeStateHash(hash, quick));
    232241
    233     OsPath path = psLogDir()/"oos_dump.txt";
     242    std::wstringstream name;
     243    name << L"oos_dump";
     244    if (g_args.Has("ooslog-unique"))
     245        name << L"_" << std::time(0) << L"_" << getpid();
     246    name << L".txt";
     247
     248    OsPath path = psLogDir()/name.str();
    234249    std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);
    235250    m_Simulation2.DumpDebugState(file);
    236251    file.close();
    237252
    238253    hash = Hexify(hash);
  • source/network/NetTurnManager.h

     
    2323
    2424#include <list>
    2525#include <map>
    2626#include <vector>
    2727
     28extern CmdLineArgs g_args;
     29
    2830class CNetServerWorker;
    2931class CNetClient;
    3032class CSimulationMessage;
    3133class CSimulation2;
    3234class IReplayLogger;