Commit ec89e019 authored by Nemo Ma's avatar Nemo Ma Committed by GitHub

Merge pull request #111 from hikawiier/waaagh

update roommng
parents 5fec49d0 321b8976
...@@ -1489,6 +1489,13 @@ $_ERROR = Array( ...@@ -1489,6 +1489,13 @@ $_ERROR = Array(
//'banned_name' => '用户名含有违禁用语,请更改用户名', //'banned_name' => '用户名含有违禁用语,请更改用户名',
//'banned_ip' => '此IP已被封禁,请与管理员联系', //'banned_ip' => '此IP已被封禁,请与管理员联系',
//'long_name' => '用户名过长,请重新输入用户名' //'long_name' => '用户名过长,请重新输入用户名'
'alreay_in_room' => '你已经在房间里了。要创建/加入房间必须退出当前房间。',
'not_in_room' => '你不在任何房间里。',
'room_ip_limit' => '相同IP最多只能创建2个房间。请先解散其他房间。',
'room_num_limit' => '房间数量已达上限,无法新建房间。',
'room_close_limit' => '你没有权限解散该房间,只有房主或管理员可以解散房间。',
'room_close_limit2' => '不能解散正在进行游戏,且游戏内尚有幸存者的房间!',
); );
?> ?>
<?php
define('CURSCRIPT', 'index');
require './include/common.inc.php';
$timing = 0;
if($gamestate > 10) {
$timing = $now - $starttime;
} else {
if($starttime > $now) {
$timing = $starttime - $now;
} else {
$timing = 0;
}
}
$adminmsg = file_get_contents('./gamedata/adminmsg.htm') ;
$systemmsg = file_get_contents('./gamedata/systemmsg.htm') ;
include template('index');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9744745-2");
pageTracker._trackPageview();
} catch(err) {}</script>
</head>
</html>
\ No newline at end of file
...@@ -49,11 +49,11 @@ function roommng_verify_db_game_structure() ...@@ -49,11 +49,11 @@ function roommng_verify_db_game_structure()
function roommng_create_new_room(&$udata) function roommng_create_new_room(&$udata)
{ {
global $db,$gtablepre,$now; global $db,$gtablepre,$now;
global $startmin,$max_rooms,$ip_max_rooms; global $startmin,$max_rooms,$ip_max_rooms,$rerror;
if(!empty($udata['roomid'])) if(!empty($udata['roomid']))
{ {
echo "你已经在房间里了。要创建新房间必须退出当前房间。<br>"; $rerror = 'alreay_in_room';
return; return;
} }
...@@ -61,7 +61,7 @@ function roommng_create_new_room(&$udata) ...@@ -61,7 +61,7 @@ function roommng_create_new_room(&$udata)
$ipresult = $db->query("SELECT roomid FROM {$gtablepre}users WHERE roomid>0 AND ip='{$udata['ip']}'"); $ipresult = $db->query("SELECT roomid FROM {$gtablepre}users WHERE roomid>0 AND ip='{$udata['ip']}'");
if($db->num_rows($ipresult) >= $ip_max_rooms) if($db->num_rows($ipresult) >= $ip_max_rooms)
{ {
echo "相同IP最多只能创建{$ip_max_rooms}个房间。请先解散其他房间。<br>"; $rerror = 'room_ip_limit';
return; return;
} }
...@@ -70,7 +70,7 @@ function roommng_create_new_room(&$udata) ...@@ -70,7 +70,7 @@ function roommng_create_new_room(&$udata)
$now_room_nums = $db->num_rows($result); $now_room_nums = $db->num_rows($result);
if($now_room_nums >= $max_rooms) if($now_room_nums >= $max_rooms)
{ {
echo "房间数量已达上限,无法新建房间。<br>"; $rerror = 'room_num_limit';
return; return;
} }
...@@ -88,11 +88,11 @@ function roommng_create_new_room(&$udata) ...@@ -88,11 +88,11 @@ function roommng_create_new_room(&$udata)
# 加入一个房间 # 加入一个房间
function roommng_join_room($rkey,&$udata) function roommng_join_room($rkey,&$udata)
{ {
global $db,$gtablepre; global $db,$gtablepre,$rerror;
if(!empty($udata['roomid'])) if(!empty($udata['roomid']))
{ {
echo "你已经在房间里了。要加入房间必须退出当前房间。<br>"; $rerror = 'alreay_in_room';
return; return;
} }
...@@ -117,11 +117,11 @@ function roommng_join_room($rkey,&$udata) ...@@ -117,11 +117,11 @@ function roommng_join_room($rkey,&$udata)
# 离开当前房间 # 离开当前房间
function roommng_exit_room(&$udata) function roommng_exit_room(&$udata)
{ {
global $db,$gtablepre; global $db,$gtablepre,$rerror;
if(empty($udata['roomid'])) if(empty($udata['roomid']))
{ {
echo "你不在任何房间里。<br>"; $rerror = 'not_in_room';
return; return;
} }
...@@ -169,11 +169,11 @@ function roommng_exit_room(&$udata) ...@@ -169,11 +169,11 @@ function roommng_exit_room(&$udata)
# 房主解散自己所在的房间 # 房主解散自己所在的房间
function roommng_close_own_room(&$udata) function roommng_close_own_room(&$udata)
{ {
global $db,$gtablepre; global $db,$gtablepre,$rerror;
if(empty($udata['roomid'])) if(empty($udata['roomid']))
{ {
echo "你不在任何房间里。<br>"; $rerror = 'not_in_room';
return; return;
} }
...@@ -184,13 +184,13 @@ function roommng_close_own_room(&$udata) ...@@ -184,13 +184,13 @@ function roommng_close_own_room(&$udata)
# 不能解散没有房主的房间 # 不能解散没有房主的房间
if(empty($gdata['groomownid']) || (!empty($gdata['groomownid']) && $gdata['groomownid'] != $udata['username'])) if(empty($gdata['groomownid']) || (!empty($gdata['groomownid']) && $gdata['groomownid'] != $udata['username']))
{ {
echo "你没有权限解散房间{$udata['roomid']}<br>"; $rerror = 'room_close_limit';
return; return;
} }
# 不能解散正在游戏中的房间 # 不能解散正在游戏中的房间
if($gdata['gamestate'] > 10 && $gdata['alivenum']) if($gdata['gamestate'] > 10 && $gdata['alivenum'])
{ {
echo "不能解散游戏正在进行且尚有幸存者的房间!<br>"; $rerror = 'room_close_limit2';
return; return;
} }
# 解散房间 # 解散房间
...@@ -202,13 +202,13 @@ function roommng_close_own_room(&$udata) ...@@ -202,13 +202,13 @@ function roommng_close_own_room(&$udata)
} }
# 强制解散指定房间 # 强制解散指定房间
function roommng_close_room($rkey) function roommng_close_room($rkey,$adminlog = 0)
{ {
global $db,$gtablepre; global $db,$gtablepre,$rerror,$cmd_info;
if(!$rkey) if(!$rkey)
{ {
echo "不能关闭大房间!<br>"; $cmd_info .= "不能关闭大房间!<br>";
return; return;
} }
...@@ -220,11 +220,12 @@ function roommng_close_room($rkey) ...@@ -220,11 +220,12 @@ function roommng_close_room($rkey)
if($gdata['groomnums']) $db->query("UPDATE {$gtablepre}users SET roomid=0 WHERE roomid={$rkey}"); if($gdata['groomnums']) $db->query("UPDATE {$gtablepre}users SET roomid=0 WHERE roomid={$rkey}");
# 关闭房间 # 关闭房间
$db->query("DELETE FROM {$gtablepre}game WHERE groomid={$rkey}"); $db->query("DELETE FROM {$gtablepre}game WHERE groomid={$rkey}");
echo "已关闭房间 {$rkey} 号<br>"; $cmd_info .= "已关闭房间 {$rkey} 号<br>";
if($adminlog) adminlog('closeroom',$rkey);
} }
else else
{ {
echo "房间 {$rkey} 未开启,或房间不存在!<br>"; $cmd_info .= "房间 {$rkey} 未开启,或房间不存在!<br>";
} }
return; return;
} }
......
...@@ -20,14 +20,16 @@ if($gamestate > 10) { ...@@ -20,14 +20,16 @@ if($gamestate > 10) {
$adminmsg = file_get_contents('./gamedata/adminmsg.htm') ; $adminmsg = file_get_contents('./gamedata/adminmsg.htm') ;
$systemmsg = file_get_contents('./gamedata/systemmsg.htm') ; $systemmsg = file_get_contents('./gamedata/systemmsg.htm') ;
if(!empty($roomact)) if(!empty($roomact))
{ {
if(!$cuser||!$cpass) { gexit($_ERROR['no_login'],__file__,__line__); } $rindex = Array();
if(!$cuser||!$cpass) {$rerror = 'no_login'; goto roommng_flag; }
$result = $db->query("SELECT * FROM {$gtablepre}users WHERE username='$cuser'"); $result = $db->query("SELECT * FROM {$gtablepre}users WHERE username='$cuser'");
if(!$db->num_rows($result)) { gexit($_ERROR['login_check'],__file__,__line__); } if(!$db->num_rows($result)) {$rerror = 'login_check'; goto roommng_flag;}
$udata = $db->fetch_array($result); $udata = $db->fetch_array($result);
if($udata['password'] != $cpass) { gexit($_ERROR['wrong_pw'], __file__, __line__); } if($udata['password'] != $cpass) {$rerror = 'wrong_pw'; goto roommng_flag;}
if($udata['groupid'] <= 0) { gexit($_ERROR['user_ban'], __file__, __line__); } if($udata['groupid'] <= 0) {$rerror = 'user_ban'; goto roommng_flag;}
if($roomact == 'create') if($roomact == 'create')
{ {
...@@ -47,6 +49,13 @@ if(!empty($roomact)) ...@@ -47,6 +49,13 @@ if(!empty($roomact))
roommng_close_own_room($udata); roommng_close_own_room($udata);
} }
unset($roomact); unset($roomact);
roommng_flag:
if(!empty($rerror) && isset($_ERROR[$rerror])) $rindex['innerHTML']['roomerror'] = $_ERROR[$rerror];
else $rindex['url'] = 'index.php';
ob_clean();
echo compatible_json_encode($rindex);
ob_end_flush();
exit();
} }
else else
{ {
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
$adminmsg $adminmsg
</span> </span>
<br> <br>
<span class="evergreen"> <span class="evergreen">当前房间列表:
<span class="evergreen">当前房间列表:
<input type="button" value="点击查看房间列表" onclick="showModalDialog($('roomlist'));"> <input type="button" value="点击查看房间列表" onclick="showModalDialog($('roomlist'));">
<div style="height:5px;">&nbsp;</div> <div style="height:5px;">&nbsp;</div>
{template roomlist} {template roomlist}
......
<dialog id="roomlist" style="max-width: 90%;max-height: 80%; text-align: left;"> <dialog id="roomlist" style="max-width: 90%;max-height: 80%; text-align: left;">
<span class="yellow b"><div id="roomerror" style="padding-bottom: 5px;"></div></span>
<form method="post" name="roomact" onsubmit="return false;" > <form method="post" name="roomact" onsubmit="return false;" >
<input type="hidden" name="roomact" id="roomact" value=""> <input type="hidden" name="roomact" id="roomact" value="">
<!--{eval $now_rooms = !empty($roomlist) ? count($roomlist) : 0;}--> <!--{eval $now_rooms = !empty($roomlist) ? count($roomlist) : 0;}-->
<span class="evergreen">当前房间列表({$now_rooms}/{$max_rooms}) <span class="evergreen">当前房间列表({$now_rooms}/{$max_rooms})
<!--{if $now_rooms < $max_rooms && !$groomid}--> <!--{if $now_rooms < $max_rooms && !$groomid && (!empty($cuser) && !empty($cpass))}-->
<input type="button" value="点击创建一个新的房间" onclick="$('roomact').value='create';postCmd('roomact','index.php');setTimeout(function(){window.location.href='index.php';},300);disabled=true;" > <input type="button" value="点击创建一个新的房间" onclick="$('roomact').value='create';postCmd('roomact','index.php');" >
<!--{/if}--> <!--{/if}-->
<br> <br>
<div style="height:5px;">&nbsp;</div> <div style="height:5px;">&nbsp;</div>
...@@ -37,22 +38,26 @@ ...@@ -37,22 +38,26 @@
</td> </td>
<!--<td class="b3" width="120px">运行时间</td>--> <!--<td class="b3" width="120px">运行时间</td>-->
<td class="b3" width="80px"> <td class="b3" width="80px">
<!--{if !empty($cuser) && !empty($cpass)}-->
<!--{if !empty($rid)}--> <!--{if !empty($rid)}-->
<!--{if $rid == $rkey}--> <!--{if $rid == $rkey}-->
<span tooltip2="退出房间后,如房间内没有其他玩家,则房间会解散;房主退出房间会将房主权限转移给房间内其他玩家;"> <span tooltip2="退出房间后,如房间内没有其他玩家,则房间会解散;房主退出房间会将房主权限转移给房间内其他玩家;">
<input type="button" value="退出" onclick="$('roomact').value='exit';postCmd('roomact','index.php');setTimeout(function(){window.location.href='index.php';},300);disabled=true;" > <input type="button" value="退出" onclick="$('roomact').value='exit';postCmd('roomact','index.php');" >
</span> </span>
<!--{if !empty($rinfo['groomownid']) && $rinfo['groomownid'] == $cuser}--> <!--{if !empty($rinfo['groomownid']) && $rinfo['groomownid'] == $cuser}-->
<span tooltip2="不能解散正在进行游戏且尚有其他玩家存活的房间"> <span tooltip2="不能解散正在进行游戏且尚有其他玩家存活的房间">
<input type="button" value="解散" onclick="$('roomact').value='close';postCmd('roomact','index.php');setTimeout(function(){window.location.href='index.php';},300);disabled=true;" > <input type="button" value="解散" onclick="$('roomact').value='close';postCmd('roomact','index.php');" >
</span> </span>
<!--{/if}--> <!--{/if}-->
<!--{else}--> <!--{else}-->
<span class="grey">-</span> <span class="grey">-</span>
<!--{/if}--> <!--{/if}-->
<!--{else}--> <!--{else}-->
<input type="button" value="加入" onclick="$('roomact').value='join{$rkey}';postCmd('roomact','index.php');setTimeout(function(){window.location.href='index.php';},300);disabled=true;" > <input type="button" value="加入" onclick="$('roomact').value='join{$rkey}';postCmd('roomact','index.php');" >
<!--{/if}--> <!--{/if}-->
<!--{else}-->
<span class="grey">-</span>
<!--{/if}-->
</td> </td>
</tr> </tr>
<!--{/loop}--> <!--{/loop}-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment