-
Notifications
You must be signed in to change notification settings - Fork 113
/
adminActionsRestricted.php
executable file
·1277 lines (1030 loc) · 41.9 KB
/
adminActionsRestricted.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
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
defined('IN_CODE') or die('This script can not be run by itself.');
/**
* This class will enable adminActions and adminActionsForum moderator
* tasks to be performed, but also allow tasks which only admins should
* be able to perform.
* This will be included anyway, but the class will only be initialized if
* the user is an admin.
*
* @package Admin
*/
class adminActionsRestricted extends adminActionsSeniorMod
{
public function __construct()
{
global $Misc;
parent::__construct();
$restrictedActions = array(
'wipeVariants' => array(
'name' => 'Clear variant caches',
'description' => 'Clears out all variant data and cache files, forcing them all to be reinstalled.',
'params' => array(),
),
'clearErrorLogs' => array(
'name' => 'Clear error logs',
'description' => 'Clears error log text files.</br>
<em>ONLY A DEV</em> should run this function, to make sure those logs aren\'t needed for debugging.',
'params' => array(),
),
'clearOrderLogs' => array(
'name' => 'Clear order logs',
'description' => 'Clears order log text files.',
'params' => array(),
),
'giveModerator' => array(
'name' => 'Give moderator status',
'description' => 'Gives moderator status to the specified user ID.',
'params' => array('userID'=>'User ID'),
),
'giveSeniorModerator' => array(
'name' => 'Give senior moderator status',
'description' => 'Gives senior moderator status to the specified user ID.',
'params' => array('userID'=>'User ID'),
),
'takeModerator' => array(
'name' => 'Take moderator status',
'description' => 'Takes moderator status from the specified user ID.',
'params' => array('userID'=>'Mod User ID'),
),
'takeSeniorModerator' => array(
'name' => 'Take senior moderator status',
'description' => 'Takes senior moderator status from the specified user ID.',
'params' => array('userID'=>'Mod User ID'),
),
'giveForumModerator' => array(
'name' => 'Give forum moderator status',
'description' => 'Gives forum moderator status to the specified user ID.',
'params' => array('userID'=>'User ID'),
),
'takeForumModerator' => array(
'name' => 'Take forum moderator status',
'description' => 'Takes forum moderator status from the specified user ID.',
'params' => array('userID'=>'Mod User ID'),
),
'changeEmail' => array(
'name' => 'Change email',
'description' => 'Update user\'s registered email.',
'params' => array('userID'=>'User ID', 'email'=>'New Email', 'reason'=>'Reason')
),
'changeUsername' => array(
'name' => 'Change username',
'description' => 'Changes user\'s current name to the specified username.',
'params' => array('userID'=>'User ID', 'username'=>'New Username', 'reason'=>'Reason'),
),
'createUser' => array(
'name' => 'Create user',
'description' => 'Creates a new user with the given username and a random password, for use on test servers for quick account creation.',
'params' => array('username'=>'Username')
),
'giveBot' => array(
'name' => 'Give bot status',
'description' => 'Gives bot status to the specified user ID.',
'params' => array('userID'=>'User ID'),
),
'takeBot' => array(
'name' => 'Take bot status',
'description' => 'Takes bot status from the specified user ID.',
'params' => array('userID'=>'User ID'),
),
'makeDonator' => array(
'name' => 'Give donator benefits',
'description' => 'Give donator benefits (in practical terms this just means opt-out of the distributed processing).<br />
<em>Only for owner use.</em>',
'params' => array('userID'=>'User ID'),
),
'makeDonatorPlatinum' => array(
'name' => 'Donator: platinum',
'description' => 'Give platinum donator marker<br />
<em>Only for owner use.</em>',
'params' => array('userID'=>'User ID'),
),
'makeDonatorGold' => array(
'name' => 'Donator: gold',
'description' => 'Give gold donator marker<br />
<em>Only for owner use.</em>',
'params' => array('userID'=>'User ID'),
),
'makeDonatorSilver' => array(
'name' => 'Donator: silver',
'description' => 'Give silver donator marker<br />
<em>Only for owner use.</em>',
'params' => array('userID'=>'User ID'),
),
'makeDonatorBronze' => array(
'name' => 'Donator: bronze',
'description' => 'Give bronze donator marker<br />
<em>Only for owner use.</em>',
'params' => array('userID'=>'User ID'),
),
'reprocessGame' => array(
'name' => 'Reprocess game',
'description' => 'Returns an active game to the last Diplomacy phase,
along with that phase\'s orders, and sets the time so that the game will be reprocessed.',
'params' => array('gameID'=>'Game ID'),
),
'updateDonators' => array(
'name' => 'Update Donators',
'description' => 'Will not do anything outside webdip, updates all donators to sync with Ranks on the new forum.',
'params' => array(),
),
'notice' => array(
'name' => 'Toggle site-wide notice',
'description' => 'Toggle the notice which is displayed in a noticebar across the whole site.',
'params' => array(),
),
'noticeMessage' => array(
'name' => 'Change notice message',
'description' => 'Sets the notice which is displayed in a noticebar across the whole site. Sample is: Excused missed turns have been added to all games. See more (<)a href="/contrib/phpBB3/viewtopic.php?f=5&t=1551">here(<)/a(>)(<)/br(>) (<)font color="red"(>)If you are seeing an error on games please clear your browsers cache.(<)/font(>)',
'params' => array('message'=>'Message'),
),
'maintenance' => array(
'name' => 'Toggle maintenance',
'description' => 'Toggle maintenance mode, which makes the server inaccessible except to admins
so changes can be made.',
'params' => array(),
),
'maintenanceMessage' => array(
'name' => 'Change maintenance message',
'description' => 'Change the message that is displayed while the site is undergoing maintenance.',
'params' => array('message'=>'Message'),
),
'panicMessage' => array(
'name' => 'Change panic message',
'description' => 'Changes the message that is displayed while the site is in panic mode.',
'params' => array('message'=>'Message'),
),
'globalAddTime' => array(
'name' => 'Add time to all games',
'description' => 'Add extra time (in hours) to all games, or 0 for the game\'s phase time.',
'params' => array('timeHours'=>'Extra time (hours)'),
),
'backupGame' => array(
'name' => 'Backup a game',
'description' => 'Save a game\'s data to the backup tables',
'params' => array('gameID'=>'Game ID'),
),
'restoreGame' => array(
'name' => 'Restore a game from backups',
'description' => 'Restores a game from a backup',
'params' => array('gameID'=>'Game ID'),
),
'wipeBackups' => array(
'name' => 'Wipe game backups',
'description' => 'Clear out all game backups',
'params' => array(),
),
'checkPausedGames' => array(
'name' => 'Check paused game process times',
'description' => 'Sometimes after extending next process times and resetting the last process
time some games are left with incorrectly set process/pause time values, which causes
users to have errors when the game gets loaded on their home page / board page.<br />
Until the cause can be tracked down and resolved this command can find and correct the
invalid values, but it shouldn\'t be used unless errors are occurring since it may alter
unaffected games.',
'params' => array(),
),
'recreateUnitDestroyIndex' => array(
'name' => 'Recreate the destroy unit indexes',
'description' => 'Refreshes the unit destroy indexes for a certain map ID. This will generally only
be run if there has been a bug found in the unit destroy index generation code which requires
the indexes to be recreated.<br />
Note that this uses the generic installation code, so if there are any variant-specific modifications
running this may give unpredictable results. Please confirm with the variant maintainer before
using this admin action.',
'params' => array('mapID'=>'Map ID'),
),
'resetLastProcessTime' => array(
'name' => 'Reset last process time',
'description' => 'Once the reason for the period of no processing is known, and it\'s safe to reenable
game processing, the last process time can be reset here.<br />
<em>Only a dev</em> should run this function after they ensure the issue has been fixed.',
'params' => array(),
),
'unCrashGames' => array(
'name' => 'Uncrash games',
'description' => 'Uncrashes all crashed games except the games specified (if any).<br />
<em>ONLY A DEV</em> should run this function. The reason for the crash needs to be found out before the games are uncrashed.',
'params' => array('excludeGameIDs'=>'Except Game ID list'),
),
'addApiKey' => array(
'name' => 'API - Add an API key for a user',
'description' => 'Associate an API key to a user.',
'params' => array('userID'=>'User ID'),
),
'deleteApiKey' => array(
'name' => 'API - Delete all API keys for a user',
'description' => 'Remove all API keys assiociated with a user.',
'params' => array('userID'=>'User ID'),
),
'setApiPermission' => array(
'name' => 'API - Set API key permission',
'description' => 'Set an API permission for a user. (getStateOfAllGames, submitOrdersForUserInCD, listGamesWithPlayersInCD)',
'params' => array('userID'=>'User ID', 'permissionName' => 'Permission name', 'permissionValue' => 'Permission value ("Yes" or "No").'),
),
'showApiKeys' => array(
'name' => 'API - Show API key and permissions for a user',
'description' => 'Display API key and permissions for a user.',
'params' => array('userID'=>'User ID'),
),
'calculateGR' => array(
'name' => 'Calculate Ghost Ratings',
'description' => 'Calculate GR for next x games and populate out the database. Note that this only needs to be done when
first adding GR to the server. After that, games will automatically calculate GR adjustments as they finish.',
'params' => array('batchSize'=>'Batch Size'),
),
'updateVariantInfo' => array(
'name' => 'Update wD_VariantInfo',
'description' => 'Will add or update the info in wD_VariantInfo for a given variantID. If left blank, it will loop through all variants.',
'params' => array('variantID'=>'Variant ID'),
)
);
adminActions::$actions = array_merge(adminActions::$actions, $restrictedActions);
}
public function wipeVariants(array $params)
{
foreach(Config::$variants as $variantID=>$variantName)
libVariant::wipe($variantName);
return l_t('All variants wiped.');
}
public function backupGameConfirm(array $params)
{
global $DB;
require_once(l_r('objects/game.php'));
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->Game($params['gameID']);
return l_t('Are you sure you want to backup this game?');
}
public function backupGame(array $params)
{
global $DB;
require_once(l_r('objects/game.php'));
$gameID = (int)$params['gameID'];
$DB->sql_put("BEGIN");
processGame::backupGame($gameID);
return l_t('Game backed up');
}
public function restoreGameConfirm(array $params)
{
global $DB;
require_once(l_r('objects/game.php'));
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->Game($params['gameID']);
return l_t('Are you sure you want to restore this game?');
}
public function restoreGame(array $params)
{
global $DB;
require_once(l_r('gamemaster/game.php'));
$gameID = (int)$params['gameID'];
$DB->sql_put("BEGIN");
processGame::restoreGame($gameID);
return l_t('Game restored');
}
public function wipeBackupsConfirm(array $params)
{
return l_t('Are you sure you want to wipe backups?');
}
public function wipeBackups(array $params)
{
global $DB;
require_once(l_r('gamemaster/game.php'));
processGame::wipeBackups();
return l_t('Backups wiped');
}
public function globalAddTime(array $params)
{
global $DB;
$timeHours=$params['timeHours'];
/*
* Paused/Finished - No change
*
* Pre-game -
* processTime-time() > phaseMinutes*60 - No change, a scheduled time is set
* processTime-time() <= phaseMinutes*60 - Add the requested time
* Active -
* phaseMinutes*60 < downtime - Pause
* phaseMinutes*60 >= downtime - Add
* downtime>phaseMinutes*60Add time up to phaseMinutes*60
*/
$DB->sql_put('UPDATE wD_Games SET processTime = processTime+'.round($timeHours*60*60).'
WHERE processStatus="Not-processing" AND NOT phase="Finished" AND
(
( phase="Pre-game" AND processTime<=phaseMinutes*60+'.time().' )
OR (NOT phase="Pre-game" AND '.round($timeHours*60*60).'<=phaseMinutes*60 )
)');
$DB->sql_put('UPDATE wD_Games SET processStatus="Paused", processTime=NULL,
pauseTimeRemaining=IF((processTime-'.time().')<=0, phaseMinutes*60, processTime-'.time().')
WHERE processStatus="Not-processing" AND NOT phase="Finished" AND
NOT phase="Pre-game" AND '.round($timeHours*60*60).'>phaseMinutes*60');
$DB->sql_put("COMMIT");
if($timeHours==0)
return l_t('All game process times have been set to their phase time');
else
return l_t('All games have had %s hours added to them',$timeHours);
}
public function maintenance(array $params)
{
global $Misc;
$Misc->Maintenance = 1-$Misc->Maintenance;
$Misc->write();
return l_t('Maintenance mode '.($Misc->Maintenance?'turned on':'turned off'));
}
public function maintenanceMessage(array $params)
{
global $DB;
$message = $params['message'];
$message = $DB->escape($message, $htmlAllowed=true);
$DB->sql_put("UPDATE wD_Config SET message='".$message."' WHERE name = 'Maintenance'");
return l_t('The maintenance message has been updated.');
}
public function notice(array $params)
{
global $Misc;
$Misc->Notice = 1-$Misc->Notice;
$Misc->write();
return l_t('Site-wide notice '.($Misc->Notice?'turned on':'turned off'));
}
public function noticeMessage(array $params)
{
global $DB;
$message = $params['message'];
$message = $DB->escape($message, $htmlAllowed=true);
$DB->sql_put("UPDATE wD_Config SET message='".$message."' WHERE name = 'Notice'");
return l_t('The site-wide notice message has been updated.');
}
public function panicMessage(array $params)
{
global $DB;
$message = $params['message'];
$message = $DB->escape($message, $htmlAllowed=true);
$DB->sql_put("UPDATE wD_Config SET message='".$message."' WHERE name = 'Panic'");
return l_t('The panic message has been updated.');
}
public function clearErrorLogs(array $params)
{
global $Misc;
$oldCount = $Misc->ErrorLogs;
libError::clear();
return l_t('The error logs were cleared, %s files deleted.',$oldCount);
}
public function clearOrderLogs(array $params)
{
$logDir = Config::orderlogDirectory();
if ( ! is_dir($logDir) or ! ( $handle = opendir($logDir) ) )
{
throw new Exception(l_t("Could not open log directory"));
}
$logs = array();
$exclude = array('.','..','index.html');
while ( false !== ( $file = readdir($handle) ) )
{
if( in_array($file, $exclude) ) continue;
$logs[] = $file;
}
closedir($handle);
$i=0;
foreach ( $logs as $log )
{
unlink($logDir.'/'.$log);
$i++;
}
return l_t('The order logs were cleared, %s files deleted.',$i);
}
public function wipeDATCTestGame(array $params)
{
global $DB;
require_once('gamemaster/game.php');
$DB->sql_put("BEGIN");
list($gameID) = $DB->sql_row("SELECT id FROM wD_Games WHERE name='DATC-Adjudicator-Test'");
processGame::eraseGame($gameID);
$DB->sql_put("COMMIT");
return l_t("DATC test game and associated data removed.");
}
public function clearAccessLogs(array $params)
{
// global $DB;
// list($i) = $DB->sql_row("SELECT COUNT(userID) FROM wD_AccessLog WHERE DATEDIFF(CURRENT_DATE, lastRequest) > 30");
// $DB->sql_put("DELETE FROM wD_AccessLog WHERE DATEDIFF(CURRENT_DATE, lastRequest) > 30");
// $DB->sql_put("OPTIMIZE TABLE wD_AccessLog");
return l_t('Disabled, do NOT clear access logs for ANY reason.');
}
public function clearAdminLogs(array $params)
{
// global $DB;
// $DB->sql_put("BEGIN");
// list($i) = $DB->sql_row("SELECT COUNT(userID) FROM wD_AdminLog");
// $DB->sql_put("DELETE FROM wD_AdminLog");
// $DB->sql_put("COMMIT");
return l_t('Disabled, do not clear admin log.');
}
public function giveModerator(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$modUser = new User($userID);
if( $modUser->type['Moderator'] )
throw new Exception(l_t("This user is already a moderator"));
$DB->sql_put("UPDATE wD_Users SET type = CONCAT_WS(',',type,'Moderator') WHERE id = ".$userID);
return l_t('This user was given moderator status.');
}
public function giveSeniorModerator(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$modUser = new User($userID);
if( $modUser->type['SeniorMod'] )
throw new Exception(l_t("This user is already a senior moderator"));
if( ! $modUser->type['Moderator'] )
throw new Exception(l_t("This user is not a moderator"));
$DB->sql_put("UPDATE wD_Users SET type = CONCAT_WS(',',type,'SeniorMod') WHERE id = ".$userID);
return l_t('This user was given senior moderator status.');
}
public function takeModerator(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$modUser = new User($userID);
if( ! $modUser->type['Moderator'] )
throw new Exception(l_t("This user isn't a moderator"));
if( $modUser->type['SeniorMod'] )
throw new Exception(l_t("Remove Senior Mod status first."));
$DB->sql_put("UPDATE wD_Users SET type = REPLACE(type,'Moderator','') WHERE id = ".$userID);
return l_t('This user had their moderator status taken.');
}
public function takeSeniorModerator(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$modUser = new User($userID);
if( ! $modUser->type['SeniorMod'] )
throw new Exception(l_t("This user isn't a senior moderator"));
$DB->sql_put("UPDATE wD_Users SET type = REPLACE(type,'SeniorMod','') WHERE id = ".$userID);
return l_t('This user had their senior moderator status taken.');
}
public function giveForumModerator(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$modUser = new User($userID);
if( $modUser->type['ForumModerator'] )
throw new Exception(l_t("This user is already a forum moderator"));
$DB->sql_put("UPDATE wD_Users SET type = CONCAT_WS(',',type,'ForumModerator') WHERE id = ".$userID);
return l_t('This user was given forum moderator status.');
}
public function takeForumModerator(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$modUser = new User($userID);
if( ! $modUser->type['ForumModerator'] )
throw new Exception(l_t("This user isn't a forum moderator"));
$DB->sql_put("UPDATE wD_Users SET type = REPLACE(type,'ForumModerator','') WHERE id = ".$userID);
return l_t('This user had their forum moderator status taken.');
}
public function changeEmail(array $params)
{
global $DB;
global $User;
$userID = (int)$params['userID'];
$newEmail = (string)$params['email'];
if( !isset($params['reason']) || strlen($params['reason'])==0 )
{
return l_t("Could not change email because no reason was given.");
}
$changeReason = $DB->msg_escape($params['reason']);
// check if new email is claimed by another account
list($result) = $DB->sql_row("SELECT username FROM wD_Users WHERE email = '".$newEmail."'");
if (!empty($result))
{
return l_t("This email has already been taken by another user: %s.", $result);
}
// get and store user's old email
$oldEmail = $DB->sql_hash("SELECT username, email FROM wD_Users WHERE id = ".$userID);
if (empty($oldEmail))
{
return l_t("User id %s has not been found.", $userID);
}
$time = time();
$changedBy = $User->username;
$DB->sql_put(
'INSERT INTO wD_EmailHistory (userID, oldEmail, newEmail, date, reason, changedBy)
VALUES ('.$userID.', "'.$oldEmail['email'].'", "'.$newEmail.'", '.$time.', "'.$changeReason.'", "'.$changedBy.'")'
);
$DB->sql_put(
"UPDATE wD_Users SET email = '".$newEmail."' WHERE id = ".$userID." limit 1"
);
return l_t("%s's email has been changed from %s to %s.", $oldEmail['username'], $oldEmail['email'], $newEmail);
}
public function changeUsername(array $params)
{
global $DB;
global $User;
$userID = (int)$params['userID'];
$newUsername = (string)$params['username'];
if( !isset($params['reason']) || strlen($params['reason'])==0 )
{
return l_t("Could not change username because no reason was given.");
}
$changeReason = $DB->msg_escape($params['reason']);
// check if username exists
list($result) = $DB->sql_row("SELECT username FROM wD_Users WHERE username = '".$newUsername."'");
if (!empty($result))
{
return l_t("This username has already been taken by another user.");
}
// get and store old username and if it exists set new username
list($oldUsername) = $DB->sql_row("SELECT username FROM wD_Users WHERE id = ".$userID);
if (empty($oldUsername))
{
return l_t("User id %s has not been found.", $userID);
}
$time = time();
$changedBy = $User->username;
$DB->sql_put(
'INSERT INTO wD_UsernameHistory (userID, oldUsername, newUsername, date, reason, changedBy)
VALUES ("'.$userID.'", "'.$oldUsername.'", "'.$newUsername.'", "'.$time.'", "'.$changeReason.'", "'.$changedBy.'")'
);
$DB->sql_put("UPDATE wD_Users SET username = '".$newUsername."' WHERE id = '".$userID."' limit 1");
// update new forum on webdip
if (isset(Config::$customForumURL))
{
$newUsernameClean = strtolower($newUsername);
$DB->sql_put(
"UPDATE phpbb_users SET username = '".$newUsername."', username_clean = '".$newUsernameClean."'
WHERE username = '".$oldUsername."' AND webdip_user_id = '".$userID."' limit 1"
);
}
return l_t("This user's username has been changed from %s to %s.",$oldUsername, $newUsername);
}
public function createUser(array $params)
{
global $DB;
$username = $DB->escape($params['username']);
$DB->sql_put("INSERT INTO wD_Users (username,email,points,timeJoined,locale,type) VALUES ('" . $username . "','" . $username . "',100,".time().",'English','User')");
$userID = $DB->last_inserted();
return l_t("<a href='profile.php?userID=".$userID."'>User #".$userID."</a> created.");
}
public function giveBot(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$botUser = new User($userID);
if( $botUser->type['Bot'] )
throw new Exception(l_t("This user is already a bot"));
$DB->sql_put("UPDATE wD_Users SET type = CONCAT_WS(',',type,'Bot') WHERE id = ".$userID);
return l_t('This user was given bot status.');
}
public function takeBot(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$botUser = new User($userID);
if( ! $botUser->type['Bot'] )
throw new Exception(l_t("This user isn't a bot"));
$DB->sql_put("UPDATE wD_Users SET type = REPLACE(type,'Bot','') WHERE id = ".$userID);
return l_t('This user had their bot status taken.');
}
public function checkPausedGames(array $params)
{
global $DB;
list($minTime) = $DB->sql_row(
"SELECT MIN(processTime) FROM wD_Games
WHERE NOT phase='Finished' AND processStatus='Not-processing'
AND processTime > 123456789"
);
$affected = 0;
$DB->sql_put(
"UPDATE `wD_Games` SET
processTime=NULL,
pauseTimeRemaining=phaseMinutes*60
WHERE pauseTimeRemaining IS NULL AND processStatus='Paused'"
);
$affected += $DB->last_affected();
$DB->sql_put(
"UPDATE `wD_Games` SET
processTime=(".$minTime."+phaseMinutes*60),
pauseTimeRemaining=NULL
WHERE processTime IS NULL AND processStatus='Not-processing'"
);
$affected += $DB->last_affected();
return l_t('Any invalid next-process/pause-length times have been reset; %s game(s) affected.',$affected);
}
public function reprocessGame(array $params)
{
global $DB, $Game;
$gameID = (int)$params['gameID'];
/*
* - Check that the game is still active and can be turned back
*
* - Delete current turn values
* - Calculate the turn being moved back to
*
* - Move the old MovesArchive back to Units
* - Move the old MovesArchive (JOIN Units) back to Orders
* - Move the old TerrStatusArchive (JOIN Units) back to TerrStatus
*
* - Update the game turn, phase and next process time
*
* - Delete Archive values if we have moved back a turn
* - Remove the invalid maps in the mapstore
*/
$DB->sql_put("BEGIN");
require_once(l_r('gamemaster/game.php'));
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->processGame($gameID);
$oldPhase = $Game->phase;
$oldTurn = $Game->turn;
// - Check that the game is still active and can be turned back
if ( $Game->turn < 1 )
{
throw new Exception(l_t('This game cannot be turned back; it is new or is finished.'));
}
// - Delete current turn values
$DB->sql_put("DELETE FROM wD_Units WHERE gameID = ".$Game->id);
$DB->sql_put("DELETE FROM wD_TerrStatus WHERE gameID = ".$Game->id);
$DB->sql_put("DELETE FROM wD_Orders WHERE gameID = ".$Game->id);
// - Calculate the turn being moved back to
$lastTurn = ( ( $Game->phase == 'Diplomacy' ) ? $Game->turn-1 : $Game->turn );
// Begin moving the archives back
{
// - Move the old MovesArchive back to Units
$DB->sql_put("INSERT INTO wD_Units ( type, terrID, countryID, gameID )
SELECT unitType, terrID, countryID, gameID FROM wD_MovesArchive
WHERE gameID = ".$Game->id." AND turn = ".$lastTurn."
/* Make sure only the Diplomacy phase unit positions are used */
AND type IN ( 'Hold', 'Move', 'Support hold', 'Support move', 'Convoy' )");
// - Move the old MovesArchive (JOIN Units) back to Orders
$DB->sql_put("INSERT INTO wD_Orders (gameID, countryID, type, toTerrID, fromTerrID, viaConvoy, unitID)
SELECT m.gameID, m.countryID, m.type, m.toTerrID, m.fromTerrID, m.viaConvoy, u.id
FROM wD_MovesArchive m INNER JOIN wD_Units u ON ( u.terrID = m.terrID AND u.gameID = m.gameID )
WHERE m.gameID = ".$Game->id." AND m.turn = ".$lastTurn."
/* Make sure only the Diplomacy phase unit positions are used */
AND m.type IN ( 'Hold', 'Move', 'Support hold', 'Support move', 'Convoy' )");
// - Move the old TerrStatusArchive back to TerrStatus
$DB->sql_put("INSERT INTO wD_TerrStatus ( terrID, standoff, gameID, countryID, occupyingUnitID )
SELECT t.terrID, t.standoff, t.gameID, t.countryID, u.id
FROM wD_TerrStatusArchive t
LEFT JOIN wD_Units u
ON ( ".$Game->Variant->deCoastCompare('t.terrID','u.terrID')." AND u.gameID = t.gameID )
WHERE t.gameID = ".$Game->id." AND t.turn = ".$lastTurn);
}
// - Update the game turn, phase and next process time
$DB->sql_put("UPDATE wD_Games
SET turn = ".$lastTurn.", phase = 'Diplomacy', gameOver='No', processTime = phaseMinutes*60+".time().",
processStatus='Not-processing', pauseTimeRemaining=NULL
WHERE id = ".$Game->id);
$DB->sql_put("UPDATE wD_Members SET votes='', orderStatus='',
status=IF(status='Won' OR status='Survived' OR status='Drawn' OR status='Playing',
'Playing',
IF(status='Resigned' OR status='Left','Left','Defeated')
)
WHERE gameID = ".$Game->id);
$DB->sql_put("COMMIT");
// - Delete Archive values if we have moved back a turn
$DB->sql_put("DELETE FROM wD_TerrStatusArchive WHERE gameID = ".$Game->id." AND turn = ".$lastTurn);
$DB->sql_put("DELETE FROM wD_MovesArchive WHERE gameID = ".$Game->id." AND turn = ".$lastTurn);
// - Remove the invalid maps in the mapstore
$Game->load();
Game::wipeCache($Game->id);
libGameMessage::send(0, 'GameMaster', l_t('This game has been moved back to %s',$Game->datetxt($lastTurn)), $Game->id);
return l_t('This game was moved from %s, %s back to Diplomacy, %s, and is ready to be reprocessed.',
$oldPhase,$Game->datetxt($oldTurn),$Game->datetxt($lastTurn));
}
public function recreateUnitDestroyIndex(array $params)
{
global $DB;
$mapID = (int)$params['mapID'];
require_once("variants/install.php");
InstallTerritory::loadExistingTerritories($mapID);
// Generate the SQL before wiping & reinserting it
$unitDestroyIndexRecreateSQL = InstallTerritory::unitDestroyIndexSQL($mapID);
$DB->sql_put("BEGIN");
list($entriesBefore) = $DB->sql_row("SELECT COUNT(*) FROM wD_UnitDestroyIndex WHERE mapID = ".$mapID);
$DB->sql_put("DELETE FROM wD_UnitDestroyIndex WHERE mapID = ".$mapID);
$DB->sql_put($unitDestroyIndexRecreateSQL);
list($entriesAfter) = $DB->sql_row("SELECT COUNT(*) FROM wD_UnitDestroyIndex WHERE mapID = ".$mapID);
$DB->sql_put("COMMIT");
return l_t('The unit destroy indexes were recreated for map ID #%s ; there were %s entries before and there are currently %s entries.', $mapID, $entriesBefore, $entriesAfter);
}
private function makeDonatorType(array $params, $type='')
{
global $DB;
$userID = (int)$params['userID'];
$DB->sql_put("UPDATE wD_Users SET type = CONCAT_WS(',',type,'Donator".$type."') WHERE id = ".$userID);
// If we're using the new forum then add a rank to the user.
if( isset(Config::$customForumURL) && ($type == 'Gold' || $type == 'Silver' || $type == 'Bronze') )
{
// Make sure the user has a new forum profile before trying an insert into the custom tables.
list($newForumID) = $DB->sql_row("SELECT user_id FROM `phpbb_users` WHERE webdip_user_id = ".$userID);
if ($newForumID > 0)
{
$rank = 12;
switch ($type)
{
case 'Gold':
$rank = 12;
break;
case 'Silver':
$rank = 13;
break;
case 'Bronze':
$rank = 14;
break;
}
$DB->sql_put("UPDATE phpbb_users SET user_rank = ".$rank." WHERE user_rank = 0 and webdip_user_id = ".$userID);
}
}
return l_t('User ID %s given donator status.',$userID);
}
public function updateDonators(array $params)
{
global $DB;
if( isset(Config::$customForumURL) )
{
$DB->sql_put("UPDATE phpbb_users p INNER JOIN wD_Users u ON u.id = p.webdip_user_id SET p.user_rank = 12 WHERE p.user_rank in (0,13,14) and u.type like '%DonatorGold%'");
$DB->sql_put("UPDATE phpbb_users p INNER JOIN wD_Users u ON u.id = p.webdip_user_id SET p.user_rank = 13 WHERE p.user_rank in (0,14) and u.type like '%DonatorSilver%'");
$DB->sql_put("UPDATE phpbb_users p INNER JOIN wD_Users u ON u.id = p.webdip_user_id SET p.user_rank = 14 WHERE p.user_rank in (0) and u.type like '%DonatorBronze%'");
return l_t('Donator ranks synced with User tables');
}
else
{
return 'This tool is not for use outside webdip';
}
}
public function makeDonator(array $params)
{
return $this->makeDonatorType($params);
}
public function makeDonatorPlatinum(array $params)
{
return $this->makeDonatorType($params,'Platinum');
}
public function makeDonatorGold(array $params)
{
return $this->makeDonatorType($params,'Gold');
}
public function makeDonatorSilver(array $params)
{
return $this->makeDonatorType($params,'Silver');
}
public function makeDonatorBronze(array $params)
{
return $this->makeDonatorType($params,'Bronze');
}
public function resetLastProcessTime(array $params)
{
global $Misc;
$Misc->LastProcessTime = time();
$Misc->write();
return l_t('Last process time reset');
}
public function unCrashGames(array $params)
{
global $DB;
require_once(l_r('gamemaster/game.php'));
$excludeGameIDs = explode(',', $params['excludeGameIDs']);
foreach($excludeGameIDs as $index=>$gameID)
{
$gameID = (int)$gameID;
$excludeGameIDs[$index] = $gameID;