-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtrackers.cpp
More file actions
259 lines (189 loc) · 5.06 KB
/
trackers.cpp
File metadata and controls
259 lines (189 loc) · 5.06 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* -----------------------------------------------------
* File trackers.cpp
* Authors David Ordnung, Impact
* License GPLv3
* Web http://dordnung.de, http://gugyclan.eu
* -----------------------------------------------------
*
* Copyright (C) 2013-2017 David Ordnung, Impact
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
// Include Project
#include "log.h"
#include "main.h"
#include "call.h"
#include "config.h"
#include "tinyxml2/tinyxml2.h"
#include "taskbar.h"
#include "trackers.h"
#include "calladmin-client.h"
// Tracker Panel
TrackerPanel* trackerPanel = NULL;
// Button ID's for Tracker Panel
enum
{
wxID_UpdateTrackers = wxID_HIGHEST+700,
};
// Button Events for Log Panel
BEGIN_EVENT_TABLE(TrackerPanel, wxPanel)
EVT_BUTTON(wxID_UpdateTrackers, TrackerPanel::OnUpdate)
END_EVENT_TABLE()
// Create Tracker Panel
TrackerPanel::TrackerPanel(wxNotebook* note) : wxPanel(note, wxID_ANY)
{
// Set Tracker Panel
trackerPanel = this;
// Border and Center
wxSizerFlags flags;
// Border and Centre
flags.Border(wxALL, 10);
flags.Centre();
// Create Box
wxSizer* const sizerTop = new wxBoxSizer(wxVERTICAL);
trackerBox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL | wxLB_SINGLE);
trackerBox->SetFont(wxFont(14, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
// Add Log Box
sizerTop->Add(trackerBox, 1, wxEXPAND);
wxSizer* const sizerBtns = new wxBoxSizer(wxHORIZONTAL);
// Hide and Exit Button
sizerBtns->Add(new wxButton(this, wxID_UpdateTrackers, "Update Trackers"), flags.Border(wxALL, 5));
// Add Buttons to Box
sizerTop->Add(sizerBtns, flags.Align(wxALIGN_CENTER_HORIZONTAL));
// Auto Size
SetSizerAndFit(sizerTop, true);
}
// Button Event -> Update List
void TrackerPanel::OnUpdate(wxCommandEvent& WXUNUSED(event))
{
// Get the Trackers Page
getPage(refreshTrackers, page + "/trackers.php?from=20&from_type=interval&key=" + key);
}
// Add new Tracker
void addTracker(wxString text)
{
// Add the new tracker to the box
if (trackerPanel != NULL)
{
trackerPanel->newTracker(text);
}
}
// Refresh Trackers
void refreshTrackers(char* errors, wxString result, int WXUNUSED(x))
{
// Valid?
if (trackerPanel == NULL)
{
return;
}
// Log Action
LogAction("Got Trackers");
wxString error = "";
// Delete old ones
trackerPanel->delTrackers();
// Not empty?
if (result != "")
{
// Everything good :)
if (strcmp(errors, "") == 0)
{
// Proceed XML result!
tinyxml2::XMLDocument doc;
tinyxml2::XMLNode *node;
tinyxml2::XMLError parseError;
// Parse the xml data
parseError = doc.Parse(result);
// Parsing good :)?
if (parseError == tinyxml2::XML_SUCCESS)
{
// Goto xml child
node = doc.FirstChild();
// Goto CallAdmin_Trackers
if (node != NULL)
{
node = node->NextSibling();
}
// Found Trackers?
if (node != NULL)
{
// found someone?
bool found = false;
// Tracker Loop
for (tinyxml2::XMLNode *node2 = node->FirstChild(); node2; node2 = node2->NextSibling())
{
// API Error?
if ((wxString)node2->Value() == "error")
{
error = (wxString)node2->FirstChild()->Value();
break;
}
// Search admin steamids
for (tinyxml2::XMLNode *node3 = node2->FirstChild(); node3; node3 = node3->NextSibling())
{
// Found steamid
if ((wxString)node3->Value() == "trackerID")
{
std::string steamidString = node3->FirstChild()->Value();
// Build csteamid
CSteamID steamidTracker = CallDialog::steamIDtoCSteamID((char*) steamidString.c_str());
// Valid Tracker ID?
if (steamidTracker.IsValid())
{
// Create Name Timer
new NameTimer(steamidTracker);
found = true;
}
}
}
}
// Have we found something?
if (found)
{
// We are finished :)
return;
}
}
}
else
{
// XML ERROR
error = "XML ERROR: Couldn't parse the trackers API!";
// Log Action
LogAction("XML Error in trackers API");
}
}
else
{
// Curl error
error = errors;
// Log Action
LogAction("CURL Error " + error);
}
}
else
{
// Curl error
error = "Couldn't init. CURL connection";
}
// Seems we found no one
if (error == "")
{
error = "Found no available trackers!";
}
if (m_taskBarIcon != NULL)
{
m_taskBarIcon->ShowMessage("Coulnd't retrieve trackers!", error, NULL);
}
}