· 3 years ago · Nov 04, 2021, 01:10 AM
1<?php
2class Functions {
3 public static function ObStart() {
4 function minify_everything($buffer) {
5 $buffer = preg_replace(array('/\>[^\S ]+/s','/[^\S ]+\</s','/(\s)+/s','/<!--(.|\s)*?-->/', '/\s+/'), array('>','<','\\1','', ' '), $buffer);
6 return $buffer;
7 }
8 ob_start('ob_gzhandler');
9 ob_start('minify_everything');
10 }
11
12 public static function LoadPage($variable) {
13 Functions::ObStart();
14
15 $mysqli = Database::GetInstance();
16
17 if (!$mysqli->connect_errno && Functions::IsLoggedIn()) {
18 $player = Functions::GetPlayer();
19 $data = json_decode($player['data']);
20
21 if ($player['clanId'] > 0) {
22 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
23 }
24 }
25
26 $page = array_filter(explode('/', str_replace('-', '_', Functions::s($variable))), function($a) {
27 return trim($a) !== '';
28 });
29
30 $path = '';
31
32 if (isset($page[0])) {
33 if ($page[0] == 'api') {
34 $path = ROOT . 'api.php';
35 } else if ($page[0] == 'cronjobs') {
36 $path = CRONJOBS . $page[1] . '.php';
37 } else {
38 if (isset($player)) {
39 if ($page[0] == 'company_select' && $player['factionId'] != 0) {
40 $page[0] = 'home';
41 } else if ($player['factionId'] == 0) {
42 $page[0] = 'company_select';
43 } else if ($page[0] == 'index') {
44 $page[0] = 'home';
45 } else if ($page[0] == 'clan' && isset($page[2]) && $page[2] == $player['clanId']) {
46 $page[0] = 'clan';
47 $page[1] = 'informations';
48 }
49 } else if ($page[0] != 'maintenance') {
50 $page[0] = 'index';
51 }
52
53 $path = EXTERNALS . $page[0] . '.php';
54 }
55 } else {
56 $page[0] = 'index';
57 }
58
59 if (!file_exists($path)) {
60 $path = EXTERNALS . 'error.php';
61 }
62
63 $require = $page[0] !== 'map_revolution' && $page[0] !== 'api' && $page[0] !== 'cronjobs' ? true : false;
64
65 if ($require) {
66 require_once(INCLUDES . 'header.php');
67 }
68
69 require_once($path);
70
71 if ($require) {
72 require_once(INCLUDES . 'footer.php');
73 }
74
75 ob_end_flush();
76 }
77
78 public static function Register($username, $password, $password_confirm, $email) {
79 $mysqli = Database::GetInstance();
80
81 $username = $mysqli->real_escape_string($username);
82 $password = $mysqli->real_escape_string($password);
83 $password_confirm = $mysqli->real_escape_string($password_confirm);
84 $email = $mysqli->real_escape_string($email);
85
86 $json = [
87 'inputs' => [
88 'username' => ['validate' => 'valid', 'error' => 'Enter a valid username!'],
89 'password' => ['validate' => 'valid', 'error' => 'Enter a valid password!'],
90 'password_confirm' => ['validate' => 'valid', 'error' => 'Enter a valid password!'],
91 'email' => ['validate' => 'valid', 'error' => 'Enter a valid e-mail address!'],
92 ],
93 'message' => ''
94 ];
95
96 if (!preg_match('/^[A-Za-z0-9_.]+$/', $username)) {
97 $json['inputs']['username']['validate'] = 'invalid';
98 $json['inputs']['username']['error'] = 'Your username is not valid.';
99 }
100
101 if (mb_strlen($username) < 4 || mb_strlen($username) > 20) {
102 $json['inputs']['username']['validate'] = 'invalid';
103 $json['inputs']['username']['error'] = 'Your username should be between 4 and 20 characters.';
104 }
105
106 if (!filter_var($email, FILTER_VALIDATE_EMAIL) || mb_strlen($email) > 260) {
107 $json['inputs']['email']['validate'] = 'invalid';
108 $json['inputs']['email']['error'] = 'Your e-mail should be max 260 characters.';
109 }
110
111 if (mb_strlen($password) < 8 || mb_strlen($password) > 45) {
112 $json['inputs']['password']['validate'] = 'invalid';
113 $json['inputs']['password']['error'] = 'Your password should be between 8 and 45 characters.';
114 }
115
116 if ($password != $password_confirm) {
117 $json['inputs']['password_confirm']['validate'] = 'invalid';
118 $json['inputs']['password_confirm']['error'] = "Those passwords didn't match. Try again.";
119 }
120
121 if ($json['inputs']['username']['validate'] === 'valid' && $json['inputs']['password']['validate'] === 'valid' && $json['inputs']['password_confirm']['validate'] === 'valid' && $json['inputs']['email']['validate'] === 'valid') {
122 if ($mysqli->query('SELECT userId FROM player_accounts WHERE username = "'.$username.'"')->num_rows <= 0) {
123 $ip = Functions::GetIP();
124 $sessionId = Functions::GetUniqueSessionId();
125 $pilotName = $username;
126
127 if ($mysqli->query('SELECT userId FROM player_accounts WHERE pilotName = "'.$pilotName.'"')->num_rows >= 1) {
128 $pilotName = Functions::GetUniquePilotName($pilotName);
129 }
130
131 $mysqli->begin_transaction();
132
133 try {
134 $info = [
135 'lastIP' => $ip,
136 'registerIP' => $ip,
137 'registerDate' => date('d.m.Y H:i:s')
138 ];
139
140 $verification = [
141 'verified' => false,
142 'hash' => $sessionId
143 ];
144
145 $mysqli->query("INSERT INTO player_accounts (sessionId, username, pilotName, email, password, info, verification) VALUES ('".$sessionId."', '".$username."', '".$pilotName."', '".$email."', '".password_hash($password, PASSWORD_DEFAULT)."', '".json_encode($info)."', '".json_encode($verification)."')");
146
147 $userId = $mysqli->insert_id;
148
149 $mysqli->query('INSERT INTO player_equipment (userId) VALUES ('.$userId.')');
150 $mysqli->query('INSERT INTO player_settings (userId) VALUES ('.$userId.')');
151 $mysqli->query('INSERT INTO player_titles (userID) VALUES ('.$userId.')');
152
153
154 SMTP::SendMail($email, $username, 'E-mail verification', '<p>Hi '.$username.', <br>Click this link to activate your account: <a href="'.DOMAIN.'api/verify/'.$userId.'/'.$verification['hash'].'">Activate</a></p><p style="font-size:small;color:#666">—<br>You are receiving this because you registered to the '.SERVER_NAME.'.<br>If that was not your request, then you can ignore this email.<br>This is an automated message, please do not reply directly to this email.</p>');
155
156 $json['message'] = 'You successfully registered, please verify your e-mail address.';
157
158 $mysqli->commit();
159
160 $mysqli->query('INSERT INTO player_equipment (config1_lasers) VALUES ("[]") where userId = '.$userID);
161 $mysqli->query('INSERT INTO player_equipment (config1_generators) VALUES ("[]") where userId = '.$userID);
162 $mysqli->query('INSERT INTO player_equipment (config2_lasers) VALUES ("[]") where userId = '.$userID);
163 $mysqli->query('INSERT INTO player_equipment (config1_drones) VALUES ("[{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]}]") where userId = '.$userID);
164 $mysqli->query('INSERT INTO player_equipment (config2_drones) VALUES ("[{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]}]") where userId = '.$userID);
165 $mysqli->query('INSERT INTO player_equipment (items) VALUES ("{"lf4Count":0,"havocCount":0,"herculesCount":0,"apis":false,"zeus":false,"pet":false,"petModules":[],"ships":[],"designs":{},"skillTree":{"logdisks":0,"researchPoints":0,"resetCount":0}}") where userId = '.$userID);
166 $mysqli->query('INSERT INTO player_equipment (skill_points) VALUES ("{"engineering":0,"shieldEngineering":0,"detonation1":0,"detonation2":0,"heatseekingMissiles":0,"rocketFusion":0,"cruelty1":0,"cruelty2":0,"explosives":0,"luck1":0,"luck2":0}") where userId = '.$userID);
167 $mysqli->query('INSERT INTO player_equipment (modules) VALUES ("[]") where userId = '.$userID);
168 $mysqli->query('INSERT INTO player_equipment (boosters) VALUES ("[]") where userId = '.$userID);
169
170 $mysqli->query('INSERT INTO player_galaxygates (parts) VALUES ("[]") where userId = '.$userID);
171 $mysqli->query('INSERT INTO player_galaxygates (multiplier) VALUES (0) where userId = '.$userID);
172 $mysqli->query('INSERT INTO player_galaxygates (lives) VALUES (-1) where userId = '.$userID);
173 $mysqli->query('INSERT INTO player_galaxygates (prepared) VALUES (0) where userId = '.$userID);
174
175
176
177 $mysqli->commit();
178
179 } catch (Exception $e) {
180 $json['message'] = 'An error occurred. Please try again later.';
181 $mysqli->rollback();
182 }
183
184 $mysqli->close();
185
186 } else {
187 $json['message'] = 'This username is already taken.';
188 }
189 }
190
191 return json_encode($json);
192 }
193
194 public static function Login($username, $password) {
195 $mysqli = Database::GetInstance();
196
197 $username = $mysqli->real_escape_string($username);
198 $password = $mysqli->real_escape_string($password);
199
200 $json = [
201 'status' => false,
202 'message' => '',
203 'toastAction' => ''
204 ];
205
206 $statement = $mysqli->query('SELECT userId, password, verification FROM player_accounts WHERE username = "'.$username.'"');
207 $fetch = $statement->fetch_assoc();
208
209 if ($statement->num_rows >= 1) {
210 if (password_verify($password, $fetch['password'])) {
211 if (json_decode($fetch['verification'])->verified) {
212 $sessionId = Functions::GenerateRandom(32);
213
214 $_SESSION['account']['id'] = $fetch['userId'];
215 $_SESSION['account']['session'] = $sessionId;
216
217 $mysqli->begin_transaction();
218
219 try {
220 $mysqli->query('UPDATE player_accounts SET sessionId = "'.$sessionId.'" WHERE userId = '.$fetch['userId'].'');
221
222 $json['status'] = true;
223
224 $mysqli->commit();
225 } catch (Exception $e) {
226 $json['message'] = 'An error occurred. Please try again later.';
227 $mysqli->rollback();
228 }
229
230 $mysqli->close();
231
232 } else {
233 if(!isset($_COOKIE['send-link-again-button'])) {
234 $json['toastAction'] = '<button id="send-link-again" class="btn-flat waves-effect waves-light toast-action">Send link again</button>';
235 }
236
237 $json['message'] = 'This account is not verified, please verify it from your e-mail address.';
238 }
239 } else {
240 $json['message'] = 'Wrong password.';
241 }
242 } else {
243 $json['message'] = 'No account with this username/password combination was found.';
244 }
245
246 return json_encode($json);
247 }
248
249 public static function ChangeShip($shipLootId) {
250 $mysqli = Database::GetInstance();
251
252 $shipLootId = $mysqli->real_escape_string($shipLootId);
253
254 $json = [
255 'message' => ''
256 ];
257
258 $player = Functions::GetPlayer();
259
260 $ship = $mysqli->query('SELECT * FROM server_ships WHERE lootID = "'.$shipLootId.'"')->fetch_assoc();
261 $currentShip = $mysqli->query("SELECT * FROM server_ships WHERE shipID = {$player['shipId']}")->fetch_assoc();
262 $equipment = $mysqli->query('SELECT * FROM player_equipment WHERE userId = '.$player['userId'].'')->fetch_assoc();
263
264 $ships = json_decode($equipment['items'])->ships;
265 array_push($ships, 8);
266 array_push($ships, 10);
267
268 if ($ship != NULL && in_array($ship['shipID'], $ships)) {
269 if ($currentShip['baseShipId'] != $ship['shipID']) {
270 if (!Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)) || (Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)) && Socket::Get('AvailableToChangeShip', array('UserId' => $player['userId'], 'Return' => false)))) {
271 $mysqli->begin_transaction();
272
273 try {
274 $mysqli->query('UPDATE player_accounts SET shipID = '.$ship['shipID'].' WHERE userId = '.$player['userId'].'');
275
276 $json['status'] = true;
277
278 $drones = '[{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]},{"items":[],"designs":[]}]';
279 $mysqli->query("UPDATE player_equipment SET config1_lasers = '[]', config2_lasers = '[]', config1_generators = '[]', config2_generators = '[]', config1_drones = '".$drones."', config2_drones = '".$drones."' WHERE userId = ".$player['userId']."");
280
281 if (Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false))) {
282 Socket::Send('ChangeShip', array('UserId' => $player['userId'], 'ShipId' => $ship['shipID']));
283 }
284
285 $mysqli->commit();
286 } catch (Exception $e) {
287 $json['message'] = 'An error occurred. Please try again later.';
288 $mysqli->rollback();
289 }
290
291 $mysqli->close();
292 } else {
293 $json['message'] = 'You cannot change spaceships until the 5 second cool-down has been completed.';
294 }
295 }
296 } else {
297 $json['message'] = 'Something went wrong!';
298 }
299
300 return json_encode($json);
301 }
302
303 public static function SendLinkAgain($username) {
304 $mysqli = Database::GetInstance();
305
306 $username = $mysqli->real_escape_string($username);
307
308 $json = [
309 'message' => ''
310 ];
311
312 if (!isset($_COOKIE['send-link-again-button'])) {
313 $statement = $mysqli->query('SELECT userId, email, verification FROM player_accounts WHERE username = "'.$username.'"');
314 $fetch = $statement->fetch_assoc();
315
316 if ($statement->num_rows >= 1) {
317 SMTP::SendMail($fetch['email'], $username, 'E-mail verification', '<p>Hi '.$username.', <br>Click this link to activate your account: <a href="'.DOMAIN.'api/verify/'.$fetch['userId'].'/'.json_decode($fetch['verification'])->hash.'">Activate</a></p><p style="font-size:small;color:#666">—<br>You are receiving this because you registered to the '.SERVER_NAME.'.<br>If that was not your request, then you can ignore this email.<br>This is an automated message, please do not reply directly to this email.</p>');
318
319 $json['message'] = 'Activation link sent again.';
320 setcookie('send-link-again-button', true, (time() + (120)), '/');
321 } else {
322 $json['message'] = 'Something went wrong!';
323 }
324 } else {
325 $json['message'] = 'You need to wait 2 minutes for send link again.';
326 }
327
328 return json_encode($json);
329 }
330
331 public static function CompanySelect($company) {
332 $mysqli = Database::GetInstance();
333
334 $json = [
335 'status' => false,
336 'message' => ''
337 ];
338
339 $player = Functions::GetPlayer();
340
341 $factionId = 0;
342
343 if ($company === 'mmo') {
344 $factionId = 1;
345 } else if ($company === 'eic') {
346 $factionId = 2;
347 } else if ($company === 'vru') {
348 $factionId = 3;
349 }
350
351 if (in_array($factionId, [1, 2, 3], true) && $player['factionId'] != $factionId) {
352 if (!in_array($player['factionId'], [1, 2, 3])) {
353 $mysqli->begin_transaction();
354
355 try {
356 $mysqli->query('UPDATE player_accounts SET factionId = '.$factionId.' WHERE userId = '.$player['userId'].'');
357 $json['status'] = true;
358 $mysqli->commit();
359 } catch (Exception $e) {
360 $json['message'] = 'An error occurred. Please try again later.';
361 $mysqli->rollback();
362 }
363
364 $mysqli->close();
365 } else {
366 $data = json_decode($player['data']);
367
368 if ($data->uridium >= 5000) {
369 $notOnlineOrOnlineAndInEquipZone = !Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)) || (Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)) && Socket::Get('IsInEquipZone', array('UserId' => $player['userId'], 'Return' => false)));
370
371 if ($notOnlineOrOnlineAndInEquipZone) {
372 $data->uridium -= 5000;
373
374 if ($data->honor > 0) {
375 $data->honor /= 2;
376 $data->honor = round($data->honor);
377 }
378
379 $mysqli->begin_transaction();
380
381 try {
382 $mysqli->query("UPDATE player_accounts SET factionId = ".$factionId.", data = '".json_encode($data)."' WHERE userId = ".$player['userId']."");
383
384 $json['status'] = true;
385 $mysqli->commit();
386 } catch (Exception $e) {
387 $json['message'] = 'An error occurred. Please try again later.';
388 $mysqli->rollback();
389 }
390
391 $mysqli->close();
392 } else {
393 $json['message'] = 'Change of company is not possible. You must be at a location with a hangar facility!';
394 }
395 } else {
396 $json['message'] = "You don't have enough Uridium.";
397 }
398
399 if ($json['status'] && Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false))) {
400 Socket::Send('ChangeCompany', ['UserId' => $player['userId'], 'UridiumPrice' => 5000, 'HonorPrice' => $data->honor]);
401 }
402 }
403 } else {
404 $json['message'] = 'Something went wrong!';
405 }
406
407 return json_encode($json);
408 }
409
410 public static function Logout() {
411 if (isset($_SESSION['account'])) {
412 unset($_SESSION['account']);
413 session_destroy();
414 }
415
416 header('Location: '.DOMAIN.'');
417 }
418
419 public static function SearchClan($keywords) {
420 $mysqli = Database::GetInstance();
421
422 $keywords = $mysqli->real_escape_string($keywords);
423
424 $clans = [];
425
426 foreach ($mysqli->query('SELECT * FROM server_clans WHERE tag like "%'.$keywords.'%" OR name like "%'.$keywords.'%"')->fetch_all(MYSQLI_ASSOC) as $key => $value) {
427 $clans[$key]['id'] = $value['id'];
428 $clans[$key]['members'] = count($mysqli->query('SELECT userId FROM player_accounts WHERE clanId = '.$value['id'].'')->fetch_all(MYSQLI_ASSOC));
429 $clans[$key]['tag'] = $value['tag'];
430 $clans[$key]['name'] = $value['name'];
431 $clans[$key]['rank'] = $value['rank'];
432 $clans[$key]['rankPoints'] = $value['rankPoints'];
433 }
434
435 return json_encode($clans);
436 }
437
438 public static function DiplomacySearchClan($keywords) {
439 $mysqli = Database::GetInstance();
440
441 $player = Functions::GetPlayer();
442 $keywords = $mysqli->real_escape_string($keywords);
443
444 $clans = [];
445
446 foreach ($mysqli->query('SELECT * FROM server_clans WHERE id != '.$player['clanId'].' AND (tag like "%'.$keywords.'%" OR name like "%'.$keywords.'%")')->fetch_all(MYSQLI_ASSOC) as $key => $value) {
447 $clans[$key]['id'] = $value['id'];
448 $clans[$key]['tag'] = $value['tag'];
449 $clans[$key]['name'] = $value['name'];
450 }
451
452 return json_encode($clans);
453 }
454
455 public static function RequestDiplomacy($clanId, $diplomacyType) {
456 $mysqli = Database::GetInstance();
457
458 $player = Functions::GetPlayer();
459 $clanId = $mysqli->real_escape_string($clanId);
460 $diplomacyType = $mysqli->real_escape_string($diplomacyType);
461 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
462
463 $json = [
464 'message' => ''
465 ];
466
467 if ($clanId != 0) {
468 if ($clan != NULL) {
469 if ($clan['leaderId'] == $player['userId']) {
470 $toClan = $mysqli->query('SELECT * FROM server_clans WHERE id = "'.$clanId.'"')->fetch_assoc();
471
472 if ($toClan != NULL && $clan['id'] != $toClan['id'] && in_array($diplomacyType, [1, 2, 3, 4])) {
473 $mysqli->begin_transaction();
474
475 try {
476 $statement = $mysqli->query('SELECT id, diplomacyType FROM server_clan_diplomacy WHERE (senderClanId = '.$clan['id'].' AND toClanId = '.$toClan['id'].') OR (toClanId = '.$clan['id'].' AND senderClanId = '.$toClan['id'].')');
477 $fetch = $statement->fetch_assoc();
478
479 if ($statement->num_rows <= 0 || $diplomacyType == 4) {
480 if ($diplomacyType == 3) {
481 $mysqli->query('INSERT INTO server_clan_diplomacy (senderClanId, toClanId, diplomacyType) VALUES ('.$clan['id'].', '.$toClan['id'].', '.$diplomacyType.')');
482
483 $declaredId = $mysqli->insert_id;
484
485 $mysqli->query('DELETE FROM server_clan_diplomacy_applications WHERE senderClanId = '.$clan['id'].' AND toClanId = '.$toClan['id'].'');
486
487 $json['message'] = 'You declared war on the '.$toClan['name'].' clan.';
488
489 $json['declared'] = [
490 'id' => $declaredId,
491 'date' => date('d.m.Y'),
492 'form' => ($diplomacyType == 1 ? 'Alliance' : ($diplomacyType == 2 ? 'NAP' : 'War')),
493 'clan' => [
494 'id' => $toClan['id'],
495 'name' => $toClan['name']
496 ]
497 ];
498
499 Socket::Send('StartDiplomacy', ['SenderClanId' => $clan['id'], 'TargetClanId' => $toClan['id'], 'DiplomacyType' => $diplomacyType]);
500 } else {
501 if ($mysqli->query('SELECT id FROM server_clan_diplomacy_applications WHERE senderClanId = '.$clan['id'].' AND toClanId = '.$toClan['id'].'')->num_rows <= 0) {
502 $mysqli->query('INSERT INTO server_clan_diplomacy_applications (senderClanId, toClanId, diplomacyType) VALUES ('.$clan['id'].', '.$toClan['id'].', '.$diplomacyType.')');
503
504 $requestId = $mysqli->insert_id;
505
506 $json['message'] = 'Your diplomacy request was sent.';
507
508 $json['request'] = [
509 'id' => $requestId,
510 'date' => date('d.m.Y'),
511 'form' => ($diplomacyType == 1 ? 'Alliance' : ($diplomacyType == 2 ? 'NAP' : ($diplomacyType == 3 ? 'War' : 'End War'))),
512 'clan' => [
513 'name' => $toClan['name']
514 ]
515 ];
516
517 } else {
518 $json['message'] = 'You already submitted a diplomacy request to this clan.';
519 }
520 }
521
522 } else {
523 $currentStatus = $fetch['diplomacyType'] == 1 ? 'Alliance' : ($fetch['diplomacyType'] == 2 ? 'NAP' : 'War');
524
525 $json['message'] = 'You already have a diplomatic status with this clan.<br>Current status: '.$currentStatus.'';
526 }
527
528 $mysqli->commit();
529 } catch (Exception $e) {
530 $json['message'] = 'An error occurred. Please try again later.';
531 $mysqli->rollback();
532 }
533
534 $mysqli->close();
535 } else {
536 $json['message'] = 'Something went wrong!';
537 }
538 } else {
539 $json['message'] = 'Only leaders are can sent a diplomacy request.';
540 }
541 } else {
542 $json['message'] = 'Something went wrong!';
543 }
544 } else {
545 $json['message'] = 'Please select a clan.';
546 }
547
548 return json_encode($json);
549 }
550
551 public static function SendClanApplication($clanId, $text) {
552 $mysqli = Database::GetInstance();
553
554 $player = Functions::GetPlayer();
555 $clanId = $mysqli->real_escape_string($clanId);
556 $text = $mysqli->real_escape_string($text);
557
558 $json = [
559 'status' => false,
560 'message' => ''
561 ];
562
563 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = "'.$clanId.'"')->fetch_assoc();
564
565 if ($clan != NULL & $clan['recruiting'] && $mysqli->query('SELECT id FROM server_clan_applications WHERE clanId = '.$clanId.' AND userId = '.$player['userId'].'')->num_rows <= 0 && $player['clanId'] == 0) {
566 $mysqli->begin_transaction();
567
568 try {
569 $mysqli->query('INSERT INTO server_clan_applications (clanId, userId, text) VALUES ('.$clanId.', '.$player['userId'].', "'.$text.'")');
570
571 $json['status'] = true;
572 $json['message'] = 'Your application was sent to the clan leader.';
573
574 $mysqli->commit();
575 } catch (Exception $e) {
576 $json['message'] = 'An error occurred. Please try again later.';
577 $mysqli->rollback();
578 }
579
580 $mysqli->close();
581 } else {
582 $json['message'] = 'Something went wrong!';
583 }
584
585 return json_encode($json);
586 }
587
588 public static function FoundClan($name, $tag, $description) {
589 $mysqli = Database::GetInstance();
590
591 $player = Functions::GetPlayer();
592 $name = $mysqli->real_escape_string($name);
593 $tag = $mysqli->real_escape_string($tag);
594 $description = $mysqli->real_escape_string($description);
595
596 $json = [
597 'inputs' => [
598 'name' => ['validate' => 'valid', 'error' => 'Enter a valid clan name!'],
599 'tag' => ['validate' => 'valid', 'error' => 'Enter a valid clan tag!'],
600 'description' => ['validate' => 'valid', 'error' => 'Enter a valid clan description!'],
601 ],
602 'status' => false,
603 'message' => ''
604 ];
605
606 if (mb_strlen($name) < 1 || mb_strlen($name) > 50) {
607 $json['inputs']['name']['validate'] = 'invalid';
608 $json['inputs']['name']['error'] = 'Your clan name should be between 1 and 50 characters.';
609 }
610
611 if (mb_strlen($tag) < 1 || mb_strlen($tag) > 4) {
612 $json['inputs']['tag']['validate'] = 'invalid';
613 $json['inputs']['tag']['error'] = 'Your clan tag should be between 1 and 4 characters.';
614 }
615
616 if (mb_strlen($description) > 16000) {
617 $json['inputs']['description']['validate'] = 'invalid';
618 $json['inputs']['description']['error'] = 'Your clan description should be max 16000 characters.';
619 }
620
621 if ($json['inputs']['name']['validate'] === 'valid' && $json['inputs']['tag']['validate'] === 'valid' && $json['inputs']['description']['validate'] === 'valid' && $player['clanId'] == 0) {
622 if ($mysqli->query('SELECT id FROM server_clans WHERE name = "'.$name.'"')->num_rows <= 0) {
623 if ($mysqli->query('SELECT id FROM server_clans WHERE tag = "'.$tag.'"')->num_rows <= 0) {
624 $mysqli->begin_transaction();
625
626 try {
627 $join_dates = [
628 $player['userId'] => date('Y-m-d H:i:s')
629 ];
630
631 $mysqli->query('DELETE FROM server_clan_applications WHERE userId = '.$player['userId'].'');
632
633 $mysqli->query("INSERT INTO server_clans (name, tag, description, factionId, recruiting, leaderId, join_dates) VALUES ('".$name."', '".$tag."', '".$description."', ".$player['factionId'].", 1, ".$player['userId'].", '".json_encode($join_dates)."')");
634
635 $clanId = $mysqli->insert_id;
636
637 $mysqli->query('UPDATE player_accounts SET clanId = '.$clanId.' WHERE userId = '.$player['userId'].'');
638
639 $json['status'] = true;
640
641 Socket::Send('CreateClan', ['UserId' => $player['userId'], 'ClanId' => $clanId, 'FactionId' => $player['factionId'], 'Name' => $name, 'Tag' => $tag]);
642
643 $mysqli->commit();
644 } catch (Exception $e) {
645 $json['message'] = 'An error occurred. Please try again later.';
646 $mysqli->rollback();
647 }
648
649 $mysqli->close();
650 } else {
651 $json['message'] = 'Another clan is already using this tag. Please select another one for your clan.';
652 }
653 } else {
654 $json['message'] = 'Another clan is already using this name. Please select another one for your clan.';
655 }
656 }
657
658 return json_encode($json);
659 }
660
661 public static function WithdrawPendingApplication($clanId) {
662 $mysqli = Database::GetInstance();
663
664 $player = Functions::GetPlayer();
665 $clanId = $mysqli->real_escape_string($clanId);
666
667 $json = [
668 'status' => false,
669 'message' => ''
670 ];
671
672 if ($mysqli->query('SELECT id FROM server_clan_applications WHERE clanId = "'.$clanId.'" AND userId = '.$player['userId'].'')->num_rows >= 1) {
673 $mysqli->begin_transaction();
674
675 try {
676 $mysqli->query('DELETE FROM server_clan_applications WHERE clanId = '.$clanId.' AND userId = '.$player['userId'].'');
677
678 $json['status'] = true;
679 $json['message'] = 'Application deleted.';
680
681 $mysqli->commit();
682 } catch (Exception $e) {
683 $json['message'] = 'An error occurred. Please try again later.';
684 $mysqli->rollback();
685 }
686
687 $mysqli->close();
688 } else {
689 $json['message'] = 'Something went wrong!';
690 }
691
692 return json_encode($json);
693 }
694
695 public static function DeleteClan() {
696 $mysqli = Database::GetInstance();
697
698 $player = Functions::GetPlayer();
699 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
700
701 $json = [
702 'status' => false,
703 'message' => ''
704 ];
705
706 if ($clan != NULL && $clan['leaderId'] == $player['userId']) {
707 $mysqli->begin_transaction();
708
709 try {
710 $mysqli->query('DELETE FROM server_clans WHERE id = '.$player['clanId'].' AND leaderId = '.$player['userId'].'');
711
712 $mysqli->query('UPDATE player_accounts SET clanId = 0 WHERE clanId = '.$clan['id'].'');
713
714 $mysqli->query('DELETE FROM server_clan_applications WHERE clanId = '.$clan['id'].'');
715
716 $mysqli->query('DELETE FROM server_clan_diplomacy WHERE senderClanId = '.$clan['id'].' OR toClanId = '.$clan['id'].'');
717
718 $mysqli->query('DELETE FROM server_clan_diplomacy_applications WHERE senderClanId = '.$clan['id'].' OR toClanId = '.$clan['id'].'');
719
720 $json['status'] = true;
721
722 Socket::Send('DeleteClan', ['ClanId' => $clan['id']]);
723
724 $mysqli->commit();
725 } catch (Exception $e) {
726 $json['message'] = 'An error occurred. Please try again later.';
727 $mysqli->rollback();
728 }
729
730 $mysqli->close();
731 } else {
732 $json['message'] = 'Something went wrong!';
733 }
734
735 return json_encode($json);
736 }
737
738 public static function LeaveClan() {
739 $mysqli = Database::GetInstance();
740
741 $player = Functions::GetPlayer();
742 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
743
744 $json = [
745 'status' => false,
746 'message' => ''
747 ];
748
749 $notOnlineOrOnlineAndInEquipZone = !Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)) || (Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)) && Socket::Get('IsInEquipZone', array('UserId' => $player['userId'], 'Return' => false)));
750
751 if ($clan != NULL && $clan['leaderId'] != $player['userId']) {
752 if ($notOnlineOrOnlineAndInEquipZone) {
753 $mysqli->begin_transaction();
754
755 try {
756 $mysqli->query('UPDATE player_accounts SET clanId = 0 WHERE userId = '.$player['userId'].'');
757
758 $join_dates = json_decode($clan['join_dates']);
759
760 if (property_exists($join_dates, $player['userId'])) {
761 unset($join_dates->{$player['userId']});
762 }
763
764 $mysqli->query("UPDATE server_clans SET join_dates = '".json_encode($join_dates)."' WHERE id = ".$clan['id']."");
765
766 $json['status'] = true;
767
768 Socket::Send('LeaveFromClan', ['UserId' => $player['userId']]);
769
770 $mysqli->commit();
771 } catch (Exception $e) {
772 $json['message'] = 'An error occurred. Please try again later.';
773 $mysqli->rollback();
774 }
775
776 $mysqli->close();
777 } else {
778 $json['message'] = 'You must be at your corporate HQ station to leave your Clan.';
779 }
780 } else {
781 $json['message'] = 'Something went wrong!';
782 }
783
784 return json_encode($json);
785 }
786
787 public static function DismissClanMember($userId) {
788 $mysqli = Database::GetInstance();
789
790 $player = Functions::GetPlayer();
791 $userId = $mysqli->real_escape_string($userId);
792 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
793 $user = $mysqli->query('SELECT * FROM player_accounts WHERE userId = "'.$userId.'" AND clanId = "'.$clan['id'].'"')->fetch_assoc();
794
795 $json = [
796 'status' => false,
797 'message' => ''
798 ];
799
800 if ($clan != NULL && $user != NULL && $clan['leaderId'] == $player['userId']) {
801 $mysqli->begin_transaction();
802
803 try {
804 $mysqli->query('UPDATE player_accounts SET clanId = 0 WHERE userId = '.$user['userId'].'');
805
806 $join_dates = json_decode($clan['join_dates']);
807
808 if (property_exists($join_dates, $user['userId'])) {
809 unset($join_dates->{$user['userId']});
810 }
811
812 $mysqli->query("UPDATE server_clans SET join_dates = '".json_encode($join_dates)."' WHERE id = ".$clan['id']."");
813
814 $json['status'] = true;
815 $json['message'] = 'Member deleted.';
816
817 Socket::Send('LeaveFromClan', array('UserId' => $user['userId']));
818
819 $mysqli->commit();
820 } catch (Exception $e) {
821 $json['message'] = 'An error occurred. Please try again later.';
822 $mysqli->rollback();
823 }
824
825 $mysqli->close();
826 } else {
827 $json['message'] = 'Something went wrong!';
828 }
829
830 return json_encode($json);
831 }
832
833 public static function AcceptClanApplication($userId) {
834 $mysqli = Database::GetInstance();
835
836 $player = Functions::GetPlayer();
837 $userId = $mysqli->real_escape_string($userId);
838 $user = $mysqli->query('SELECT * FROM player_accounts WHERE userId = "'.$userId.'"')->fetch_assoc();
839 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
840
841 $json = [
842 'status' => false,
843 'message' => ''
844 ];
845
846 if ($clan != NULL && $user != NULL && $clan['leaderId'] == $player['userId'] && $user['clanId'] == 0) {
847 $mysqli->begin_transaction();
848
849 try {
850 $mysqli->query('UPDATE player_accounts SET clanId = '.$clan['id'].' WHERE userId = '.$user['userId'].'');
851
852 $join_dates = json_decode($clan['join_dates']);
853 $join_dates->{$user['userId']} = date('Y-m-d H:i:s');
854
855 $mysqli->query("UPDATE server_clans SET join_dates = '".json_encode($join_dates)."' WHERE id = ".$clan['id']."");
856
857 $mysqli->query('DELETE FROM server_clan_applications WHERE userId = '.$user['userId'].'');
858
859 $json['status'] = true;
860
861 $json['acceptedUser'] = [
862 'userId' => $user['userId'],
863 'pilotName' => $user['pilotName'],
864 'experience' => number_format(json_decode($user['data'])->experience),
865 'rank' => [
866 'id' => $user['rankId'],
867 'name' => Functions::GetRankName($user['rankId'])
868 ],
869 'joined_date' => date('Y.m.d'),
870 'company' => $user['factionId'] == 1 ? 'MMO' : ($user['factionId'] == 2 ? 'EIC' : 'VRU')
871 ];
872
873 $json['message'] = 'Clan joined: ' . $user['pilotName'];
874
875 if (Socket::Get('IsOnline', ['UserId' => $user['userId'], 'Return' => false])) {
876 Socket::Send('JoinToClan', ['UserId' => $user['userId'], 'ClanId' => $clan['id']]);
877 }
878
879 $mysqli->commit();
880 } catch (Exception $e) {
881 $json['message'] = 'An error occurred. Please try again later.';
882 $mysqli->rollback();
883 }
884
885 $mysqli->close();
886 } else {
887 $json['message'] = 'Something went wrong!';
888 }
889
890 return json_encode($json);
891 }
892
893 public static function DeclineClanApplication($userId) {
894 $mysqli = Database::GetInstance();
895
896 $player = Functions::GetPlayer();
897 $userId = $mysqli->real_escape_string($userId);
898 $user = $mysqli->query('SELECT * FROM player_accounts WHERE userId = "'.$userId.'"')->fetch_assoc();
899 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
900
901 $json = [
902 'status' => false,
903 'message' => ''
904 ];
905
906 if ($clan != NULL && $user != NULL && $clan['leaderId'] == $player['userId']) {
907 $mysqli->begin_transaction();
908
909 try {
910 $mysqli->query('DELETE FROM server_clan_applications WHERE clanId = '.$clan['id'].' AND userId = '.$user['userId'].'');
911
912 $json['status'] = true;
913 $json['message'] = 'This user was declined: ' . $user['pilotName'];
914
915 $mysqli->commit();
916 } catch (Exception $e) {
917 $json['message'] = 'An error occurred. Please try again later.';
918 $mysqli->rollback();
919 }
920
921 $mysqli->close();
922 } else {
923 $json['message'] = 'Something went wrong!';
924 }
925
926 return json_encode($json);
927 }
928
929 public static function CancelDiplomacyRequest($requestId) {
930 $mysqli = Database::GetInstance();
931
932 $player = Functions::GetPlayer();
933 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
934 $requestId = $mysqli->real_escape_string($requestId);
935
936 $json = [
937 'status' => false,
938 'message' => ''
939 ];
940
941 if ($clan != NULL) {
942 if ($clan['leaderId'] == $player['userId']) {
943 $statement = $mysqli->query('SELECT id FROM server_clan_diplomacy_applications WHERE senderClanId = '.$player['clanId'].' AND id = "'.$requestId.'"');
944 $fetch = $statement->fetch_assoc();
945
946 if ($statement->num_rows >= 1) {
947 $mysqli->begin_transaction();
948
949 try {
950 $mysqli->query('DELETE FROM server_clan_diplomacy_applications WHERE id = '.$fetch['id'].'');
951
952 $json['status'] = true;
953 $json['message'] = 'Your diplomatic request was withdrawn.';
954
955 $mysqli->commit();
956 } catch (Exception $e) {
957 $json['message'] = 'An error occurred. Please try again later.';
958 $mysqli->rollback();
959 }
960
961 $mysqli->close();
962 } else {
963 $json['message'] = 'Something went wrong!';
964 }
965 } else {
966 $json['message'] = 'Only leaders are can cancel a diplomacy request.';
967 }
968 } else {
969 $json['message'] = 'Something went wrong!';
970 }
971
972 return json_encode($json);
973 }
974
975 public static function DeclineDiplomacyRequest($requestId) {
976 $mysqli = Database::GetInstance();
977
978 $player = Functions::GetPlayer();
979 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
980 $requestId = $mysqli->real_escape_string($requestId);
981
982 $json = [
983 'status' => false,
984 'message' => ''
985 ];
986
987
988 if ($clan != NULL) {
989 if ($clan['leaderId'] == $player['userId']) {
990 $statement = $mysqli->query('SELECT id, senderClanId FROM server_clan_diplomacy_applications WHERE toClanId = '.$player['clanId'].' AND id = "'.$requestId.'"');
991 $fetch = $statement->fetch_assoc();
992
993 if ($statement->num_rows >= 1) {
994 $mysqli->begin_transaction();
995
996 try {
997 $mysqli->query('DELETE FROM server_clan_diplomacy_applications WHERE id = '.$fetch['id'].'');
998
999 $senderClanName = $mysqli->query('SELECT name FROM server_clans WHERE id = '.$fetch['senderClanId'].'')->fetch_assoc()['name'];
1000
1001 $json['status'] = true;
1002 $json['message'] = "You declined the ".$senderClanName." clan's diplomacy request.";
1003
1004 $mysqli->commit();
1005 } catch (Exception $e) {
1006 $json['message'] = 'An error occurred. Please try again later.';
1007 $mysqli->rollback();
1008 }
1009
1010 $mysqli->close();
1011 } else {
1012 $json['message'] = 'Something went wrong!';
1013 }
1014 } else {
1015 $json['message'] = 'Only leaders are can cancel a diplomacy request.';
1016 }
1017 } else {
1018 $json['message'] = 'Something went wrong!';
1019 }
1020
1021 return json_encode($json);
1022 }
1023
1024 public static function AcceptDiplomacyRequest($requestId) {
1025 $mysqli = Database::GetInstance();
1026
1027 $player = Functions::GetPlayer();
1028 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
1029 $requestId = $mysqli->real_escape_string($requestId);
1030
1031 $json = [
1032 'status' => false,
1033 'message' => ''
1034 ];
1035
1036 if ($clan != NULL) {
1037 if ($clan['leaderId'] == $player['userId']) {
1038 $statement = $mysqli->query('SELECT * FROM server_clan_diplomacy_applications WHERE toClanId = '.$player['clanId'].' AND id = "'.$requestId.'"');
1039 $fetch = $statement->fetch_assoc();
1040
1041 if ($statement->num_rows >= 1) {
1042 $mysqli->begin_transaction();
1043
1044 try {
1045 $mysqli->query('DELETE FROM server_clan_diplomacy_applications WHERE id = '.$fetch['id'].'');
1046
1047 if ($fetch['diplomacyType'] == 4) {
1048 $diplomacyId = $mysqli->query('SELECT id FROM server_clan_diplomacy WHERE (senderClanId = '.$fetch['senderClanId'].' AND toClanId = '.$fetch['toClanId'].') OR (toClanId = '.$fetch['senderClanId'].' AND senderClanId = '.$fetch['toClanId'].')')->fetch_assoc()['id'];
1049
1050 $mysqli->query('DELETE FROM server_clan_diplomacy WHERE id = '.$diplomacyId.'');
1051
1052 $json['warEnded'] = [
1053 'id' => $diplomacyId
1054 ];
1055
1056 $json['status'] = true;
1057 $json['message'] = 'War ended';
1058
1059 Socket::Send('EndDiplomacy', ['SenderClanId' => $fetch['senderClanId'], 'TargetClanId' => $fetch['toClanId']]);
1060 } else {
1061 $mysqli->query('INSERT INTO server_clan_diplomacy (senderClanId, toClanId, diplomacyType) VALUES ('.$fetch['senderClanId'].', '.$fetch['toClanId'].', '.$fetch['diplomacyType'].')');
1062
1063 $diplomacyId = $mysqli->insert_id;
1064
1065 $senderClanName = $mysqli->query('SELECT name FROM server_clans WHERE id = '.$fetch['senderClanId'].'')->fetch_assoc()['name'];
1066
1067 $form = ($fetch['diplomacyType'] == 1 ? 'Alliance' : ($fetch['diplomacyType'] == 2 ? 'NAP' : 'War'));
1068
1069 $json['acceptedRequest'] = [
1070 'id' => $diplomacyId,
1071 'name' => $senderClanName,
1072 'form' => $form,
1073 'diplomacyType' => $fetch['diplomacyType'],
1074 'date' => date('d.m.Y')
1075 ];
1076
1077 $json['status'] = true;
1078 $json['message'] = "You accepted the ".$senderClanName." clan's diplomacy request.<br>New status: ".$form."";
1079
1080 Socket::Send('StartDiplomacy', ['SenderClanId' => $fetch['senderClanId'], 'TargetClanId' => $fetch['toClanId'], 'DiplomacyType' => $fetch['diplomacyType']]);
1081 }
1082
1083 $mysqli->commit();
1084 } catch (Exception $e) {
1085 $json['message'] = 'An error occurred. Please try again later.';
1086 $mysqli->rollback();
1087 }
1088
1089 $mysqli->close();
1090 } else {
1091 $json['message'] = 'Something went wrong!';
1092 }
1093 } else {
1094 $json['message'] = 'Only leaders are can cancel a diplomacy request.';
1095 }
1096 } else {
1097 $json['message'] = 'Something went wrong!';
1098 }
1099
1100 return json_encode($json);
1101 }
1102
1103 public static function EndDiplomacy($diplomacyId) {
1104 $mysqli = Database::GetInstance();
1105
1106 $player = Functions::GetPlayer();
1107 $clan = $mysqli->query('SELECT * FROM server_clans WHERE id = '.$player['clanId'].'')->fetch_assoc();
1108 $diplomacyId = $mysqli->real_escape_string($diplomacyId);
1109
1110 $json = [
1111 'status' => false,
1112 'message' => ''
1113 ];
1114
1115 if ($clan != NULL) {
1116 if ($clan['leaderId'] == $player['userId']) {
1117 $statement = $mysqli->query('SELECT * FROM server_clan_diplomacy WHERE id = "'.$diplomacyId.'"');
1118 $fetch = $statement->fetch_assoc();
1119
1120 if ($statement->num_rows >= 1 && $fetch['diplomacyType'] != 3) {
1121 $mysqli->begin_transaction();
1122
1123 try {
1124 $mysqli->query('DELETE FROM server_clan_diplomacy WHERE id = '.$diplomacyId.'');
1125
1126 $json['status'] = true;
1127 $json['message'] = 'Diplomacy was ended.';
1128
1129 Socket::Send('EndDiplomacy', ['SenderClanId' => $fetch['senderClanId'], 'TargetClanId' => $fetch['toClanId']]);
1130
1131 $mysqli->commit();
1132 } catch (Exception $e) {
1133 $json['message'] = 'An error occurred. Please try again later.';
1134 $mysqli->rollback();
1135 }
1136
1137 $mysqli->close();
1138 } else {
1139 $json['message'] = 'Something went wrong!';
1140 }
1141 } else {
1142 $json['message'] = 'Only leaders are can end a diplomacy.';
1143 }
1144 } else {
1145 $json['message'] = 'Something went wrong!';
1146 }
1147
1148 return json_encode($json);
1149 }
1150
1151 public static function GetUniqueSessionId() {
1152 $mysqli = Database::GetInstance();
1153
1154 $sessionId = Functions::GenerateRandom(32);
1155
1156 if ($mysqli->query('SELECT userId FROM player_accounts WHERE sessionId = "'.$sessionId.'"')->num_rows >= 1)
1157 $sessionId = GetUniqueSessionId();
1158
1159 return $sessionId;
1160 }
1161
1162 public static function VerifyEmail($userId, $hash) {
1163 $mysqli = Database::GetInstance();
1164
1165 $userId = $mysqli->real_escape_string($userId);
1166 $hash = $mysqli->real_escape_string($hash);
1167
1168 $message = '';
1169
1170 if ($mysqli->query('SELECT userId FROM player_accounts WHERE userId = "'.$userId.'"')->num_rows >= 1) {
1171 $verification = json_decode($mysqli->query('SELECT verification FROM player_accounts WHERE userId = '.$userId.'')->fetch_assoc()['verification']);
1172
1173 if (!$verification->verified) {
1174 if ($verification->hash === $hash) {
1175 $verification->verified = true;
1176
1177 $mysqli->begin_transaction();
1178
1179 try {
1180 $mysqli->query("UPDATE player_accounts SET verification = '".json_encode($verification)."' WHERE userId = ".$userId."");
1181
1182 $message = 'Your account is now verified.';
1183
1184 $mysqli->commit();
1185 } catch (Exception $e) {
1186 $message = 'An error occurred. Please try again later.';
1187 $mysqli->rollback();
1188 }
1189
1190 $mysqli->close();
1191
1192 } else {
1193 $message = 'Hash is not matches.';
1194 }
1195 } else {
1196 $message = 'This account is already verified.';
1197 }
1198 } else {
1199 $message = 'User not found.';
1200 }
1201
1202 return $message;
1203 }
1204
1205 public static function Buy($itemId, $amount) {
1206 $mysqli = Database::GetInstance();
1207
1208 $player = Functions::GetPlayer();
1209 $itemId = $mysqli->real_escape_string($itemId);
1210 $amount = $mysqli->real_escape_string($amount);
1211 $shop = Functions::GetShop();
1212
1213 $json = [
1214 'status' => false,
1215 'message' => ''
1216 ];
1217
1218 if (isset($shop['items'][$itemId]) && $shop['items'][$itemId]['active']) {
1219 $items = json_decode($mysqli->query('SELECT items FROM player_equipment WHERE userId = '.$player['userId'].'')->fetch_assoc()['items']);
1220 $data = json_decode($player['data']);
1221
1222 $price = $shop['items'][$itemId]['price'];
1223
1224 if ($shop['items'][$itemId]['amount'] && $amount <= 0) {
1225 $amount = 1;
1226 }
1227
1228 if ($shop['items'][$itemId]['amount'] && $amount >= 1) {
1229 $price *= $amount;
1230 }
1231
1232 if (($shop['items'][$itemId]['priceType'] == 'uridium' ? $data->uridium : $data->credits) >= $price) {
1233 $data->{($shop['items'][$itemId]['priceType'] == 'uridium' ? 'uridium' : 'credits')} -= $price;
1234
1235 $status = false;
1236
1237 if ($shop['items'][$itemId]['name'] == 'Apis') {
1238 if (!$items->apis) {
1239 $items->apis = true;
1240 $status = true;
1241 } else {
1242 $json['message'] = 'You already have an '.$shop['items'][$itemId]['name'].' Drone.';
1243 }
1244 } else if ($shop['items'][$itemId]['name'] == 'Zeus') {
1245 if (!$items->zeus) {
1246 $items->zeus = true;
1247 $status = true;
1248 } else {
1249 $json['message'] = 'You already have an '.$shop['items'][$itemId]['name'].' Drone.';
1250 }
1251 } else if ($shop['items'][$itemId]['name'] == 'Logdisk') {
1252 $items->skillTree->logdisks += $amount;
1253 $status = true;
1254 }
1255
1256 if ($status) {
1257 $mysqli->begin_transaction();
1258
1259 try {
1260 $mysqli->query("UPDATE player_accounts SET data = '".json_encode($data)."' WHERE userId = ".$player['userId']."");
1261 $mysqli->query("UPDATE player_equipment SET items = '".json_encode($items)."' WHERE userId = ".$player['userId']."");
1262
1263 $json['newStatus'] = [
1264 'uridium' => number_format($data->uridium),
1265 'credits' => number_format($data->credits)
1266 ];
1267
1268 if (Socket::Get('IsOnline', ['UserId' => $player['userId'], 'Return' => false])) {
1269 Socket::Send('BuyItem', ['UserId' => $player['userId'], 'ItemType' => $shop['items'][$itemId]['category'], 'DataType' => ($shop['items'][$itemId]['priceType'] == 'uridium' ? 0 : 1), 'Amount' => $price]);
1270 }
1271
1272 $json['message'] = ''.$shop['items'][$itemId]['name'].' '.($amount != 0 ? '('.number_format($amount).')' : '').' purchased';
1273
1274 $mysqli->commit();
1275 } catch (Exception $e) {
1276 $json['message'] = 'An error occurred. Please try again later.';
1277 $mysqli->rollback();
1278 }
1279
1280 $mysqli->close();
1281 }
1282 } else {
1283 $json['message'] = "You don't have enough " . ($shop['items'][$itemId]['priceType'] == 'uridium' ? 'Uridium' : 'Credits');
1284 }
1285 } else {
1286 $json['message'] = 'Something went wrong!';
1287 }
1288
1289 return json_encode($json);
1290 }
1291
1292 public static function ChangePilotName($newPilotName) {
1293 $mysqli = Database::GetInstance();
1294
1295 $player = Functions::GetPlayer();
1296 $newPilotName = $mysqli->real_escape_string($newPilotName);
1297
1298 $json = [
1299 'inputs' => [
1300 'pilotName' => ['validate' => 'valid', 'error' => 'Enter a valid pilot name!']
1301 ],
1302 'message' => ''
1303 ];
1304
1305 if (mb_strlen($newPilotName) < 4 || mb_strlen($newPilotName) > 20) {
1306 $json['inputs']['pilotName']['validate'] = 'invalid';
1307 $json['inputs']['pilotName']['error'] = 'Your pilot name should be between 4 and 20 characters.';
1308 }
1309
1310 if ($json['inputs']['pilotName']['validate'] === 'valid') {
1311 $oldPilotNames = json_decode($player['oldPilotNames']);
1312
1313 if (count($oldPilotNames) <= 0 || ((new DateTime(date('d.m.Y H:i:s')))->diff(new DateTime(end($oldPilotNames)->date))->days >= 1) || $player['rankId'] == 21) {
1314 if ($mysqli->query('SELECT userId FROM player_accounts WHERE pilotName = "'.$newPilotName.'"')->num_rows <= 0) {
1315 $mysqli->begin_transaction();
1316
1317 try {
1318 array_push($oldPilotNames, ['name' => $player['pilotName'], 'date' => date('d.m.Y H:i:s')]);
1319
1320 $mysqli->query("UPDATE player_accounts SET pilotName = '".$newPilotName."', oldPilotNames = '".json_encode($oldPilotNames, JSON_UNESCAPED_UNICODE)."' WHERE userId = ".$player['userId']."");
1321
1322 $json['message'] = 'Your Pilot name has been changed.';
1323
1324 $mysqli->commit();
1325 } catch (Exception $e) {
1326 $message = 'An error occurred. Please try again later.';
1327 $mysqli->rollback();
1328 }
1329
1330 $mysqli->close();
1331 } else {
1332 $json['message'] = 'This Pilot name is already in use.';
1333 }
1334 } else {
1335 $json['message'] = 'You can only rename your Pilot once every 24 hours. <br> (Your last name change: '.date('d.m.Y H:i', strtotime(end($oldPilotNames)->date)).')';
1336 }
1337 }
1338
1339 return json_encode($json);
1340 }
1341
1342 public static function ExchangeLogdisks() {
1343 $mysqli = Database::GetInstance();
1344
1345 $player = Functions::GetPlayer();
1346
1347 $equipment = $mysqli->query('SELECT skill_points, items FROM player_equipment WHERE userId = '.$player['userId'].'')->fetch_assoc();
1348 $skillPoints = json_decode($equipment['skill_points']);
1349 $items = json_decode($equipment['items']);
1350 $requiredLogdisks = Functions::GetRequiredLogdisks((array_sum((array)json_decode($equipment['skill_points'])) + $items->skillTree->researchPoints) + 1);
1351
1352 $json = [
1353 'message' => ''
1354 ];
1355
1356 if ($items->skillTree->logdisks >= $requiredLogdisks && ((array_sum((array)$skillPoints) + $items->skillTree->researchPoints) < array_sum(array_column(Functions::GetSkills($skillPoints), 'maxLevel')))) {
1357 $items->skillTree->logdisks -= $requiredLogdisks;
1358 $items->skillTree->researchPoints++;
1359
1360 $mysqli->begin_transaction();
1361
1362 try {
1363 $mysqli->query("UPDATE player_equipment SET items = '".json_encode($items)."' WHERE userId = ".$player['userId']."");
1364
1365 $json['newStatus'] = [
1366 'logdisks' => $items->skillTree->logdisks,
1367 'researchPoints' => $items->skillTree->researchPoints,
1368 'researchPointsMaxed' => ((array_sum((array)$skillPoints) + $items->skillTree->researchPoints) == array_sum(array_column(Functions::GetSkills($skillPoints), 'maxLevel'))),
1369 'requiredLogdisks' => Functions::GetRequiredLogdisks((array_sum((array)json_decode($equipment['skill_points'])) + $items->skillTree->researchPoints) + 1)
1370 ];
1371
1372 $json['message'] = 'Log disks exchanged.';
1373
1374 $mysqli->commit();
1375 } catch (Exception $e) {
1376 $json['message'] = 'An error occurred. Please try again later.';
1377 $mysqli->rollback();
1378 }
1379
1380 $mysqli->close();
1381 } else {
1382 $json['message'] = 'Something went wrong!';
1383 }
1384
1385 return json_encode($json);
1386 }
1387
1388 public static function ResetSkills() {
1389 $mysqli = Database::GetInstance();
1390
1391 $player = Functions::GetPlayer();
1392
1393 $equipment = $mysqli->query('SELECT skill_points, items FROM player_equipment WHERE userId = '.$player['userId'].'')->fetch_assoc();
1394 $skillPoints = json_decode($equipment['skill_points']);
1395 $items = json_decode($equipment['items']);
1396 $data = json_decode($player['data']);
1397
1398 $json = [
1399 'status' => false,
1400 'message' => ''
1401 ];
1402
1403 $cost = Functions::GetResetSkillCost($items->skillTree->resetCount);
1404 if ($data->uridium >= $cost) {
1405 $data->uridium -= $cost;
1406 $items->skillTree->resetCount++;
1407
1408 $items->skillTree->researchPoints += array_sum((array)$skillPoints);
1409
1410 foreach ($skillPoints as $key => $value) {
1411 $skillPoints->$key = 0;
1412 }
1413
1414 $mysqli->begin_transaction();
1415
1416 try {
1417 $mysqli->query("UPDATE player_accounts SET data = '".json_encode($data)."' WHERE userId = ".$player['userId']."");
1418
1419 $mysqli->query("UPDATE player_equipment SET items = '".json_encode($items)."', skill_points = '".json_encode($skillPoints)."' WHERE userId = ".$player['userId']."");
1420
1421 $json['status'] = true;
1422 $json['message'] = 'Research points resetted.';
1423
1424 if (Socket::Get('IsOnline', ['UserId' => $player['userId'], 'Return' => false])) {
1425 Socket::Send('ResetSkillTree', ['UserId' => $player['userId']]);
1426 }
1427
1428 $mysqli->commit();
1429 } catch (Exception $e) {
1430 $json['message'] = 'An error occurred. Please try again later.';
1431 $mysqli->rollback();
1432 }
1433
1434 $mysqli->close();
1435 } else {
1436 $json['message'] = "You don't have enough Uridium.";
1437 }
1438
1439 return json_encode($json);
1440 }
1441
1442 public static function UseResearchPoints($skill) {
1443 $mysqli = Database::GetInstance();
1444
1445 $player = Functions::GetPlayer();
1446 $skill = $mysqli->real_escape_string($skill);
1447
1448 $equipment = $mysqli->query('SELECT skill_points, items FROM player_equipment WHERE userId = '.$player['userId'].'')->fetch_assoc();
1449 $skillPoints = json_decode($equipment['skill_points']);
1450 $items = json_decode($equipment['items']);
1451
1452 $skills = Functions::GetSkills($skillPoints);
1453
1454 $json = [
1455 'message' => ''
1456 ];
1457
1458 if (array_key_exists($skill, $skills) && isset($skillPoints->{$skill}) && (!isset($skills[$skill]['baseSkill']) || (isset($skills[$skill]['baseSkill']) && $skills[$skills[$skill]['baseSkill']]['currentLevel'] == $skills[$skills[$skill]['baseSkill']]['maxLevel']))) {
1459 if ($items->skillTree->researchPoints >= 1 && $skillPoints->{$skill} < $skills[$skill]['maxLevel']) {
1460 $items->skillTree->researchPoints--;
1461 $skillPoints->{$skill}++;
1462
1463 $mysqli->begin_transaction();
1464
1465 try {
1466 $mysqli->query("UPDATE player_equipment SET items = '".json_encode($items)."', skill_points = '".json_encode($skillPoints)."' WHERE userId = ".$player['userId']."");
1467
1468 $json['newStatus'] = [
1469 'researchPoints' => $items->skillTree->researchPoints,
1470 'currentLevel' => $skillPoints->{$skill},
1471 'usedResearchPoints' => array_sum((array)$skillPoints),
1472 'isMaxed' => $skillPoints->{$skill} == $skills[$skill]['maxLevel'],
1473 'tooltip' => Functions::GetSkillTooltip($skills[$skill]['name'], $skillPoints->{$skill}, $skills[$skill]['maxLevel'])
1474 ];
1475
1476 if ($json['newStatus']['isMaxed'] && isset($skills[$skill]['nextSkill'])) {
1477 $json['newStatus']['nextSkill'] = $skills[$skill]['nextSkill'];
1478 }
1479
1480 if (Socket::Get('IsOnline', ['UserId' => $player['userId'], 'Return' => false])) {
1481 Socket::Send('UpgradeSkillTree', ['UserId' => $player['userId'], 'Skill' => $skill]);
1482 }
1483
1484 $mysqli->commit();
1485 } catch (Exception $e) {
1486 $json['message'] = 'An error occurred. Please try again later.';
1487 $mysqli->rollback();
1488 }
1489
1490 $mysqli->close();
1491 } else {
1492 $json['message'] = 'Something went wrong!';
1493 }
1494 } else {
1495 $json['message'] = 'Something went wrong!';
1496 }
1497
1498 return json_encode($json);
1499 }
1500
1501 public static function GetShop() {
1502 return [
1503 'categories' => ['drones', 'extras'],
1504 'items' => [
1505 [
1506 'id' => 0,
1507 'category' => 'drones',
1508 'name' => 'Apis',
1509 'price' => 100000,
1510 'priceType' => 'uridium',
1511 'amount' => false,
1512 'image' => 'do_img/global/items/drone/apis-5_top.png',
1513 'active' => true
1514 ],
1515 [
1516 'id' => 1,
1517 'category' => 'drones',
1518 'name' => 'Zeus',
1519 'price' => 100000,
1520 'priceType' => 'uridium',
1521 'amount' => false,
1522 'image' => 'do_img/global/items/drone/zeus-5_top.png',
1523 'active' => true
1524 ],
1525 [
1526 'id' => 2,
1527 'category' => 'extras',
1528 'name' => 'Logdisk',
1529 'price' => 50,
1530 'priceType' => 'uridium',
1531 'amount' => true,
1532 'image' => 'do_img/global/items/resource/logfile_100x100.png',
1533 'active' => true
1534 ]
1535 ]
1536 ];
1537 }
1538
1539 public static function GetResetSkillCost($resetCount) {
1540 $cost = 1000;
1541
1542 for ($i = 0; $i < $resetCount; $i++) {
1543 $cost *= 2;
1544 }
1545
1546 return $cost;
1547 }
1548
1549 public static function GetSkillDescription($skill, $level) {
1550 $array = [
1551 'Engineering' => 'Lets your repair bots repair '.($level <= 1 ? '5' : ($level == 2 ? '10' : ($level == 3 ? '15' : ($level == 4 ? '20' : ($level == 5 ? '30' : '0'))))).'% more HP<br> per second',
1552 'Shield Engineering' => 'Increases your shield strength by '.($level <= 1 ? '4' : ($level == 2 ? '8' : ($level == 3 ? '12' : ($level == 4 ? '18' : ($level == 5 ? '25' : '0'))))).'%',
1553 'Detonation I' => 'Makes your mines cause '.($level <= 1 ? '7' : ($level == 2 ? '14' : 0)).'% more damage',
1554 'Detonation II' => 'Makes your mines cause '.($level <= 1 ? '21' : ($level == 2 ? '28' : ($level == 3 ? '50' : 0))).'% more damage',
1555 'Heat-seeking Missiles' => 'Increases hit probability of your rockets by '.($level <= 1 ? '1' : ($level == 2 ? '2' : ($level == 3 ? '4' : ($level == 4 ? '6' : ($level == 5 ? '10' : '0'))))).'%',
1556 'Rocket Fusion' => 'Makes your rockets cause '.($level <= 1 ? '2' : ($level == 2 ? '2' : ($level == 3 ? '4' : ($level == 4 ? '6' : ($level == 5 ? '10' : '0'))))).'% more damage',
1557 'Cruelty I' => 'Gives you '.($level <= 1 ? '4' : ($level == 2 ? '8' : 0)).'% more honor points',
1558 'Cruelty II' => 'Gives you '.($level <= 1 ? '12' : ($level == 2 ? '18' : ($level == 3 ? '25' : 0))).'% more honor points',
1559 'Explosives' => 'Increases the radius of mine explosions by '.($level <= 1 ? '4' : ($level == 2 ? '8' : ($level == 3 ? '12' : ($level == 4 ? '18' : ($level == 5 ? '25' : '0'))))).'%',
1560 'Luck I' => 'Gives you '.($level <= 1 ? '2' : ($level == 2 ? '4' : 0)).'% more bonus-box Uridium',
1561 'Luck II' => 'Gives you '.($level <= 1 ? '6' : ($level == 2 ? '8' : ($level == 3 ? '12' : 0))).'% more bonus-box Uridium'
1562 ];
1563
1564 return $array[$skill];
1565 }
1566
1567 public static function GetSkillTooltip($skillName, $currentLevel, $maxLevel) {
1568 return 'Name: <span style=\'color: #a4d3ef;\'>'.$skillName.'</span><br>Level: <span style=\'color: #a4d3ef;\'>'.$currentLevel.'/'.$maxLevel.'</span>'.($currentLevel != 0 ? '<br>Current Level: <span style=\'color: #a4d3ef;\'>'.Functions::GetSkillDescription($skillName, $currentLevel).'</span>' : '').''.($currentLevel != $maxLevel ? '<br>Next Level: <span style=\'color: #a4d3ef;\'>'.Functions::GetSkillDescription($skillName, $currentLevel + 1).'</span>' : '').'';
1569 }
1570
1571 public static function GetSkills($skillPoints) {
1572 return [
1573 'engineering' => [
1574 'name' => 'Engineering',
1575 'currentLevel' => $skillPoints->engineering,
1576 'maxLevel' => 5
1577 ],
1578 'shieldEngineering' => [
1579 'name' => 'Shield Engineering',
1580 'currentLevel' => $skillPoints->shieldEngineering,
1581 'maxLevel' => 5
1582 ],
1583 'detonation1' => [
1584 'name' => 'Detonation I',
1585 'currentLevel' => $skillPoints->detonation1,
1586 'maxLevel' => 2,
1587 'nextSkill' => 'detonation2'
1588 ],
1589 'detonation2' => [
1590 'name' => 'Detonation II',
1591 'currentLevel' => $skillPoints->detonation2,
1592 'maxLevel' => 3,
1593 'baseSkill' => 'detonation1'
1594 ],
1595 'heatseekingMissiles' => [
1596 'name' => 'Heat-seeking Missiles',
1597 'currentLevel' => $skillPoints->heatseekingMissiles,
1598 'maxLevel' => 5
1599 ],
1600 'rocketFusion' => [
1601 'name' => 'Rocket Fusion',
1602 'currentLevel' => $skillPoints->rocketFusion,
1603 'maxLevel' => 5
1604 ],
1605 'cruelty1' => [
1606 'name' => 'Cruelty I',
1607 'currentLevel' => $skillPoints->cruelty1,
1608 'maxLevel' => 2,
1609 'nextSkill' => 'cruelty2'
1610 ],
1611 'cruelty2' => [
1612 'name' => 'Cruelty II',
1613 'currentLevel' => $skillPoints->cruelty2,
1614 'maxLevel' => 3,
1615 'baseSkill' => 'cruelty1'
1616 ],
1617 'explosives' => [
1618 'name' => 'Explosives',
1619 'currentLevel' => $skillPoints->explosives,
1620 'maxLevel' => 5
1621 ],
1622 'luck1' => [
1623 'name' => 'Luck I',
1624 'currentLevel' => $skillPoints->luck1,
1625 'maxLevel' => 2,
1626 'nextSkill' => 'luck2'
1627 ],
1628 'luck2' => [
1629 'name' => 'Luck II',
1630 'currentLevel' => $skillPoints->luck2,
1631 'maxLevel' => 3,
1632 'baseSkill' => 'luck1'
1633 ]
1634 ];
1635 }
1636
1637 public static function ChangeVersion($version) {
1638 $mysqli = Database::GetInstance();
1639
1640 $player = Functions::GetPlayer();
1641 $version = $mysqli->real_escape_string($version);
1642
1643 $json = [
1644 'message' => ''
1645 ];
1646
1647 if ($version === 'false' || $version === 'true') {
1648 $mysqli->begin_transaction();
1649
1650 try {
1651 $mysqli->query('UPDATE player_accounts SET version = '.$version.' WHERE userId = '.$player['userId'].'');
1652
1653 $json['message'] = 'Your version has been changed.';
1654
1655 $mysqli->commit();
1656 } catch (Exception $e) {
1657 $message = 'An error occurred. Please try again later.';
1658 $mysqli->rollback();
1659 }
1660
1661 $mysqli->close();
1662 } else {
1663 $json['message'] = 'Something went wrong!';
1664 }
1665
1666 return json_encode($json);
1667 }
1668
1669 public static function GetLevel($exp) {
1670 $lvl = 1;
1671 $expNext = 10000;
1672
1673 while ($exp >= $expNext) {
1674 $expNext *= 2;
1675 $lvl++;
1676 }
1677
1678 return $lvl;
1679 }
1680
1681 public static function GetUniquePilotName($pilotName) {
1682 $mysqli = Database::GetInstance();
1683
1684 $newPilotName = $pilotName .= Functions::GenerateRandom(4, true, false, false);
1685
1686 if ($mysqli->query('SELECT userId FROM player_accounts WHERE pilotName = "'.$newPilotName.'"')->num_rows >= 1)
1687 $newPilotName = GetUniquePilotName($pilotName);
1688
1689 return $newPilotName;
1690 }
1691
1692 public static function GetIP() {
1693 if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
1694 $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
1695 $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
1696 }
1697
1698 $client = @$_SERVER['HTTP_CLIENT_IP'];
1699 $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
1700 $remote = $_SERVER['REMOTE_ADDR'];
1701
1702 if(filter_var($client, FILTER_VALIDATE_IP)) {
1703 $ip = $client;
1704 } else if(filter_var($forward, FILTER_VALIDATE_IP)) {
1705 $ip = $forward;
1706 } else {
1707 $ip = $remote;
1708 }
1709
1710 return $ip;
1711 }
1712
1713 public static function GenerateRandom($length, $numbers = true, $letters = true, $uppercase = true) {
1714 $chars = '';
1715 $chars .= ($numbers) ? '0123456789' : '';
1716 $chars .= ($uppercase) ? 'QWERTYUIOPASDFGHJKLLZXCVBNM' : '';
1717 $chars .= ($letters) ? 'qwertyuiopasdfghjklzxcvbnm' : '';
1718
1719 $str = '';
1720 $c = 0;
1721 while ($c < $length){
1722 $str .= substr($chars, rand(0, mb_strlen($chars) -1), 1);
1723 $c++;
1724 }
1725
1726 return $str;
1727 }
1728
1729 public static function s($input) {
1730 return htmlspecialchars(trim($input));
1731 }
1732
1733 public static function IsLoggedIn() {
1734 $mysqli = Database::GetInstance();
1735
1736 if (!MAINTENANCE && !$mysqli->connect_errno) {
1737 if (isset($_SESSION['account'])) {
1738 if (isset($_SESSION['account']['id'], $_SESSION['account']['session'])) {
1739 $id = $mysqli->real_escape_string(Functions::s($_SESSION['account']['id']));
1740 $fetch = $mysqli->query('SELECT sessionId FROM player_accounts WHERE userId = '.$id.'')->fetch_assoc();
1741
1742 if ($fetch['sessionId'] === $_SESSION['account']['session']) {
1743 return true;
1744 } else {
1745 return false;
1746 }
1747 } else {
1748 return false;
1749 }
1750 } else {
1751 return false;
1752 }
1753 } else {
1754 return false;
1755 }
1756 }
1757
1758 public static function GetRankName($rankId) {
1759 $array = [
1760 '1' => 'Basic Space Pilot',
1761 '2' => 'Space Pilot',
1762 '3' => 'Chief Space Pilot',
1763 '4' => 'Basic Sergeant',
1764 '5' => 'Sergeant',
1765 '6' => 'Chief Sergeant',
1766 '7' => 'Basic Lieutenant',
1767 '8' => 'Lieutenant',
1768 '9' => 'Chief Lieutenant',
1769 '10' => 'Basic Captain',
1770 '11' => 'Captain',
1771 '12' => 'Chief Captain',
1772 '13' => 'Basic Major',
1773 '14' => 'Major',
1774 '15' => 'Chief Major',
1775 '16' => 'Basic Colonel',
1776 '17' => 'Colonel',
1777 '18' => 'Chief Colonel',
1778 '19' => 'Basic General',
1779 '20' => 'General',
1780 '21' => 'Administrator',
1781 '22' => 'Wanted'
1782 ];
1783
1784 return $array[$rankId];
1785 }
1786
1787 public static function GetRequiredLogdisks($sumPoints) {
1788 $array = array(
1789 '1' => '30',
1790 '2' => '63',
1791 '3' => '99',
1792 '4' => '139',
1793 '5' => '183',
1794 '6' => '231',
1795 '7' => '284',
1796 '8' => '342',
1797 '9' => '406',
1798 '10' => '477',
1799 '11' => '555',
1800 '12' => '641',
1801 '13' => '735',
1802 '14' => '839',
1803 '15' => '953',
1804 '16' => '1078',
1805 '17' => '1216',
1806 '18' => '1368',
1807 '19' => '1535',
1808 '20' => '1718',
1809 '21' => '1920',
1810 '22' => '2142',
1811 '23' => '2386',
1812 '24' => '2655',
1813 '25' => '2950',
1814 '26' => '3275',
1815 '27' => '3633',
1816 '28' => '4026',
1817 '29' => '4459',
1818 '30' => '4935',
1819 '31' => '5458',
1820 '32' => '6034',
1821 '33' => '6667',
1822 '34' => '7364',
1823 '35' => '8130',
1824 '36' => '8973',
1825 '37' => '9900',
1826 '38' => '10920',
1827 '39' => '12042',
1828 '40' => '13276',
1829 '41' => '14634',
1830 '42' => '16128',
1831 '43' => '17771',
1832 '44' => '19578',
1833 '45' => '21566',
1834 '46' => '23753',
1835 '47' => '26158',
1836 '48' => '28804',
1837 '49' => '31715',
1838 '50' => '34917'
1839 );
1840
1841 return isset($array[$sumPoints]) ? $array[$sumPoints] : '0';
1842 }
1843
1844 public static function GetPlayer() {
1845 $mysqli = Database::GetInstance();
1846
1847 if (isset($_SESSION['account']['id'])) {
1848 $id = $mysqli->real_escape_string(Functions::s($_SESSION['account']['id']));
1849 return $mysqli->query('SELECT * FROM player_accounts WHERE userId = '.$id.'')->fetch_assoc();
1850 } else {
1851 return null;
1852 }
1853 }
1854}
1855
1856?>
1857