<?php

defined('IN_HS') or exit('Access Denied');
$submenu = array
(
array("<input class=btn type=button value=' 添加服务器 ' onclick=window.location='?mod=$mod&file=$file&action=addserver'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class=btn type=button value=' 服务器列表 ' onclick=window.location='?mod=$mod&file=$file'>","#"),
);
$menu = adminmenu('游戏区域管理(要管理游戏，服务器都必须设置！)',$submenu);
$action = $action ?$action : 'manage';
switch($action)
{
case 'addserver':
if($dosubmit)
{
if(!$servername ||!$serverip ||!$loginname ||!$loginpass ||!$port ||!$dataattr ||!$dataacc ||!$datafso) showmessage('所有选项必须填写！');
$check = $db->get_one("SELECT id FROM ".TABLE_GAMESERVER." WHERE servername='$servername'");
if ($check) showmessage("该服务器名称已存在，请返回重新设置！");
$db->query("INSERT INTO ".TABLE_GAMESERVER." (`status`,`servername`,`serverip`,`loginname`,`loginpass`,`port`,`dataattr`,`dataacc`,`datafso`,`datalog`,`enableout`,`enablecome`,`enablezs`,`gameamo`) VALUES ('$status','$servername','$serverip','$loginname','$loginpass','$port','$dataattr','$dataacc','$datafso','$datalog','$enableout','$enablecome','$enablezs','$gameamo')");
cache_gamelist();
showmessage('操作成功','?mod='.$mod.'&file='.$file.'');
}
include admintpl('server_add');
break;
case 'editserver':
$id = intval($id);
if ($dosubmit)
{
if(!$id) showmessage('非法操作');
if(!$servername ||!$serverip ||!$loginname ||!$loginpass ||!$port ||!$dataattr ||!$dataacc ||!$datafso) showmessage('所有选项必须填写！');
if($servername != $oldname)
{
$check = $db->get_one("SELECT id FROM ".TABLE_GAMESERVER." WHERE servername='$servername'");
if ($check) showmessage("该服务器名称已存在，请返回重新设置！");
}
$db->query("UPDATE ".TABLE_GAMESERVER." SET `status`='$status',`servername`='$servername',`serverip`='$serverip',`loginname`='$loginname',`loginpass`='$loginpass',`port`='$port',`dataattr`='$dataattr',`dataacc`='$dataacc',`datafso`='$datafso',`datalog`='$datalog',`enableout`='$enableout',`enablecome`='$enablecome',`enablezs`='$enablezs',`gameamo`='$gameamo' WHERE id='$id'");
cache_gamelist();
showmessage('修改成功','?mod='.$mod.'&file='.$file.'');
}else{
$result = $db->get_one("SELECT * FROM ".TABLE_GAMESERVER." WHERE id=$id");
@extract($result);
}
include admintpl('serverlist_edit');
break;
case 'delete':
$id=intval($id);
if(!$id) showmessage('非法操作');
$db->query("DELETE FROM ".TABLE_GAMESERVER." WHERE id='$id'");
cache_gamelist();
showmessage('操作成功！','?mod='.$mod.'&file='.$file.'');
break;
case 'manage':
$gamelist = array();
$result = $db->query("SELECT * FROM ".TABLE_GAMESERVER." ORDER BY id");
while($r = $db->fetch_array($result))
{
$gamelist[] = $r;
}
include admintpl('gamelist');
break;
}
?>