$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id'] )); return $conn; } protected function getAllMysql() { global $g_conf_mysql_cluster; $conns = array(); foreach ($g_conf_mysql_cluster as $mysql_conf) { $conn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id'] )); array_push($conns, $conn); } return $conns; } protected function getSeasonPoint($seaPoint_id) { $seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php'); $seaPoint_meta = getSeasonPointConfig($seaPoint_meta_table, $seaPoint_id); $seaPoint = array( 'id' => $seaPoint_meta['id'], 'min' => $seaPoint_meta['min_point'], 'max' => $seaPoint_meta['max_point'], 'des' => $seaPoint_meta['des'], ); return $seaPoint; } public function selectUserInfo() { $account_id = $_REQUEST['account_id']; $conns = $this->getAllMysql(); if (!$conns) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $flag = 0; $max_rank = 1; $rank = 1; $avatar_url = 18001; $vip_level = 0; foreach ($conns as $conn) { $row = $conn->execQueryOne('SELECT accountid, user_name, avatar_url, game_times, win_times, kill_his, kills, harm_his, harm, integral, modify_time, alive_time, add_HP, head_kuang_id, max_integral, sex FROM user WHERE accountid=:account_id;', array( ':account_id' => $account_id, )); if ($row) { $flag = 1; } $rowbags = $conn->execQuery('SELECT id, color_id FROM bag WHERE accountid=:account_id AND status=0;', array( ':account_id' => $account_id, )); if ($rowbags) { $flag = 1; } $rowequip = $conn->execQueryOne('SELECT using_id FROM equip WHERE accountid=:account_id;', array( ':account_id' => $account_id, )); $rowlv = $conn->execQueryOne('SELECT using_id, lv FROM equip WHERE accountid=:account_id AND id=:id;', array( ':account_id' => $account_id, ':id' => $rowequip['using_id'] )); if ($rowequip || $rowlv) { $flag = 1; } if ($flag == 1) { break; } $max_rank = 1; $rank = 1; $seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php'); for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) { $seaPoint = $this->getSeasonPoint($ii); if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max'] || $seaPoint['max'] == -1) { $rank = $ii; break; } if ($row['max_integral'] >= $seaPoint['min'] && $row['max_integral'] <= $seaPoint['max'] || $seaPoint['max'] == -1) { $max_rank = $ii; break; } } $addreward = new classes\Addreward(); $vip_level = $addreward->getVipLevel($account_id); $avatar_url = $row['avatar_url']; } if ($flag == 0) { phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在'); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'accountid' => $row['accountid'], 'user_name' => $row['user_name'], 'avatar_url' => $row['avatar_url'], 'game_times' => $row['game_times'], 'win_times' => $row['win_times'], 'kill_his' => $row['kill_his'], 'kills' => $row['kills'], 'harm_his' => $row['harm_his'], 'harm' => $row['harm'], 'level' => $rank, 'modify_time' => $row['modify_time'], 'alive_time' => $row['alive_time'], 'add_HP' => $row['add_HP'], 'head_kuang_id' => $row['head_kuang_id'], 'vip_level' => $vip_level, 'max_rank' => $max_rank, 'bags' => $rowbags, 'equip' => $rowlv, 'sex' => $row['sex'], )); } public function selectUser() { $account_id = $_REQUEST['account_id']; $conns = $this->getAllMysql(); if (!$conns) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $flag = 0; $name = ''; foreach ($conns as $conn) { $row = $conn->execQueryOne('SELECT user_name FROM user WHERE accountid=:account_id;', array( ':account_id' => $account_id, )); if ($row) { $flag = 1; $name = $row['user_name']; break; } } if ($flag == 0) { phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在'); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'name' => $name, )); } public function selectUserByName() { $account_id = $_REQUEST['account_id']; $conns = $this->getAllMysql(); if (!$conns) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $accountid = ''; $user_name = $_REQUEST['user_name']; foreach ($conns as $conn) { $row = $conn->execQueryOne('SELECT accountid FROM user WHERE user_name=:user_name;', array( ':user_name' => $user_name, )); $flag = 0; if (!$row) { $robot_meta_cluster = require('../res/robot@robot.php'); for ($i = 0; $i < count($robot_meta_cluster); $i++) { $robot_id = 10000 + $i; $robot_meta = getRobotConfig($robot_meta_cluster, $robot_id); if ($robot_meta['name'] == $user_name) { $flag = 1; $accountid = '6511_2005_robot' . $i; break; } } if ($flag != 0) { break; } } else { $flag = 1; $accountid = $row['accountid']; break; } } if ($flag == 0) { phpcommon\sendError(ERR_USER_BASE + 2, '玩家不存在'); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'fri_accountid' => $accountid, )); } public function createRoleInfo() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $user_name = $_REQUEST['user_name']; $avatar_url = $_REQUEST['avatar_url']; $sex = $_REQUEST['sex']; $this->updateRoleInfo($account_id, $user_name, $avatar_url, $sex); $item_id = metatable\getParameterByName('creator_hair_m'); if ($sex == 1) { $item_id = metatable\getParameterByName('creator_hair_f'); } if ($item_id != 0) { $ret = $conn->execScript('INSERT INTO bag(accountid, id, color_id, status, num, active_time, create_time, modify_time) ' . ' VALUES(:account_id, :id, 0, :status, :num, :active_time, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, color_id=0, status=:status, num=:num, active_time=:active_time, modify_time=:modify_time;', array( ':account_id' => $account_id, ':id' => $item_id, ':active_time' => 0, ':status' => 0, ':num' => 1, ':create_time' => phpcommon\getNowTime(), ':modify_time' => phpcommon\getNowTime() )); if(!$ret){ die(); } } $addreward = new classes\Addreward(); $addreward->addReward($avatar_url, 1, $account_id, 0, 0); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'user_name' => $user_name, 'avatar_url' => $avatar_url, 'create_user' => 1, 'sex' => $sex, )); } protected function updateRoleInfo($account_id, $user_name, $avatar_url, $sex) { $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $ret = $conn->execScript('UPDATE user SET user_name=:user_name, avatar_url=:avatar_url, modify_time=:modify_time, create_user=1, sex=:sex ' . ' WHERE accountid=:accountid;', array( ':user_name' => $user_name, ':avatar_url' => $avatar_url, ':modify_time' => phpcommon\getNowTime(), ':accountid' => $account_id, ':sex' => $sex, )); if (!$ret) { die(); return; } } public function changeRoleInfo() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $user_name = $_REQUEST['user_name']; $avatar_url = $_REQUEST['avatar_url']; $sex = $_REQUEST['sex']; $this->updateRoleInfo($account_id, $user_name, $avatar_url, $sex); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'user_name' => $user_name, 'avatar_url' => $avatar_url, 'create_user' => 1, 'sex' => $sex, )); } public function selRepeatName() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conns = $this->getAllMysql(); if (!$conns) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $user_name = $_REQUEST['user_name']; foreach ($conns as $conn) { $row = $conn->execQueryOne('SELECT accountid FROM user WHERE accountid!=:account_id AND user_name=:user_name;', array( ':account_id' => $account_id, ':user_name' => $user_name, )); if ($row) { phpcommon\sendError(ERR_USER_BASE + 2, '名字重名'); return; } } $robot_meta_cluster = require('../res/robot@robot.php'); for ($i = 0; $i < count($robot_meta_cluster); $i++) { $robot_id = 10000 + $i; $robot_meta = getRobotConfig($robot_meta_cluster, $robot_id); if ($robot_meta['name'] == $user_name) { phpcommon\sendError(ERR_USER_BASE + 2, '名字重名'); return; } } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } } ?>