game2006api/webapp/controller/GMController.class.php
2023-08-22 16:15:14 +08:00

212 lines
6.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once('mt/Item.php');
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
require_once('models/Nft.php');
use phpcommon\SqlHelper;
use models\Nft;
class GMController extends BaseAuthedController {
public function _handlePre()
{
parent::_handlePre();
if (SERVER_ENV == _ONLINE) {
die("can't create GMController");
return;
}
}
public function execCmd()
{
$cmds = explode(' ', getReqVal('cmd', ''));
if (count($cmds) < 0) {
$this->_rspErr(1, 'Please enter instructions');
return;
}
$cmd = $cmds[0];
$params = count($cmds) > 1 ? array_slice($cmds, 1) : array();
$cmdHash = array(
'.help' => function () use($params) {
$this->help($params);
},
'.additem' => function () use($params) {
$this->addItem($params);
},
'.addnft' => function () use($params) {
$this->addNft($params);
},
'.addtili' => function () use($params) {
$this->addTili($params);
},
'.getsystime' => function () use($params) {
$this->getSysTime($params);
},
'.setsystime' => function () use($params) {
$this->setSysTime($params);
},
'.reset_mission' => function () use($params) {
$this->resetMission($params);
},
'.addtest' => function () use($params) {
$this->addDyndata($params);
}
);
$func = getXVal($cmdHash, $cmd);
if ($func) {
$func($params);
} else {
$this->_rspErr(2, 'Unrecognized instruction');
return;
}
}
private function help($params)
{
$this->_rspData(array(
'text' => <<<END
.additem 道具id 道具数量 //添加道具
.addtili 英雄id 体力值 //添加英雄体力
.getsystime //获取服务器时间
.setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00
.reset_mission //重置任务
.addtest //添加测试数据 1击杀数 2星星数 3升段数
END
));
}
private function addItem($params)
{
$itemId = getXVal($params, 0, 0);
$itemNum = getXVal($params, 1, 0);
$propertyChgService = new services\PropertyChgService();
$awardService = new services\AwardService();
$this->_addItems(array(
array(
'item_id' => $itemId,
'item_num' => $itemNum
)
), $awardService, $propertyChgService);
$this->_rspData(array(
'text' => 'add item success',
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
private function addNft($params)
{
$itemId = getXVal($params, 0, 0);
$propertyChgService = new services\PropertyChgService();
$awardService = new services\AwardService();
$itemMeta = mt\Item::get($itemId);
if ($itemMeta) {
$tokenType = Nft::getTokenType($itemMeta);
if ($tokenType == Nft::NONE_TYPE) {
myself()->_rspErr(1, 'param item_id error');
return;
} else {
SqlHelper::insert(
myself()->_getMarketMysql(),
't_nft',
array(
'token_id' => Nft::genTempTokenId(),
'token_type' => $tokenType,
'game_id' => 2006,
'item_id' => $itemId,
'owner_address' => myself()->_getAddress(),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
} else {
myself()->_rspErr(1, 'param item_id error');
return;
}
$this->_rspData(array(
'text' => 'add nft success',
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
private function addTili($params)
{
$heroId = getXVal($params, 0, 0);
$tili = getXVal($params, 1, 0);
Hero::update($heroId, array(
'hero_tili' => "hero_tili + ${tili}"
));
$propertyChgService->addHeroChg();
$this->_rspData(array(
'text' => 'add item success',
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
private function getSysTime($params)
{
$sysTime = phpcommon\timestamp_to_datetime(phpcommon\getNowTime());
$this->_rspData(array(
'text' => $sysTime,
));
}
private function setSysTime($params)
{
if (!defined('GLOBAL_TIME_OFFSET_KEY')) {
die('不支持设置系统时间');
return;
}
$newtime = strtotime($_REQUEST['newtime']);
if ($newtime <= 0) {
die('时间格式错误');
return;
}
$time_offset = $newtime - phpcommon\getRealTime();
$r = new phpcommon\Redis(array(
'host' => '127.0.0.1',
'port' => 6379,
'passwd' => ''
));
$r->set(GLOBAL_TIME_OFFSET_KEY, $time_offset);
}
private function resetMission($params)
{
myself()->_getSelfMysql()->execScript('DELETE FROM t_mission;');
myself()->_getSelfMysql()->execScript('DELETE FROM t_bigdata;');
myself()->_rspOk();
}
private function addDyndata($params){
$type = getXVal($params, 0, 0);
$num = getXVal($params, 1, 0);
switch ($type){
case 1 : {
myself()->_incV(TN_TOTAL_KILLS_NUM,0,$num);
}
break;
case 2 : {
myself()->_incV(TN_TOTAL_STAR_NUM,0,$num);
}
break;
case 3 : {
myself()->_incV(TN_TOTAL_DIAMOND_CONSUME,0,$num);
}
break;
case 4 : {
myself()->_incV(TN_TOTAL_CEG_CONSUME,0,$num);
}
}
}
}