-
Notifications
You must be signed in to change notification settings - Fork 113
/
adminActions.php
executable file
·1257 lines (1023 loc) · 45.1 KB
/
adminActions.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 gives the static information for moderator tasks, and the code
* which runs each task. The adminActionsForms class can use the static data
* to present forms for each task, and correctly pass the submitted form data
* to the right task code here.
*
* @package Admin
*/
class adminActions extends adminActionsForms
{
public static $actions = array(
'drawGame' => array(
'name' => 'Draw game',
'description' => 'Splits points among all the surviving players in a game according to its scoring system, and ends the game.',
'params' => array('gameID'=>'Game ID'),
),
'cancelGame' => array(
'name' => 'Cancel game',
'description' => 'Refunds points each player has bet unless the game is finished. Finished games need manual point adjustments. Then deletes the game. Does not work on games that have not started, instead force all users into CD.',
'params' => array('gameID'=>'Game ID'),
),
'togglePause' => array(
'name' => 'Toggle-pause game',
'description' => 'Flips a game\'s paused status; if it\'s paused it\'s unpaused, otherwise it\'s paused.<br />
If you are using this tool on a phone navigate away from this page after using or an auto refresh will cause accidental toggles.',
'params' => array('gameID'=>'Game ID'),
),
'makePublic' => array(
'name' => 'Make a private game public',
'description' => 'Removes a private game\'s password. This allows anyone to join.',
'params' => array('gameID'=>'Game ID'),
),
'makePrivate' => array(
'name' => 'Make a public game private',
'description' => 'Add a password to a private game. Only people with this password can join.',
'params' => array('gameID'=>'Game ID','password'=>'Password'),
),
'cdUser' => array(
'name' => 'Force a user into CD',
'description' => 'Force a user into CD in all their games, or in one game if non-zero gameID given.<br />
Forced CDs do not count against the player\'s RR.<br />
If the game has not started yet the user will be removed from the game entirely, and if they were the only user in the game, the game will be cancelled.',
'params' => array('userID'=>'User ID','gameID'=>'Game ID'),
),
'replaceCoutries' => array(
'name' => 'Replace country-player.',
'description' => 'Replace one player in a given game with another one. This does not impact points. If the replacing player does not meet the RR requirements for the game or is already in the game, that game replacement will not occur.',
'params' => array('userID'=>'UserID to be replaced','replaceID'=>'UserID replacing','gameIDs'=>'GameID (all active if empty)', )
),
'banIP' => array(
'name' => 'Ban an IP',
'description' => 'Bans a certain IP address.<br />
Note: Doesn\'t work.',
'params' => array('IP'=>'IP address (xxx.xxx.xxx.xxx)'),
),
'tempBan' => array(
'name' => 'Temporary ban a player',
'description' => 'Stops a player from joining or creating new games for that many days. To remove a temp ban, enter 0 days',
'params' => array('userID'=>'User ID', 'ban'=>'Days')
),
'modExcuseDelay' => array(
'name' => 'Mod Excuse Missed Turn',
'description' => 'Enter the user to excuse and the ID of the missed turn to excuse (found on RR breakdown page)',
'params' => array('userID'=>'User ID', 'excuseID'=>'Excuse ID','reason'=>'Reason')
),
'banUser' => array(
'name' => 'Ban a user',
'description' => 'Bans a user, setting his games to civil disorder, and removing his points.',
'params' => array('userID'=>'User ID','reason'=>'Reason'),
),
'unbanUser' => array(
'name' => 'Unban a user',
'description' => 'Unbans a user; does not return the player from civil disorder, remove the ban comment from their profile, or return the points taken.',
'params' => array('userID'=>'Banned User ID'),
),
'givePoints' => array(
'name' => 'Give or take points',
'description' => 'Enter a positive number of points to give, or a negative number of points to take.',
'params' => array('userID'=>'User ID', 'points'=>'Points')
),
'resetPass' => array(
'name' => 'Reset password',
'description' => 'Resets a users password',
'params' => array('userID'=>'User ID'),
),
'updateEmergencyDate' => array(
'name' => 'Adjust Emergency Date',
'description' => 'Enter 0 to grant the user another emergency pause, enter 1 to stop this user from having emergency pauses.',
'params' => array('userID'=>'User ID','setting'=>'Setting'),
),
'setProcessTimeToPhase' => array(
'name' => 'Reset process time',
'description' => 'Set a game process time to now + the phase length, resetting the turn length',
'params' => array('gameID'=>'Game ID'),
),
'setProcessTimeToNow' => array(
'name' => 'Process game now',
'description' => 'Set a game process time to now, resulting in it being processed now.<br />
<em>Be careful:</em> this will cause any players without submitted moves to NMR.',
'params' => array('gameID'=>'Game ID'),
),
'toggleWaitForOrders' => array(
'name' => 'Toggle Wait for orders mode',
'description' => 'Will toggle this game between normal NMR rules and wait-for-orders mode.<br />
<em>Be careful:</em> flipping from on to off while the game is in wait mode will cause any players without submitted moves to NMR.',
'params' => array('gameID'=>'Game ID'),
),
'resetMinimumBet' => array(
'name' => 'Reset the minimum bet',
'description' => 'If there is no join button on a game and the minimum bet hasn\'t been set correctly you can use this to reset it.',
'params' => array('gameID'=>'Game ID'),
),
'panic' => array(
'name' => 'Toggle panic button',
'description' => 'Toggle the panic button; turning it on prevents games from being processed, users joining games,
users registering. It is intended to limit the damage a problem can do.
<em>This effectively shuts down the site, so be sure before pressing this.</em>',
'params' => array(),
),
'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(),
),
'changePhaseLength' => array(
'name' => 'Change phase length',
'description' => 'Change the maximum number of minutes that a phase lasts.
The time must be given in minutes (5 minutes to 10 days = 5-14400).<br />
Also the next process time is reset to the new phase length.',
'params' => array('gameID'=>'Game ID','phaseMinutes'=>'Minutes per phase'),
),
'countryReallocate' => array(
'name' => 'Reallocate countries',
'description' => 'Alter which player has which country. Enter a list like so:
"<em>R,T,A,G,I,F,E</em>".<br />
The result will be that England will be set to Russia, France to Turkey, etc.<br /><br />
If you aren\'t sure about the order of each country just enter the gameID without anything else and the list of
countries in the order will be output.<br /><br />
To prevent people sharing invalid info before the countries have been reallocated only no-message games
can have their countries reallocated; messages should be enabled only after the countries have been reallocated.<br /><br />
(The substitution string to reverse the reallocation will be generated, in case you need to reverse the reallocation.)<br />
(If changing the countries of a variant for which the first letter of the countries are not distinct countryID numbers must be used instead.)<br />
(Alternatively you can enter [userID1]=[countryLetter1],[userID2]=[countryLetter2],etc)',
'params' => array(
'gameID'=>'Game ID',
'reallocations'=>'Reallocations list (e.g "<em>R,T,A,G,I,F,E</em>")'
)
),
'drawType' => array(
'name' => 'Change the draw visibility',
'description' => 'Change a game\'s draw visibility (public or hidden).',
'params' => array(
'gameID'=>'Game ID',
'newSetting'=>'Enter a number for the desired setting: 1=Public, 2=Hidden'
),
),
'alterMessaging' => array(
'name' => 'Alter game messaging',
'description' => 'Change a game\'s messaging settings, e.g. to convert from gunboat to public-only or all messages allowed.',
'params' => array(
'gameID'=>'Game ID',
'newSetting'=>'Enter a number for the desired setting: 1=Regular, 2=PublicPressOnly, 3=NoPress, 4=RuleBookPress'
),
),
'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'),
),
'reportMuteToggle' => array(
'name' => 'Toggle mod-report mute',
'description' => 'Toggles whether the given userID can submit reports, to prevent annoying users from abusing the report feature.</br>
Note: Doesn\'t work.',
'params' => array('userID'=>'User ID'),
),
'setDirector' => array(
'name' => 'Set a user as a game director',
'description' => 'Sets the given user ID to be the director of the given game ID (set to 0 to remove someone as game director).
This will give them mod capabilities for this game.',
'params' => array('gameID'=>'Game ID','userID'=>'User ID'),
),
'excusedMissedTurnsIncreaseAll' => array(
'name' => 'Excused Missed Turns - Add for All',
'description' => 'Adds 1 excused missed turn to all members in the game.',
'params' => array('gameID'=>'Game ID'),
),
'excusedMissedTurnsDecreaseAll' => array(
'name' => 'Excused Missed Turns - Remove for All',
'description' => 'Removes 1 excused missed turn for all members in the game. If the user(s) do not have excused turns left nothing will happen.',
'params' => array('gameID'=>'Game ID'),
),
'excusedMissedTurnsIncrease' => array(
'name' => 'Excused Missed Turns - Add',
'description' => 'Adds 1 excused missed turn to a specific user in a game.',
'params' => array('gameID'=>'Game ID','userID'=>'User ID'),
),
'excusedMissedTurnsDecrease' => array(
'name' => 'Excused Missed Turns - Remove',
'description' => 'Removes 1 excused missed turn for a specific user in a game. If the user(s) do not have excused turns left nothing will happen.',
'params' => array('gameID'=>'Game ID','userID'=>'User ID'),
)
);
public function __construct()
{
global $Misc;
}
public function resetMinimumBet(array $params)
{
require_once(l_r('gamemaster/game.php'));
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->processGame($params['gameID']);
$Game->resetMinimumBet();
return l_t("The minimum bet has been 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;
}
$excludeGameIDs = implode(',', $excludeGameIDs);
$tabl = $DB->sql_tabl(
"SELECT * FROM wD_Games WHERE processStatus = 'Crashed' ".( $excludeGameIDs ? "AND id NOT IN (".$excludeGameIDs.")" : "" )." FOR UPDATE"
);
$count=0;
while($row=$DB->tabl_hash($tabl))
{
$count++;
$Variant=libVariant::loadFromVariantID($row['variantID']);
$Game = $Variant->processGame($row);
if( $Game->phase == 'Finished' )
{
$DB->sql_put("UPDATE wD_Games SET processStatus = 'Not-processing', pauseTimeRemaining=NULL, processTime = ".time()." WHERE id = ".$Game->id);
continue;
}
if ( $Game->phaseMinutes < 12*60 )
{
if( $Game->phase == 'Pre-game' )
{
$newTimeDetails = "";
$DB->sql_put("UPDATE wD_Games SET processStatus = IF(pauseTimeRemaining IS NULL,'Not-processing','Paused') WHERE id = ".$Game->id);
}
else
{
$newTimeDetails = l_t(", and the game has been paused, since it's a fast game, to give players a chance to regroup");
$Game->processStatus = 'Not-processing';
$Game->togglePause();
}
}
else
{
$newTimeDetails = l_t(", and the game's next process time has been reset");
$DB->sql_put("UPDATE wD_Games SET processStatus = 'Not-processing', processTime = ".time()." + 60*phaseMinutes, pauseTimeRemaining=NULL WHERE id = ".$Game->id);
}
$Game->Members->send('No',l_t("This game has been uncrashed%s. Thanks for your patience.",$newTimeDetails));
}
/* Simpler, but doesn't accomodate live games well
$DB->sql_put(
"UPDATE wD_Games SET processStatus = 'Not-processing', processTime = ".time()." + 60*phaseMinutes
WHERE AND processStatus = 'Crashed' ".( $excludeGameIDs ? "AND id NOT IN (".$excludeGameIDs.")" : "" )
);*/
$details = l_t('All crashed games were un-crashed');
if ( $excludeGameIDs )
$details .= l_t(', except: %s',$excludeGameIDs);
$details .= l_t('. %s games in total.',$count);
return $details;
}
public function countryReallocate(array $params)
{
global $DB;
$gameID=(int)$params['gameID'];
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->Game($gameID);
if( strlen($params['reallocations'])==0 )
{
$c=array();
foreach($Variant->countries as $index=>$country)
{
$index++;
$countryLetter=strtoupper(substr($country,0,1));
$c[$countryLetter] = '#'.$index.": ".$country;
}
$ids=array_keys($c);
return implode('<br />',$c)."<br />".l_t("e.g. \"%s\"\" would change nothing",implode(',',$ids));
}
$reallocations=explode(',',$params['reallocations']);
if ( $Game->pressType != 'NoPress' )
throw new Exception(l_t("Only games with no messages allowed can have their countries reordered, ".
"otherwise information may already have been communicated while believing countries were already allocated."));
if ( $Game->phase == 'Pre-game' )
throw new Exception(l_t("This game hasn't yet started; countries can only be reallocated after they have been allocated already."));
if ( $Game->phase == 'Finished' )
throw new Exception(l_t("This game has finished, countries can't be reallocated."));
if( count($reallocations) != count($Variant->countries) )
throw new Exception(l_t("The number of inputted reallocations (%s) aren't equal to the number of countries (%s).",count($reallocations),count($Variant->countries)));
if( !is_numeric(implode('', $reallocations)) )
{
$countryIDsByLetter=array();
foreach($Variant->countries as $countryID=>$countryName)
{
$countryID++;
$countryLetter=strtoupper(substr($countryName,0,1));
if( isset($countryIDsByLetter[$countryLetter]) )
throw new Exception(l_t("For the given variant two countries have the same start letter: '%s (one is '%s'), you must give countryIDs instead of letters.",$countryLetter,$countryName));
$countryIDsByLetter[$countryLetter]=$countryID;
}
if( count(explode('=',$reallocations[0]))==2 )
{
$newCountryIDsByOldCountryID=array();
foreach($reallocations as $r)
{
list($userID,$countryLetter)=explode('=', $r);
$countryID=$countryIDsByLetter[$countryLetter];
$oldCountryID=false;
list($oldCountryID)=$DB->sql_row("SELECT countryID FROM wD_Members WHERE userID=".$userID." AND gameID = ".$Game->id);
if( !$oldCountryID )
throw new Exception(l_t("User %s not found in this game.",$userID));
$newCountryIDsByOldCountryID[$oldCountryID]=$countryID;
}
}
else
{
$newCountryIDsByOldCountryID=array();
for($oldCountryID=1; $oldCountryID<=count($reallocations); $oldCountryID++)
{
$countryLetter=$reallocations[$oldCountryID-1];
if( !isset($countryIDsByLetter[$countryLetter]) )
throw new Exception(l_t("No country name starts with letter '%s'",$countryLetter));
$newCountryIDsByOldCountryID[$oldCountryID]=$countryIDsByLetter[$countryLetter];
}
}
}
else
{
$newCountryIDsByOldCountryID=array();
for($oldCountryID=1; $oldCountryID<=count($reallocations); $oldCountryID++)
{
$newCountryID=$reallocations[$oldCountryID-1];
$newCountryIDsByOldCountryID[$oldCountryID]=(int)$newCountryID;
}
}
$changes=array();
$newUserIDByNewCountryID=array();
$changeBack=array();
foreach($newCountryIDsByOldCountryID as $oldCountryID=>$newCountryID)
{
list($userID)=$DB->sql_row("SELECT userID FROM wD_Members WHERE gameID=".$Game->id." AND countryID=".$oldCountryID." FOR UPDATE");
$newUserIDByNewCountryID[$newCountryID]=$userID;
$changes[] = l_t("Changed %s (#%s) to %s (#%s).",$Variant->countries[$oldCountryID-1],$oldCountryID,$Variant->countries[$newCountryID-1],$newCountryID);
$changeBack[$newCountryID]=$oldCountryID;
}
$changeBackStr=array();
for($i=1; $i<=count($Variant->countries); $i++)
$changeBackStr[] = $changeBack[$i];
$changeBackStr=implode(',', $changeBackStr);
// Foreach member set the new owners' userID
// The member isn't given a new countryID, instead the user in control of the countryID is moved into the other countryID:
// userID is what gets changed, not countryID (if it's not done this way all sorts of problems e.g. supplyCenterNo crop up)
$DB->sql_put("BEGIN");
foreach($newUserIDByNewCountryID as $newCountryID=>$userID)
$DB->sql_put("UPDATE wD_Members SET userID=".$userID." WHERE gameID=".$Game->id." AND countryID=".$newCountryID);
$DB->sql_put("COMMIT");
return l_t('In this game these countries were successfully swapped:').'<br />'.implode(',<br />', $changes).'.<br />
'.l_t('These changes can be reversed with "%s"',$changeBackStr);
}
public function reportMuteToggle(array $params) {
global $DB;
$userID=(int)$params['userID'];
$DB->sql_put("UPDATE wD_Users SET muteReports=IF(muteReports='Yes','No','Yes') WHERE id=".$userID);
return l_t("User's reporting ability has been toggled.");
}
public function drawType(array $params)
{
global $DB;
$gameID=(int)$params['gameID'];
$newSetting=(int)$params['newSetting'];
switch($newSetting)
{
case 1: $newSettingName='draw-votes-public'; break;
case 2: $newSettingName='draw-votes-hidden'; break;
default: throw new Exception(l_t("Invalid draw vote setting - enter 1 (public) or 2 (hidden)"));
}
$DB->sql_put("UPDATE wD_Games SET drawType = '".$newSettingName."' WHERE id = ".$gameID);
return l_t('Game changed to drawType=%s.',$newSettingName);
}
public function alterMessaging(array $params)
{
global $DB;
$gameID=(int)$params['gameID'];
$newSetting=(int)$params['newSetting'];
switch($newSetting)
{
case 1: $newSettingName='Regular'; break;
case 2: $newSettingName='PublicPressOnly'; break;
case 3: $newSettingName='NoPress'; break;
case 4: $newSettingName='RuleBookPress'; break;
default: throw new Exception(l_t("Invalid messaging setting; enter 1, 2, 3, or 4."));
}
$DB->sql_put("UPDATE wD_Games SET pressType = '".$newSettingName."' WHERE id = ".$gameID);
return l_t('Game changed to pressType=%s.',$newSettingName);
}
public function changePhaseLength(array $params)
{
global $DB;
require_once(l_r('objects/game.php'));
$newPhaseMinutes = (int)$params['phaseMinutes'];
if ( $newPhaseMinutes < 5 || $newPhaseMinutes > 10*24*60 )
throw new Exception(l_t("Given phase minutes out of bounds (5 minutes to 10 days)"));
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->Game($params['gameID']);
if( $Game->processStatus != 'Not-processing' || $Game->phase == 'Finished' )
throw new Exception(l_t("Game is either crashed/paused/finished/processing, and so the next-process time cannot be altered."));
$oldPhaseMinutes = $Game->phaseMinutes;
$Game->phaseMinutes = $newPhaseMinutes;
$Game->processTime = time()+($newPhaseMinutes*60);
$DB->sql_put("UPDATE wD_Games SET
phaseMinutes = ".$Game->phaseMinutes.",
processTime = ".$Game->processTime."
WHERE id = ".$Game->id);
return l_t('Process time changed from %s to %s. Next process time is %s.',
libTime::timeLengthText($oldPhaseMinutes*60),libTime::timeLengthText($Game->phaseMinutes*60),libTime::text($Game->processTime));
}
public function toggleWaitForOrders(array $params)
{
global $DB;
require_once(l_r('objects/game.php'));
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->Game($params['gameID']);
if( $Game->missingPlayerPolicy == 'Wait' )
{
$msg = "Set game to normal mode.";
$setting = 'Normal';
}
else
{
$msg = "Set game to wait-for-orders mode.";
$setting = 'Wait';
}
$DB->sql_put("UPDATE wD_Games SET missingPlayerPolicy = '".$setting."' WHERE id = ".$Game->id);
return l_t($msg);
}
public function resetLastProcessTime(array $params)
{
global $Misc;
$Misc->LastProcessTime = time();
$Misc->write();
return l_t('Last process time reset');
}
public function setProcessTimeToPhaseConfirm(array $params)
{
global $DB;
require_once(l_r('objects/game.php'));
$gameID = intval($params['gameID']);
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->Game($gameID);
return l_t('Are you sure you want to reset the phase process time of this game to process in %s hours?',($Game->phaseMinutes/60));
}
public function setProcessTimeToPhase(array $params)
{
global $DB;
$gameID = intval($params['gameID']);
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->Game($gameID);
if( $Game->processStatus != 'Not-processing' || $Game->phase == 'Finished' )
return l_t('This game is paused/crashed/finished.');
$DB->sql_put(
"UPDATE wD_Games
SET processTime = ".time()." + phaseMinutes * 60
WHERE id = ".$Game->id
);
return l_t('Process time reset successfully');
}
public function setProcessTimeToNowConfirm(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 start processing this game now?');
}
public function makePublic(array $params)
{
global $DB;
$gameID = intval($params['gameID']);
$DB->sql_put(
"UPDATE wD_Games
SET password = NULL
WHERE id = ".$gameID
);
return l_t('Password removed');
}
public function makePrivate(array $params)
{
global $DB;
$gameID = intval($params['gameID']);
$password=$params['password'];
$DB->sql_put(
"UPDATE wD_Games
SET password = UNHEX('".md5($password)."')
WHERE id = ".$gameID
);
return l_t('Password set to "%s"',$password);
}
public function setProcessTimeToNow(array $params)
{
global $DB;
$gameID = intval($params['gameID']);
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->Game($gameID);
if( $Game->processStatus != 'Not-processing' || $Game->phase == 'Finished' )
return l_t('This game is paused/crashed/finished.');
$DB->sql_put(
"UPDATE wD_Games
SET processTime = ".time()."
WHERE id = ".$Game->id
);
return 'Process time set to now successfully';
}
public function panic(array $params)
{
global $Misc;
$Misc->Panic = 1-$Misc->Panic;
$Misc->write();
return l_t('Panic button '.($Misc->Panic?'turned on':'turned off'));
}
public function resetPassConfirm(array $params)
{
global $DB;
$User= new User($params['userID']);
return l_t('Are you sure you want to reset the password of this user?');
}
public function resetPass(array $params)
{
global $DB,$User;
$ChangeUser= new User($params['userID']);
if( $ChangeUser->type['Admin'] || ( $ChangeUser->type['Moderator'] && !$User->type['Admin'] ) )
{
throw new Exception(l_t("Cannot reset an admin/moderator's password if you aren't admin."));
}
$password = base64_encode(rand(1000000,2000000));
$DB->sql_put(
"UPDATE wD_Users
SET password = UNHEX('".libAuth::pass_Hash($password)."')
WHERE id = ".$ChangeUser->id
);
return l_t('Users password reset to %s',$password);
}
public function drawGameConfirm(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 draw this game? This is really hard to undo, so be sure this is correct!');
}
public function drawGame(array $params)
{
global $DB, $Game;
$gameID = (int)$params['gameID'];
$DB->sql_put("BEGIN");
require_once(l_r('gamemaster/game.php'));
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->processGame($gameID);
if( $Game->phase != 'Diplomacy' and $Game->phase != 'Retreats' and $Game->phase != 'Builds' )
{
throw new Exception(l_t('This game is in phase %s, so it can\'t be drawn.',$Game->phase), 987);
}
$Game->setDrawn();
$DB->sql_put("COMMIT");
return l_t('The game was drawn.');
}
public function cancelGameConfirm(array $params)
{
global $DB;
require_once('objects/game.php');
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->Game($params['gameID']);
return l_t('Are you sure you want to cancel this game? This is really hard to undo, so be sure this is correct!');
}
public function cancelGame(array $params)
{
global $DB, $Game;
$gameID = (int)$params['gameID'];
$DB->sql_put("BEGIN");
require_once(l_r('gamemaster/game.php'));
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->processGame($gameID);
if( $Game->phase == 'Diplomacy' or $Game->phase == 'Retreats' or $Game->phase == 'Builds' )
{
$Game->setCancelled(); // This throws an exception, since it expects to be run from within the
// main gamemaster loop, and wants to stop the loop from continuing to use this game after
// it has been cancelled. But it also contains its own commit, so the exception does not prevent
// the game from being cancelled (it is messy though).
// This point after $Game->setCancelled(); shouldn't actually be reached.
}
elseif( $Game->phase == 'Finished' )
{
/*
* Some special action is needed; this game has already finished.
*
* We need to get back all winnings that have been distributed first, then we need to
* return all starting bets.
*
* Note: with the introduction of new scoring systems and with the introduction of free takeovers this logic no longer works right.
* As such it is being commented out. It is more important for moderators to be able to cancel an old game if absolutely necessary
* and to have to make manual point adjustments then to have this key functionality broken.
*/
/*$transactions = array();
$sumPoints = 0; // Used to ensure the total points transactions add up roughly to 0
$tabl = $DB->sql_tabl("SELECT type, points, userID, memberID FROM wD_PointsTransactions WHERE gameID = ".$Game->id
." FOR UPDATE"); // Lock it for update, so other transactions can't interfere with these ones
while(list($type, $points, $userID, $memberID) = $DB->tabl_row($tabl))
{
if( !isset($transactions[$userID])) $transactions[$userID] = array();
if( !isset($transactions[$userID][$type])) $transactions[$userID][$type] = 0;
if( $type != 'Bet' ) $points = $points * -1; // Bets are to be credited back, everything else is to be debited
if( $type != 'Supplement') $sumPoints += $points;
$transactions[$userID][$type] += $points;
}
// Check that the total points transactions within this game make sense (i.e. they add up to roughly 0 accounting for rounding errors)
if( $sumPoints < (count($transactions)*-1) or count($transactions) < $sumPoints )
throw new Exception(l_t("The total points transactions (in a finished game) add up to %s, but there are %s members; ".
"cannot cancel game with an unusual points transaction log.", $sumPoints, count($transactions)), 274);
// The points transactions make sense; we can now try and reverse them.
// Get the current points each user has
$tabl = $DB->sql_tabl("SELECT u.id, u.points FROM wD_Users u INNER JOIN wD_PointsTransactions pt ON pt.userID = u.id WHERE pt.gameID = ".$Game->id
." GROUP BY u.id, u.points "
." FOR UPDATE"); // Lock it for update, so other transactions can't interfere with these ones
$pointsInAccount = array();
$pointsInPlay = array();
while(list($userID, $points) = $DB->tabl_row($tabl))
{
$sumPoints = 0;
foreach($transactions[$userID] as $type=>$typePoints)
$sumPoints += $typePoints;
if( ( $points + $sumPoints) < 0 )
{
// If the user doesn't have enough points on hand to pay back the points transactions for this game we will need to supplement him the points to do it:
$supplementPoints = -($points + $sumPoints);
$points += $supplementPoints;
$DB->sql_put("INSERT INTO wD_PointsTransactions ( type, points, userID, gameID ) VALUES ( 'Supplement', ".$supplementPoints.", ".$userID.", ".$Game->id.")");
$DB->sql_put("UPDATE wD_Users SET points = ".$points." WHERE id = ".$userID);
}
// Now we have given the user enough points so their points transactions for this game can definitely be undone:
$DB->sql_put("INSERT INTO wD_PointsTransactions ( type, points, userID, gameID ) VALUES ( 'Correction', ".$sumPoints.", ".$userID.", ".$Game->id.")");
$points += $sumPoints;
$DB->sql_put("UPDATE wD_Users SET points = ".$points." WHERE id = ".$userID);
// Now check that they don't need a supplement to bring their total points in play back up to 100:
$pointsInPlay = User::pointsInPlay($userID);
if( ($points + $pointsInPlay) < 100 )
{
$supplementPoints = 100 - ($points + $pointsInPlay);
$points += $supplementPoints;
$DB->sql_put("INSERT INTO wD_PointsTransactions ( type, points, userID, gameID ) VALUES ( 'Supplement', ".$supplementPoints.", ".$userID.", ".$Game->id.")");
$DB->sql_put("UPDATE wD_Users SET points = ".$points." WHERE id = ".$userID);
}
notice::send(
$userID, $Game->id, 'Game',
'No', 'No',
l_t("This game has been cancelled after having finished (usually to undo the effects of cheating). ".
"%s points had to be added/taken from your account to undo the effects of the game. ".
"Please contact the mod team with any queries.", $sumPoints, $points),
$Game->name, $Game->id);
}*/
// Now backup and erase the game from existence, then commit:
processGame::eraseGame($Game->id);
}
else
{
throw new Exception(l_t('This game is in phase %s, so it can\'t be cancelled',$Game->phase), 987);
}
// $DB->sql_put("COMMIT"); // $
return l_t('This game was cancelled.');
}
public function togglePause(array $params)
{
global $DB, $Game;
$gameID = (int)$params['gameID'];
$DB->sql_put("BEGIN");
require_once(l_r('gamemaster/game.php'));
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->processGame($gameID);
$Game->togglePause();
$DB->sql_put("COMMIT");
return l_t('This game is now '.( $Game->processStatus == 'Paused' ? 'paused':'unpaused').'.');
}
public function cdUserConfirm(array $params)
{
global $DB;
require_once('objects/game.php');
$User = new User($params['userID']);
if ( isset($params['gameID']) && $params['gameID'] )
{
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->Game($params['gameID']);
}
return l_t('Are you sure you want to put this user into civil-disorder'.(isset($Game)?', in this game':', in all his games').'?');
}
public function cdUser(array $params)
{
global $DB, $Game;
require_once(l_r('gamemaster/game.php'));
$User = new User($params['userID']);
if ( isset($params['gameID']) && $params['gameID'] )
{
$Variant=libVariant::loadFromGameID($params['gameID']);
$Game = $Variant->processGame($params['gameID']);
// If the game is finished do not CD and throw an error.
if( $Game->phase == 'Finished' )
{
throw new Exception(l_t("Invalid phase to set CD"));
}
// If the game hasn't started check if there's just 1 person in it. If there is then delete the game, otherwise remove that 1 user.
else if( $Game->phase == 'Pre-game' )
{
if(count($Game->Members->ByID)==1) {
processGame::eraseGame($Game->id);
}
else{
$DB->sql_put("DELETE FROM wD_Members WHERE gameID = ".$Game->id." AND userID = ".$params['userID']);
// If there are still people in the game reset the min bet in case the game was full to readd the join button.
$Game->resetMinimumBet();
}
}
else{
$Game->Members->ByUserID[$User->id]->setLeft(1);
$Game->resetMinimumBet();
}
}
else
{
$tabl = $DB->sql_tabl("SELECT gameID, status FROM wD_Members
WHERE userID = ".$userID);
while( list($gameID, $status) = $DB->tabl_row($tabl) )
{
if ( $status != 'Playing' ) continue;
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->processGame($gameID);
$Game->Members->ByUserID[$User->id]->setLeft(1);
$Game->resetMinimumBet();
}
}
return l_t('This user was put into civil-disorder'.
((isset($params['gameID']) && $params['gameID'])?', in this game':', in all his games'));
}
public function replaceCoutries(array $params)
{
global $DB;
$gameIDs = (int)$params['gameIDs'];
$userID = (int)$params['userID'];
$replaceID = (int)$params['replaceID'];
$games = array();
$tabl = $DB->sql_tabl(
'SELECT gameID FROM wD_Members
WHERE status = "Playing" AND userID = "'.$userID.'"'.($gameIDs != 0 ? ' AND gameID = "'.$gameIDs.'"':'') );
while(list($gameID) = $DB->tabl_row($tabl))
$games[] = $gameID;
// Load the two users as Userobjects.
try
{
$SendToUser = new User($replaceID);
}
catch (Exception $e)
{
$error = l_t("Invalid user ID given.");
}
try
{
$SendFromUser = new User($userID);
}
catch (Exception $e)
{
$error = l_t("Invalid user ID given.");
}
$ret = '';
foreach ($games AS $gameID)
{
$Variant=libVariant::loadFromGameID($gameID);
$Game = $Variant->Game($gameID);
list($blocked) = $DB->sql_row("SELECT count(*) FROM wD_Members AS m WHERE m.gameID = ".$Game->id);
// Check for additional requirements:
if ( $Game->minimumReliabilityRating > $SendToUser->reliabilityRating)
{
$ret .= '<b>Error:</b> The reliability of '.$SendToUser->username.' is not high enough to join the game <a href="board.php?gameID='.$Game->id.'">'.$Game->name.'</a>.<br>';
}
elseif ( array_key_exists ( $SendToUser->id , $Game->Members->ByUserID))
{
$ret .= '<b>Error:</b> '.$SendToUser->username.' is already a member of the game <a href="board.php?gameID='.$Game->id.'">'.$Game->name.'</a>.<br>';
}
else
{
$DB->sql_put("UPDATE wD_Members SET userID = ".$SendToUser->id." WHERE userID=".$SendFromUser->id." AND gameID=".$Game->id);
$ret.= 'In game <a href="board.php?gameID='.$Game->id.'">'.$Game->name.'</a> the user '.$SendFromUser->username.' was removed and replaced by '.$SendToUser->username.'.<br>';
}
}
return $ret;
}
public function replaceCoutriesConfirm(array $params)
{
global $DB;
$userID = (int)$params['userID'];
$replaceID = (int)$params['replaceID'];
$gameIDs = (int)$params['gameIDs'];
list($userName) = $DB->sql_row("SELECT username FROM wD_Users WHERE id=".$userID);
list($replaceName) = $DB->sql_row("SELECT username FROM wD_Users WHERE id=".$replaceID);
if ($gameIDs == 0)
{