-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmonorail.php
95 lines (94 loc) · 2.5 KB
/
monorail.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
<?php
declare(strict_types=1);
/**
* MCCodes v2 by Dabomstew & ColdBlooded
*
* Repository: https://github.com/davemacaulay/mccodesv2
* License: MIT License
*/
global $db, $ir, $userid, $h;
require_once('globals.php');
# Basic config setting
$cost_of_travel = 1000;
# end
$_GET['to'] =
(isset($_GET['to']) && is_numeric($_GET['to']))
? abs(intval($_GET['to'])) : '';
if (empty($_GET['to']))
{
echo '
Welcome to the Monorail Station. It costs '
. money_formatter($cost_of_travel)
. ' for a ticket.
<br />
Where would you like to travel today?
<br />
';
$q =
$db->query(
"SELECT `cityid`, `cityname`, `citydesc`, `cityminlevel`
FROM `cities`
WHERE `cityid` != {$ir['location']}
AND `cityminlevel` <= {$ir['level']}");
echo "
<table width='75%' cellspacing='1' cellpadding='1' class='table'>
<tr style='background:gray'>
<th>Name</th>
<th>Description</th>
<th>Min Level</th>
<th> </th>
</tr>
";
while ($r = $db->fetch_row($q))
{
echo "
<tr>
<td>{$r['cityname']}</td>
<td>{$r['citydesc']}</td>
<td>{$r['cityminlevel']}</td>
<td><a href='monorail.php?to={$r['cityid']}'>Go</a></td>
</tr>
";
}
echo '</table>';
$db->free_result($q);
}
else
{
if ($ir['money'] < $cost_of_travel)
{
echo 'You don\'t have enough money.';
}
elseif ($ir['location'] == $_GET['to'])
{
echo 'You are already here.';
}
else
{
$q =
$db->query(
"SELECT `cityname`
FROM `cities`
WHERE `cityid` = {$_GET['to']}
AND `cityminlevel` <= {$ir['level']}");
if (!$db->num_rows($q))
{
echo 'Error, this city either does not exist or you cannot go there.';
}
else
{
$db->query(
"UPDATE `users`
SET `money` = `money` - $cost_of_travel,
`location` = {$_GET['to']}
WHERE `userid` = $userid");
$cityName = $db->fetch_single($q);
echo 'Congratulations, you paid '
. money_formatter($cost_of_travel) . ' and travelled to '
. $cityName . ' on the monorail!';
}
$db->free_result($q);
}
echo '<br />> <a href="index.php">Go back</a> to index.';
}
$h->endpage();