<?php
 
include_once './include/common.inc.php';
sajax_init();
sajax_export("savemfso");
sajax_handle_client_request();
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
if (!$MOD['enablemfso']) showmessage("对不起，管理员未开启分区转移功能！");
function savemfso($id,$idfso,$id1,$idfso1,$Skills,$Task,$Items)  
{
global $db,$_username,$MOD;
if(!$id) return "没读取到转出服务器";
if(!$idfso) return "没读取到转出角色";
if(!$id1) return "没读取到转入服务器";
if(!$idfso1) return "没读取到转入角色";
if (!check_con($id)) return "转出分区连接失败，请与管理员联系";
if (!check_con($id1)) return "转入分区连接失败，请与管理员联系";
$Skills = $_COOKIE['cookskills'];
$Task = $_COOKIE['cooktask'];
$Items = $_COOKIE['cookitems'];
if(!$Items) return "你禁用了Cookie！无法完成转区操作！";
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT ID,AccountID,Faction,Name,deleted FROM user WHERE ID='$idfso'");
if (!$fsoinfo) return "错误的请求！";
if ($fsoinfo['deleted']=='1') return "已转区成功，请不要多次提交！！！";
$sqldb1 = real_con($id1);
$sqldb1->select_db(game_fso($id1));
$fsoinfo1 = $sqldb1->get_one("SELECT AccountID,Faction,Name FROM user WHERE ID='$idfso1'");
if ($fsoinfo1) {
if ($fsoinfo[Faction]!=$fsoinfo1[Faction]) return "转入转出分区存在不同的阵营的角色，请修改或联系管理员！";
$checknum = $sqldb->get_one("SELECT count(ID) as num FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted != 1");
if($checknum[num] >3) return "当前帐号下有".$check[num]."个角色，请保证角色数量不大于3个！";
}
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo[AccountID]'");
if(!$accinfo) return "错误的请求！";
if($accinfo['username'] != "$_username") return "非法操作，你的操作已被记录！";
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo1 = $sqldb->get_one("SELECT * FROM user WHERE ID='$idfso'");
$sqldb1 = real_con($id1);
$sqldb1->select_db(game_fso($id1));
$sqldb1->query("update user set ActorID='$fsoinfo1[ActorID]',Scene='$fsoinfo1[Scene]',HP='$fsoinfo1[HP]',MP='$fsoinfo1[MP]',`EXP`='$fsoinfo1[EXP]',AP='$fsoinfo1[AP]',Level='$fsoinfo1[Level]',Lottery='$fsoinfo1[Lottery]',DeleteDate='$fsoinfo1[DeleteDate]',CreateDate='$fsoinfo1[CreateDate]', LastUpdateDate='$fsoinfo1[LastUpdateDate]',Metier='$fsoinfo1[Metier]',MetierLevel='$fsoinfo1[MetierLevel]',X='$fsoinfo1[X]',Y='$fsoinfo1[Y]',Gold='$fsoinfo1[Gold]',SP='$fsoinfo1[SP]',
 Str='$fsoinfo1[Str]',Con='$fsoinfo1[Con]',Dex='$fsoinfo1[Dex]',Hit='$fsoinfo1[Hit]',Skills='$Skills',Items='$Items',Shortcut='$fsoinfo1[Shortcut]',Config='$fsoinfo1[Config]',PK='$fsoinfo1[PK]',Task='$Task',Score='$fsoinfo1[Score]',HeadModelID='$fsoinfo1[HeadModelID]',Credit='$fsoinfo1[Credit]',OnlineTime='$fsoinfo1[OnlineTime]',usertype='$fsoinfo1[usertype]',LastDelUnionTime='$fsoinfo1[LastDelUnionTime]',LastRemoveMPTime='$fsoinfo1[LastRemoveMPTime]',deleted='$fsoinfo1[deleted]',Faction='$fsoinfo1[Faction]',ClearCnt='$fsoinfo1[ClearCnt]',DungeonTID='$fsoinfo1[DungeonTID]',DungeonUID='$fsoinfo1[DungeonUID]',DungeonQuit='$fsoinfo1[DungeonQuit]',DungeonTask='$fsoinfo1[DungeonTask]',InWarfield='$fsoinfo1[InWarfield]',WarfieldQuit='$fsoinfo1[WarfieldQuit]',WithdrawMPGift='$fsoinfo1[WithdrawMPGift]',MyData='*',`Int`='$fsoinfo1[Int]'  where ID='$idfso1'");
if($sqldb1->affected_rows())
{
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$sqldb->query("update user set deleted='1',deletedate=NOW() WHERE ID='$fsoinfo[ID]'");
return "true";
}else{
return "转区失败，请与管理员连系！";
}
}
switch($action)
{
case 'visa':
$idserver=intval($idserver);
$idserver1=intval($idserver1);
$idfso=intval($idfso);
$idfso1=intval($idfso1);
if(!idserver) showmessage("非法操作！");
if(!idserver1) showmessage("非法操作！");
if(!idfso) showmessage("非法操作！");
if(!idfso1) showmessage("非法操作！");
$gamels = $db->get_one("SELECT * FROM ".TABLE_GAMESERVER." WHERE id='$idserver'");
@extract($gamels,EXTR_OVERWRITE);
$mysqlco = @mysql_connect($serverip.':'.$port,$loginname,$loginpass,$dataacc);
if(!$mysqlco) showmessage("连接转出分区失败，请检查服务器分区设置情况！");
$sqldb = new db_mysql;
$sqldb->connect($serverip.':'.$port,$loginname,$loginpass,$datafso);
$fsoinfo1 = $sqldb->get_one("SELECT * FROM user WHERE ID='$idfso'");
$metier = getmetier($fsoinfo1['Metier']);
$faction = getfaction($fsoinfo1['Faction']);
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo1[AccountID]'");
if(!$accinfo) return "错误的请求！";
if($accinfo['username'] != "$_username") return "非法操作，你的操作已被记录！";
$gamels = $db->get_one("SELECT * FROM ".TABLE_GAMESERVER." WHERE id='$idserver1'");
@extract($gamels,EXTR_OVERWRITE);
$mysqlco = @mysql_connect($serverip.':'.$port,$loginname,$loginpass,$dataacc);
if(!$mysqlco) showmessage("连接转出分区失败，请检查服务器分区设置情况！");
$sqldb = new db_mysql;
$sqldb->connect($serverip.':'.$port,$loginname,$loginpass,$datafso);
$fsoinfo2 = $sqldb->get_one("SELECT * FROM user WHERE ID='$idfso1'");
$metier2 = getmetier($fsoinfo2['Metier']);
$faction2 = getfaction($fsoinfo2['Faction']);
include template($mod,'mfsosave');
break;
}
$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;
}
?>