279 lines
12 KiB
PHP
279 lines
12 KiB
PHP
<?php
|
|
|
|
class TankController{
|
|
|
|
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;
|
|
}
|
|
|
|
protected function getTank($tank_id)
|
|
{
|
|
$tank_meta_table = require('../res/tank_economy@tank_economy.php');
|
|
$tank_meta = getTankConfig($tank_meta_table, $tank_id);
|
|
$t = array(
|
|
'id' => $tank_meta['tank_id'],
|
|
'level' => $tank_meta['level'],
|
|
'coin_origin' => $tank_meta['coin_origin'],
|
|
'coin_times' => $tank_meta['coin_times'],
|
|
'coin_sell' => $tank_meta['coin_sell'],
|
|
'diamond' => $tank_meta['diamond'],
|
|
'coin_produce' => $tank_meta['coin_produce'],
|
|
'coin_lv' => $tank_meta['coin_lv'],
|
|
'diamond_lv' => $tank_meta['diamond_lv'],
|
|
'drop_level' => $tank_meta['drop_level'],
|
|
'drop_number' => $tank_meta['drop_number'],
|
|
'ad_level' => $tank_meta['ad_level'],
|
|
'buy_range1' => $tank_meta['buy_range1'],
|
|
'buy_times1' => $tank_meta['buy_times1'],
|
|
'free_lv1' => $tank_meta['free_lv1'],
|
|
'buy_range2' => $tank_meta['buy_range2'],
|
|
'buy_times2' => $tank_meta['buy_times2'],
|
|
'free_lv2' => $tank_meta['free_lv2'],
|
|
);
|
|
return $t;
|
|
}
|
|
|
|
public function sendInfo()
|
|
{
|
|
$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;
|
|
}
|
|
$tankInfo = json_decode(file_get_contents('php://input'), true);
|
|
//error_log(file_get_contents('php://input'));
|
|
//error_log(json_encode($tankInfo));
|
|
if (isset($tankInfo['tank_list'])) {
|
|
$tank_data = $tankInfo['tank_list'];
|
|
$ret = $conn->execScript('UPDATE user SET tank_data=:tank_data, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':tank_data' => json_encode($tank_data),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['coin_num'])) {
|
|
$coin_num = $tankInfo['coin_num'];
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':coin_num' => $coin_num,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['buy_list'])) {
|
|
$buy_data = $tankInfo['buy_list'];
|
|
$ret = $conn->execScript('UPDATE user SET buy_data=:buy_data, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':buy_data' => json_encode($buy_data),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['pass'])) {
|
|
$pass = $tankInfo['pass'];
|
|
$ret = $conn->execScript('UPDATE user SET pass=:pass, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':pass' => $pass,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['energy'])) {
|
|
$energy = $tankInfo['energy'];
|
|
$ret = $conn->execScript('UPDATE user SET energy=:energy, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':energy' => $energy,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['diamond_num'])) {
|
|
$diamond_num = $tankInfo['diamond_num'];
|
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':diamond_num' => $diamond_num,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['cumul_coin'])) {
|
|
$cumul_coin = $tankInfo['cumul_coin'];
|
|
$ret = $conn->execScript('UPDATE user SET cumul_coin=:cumul_coin, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':cumul_coin' => $cumul_coin,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET off_time=:off_time, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':off_time' => time(),
|
|
':modify_time' => time(),
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
if (isset($tankInfo['battlecount'])) {
|
|
$battlecount = $tankInfo['battlecount'];
|
|
$ret = $conn->execScript('UPDATE user SET battlecount=:battlecount, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':battlecount' => $battlecount,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['invite_status'])) {
|
|
$invite_status = $tankInfo['invite_status'];
|
|
$ret = $conn->execScript('UPDATE user SET invite_status=:invite_status, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':invite_status' => $invite_status,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['life_times'])) {
|
|
$life_times = $tankInfo['life_times'];
|
|
$ret = $conn->execScript('UPDATE user SET life_times=:life_times, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':life_times' => $life_times,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['new_info'])) {
|
|
$new_info = $tankInfo['new_info'];
|
|
$ret = $conn->execScript('UPDATE user SET new_info=:new_info, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':new_info' => json_encode($new_info),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if (isset($tankInfo['daily_buy_times'])) {
|
|
$daily_buy_times = $tankInfo['daily_buy_times'];
|
|
$ret = $conn->execScript('UPDATE user SET daily_buy_times=:daily_buy_times, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':daily_buy_times' => $daily_buy_times,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (isset($tankInfo['pass_reward'])) {
|
|
$pass_reward = $tankInfo['pass_reward'];
|
|
$ret = $conn->execScript('UPDATE user SET pass_reward=:pass_reward, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':pass_reward' => json_encode($pass_reward),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (isset($tankInfo['demotank'])) {
|
|
$demotank = $tankInfo['demotank'];
|
|
$ret = $conn->execScript('UPDATE user SET demotank=:demotank, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':demotank' => $demotank,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
|
|
}
|
|
}
|
|
?>
|