mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
Client: server port and testing options cleanup
Now we only pass port as ui16 instead of std::string
This commit is contained in:
parent
4a302d4fe5
commit
6642816b1e
@ -254,9 +254,9 @@ int main(int argc, char** argv)
|
|||||||
("loadplayer", po::value<int>(),"specifies which player we are in multiplayer loaded games (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")
|
("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")
|
("serverport", po::value<si64>(), "override port specified in config file")
|
||||||
("testingfileprefix",po::value<std::string>(),"prefix for auto save files")
|
("saveprefix", po::value<std::string>(), "prefix for auto save files")
|
||||||
("testingsavefrequency",po::value<int>(),"how often auto save should be created");
|
("savefrequency", po::value<si64>(), "limit auto save creation to each N days");
|
||||||
|
|
||||||
if(argc > 1)
|
if(argc > 1)
|
||||||
{
|
{
|
||||||
@ -316,14 +316,10 @@ int main(int argc, char** argv)
|
|||||||
settings.init();
|
settings.init();
|
||||||
|
|
||||||
// Init special testing settings
|
// Init special testing settings
|
||||||
Settings testingSettings = settings.write["testing"];
|
Settings session = settings.write["session"];
|
||||||
if(vm.count("testingport") && vm.count("testingfileprefix"))
|
session["serverport"].Integer() = vm.count("serverport") ? vm["serverport"].as<si64>() : 0;
|
||||||
{
|
session["saveprefix"].String() = vm.count("saveprefix") ? vm["saveprefix"].as<std::string>() : "";
|
||||||
testingSettings["enabled"].Bool() = true;
|
session["savefrequency"].Integer() = vm.count("savefrequency") ? vm["savefrequency"].as<si64>() : 1;
|
||||||
testingSettings["port"].String() = vm["testingport"].as<std::string>();
|
|
||||||
testingSettings["prefix"].String() = vm["testingfileprefix"].as<std::string>();
|
|
||||||
testingSettings["savefrequency"].Float() = vm.count("testingsavefrequency") ? vm["testingsavefrequency"].as<int>() : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize logging based on settings
|
// Initialize logging based on settings
|
||||||
logConfig.configure();
|
logConfig.configure();
|
||||||
@ -1309,7 +1305,7 @@ void startGame(StartInfo * options, CConnection *serv/* = nullptr*/)
|
|||||||
if(!vm.count("loadplayer"))
|
if(!vm.count("loadplayer"))
|
||||||
client->loadGame(fname);
|
client->loadGame(fname);
|
||||||
else
|
else
|
||||||
client->loadGame(fname,vm.count("loadserver"),vm.count("loadhumanplayerindices") ? vm["loadhumanplayerindices"].as<std::vector<int>>() : std::vector<int>(),vm.count("loadnumplayers") ? vm["loadnumplayers"].as<int>() : 1,vm["loadplayer"].as<int>(),vm.count("loadserverip") ? vm["loadserverip"].as<std::string>() : "", vm.count("loadserverport") ? vm["loadserverport"].as<std::string>() : "3030");
|
client->loadGame(fname,vm.count("loadserver"),vm.count("loadhumanplayerindices") ? vm["loadhumanplayerindices"].as<std::vector<int>>() : std::vector<int>(),vm.count("loadnumplayers") ? vm["loadnumplayers"].as<int>() : 1,vm["loadplayer"].as<int>(),vm.count("loadserverip") ? vm["loadserverip"].as<std::string>() : "", vm.count("loadserverport") ? vm["loadserverport"].as<ui16>() : CServerHandler::getDefaultPort());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,12 +171,7 @@ void CPlayerInterface::yourTurn()
|
|||||||
GH.curInt = this;
|
GH.curInt = this;
|
||||||
adventureInt->selection = nullptr;
|
adventureInt->selection = nullptr;
|
||||||
|
|
||||||
std::string prefix = "";
|
std::string prefix = settings["session"]["saveprefix"].String();
|
||||||
if (settings["testing"]["enabled"].Bool())
|
|
||||||
{
|
|
||||||
prefix = settings["testing"]["prefix"].String();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstCall)
|
if (firstCall)
|
||||||
{
|
{
|
||||||
if (howManyPeople == 1)
|
if (howManyPeople == 1)
|
||||||
@ -192,7 +187,7 @@ void CPlayerInterface::yourTurn()
|
|||||||
}
|
}
|
||||||
firstCall = 0;
|
firstCall = 0;
|
||||||
}
|
}
|
||||||
else if (settings["testing"].isNull() || cb->getDate() % static_cast<int>(settings["testing"]["savefrequency"].Float()) == 0)
|
else if (cb->getDate() % static_cast<int>(settings["session"]["savefrequency"].Integer()) == 0)
|
||||||
{
|
{
|
||||||
LOCPLINT->cb->save("Saves/" + prefix + "Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
|
LOCPLINT->cb->save("Saves/" + prefix + "Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
|
||||||
autosaveCount %= 5;
|
autosaveCount %= 5;
|
||||||
|
@ -559,7 +559,7 @@ void CGPreGame::removeFromGui()
|
|||||||
GH.popInt(GH.topInt()); //remove background
|
GH.popInt(GH.topInt()); //remove background
|
||||||
}
|
}
|
||||||
|
|
||||||
CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/, const std::map<ui8, std::string> * Names /*= nullptr*/, const std::string & Address /*=""*/, const std::string & Port /*= ""*/)
|
CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/, const std::map<ui8, std::string> * Names /*= nullptr*/, const std::string & Address /*=""*/, const ui16 Port)
|
||||||
: ISelectionScreenInfo(Names), serverHandlingThread(nullptr), mx(new boost::recursive_mutex),
|
: ISelectionScreenInfo(Names), serverHandlingThread(nullptr), mx(new boost::recursive_mutex),
|
||||||
serv(nullptr), ongoingClosing(false), myNameID(255)
|
serv(nullptr), ongoingClosing(false), myNameID(255)
|
||||||
{
|
{
|
||||||
@ -4320,7 +4320,7 @@ CSimpleJoinScreen::CSimpleJoinScreen(CMenuScreen::EMultiMode mode)
|
|||||||
cancel = new CButton(Point(142, 142), "MUBCANC.DEF", CGI->generaltexth->zelp[561], std::bind(&CGuiHandler::popIntTotally, std::ref(GH), this), SDLK_ESCAPE);
|
cancel = new CButton(Point(142, 142), "MUBCANC.DEF", CGI->generaltexth->zelp[561], std::bind(&CGuiHandler::popIntTotally, std::ref(GH), this), SDLK_ESCAPE);
|
||||||
bar = new CGStatusBar(new CPicture(Rect(7, 186, 218, 18), 0));
|
bar = new CGStatusBar(new CPicture(Rect(7, 186, 218, 18), 0));
|
||||||
|
|
||||||
port->setText(boost::lexical_cast<std::string>(settings["server"]["port"].Float()), true);
|
port->setText(CServerHandler::getDefaultPortStr(), true);
|
||||||
address->setText(settings["server"]["server"].String(), true);
|
address->setText(settings["server"]["server"].String(), true);
|
||||||
address->giveFocus();
|
address->giveFocus();
|
||||||
}
|
}
|
||||||
@ -4332,7 +4332,7 @@ void CSimpleJoinScreen::enterSelectionScreen(CMenuScreen::EMultiMode mode)
|
|||||||
|
|
||||||
GH.popIntTotally(this);
|
GH.popIntTotally(this);
|
||||||
|
|
||||||
GH.pushInt(new CSelectionScreen(CMenuScreen::newGame, mode, nullptr, textAddress, textPort));
|
GH.pushInt(new CSelectionScreen(CMenuScreen::newGame, mode, nullptr, textAddress, boost::lexical_cast<ui16>(textPort)));
|
||||||
}
|
}
|
||||||
void CSimpleJoinScreen::onChange(const std::string & newText)
|
void CSimpleJoinScreen::onChange(const std::string & newText)
|
||||||
{
|
{
|
||||||
|
@ -371,7 +371,7 @@ public:
|
|||||||
bool ongoingClosing;
|
bool ongoingClosing;
|
||||||
ui8 myNameID; //used when networking - otherwise all player are "mine"
|
ui8 myNameID; //used when networking - otherwise all player are "mine"
|
||||||
|
|
||||||
CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER, const std::map<ui8, std::string> * Names = nullptr, const std::string & Address = "", const std::string & Port = "");
|
CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER, const std::map<ui8, std::string> * Names = nullptr, const std::string & Address = "", const ui16 Port = 0);
|
||||||
~CSelectionScreen();
|
~CSelectionScreen();
|
||||||
void toggleTab(CIntObject *tab);
|
void toggleTab(CIntObject *tab);
|
||||||
void changeSelection(const CMapInfo *to);
|
void changeSelection(const CMapInfo *to);
|
||||||
|
@ -251,24 +251,16 @@ void CClient::endGame(bool closeConnection /*= true*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#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)
|
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 ui16 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;
|
CServerHandler sh;
|
||||||
if(server)
|
if(server)
|
||||||
sh.startServer();
|
sh.startServer();
|
||||||
else
|
else
|
||||||
serv = sh.justConnectToServer(ipaddr, realPort);
|
serv = sh.justConnectToServer(ipaddr, port);
|
||||||
|
|
||||||
CStopWatch tmh;
|
CStopWatch tmh;
|
||||||
std::unique_ptr<CLoadFile> loader;
|
std::unique_ptr<CLoadFile> loader;
|
||||||
@ -998,7 +990,6 @@ CConnection * CServerHandler::connectToServer()
|
|||||||
{
|
{
|
||||||
if(!shared->sr->ready)
|
if(!shared->sr->ready)
|
||||||
waitForServer();
|
waitForServer();
|
||||||
port = boost::lexical_cast<std::string>(shared->sr->port);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
waitForServer();
|
waitForServer();
|
||||||
@ -1006,7 +997,11 @@ CConnection * CServerHandler::connectToServer()
|
|||||||
|
|
||||||
th.update(); //put breakpoint here to attach to server before it does something stupid
|
th.update(); //put breakpoint here to attach to server before it does something stupid
|
||||||
|
|
||||||
CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port);
|
#ifndef VCMI_ANDROID
|
||||||
|
CConnection *ret = justConnectToServer(settings["server"]["server"].String(), shared ? shared->sr->port : 0);
|
||||||
|
#else
|
||||||
|
CConnection *ret = justConnectToServer(settings["server"]["server"].String());
|
||||||
|
#endif
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
logNetwork->infoStream()<<"\tConnecting to the server: "<<th.getDiff();
|
logNetwork->infoStream()<<"\tConnecting to the server: "<<th.getDiff();
|
||||||
@ -1014,14 +1009,23 @@ CConnection * CServerHandler::connectToServer()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui16 CServerHandler::getDefaultPort()
|
||||||
|
{
|
||||||
|
if(settings["session"]["serverport"].Integer())
|
||||||
|
return settings["session"]["serverport"].Integer();
|
||||||
|
else
|
||||||
|
return settings["server"]["port"].Integer();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CServerHandler::getDefaultPortStr()
|
||||||
|
{
|
||||||
|
return boost::lexical_cast<std::string>(getDefaultPort());
|
||||||
|
}
|
||||||
|
|
||||||
CServerHandler::CServerHandler(bool runServer /*= false*/)
|
CServerHandler::CServerHandler(bool runServer /*= false*/)
|
||||||
{
|
{
|
||||||
serverThread = nullptr;
|
serverThread = nullptr;
|
||||||
shared = nullptr;
|
shared = nullptr;
|
||||||
if(settings["testing"]["enabled"].Bool())
|
|
||||||
port = settings["testing"]["port"].String();
|
|
||||||
else
|
|
||||||
port = boost::lexical_cast<std::string>(settings["server"]["port"].Float());
|
|
||||||
verbose = true;
|
verbose = true;
|
||||||
|
|
||||||
#ifndef VCMI_ANDROID
|
#ifndef VCMI_ANDROID
|
||||||
@ -1055,7 +1059,7 @@ void CServerHandler::callServer()
|
|||||||
setThreadName("CServerHandler::callServer");
|
setThreadName("CServerHandler::callServer");
|
||||||
const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
|
const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
|
||||||
const std::string comm = VCMIDirs::get().serverPath().string()
|
const std::string comm = VCMIDirs::get().serverPath().string()
|
||||||
+ " --port=" + port
|
+ " --port=" + getDefaultPortStr()
|
||||||
+ " --run-by-client"
|
+ " --run-by-client"
|
||||||
+ (shared ? " --use-shm" : "")
|
+ (shared ? " --use-shm" : "")
|
||||||
+ " > \"" + logName + '\"';
|
+ " > \"" + logName + '\"';
|
||||||
@ -1075,16 +1079,8 @@ void CServerHandler::callServer()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CConnection * CServerHandler::justConnectToServer(const std::string &host, const std::string &port)
|
CConnection * CServerHandler::justConnectToServer(const std::string &host, const ui16 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;
|
CConnection *ret = nullptr;
|
||||||
while(!ret)
|
while(!ret)
|
||||||
{
|
{
|
||||||
@ -1092,7 +1088,7 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const
|
|||||||
{
|
{
|
||||||
logNetwork->infoStream() << "Establishing connection...";
|
logNetwork->infoStream() << "Establishing connection...";
|
||||||
ret = new CConnection( host.size() ? host : settings["server"]["server"].String(),
|
ret = new CConnection( host.size() ? host : settings["server"]["server"].String(),
|
||||||
realPort,
|
port ? port : getDefaultPort(),
|
||||||
NAME);
|
NAME);
|
||||||
ret->connectionID = 1; // TODO: Refactoring for the server so IDs set outside of CConnection
|
ret->connectionID = 1; // TODO: Refactoring for the server so IDs set outside of CConnection
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ public:
|
|||||||
boost::thread *serverThread; //thread that called system to run server
|
boost::thread *serverThread; //thread that called system to run server
|
||||||
SharedMem *shared; //interprocess memory (for waiting for server)
|
SharedMem *shared; //interprocess memory (for waiting for server)
|
||||||
bool verbose; //whether to print log msgs
|
bool verbose; //whether to print log msgs
|
||||||
std::string port; //port number in text form
|
|
||||||
|
|
||||||
//functions setting up local server
|
//functions setting up local server
|
||||||
void startServer(); //creates a thread with callServer
|
void startServer(); //creates a thread with callServer
|
||||||
@ -56,7 +55,9 @@ public:
|
|||||||
CConnection * connectToServer(); //connects to server
|
CConnection * connectToServer(); //connects to server
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
static CConnection * justConnectToServer(const std::string &host = "", const std::string &port = ""); //connects to given host without taking any other actions (like setting up server)
|
static CConnection * justConnectToServer(const std::string &host = "", const ui16 port = 0); //connects to given host without taking any other actions (like setting up server)
|
||||||
|
static ui16 getDefaultPort();
|
||||||
|
static std::string getDefaultPortStr();
|
||||||
|
|
||||||
CServerHandler(bool runServer = false);
|
CServerHandler(bool runServer = false);
|
||||||
virtual ~CServerHandler();
|
virtual ~CServerHandler();
|
||||||
@ -154,7 +155,7 @@ public:
|
|||||||
void endGame(bool closeConnection = true);
|
void endGame(bool closeConnection = true);
|
||||||
void stopConnection();
|
void stopConnection();
|
||||||
void save(const std::string & fname);
|
void save(const std::string & fname);
|
||||||
void loadGame(const std::string & fname, const bool server = true, const std::vector<int>& humanplayerindices = std::vector<int>(), const int loadnumplayers = 1, int player_ = -1, const std::string & ipaddr = "", const std::string & port = "");
|
void loadGame(const std::string & fname, const bool server = true, const std::vector<int>& humanplayerindices = std::vector<int>(), const int loadnumplayers = 1, int player_ = -1, const std::string & ipaddr = "", const ui16 port = 0);
|
||||||
void run();
|
void run();
|
||||||
void campaignMapFinished( std::shared_ptr<CCampaignState> camp );
|
void campaignMapFinished( std::shared_ptr<CCampaignState> camp );
|
||||||
void finishCampaign( std::shared_ptr<CCampaignState> camp );
|
void finishCampaign( std::shared_ptr<CCampaignState> camp );
|
||||||
|
@ -55,7 +55,7 @@ void CSettingsView::loadSettings()
|
|||||||
ui->comboBoxEnemyAI->setCurrentIndex(enemyAIIndex);
|
ui->comboBoxEnemyAI->setCurrentIndex(enemyAIIndex);
|
||||||
ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
|
ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
|
||||||
|
|
||||||
ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Float());
|
ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Integer());
|
||||||
|
|
||||||
ui->comboBoxAutoCheck->setCurrentIndex(settings["launcher"]["autoCheckRepositories"].Bool());
|
ui->comboBoxAutoCheck->setCurrentIndex(settings["launcher"]["autoCheckRepositories"].Bool());
|
||||||
// all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
|
// all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
|
||||||
|
@ -61,14 +61,14 @@ void CConnection::init()
|
|||||||
iser.fileVersion = SERIALIZATION_VERSION;
|
iser.fileVersion = SERIALIZATION_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
CConnection::CConnection(std::string host, std::string port, std::string Name)
|
CConnection::CConnection(std::string host, ui16 port, std::string Name)
|
||||||
:iser(this), oser(this), io_service(new asio::io_service), name(Name)
|
:iser(this), oser(this), io_service(new asio::io_service), name(Name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
boost::system::error_code error = asio::error::host_not_found;
|
boost::system::error_code error = asio::error::host_not_found;
|
||||||
socket = new tcp::socket(*io_service);
|
socket = new tcp::socket(*io_service);
|
||||||
tcp::resolver resolver(*io_service);
|
tcp::resolver resolver(*io_service);
|
||||||
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error);
|
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host, boost::lexical_cast<std::string>(port)),error);
|
||||||
if(error)
|
if(error)
|
||||||
{
|
{
|
||||||
logNetwork->errorStream() << "Problem with resolving: \n" << error;
|
logNetwork->errorStream() << "Problem with resolving: \n" << error;
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
|
|
||||||
bool receivedStop, sendStop;
|
bool receivedStop, sendStop;
|
||||||
|
|
||||||
CConnection(std::string host, std::string port, std::string Name);
|
CConnection(std::string host, ui16 port, std::string Name);
|
||||||
CConnection(TAcceptor * acceptor, boost::asio::io_service *Io_service, std::string Name);
|
CConnection(TAcceptor * acceptor, boost::asio::io_service *Io_service, std::string Name);
|
||||||
CConnection(TSocket * Socket, std::string Name); //use immediately after accepting connection into socket
|
CConnection(TSocket * Socket, std::string Name); //use immediately after accepting connection into socket
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user