mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Client: add command line options to simplify multi-instance testing
Use these when you need to run multiple instances of VCMI simultaneously. --testingport is port used to start server. Override port number from configuration files. --testingfileprefix is prefix for auto save filenames. Both options has to be set in order to work.
This commit is contained in:
@@ -170,9 +170,9 @@ static void prog_version(void)
|
||||
static void prog_help(const po::options_description &opts)
|
||||
{
|
||||
printf("%s - A Heroes of Might and Magic 3 clone\n", GameConstants::VCMI_VERSION.c_str());
|
||||
printf("Copyright (C) 2007-2014 VCMI dev team - see AUTHORS file\n");
|
||||
printf("This is free software; see the source for copying conditions. There is NO\n");
|
||||
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
|
||||
printf("Copyright (C) 2007-2016 VCMI dev team - see AUTHORS file\n");
|
||||
printf("This is free software; see the source for copying conditions. There is NO\n");
|
||||
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
|
||||
printf("\n");
|
||||
printf("Usage:\n");
|
||||
std::cout << opts;
|
||||
@@ -244,7 +244,9 @@ int main(int argc, char** argv)
|
||||
("loadhumanplayerindices",po::value<std::vector<int>>(),"Indexes of human players (0=Red, etc.)")
|
||||
("loadplayer", po::value<int>(),"specifies which player we are in multiplayer loaded games (0=Red, etc.)")
|
||||
("loadserverip",po::value<std::string>(),"IP for loaded game server")
|
||||
("loadserverport",po::value<std::string>(),"port for loaded game server");
|
||||
("loadserverport",po::value<std::string>(),"port for loaded game server")
|
||||
("testingport",po::value<std::string>(),"port for testing, override specified in config file")
|
||||
("testingfileprefix",po::value<std::string>(),"prefix for auto save files");
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
@@ -281,7 +283,7 @@ int main(int argc, char** argv)
|
||||
// it may result in very small \ very fast mouse when game in fullscreen mode
|
||||
putenv((char*)"SDL_VIDEO_X11_DGAMOUSE=0");
|
||||
|
||||
// Init old logging system and new (temporary) logging system
|
||||
// Init old logging system and new (temporary) logging system
|
||||
CStopWatch total, pomtime;
|
||||
std::cout.flags(std::ios::unitbuf);
|
||||
console = new CConsoleHandler;
|
||||
@@ -291,16 +293,25 @@ int main(int argc, char** argv)
|
||||
|
||||
const bfs::path logPath = VCMIDirs::get().userCachePath() / "VCMI_Client_log.txt";
|
||||
CBasicLogConfigurator logConfig(logPath, console);
|
||||
logConfig.configureDefault();
|
||||
logConfig.configureDefault();
|
||||
logGlobal->infoStream() << "Creating console and configuring logger: " << pomtime.getDiff();
|
||||
logGlobal->infoStream() << "The log file will be saved to " << logPath;
|
||||
|
||||
// Init filesystem and settings
|
||||
// Init filesystem and settings
|
||||
preinitDLL(::console);
|
||||
settings.init();
|
||||
settings.init();
|
||||
|
||||
// Initialize logging based on settings
|
||||
logConfig.configure();
|
||||
// Init special testing settings
|
||||
Settings testingSettings = settings.write["testing"];
|
||||
if(vm.count("testingport") && vm.count("testingfileprefix"))
|
||||
{
|
||||
testingSettings["enabled"].Bool() = true;
|
||||
testingSettings["port"].String() = vm["testingport"].as<std::string>();
|
||||
testingSettings["prefix"].String() = vm["testingfileprefix"].as<std::string>();
|
||||
}
|
||||
|
||||
// Initialize logging based on settings
|
||||
logConfig.configure();
|
||||
|
||||
// Some basic data validation to produce better error messages in cases of incorrect install
|
||||
auto testFile = [](std::string filename, std::string message) -> bool
|
||||
@@ -308,13 +319,15 @@ int main(int argc, char** argv)
|
||||
if (CResourceHandler::get()->existsResource(ResourceID(filename)))
|
||||
return true;
|
||||
|
||||
logGlobal->errorStream() << "Error: " << message << " was not found!";
|
||||
logGlobal->errorStream() << "Error: " << message << " was not found!";
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!testFile("DATA/HELP.TXT", "Heroes III data") ||
|
||||
!testFile("MODS/VCMI/MOD.JSON", "VCMI data"))
|
||||
!testFile("MODS/VCMI/MOD.JSON", "VCMI data"))
|
||||
{
|
||||
exit(1); // These are unrecoverable errors
|
||||
}
|
||||
|
||||
// these two are optional + some installs have them on CD and not in data directory
|
||||
testFile("VIDEO/GOOD1A.SMK", "campaign movies");
|
||||
|
@@ -157,24 +157,30 @@ void CPlayerInterface::yourTurn()
|
||||
GH.curInt = this;
|
||||
adventureInt->selection = nullptr;
|
||||
|
||||
std::string prefix = "";
|
||||
if(settings["testing"]["enabled"].Bool())
|
||||
{
|
||||
prefix = settings["testing"]["prefix"].String();
|
||||
}
|
||||
|
||||
if(firstCall)
|
||||
{
|
||||
if(howManyPeople == 1)
|
||||
adventureInt->setPlayer(playerID);
|
||||
|
||||
autosaveCount = getLastIndex("Autosave_");
|
||||
autosaveCount = getLastIndex(prefix + "Autosave_");
|
||||
|
||||
if(firstCall > 0) //new game, not loaded
|
||||
{
|
||||
int index = getLastIndex("Newgame_Autosave_");
|
||||
int index = getLastIndex(prefix + "Newgame_");
|
||||
index %= SAVES_COUNT;
|
||||
cb->save("Saves/Newgame_Autosave_" + boost::lexical_cast<std::string>(index + 1));
|
||||
cb->save("Saves/" + prefix + "Newgame_Autosave_" + boost::lexical_cast<std::string>(index + 1));
|
||||
}
|
||||
firstCall = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOCPLINT->cb->save("Saves/Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
|
||||
LOCPLINT->cb->save("Saves/" + prefix + "Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
|
||||
autosaveCount %= 5;
|
||||
}
|
||||
|
||||
|
@@ -246,18 +246,25 @@ void CClient::endGame( bool closeConnection /*= true*/ )
|
||||
#if 1
|
||||
void CClient::loadGame(const std::string & fname, const bool server, const std::vector<int>& humanplayerindices, const int loadNumPlayers, int player_, const std::string & ipaddr, const std::string & port)
|
||||
{
|
||||
PlayerColor player(player_); //intentional shadowing
|
||||
PlayerColor player(player_); //intentional shadowing
|
||||
logNetwork->infoStream() << "Loading procedure started!";
|
||||
|
||||
logNetwork->infoStream() <<"Loading procedure started!";
|
||||
std::string realPort;
|
||||
if(settings["testing"]["enabled"].Bool())
|
||||
realPort = settings["testing"]["port"].String();
|
||||
else if(port.size())
|
||||
realPort = port;
|
||||
else
|
||||
realPort = boost::lexical_cast<std::string>(settings["server"]["port"].Float());
|
||||
|
||||
CServerHandler sh;
|
||||
if(server)
|
||||
sh.startServer();
|
||||
else
|
||||
serv = sh.justConnectToServer(ipaddr,port=="" ? "3030" : port);
|
||||
if(server)
|
||||
sh.startServer();
|
||||
else
|
||||
serv = sh.justConnectToServer(ipaddr, realPort);
|
||||
|
||||
CStopWatch tmh;
|
||||
unique_ptr<CLoadFile> loader;
|
||||
unique_ptr<CLoadFile> loader;
|
||||
try
|
||||
{
|
||||
std::string clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(fname, EResType::CLIENT_SAVEGAME));
|
||||
@@ -967,7 +974,10 @@ CServerHandler::CServerHandler(bool runServer /*= false*/)
|
||||
{
|
||||
serverThread = nullptr;
|
||||
shared = nullptr;
|
||||
port = boost::lexical_cast<std::string>(settings["server"]["port"].Float());
|
||||
if(settings["testing"]["enabled"].Bool())
|
||||
port = settings["testing"]["port"].String();
|
||||
else
|
||||
port = boost::lexical_cast<std::string>(settings["server"]["port"].Float());
|
||||
verbose = true;
|
||||
|
||||
#ifndef VCMI_ANDROID
|
||||
@@ -1009,6 +1019,14 @@ void CServerHandler::callServer()
|
||||
|
||||
CConnection * CServerHandler::justConnectToServer(const std::string &host, const std::string &port)
|
||||
{
|
||||
std::string realPort;
|
||||
if(settings["testing"]["enabled"].Bool())
|
||||
realPort = settings["testing"]["port"].String();
|
||||
else if(port.size())
|
||||
realPort = port;
|
||||
else
|
||||
realPort = boost::lexical_cast<std::string>(settings["server"]["port"].Float());
|
||||
|
||||
CConnection *ret = nullptr;
|
||||
while(!ret)
|
||||
{
|
||||
@@ -1016,7 +1034,7 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const
|
||||
{
|
||||
logNetwork->infoStream() << "Establishing connection...";
|
||||
ret = new CConnection( host.size() ? host : settings["server"]["server"].String(),
|
||||
port.size() ? port : boost::lexical_cast<std::string>(settings["server"]["port"].Float()),
|
||||
realPort,
|
||||
NAME);
|
||||
}
|
||||
catch(...)
|
||||
|
Reference in New Issue
Block a user