-
Notifications
You must be signed in to change notification settings - Fork 82
/
blackjack.php
403 lines (349 loc) · 23.1 KB
/
blackjack.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
<?php
require_once "include/bittorrent.php";
//require_once "include/user_functions.php";
dbconn();
loggedinorreturn();
//$lang = array_merge( load_language('global') );
$HTMLOUT='';
if ($CURUSER['class'] < UC_USER)
stderr("抱歉", "您的等级太低",false);
$mb = 100;
$percent=0.9;
$required_ratio = 1;
$now = sqlesc(date("Y-m-d H:i:s"));
$game = isset($_POST["game"]) ? htmlspecialchars(trim($_POST["game"])) : '';
$start = isset($_POST["start"]) ? htmlspecialchars(trim($_POST["start"])) : '';
if ($game)
{
function cheater_check($arg)
{
if ($arg)
{
header('Location: blackjack.php');
exit;
}
}
$cardcount = 52;
$points='';
$showcards='';
$aces='';
if ($start != 'yes')
{
$playeres = sql_query("SELECT * FROM blackjack WHERE userid = ".sqlesc($CURUSER['id']));
$playerarr = mysql_fetch_assoc($playeres);
if ($game == 'hit')
$points = $aces = 0;
$gameover = ($playerarr['gameover'] == 'yes' ? true : false);
$HTMLOUT .= cheater_check($gameover && ($game == 'hit' ^ $game == 'stop'));
$cards = $playerarr["cards"];
$usedcards = explode(" ", $cards);
$arr = array();
foreach ($usedcards as $array_list)
$arr[] = $array_list;
foreach ($arr as $card_id)
{
$used_card = sql_query("SELECT * FROM cards WHERE id=".sqlesc($card_id));
$used_cards = mysql_fetch_assoc($used_card);
$showcards .= "<img src='cards/".$used_cards["pic"]."' style=\"border: 1px\" alt='Cards' title='Cards' />";
if ($used_cards["points"] > 1)
$points += $used_cards['points'];
else
$aces++;
}
}
if ($_POST["game"] == 'hit')
{
if ($start == 'yes')
{
if ($CURUSER["seedbonus"] < $mb)
stderr("抱歉 ".$CURUSER["username"], "您现在需要".$mb."个魔力值.",false);
if ($CURUSER["downloaded"] > 0)
$ratio = number_format($CURUSER["uploaded"] / $CURUSER["downloaded"], 3);
elseif ($CURUSER["uploaded"] > 0)
$ratio = 999;
else
$ratio = 0;
if ($ratio < $required_ratio)
stderr("抱歉 ".$CURUSER["username"], "您的分享率小于 ".$required_ratio." .",false);
$res = sql_query("SELECT status, gameover FROM blackjack WHERE userid = ".sqlesc($CURUSER['id']));
$arr = mysql_fetch_assoc($res);
if ($arr['status'] == 'waiting')
stderr("抱歉", "您需要等待上一局结束",false);
elseif ($arr['status'] == 'playing')
stderr("抱歉", "您需要继续玩完上一盘.<form method='post' action='blackjack.php'><input type='hidden' name='game' value='hit' readonly='readonly' /><input type='hidden' name='continue' value='yes' readonly='readonly' /><input type='submit' value='Continue old game' /></form>",false);
$HTMLOUT .= cheater_check($arr['gameover'] == 'yes');
$cardids = array();
for ($i = 0; $i <= 1; $i++)
$cardids[] = rand(1, $cardcount);
foreach ($cardids as $cardid)
{
while (in_array($cardid, $cardids))
$cardid = rand(1, $cardcount);
$cardres = sql_query("SELECT points, pic FROM cards WHERE id='$cardid'");
$cardarr = mysql_fetch_assoc($cardres);
if ($cardarr["points"] > 1)
$points += $cardarr["points"];
else
$aces++;
$showcards .= "<img src='cards/".$cardarr['pic']."' style=\"border: 1px\" alt='Cards' title='Cards' />";
$cardids2[] = $cardid;
}
for ($i = 0; $i < $aces; $i++)
$points += ($points < 11 && $aces - $i == 1 ? 11 : 1);
sql_query("INSERT INTO blackjack (userid, points, cards, date) VALUES(".sqlesc($CURUSER['id']).", '$points', '".join(" ",$cardids2)."', ".TIMENOW.")");
if ($points < 21)
{
$HTMLOUT .="<h1>欢迎您, {$CURUSER['username']}!</h1>
<table cellspacing='0' cellpadding='3' width='600'>
<tr><td colspan='2'>
<table class='message' width='100%' cellspacing='0' cellpadding='5' bgcolor='white'>
<tr><td align='center'>".trim($showcards)."</td></tr>
<tr><td align='center'><b>Points = {$points}</b></td></tr>
<tr><td align='center'>
<form method='post' action='blackjack.php'><input type='hidden' name='game' value='hit' readonly='readonly' /><input type='submit' value='拿牌' /></form>
</td></tr>";
if ($points >= 10)
{
$HTMLOUT .="<tr><td align='center'>
<form method='post' action='blackjack.php'><input type='hidden' name='game' value='stop' readonly='readonly' /><input type='submit' value='停牌' /></form>
</td></tr>";
}
$HTMLOUT .="</table></td></tr></table>";
stdhead('21点');
print $HTMLOUT ;
sql_query("delete from messages where subject like '21点的结果%' AND unread='no'");
stdfoot();
die();
}
}
elseif (($start != 'yes' && isset($_POST['continue']) != 'yes') && !$gameover)
{
$HTMLOUT .= cheater_check(empty($playerarr));
$cardid = rand(1, $cardcount);
while (in_array($cardid, $arr))
$cardid = rand(1, $cardcount);
$cardres = sql_query("SELECT points, pic FROM cards WHERE id='$cardid'");
$cardarr = mysql_fetch_assoc($cardres);
$showcards .= "<img src='cards/".$cardarr['pic']."' style=\"border: 1px\" alt='Cards' title='Cards' />";
if ($cardarr["points"] > 1)
$points += $cardarr["points"];
else
$aces++;
for ($i = 0; $i < $aces; $i++)
$points += ($points < 11 && $aces - $i == 1 ? 11 : 1);
sql_query("UPDATE blackjack SET points='$points', cards='".$cards." ".$cardid."' WHERE userid=".sqlesc($CURUSER['id']));
}
if ($points == 21 || $points > 21)
{
$waitres = sql_query("SELECT COUNT(userid) AS c FROM blackjack WHERE status = 'waiting' AND userid != ".sqlesc($CURUSER['id']));
$waitarr = mysql_fetch_assoc($waitres);
$HTMLOUT .="<h1>游戏结束</h1>
<table cellspacing='0' cellpadding='3' width='600'>
<tr><td colspan='2'>
<table width='100%' cellspacing='0' cellpadding='5' bgcolor='white'>
<tr><td align='center'>".trim($showcards)."</td></tr>
<tr><td align='center'><b>你的点数是 ${points} 。</b></td></tr>";
}
if ($points == 21)
{
if ($waitarr['c'] > 0)
{
$r = sql_query("SELECT bj.*, u.username FROM blackjack AS bj LEFT JOIN users AS u ON u.id=bj.userid WHERE bj.status='waiting' AND bj.userid != ".sqlesc($CURUSER['id'])." ORDER BY bj.date ASC LIMIT 1");
$a = mysql_fetch_assoc($r);
if ($a["points"] != 21)
{
$winorlose = "赢局,你赢了 ".(${percent}*$mb)."个魔力值";
sql_query("UPDATE users SET seedbonus = seedbonus + ${percent}*$mb, bjwins = bjwins + 1 WHERE id=".sqlesc($CURUSER['id']));
sql_query("UPDATE users SET seedbonus = seedbonus - $mb, bjlosses = bjlosses + 1 WHERE id=".sqlesc($a['userid']));
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$subject = sqlesc("21点的结果 : 输局 (你有 ".$a['points']." 点, ".$CURUSER['username']." 有 21 点)");
}
else
{
$winorlose = "平局";
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$subject = sqlesc("21点的结果 : 平局 (你和 ".$CURUSER['username']."都有21点)");
}
sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, ".$a['userid'].", $now, $msg, $subject)");
sql_query("DELETE FROM blackjack WHERE userid IN (".sqlesc($CURUSER['id']).", ".sqlesc($a['userid']).")");
$HTMLOUT .="<tr><td align='center'>你的对手是 ".$a["username"].",TA有 ".$a['points']." 点, $winorlose.<br />
<form method='post' action='blackjack.php'>
<input type='hidden' name='game' value='hit' readonly='readonly' />
<input type='hidden' name='start' value='yes' readonly='readonly' />
<input type='submit' value='再来一局' /></form></td></tr>";
}
else
{
sql_query("UPDATE blackjack SET status = 'waiting', date=".TIMENOW.", gameover = 'yes' WHERE userid = ".sqlesc($CURUSER['id']));
$HTMLOUT .="<tr><td align='center'>暂时没有其他玩家, 所以你需要等待。<br />游戏结束你将会收到站内信通知。<br /><br /><b><a href='blackjack.php'>返回</a></b><br /></td></tr>";
}
$HTMLOUT .="</table></td></tr></table><br />";
stdhead('21点');
print $HTMLOUT ;
stdfoot();
}
elseif ($points > 21)
{
if ($waitarr['c'] > 0)
{
$r = sql_query("SELECT bj.*, u.username FROM blackjack AS bj LEFT JOIN users AS u ON u.id=bj.userid WHERE bj.status='waiting' AND bj.userid != ".sqlesc($CURUSER['id'])." ORDER BY bj.date ASC LIMIT 1");
$a = mysql_fetch_assoc($r);
if ($a["points"] > 21)
{
$winorlose = "平局";
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$subject = sqlesc("21点的结果 : 平局 (你和 ".$CURUSER['username']." 的点数都超过 21)");
}
else
{
$winorlose = "输局,你失去了".$mb."个魔力值";
sql_query("UPDATE users SET seedbonus = seedbonus + ${percent}*$mb, bjwins = bjwins + 1 WHERE id=".sqlesc($a['userid']));
sql_query("UPDATE users SET seedbonus = seedbonus - $mb, bjlosses = bjlosses + 1 WHERE id=".sqlesc($CURUSER['id']));
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$subject = sqlesc("21点的结果 : 赢局 (你有 ".$a['points']." 点, ".$CURUSER['username']." 的点数超过 21)");
}
sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, ".$a['userid'].", $now, $msg, $subject)");
sql_query("DELETE FROM blackjack WHERE userid IN (".sqlesc($CURUSER['id']).", ".sqlesc($a['userid']).")");
$HTMLOUT .="<tr><td align='center'>你的对手是 ".$a["username"].",TA有 ".$a['points']." 点, $winorlose.<br /><form method='post' action='blackjack.php'>
<input type='hidden' name='game' value='hit' readonly='readonly' />
<input type='hidden' name='start' value='yes' readonly='readonly' />
<input type='submit' value='再来一局' /></form></td></tr>";
}
else
{
sql_query("UPDATE blackjack SET status = 'waiting', date=".TIMENOW.", gameover='yes' WHERE userid = ".sqlesc($CURUSER['id']));
$HTMLOUT .="<tr><td align='center'>暂时没有其他玩家, 所以你需要等待.<br />游戏结束你将会收到站内信通知。<br /><br /><b><a href='blackjack.php'>返回</a></b><br /></td></tr>";
}
$HTMLOUT .="</table></td></tr></table><br />";
stdhead('21点');
print $HTMLOUT ;
stdfoot();
}
else
{
$HTMLOUT .= cheater_check(empty($playerarr));
$HTMLOUT .="<h1>Welcome, {$CURUSER['username']}!</h1>
<table cellspacing='0' cellpadding='3' width='600'>
<tr><td colspan='2'>
<table class='message' width='100%' cellspacing='0' cellpadding='5' bgcolor='white'>
<tr><td align='center'>{$showcards}</td></tr>
<tr><td align='center'><b>Points = {$points}</b></td></tr>";
$HTMLOUT .="<tr>
<td align='center'><form method='post' action='blackjack.php'><input type='hidden' name='game' value='hit' readonly='readonly' /><input type='submit' value='拿牌' /></form></td>
</tr>";
$HTMLOUT .="<tr>
<td align='center'><form method='post' action='blackjack.php'><input type='hidden' name='game' value='stop' readonly='readonly' /><input type='submit' value='停牌' /></form></td>
</tr>";
$HTMLOUT .="</table></td></tr></table><br />";
stdhead('21点');
print $HTMLOUT ;
stdfoot();
}
}
elseif ($_POST["game"] == 'stop')
{
$HTMLOUT .= cheater_check(empty($playerarr));
$waitres = sql_query("SELECT COUNT(userid) AS c FROM blackjack WHERE status='waiting' AND userid != ".sqlesc($CURUSER['id']));
$waitarr = mysql_fetch_assoc($waitres);
$HTMLOUT .="<h1>Game over</h1>
<table cellspacing='0' cellpadding='3' width='600'>
<tr><td colspan='2'>
<table class='message' width='100%' cellspacing='0' cellpadding='5' bgcolor='white'>
<tr><td align='center'>{$showcards}</td></tr>
<tr><td align='center'><b>Points = {$playerarr['points']}</b></td></tr>";
if ($waitarr['c'] > 0)
{
$r = sql_query("SELECT bj.*, u.username FROM blackjack AS bj LEFT JOIN users AS u ON u.id=bj.userid WHERE bj.status='waiting' AND bj.userid != ".sqlesc($CURUSER['id'])." ORDER BY bj.date ASC LIMIT 1");
$a = mysql_fetch_assoc($r);
if ($a["points"] == $playerarr['points'])
{
$winorlose = "平局";
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$subject = sqlesc("21点的结果 : 平局 (你和".$CURUSER['username']."都有 ".$a['points']." 点)");
}
else
{
if (($a["points"] < $playerarr['points'] && $a['points'] < 21) || ($a["points"] > $playerarr['points'] && $a['points'] > 21))
{
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$subject = sqlesc("21点的结果 : 输局 (你有 ".$a['points']." 点, ".$CURUSER['username']." 有 ".$playerarr['points']." 点)");
$winorlose = "赢局,你获得了 ".(${percent}*$mb)."个魔力值";
$st_query = "+ ".$mb.", bjwins = bjwins +";
$nd_query = "- ".$mb.", bjlosses = bjlosses +";
}
elseif (($a["points"] > $playerarr['points'] && $a['points'] < 21) || $a["points"] == 21 || ($a["points"] < $playerarr['points'] && $a['points'] > 21))
{
$msg = sqlesc("[url=blackjack.php]你可以请进这个页面查看你的胜率。[/url]");
$winorlose = "输局,你失去了 ".$mb."个魔力值";
$subject = sqlesc("21点的结果 : 赢局 (你有 ".$a['points']." 点, ".$CURUSER['username']." 有 ".$playerarr['points']." 点)");
$st_query = "- ".$mb.", bjlosses = bjlosses +";
$nd_query = "+ ".$mb.", bjwins = bjwins +";
}
sql_query("UPDATE users SET seedbonus = seedbonus ".$st_query." 1 WHERE id=".sqlesc($CURUSER['id']));
sql_query("UPDATE users SET seedbonus = seedbonus ".$nd_query." 1 WHERE id=".sqlesc($a['userid']));
}
sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, ".$a['userid'].", $now, $msg, $subject)");
sql_query("DELETE FROM blackjack WHERE userid IN (".sqlesc($CURUSER['id']).", ".sqlesc($a['userid']).")");
$HTMLOUT .="<tr><td align='center'>你的对手是 ".$a["username"]." , TA有 ".$a['points']." 点, $winorlose.<br />
<form method='post' action='blackjack.php'>
<input type='hidden' name='game' value='hit' readonly='readonly' />
<input type='hidden' name='start' value='yes' readonly='readonly' />
<input type='submit' value='再来一局' /></form></td></tr>";
}
else
{
sql_query("UPDATE blackjack SET status = 'waiting', date=".TIMENOW.", gameover='yes' WHERE userid = ".sqlesc($CURUSER['id']));
$HTMLOUT .="<tr><td align='center'>暂时没有其他玩家, 所以你需要等待。<br />游戏结束你将会收到站内信通知。<br /><br /><b><a href='blackjack.php'>返回</a></b><br /></td></tr>";
}
$HTMLOUT .="</table></td></tr></table><br />";
stdhead('21点');
print $HTMLOUT ;
stdfoot();
}
}
else
{
$waitres = sql_query("SELECT COUNT(userid) AS c FROM blackjack WHERE (date > ".TIMENOW."-10 OR status ='waiting') AND userid != ".sqlesc($CURUSER['id']));
$waitarr = mysql_fetch_assoc($waitres);
$res = sql_query("SELECT status, gameover FROM blackjack WHERE userid = ".sqlesc($CURUSER['id']));
$arr = mysql_fetch_assoc($res);
$tot_wins = $CURUSER['bjwins'];
$tot_losses = $CURUSER['bjlosses'];
$tot_games = $tot_wins + $tot_losses;
$win_perc = ($tot_losses==0?($tot_wins==0?"---":"100%"):($tot_wins==0?"0":number_format(($tot_wins/$tot_games)*100,1)).'%');
$plus_minus = (${percent}*$tot_wins-$tot_losses<0?'-':'').((${percent}*$tot_wins-$tot_losses>=0?(${percent}*$tot_wins-$tot_losses):($tot_losses-${percent}*$tot_wins)))*$mb;
$HTMLOUT .="<h1>21点</h1>
<table cellspacing='0' cellpadding='3' width='400'>
<tr><td colspan='2' align='center'>
<table class='message' width='100%' cellspacing='0' cellpadding='10' bgcolor='white'>
<tr><td align='center'><img src='cards/tp.bmp' style=\"border: 1px\" alt='' /> <img src='cards/vp.bmp' style=\"border: 1px\" alt='' /></td></tr>
<tr><td align='left'>传统的21点游戏,您要抓足够接近21点,和对手对抗。<br />A在总分不超过21时作11,总分超过21则作1。J,Q,K作为10。<br /><br />
<b>当前在线人数: </b>". $waitarr['c']."<br/>
<b>提示:</b> 每局赌注为".$mb."个魔力值<br/>\n(每局服务器将抽取赌注的".(100*(1-${percent}))."%作为佣金)<br/>
</td></tr>
<tr><td align='center'>
<form method='post' action='blackjack.php'>
".($arr['status'] == 'waiting'?
"请等待上局结束<br /><input type='submit' value='刷新' />":
"<input type='hidden' name='game' value='hit' readonly='readonly' />
<input type='hidden' name='start' value='yes' readonly='readonly' />
<input type='submit' value='开牌'/>
")."
</form>
</td></tr></table>
</td></tr></table>
<br /><br /><br />
<table cellspacing='0' cellpadding='3' width='400'>
<tr><td colspan='2' align='center'>
<h1>个人记录</h1></td></tr>
<tr><td align='left'><b>胜局</b></td><td align='center'><b>{$tot_wins}</b></td></tr>
<tr><td align='left'><b>输局</b></td><td align='center'><b>{$tot_losses}</b></td></tr>
<tr><td align='left'><b>游戏次数</b></td><td align='center'><b>{$tot_games}</b></td></tr>
<tr><td align='left'><b>获胜率</b></td><td align='center'><b>{$win_perc}</b></td></tr>
<tr><td align='left'><b>+/-</b></td><td align='center'><b>".(round($plus_minus))."个魔力值</b></td></tr>
</table><br /><b><div align=\"center\"><a href=\"bjstats.php\">排行榜</a></div></b> ";
stdhead('21点');
print $HTMLOUT ;
stdfoot();
}
?>