-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlot_manager.php
2131 lines (1937 loc) · 81.5 KB
/
lot_manager.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
/*
* This file is part of Uncovery Minecraft.
* Copyright (C) 2015 uncovery.me
*
* Uncovery Minecraft is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* This is the central lot management system, mainly used during lot registration
* when becoming a Settler or on the website when regisering a lot or managing
* the lot features. This system is quite complex and - if broken - can create
* a huge amount of issues on the server, hadle with care.
*/
global $UMC_USER;
/**
* Main Lot manager function, single direct entry into the file
*/
function umc_lot_manager_main() {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER, $UMC_DOMAIN;
// levels which should be able to get draftlands lots
$elder_ranks = array('Elder', 'ElderDonator', 'Owner');
// ***** ACCESS ***** //
$out = '';
if (!$UMC_USER) {
return "<strong>You need to be <a href=\"$UMC_DOMAIN/wp-login.php\">logged in</a></strong> to see this!\n";
} else {
$username = $UMC_USER['username'];
$userlevel = $UMC_USER['userlevel'];
$uuid = $UMC_USER['uuid'];
}
if ($userlevel == 'Guest') {
return "Since you are not Settler yet, you need to go to <a href=\"$UMC_DOMAIN/private-area-allocation-map/\">this page</a> to become one!";
} else if (in_array($userlevel, $elder_ranks)) {
$worlds = array('empire', 'aether', 'kingdom', 'skyblock', 'draftlands');
} else {
$worlds = array('empire', 'aether', 'kingdom', 'skyblock');
}
$out .= "Welcome $username ($userlevel)!<br>";
// ***** INITIALIZE ***** //
if (!isset($UMC_USER['lots'])) {
$UMC_USER['lots'] = array();
foreach ($worlds as $world) {
$UMC_USER['lots'][$world] = umc_get_lot_number($uuid, $world);
}
}
$sani_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$sani_get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
// is this a form for a single lot?
$edit_lot = false;
if (isset($sani_post['edit_lot'])) {
$world = umc_get_lot_world($sani_post['lot']);
$edit_lot = $sani_post['lot'];
} else if (isset($sani_get['world'])) {
$world = $sani_get['world'];
if (!in_array($world, $worlds)) {
$world = 'empire';
}
} else {
$world = 'empire';
}
if ($world == 'flatlands') {
$world = 'empire';
}
if (isset($sani_post['delete_dib'])) {
$dib_lot = $sani_post['lot'];
$out .= umc_lot_manager_dib_delete($uuid, $dib_lot);
}
if (isset($sani_post['save_lot'])) {
$out .= umc_lot_manager_process();
}
if (isset($sani_post['new_lot']) && ($sani_post['new_lot'] != 'false')) {
// add the new lot
$check = umc_lot_manager_check_before_assign($uuid, $sani_post['new_lot']);
if ($check['result']) {
umc_lot_add_player($uuid, $sani_post['new_lot'], 1, $check['cost']);
}
$out .= $check['text'];
}
if (isset($sani_post['new_dib']) && ($sani_post['new_dib'] != 'false')) {
// add the new lot
$result = umc_lot_manager_dib_add($uuid, $sani_post['new_dib'], $sani_post['dib_action']);
$out .= $result;
}
$out .= "\n<strong>Notes:</strong>
<ol>
<li>
If you chose to <strong>abandon, refund or give</strong> a lot to someone else, you will <span style=\"color: #ff0000;\">lose access immediately</span>!
If that gives you free available lots in the same world, you can pick a new lot immediately!
</li>
<li>
If you chose to <strong>reset</strong> a lot <span style=\"color: #ff0000;\">EVERYTHING</span> on the lot will be gone!
Resets will happen at the next restart of the server. Until then, you can still change your mind.
Restarts are at 16:00 HKG (see time at the server status on the front page)
</li>
<li>You can abandon a flatlands lot anytime and get an empire lot for it, but you cannot abandon an empire lot if it is generated with the current minecraft version!</li>
<li>You can get dibs on an occupied lot. If nobody before you called dibs, you will get the lot once it's abandoned - provided you have the free lots/cash. This will be checcked at the moment of transfer. If you do not, the next in line gets it</li>
</ol>
The tabs show \"World (Owned Lots/Max lots/Dibs)\"
\n";
$out .= umc_lot_manager_menu($worlds, $world);
$current_lots = $UMC_USER['lots'][$world];
// get user lots per world
$out .= "<div class=\"formbox\">";
$out .= umc_lot_manager_get_lots($world, $edit_lot);
$uworld = ucwords($world);
if ($world == 'empire') {
$uworld = 'Empire & Flatlands';
}
// in the dibs tab, we do not show a "new lot form".
$out .= umc_lot_costs_simulation($world);
$form = umc_lot_manager_new_lot_form($world);
if ($current_lots['avail_lots'] == 0) {
$out .= "<div class=\"newlotform\">You do not have enough available lots to get one in $uworld!</div>";
} else if (!$form) {
$out .= "<div class=\"newlotform\">There are no available lots for you in $uworld! "
. "Further, we are changing the way kingdom lots are being bought, until then, no new lots are up for sale."
. "You need to be Citizen for Ather lots. Also, you need to have 10'000 Uncs in your account for Kingdom lots, 50k for Draftland lots.</div>";
return $out;
} else {
$out .= "<form class=\"newlotform\" method=\"POST\">\n"
. "<p><strong>Get a new lot:</strong></p>\n"
. "<p>You have {$current_lots['avail_lots']} lots available in $uworld.<br>If you want an additional lot, please chose from the list: "
. $form . " <input type=\"submit\" name=\"submit\" value=\"Get this lot\"></p>\n</form>\n";
}
// dibs form
if ($world != 'draftlands') {
$dibs_form = umc_lot_manager_new_lot_form($world, true);
$out .= "<form class=\"newlotform\" method=\"POST\">\n"
. "<p><strong>Call dibs for an occupied lot:</strong></p>\n"
. "<p>If you call dibs, you will be given that lot once it becomes available and if you have the resources (money/free lots) "
. "for it at that moment. If there are other people who called dibs first, they will get it instead "
. $dibs_form . " <input type=\"submit\" name=\"submit\" value=\"Call dibs!\"></p>\n</form>\n";
}
$out .= "</div>";
return $out;
}
/**
* Display the menu on top of the lot manager page
*
*/
function umc_lot_manager_menu($worlds, $world) {
global $UMC_USER;
// top menu
$out = '<ul class="lot_tabs">' . "\n";
// get available worlds
foreach ($worlds as $menu_world) {
$user_lots = $UMC_USER['lots'][$menu_world];
// create tabs
$uworld = ucwords($menu_world);
if ($menu_world == 'empire') {
$uworld = 'Empire & Flatlands';
}
$taken_lots = $user_lots['used_lots'];
$max_lots = $user_lots['max_lots'];
$dibs = count($UMC_USER['lots'][$menu_world]['dib_list']);
$count_str = "($taken_lots/$max_lots/$dibs)";
if ($world == $menu_world) {
$out .= "<li class=\"active_world\">$uworld $count_str</li>";
} else {
$out .= "<li><a href=\"?world=$menu_world\">$uworld $count_str</a></li>";
}
}
$out .= "</ul><div style=\"clear:both\"></div>";
return $out;
}
/**
* Get all lots that the user has for a specific world
*
* @global type $UMC_USER
* @global type $UMC_SETTING
* @param type $world
* @param type $edit_lot
* @return string
*/
function umc_lot_manager_get_lots($world, $edit_lot) {
global $UMC_USER;
$world_lots = $UMC_USER['lots'][$world]['lot_list'];
// list existing lots
$out = "";
foreach ($world_lots as $lot => $lot_data) {
$form = false;
$button = "<input class=\"submitbutton\" type=\"submit\" name=\"edit_lot\" value=\"Edit $lot\">";
$class = '';
if ($lot == $edit_lot) {
$class = ' editform';
$form = true;
$button = "<input class=\"submitbutton\" type=\"submit\" name=\"save_lot\" value=\"Save\">";
}
$members_form = umc_get_member_form($lot, $form);
$flags_form = umc_get_flag_form($lot, $form);
$lot_change_form = umc_get_lot_change_form($lot, $form);
$image = umc_lot_get_tile($lot);
$out .= "<a name=\"$lot\"></a><form style=\"overflow:auto;\" action=\"#$lot\" class=\"lotform$class\" method=\"POST\">
<input type=\"hidden\" name=\"lot\" value=\"$lot\">
<div>
$image
<div class=\"lot_features\">
<p><strong>Lot:</strong> $lot</p>
<p><strong>Members:</strong> $members_form</p>
<p><strong>Flags:</strong> $flags_form</p>
<p>$lot_change_form</p>
</div>
$button
</div>
</form>\n";
}
// get dibs
// $out .= "<div>Dibs</div>\n";
$dibs = $UMC_USER['lots'][$world]['dib_list'];
foreach ($dibs as $lot => $lot_data) {
$form = false;
$button = "<input class=\"submitbutton\" type=\"submit\" name=\"delete_dib\" value=\"Cancel dibs on $lot\">";
$class = '';
$image = umc_lot_get_tile($lot);
$action = $lot_data['action'];
$out .= "<a name=\"$lot\"></a><form action=\"#$lot\" style=\"overflow:auto;\" class=\"lotform\" method=\"POST\">
<input type=\"hidden\" name=\"lot\" value=\"$lot\">
<div>
$image
<div class=\"lot_features\">
<p><strong>Dibs on Lot:</strong>$lot</p>
<p><strong>Action:</strong> $action</p>
</div>
$button
</div>
</form>\n";
}
return $out;
}
/**
* returns the minimum user level and money that is needed to get a lot in a certain world.
*
* @param type $userlevel
* @param type $world
*/
function umc_lot_manager_minimum_requirements($userlevel, $world) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
// Check for userlevel
global $UMC_SETTING;
$max_lots = $UMC_SETTING['lot_limits'][$userlevel][$world];
$out = "As $userlevel level user, you can get a max of $max_lots in $world.";
if ($world == 'kingdom') {
$min_price = $UMC_SETTING['lot_costs']['^draft_[a-zA-Z]+\d*$'];
} else if ($world == 'skyblock') {
$min_price = $UMC_SETTING['lot_costs']['^block_[a-zA-Z]+\d*$'];
} else {
return $out;
}
$out . " Further, in $world, you need $min_price Uncs to get your first lot.";
return $out;
}
/*
* retrieves a region from it's coordinates and the world
*/
function umc_lot_get_from_coords($x, $z, $world) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
$floor_x = floor($x);
$floot_z = floor($z);
$sql = "SELECT region_id from minecraft_worldguard.region_cuboid
LEFT JOIN minecraft_worldguard.world ON world_id=id
WHERE min_x<=$floor_x
AND min_z<=$floot_z
AND max_x>=$floor_x
AND max_z>=$floot_z
AND name='$world'
LIMIT 1;";
$D = umc_mysql_fetch_all($sql);
if (count($D) == 0) {
return false;
} else {
$region = $D[0]['region_id'];
}
return $region;
}
/*
* this processes forms from the lot manager before displaying it.
*/
function umc_lot_manager_process() {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER;
$out = '';
$sani_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
// var_dump($sani_post);
$lot = $sani_post['lot'];
$check_owner = umc_check_lot_owner($lot, $UMC_USER['username']);
if (!$check_owner) {
XMPP_ERROR_trigger($UMC_USER['username'] . " tried to edit lot $lot, but is not owner! (umc_lot_manager_process)");
die('umc_lot_manager_process');
}
// process flags
if (isset($sani_post['flag'])) {
$flag_arr = $sani_post['flag'];
foreach($flag_arr as $flag => $value) {
$check = umc_lot_set_flag($lot, $flag, $value);
}
}
// process new members
$new_member = $sani_post['new_member'];
$check = false;
if ($new_member != 'none') {
$check = umc_lot_add_player($new_member, $lot, 0);
}
if ($check) {
$out .= "$new_member added to $lot!";
}
// process removed members
if (isset($sani_post['remove_member'])) {
$remove_arr = $sani_post['remove_member'];
foreach ($remove_arr as $member => $data) {
$check = umc_lot_rem_player($member, $lot, 0);
}
}
// process lot changes
if (isset($sani_post['lot_action'])) {
$lot_action = $sani_post['lot_action'];
$out .= umc_lot_do_action($lot, $lot_action);
}
return $out;
}
/**
* Deletes a dib for a lot of a specific user.
* If lot=false, all dibs of that user will be removed (when a user becomes inactive)
*
* @global type $UMC_USER
* @param type $uuid
* @param type $lot
* @return string
*/
function umc_lot_manager_dib_delete($uuid, $lot = false) {
global $UMC_USER;
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
$lot_sql = '';
if ($lot) {
$lot_sql = "AND lot=" . umc_mysql_real_escape_string($lot);
$world = umc_get_lot_world($lot);
if ($UMC_USER && isset($UMC_USER['lots'][$world]['dib_list'][$lot])) {
unset($UMC_USER['lots'][$world]['dib_list'][$lot]);
}
$log_msg = "for lot $lot in world $world";
} else { // we remove all dibs, so we
$log_msg = "for all lots";
}
$sql = "DELETE FROM minecraft_srvr.lot_reservation WHERE uuid='$uuid' $lot_sql;";
$count = umc_mysql_execute_query($sql);
XMPP_ERROR_send_msg("User $uuid removed $count dibs $log_msg");
umc_log("Lot", "wipe_user_dibs", "$count dibs removed from $uuid");
}
/**
* Adds a dib for a lot of a specific user.
* If lot=false, all dibs of that user will be removed (when a user becomes inactive)
*
* @param type $uuid
* @param type $lot
* @param type $action
* @return string
*/
function umc_lot_manager_dib_add($uuid, $lot, $action) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER;
// check first if dib exists already
$world = umc_get_lot_world($lot);
$dibs = umc_lot_manager_dib_get_number($uuid, $world);
if (isset($dibs[$lot])) {
return false;
}
$sql = "INSERT INTO minecraft_srvr.lot_reservation(`uuid`, `lot`, `world`, `action`) VALUES ('$uuid','$lot','$world','$action')";
umc_mysql_execute_query($sql);
// refresh the variable
$UMC_USER['lots'][$world]['dib_list'] = umc_lot_manager_dib_get_number($uuid, $world);
$out = "Successfully added dib for lot $lot;";
XMPP_ERROR_send_msg("User $uuid got dibs for lot $lot in world $world");
return $out;
}
/**
* iterates all dibs and kicks out invalid ones (user is not active or owns the lot already
*/
function umc_lot_manager_dib_cleanup() {
$sql = "SELECT * FROM minecraft_srvr.lot_reservation;";
$R = umc_mysql_fetch_all($sql);
foreach ($R as $r) {
$uuid = $r['uuid'];
$lot = $r['lot'];
$countlots = umc_user_countlots($uuid);
if ($countlots < 1) {
XMPP_ERROR_send_msg("User $uuid is not active anymore, remove dibs for $lot!");
umc_lot_manager_dib_delete($uuid, $lot);
} else {
$user_lots = umc_user_getlots($uuid);
if (isset($user_lots[$lot])) {
XMPP_ERROR_send_msg("User $uuid is owner of $lot already, remove dibs!");
umc_lot_manager_dib_delete($uuid, $lot);
}
}
}
}
/*
* displays a form where you can change the lot
*/
function umc_get_lot_change_form($lot, $form = false) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
// get possible options
$options = umc_get_lot_options($lot, $form);
// get current option
$sql = "SELECT choice FROM minecraft_srvr.lot_version WHERE lot='$lot'";
$D = umc_mysql_fetch_all($sql);
$choice = $D[0]['choice'];
If ($choice != null) {
$out = "<strong>Lot action on next server restart:</strong> ";
} else {
$out = "<strong>Available Lot actions:</strong> ";
}
$selected = array();
$selected[$choice] = " selected=\"selected\"";
if (count($options) < 1) {
return $out . "No actions available";
} else {
if ($form) {
$out .= "<select name=\"lot_action\">";
foreach ($options as $option => $text) {
$sel_str = '';
if (isset($selected[$option])) {
$sel_str = $selected[$option];
}
$out .= "<option value=\"$option\"$sel_str>$text</option>\n";
}
$out .= "</select> (Resets happen @ next reboot in " . umc_time_until_restart() .")";
} else {
if ($choice == null) {
$out .= "<ul>";
foreach ($options as $option => $text) {
$out .= "<li>$text</li>";
}
$out .= "</ul>";
} else {
$out .= "$choice (@ next reboot in " . umc_time_until_restart() .")";
}
}
return $out;
}
}
function umc_lot_do_action($lot, $choice) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER;
$username = $UMC_USER['username'];
$world = umc_get_lot_world($lot);
$options = umc_get_lot_options($lot, true); // get ALL choices
$members = umc_get_active_members();
if (!isset($options[$choice]) && !in_array($choice, $members)) {
XMPP_ERROR_trigger("attemped to execute $choice on $lot, but action is not available!");
die('umc_lot_do_action');
}
$message = '';
switch($choice) {
case 'abandon':
umc_lot_remove_all($lot);
umc_lot_add_player('_abandoned_', $lot, 1);
$message = "Your access to lot $lot has been removed. It will be reset on the next server restart";
umc_log('lot_manager', 'abandon', "$username abandoned $lot in $world. Reset on restart pending.");
break;
case 'reset':
$sql = "UPDATE minecraft_srvr.lot_version SET `choice`='reset' WHERE lot='$lot';";
umc_mysql_execute_query($sql);
$message = 'Your lot $lot will be reset on the next server restart. Please get all your goods from it ASAP.';
umc_log('lot_manager', 'RESET', "$username asked for reset of $lot in $world. Reset on restart pending.");
break;
case 'refund':
$costs = umc_lot_get_costs($lot);
$refund = $costs / 2;
umc_money(false, $username, $refund);
$message = "Your access to lot $lot has been removed. "
. "It will be reset on the next server restart. "
. "$refund Uncs have been transferred to your account.";
umc_lot_remove_all($lot);
umc_lot_add_player('_abandoned_', $lot, 1);
umc_log('lot_manager', 'REFUND', "$username asked for refund of $lot in $world. $refund uncs paid. Reset on restart pending.");
break;
case 'none':
$sql = "UPDATE minecraft_srvr.lot_version SET `choice`=NULL WHERE lot='$lot';";
umc_mysql_execute_query($sql);
break;
default:
if ($world == 'kingdom') { // gifting choices for kingdom
if (isset($choice, $members)) {
XMPP_ERROR_send_msg("$username tries to give $lot to $choice");
// This is pre-checked already but let's make sure this does not conflict and fail with other upcomingoptions
umc_lot_remove_all($lot);
umc_lot_add_player($choice, $lot, 1);
umc_log('lot_manager', 'TRANSFER', "$username gave lot $lot in $world to $choice");
}
} else if (($world == 'flatlands') || ($world == 'skyblock') || ($world == 'draftlands')) {
$sql = "UPDATE minecraft_srvr.lot_version SET `choice`='$choice' WHERE lot='$lot';";
umc_mysql_execute_query($sql);
umc_log('lot_manager', 'RESET', "$username had lot $lot reset to choice $choice");
} else {
XMPP_ERROR_trigger("$username had invalid choice $choice for $lot in $world!");
}
}
return $message;
}
/*
* this finds out what one can do with the lot
*/
function umc_get_lot_options($lot, $form = false){
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_SETTING;
$sql = "SELECT version FROM minecraft_srvr.lot_version WHERE lot='$lot';";
$D = umc_mysql_fetch_all($sql);
$row = $D[0];
$world = umc_get_lot_world($lot);
$mint_version = $UMC_SETTING['world_data'][$world]['mint_version'];
if ($form) {
$lot_options = array('none' => 'Leave as-is');
} else {
$lot_options = array();
}
if ($world == 'kingdom') {
$lot_options['abandon'] = 'Abandon now (no refund, lot will be reset)!';
// $lot_options['refund'] = 'abandon & reset (refunds 50%)';
/*
if ($form) {
$members = umc_get_active_members();
foreach ($members as $uuid => $member) {
$lot_options[$uuid] = "Gift to $member";
}
} else {
$lot_options['gift'] = "Gift to someone (as-is)";
}
*/
} else if ($world == 'draftlands') {
// allow gift & refund etc
$lot_options['refund'] = 'abandon & reset (refunds 50%)';
$lot_options['reset'] = 'reset to flatlands';
$lot_options['mint_king'] = 'reset to mint kingdom';
$lot_options['curr_king'] = 'reset to current kingdom';
return $lot_options;
} else if ($world == 'flatlands' || $world == 'skyblock') {
$lot_choices = $UMC_SETTING['mint_lots'][$world];
foreach($lot_choices as $lot_choice => $desc) {
$lot_options[$lot_choice] = $desc;
}
}
if ($mint_version == '0') {
$lot_options['abandon'] = 'Abandon now!';
} else if ($mint_version != $row['version']) {
$lot_options['reset'] = "Wipe & Reset to version " . $mint_version;
$lot_options['abandon'] = 'Abandon now!';
}
return $lot_options;
}
/*
* This is converting a draftlands lot to the appropriate kingdom lot
* and vice-versa
*/
function umc_get_draftlands_kingdom_equivalent($draftlands_lot) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
$target = 'king_';
if (substr($draftlands_lot, 0, 4) == 'king') {
$target = 'draft_';
}
$lot_arr = explode("_", $draftlands_lot);
array_shift($lot_arr);
$kingdom_arr = $target . implode("_", $lot_arr);
return $kingdom_arr;
}
// displays a form to chose a new lot in a specific world.
// merges empire & flatlands worlds
function umc_lot_manager_new_lot_form($world, $dibs = false) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER;
$out = '';
$docs = "<ul>\n";
if (!$dibs) {
$avail_lots = umc_get_available_lots($world);
// we show flatlands & empire together
if ($world == 'empire') {
$avail_lots = array_merge($avail_lots, umc_get_available_lots('flatlands'));
}
$out .= "<select name=\"new_lot\">";
$multiplier = 1;
$actions = "";
} else {
$avail_lots = umc_lot_manager_get_occupied_lots($world);
// we show flatlands & empire together
if ($world == 'empire') {
$avail_lots = array_merge($avail_lots, umc_lot_manager_get_occupied_lots('flatlands'));
}
$out .= "<select name=\"new_dib\">";
$actions = "<select name=\"dib_action\"><option value=\"none\">[none]</option><option value=\"reset\">Reset</option></select>\n";
$multiplier = 2;
}
$out .= "<option value=\"false\">[none]</option>\n";
$mainlot = false;
If ($world == 'kingdom' || $world == 'draftlands') {
// check if the user has a main lot already, if not, hide street lots.
$mainlot = umc_check_if_world_mainlot($world);
}
if ($world == 'kingdom' && $dibs == false) {
$docs .= "<li><strong>Snow:</strong> It might not snow anymore on a lot that has snow on it now! Please see the <a href=\"https://uncovery.me/about-this-server/faq/\">FAQ</a> for more info.</li>";
}
$uuid = $UMC_USER['uuid'];
$account = umc_money_check($uuid);
// get allowed draftland lots
if ($world == 'draftlands') {
$draft_lots = array();
$world_lots = $UMC_USER['lots']['kingdom']['lot_list'];
foreach ($world_lots as $lot) {
$draft_lots[] = str_replace('king', 'draft', $lot);
}
}
$count = 0;
$fixed_lots = array();
foreach ($avail_lots as $lot => $distance) {
// we match the king_a1_b with "world" = king, "alpha" = a, "number" = 1, "extras" = _b
$regex = '/(?P<world>^[a-z]*_)(?P<alpha>[a-z]*)(?P<number>[0-9]*)(?P<extras>.*)/';
$matches = false;
preg_match($regex, $lot, $matches);
$new_lot_name = $matches['world'] . str_pad($matches['alpha'], 3, 0, STR_PAD_LEFT) . str_pad($matches['number'], 3, 0, STR_PAD_LEFT) . $matches['extras'];
$fixed_lots[$new_lot_name] = $lot;
}
ksort($fixed_lots);
// lots might be hidden for various reasons. Show those with this array.
$unavailable = array(
'dibs' => array('count' => 0, 'reason' => 'lots unavailable since you already have dibs on them.'),
'draftlands' => array('count' => 0, 'reason' => 'draftlands lots unavailable since you don\'t own the corresponding Kingdom lots.'),
'price_issues' => array('count' => 0, 'reason' => 'lots unavailable since you cannot afford them.'),
'street_lots' => array('count' => 0, 'reason' => 'street lots unavailable since you don\'t own a main lot.'),
);
foreach ($fixed_lots as $lot) {
// drop already diped losts
if ($dibs && isset($UMC_USER['lots'][$world]['dib_list'][$lot])) {
$unavailable['dibs']['count']++;
continue;
}
// only draftland lots where the user has the equivalent kingdom lot
if ($world == 'draftlands' && !in_array($lot, $draft_lots)) {
$unavailable['draftlands']['count']++;
continue;
}
// check costs
$price = umc_lot_get_costs($lot);
if ($price) {
if ($price > $account) {
$unavailable['price_issues']['count']++;
continue;
}
$price = number_format($price * $multiplier, 0, ',', '\'');
}
// kingdom street lots check
if (($world == 'kingdom' || $world == 'draftlands') && !$mainlot) {
$lot_segments = explode("_", $lot);
if (count($lot_segments) > 2) {
$unavailable['street_lots']['count']++;
continue;
}
}
$count++;
$out .= "<option value=\"$lot\">$lot @ $price</option>\n";
}
$out .= "</select><br>";
if ($actions != '') {
$out .= "Action on Tranfer: " . $actions;
}
if ($count == 0) {
$out = umc_lot_manager_minimum_requirements($UMC_USER['userlevel'], $world);
return false;
}
// iterate reasons of unavailability and show if lots were hidden
foreach ($unavailable as $title => $U) {
if ($U['count'] > 0) {
$title_nice = umc_pretty_name($title);
$docs .= "<li><strong>$title_nice:</strong> {$U['count']} {$U['reason']}</li>";
}
}
$docs .= "</ul>";
return $out . $docs;
}
/*
* Kingdom / draftlands street lots are only available if the user has a main lot. This
* process checks if that is true.
*/
function umc_check_if_world_mainlot($world) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER, $UMC_SETTING;
// iterate kingdom / draftlands lots to find main lots
$world_lots = $UMC_USER['lots'][$world]['lot_list'];
$prefix = $UMC_SETTING['world_data'][$world]['prefix'];
foreach ($world_lots as $world_lot => $world_lot_data) {
$check = preg_match("/^{$prefix}_[a-zA-Z]+\d*$/", $world_lot);
if ($check) {
return true;
}
}
return false;
}
/*
* This shows a form to add new members to the lot
* Lists only active members
*/
function umc_get_member_form($lot, $form = false) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER;
$username = $UMC_USER['username'];
$members = umc_get_active_members();
$lot_members = umc_get_lot_members($lot);
$out = '';
if ($lot_members) {
if ($form) {
$out .= '<br>Check members you want to remove: ';
}
// make a form where existing members can be removed
foreach ($lot_members as $UUID => $member) {
// remoe all inactive members from the lot
if (!isset($members[$UUID])) {
XMPP_ERROR_trace("Removing inactive player $UUID from lot, list of active members:", $members);
umc_lot_rem_player($UUID, $lot, 0);
}
if ($form) {
$out .= "$member <input type=\"checkbox\" name=\"remove_member[$UUID]\">;";
} else {
$out .= "$member; ";
}
}
} else {
$out .= "No members";
}
if (!$form) {
return $out;
}
$out .= "<br>Add member: <select name=\"new_member\">"
. "<option value=\"none\">- none -</option>\n";
foreach ($members as $member) {
// do not add the lot owner
if ($member == $username) {
continue;
}
// do not add existing members again
if (!$lot_members || !in_array($member, $lot_members)) {
$out .= "<option value=\"$member\">$member</option>\n";
}
}
$out .= "</select>";
return $out;
}
/*
* adds a form that lets you chose flags for a lot
*/
function umc_get_flag_form($lot, $form = false) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_USER, $UMC_SETTING;
$out = '';
if ($UMC_USER['donator'] == 'Donator' || $UMC_USER['username'] == 'uncovery') {
$flags = umc_get_lot_flags($lot);
$avail_flags = $UMC_SETTING['lot_flags'];
foreach ($avail_flags as $flag) {
if ($form) {
$selected = array();
if (isset($flags[$flag])) {
$value = $flags[$flag];
$selected[$value] = " selected=\"selected\"";
}
$sel_allow = '';
$sel_deny = '';
if (isset($selected['allow'])) {
$sel_allow = $selected['allow'];
}
if (isset($selected['deny'])) {
$sel_deny = $selected['deny'];
}
$out .= " $flag: <select name=\"flag[$flag]\">"
. "<option value=\"false\">n/a</option>\n"
. "<option value=\"allow\"$sel_allow>allow</option>\n"
. "<option value=\"deny\"$sel_deny>deny</option>\n"
. "</select>";
} else if (isset($flags[$flag])) {
$value = $flags[$flag];
$out .= "$flag: $value; ";
}
}
if (!$form && !$flags) {
$out .= "No flags set";
}
} else if ($form) {
$out .= "Flag changes are only available to Donators;";
} else {
$out .= " No Flags;";
}
return $out;
}
function umc_lot_set_flag($lot, $flag, $value) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
global $UMC_SETTING;
$flag_values = array('allow', 'deny', 'false');
$world = umc_get_lot_world($lot);
$world_id = umc_get_worldguard_id('world', $world);
if (!$world) {
XMPP_ERROR_trigger("World could not be found for lot_name $lot, $flag, $value (umc_lot_set_flag)");
die('umc_lot_set_flag');
}
if (!in_array($flag, $UMC_SETTING['lot_flags'])) {
XMPP_ERROR_trigger("attempt to set invalid flag $flag (umc_lot_set_flag)");
die('umc_lot_set_flag');
}
if (!in_array($value, $flag_values)) {
XMPP_ERROR_trigger("attempt to set invalid flag value $value (umc_lot_set_flag)");
die('umc_lot_set_flag');
}
// first, find out if the flag is set
$sql = "SELECT value FROM minecraft_worldguard.region_flag WHERE world_id=$world_id AND region_id='$lot' AND flag='$flag';";
$D = umc_mysql_fetch_all($sql);
if (count($D) > 0) {
$old_value = $D[0]['value'];
} else {
$old_value = false;
}
if ($old_value && $value == 'false') { //remove flag
$sql = "DELETE FROM minecraft_worldguard.region_flag WHERE world_id=$world_id AND region_id='$lot' AND flag='$flag';";
umc_log('lot_manager', 'remove flag', "$flag was removed from lot $lot");
} else if ($old_value && ($old_value != $value)){ // update with new value
$sql = "UPDATE minecraft_worldguard.region_flag SET value='$value' WHERE world_id=$world_id AND region_id='$lot' AND flag='$flag';";
umc_log('lot_manager', 'remove player', "$flag was changed for lot $lot to $value");
} else if (!$old_value && $value != 'false') { // insert new flag, but only if needed
$sql = "INSERT INTO minecraft_worldguard.region_flag (`region_id`, `world_id`, `flag`, `value`) VALUES ('$lot',$world_id,'$flag','$value')";
umc_log('lot_manager', 'remove player', "New $flag was set for lot $lot to $value");
} else { // nothing to do
return;
}
umc_mysql_execute_query($sql);
}
/**
* Check if a user can have a lot or not, also check for money requirements
*
* @param type $user
* @param type $new_lot
* @return boolean|string\
*/
function umc_lot_manager_check_before_assign($user, $new_lot) {
XMPP_ERROR_trace(__FUNCTION__, func_get_args());
// get username
$U = umc_uuid_getboth($user);
$uuid = $U['uuid'];
$username = $U['username'];
// validate input and check if lot is free
// find world & sanitize
$world = umc_get_lot_world($new_lot);
$userlevel = umc_userlevel_get($uuid);
if (!$world) {
XMPP_ERROR_send_msg("Guest $username tried to get lot $new_lot, but world could not be found! (umc_assign_new_lot)");
$result = array('result' => false, 'text' => "The lot you chose is invalid!", 'cost' => false);
return $result;
}
$cost = umc_lot_get_costs($new_lot);
// guests need to get either an empire or flatlands lot
$guest_worlds = array('empire', 'flatlands');
if (($userlevel == 'Guest') && !in_array($world, $guest_worlds)) {
XMPP_ERROR_send_msg("Guest $username tried to get lot $new_lot in $world (umc_assign_new_lot)");
$result = array('result' => false, 'text' => "You can only get lots in Empire & Flatlands as Guest!", 'cost' => $cost);
return $result;
}
$userlots = umc_get_lot_number($uuid, $world);
// check costs
if ($cost) { // see if the user has enough money
$balance = umc_money_check($uuid);
if ($balance < $cost) {
XMPP_ERROR_send_msg("User $username did not have enough money to get $new_lot (umc_assign_new_lot)");
$result = array('result' => false, 'text' => "You do not have enough money to get this lot!", 'cost' => $cost);
return $result;
}
}
//check if user has approriate kingdom lot
if ($world == 'draftlands') {
$draft_lots = array();
$king_lots = umc_get_lot_number($uuid, 'kingdom');
$king_lots_list = $king_lots['lot_list'];
foreach ($king_lots_list as $king_lot) {
$draft_lots[] = str_replace('king', 'draft', $king_lot);
}
if (!in_array($new_lot, $draft_lots)) {
$result = array('result' => false, 'text' => "You need to own the same kingdom lot!", 'cost' => $cost);
return $result;
}
}
// check if the lot is owned already by someone
$occupied_check = umc_check_lot_owner($new_lot, false);
if ($occupied_check) {
XMPP_ERROR_trigger("User $username tried to get $new_lot but someone else owns it! (umc_assign_new_lot)");
$result = array('result' => false, 'text' => "This lot is owned by someone else already!", 'cost' => $cost);
return $result;
}
// check if user has lots free
if (isset($userlots['lot_list'][$new_lot])) {
XMPP_ERROR_send_msg("User $username tried to get $new_lot but is an owner already! (umc_assign_new_lot)");
$result = array('result' => false, 'text' => "You own this lot already!", 'cost' => $cost);
return $result;
} else if ($userlots['avail_lots'] > 0) {
// user can get the lot!
umc_log("lot_manager", "assign_new_lot", "$username was added as owner to lot $new_lot");