<?php

require './include/common.inc.php';
sajax_init();
sajax_export("checkserv","doSub");
sajax_handle_client_request();
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
$infos = $db->get_one("SELECT area FROM ".TABLE_MEMBER_INFO." WHERE userid='$_userid'");
if(!$infos['area']) showmessage("请选激活游戏分区再进行此操作！","/game/actgame.php");
$servers = array();
$rs = $db->query("SELECT * FROM ".TABLE_GAMESERVER." WHERE id IN ($infos[area]) ORDER BY id");
while($r = $db->fetch_array($rs))
{
$servers[] = $r;
}
function checkserv($id)
{
global $db,$_userid,$_username;
if(!$id) return "<span class=font06>请选择分区</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT password FROM user WHERE username='$_username'");
if(!$info) return "<span class=font06>您没有激活该分区</span>";
return "true";
}
function doSub($id,$opwd,$npwd,$rpwd)
{
global $db,$_username;
if($id == '') return "<span class=font06>请选择游戏分区</span>";
if($opwd == '') return "<span class=font06>原密码不能为空</span>";
if($npwd == '') return "<span class=font06>新密码不能为空</span>";
if(strlen($npwd) <5 ||strlen($npwd) >20) return "<span class=font06>新密码长度为5-20位</span>";
if($rpwd == '') return "<span class=font06>确认密码不能为空</span>";
if($opwd == $npwd) return "<span class=font06>原密码不能与新密码一致</span>";
if($npwd != $rpwd) return "<span class=font06>确认密码与新密码不一致</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT password FROM user WHERE username='$_username'");
if(!$info) return "<span class=font06>您没有激活该分区</span>";
$opwd = hsmd5($opwd);
if($opwd != $info['password']) return "<span class=font06>原密码输入错误</span>";
$npwd = hsmd5($npwd);
$sqldb->query("UPDATE user SET password='$npwd' WHERE username='$_username'");
if($sqldb->affected_rows())
{
return "true";
}else{
return "错误类型：UPDATE ERROR!，请与管理员连系！";
}
}
$head['title'] = "修改游戏密码";
include template('game','gpass');
?>