forked from Znote/ZnoteAAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auctionChar.php
958 lines (939 loc) · 33.2 KB
/
auctionChar.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
<?php require_once 'engine/init.php';
protect_page();
include 'layout/overall/header.php';
// Convert a seconds integer value into days, hours, minutes and seconds string.
function toDuration($is) {
$duration['day'] = $is / (24 * 60 * 60);
if (($duration['day'] - (int)$duration['day']) > 0)
$duration['hour'] = ($duration['day'] - (int)$duration['day']) * 24;
if (isset($duration['hour'])) {
if (($duration['hour'] - (int)$duration['hour']) > 0)
$duration['minute'] = ($duration['hour'] - (int)$duration['hour']) * 60;
if (isset($duration['minute'])) {
if (($duration['minute'] - (int)$duration['minute']) > 0)
$duration['second'] = ($duration['minute'] - (int)$duration['minute']) * 60;
}
}
$tmp = array();
foreach ($duration as $type => $value) {
if ($value >= 1) {
$pluralType = ((int)$value === 1) ? $type : $type . 's';
if ($type !== 'second') $tmp[] = (int)$value . " $pluralType";
else $tmp[] = (int)$value . " $pluralType";
}
}
return implode(', ', $tmp);
}
?>
<h1>Character auction</h1>
<?php
// Import from config:
$auction = $config['shop_auction'];
$loadOutfits = ($config['show_outfits']['highscores']) ? true : false;
$this_account_id = (int)$session_user_id;
$is_admin = is_admin($user_data);
// If character auction is enabled in config.php
if ($auction['characterAuction']) {
if ($config['ServerEngine'] != 'TFS_10') {
echo "<p>Character shop auction system is currently only available for ServerEngine TFS_10.</p>";
include 'layout/overall/footer.php';
die();
}
if ((int)$auction['storage_account_id'] === (int)$this_account_id) {
echo "<p>The storage account cannot use the character auction.</p>";
include 'layout/overall/footer.php';
die();
}
$step = $auction['step'];
$step_duration = $auction['step_duration'];
$actions = array(
'list', // list all available players in auction
'view', // view a specific player
'create', // select which character to add and initial price
'add', // add character to list
'bid', // Bid or buy a specific player
'refund', // Refund a player you added back to your account
'claim' // Claim a character you won through purchase or bid
);
// Default action is list, but $_GET or $_POST will override it.
$action = 'list';
// Load selected string from actions array based on input, strict whitelist validation
if (isset( $_GET['action']) && in_array( $_GET['action'], $actions)) {
$action = $actions[array_search( $_GET['action'], $actions, true)];
}
if (isset($_POST['action']) && in_array($_POST['action'], $actions)) {
$action = $actions[array_search($_POST['action'], $actions, true)];
}
// Passive check to see if bid period has expired and someone won a deal
$time = time();
$expired_auctions = mysql_select_multi("
SELECT
`id`,
`original_account_id`,
(`bid`+`deposit`) as `points`
FROM `znote_auction_player`
WHERE `sold` = 0
AND `time_end` < {$time}
AND `bidder_account_id` > 0
");
//data_dump($expired_auctions, $this_account_id, "expired_auctions");
if ($expired_auctions !== false) {
$soldIds = array();
foreach ($expired_auctions as $a) {
$soldIds[] = $a['id'];
}
if (!empty($soldIds)) {
mysql_update("
UPDATE `znote_auction_player`
SET `sold` = 1
WHERE `id` IN(".implode(',', $soldIds).")
LIMIT ".COUNT($soldIds).";
");
// Transfer points to seller account
foreach ($expired_auctions as $a) {
mysql_update("
UPDATE `znote_accounts`
SET `points` = (`points`+{$a['points']})
WHERE `account_id` = {$a['original_account_id']};
");
}
}
}
// end passive check
// If we bid or buy a character
// silently continues to list if buy, back to view if bid
if ($action === 'bid') {
//data_dump($_POST, false, "Bid or buying:");
$zaid = (isset($_POST['zaid']) && (int)$_POST['zaid'] > 0) ? (int)$_POST['zaid'] : false;
$price = (isset($_POST['price']) && (int)$_POST['price'] > 0) ? (int)$_POST['price'] : false;
$action = 'list';
if ($zaid !== false && $price !== false) {
// The account of the buyer, if he can afford what he is trying to pay
$account = mysql_select_single("
SELECT
`a`.`id`,
`za`.`points`
FROM `accounts` a
INNER JOIN `znote_accounts` za
ON `a`.`id` = `za`.`account_id`
WHERE `a`.`id`= {$this_account_id}
AND `za`.`points` >= {$price}
LIMIT 1;
");
//data_dump($account, false, "Buyer account:");
// The character to buy, presuming it isn't sold, buyer isn't the owner, buyer can afford it
if ($account !== false) {
$character = mysql_select_single("
SELECT
`za`.`id` AS `zaid`,
`za`.`player_id`,
`za`.`original_account_id`,
`za`.`bidder_account_id`,
`za`.`time_begin`,
`za`.`time_end`,
`za`.`price`,
`za`.`bid`,
`za`.`deposit`,
`za`.`sold`
FROM `znote_auction_player` za
WHERE `za`.`id` = {$zaid}
AND `za`.`sold` = 0
AND `za`.`original_account_id` != {$this_account_id}
AND `za`.`price` <= {$price}
AND `za`.`bid`+{$step} <= {$price}
LIMIT 1
");
//data_dump($character, false, "Character to buy:");
if ($character !== false) {
// If auction already have a previous bidder, refund him his points
if ($character['bid'] > 0 && $character['bidder_account_id'] > 0) {
mysql_update("
UPDATE `znote_accounts`
SET `points` = `points`+{$character['bid']}
WHERE `account_id` = {$character['bidder_account_id']}
LIMIT 1;
");
// If previous bidder is not you, increase bidding period by 1 hour
// (Extending bid war to give bidding competitor a chance to retaliate)
if ((int)$character['bidder_account_id'] !== (int)$account['id']) {
mysql_update("
UPDATE `znote_auction_player`
SET `time_end` = `time_end`+{$step_duration}
WHERE `id` = {$character['zaid']}
LIMIT 1;
");
}
}
// Remove points from buyer
mysql_update("
UPDATE `znote_accounts`
SET `points` = `points`-{$price}
WHERE `account_id` = {$account['id']}
LIMIT 1;
");
// Update auction, and set new bidder data
$time = time();
mysql_update("
UPDATE `znote_auction_player`
SET
`bidder_account_id` = {$account['id']},
`bid` = {$price},
`sold` = CASE WHEN {$time} >= `time_end` THEN 1 ELSE 0 END
WHERE `id` = {$character['zaid']}
LIMIT 1;
");
// If character is sold, give points to seller
if (time() >= $character['time_end']) {
mysql_update("
UPDATE `znote_accounts`
SET `points` = (`points`+{$character['deposit']}+{$price})
WHERE `account_id` = {$character['original_account_id']}
LIMIT 1;
");
} else {
// If character is not sold, this is a bidding war, we want to send user back to view.
$action = 'view';
}
// Note: Transferring character to the new account etc happens later in $action = 'claim'
}
}
}
}
// See a specific character in auction,
// silently fallback to list if he doesn't exist or is already sold
if ($action === 'view') { // View a character in the auction
if (!isset($zaid)) {
$zaid = (isset($_GET['zaid']) && (int)$_GET['zaid'] > 0) ? (int)$_GET['zaid'] : false;
}
if ($zaid !== false) {
// Retrieve basic character information
$character = mysql_select_single("
SELECT
`za`.`id` AS `zaid`,
`za`.`player_id`,
`za`.`original_account_id`,
`za`.`bidder_account_id`,
`za`.`time_begin`,
`za`.`time_end`,
CASE WHEN `za`.`price` > `za`.`bid`
THEN `za`.`price`
ELSE `za`.`bid`+{$step}
END AS `price`,
CASE WHEN `za`.`original_account_id` = {$this_account_id}
THEN 1
ELSE 0
END AS `own`,
CASE WHEN `za`.`original_account_id` = {$this_account_id}
THEN `p`.`name`
ELSE ''
END AS `name`,
CASE WHEN `za`.`original_account_id` = {$this_account_id}
THEN `za`.`bid`
ELSE 0
END AS `bid`,
CASE WHEN `za`.`original_account_id` = {$this_account_id}
THEN `za`.`deposit`
ELSE 0
END AS `deposit`,
`p`.`vocation`,
`p`.`level`,
`p`.`balance`,
`p`.`lookbody` AS `body`,
`p`.`lookfeet` AS `feet`,
`p`.`lookhead` AS `head`,
`p`.`looklegs` AS `legs`,
`p`.`looktype` AS `type`,
`p`.`lookaddons` AS `addons`,
`p`.`maglevel` AS `magic`,
`p`.`skill_fist` AS `fist`,
`p`.`skill_club` AS `club`,
`p`.`skill_sword` AS `sword`,
`p`.`skill_axe` AS `axe`,
`p`.`skill_dist` AS `dist`,
`p`.`skill_shielding` AS `shielding`,
`p`.`skill_fishing` AS `fishing`
FROM `znote_auction_player` za
INNER JOIN `players` p
ON `za`.`player_id` = `p`.`id`
WHERE `za`.`id` = {$zaid}
AND `za`.`sold` = 0
LIMIT 1;
");
//data_dump($character, false, "Character info");
if (is_array($character) && !empty($character)) {
// If the end of the bid is in the future, the bid is currently ongoing
$bidding_period = ((int)$character['time_end']+1 > time()) ? true : false;
$player_items = mysql_select_multi("
SELECT `itemtype`, SUM(`count`) AS `count`
FROM `player_items`
WHERE `player_id` = {$character['player_id']}
GROUP BY `itemtype`
ORDER BY MIN(`pid`) ASC
");
$depot_items = mysql_select_multi("
SELECT `itemtype`, SUM(`count`) AS `count`
FROM `player_depotitems`
WHERE `player_id` = {$character['player_id']}
GROUP BY `itemtype`
ORDER BY MIN(`pid`) ASC
");
$account = mysql_select_single("
SELECT `points`
FROM `znote_accounts`
WHERE `account_id` = {$this_account_id}
AND `points` >= {$character['price']}
LIMIT 1;
");
?>
<p>Detailed character information. <a href="/auctionChar.php?action=list">Go back to list.</a></p>
<!-- Basic info -->
<table class="auction_char">
<tr class="yellow">
<td>Level</td>
<td>Vocation</td>
<?php if ($loadOutfits): ?>
<td>Image</td>
<?php endif; ?>
<td>Bank</td>
<td>Price</td>
</tr>
<tr>
<td><?php echo $character['level']; ?></td>
<td><?php echo vocation_id_to_name($character['vocation']); ?></td>
<?php if ($loadOutfits): ?>
<td class="outfitColumn">
<img src="<?php echo $config['show_outfits']['imageServer']; ?>?id=<?php echo $character['type']; ?>&addons=<?php echo $character['addons']; ?>&head=<?php echo $character['head']; ?>&body=<?php echo $character['body']; ?>&legs=<?php echo $character['legs']; ?>&feet=<?php echo $character['feet']; ?>" alt="img">
</td>
<?php endif; ?>
<td><?php echo $character['balance']; ?></td>
<td><?php echo $character['price']; ?> points</td>
</tr>
<?php if ($bidding_period): ?>
<tr>
<td colspan="<?php echo ($loadOutfits) ? 5 : 4; ?>">
<p><strong>Remaining bid period:</strong> <?php echo toDuration((int)$character['time_end']-time()); ?>.</p>
</td>
</tr>
<?php endif; ?>
</table>
<!-- Bid on character -->
<?php
if ($character['own'] == 0) {
if (is_array($account) && !empty($account)): ?>
<p>You have <strong><?php echo $account['points']; ?></strong> shop points remaining.</p>
<?php if ((int)$character['bidder_account_id'] === $this_account_id): ?>
<p><strong>So far so good!</strong>
<br>You currently have the highest bid at: <?php echo (int)$character['price']-$step; ?>
</p>
<p>If nobody bids higher than you, this character will be yours in:
<br><?php echo toDuration((int)$character['time_end']-time()); ?>.
</p>
<?php endif; ?>
<form action="/auctionChar.php" method="POST">
<input type="hidden" name="action" value="bid">
<input type="hidden" name="zaid" value="<?php echo $character['zaid']; ?>">
<input type="number" name="price" min="<?php echo $character['price']; ?>" max="<?php echo $account['points']; ?>" step="5" value="<?php echo $character['price']; ?>" <?php if (!$bidding_period) echo 'disabled'; ?>>
<?php if (!$bidding_period): /* Because above input is disabled */ ?>
<input type="hidden" name="price" value="<?php echo $character['price']; ?>">
<?php endif; ?>
<input type="submit" value="<?php echo ($bidding_period) ? 'Bid' : 'Buy'; ?>">
</form>
<?php else: ?>
<?php if ((int)$character['bidder_account_id'] === $this_account_id): ?>
<p><strong>So far so good!</strong>
<br>You currently have the highest bid at: <?php echo (int)$character['price']-$step; ?>
</p>
<p>If nobody bids higher than you, this character will be yours in:
<br><?php echo toDuration((int)$character['time_end']-time()); ?>.
</p>
<?php else: ?>
<p>You cannot afford to buy this character.</p>
<?php endif; ?>
<?php endif;
} else {
?>
<p><strong>You are the seller of this character.</strong>
<br><strong>Name:</strong> <a href="/characterprofile.php?name=<?php echo $character['name']; ?>"><?php echo $character['name']; ?></a>
<br><strong>Price:</strong> <?php echo $character['price']; ?>
<br><strong>Bid:</strong> <?php echo $character['bid']; ?>
<br><strong>Deposit:</strong> <?php echo $character['deposit']; ?>
<?php if (!$bidding_period): ?>
<p>The bidding period has ended, you can wait until someone decides to instantly buy it, or you can reclaim your character to your account.</p>
<form action="/auctionChar.php" method="POST">
<input type="hidden" name="action" value="refund">
<input type="hidden" name="zaid" value="<?php echo $character['zaid']; ?>">
<input type="submit" value="Reclaim character back to your account">
</form>
<?php else: ?>
<p>The bidding period will last for <?php echo toDuration($character['time_end']-time()); ?>. After this period, you can reclaim your character if nobody has bid on it.</p>
<?php endif; ?>
</p>
<?php
}
?>
<!-- SKILLS -->
<table class="auction_skills">
<tr class="yellow"><td colspan="4">Character skills:</td></tr>
<tr><td>magic</td><td><?php echo $character['magic']; ?></td></tr>
<tr><td>fist</td><td><?php echo $character['fist']; ?></td></tr>
<tr><td>club</td><td><?php echo $character['club']; ?></td></tr>
<tr><td>sword</td><td><?php echo $character['sword']; ?></td></tr>
<tr><td>axe</td><td><?php echo $character['axe']; ?></td></tr>
<tr><td>dist</td><td><?php echo $character['dist']; ?></td></tr>
<tr><td>shielding</td><td><?php echo $character['shielding']; ?></td></tr>
<tr><td>fishing</td><td><?php echo $character['fishing']; ?></td></tr>
</table>
<?php
$server = $config['shop']['imageServer'];
$imageType = $config['shop']['imageType'];
$items = getItemList();
?>
<!-- Player items -->
<?php if (is_array($player_items) && !empty($player_items)): ?>
<table>
<tr class="yellow">
<td colspan="3">Player items:</td>
</tr>
<tr class="yellow">
<td>Image</td>
<td>Item</td>
<td>Count</td>
</tr>
<?php foreach($player_items as $item): ?>
<tr>
<td><img src="<?php echo "http://".$server."/".$item['itemtype'].".".$imageType; ?>" alt="Item Image"></td>
<td><a href="/market.php?compare=<?php echo $item['itemtype']; ?>" target="_BLANK"><?php echo (isset($items[$item['itemtype']])) ? $items[$item['itemtype']] : $item['itemtype']; ?></a></td>
<td><?php echo $item['count']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<!-- Depot items -->
<?php if (is_array($depot_items) && !empty($depot_items)): ?>
<table>
<tr class="yellow">
<td colspan="3">Depot items:</td>
</tr>
<tr class="yellow">
<td>Image</td>
<td>Item</td>
<td>Count</td>
</tr>
<?php foreach($depot_items as $item): ?>
<tr>
<td><img src="<?php echo "http://".$server."/".$item['itemtype'].".".$imageType; ?>" alt="Item Image"></td>
<td><a href="/market.php?compare=<?php echo $item['itemtype']; ?>" target="_BLANK"><?php echo (isset($items[$item['itemtype']])) ? $items[$item['itemtype']] : $item['itemtype']; ?></a></td>
<td><?php echo $item['count']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif;
} else {
$action = 'list';
}
}
}
// If we are adding a character to the list
// silently continues to list
if ($action === 'add') {
$pid = (isset($_POST['pid']) && (int)$_POST['pid'] > 0) ? (int)$_POST['pid'] : false;
$cost = (isset($_POST['cost']) && (int)$_POST['cost'] > 0) ? (int)$_POST['cost'] : false;
$deposit = (int)$cost * ($auction['deposit'] / 100);
$password = SHA1($_POST['password']);
// Verify values
$status = false;
$account = false;
if ($pid > 0 && $cost >= $auction['lowestPrice']) {
$account = mysql_select_single("
SELECT `a`.`id`, `a`.`password`, `za`.`points`
FROM `accounts` a
INNER JOIN `znote_accounts` za
ON `a`.`id` = `za`.`account_id`
WHERE `a`.`id`= {$this_account_id}
AND `a`.`password`='{$password}'
AND `za`.`points` >= {$deposit}
LIMIT 1
;");
if (isset($account['password']) && $account['password'] === $password) {
// Check if player exist, is offline and not already in auction
// And is not a tutor or a GM+.
$player = mysql_select_single("
SELECT `p`.`id`, `p`.`name`,
CASE
WHEN `po`.`player_id` IS NULL
THEN 0
ELSE 1
END AS `online`,
CASE
WHEN `za`.`player_id` IS NULL
THEN 0
ELSE 1
END AS `alreadyInAuction`
FROM `players` p
LEFT JOIN `players_online` po
ON `p`.`id` = `po`.`player_id`
LEFT JOIN `znote_auction_player` za
ON `p`.`id` = `za`.`player_id`
AND `p`.`account_id` = `za`.`original_account_id`
AND `za`.`claimed` = 0
WHERE `p`.`id` = {$pid}
AND `p`.`account_id` = {$this_account_id}
AND `p`.`group_id` = 1
LIMIT 1
;");
// Verify storage account ID exist
$storage_account = mysql_select_single("
SELECT `id`
FROM `accounts`
WHERE `id`={$auction['storage_account_id']}
LIMIT 1;
");
if ($storage_account === false) {
data_dump($auction, false, "Configured storage_account_id in config.php does not exist!");
} else {
if (isset($player['online']) && $player['online'] == 0) {
if (isset($player['alreadyInAuction']) && $player['alreadyInAuction'] == 0) {
$status = true;
}
}
}
}
}
if ($status) {
$time_begin = time();
$time_end = $time_begin + ($auction['biddingDuration']);
// Insert row to znote_auction_player
mysql_insert("
INSERT INTO `znote_auction_player` (
`player_id`,
`original_account_id`,
`bidder_account_id`,
`time_begin`,
`time_end`,
`price`,
`bid`,
`deposit`,
`sold`,
`claimed`
) VALUES (
{$pid},
{$this_account_id},
0,
{$time_begin},
{$time_end},
{$cost},
0,
{$deposit},
0,
0
);
");
// Move player to storage account
mysql_update("
UPDATE `players`
SET `account_id` = {$auction['storage_account_id']}
WHERE `id` = {$pid}
LIMIT 1;
");
// Hide character from public character list (in pidprofile.php)
mysql_update("
UPDATE `znote_players`
SET `hide_char` = 1
WHERE `player_id` = {$pid}
LIMIT 1;
");
// Remove deposit from account
$afterDeposit = $account['points'] - $deposit;
mysql_update("
UPDATE `znote_accounts`
SET `points` = {$afterDeposit}
WHERE `account_id` = {$account['id']}
LIMIT 1;
");
}
$action = 'list';
}
// If we are refunding a player back to its original owner
// silently continues to list
if ($action === 'refund') {
$zaid = (isset($_POST['zaid']) && (int)$_POST['zaid'] > 0) ? (int)$_POST['zaid'] : false;
//data_dump($_POST, false, "POST");
if ($zaid !== false) {
$time = time();
// If original account is the one trying to get it back,
// and bidding period is over,
// and its not labeled as sold
// and nobody has bid on it
$character = mysql_select_single("
SELECT `player_id`
FROM `znote_auction_player`
WHERE `id`= {$zaid}
AND `original_account_id` = {$this_account_id}
AND `time_end` <= {$time}
AND `bidder_account_id` = 0
AND `bid` = 0
AND `sold` = 0
LIMIT 1
");
//data_dump($character, false, "Character");
if ($character !== false) {
// Move character to buyer account and give it a new name
mysql_update("
UPDATE `players`
SET `account_id` = {$this_account_id}
WHERE `id` = {$character['player_id']}
LIMIT 1;
");
// Set label to sold
mysql_update("
UPDATE `znote_auction_player`
SET `sold` = 1
WHERE `id`= {$zaid}
LIMIT 1;
");
// Show character in public character list (in characterprofile.php)
mysql_update("
UPDATE `znote_players`
SET `hide_char` = 0
WHERE `player_id` = {$character['player_id']}
LIMIT 1;
");
}
}
$action = 'list';
}
// If we are claiming a character
// If validation fails then explain why, but then head over to list regardless of status
if ($action === 'claim') {
$zaid = (isset($_POST['zaid']) && (int)$_POST['zaid'] > 0) ? (int)$_POST['zaid'] : false;
$name = (isset($_POST['name']) && !empty($_POST['name'])) ? getValue($_POST['name']) : false;
$errors = array();
//data_dump($_POST, $name, "Post data:");
if ($zaid === false) {
$errors[] = 'We are unable to find this auction order.';
}
if ((int)$auction['storage_account_id'] === $this_account_id) {
$errors[] = 'Silly you! You cannot claim characters with the storage account configured in <br>$config[\'shop_auction\'][\'storage_account_id\']<br>because you already have those characters in your account! :P';
if ($is_admin) {
$errors[] = "ADMIN: The storage account in config.php should not be the same as the admin account.";
}
}
if ($name === false) {
$errors[] = 'Please give the character a name.';
} else {
// begin name validation
$name = validate_name($name);
if (user_character_exist($name) !== false) {
$errors[] = 'Sorry, that character name already exist.';
}
if (!preg_match("/^[a-zA-Z_ ]+$/", $name)) {
$errors[] = 'Your name may only contain a-z, A-Z and spaces.';
}
if (strlen($name) < $config['minL'] || strlen($name) > $config['maxL']) {
$errors[] = 'Your character name must be between ' . $config['minL'] . ' - ' . $config['maxL'] . ' characters long.';
}
// name restriction
$resname = explode(" ", $name);
foreach($resname as $res) {
if(in_array(strtolower($res), $config['invalidNameTags'])) {
$errors[] = 'Your username contains a restricted word.';
}
else if(strlen($res) == 1) {
$errors[] = 'Too short words in your name.';
}
}
$name = format_character_name($name);
// end name validation
if (empty($errors)) {
// Make sure you have access to claim this zaid character.
// And that you haven't already claimed it.
// And that the character isn't online...
$character = mysql_select_single("
SELECT
`za`.`id` AS `zaid`,
`za`.`player_id`,
`p`.`account_id`
FROM `znote_auction_player` za
INNER JOIN `players` p
ON `za`.`player_id` = `p`.`id`
LEFT JOIN `players_online` po
ON `p`.`id` = `po`.`player_id`
WHERE `za`.`id` = {$zaid}
AND `za`.`sold` = 1
AND `p`.`account_id` != {$this_account_id}
AND `za`.`bidder_account_id` = {$this_account_id}
AND `po`.`player_id` IS NULL
");
//data_dump($character, false, "Character");
if ($character !== false) {
// Set character to claimed
mysql_update("
UPDATE `znote_auction_player`
SET `claimed`='1'
WHERE `id` = {$character['zaid']}
");
// Move character to buyer account and give it a new name
mysql_update("
UPDATE `players`
SET `name` = '{$name}',
`account_id` = {$this_account_id}
WHERE `id` = {$character['player_id']}
LIMIT 1;
");
// Show character in public character list (in characterprofile.php)
mysql_update("
UPDATE `znote_players`
SET `hide_char` = 0
WHERE `player_id` = {$character['player_id']}
LIMIT 1;
");
// Remove character from other players VIP lists
mysql_delete("
DELETE FROM `account_viplist`
WHERE `player_id` = {$character['player_id']}
");
// Remove the character deathlist
mysql_delete("
DELETE FROM `player_deaths`
WHERE `player_id` = {$character['player_id']}
");
} else {
$errors[] = "You either don't have access to claim this character, or you have already claimed it, or this character isn't sold yet, or we were unable to find this auction order.";
if ($is_admin) {
$errors[] = "ADMIN: ... Or character is online.";
}
}
}
}
if (!empty($errors)) {
//data_dump($errors, false, "Errors:");
?>
<table class="auction_error">
<tr class="yellow">
<td>#</td>
<td>Issues occurred while claiming your name</td>
</tr>
<?php foreach($errors as $i => $error): ?>
<tr>
<td><?php echo $i+1; ?></td>
<td><?php echo $error; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php
}
$action = 'list';
}
// List characters currently in the auction
if ($action === 'list') {
// If this account have successfully bought or won an auction
// Intercept the list action and let the user do claim actions
$pending = mysql_select_multi("
SELECT
`za`.`id` AS `zaid`,
CASE WHEN `za`.`price` > `za`.`bid`
THEN `za`.`price`
ELSE `za`.`bid`
END AS `price`,
`za`.`time_begin`,
`za`.`time_end`,
`p`.`vocation`,
`p`.`level`,
`p`.`lookbody` AS `body`,
`p`.`lookfeet` AS `feet`,
`p`.`lookhead` AS `head`,
`p`.`looklegs` AS `legs`,
`p`.`looktype` AS `type`,
`p`.`lookaddons` AS `addons`
FROM `znote_auction_player` za
INNER JOIN `players` p
ON `za`.`player_id` = `p`.`id`
WHERE `p`.`account_id` = {$auction['storage_account_id']}
AND `za`.`claimed` = 0
AND `za`.`sold` = 1
AND `za`.`bidder_account_id` = {$this_account_id}
ORDER BY `p`.`level` desc
");
//data_dump($pending, false, "Pending characters:");
if ($pending !== false) {
?>
<h2>Congratulations!</h2>
<p>You have <?php echo (COUNT($pending) > 1) ? 'characters' : 'a character'; ?> ready to claim!</p>
<?php foreach($pending as $character): ?>
<table class="auction_char">
<tr class="yellow">
<td>Level</td>
<td>Vocation</td>
<td>Details</td>
<td>Price</td>
</tr>
<tr>
<td><?php echo $character['level']; ?></td>
<td><?php echo vocation_id_to_name($character['vocation']); ?></td>
<td><a href="/auctionChar.php?action=view&zaid=<?php echo $character['zaid']; ?>">VIEW</a></td>
<td><?php echo $character['price']; ?></td>
</tr>
<tr>
<?php if ($loadOutfits): ?>
<td class="outfitColumn">
<img src="<?php echo $config['show_outfits']['imageServer']; ?>?id=<?php echo $character['type']; ?>&addons=<?php echo $character['addons']; ?>&head=<?php echo $character['head']; ?>&body=<?php echo $character['body']; ?>&legs=<?php echo $character['legs']; ?>&feet=<?php echo $character['feet']; ?>" alt="img">
</td>
<?php endif; ?>
<td colspan="3">
<p>Hello master, what should my new name be?</p>
<form action="/auctionChar.php" method="POST">
<input type="hidden" name="action" value="claim">
<input type="hidden" name="zaid" value="<?php echo $character['zaid']; ?>">
<input type="text" name="name">
<input type="submit" value="Claim character">
</form>
</td>
</tr>
</table>
<?php endforeach; ?>
<h2>Ongoing auctions:</h2>
<?php
}
// Show the list
$characters = mysql_select_multi("
SELECT
`za`.`id` AS `zaid`,
CASE WHEN `za`.`price` > `za`.`bid`
THEN `za`.`price`
ELSE `za`.`bid`+{$step}
END AS `price`,
`za`.`time_begin`,
`za`.`time_end`,
`p`.`vocation`,
`p`.`level`,
`p`.`lookbody` AS `body`,
`p`.`lookfeet` AS `feet`,
`p`.`lookhead` AS `head`,
`p`.`looklegs` AS `legs`,
`p`.`looktype` AS `type`,
`p`.`lookaddons` AS `addons`
FROM `znote_auction_player` za
INNER JOIN `players` p
ON `za`.`player_id` = `p`.`id`
WHERE `p`.`account_id` = {$auction['storage_account_id']}
AND `za`.`sold` = 0
ORDER BY `p`.`level` desc;
");
//data_dump($characters, false, "List characters");
if ($is_admin) {
?>
<p>Admin: <a href="/admin_auction.php">Character auction history</a></p>
<?php
}
if (is_array($characters) && !empty($characters)):
?>
<table class="auction_char">
<tr class="yellow">
<td>Level</td>
<td>Vocation</td>
<?php if ($loadOutfits): ?>
<td>Image</td>
<?php endif; ?>
<td>Details</td>
<td>Price</td>
<td>Added</td>
<td>Type</td>
</tr>
<?php foreach($characters as $character): ?>
<tr>
<td><?php echo $character['level']; ?></td>
<td><?php echo vocation_id_to_name($character['vocation']); ?></td>
<?php if ($loadOutfits): ?>
<td class="outfitColumn">
<img src="<?php echo $config['show_outfits']['imageServer']; ?>?id=<?php echo $character['type']; ?>&addons=<?php echo $character['addons']; ?>&head=<?php echo $character['head']; ?>&body=<?php echo $character['body']; ?>&legs=<?php echo $character['legs']; ?>&feet=<?php echo $character['feet']; ?>" alt="img">
</td>
<?php endif; ?>
<td><a href="/auctionChar.php?action=view&zaid=<?php echo $character['zaid']; ?>">VIEW</a></td>
<td><?php echo $character['price']; ?></td>
<td><?php
$ended = (time() > $character['time_end']) ? true : false;
echo getClock($character['time_begin'], true);
?>
</td>
<td><?php echo ($ended) ? 'Instant' : 'Bidding<br>('.toDuration(($character['time_end'] - time())).')'; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php
endif;
?>
<p><a href="/auctionChar.php?action=create">Add a character to the auction</a>.</p>
<?php
} elseif ($action === 'create') { // Add player to auction view
$minToCreate = (int)ceil(($auction['lowestPrice'] / 100) * $auction['deposit']);
$own_characters = mysql_select_multi("
SELECT
`p`.`id`,
`p`.`name`,
`p`.`level`,
`p`.`vocation`,
`a`.`points`
FROM `players` p
INNER JOIN `znote_accounts` a
ON `p`.`account_id` = `a`.`account_id`
LEFT JOIN `znote_auction_player` za
ON `p`.`id` = `za`.`player_id`
AND `p`.`account_id` = `za`.`original_account_id`
AND `za`.`claimed` = 0
LEFT JOIN `players_online` po
ON `p`.`id` = `po`.`player_id`
WHERE `p`.`account_id`={$this_account_id}
AND `za`.`player_id` IS NULL
AND `po`.`player_id` IS NULL
AND `p`.`level` >= {$auction['lowestLevel']}
AND `a`.`points` >= $minToCreate
;");
//data_dump($own_characters, false, "own_chars");
if (is_array($own_characters) && !empty($own_characters)) {
$max = ($own_characters[0]['points'] / $auction['deposit']) * 100;
?>
<p><a href="/auctionChar.php?action=list">Go back to list.</a></p>
<form action="/auctionChar.php" method="POST">
<input type="hidden" name="action" value="add">
<p>Character: (Must be offline)</p>
<select name="pid">
<?php if(is_array($own_characters) && !empty($own_characters))
foreach($own_characters as $char): ?>
<option value="<?php echo $char['id']; ?>">
<?php echo "Level: ", $char['level'], " ", vocation_id_to_name($char['vocation']), ": ", $char['name']; ?>
</option>
<?php endforeach; ?>
</select>
<p><strong>Shop points:</strong>
<br>Your current points: <?php echo $own_characters[0]['points']; ?>
<br>Minimum: <?php echo $auction['lowestPrice']; ?>
<br>deposit: <?php echo $auction['deposit']; ?>%
<br>Your maximum: <?php echo $max; ?>
</p>
<p><strong>Deposit information:</strong>
<br>To ensure you as the seller is a legitimate account, and to encourage fair prices you have to temporarily invest <?php echo $auction['deposit']; ?>% of the selling price as a deposit.
</p>
<p>Once the auction has completed, the deposit fee will be refunded back to your account.</p>
<p>If you wish to reclaim your character, you can do it after the bidding period if nobody has placed an offer on it. But if you do this you will not get the deposit back. It is therefore advisable that you create a good and appealing offer to our community.</p>
<p>Sell price:</p>
<input type="number" name="cost" min="<?php echo $auction['lowestPrice']; ?>" max="<?php echo $max; ?>" step="5" placeholder="<?php echo $auction['lowestPrice']; ?> - <?php echo $max; ?>">
<br>
<p>Verify with your password:</p>
<input type="password" name="password">
<br>
<input type="submit" value="Sell character">
</form>
<?php
} else {
?>
<p><a href="/auctionChar.php?action=list">Go back to list.</a></p>
<p>Your account does not follow the required rules to sell characters.
<br>1. Minimum level: <?php echo $auction['lowestLevel']; ?>
<br>2. Minimum already earned shop points: <?php echo $minToCreate; ?>
<br>3. Eligible characters must be offline.
</p>
<?php
}
}
} else echo "<p>Character shop auctioning system is disabled.</p>";
include 'layout/overall/footer.php'; ?>