<?php
 
include_once './include/common.inc.php';
sajax_init();
sajax_export("doSub","listfso","listfso1","checkserv","doView","doView1","checkserv1");
sajax_handle_client_request();
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
if (!$MOD['enablemfso']) showmessage("对不起，管理员未开启分区转移功能！");
function doSub($id,$idfso,$id1,$idfso1)  
{
global $db,$_username,$MOD;
if(!$id) return "<span class=font06>请选择转出服务器</span>";
if(!$idfso) return "<span class=font06>请选择转出角色</span>";
if(!$id1) return "<span class=font06>请选择转入服务器</span>";
if(!$idfso1) return "<span class=font06>请选择转入角色</span>";
if (!check_con($id)) return "<span class=font06>转出分区连接失败，请与管理员联系</span>";
if (!check_con($id1)) return "<span class=font06>转入分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Faction,Name FROM user WHERE ID='$idfso'");
if (!$fsoinfo) return "<span class=font06>错误的请求！</span>";
$sqldb1 = real_con($id1);
$sqldb1->select_db(game_fso($id1));
$fsoinname = $sqldb1->get_one("SELECT AccountID,Faction,Name FROM user WHERE Name='$fsoinfo[Name]'");
$fsoinfo1 = $sqldb1->get_one("SELECT AccountID,Faction,Name FROM user WHERE ID='$idfso1'");
if ($fsoinfo1) {
if ($fsoinfo[Faction]!=$fsoinfo1[Faction]) return "<span class=font06>转入转出分区存在不同的阵营的角色，请修改或联系管理员！</span>";
$checknum = $sqldb->get_one("SELECT count(ID) as num FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted != 1");
if($checknum[num] >3) return "<span class=font06>当前帐号下有".$check[num]."个角色，请保证角色数量不大于3个！</span>";
}
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo[AccountID]'");
if(!$accinfo) return "<span class=font06>错误的请求！</span>";
if($accinfo['username'] != "$_username") return "<span class=font06>非法操作，你的操作已被记录！</span>";
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo1 = $sqldb->get_one("SELECT * FROM user WHERE ID='$idfso'");
if($fsoinfo1){
return "true";
}else{
return "<span class=font06>角色数据读取失败，请联系管理员！</span>";
}
}
function doView($id,$value)
{
global $db,$_username,$MOD;
if(!$id) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">游戏分区读取错误！</TD></TR></TBODY></TABLE>';
if(!$value) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">请选择转移角色！</TD></TR></TBODY></TABLE>';
if (!check_con($id)) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前分区连接失败，请与管理员联系</TD></TR></TBODY></TABLE>';
if (is_online($id)) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">转出转入分区任意角色需要退出游戏3分钟才能操作！</TD></TR></TBODY></TABLE>';
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Metier,Metierlevel,Level,CreateDate,LastUpdateDate,Faction FROM user WHERE ID='$value'");
$banks = $sqldb->get_one("SELECT BankMoney FROM t_bank WHERE AccountID='$fsoinfo[AccountID]'");
if($fsoinfo)
{
$faction = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted != 1 AND Faction !='$fsoinfo[Faction]'");
if ($faction) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前帐号下存在不同阵营的角色，不能进行操作！</TD></TR></TBODY></TABLE>';
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo[AccountID]'");
if(!$accinfo)
{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">非法请求！</TD></TR></TBODY></TABLE>';
}else{
if($accinfo['username'] != "$_username") return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">非法操作，你的操作已被记录！</TD></TR></TBODY></TABLE>';
}
$CreateDate = strtotime($fsoinfo[LastUpdateDate]);
$CreateDate = date("Y年m月d日 H点i分",$CreateDate);
$Level = $fsoinfo['Level'];
$metier = getmetier($fsoinfo['Metier']);
$faction = getfaction($fsoinfo['Faction']);
if($Level &&$metier)
{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH style="font-weight:bold;font-size:14px">角色信息： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$Level.'级'.$metier.'</TD></TR><TR><TH style="font-weight:bold;font-size:14px">角色职业： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold"> '.$metier.'('.$faction.')</TD></TR><TR><TH style="font-weight:bold;font-size:14px">最后登录： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$CreateDate.'</TD></TR><TR><TH></TH><TD colSpan=2><input id="subok" type="submit" onClick="doSub()" class="hsbtn" value="确认"></TD></TR></TBODY></TABLE>';
}else{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">角色信息读取失败!</TD></TR></TBODY></TABLE>';
}
}else{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">未读取到角色信息!</TD></TR></TBODY></TABLE>';
}
}
function doView1($id,$value)
{
global $db,$_username,$MOD;
if(!$id) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">游戏分区读取错误！</TD></TR></TBODY></TABLE>';
if(!$value) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">请选择转移角色！</TD></TR></TBODY></TABLE>';
if (!check_con($id)) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前分区连接失败，请与管理员联系</TD></TR></TBODY></TABLE>';
if (is_online($id)) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">请确保其它角色未在游戏中或在正常退出游戏后三分钟再进行恢复！</TD></TR></TBODY></TABLE>';
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Metier,Metierlevel,Level,CreateDate,Faction FROM user WHERE ID='$value'");
$banks = $sqldb->get_one("SELECT BankMoney FROM t_bank WHERE AccountID='$fsoinfo[AccountID]'");
$check = $sqldb->get_one("SELECT count(ID) as num FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted != 1");
if($check[num] >2) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前帐号下有'.$check[num].'个角色，请保证角色数量不大于两个！</TD></TR></TBODY></TABLE>';
if($fsoinfo)
{
$faction = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted != 1 AND Faction !='$fsoinfo[Faction]'");
if ($faction) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前帐号下存在不同阵营的角色，不能进行恢复！</TD></TR></TBODY></TABLE>';
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo[AccountID]'");
if(!$accinfo)
{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">非法请求！</TD></TR></TBODY></TABLE>';
}else{
if($accinfo['username'] != "$_username") return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">非法操作，你的操作已被记录！</TD></TR></TBODY></TABLE>';
}
$CreateDate = strtotime($fsoinfo[CreateDate]);
$CreateDate = date("Y年m月d日 H点i分",$CreateDate);
$Level = $fsoinfo['Level'];
$metier = getmetier($fsoinfo['Metier']);
if($Level &&$metier)
{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH style="font-weight:bold;font-size:14px">角色信息： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$Level.'级'.$metier.'</TD></TR><TR><TH style="font-weight:bold;font-size:14px">角色职业： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold"> '.$metier.'</TD></TR><TR><TH style="font-weight:bold;font-size:14px">创建时间： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$CreateDate.'</TD></TR><TR><TH></TH><TD colSpan=2><input id="subok" type="submit" onClick="doSub()" class="hsbtn" value="确认"></TD></TR></TBODY></TABLE>';
}else{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">角色信息读取失败!</TD></TR></TBODY></TABLE>';
}
}else{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">未读取到角色信息!</TD></TR></TBODY></TABLE>';
}
}
function listfso($id)
{
global $db,$_userid,$_username;
if(!$id) return "游戏分区读取错误";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
if($info)
{
$sqldb->select_db(game_fso($id));
$users = array();
$rs = $sqldb->query("SELECT ID,Name FROM user WHERE AccountID='".$info['idx']."' and  deleted != 1");
if(!$rs)
{
return "没有接受转移的分区。";
}else{
while($r = $sqldb->fetch_array($rs))
{
$users[] = $r;
}
foreach($users as $value)
{
$bstr .= '<option value='.$value[ID].'>'.$value[Name].'</option>';
}
return '<select id="idfso" onchange="doView(this.value)"><option>-- 请选择转出角色 --</option>'.$bstr.'</select>';
}
}else{
return "您没有激活该分区";
}
}
function listfso1($id)
{
global $db,$_userid,$_username;
if(!$id) return "游戏分区读取错误";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
if($info)
{
$sqldb->select_db(game_fso($id));
$users = array();
$rs = $sqldb->query("SELECT ID,Name FROM user WHERE AccountID='".$info['idx']."' and  deleted != 1");
if(!$rs)
{
return "没有接受转移的分区。";
}else{
while($r = $sqldb->fetch_array($rs))
{
$users[] = $r;
}
foreach($users as $value)
{
$bstr1 .= '<option value='.$value[ID].'>'.$value[Name].'</option>';
}
return '<select id="idfso1" onchange="doView1(this.value)"><option>-- 请选择转入角色 --</option>'.$bstr1.'</select>';
}
}else{
return "您没有激活该分区";
}
}
function checkserv($id)
{
global $db,$_userid,$_username;
if(!$id) return "<span class=font06>请选择转出分区</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$query= "select enableout from  ".TABLE_GAMESERVER."  where id='".$id."' and enableout='1'";
$p = $db->get_one($query);
if(!$p['enableout']){
return "<span class=font06>该分区不允许转出，请重新选择</span>";
}
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
if($info)
{
$sqldb->select_db(game_fso($id));
$infou = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='".$info['idx']."' and  deleted != 1 ");
if(!$infou)
{
return "<span class=font06>分区连接成功，但该分区没有可转出角色。</span>";
}else{
return "true";
}
}else{
return "<span class=font06>您没有激活该分区</span>";
}
return "true";
}
function checkserv1($id,$idfso)
{
global $db,$_userid,$_username;
if(!$id) return "<span class=font06>请选择转入分区</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$query= "select enablecome from  ".TABLE_GAMESERVER."  where id='".$id."' and enablecome='1'";
$p = $db->get_one($query);
if(!$p['enablecome']){
return "<span class=font06>该分区不允许转入，请重新选择</span>";
}
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
if($info){
$sqldb->select_db(game_fso($id));
$infou = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='".$info['idx']."' and  deleted != 1 ");
if(!$infou)
{
return "<span class=font06>分区连接成功，但该分区没有可操作的角色。</span>";
}else{
return "true";
}
}else{
return "<span class=font06>您没有激活该分区</span>";
}
return "true";
}
$head['title'] = '角色转移(自助合区)';
$head['keywords'] = $MOD['seo_keywords'];
$head['description'] = $MOD['seo_description'];
$query = "SELECT truename,telephone,qq,area FROM ".TABLE_MEMBER_INFO." WHERE userid=$_userid";
@extract($db->get_one($query));
if(!$area) showmessage("请选激活游戏分区再进行此操作！","/game/actgame.php");
$query = "SELECT * FROM ".TABLE_GAMESERVER." WHERE id IN ($area) ORDER BY id";
$result=$db->query($query);
while($r=$db->fetch_array($result))
{
$gamelists[]=$r;
}
include template($mod,'mfso');
?>