1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Attempt to pass lobby parameters as command line arguments

This commit is contained in:
nordsoft 2022-11-07 13:44:58 +04:00
parent 9486373906
commit 7b6d9c23b3
7 changed files with 50 additions and 11 deletions

View File

@ -201,7 +201,8 @@ int main(int argc, char * argv[])
("donotstartserver,d","do not attempt to start server and just connect to it instead server")
("serverport", po::value<si64>(), "override port specified in config file")
("saveprefix", po::value<std::string>(), "prefix for auto save files")
("savefrequency", po::value<si64>(), "limit auto save creation to each N days");
("savefrequency", po::value<si64>(), "limit auto save creation to each N days")
("lobby", po::value<std::array<std::string, 3>>(), "parameters to connect ro remote lobby session");
if(argc > 1)
{
@ -483,6 +484,16 @@ int main(int argc, char * argv[])
session["autoSkip"].Bool() = vm.count("autoSkip");
session["oneGoodAI"].Bool() = vm.count("oneGoodAI");
session["aiSolo"].Bool() = false;
session["lobby"] = false;
if(vm.count("lobby"))
{
auto lobbyParams = vc["lobby"].as<std::array<std::string, 3>>();
session["lobby"].Bool() = true;
session["address"].String() = lobbyParams[0];
session["port"].Integer() = std::stoi(lobbyParams[1]);
session["uuid"].String() = lobbyParams[2];
}
if(vm.count("testmap"))
{

View File

@ -209,11 +209,16 @@ void Lobby::serverCommand(const ServerCommand & command) try
case START: {
protocolAssert(args.size() == 1);
//actually start game
Settings node = settings.write["server"];
node["lobby"].Bool() = true;
//Settings node = settings.write["server"];
gameArguments.clear();
gameArguments << "--lobby";
gameArguments << ui->hostEdit->text();
gameArguments << ui->portEdit->text();
gameArguments << args[0];
/*node["lobby"].Bool() = true;
node["server"].String() = ui->hostEdit->text().toStdString();
node["serverport"].Integer() = ui->portEdit->text().toInt();
node["uuid"].String() = args[0].toStdString();
node["uuid"].String() = args[0].toStdString();*/
startGame = true;
//on_startGameButton_clicked
//node["names"].Vector().clear();
@ -264,7 +269,7 @@ void Lobby::dispatchMessage(QString txt) try
}
if(startGame)
qobject_cast<MainWindow *>(qApp->activeWindow())->on_startGameButton_clicked();
qobject_cast<MainWindow *>(qApp->activeWindow())->startGame(gameArguments);
}
catch(const ProtocolError & e)
{

View File

@ -131,6 +131,7 @@ private:
QString session;
QString username;
bool startGame = false;
QStringList gameArguments;
private:
void protocolAssert(bool);

View File

@ -24,6 +24,8 @@ int main(int argc, char * argv[])
int result;
#ifdef VCMI_IOS
{
__argc = argc;
__argv = argv;
#endif
QApplication vcmilauncher(argc, argv);
MainWindow mainWindow;
@ -32,7 +34,7 @@ int main(int argc, char * argv[])
#ifdef VCMI_IOS
}
if (result == 0)
launchGame(argc, argv);
launchGame(__argc, __argv);
#endif
return result;
}

View File

@ -9,6 +9,9 @@
*/
#pragma once
inline int __argc;
inline char ** __argv;
#ifdef VCMI_IOS
extern "C" void launchGame(int argc, char * argv[]);
#endif

View File

@ -20,6 +20,7 @@
#include "../lib/logging/CBasicLogConfigurator.h"
#include "updatedialog_moc.h"
#include "main.h"
void MainWindow::load()
{
@ -112,22 +113,36 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::on_startGameButton_clicked()
void MainWindow::startGame(const QStringList & args)
{
__argc = args.size();
__argv = new char*[__argc];
for(int i = 0; i < __argc; ++i)
{
const char * s = args[i].toLocal8Bit().constData();
__argv[i] = new char[strlen(s)];
strcpy(__argv[i], s);
}
#ifdef Q_OS_IOS
qApp->quit();
#else
startExecutable(pathToQString(VCMIDirs::get().clientPath()));
startExecutable(pathToQString(VCMIDirs::get().clientPath()), args);
#endif
}
void MainWindow::on_startGameButton_clicked()
{
startGame({});
}
#ifndef Q_OS_IOS
void MainWindow::startExecutable(QString name)
void MainWindow::startExecutable(QString name, const QStringList & args)
{
QProcess process;
// Start the executable
if(process.startDetached(name, {}))
if(process.startDetached(name, args))
{
close(); // exit launcher
}

View File

@ -28,12 +28,14 @@ private:
Ui::MainWindow * ui;
void load();
#ifndef Q_OS_IOS
void startExecutable(QString name);
void startExecutable(QString name, const QStringList & args);
#endif
public:
explicit MainWindow(QWidget * parent = 0);
~MainWindow();
void startGame(const QStringList & args);
public slots:
void on_startGameButton_clicked();