159 lines
5.9 KiB
PHP
159 lines
5.9 KiB
PHP
<?php
|
|
|
|
class RoleController{
|
|
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => 'gamedb2003_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
public function roleInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$user_name = $_REQUEST['name'];
|
|
$avatar_url = $_REQUEST['avatar_url'];
|
|
//登录校验
|
|
$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;
|
|
}
|
|
if (empty($_REQUEST['account_id'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
$ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, coin_num, create_time, modify_time, collect_status, kefu_status, sign_sum, diamond_num, pass_status, pass, energy, buy_data, tank_data, cumul_coin, off_time) ' .
|
|
' VALUES(:accountid, :user_name, :avatar_url, 1000, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, :buy_data, :tank_data, 0, :off_time)',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':user_name' => $user_name,
|
|
':avatar_url' => $avatar_url,
|
|
':tank_data' => '',
|
|
':buy_data' => '',
|
|
':create_time' => time(),
|
|
':modify_time' => time(),
|
|
':off_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'coin_num' => 1000,
|
|
'collect_status' => 0,
|
|
'energy' => 0,
|
|
'kefu_status' => 0,
|
|
'diamond_num' => 0,
|
|
'pass_status' => 0,
|
|
'pass' => 0,
|
|
'buy_list' => '',
|
|
'tank_list' => '',
|
|
'cumul_coin' => 0
|
|
));
|
|
} else {
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'coin_num' => $row['coin_num'],
|
|
'collect_status' => $row['collect_status'],
|
|
'energy' => $row['energy'],
|
|
'kefu_status' => $row['kefu_status'],
|
|
'diamond_num' => $row['diamond_num'],
|
|
'pass_status' => $row['pass_status'],
|
|
'pass' => $row['pass'],
|
|
'buy_list' => $row['buy_data'],
|
|
'tank_list' => $row['tank_data'],
|
|
'cumul_coin' => $row['cumul_coin'],
|
|
));
|
|
}
|
|
}
|
|
|
|
public function getOfflineTime()
|
|
{
|
|
$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;
|
|
}
|
|
if (empty($_REQUEST['account_id'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT off_time FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
error_log(time() - $row['off_time']);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'time' => time() - $row['off_time'],
|
|
));
|
|
}
|
|
|
|
public function getDiamondNum()
|
|
{
|
|
$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;
|
|
}
|
|
if (empty($_REQUEST['account_id'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'diamond_num' => $row['diamond_num'],
|
|
));
|
|
}
|
|
}
|
|
?>
|