feat: GeneralList를 API로 이동
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\List\Nation;
|
||||
|
||||
use sammo\DB;
|
||||
use sammo\General;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
use sammo\RootDB;
|
||||
use sammo\Session;
|
||||
use sammo\Util;
|
||||
use sammo\Validator;
|
||||
|
||||
use function sammo\calcLeadershipBonus;
|
||||
use function sammo\checkLimit;
|
||||
use function sammo\checkSecretPermission;
|
||||
use function sammo\getDed;
|
||||
use function sammo\getDedLevelText;
|
||||
use function sammo\getExpLevel;
|
||||
use function sammo\getGenChar;
|
||||
use function sammo\getGeneralSpecialDomesticName;
|
||||
use function sammo\getGeneralSpecialWarName;
|
||||
use function sammo\getHonor;
|
||||
use function sammo\getNationStaticInfo;
|
||||
use function sammo\getOfficerLevelText;
|
||||
use function sammo\increaseRefresh;
|
||||
|
||||
class GeneralList extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v
|
||||
->rule('boolean', 'with_token');
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return static::REQ_LOGIN;
|
||||
}
|
||||
|
||||
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
$db = DB::db();
|
||||
$withToken = $this->args['with_token']??false;
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
$userID = $session->userID;
|
||||
if ($session->isGameLoggedIn()) {
|
||||
increaseRefresh("장수일람", 2);
|
||||
$me = $db->queryFirstRow('SELECT con, turntime FROM general WHERE owner=%i', $userID);
|
||||
$con = checkLimit($me['con']);
|
||||
if ($con >= 2) {
|
||||
return '접속 제한중입니다. 1턴 이내에 너무 많은 갱신을 하셨습니다.';
|
||||
}
|
||||
} else {
|
||||
$availableNextCall = $session->availableNextCallGetGeneralList ?? '2000-01-01 00:00:00';
|
||||
$now = new \DateTimeImmutable();
|
||||
|
||||
if ($now <= new \DateTimeImmutable($availableNextCall) && $session->userGrade < 5) {
|
||||
return "장수 리스트는 10초에 한번 갱신 가능합니다.\n다음 시간 : " . $availableNextCall;
|
||||
}
|
||||
|
||||
$availableNextCall = $now->add(new \DateInterval('PT10S'))->format('Y-m-d H:i:s');
|
||||
$session->availableNextCallGetGeneralList = $availableNextCall;
|
||||
}
|
||||
|
||||
$session->setReadOnly();
|
||||
|
||||
|
||||
$rawGeneralList = $db->queryAllLists('SELECT owner,no,picture,imgsvr,npc,age,nation,special,special2,personal,name,owner_name as ownerName,injury,leadership,strength,intel,experience,dedication,officer_level,killturn,connect from general');
|
||||
|
||||
$ownerNameList = [];
|
||||
if ($gameStor->isunited) {
|
||||
foreach (RootDB::db()->queryAllLists('SELECT no, name FROM member') as [$ownerID, $ownerName]) {
|
||||
$ownerNameList[$ownerID] = $ownerName;
|
||||
}
|
||||
}
|
||||
|
||||
$generalList = [];
|
||||
foreach ($rawGeneralList as $rawGeneral) {
|
||||
[$owner, $no, $picture, $imgsvr, $npc, $age, $nation, $special, $special2, $personal, $name, $ownerName, $injury, $leadership, $strength, $intel, $experience, $dedication, $officerLevel, $killturn, $connectCnt] = $rawGeneral;
|
||||
|
||||
if (key_exists($owner, $ownerNameList)) {
|
||||
$ownerName = $ownerNameList[$owner];
|
||||
}
|
||||
|
||||
$nationArr = getNationStaticInfo($nation);
|
||||
$lbonus = calcLeadershipBonus($officerLevel, $nationArr['level']);
|
||||
|
||||
$generalList[] = [
|
||||
$no,
|
||||
$picture,
|
||||
$imgsvr,
|
||||
$npc,
|
||||
$age,
|
||||
$nationArr['name'],
|
||||
getGeneralSpecialDomesticName($special),
|
||||
getGeneralSpecialWarName($special2),
|
||||
getGenChar($personal),
|
||||
$name,
|
||||
$npc == 1 ? $ownerName : null,
|
||||
$injury,
|
||||
$leadership,
|
||||
$lbonus,
|
||||
$strength,
|
||||
$intel,
|
||||
getExpLevel($experience),
|
||||
getHonor($experience),
|
||||
getDed($dedication),
|
||||
getOfficerLevelText($officerLevel, $nationArr['level']),
|
||||
$killturn,
|
||||
$connectCnt
|
||||
];
|
||||
}
|
||||
|
||||
$resultColumns = [
|
||||
'no',
|
||||
'picture',
|
||||
'imgsvr',
|
||||
'npc',
|
||||
'age',
|
||||
'nationName',
|
||||
'special',
|
||||
'special2',
|
||||
'personal',
|
||||
'name',
|
||||
'ownerName',
|
||||
'injury',
|
||||
'leadership',
|
||||
'lbonus',
|
||||
'strength',
|
||||
'intel',
|
||||
'explevel',
|
||||
'honorText',
|
||||
'dedLevelText',
|
||||
'officerLevelText',
|
||||
];
|
||||
|
||||
$result = [
|
||||
'result' => 'true',
|
||||
'column' => $resultColumns,
|
||||
'list' => $generalList,
|
||||
];
|
||||
|
||||
|
||||
if ($withToken) {
|
||||
$now = (new \DateTimeImmutable())->format('Y-m-d H:i:s');
|
||||
$tokens = [];
|
||||
foreach ($db->query('SELECT * FROM select_npc_token WHERE `valid_until`>=%s', $now) as $token) {
|
||||
$validUntil = $token['valid_until'];
|
||||
|
||||
foreach (Json::decode($token['pick_result']) as $pickResult) {
|
||||
$tokens[$pickResult['no']] = $pickResult['keepCnt'];
|
||||
}
|
||||
}
|
||||
$result['token'] = $tokens;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\List;
|
||||
namespace sammo\API\List\Nation;
|
||||
|
||||
use sammo\ActionLogger;
|
||||
use sammo\CityConst;
|
||||
use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\GameUnitConst;
|
||||
use sammo\General;
|
||||
use sammo\JosaUtil;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
use sammo\RootDB;
|
||||
use sammo\Session;
|
||||
use sammo\SpecialityHelper;
|
||||
use sammo\StringUtil;
|
||||
use sammo\TimeUtil;
|
||||
use sammo\UserLogger;
|
||||
use sammo\Util;
|
||||
use sammo\Validator;
|
||||
use sammo\WebUtil;
|
||||
|
||||
use function sammo\addTurn;
|
||||
use function sammo\calcLeadershipBonus;
|
||||
use function sammo\checkLimit;
|
||||
use function sammo\checkSecretPermission;
|
||||
use function sammo\cutTurn;
|
||||
use function sammo\getDedLevelText;
|
||||
use function sammo\getGenChar;
|
||||
use function sammo\getGeneralSpecialDomesticName;
|
||||
@@ -33,12 +18,9 @@ use function sammo\getGeneralSpecialWarName;
|
||||
use function sammo\getHonor;
|
||||
use function sammo\getNationStaticInfo;
|
||||
use function sammo\getOfficerLevelText;
|
||||
use function sammo\getRandTurn;
|
||||
use function sammo\increaseRefresh;
|
||||
use function sammo\pushAdminLog;
|
||||
use function sammo\resetInheritanceUser;
|
||||
|
||||
class NationGeneral extends \sammo\BaseAPI
|
||||
class GeneralList extends \sammo\BaseAPI
|
||||
{
|
||||
|
||||
private int $reqType;
|
||||
Reference in New Issue
Block a user