forked from photogabble/blacknova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_fighters.php
206 lines (186 loc) · 10.1 KB
/
check_fighters.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
<?php
// Blacknova Traders - A web-based massively multiplayer space combat and trading game
// Copyright (C) 2001-2014 Ron Harwood and the BNT development team
//
// This program 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.
//
// 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// File: check_fighters.php
if (strpos($_SERVER['PHP_SELF'], 'check_fighters.php')) // Prevent direct access to this file
{
die('Blacknova Traders error: You cannot access this file directly.');
}
// Database driven language entries
$langvars = Bnt\Translate::load($pdo_db, $lang, array('check_fighters', 'common', 'global_includes', 'global_funcs', 'combat', 'footer', 'news', 'regional'));
$result2 = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id=?;", array($sector));
Bnt\Db::logDbErrors($db, $result2, __LINE__, __FILE__);
// Put the sector information into the array "sectorinfo"
$sectorinfo = $result2->fields;
$result3 = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? and defence_type ='F' ORDER BY quantity DESC;", array($sector));
Bnt\Db::logDbErrors($db, $result3, __LINE__, __FILE__);
// Put the defence information into the array "defences"
$i = 0;
$total_sector_fighters = 0;
$owner = true;
// Detect if this variable exists, and filter it. Returns false if anything wasn't right.
$response = null;
$response = filter_input(INPUT_POST, 'response', FILTER_SANITIZE_STRING);
if (mb_strlen(trim($response)) === 0)
{
$response = false;
}
$destination = null;
if (array_key_exists('destination', $_REQUEST) == true)
{
$destination = $_REQUEST['destination'];
}
$engage = null;
if (array_key_exists('engage', $_REQUEST) == true)
{
$engage = $_REQUEST['engage'];
}
while (!$result3->EOF)
{
$row = $result3->fields;
$defences[$i] = $row;
$total_sector_fighters += $defences[$i]['quantity'];
if ($defences[$i]['ship_id'] != $playerinfo['ship_id'])
{
$owner = false;
}
$i++;
$result3->MoveNext();
}
$num_defences = $i;
if ($num_defences > 0 && $total_sector_fighters > 0 && !$owner)
{
// Find out if the fighter owner and player are on the same team
// All sector defences must be owned by members of the same team
$fm_owner = $defences[0]['ship_id'];
$result2 = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id=?;", array($fm_owner));
Bnt\Db::logDbErrors($db, $result2, __LINE__, __FILE__);
$fighters_owner = $result2->fields;
if ($fighters_owner['team'] != $playerinfo['team'] || $playerinfo['team'] == 0)
{
switch ($response)
{
case "fight":
$resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defences = ' ' WHERE ship_id = ?;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
echo "<h1>" . $title . "</h1>\n";
include_once './sector_fighters.php';
break;
case "retreat":
$resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defences = ' ' WHERE ship_id = ?;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$stamp = date("Y-m-d H:i:s");
$resx = $db->Execute("UPDATE {$db->prefix}ships SET last_login='$stamp', turns = turns - 2, turns_used = turns_used + 2, sector=? WHERE ship_id=?;", array($playerinfo['sector'], $playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
echo "<h1>" . $title . "</h1>\n";
echo $langvars['l_chf_youretreatback'] . "<br>";
Bnt\Text::gotoMain($db, $lang, $langvars);
die();
break;
case "pay":
$resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defences = ' ' WHERE ship_id = ?;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$fighterstoll = $total_sector_fighters * $fighter_price * 0.6;
if ($playerinfo['credits'] < $fighterstoll)
{
echo $langvars['l_chf_notenoughcreditstoll'] . "<br>";
echo $langvars['l_chf_movefailed'] . "<br>";
// Undo the move
$resx = $db->Execute("UPDATE {$db->prefix}ships SET sector=? WHERE ship_id=?;", array($playerinfo['sector'], $playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$ok = 0;
}
else
{
$tollstring = number_format($fighterstoll, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']);
$langvars['l_chf_youpaidsometoll'] = str_replace("[chf_tollstring]", $tollstring, $langvars['l_chf_youpaidsometoll']);
echo $langvars['l_chf_youpaidsometoll'] . "<br>";
$resx = $db->Execute("UPDATE {$db->prefix}ships SET credits=credits - $fighterstoll WHERE ship_id = ?;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
Bnt\Toll::distribute($db, $sector, $fighterstoll, $total_sector_fighters);
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TOLL_PAID, "$tollstring|$sector");
$ok = 1;
}
break;
case "sneak":
$resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defences = ' ' WHERE ship_id = ?;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$success = Bnt\Scan::success($fighters_owner['sensors'], $playerinfo['cloak']);
if ($success < 5)
{
$success = 5;
}
if ($success > 95)
{
$success = 95;
}
$roll = Bnt\Rand::betterRand(1, 100);
if ($roll < $success)
{
// Sector defences detect incoming ship
echo "<h1>" . $title . "</h1>\n";
echo $langvars['l_chf_thefightersdetectyou'] . "<br>";
include_once './sector_fighters.php';
break;
}
else
{
// Sector defences don't detect incoming ship
$ok = 1;
}
break;
default:
$interface_string = $calledfrom . '?sector='.$sector.'&destination='.$destination.'&engage='.$engage;
$resx = $db->Execute("UPDATE {$db->prefix}ships SET cleared_defences = ? WHERE ship_id = ?;", array($interface_string, $playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$fighterstoll = $total_sector_fighters * $fighter_price * 0.6;
echo "<h1>" . $title . "</h1>\n";
echo "<form accept-charset='utf-8' action='{$calledfrom}' method='post'>";
$langvars['l_chf_therearetotalfightersindest'] = str_replace("[chf_total_sector_fighters]", $total_sector_fighters, $langvars['l_chf_therearetotalfightersindest']);
echo $langvars['l_chf_therearetotalfightersindest'] . "<br>";
if ($defences[0]['fm_setting'] == "toll")
{
$langvars['l_chf_creditsdemanded'] = str_replace("[chf_number_fighterstoll]", number_format($fighterstoll, 0, $langvars['local_number_dec_point'], $langvars['local_number_thousands_sep']), $langvars['l_chf_creditsdemanded']);
echo $langvars['l_chf_creditsdemanded'] . "<br>";
}
$langvars['l_chf_youcanretreat'] = str_replace("[retreat]", "<strong>Retreat</strong>", $langvars['l_chf_youcanretreat']);
echo $langvars['l_chf_youcan'] . " <br><input type='radio' name='response' value='retreat'>" . $langvars['l_chf_youcanretreat'] . "<br></input>";
if ($defences[0]['fm_setting'] == "toll")
{
$langvars['l_chf_inputpay'] = str_replace("[pay]", "<strong>Pay</strong>", $langvars['l_chf_inputpay']);
echo "<input type='radio' name='response' checked value='pay'>" . $langvars['l_chf_inputpay'] . "<br></input>";
}
echo "<input type='radio' name='response' checked value='fight'>";
$langvars['l_chf_inputfight'] = str_replace("[fight]", "<strong>Fight</strong>", $langvars['l_chf_inputfight']);
echo $langvars['l_chf_inputfight'] . "<br></input>";
echo "<input type=radio name=response checked value=sneak>";
$langvars['l_chf_inputcloak'] = str_replace("[cloak]", "<strong>Cloak</strong>", $langvars['l_chf_inputcloak']);
echo $langvars['l_chf_inputcloak'] . "<br></input><br>";
echo "<input type='submit' value='" . $langvars['l_chf_go'] . "'><br><br>";
echo "<input type='hidden' name='sector' value='{$sector}'>";
echo "<input type='hidden' name='engage' value='1'>";
echo "<input type='hidden' name='destination' value='{$destination}'>";
echo "</form>";
die();
break;
}
// Clean up any sectors that have used up all mines or fighters
$resx = $db->Execute("DELETE FROM {$db->prefix}sector_defence WHERE quantity <= 0 ");
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
}
}
?>