2022-01-24 02:23:08 +00:00
|
|
|
#include "qmlbackend.h"
|
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2022-03-30 06:14:40 +00:00
|
|
|
QCoreApplication *app;
|
|
|
|
QCoreApplication::setApplicationName("FreeKill");
|
|
|
|
QCoreApplication::setApplicationVersion("Alpha 0.0.1");
|
2022-01-24 02:23:08 +00:00
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription("FreeKill server");
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
parser.addOption({{"s", "server"}, "start server at <port>", "port"});
|
2022-03-30 06:14:40 +00:00
|
|
|
QStringList cliOptions;
|
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
cliOptions << argv[i];
|
|
|
|
|
|
|
|
parser.parse(cliOptions);
|
2022-01-24 02:23:08 +00:00
|
|
|
|
|
|
|
bool startServer = parser.isSet("server");
|
|
|
|
ushort serverPort = 9527;
|
|
|
|
|
|
|
|
if (startServer) {
|
2022-03-30 06:14:40 +00:00
|
|
|
app = new QCoreApplication(argc, argv);
|
2022-01-24 02:23:08 +00:00
|
|
|
bool ok = false;
|
|
|
|
if (parser.value("server").toInt(&ok) && ok)
|
|
|
|
serverPort = parser.value("server").toInt();
|
|
|
|
Server *server = new Server;
|
|
|
|
if (!server->listen(QHostAddress::Any, serverPort)) {
|
|
|
|
fprintf(stderr, "cannot listen on port %d!\n", serverPort);
|
2022-03-30 06:14:40 +00:00
|
|
|
app->exit(1);
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
return app->exec();
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 06:14:40 +00:00
|
|
|
app = new QGuiApplication(argc, argv);
|
|
|
|
|
2022-03-27 12:00:29 +00:00
|
|
|
QQmlApplicationEngine *engine = new QQmlApplicationEngine;
|
2022-03-27 06:49:41 +00:00
|
|
|
|
2022-01-24 02:23:08 +00:00
|
|
|
QmlBackend backend;
|
2022-03-27 12:00:29 +00:00
|
|
|
backend.setEngine(engine);
|
2022-03-27 06:49:41 +00:00
|
|
|
|
2022-03-27 12:00:29 +00:00
|
|
|
engine->rootContext()->setContextProperty("Backend", &backend);
|
|
|
|
engine->rootContext()->setContextProperty("AppPath", QUrl::fromLocalFile(QDir::currentPath()));
|
2022-03-23 11:40:28 +00:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
bool debugging = true;
|
|
|
|
#else
|
|
|
|
bool debugging = false;
|
|
|
|
#endif
|
2022-03-27 12:00:29 +00:00
|
|
|
engine->rootContext()->setContextProperty("Debugging", debugging);
|
|
|
|
engine->load("qml/main.qml");
|
2022-01-24 02:23:08 +00:00
|
|
|
|
2022-03-30 06:14:40 +00:00
|
|
|
int ret = app->exec();
|
2022-03-27 12:00:29 +00:00
|
|
|
|
|
|
|
// delete the engine first
|
|
|
|
// to avoid "TypeError: Cannot read property 'xxx' of null"
|
|
|
|
delete engine;
|
|
|
|
|
|
|
|
return ret;
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|