86 lines
2.7 KiB
PHP
86 lines
2.7 KiB
PHP
<?php
|
|
|
|
class HangController{
|
|
|
|
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' => 'gamedb2001_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
public function GetHangReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$item_id = 0;
|
|
$num = 0;
|
|
$weight = $_REQUEST['weight'];
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
$ret = $conn->execScript('INSERT INTO hang(accountid, hang_time) ' .
|
|
' VALUES(:accountid, :hang_time);',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':hang_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
$ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':hang_time' => time(),
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$item_id = 1;
|
|
$num = time() - $row['hang_time'];
|
|
if ($weight != 0) {
|
|
$num = $num * 3;
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'num' => $num,
|
|
'time' => time()
|
|
));
|
|
}
|
|
|
|
public function GetTime()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'time' => time()
|
|
));
|
|
}
|
|
}
|
|
?>
|