175 lines
6.3 KiB
PHP
175 lines
6.3 KiB
PHP
<?php
|
|
|
|
class AdditemController{
|
|
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' => 'gamedb2004_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getItem($item_id)
|
|
{
|
|
$g_conf_item_cluster = require('../res/item@item.php');
|
|
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
|
|
$it = array(
|
|
'id' => $item_conf['id'],
|
|
'diamond' => $item_conf['diamond'],
|
|
'type' => $item_conf['fuction'],
|
|
'diamond_hour' => $item_conf['diamond_hour']
|
|
);
|
|
return $it;
|
|
}
|
|
|
|
protected function getBag($bag_id)
|
|
{
|
|
$g_conf_bag_cluster = require('../res/bag@bag.php');
|
|
$bag_conf = getBagConfig($g_conf_bag_cluster, $bag_id);
|
|
$b = array(
|
|
'id' => $bag_conf['id'],
|
|
'name' => $bag_conf['name'],
|
|
'fuction' => $bag_conf['fuction'],
|
|
);
|
|
return $b;
|
|
}
|
|
|
|
protected function getExplode($string)
|
|
{
|
|
$delim = "|";
|
|
$drop_multiply = explode($delim, $string);
|
|
$delim1 = ":";
|
|
$arr = array();
|
|
for ($i = 0; $i < count($drop_multiply); $i++) {
|
|
$mul = explode($delim1, $drop_multiply[$i]);
|
|
array_push($arr, $mul);
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
public function additem()
|
|
{
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_num = $_REQUEST['item_num'];
|
|
$accountid = $_REQUEST['account_id'];
|
|
$time = $_REQUEST['time'];
|
|
if (phpcommon\getIPv4() != '116.228.166.182') {
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
return;
|
|
}
|
|
$it = $this->getItem($item_id);
|
|
if (!$it) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
|
|
die();
|
|
return;
|
|
}
|
|
|
|
$row = $conn->execQueryOne('SELECT * FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
'id' => $item_id
|
|
));
|
|
$status = 1;
|
|
$active_time = 0;
|
|
if ($item_id != 0){
|
|
if ($it['type'] == 10 || $it['type'] == 11) {
|
|
$item_num = $row['num'] + $item_num;
|
|
} else {
|
|
$item_num = 1;
|
|
}
|
|
$ret = $conn->execScript('INSERT INTO bag(accountid, id, color_id, status, active_time, create_time, modify_time, num) ' .
|
|
' VALUES(:account_id, :id, 0, :status, :active_time, :create_time, :modify_time, :num) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, color_id=0, status=:status, active_time=:active_time, modify_time=:modify_time, num=:num;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $item_id,
|
|
':active_time' => $active_time,
|
|
':status' => $status,
|
|
':create_time' => time(),
|
|
':modify_time' => time(),
|
|
':num' => $item_num
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//添加钻石
|
|
public function addDiamond()
|
|
{
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_num = $_REQUEST['item_num'];
|
|
$accountid = $_REQUEST['account_id'];
|
|
$time = $_REQUEST['time'];
|
|
if (phpcommon\getIPv4() != '116.228.166.182') {
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
));
|
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':diamond_num' => $item_num + $row['diamond_num'],
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
//添加金币
|
|
public function addCoin()
|
|
{
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_num = $_REQUEST['item_num'];
|
|
$accountid = $_REQUEST['account_id'];
|
|
$time = $_REQUEST['time'];
|
|
if (phpcommon\getIPv4() != '116.228.166.182') {
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
));
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':coin_num' => $item_num + $row['coin_num'],
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|