-
Notifications
You must be signed in to change notification settings - Fork 1
/
bounty.php
382 lines (354 loc) · 11.9 KB
/
bounty.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
<?php
// Blacknova Traders - A web-based massively multiplayer space combat and trading game
// Copyright (C) 2001-2012 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: bounty.php
include "config/config.php";
updatecookie ();
// New database driven language entries
load_languages($db, $lang, array('bounty', 'port', 'common', 'global_includes', 'global_funcs', 'combat', 'footer', 'news'), $langvars, $db_logging);
$title = $l_by_title;
include "header.php";
if (checklogin())
{
die ();
}
$response = null;
if (array_key_exists('response', $_POST) == true)
{
$response = $_POST['response'];
}
$res = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id=?", array($user_ship_id));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$playerinfo = $res->fields;
switch ($response) {
case "display":
?>
<div class="tablecell content both-border">
<div class="pad">
<?
bigtitle ();
$res5 = $db->Execute("SELECT * FROM {$db->prefix}ships,{$db->prefix}bounty WHERE bounty_on = ship_id AND bounty_on = ?", array($bounty_on));
db_op_result ($db, $res5, __LINE__, __FILE__, $db_logging);
$j = 0;
if ($res5)
{
while (!$res5->EOF)
{
$bounty_details[$j] = $res5->fields;
$j++;
$res5->MoveNext();
}
}
$num_details = $j;
if ($num_details < 1)
{
echo $l_by_nobounties . "<br>";
}
else
{
echo $l_by_bountyon. " " . $bounty_details[0]['character_name'];
echo '<table border=1 cellspacing=1 cellpadding=2 width="50%" align=center>';
echo "<tr bgcolor=\"$color_header\">";
echo "<td><strong>" . $l_amount . "</td>";
echo "<td><strong>" . $l_by_placedby . "</td>";
echo "<td><strong>" . $l_by_action . "</td>";
echo "</tr>";
$color = $color_line1;
for ($j = 0; $j < $num_details; $j++)
{
$someres = $db->execute("SELECT character_name FROM {$db->prefix}ships WHERE ship_id = ?", array($bounty_details[$j]['placed_by']));
db_op_result ($db, $someres, __LINE__, __FILE__, $db_logging);
$details = $someres->fields;
echo "<tr bgcolor=\"$color\">";
echo "<td>" . $bounty_details[$j]['amount'] . "</td>";
if ($bounty_details[$j]['placed_by'] == 0)
{
echo "<td>$l_by_thefeds</td>";
}
else
{
echo "<td>" . $details['character_name'] . "</td>";
}
if ($bounty_details[$j]['placed_by'] == $playerinfo['ship_id'])
{
echo "<td><a href=bounty.php?bid=" . $bounty_details[$j]['bounty_id'] . "&response=cancel>$l_by_cancel</A></td>";
}
else
{
echo "<td>n/a</td>";
}
echo "</tr>";
if ($color == $color_line1)
{
$color = $color_line2;
}
else
{
$color = $color_line1;
}
}
echo "</table>";
}
break;
case "cancel":
$bid = (int)$_GET['bid'];
?>
<div class="tablecell content both-border">
<div class="pad">
<?
bigtitle ();
if ($playerinfo['turns'] < 1)
{
echo "$l_by_noturn<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
$res = $db->Execute("SELECT * FROM {$db->prefix}bounty WHERE bounty_id = ?", array($bid));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
if (!res || $res->RowCount() ==0)
{
echo "$l_by_nobounty<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
$bty = $res->fields;
if ($bty['placed_by'] != $playerinfo['ship_id'])
{
echo "$l_by_notyours<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
$del = $db->Execute("DELETE FROM {$db->prefix}bounty WHERE bounty_id = ?", array($bid));
db_op_result ($db, $del, __LINE__, __FILE__, $db_logging);
$stamp = date("Y-m-d H-i-s");
$refund = $bty['amount'];
$resx = $db->Execute("UPDATE {$db->prefix}ships SET last_login=?,turns=turns-1, turns_used=turns_used+1, credits=credits+? WHERE ship_id=?", array($stamp, $refund, $playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
echo "$l_by_canceled<br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
die ();
break;
case "place":
?>
<div class="tablecell content both-border">
<div class="pad">
<?
bigtitle ();
$bounty_on = stripnum ($bounty_on);
$ex = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id = ?", array($bounty_on));
db_op_result ($db, $ex, __LINE__, __FILE__, $db_logging);
if (!$ex)
{
echo "$l_by_notexists<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
$bty = $ex->fields;
if ($bty['ship_destroyed'] == "Y")
{
echo "$l_by_destroyed<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
if ($playerinfo['turns']<1 )
{
echo "$l_by_noturn<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
$amount = stripnum ($amount);
if ($amount < 0)
{
echo "$l_by_zeroamount<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
if ($bounty_on == $playerinfo['ship_id'])
{
echo "$l_by_yourself<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
if ($amount > $playerinfo['credits'])
{
echo "$l_by_notenough<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
if ($bounty_maxvalue != 0)
{
$percent = $bounty_maxvalue * 100;
$score = gen_score ($playerinfo['ship_id']);
$maxtrans = $score * $score * $bounty_maxvalue;
$previous_bounty = 0;
$pb = $db->Execute("SELECT SUM(amount) AS totalbounty FROM {$db->prefix}ships WHERE bounty_on = ? AND placed_by = ?;", array($bounty_on, $playerinfo['ship_id']));
db_op_result ($db, $pb, __LINE__, __FILE__, $db_logging);
if ($pb)
{
$prev = $pb->fields;
$previous_bounty = $prev['totalbounty'];
}
if ($amount + $previous_bounty > $maxtrans)
{
$l_by_toomuch = str_replace("[percent]", $percent, $l_by_toomuch);
echo "$l_by_toomuch<br><br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
die ();
}
}
$insert = $db->Execute("INSERT INTO {$db->prefix}bounty (bounty_on,placed_by,amount) values (?,?,?);", array($bounty_on, $playerinfo['ship_id'] ,$amount));
db_op_result ($db, $insert, __LINE__, __FILE__, $db_logging);
$stamp = date("Y-m-d H-i-s");
$resx = $db->Execute("UPDATE {$db->prefix}ships SET last_login=?, turns=turns-1, turns_used=turns_used+1, credits=credits-? WHERE ship_id=?", array($stamp, $amount, $playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
echo "$l_by_placed<br>";
TEXT_GOTOMAIN ();
?>
</div></div>
<?
die ();
break;
default:
?>
<div class="tablecell content both-border">
<div class="pad">
<?
bigtitle ();
$res = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_destroyed = 'N' AND ship_id <> ? ORDER BY character_name ASC", array($playerinfo['ship_id']));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
echo "<form action=bounty.php method=post>";
echo "<table>";
echo "<tr><td>$l_by_bountyon</td><td><select NAME=bounty_on>";
while (!$res->EOF)
{
if (isset($bounty_on) && $bounty_on == $res->fields['ship_id'])
{
$selected = "selected";
}
else
{
$selected = "";
}
$charname = $res->fields['character_name'];
$ship_id = $res->fields['ship_id'];
echo "<OPTION VALUE=$ship_id $selected>$charname</OPTION>";
$res->MoveNext();
}
echo "</select></td></tr>";
echo "<tr><td>$l_by_amount:</td><td><input type=text name=amount size=20 maxlength=20></td></tr>";
echo "<tr><td></td><td><input type=submit value=$l_by_place><input type=reset value=Clear></td>";
echo "</table>";
echo "<input type=hidden name=response value=place>";
echo "</form>";
$result3 = $db->Execute ("SELECT bounty_on, SUM(amount) as total_bounty FROM {$db->prefix}bounty GROUP BY bounty_on");
db_op_result ($db, $result3, __LINE__, __FILE__, $db_logging);
$i = 0;
if ($result3)
{
while (!$result3->EOF)
{
$bounties[$i] = $result3->fields;
$i++;
$result3->MoveNext();
}
}
$num_bounties = $i;
if ($num_bounties < 1)
{
echo "$l_by_nobounties<br>";
}
else
{
echo $l_by_moredetails . "<br><br>";
echo "<table width=\"100%\" border=0 cellspacing=0 cellpadding=2>";
echo "<tr bgcolor=\"$color_header\">";
echo "<td><strong>$l_by_bountyon</strong></td>";
echo "<td><strong>$l_amount</td>";
echo "</tr>";
$color = $color_line1;
for ($i = 0; $i < $num_bounties; $i++)
{
$someres = $db->execute("SELECT character_name FROM {$db->prefix}ships WHERE ship_id = " . $bounties[$i]['bounty_on']);
db_op_result ($db, $someres, __LINE__, __FILE__, $db_logging);
$details = $someres->fields;
echo "<tr bgcolor=\"$color\">";
echo "<td><a href=bounty.php?bounty_on=" . $bounties[$i]['bounty_on'] . "&response=display>". $details['character_name'] ."</A></td>";
echo "<td>" . $bounties[$i]['total_bounty'] . "</td>";
echo "</tr>";
if ($color == $color_line1)
{
$color = $color_line2;
}
else
{
$color = $color_line1;
}
}
echo "</table>";
}
echo "<br><br>";
break;
}
TEXT_GOTOMAIN ();
?>
</div></div>
<?
include "footer.php";
?>