-
Notifications
You must be signed in to change notification settings - Fork 35
/
mainwindow.cpp
192 lines (166 loc) · 4.55 KB
/
mainwindow.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "ui_mainwindow.h"
#include "mainwindow.h"
#include "customitems.h"
#include "settings.h"
#include <QKeyEvent>
#include <QTimer>
extern Settings *settings;
extern QList<ServerInfo *> serverList;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
pPlayerQuery = NULL;
pRulesQuery = NULL;
ui->setupUi(this);
setWindowTitle("Source Admin Tool");
commandIter = new QMutableListIterator<QString>(this->commandHistory);
commandIterDirection = kIterInit;
sayIter = new QMutableListIterator<QString>(this->sayHistory);
sayIterDirection = kIterInit;
this->ui->commandOutput->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
this->SetRconEnabled(false);
settings = new Settings(this);
settings->SetDefaultSettings();
settings->ReadSettings();
settings->GetCtxCommands();
pLogHandler = new LogHandler(this);
pLogHandler->createBind(u16logPort);
if(this->ui->browserTable->rowCount() > 0)
{
this->ui->browserTable->selectRow(0);
this->browserTableItemSelected();
this->SetRconEnabled(true);
this->SetRconSignals(true);
this->RestoreRcon(0);
this->SetRconSignals(false);
}
this->HookEvents();
this->ConnectSlots();
this->updateTimer = new QTimer(this);
connect(this->updateTimer, &QTimer::timeout, this, &MainWindow::TimedUpdate);
this->updateTimer->start(1000);
}
MainWindow::~MainWindow()
{
delete settings;
serverList.clear();
delete ui;
delete pLogHandler;
delete sayIter;
delete commandIter;
}
AddServerError MainWindow::CheckServerList(QString server)
{
QStringList address = server.split(":");
bool ok;
if(address.size() == 1)
{
address.append("27015");
}
else if (address.size() != 2)
{
return AddServerError_Invalid;
}
QString ip = address.at(0);
quint16 port = address.at(1).toInt(&ok);
QHostAddress addr;
AddServerError ret = AddServerError_None;
if(!port || !ok)
{
return AddServerError_Invalid;
}
else if(!addr.setAddress(ip))
{
//Check if it is a hostname
QUrl url = QUrl::fromUserInput(ip);
if(url != QUrl())
{
ret = AddServerError_Hostname;
}
else
{
return AddServerError_Invalid;
}
}
for(int i = 0; i < serverList.size(); i++)
{
//Check if the ip or hostname already exists.
if(serverList.at(i)->hostPort == server)
{
return AddServerError_AlreadyExists;
}
}
return ret;
}
ServerInfo *MainWindow::AddServerToList(QString server, AddServerError *pError)
{
AddServerError error = CheckServerList(server);
if(pError != nullptr)
{
*pError = error;
}
if(error != AddServerError_None && error != AddServerError_Hostname)
{
return nullptr;
}
bool isIP = (error == AddServerError_None);
QueryState state = (error == AddServerError_None) ? QueryRunning : QueryResolving;
ServerInfo *info = new ServerInfo(server, state, isIP);
serverList.append(info);
int row = ui->browserTable->rowCount();
ui->browserTable->insertRow(row);
ServerTableIndexItem *id = new ServerTableIndexItem(info);
id->setData(Qt::DisplayRole, serverList.size());
ui->browserTable->setItem(row, kBrowserColIndex, id);
this->CreateTableItemOrUpdate(row, kBrowserColHostname, ui->browserTable, info);
if(isIP)
{
InfoQuery *infoQuery = new InfoQuery(this);
infoQuery->query(&info->host, info->port, id);
}
else
{
//Resolve Address
HostQueryResult *res = new HostQueryResult(info, this, id);
QHostInfo::lookupHost(info->hostname, res, SLOT(HostInfoResolved(QHostInfo)));
}
return info;
}
QImage MainWindow::GetVACImage()
{
if(this->ui->actionDark_Theme->isChecked())
{
static QImage vacDark(":/icons/icons/vac.png");
return vacDark;
}
else
{
static QImage vacLight(":/icons/icons/vac-light.png");
return vacLight;
}
}
QImage MainWindow::GetLockImage()
{
if(this->ui->actionDark_Theme->isChecked())
{
static QImage lockDark(":/icons/icons/lock.png");
return lockDark;
}
else
{
static QImage lockLight(":/icons/icons/lock-light.png");
return lockLight;
}
}
QColor MainWindow::GetTextColor()
{
if(this->ui->actionDark_Theme->isChecked())
{
return Qt::white;
}
else
{
return Qt::black;
}
}