-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (45 loc) · 1.42 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <QCoreApplication>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include "observer.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("Snake client");
QCoreApplication::setApplicationVersion("0.2");
QCommandLineParser parser;
parser.setApplicationDescription("Basic snake client (observe only)");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption addressOpt(QStringList() << "a" << "address",
"Server address", "address", "127.0.0.1");
parser.addOption(addressOpt);
QCommandLineOption portOpt(QStringList() << "p" << "port",
"Server port", "port", "9898");
parser.addOption(portOpt);
parser.process(a);
QHostAddress address = QHostAddress::LocalHost;
quint16 port = 9898;
if (parser.isSet(addressOpt))
{
address = QHostAddress(parser.value(addressOpt));
if (address.isNull())
{
qDebug() << "Can't parse address" << parser.value(addressOpt);
return 1;
}
}
if (parser.isSet(portOpt))
{
bool ok = false;
port = parser.value(portOpt).toUShort(&ok);
if (!ok)
{
qDebug() << "Can't parse port" << parser.value(portOpt);
return 2;
}
}
auto observer = new Observer();
observer->connectTo(address, port);
return a.exec();
}