2022-01-24 02:23:08 +00:00
|
|
|
#include "qmlbackend.h"
|
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QGuiApplication::setApplicationName("FreeKill");
|
|
|
|
QGuiApplication::setApplicationVersion("Alpha 0.0.1");
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription("FreeKill server");
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
parser.addOption({{"s", "server"}, "start server at <port>", "port"});
|
|
|
|
parser.process(app);
|
|
|
|
|
|
|
|
bool startServer = parser.isSet("server");
|
|
|
|
ushort serverPort = 9527;
|
|
|
|
|
|
|
|
if (startServer) {
|
|
|
|
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-27 06:49:41 +00:00
|
|
|
app.exit(1);
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
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-27 12:00:29 +00:00
|
|
|
int ret = app.exec();
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|