-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_playerData.php
1487 lines (1377 loc) · 52.1 KB
/
request_playerData.php
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* Gladiatus Battle Simulator by Gladiatus Crazy Team
* https://github.com/DinoDevs
* https://www.facebook.com/GladiatusCrazyAddOn
* Authors : GramThanos, GreatApo
*
* Gladiatus Player Data Get Library
*/
/*
Example Use
$stats = getPlayerData(
array(
'country' => 'gr',
'server' => '4',
'name' => 'darkthanos',
'id' => null
),
array(
'profile' => true,
'statistics' => false,
'achievements' => false,
'turma' => false
)
);
*/
/*
Validate Functions
*/
// Country Validate
function request_validate_country ($country) {
switch ($country) {
// 31 servers
case 'ar': case 'ba': case 'br': case 'dk': case 'de': case 'ee': case 'es': case 'fr': case 'it': case 'lv': case 'lt': case 'hu': case 'mx': case 'nl': case 'no': case 'pl': case 'pt': case 'ro': case 'sk': case 'fi': case 'se': case 'tr': case 'us': case 'en': case 'cz': case 'gr': case 'bg': case 'ru': case 'il': case 'ae': case 'tw':
return true;
break;
default:
return false;
break;
}
}
// Validate Server
function request_validate_server ($server) {
if (!preg_match("/^[1-9][0-9]*$/i", $server)) {
return false;
}
return true;
}
// Validate Player Name
function request_validate_name ($name) {
if (!preg_match('/^[^~#&\\[\\]\\{\\}\|\\/\'\\";:?,<>]{3,15}$/', $name)) {
return false;
}
return true;
}
// Validate Player ID
function request_validate_id ($id) {
if (!preg_match("/^[1-9][0-9]*$/i", $id)) {
return false;
}
return true;
}
/*
Help Functions
*/
// If server is in backup mode
function isSeverInBackUpMode ($html) {
if (strpos($html, '<h2 id="logoGladiatus_infobox"></h2>') !== false) {
return true;
}
return false;
}
/*
Cache Functions
*/
// Cache Variable
$request_cache = array();
// Load a cache
// This needs more options
// like a global on/off option and a folder location option
function request_cache_load($country, $server) {
// Pointer to cache variable
global $request_cache;
// Load Cache File
$cache = @file_get_contents(dirname(__File__).'/request_playerData_cache/'.$country.'_'.$server.'.json');
// If country section do not exist create
if (!isset($request_cache[$country])) {
$request_cache[$country] = array();
}
// Check if cache exist
if (!$cache) {
return false;
}
// Parse cache
$cache = json_decode($cache, true);
if (is_null($cache) || !$cache) {
return false;
}
// Save cache
$request_cache[$country][$server] = $cache;
// Return
return true;
}
// Check the cache exist
function request_cache_check($country, $server) {
// Pointer to cache variable
global $request_cache;
// If cache not loaded
if (!isset($request_cache[$country]) || !isset($request_cache[$country][$server])) {
// Load cache
request_cache_load($country, $server);
// No cache
if (!isset($request_cache[$country][$server])) {
return false;
}
}
return true;
}
// Check the cache if name exist
function request_cache_check_name($country, $server, $name) {
// Pointer to cache variable
global $request_cache;
// Check cache ready
if (!request_cache_check($country, $server)) {
return false;
}
$name = strtolower($name);
// Check if player exist on cache
if (isset($request_cache[$country][$server][$name])) {
// Return data
return $request_cache[$country][$server][$name];
}
return false;
}
// Check the cache if id exist
function request_cache_check_id($country, $server, $id) {
// Pointer to cache variable
global $request_cache;
// Check cache ready
if (!request_cache_check($country, $server)) {
return false;
}
// Check if player exist on cache
if (isset($request_cache[$country][$server]['id'][$id])) {
// Return data
$cache = $request_cache[$country][$server]['id'][$id];
// If data exist too
if (isset($request_cache[$country][$server][$cache['name']])) {
// Return data
return $request_cache[$country][$server][$cache['name']];
}
// Insert more data
$cache['id'] = $id;
$cache['game'] = array(
'country' => $country,
'server' => $server
);
// Return data
return $cache;
}
return false;
}
// Save
function request_cache_save($country, $server) {
// Pointer to cache variable
global $request_cache;
// Save Cache File
$cache = @file_put_contents(dirname(__File__).'/request_playerData_cache/'.$country.'_'.$server.'.json', json_encode($request_cache[$country][$server]));
if (!$cache) {
return false;
}
return true;
}
function request_cache_save_search($country, $server, $data) {
// Pointer to cache variable
global $request_cache;
// Check if exist
if (!isset($request_cache[$country][$server])) {
$request_cache[$country][$server] = array();
if (!isset($request_cache[$country][$server]['id'])) {
$request_cache[$country][$server]['id'] = array();
}
}
$request_cache[$country][$server]['id'][$data['id']] = array(
'name' => $data['name']
);
$request_cache[$country][$server][strtolower($data['name'])] = array(
'id' => $data['id']
);
}
function request_cache_remove_by_id($country, $server, $id) {
// Pointer to cache variable
global $request_cache;
// Check if exist
if (!isset($request_cache[$country][$server])) {
$request_cache[$country][$server] = array();
if (!isset($request_cache[$country][$server]['id'])) {
$request_cache[$country][$server]['id'] = array();
}
}
// Check if id is cached
if (!isset($request_cache[$country][$server]['id'][$id])) {
$name = $request_cache[$country][$server]['id'][$id]['name'];
uset($request_cache[$country][$server]['id'][$id]);
if (!isset($request_cache[$country][$server][strtolower($name)])) {
uset($request_cache[$country][$server][strtolower($name)]);
}
}
}
/*
Request Functions
*/
// Make a player search by name request
function request_searchPlayerByName($country, $server, $name) {
// Check cashe
$cache = request_cache_check_name($country, $server, $name);
if ($cache) {
return $cache;
}
// Post data and get search results
$html = @file_get_contents(
'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/index.php?mod=highscore&submod=suche',
false,
stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(array('s' => 's', 'xs' => $name))
)
))
);
// On request error
if (!$html) {
// Return page not found error
return array(
'error' => true,
'message' => 'Our monkeys-workers failed to complete the task.'
);
}
// Shrink string by deleting useless data
$html = substr($html, 40000, -2000);
// Check if backup
if (isSeverInBackUpMode($html)) {
return array(
'error' => true, 'backup' => true,
'message' => 'Gladiatus server is in backup mode.'
);
}
// Match results patterns
$found = preg_match_all('/<a\\s+href="index\\.php\\?mod=player&p=(\\d+)[^>]+>\\s*([^<]+)<\\/a>(<a href="index\\.php\\?mod=guild&i=(\\d+)[^>]+>\\s*([^<]+)<\\/a>)*/', $html, $matches);
// Check if no player was found
$index = 0;
if($found && $matches[2][0] != $name ){
$found = false;
for ($i = 0; $i < count($matches[1]); $i++) {
if($matches[2][$i] == $name){
$found = true;
$index = $i;
break;
}
}
}
if (!$found) {
return array(
'error' => true,
'message' => 'Player not found.'
);
}
// Create player object
$player = array(
'name' => $matches[2][0],
'id' => $matches[1][0]
);
// Cache it
for ($i = 0; $i < count($matches[1]); $i++) {
request_cache_save_search($country, $server, array(
'name' => $matches[2][$i],
'id' => $matches[1][$i]
));
}
request_cache_save($country, $server);
// Insert guild if any
if (isset($matches[4]) && strlen($matches[4][0]) > 0) {
$player['guild'] = array(
'tag' => $matches[5][0],
'id' => $matches[4][0]
);
}
// Game server info
$player['game'] = array(
'country' => $country,
'server' => $server
);
// Return the object
return $player;
}
// Request player's profile page data
function request_getPlayerProfileData($country, $server, $id) {
// Get profile page code
$html = @file_get_contents(
'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/index.php?mod=player&p='.$id,
false,
stream_context_create(array(
'http' => array('method' => 'GET')
))
);
// On request error
if (!$html) {
// Return page not found error
return array(
'error' => true,
'message' => 'Our monkeys-workers failed to complete the task.'
);
}
// Shrink string by deleting useless data
$html = substr($html, 40000, -2000);
// Check if backup
if (isSeverInBackUpMode($html)) {
return array(
'error' => true, 'backup' => true,
'message' => 'Gladiatus server is in backup mode.'
);
}
// Check if player was not found
$found = preg_match('/<article>[^<]*<h2 class="section-header">[^<]*<\/h2>[^<]*<section style="[^"]+" id="exitMessage">[^<]+<\/section>[^<]*<\/article>/', $html, $matches);
if ($found) {
request_cache_remove_by_id($country, $server, $id);
request_cache_save($country, $server);
return array('error' => true,'message' => 'Failed to load player data. Maybe this was a cache problem.');
}
// Create player object
$player = array(
'id' => $id,
'name' => NULL,
'profile' => array(),
'game' => array(
'country' => $country,
'server' => $server
)
);
// Get player's name
$found = preg_match('/<div class="playername(_achievement)* ellipsis">([^<]+)<\\/div>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [001].');}
$player['name'] = preg_replace('/\s+/', '', $matches[2]);
// Get player's image
$found = preg_match('/<div id="avatar" class="player_picture"[^>]*>[^<]*(<[^>]*>)/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [002].');}
$found = preg_match('/background-image: *url\\(([^\\)]+)\\);*/', $matches[1], $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [003].');}
$player['img'] = 'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/'.$matches[1];
$custom_img = false;
$found = preg_match('/##GTI=(http[^#]+)##/', $html, $matches);
if ($found) {
//##GTI=http://i617.photobucket.com/albums/tt260/goldisever/GCAO/dragoni.jpg##
$found = preg_match('/(\\.png|\\.jpeg|\\.jpg|\\.gif|\\.bmp)$/', $matches[1]);
if ($found) {
$player['img'] = $matches[1];
$custom_img = true;
}
}
if(!$custom_img){
//avatar avatar_costume_part
$found = preg_match_all('/"avatar avatar_costume_part"[^>]+/', $html, $matches);
if ($found) {
$player['img'] = [];
foreach ($matches[0] as $image_part) {
$found = preg_match('/background-image: *url\\(([^\\)]+)\\);*/', $image_part, $matches_image_part);
array_push($player['img'], 'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/'.$matches_image_part[1]);
}
}
}
// Get guild info
$found = preg_match('/<a href="index.php\\?mod=guild&i=(\\d+)">([^ ]+) \\[([^<]+)\\]<\\/a>/', $html, $matches);
if ($found) {
$player['guild'] = array();
$player['guild']['id'] = $matches[1];
$player['guild']['name'] = $matches[2];
$player['guild']['tag'] = $matches[3];
}
// Get player's level
$found = preg_match('/<span id="char_level" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [004].');}
$player['profile']['level'] = $matches[1];
// Get player's life
$found = preg_match('/<div\\s+class="charstats_bg"\\s+id="char_leben_tt"\\s+data-tooltip="\\[\\[\\[\\[[^,]+,"(\\d+)\\s*\\\\\\/\\s*(\\d+)"/', $html, $matches);
if (!$found) {
return array('error' => true,'message' => 'Internal parse error [005].');
}
$player['profile']['life'] = array(
$matches[1],
$matches[2]
);
// Get player's experience
$found = preg_match('/<div\\s+class="charstats_bg"\\s+id="char_exp_tt"\\s+data-tooltip="\\[\\[\\[\\[[^,]+,"(\\d+)\\s*\\\\\\/\\s*(\\d+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [006].');}
$player['profile']['experience'] = array(
$matches[1],
$matches[2]
);
// Get player's strength
$found = preg_match('/<span id="char_f0" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [007].');}
$player['profile']['strength'] = $matches[1];
// Get player's skill
$found = preg_match('/<span id="char_f1" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [008].');}
$player['profile']['skill'] = $matches[1];
// Get player's agility
$found = preg_match('/<span id="char_f2" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [009].');}
$player['profile']['agility'] = $matches[1];
// Get player's constitution
$found = preg_match('/<span id="char_f3" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [010].');}
$player['profile']['constitution'] = $matches[1];
// Get player's charisma
$found = preg_match('/<span id="char_f4" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [011].');}
$player['profile']['charisma'] = $matches[1];
// Get player's intelligence
$found = preg_match('/<span id="char_f5" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [012].');}
$player['profile']['intelligence'] = $matches[1];
// Get player's armor
$found = preg_match('/<span id="char_panzer" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [013].');}
$player['profile']['armor'] = $matches[1];
// Get player's damage
$found = preg_match('/<span id="char_schaden" class="charstats_value22">(\\d+)\\s*-\\s*(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [014].');}
$player['profile']['damage'] = array(
$matches[1],
$matches[2]
);
// Get player's healing
$found = preg_match('/<span id="char_healing" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [015].');}
$player['profile']['healing'] = $matches[1];
// Find criticals
$found = preg_match_all('/",(-?\\d+)],\s*\\["#BA9700","#BA9700"\\]\\]/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [016].');}
if (count($matches[1]) <= 10) {return array('error' => true,'message' => 'Internal parse error [016].');}
$player['profile']['avoid-critical-points'] = $matches[1][7];
$player['profile']['block-points'] = $matches[1][8];
$player['profile']['critical-points'] = $matches[1][9];
$player['profile']['critical-healing'] = $matches[1][11];
// Find criticals
$found = preg_match_all('/","(\d+) %"\],\["#DDDDDD","#DDDDDD"\]\]/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [017].');}
if (count($matches[1]) < 4) {return array('error' => true,'message' => 'Internal parse error [017].');}
$player['profile']['avoid-critical-percent'] = $matches[1][0];
$player['profile']['block-percent'] = $matches[1][1];
$player['profile']['critical-percent'] = $matches[1][2];
$player['profile']['critical-healing-percent'] = $matches[1][3];
// Buffs
$player['profile']['buffs'] = array(
'minerva' => false, // Can't detect
'mars' => false, // Can't detect
'apollo' => false, // Can't detect
'honour_veteran' => false,
'honour_destroyer' => false // Can't detect
);
$level_factor = $player['profile']['level'] - 8;
if($level_factor < 2) $level_factor = 2;
// Detect buff honour of the veteran
if ($player['profile']['critical-percent'] - round($player['profile']['critical-points'] * 52 / $level_factor / 5) == 10) {
$player['profile']['buffs']['honour_veteran'] = true;
}
// Return the object
return $player;
}
// Request player's turma players data
function request_getPlayerTurmaData($country, $server, $id) {
// Players array
$turma_data = array(
'id' => $id,
'players' => array(),
'game' => array(
'country' => $country,
'server' => $server
)
);
// Get main player data
$data = request_getPlayerTurmaPlayerData($country, $server, $id, 0, true);
if (isset($data['error'])) {return $data;}
$team = $data['team'];
$data['player']['role'] = $team['0'];
array_push($turma_data['players'], $data['player']);
// Get player 1
if ($team['1']) {
$data = request_getPlayerTurmaPlayerData($country, $server, $id, 1);
if (isset($data['error'])) {return $data;}
$data['player']['role'] = $team['1'];
array_push($turma_data['players'], $data['player']);
}
// Get player 2
if ($team['2']) {
$data = request_getPlayerTurmaPlayerData($country, $server, $id, 2);
if (isset($data['error'])) {return $data;}
$data['player']['role'] = $team['2'];
array_push($turma_data['players'], $data['player']);
}
// Get player 3
if ($team['3']) {
$data = request_getPlayerTurmaPlayerData($country, $server, $id, 3);
if (isset($data['error'])) {return $data;}
$data['player']['role'] = $team['3'];
array_push($turma_data['players'], $data['player']);
}
// Get player 4
if ($team['4']) {
$data = request_getPlayerTurmaPlayerData($country, $server, $id, 4);
if (isset($data['error'])) {return $data;}
$data['player']['role'] = $team['4'];
array_push($turma_data['players'], $data['player']);
}
return $turma_data;
}
// Request player's turma player data
function request_getPlayerTurmaPlayerData($country, $server, $id, $player_index, $getOtherPlayers = false) {
// Get profile page code
$html = @file_get_contents(
'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/index.php?mod=player&doll='.($player_index+2).'&p='.$id,
false,
stream_context_create(array(
'http' => array('method' => 'GET')
))
);
// On request error
if (!$html) {
// Return page not found error
return array(
'error' => true,
'message' => 'Our monkeys-workers failed to complete the task.'
);
}
// Shrink string by deleting useless data
$htmlStartPos = strpos($html, '<div id="content">');
$html = substr($html, ($htmlStartPos ? $htmlStartPos : 30000), -2000);
// Check if backup
if (isSeverInBackUpMode($html)) {
return array(
'error' => true, 'backup' => true,
'message' => 'Gladiatus server is in backup mode.'
);
}
// Create player object
$data = array(
'player' => array(),
'team' => array(
'0' => false,
'1' => false,
'2' => false,
'3' => false,
'4' => false
)
);
// Get player's name
$found = preg_match('/<div class="playername(_achievement)* ellipsis">([^<]+)<\\/div>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T001].');}
$data['player']['name'] = trim($matches[2]);
// Get player's level
$found = preg_match('/<span id="char_level" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T002].');}
$data['player']['level'] = $matches[1];
// Get player's life
$found = preg_match('/<div\\s+class="charstats_bg"\\s+id="char_leben_tt"\\s+data-tooltip="\\[\\[\\[\\[[^,]+,"(\\d+)\\s*\\\\\\/\\s*(\\d+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T003].');}
$data['player']['life'] = array(
$matches[1],
$matches[2]
);
// Get player's strength
$found = preg_match('/<span id="char_f0" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T004].');}
$data['player']['strength'] = $matches[1];
// Get player's skill
$found = preg_match('/<span id="char_f1" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T005].');}
$data['player']['skill'] = $matches[1];
// Get player's agility
$found = preg_match('/<span id="char_f2" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T006].');}
$data['player']['agility'] = $matches[1];
// Get player's constitution
$found = preg_match('/<span id="char_f3" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T007].');}
$data['player']['constitution'] = $matches[1];
// Get player's charisma
$found = preg_match('/<span id="char_f4" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T008].');}
$data['player']['charisma'] = $matches[1];
// Get player's intelligence
$found = preg_match('/<span id="char_f5" class="charstats_value">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T009].');}
$data['player']['intelligence'] = $matches[1];
// Get player's armor
$found = preg_match('/<span id="char_panzer" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T010].');}
$data['player']['armor'] = $matches[1];
// Get player's damage
$found = preg_match('/<span id="char_schaden" class="charstats_value22">(\\d+)\\s*-\\s*(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T011].');}
$data['player']['damage'] = array(
$matches[1],
$matches[2]
);
// Get player's healing
$found = preg_match('/<span id="char_healing" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T012].');}
$data['player']['healing'] = $matches[1];
// Get player's threat
$found = preg_match('/<span id="char_threat" class="charstats_value22">(\\d+)<\\/span>/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T013].');}
$data['player']['threat'] = $matches[1];
// Find criticals
$found = preg_match_all('/",(\\d+)],\s*\\["#BA9700","#BA9700"\\]\\]/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [016].');}
if (count($matches[1]) <= 10) {return array('error' => true,'message' => 'Internal parse error [016].');}
// Get player's avoid critical points
$data['player']['avoid-critical-points'] = $matches[1][7];
// Get player's block points
$data['player']['block-points'] = $matches[1][8];
// Get player's critical points
$data['player']['critical-points'] = $matches[1][9];
// Get player's critical healing
$data['player']['critical-healing'] = isset($matches[1][12]) ? $matches[1][12] : 0;
if ($getOtherPlayers) {
// Get Roles
$roles = request_turma_roles_translation($country);
// Main Player
$found = preg_match('/<div class="charmercpic doll2"\\s*data-tooltip="([^"]+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T002R].');}
$data['team']['0'] = request_turma_resolve_role($roles, $matches[1]);
// Player 1
$found = preg_match('/<div class="charmercpic doll3"/', $html);
if ($found) {
$found = preg_match('/<div class="charmercpic doll3"\\s*data-tooltip="([^"]+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T003R].');}
$data['team']['1'] = request_turma_resolve_role($roles, $matches[1]);
}
// Player 2
$found = preg_match('/<div class="charmercpic doll4"/', $html);
if ($found) {
$found = preg_match('/<div class="charmercpic doll4"\\s*data-tooltip="([^"]+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T004R].');}
$data['team']['2'] = request_turma_resolve_role($roles, $matches[1]);
}
// Player 3
$found = preg_match('/<div class="charmercpic doll5"/', $html);
if ($found) {
$found = preg_match('/<div class="charmercpic doll5"\\s*data-tooltip="([^"]+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T005R].');}
$data['team']['3'] = request_turma_resolve_role($roles, $matches[1]);
}
// Player 4
$found = preg_match('/<div class="charmercpic doll6"/', $html);
if ($found) {
$found = preg_match('/<div class="charmercpic doll6"\\s*data-tooltip="([^"]+)"/', $html, $matches);
if (!$found) {return array('error' => true,'message' => 'Internal parse error [T006R].');}
$data['team']['4'] = request_turma_resolve_role($roles, $matches[1]);
}
}
// Return the object
return $data;
}
// Request player's profile page data
function request_getPlayerStatisticsData($country, $server, $id) {
// Get statistics page code
$html = @file_get_contents(
'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/index.php?mod=player&submod=stats&p='.$id,
false,
stream_context_create(array(
'http' => array('method' => 'GET')
))
);
// On request error
if (!$html) {
// Return page not found error
return array(
'error' => true,
'message' => 'Our monkeys-workers failed to complete the task.'
);
}
// Shrink string by deleting useless data
$html = substr($html, 45000, -2000);
// Check if backup
if (isSeverInBackUpMode($html)) {
return array(
'error' => true, 'backup' => true,
'message' => 'Gladiatus server is in backup mode.'
);
}
// Create player object
$player = array(
'id' => $id,
'statistics' => array(),
'game' => array(
'country' => $country,
'server' => $server
)
);
// Get player's statistics
$found = preg_match_all('/<th>[^<]+<\\/th>\\s*<td class="stats_value">(\\d+\\.*\\d*\\.*\\d*\\.*\\d*)\\s*</', $html, $statistics_code);
if (!$found) {return array('error' => true,'message' => 'Internal parse error.');}
// Counting index
$index = 0;
$statistics_order_names = array(
'arena' => array(
'Battles',
'Wins',
'Defeats',
'Draws',
'Issued hit points',
'Taken hit points',
'Gold captured',
'Gold lost',
'Wins in a row'
),
'turma' => array(
'Battles',
'Wins',
'Defeats',
'Draws',
'Gold captured',
'Gold lost',
'Wins in a row'
),
'quests' => array(
'Completed quests',
'Completed quests with a time limit'
),
'victories' => array(
'Points',
'Honour',
'Fame',
'People mugged'
)
);
// Arena
for ($i = 0; $i < count($statistics_order_names['arena']); $i++) {
$satistic_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($statistics_order_names['arena'][$i])));
$player['statistics']['arena'][$satistic_name] = str_replace(array('.',','), '', $statistics_code[1][$index]);
$index++;
}
// Turma
for ($i = 0; $i < count($statistics_order_names['turma']); $i++) {
$satistic_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($statistics_order_names['turma'][$i])));
$player['statistics']['turma'][$satistic_name] = str_replace(array('.',','), '', $statistics_code[1][$index]);
$index++;
}
// Quests
for ($i = 0; $i < count($statistics_order_names['quests']); $i++) {
$satistic_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($statistics_order_names['quests'][$i])));
$player['statistics']['quests'][$satistic_name] = str_replace(array('.',','), '', $statistics_code[1][$index]);
$index++;
}
// Victories
for ($i = 0; $i < count($statistics_order_names['victories']); $i++) {
$satistic_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($statistics_order_names['victories'][$i])));
$player['statistics']['victories'][$satistic_name] = str_replace(array('.',','), '', $statistics_code[1][$index]);
$index++;
}
// Return the object
return $player;
}
// Request player's achievements page data
function request_getPlayerAchievementsData($country, $server, $id) {
// Get achievements page code
$html = @file_get_contents(
'https://s'.$server.'-'.$country.'.gladiatus.gameforge.com/game/index.php?mod=player&submod=achievements&p='.$id,
false,
stream_context_create(array(
'http' => array('method' => 'GET')
))
);
// On request error
if (!$html) {
// Return page not found error
return array(
'error' => true,
'message' => 'Our monkeys-workers failed to complete the task.'
);
}
// Shrink string by deleting useless data
$html = substr($html, 45000, -2000);
// Check if backup
if (isSeverInBackUpMode($html)) {
return array(
'error' => true, 'backup' => true,
'message' => 'Gladiatus server is in backup mode.'
);
}
// Create player object
$player = array(
'id' => $id,
'achievements' => array(),
'game' => array(
'country' => $country,
'server' => $server
)
);
// Get player's achievements
$found = preg_match_all('/<div class="achievement_detail_current">\\s*(\\d+\\.*\\d*\\.*\\d*)\\s*\\/\\s*(\\d+\\.*\\d*\\.*\\d*)\\s*<\\/div>/', $html, $achievements_code);
if (!$found) {return array('error' => true,'message' => 'Internal parse error.');}
// Counting index
$index = 0;
$achievements_order_names = array(
'general' => array(
'Earn gold',
'Train strength',
'Train dexterity',
'Train mobility',
'Train constitution',
'Train Charisma',
'Train intelligence',
'Collect honour',
'Collect honour (Provinciarum)',
'Get fame',
'Get fame (Provinciarum)',
'Go to work'
),
'items' => array(
'Find items',
'Find blue items',
'Find purple items',
'Find orange items'
),
'social' => array(
'Increase Circle of Buddies',
'Look at profiles',
'Be the centre of attention'
),
'guild' => array(
'Donate gold',
'Store items',
'Have yourself healed',
'Pray in the temple',
'Fight with the guild',
'Win guild battles',
'Store recipes',
'Activate recipes',
'Catch dungeon bosses',
'Defeat dungeon bosses'
),
'trade' => array(
'Sell items',
'Buy items',
'Sell market items',
'Buy market items',
'Win auctions'
),
'arena' => array(
'Win in the arena',
'Win in the Arena (Provinciarum)',
'Deal out damage',
'Accept damage',
'Absorb damage',
'Win in succession',
'Win arena pot',
'Kill gladiators',
'Die in the arena',
'Win naked'
),
'turma' => array(
'Win in Circus Turma',
'Defeat in Circus Turma (Provinciarum)',
'Deal out damage',
'Accept damage',
'Absorb damage',
'Win in succession',
'Win Circus Turma Pot'
),
'dungeons' => array(
'Dungeon successfully completed'
)
);
// General
for ($i = 0; $i < count($achievements_order_names['general']); $i++) {
$achiv_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($achievements_order_names['general'][$i])));
if ($achievements_code[1][$index] != $achievements_code[2][$index])
$player['achievements']['general'][$achiv_name] = str_replace(array('.',','), '', $achievements_code[1][$index]);
$index++;
}
// Items
for ($i = 0; $i < count($achievements_order_names['items']); $i++) {
$achiv_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($achievements_order_names['items'][$i])));
if ($achievements_code[1][$index] != $achievements_code[2][$index])
$player['achievements']['items'][$achiv_name] = str_replace(array('.',','), '', $achievements_code[1][$index]);
$index++;
}
// Social
for ($i = 0; $i < count($achievements_order_names['social']); $i++) {
$achiv_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($achievements_order_names['social'][$i])));
if ($achievements_code[1][$index] != $achievements_code[2][$index])
$player['achievements']['social'][$achiv_name] = str_replace(array('.',','), '', $achievements_code[1][$index]);
$index++;
}
// Guild
for ($i = 0; $i < count($achievements_order_names['guild']); $i++) {
$achiv_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($achievements_order_names['guild'][$i])));
if ($achievements_code[1][$index] != $achievements_code[2][$index])
$player['achievements']['guild'][$achiv_name] = str_replace(array('.',','), '', $achievements_code[1][$index]);
$index++;
}
// Trade
for ($i = 0; $i < count($achievements_order_names['trade']); $i++) {
$achiv_name = str_replace(array('(', ')'), '', str_replace(' ', '_', strtolower($achievements_order_names['trade'][$i])));
if ($achievements_code[1][$index] != $achievements_code[2][$index])