109 lines
3.2 KiB
PHP
109 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace sammo\API\Nation;
|
|
|
|
use sammo\DB;
|
|
use sammo\Session;
|
|
use sammo\Validator;
|
|
|
|
use function sammo\checkLimit;
|
|
use function sammo\checkSecretPermission;
|
|
use function sammo\getBattleDetailLogMore;
|
|
use function sammo\getBattleResultMore;
|
|
use function sammo\getBattleResultRecent;
|
|
use function sammo\getGeneralActionLogMore;
|
|
use function sammo\getGeneralActionLogRecent;
|
|
use function sammo\getGeneralHistoryLogAll;
|
|
use function sammo\getNationStaticInfo;
|
|
|
|
class GetNationInfo extends \sammo\BaseAPI
|
|
{
|
|
public function validateArgs(): ?string
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function getRequiredSessionMode(): int
|
|
{
|
|
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
|
}
|
|
|
|
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
|
{
|
|
$userID = $session->userID;
|
|
|
|
$db = DB::db();
|
|
$nationID = $db->queryFirstField('SELECT nation FROM general WHERE `owner` = %i', $userID);
|
|
|
|
if(!$nationID){
|
|
return [
|
|
'result' => true,
|
|
'nation' => getNationStaticInfo(0)
|
|
];
|
|
}
|
|
|
|
|
|
|
|
$targetGeneralID = $this->getTargetGeneralID($session);
|
|
$reqType = $this->args['type'];
|
|
$reqTo = $this->args['reqTo'] ?? null;
|
|
|
|
|
|
$me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,permission,penalty from general where owner=%i', $userID);
|
|
|
|
$con = checkLimit($me['con']);
|
|
if ($con >= 2) {
|
|
return '접속 제한입니다.';
|
|
}
|
|
|
|
$permissionResult = $this->checkPermission($me);
|
|
if ($permissionResult !== null) {
|
|
return $permissionResult;
|
|
}
|
|
|
|
if ($reqType == static::GENERAL_HISTORY) {
|
|
return [
|
|
'result' => true,
|
|
'reqType' => $reqType,
|
|
'generalID' => $targetGeneralID,
|
|
'log' => getGeneralHistoryLogAll($targetGeneralID)
|
|
];
|
|
}
|
|
|
|
if ($reqType == static::GENERAL_ACTION) {
|
|
return [
|
|
'result' => true,
|
|
'reqType' => $reqType,
|
|
'generalID' => $targetGeneralID,
|
|
'log' => $reqTo === null
|
|
? getGeneralActionLogRecent($targetGeneralID, 30)
|
|
: getGeneralActionLogMore($targetGeneralID, $reqTo, 30)
|
|
];
|
|
}
|
|
|
|
if ($reqType == static::BATTLE_RESULT) {
|
|
return [
|
|
'result' => true,
|
|
'reqType' => $reqType,
|
|
'generalID' => $targetGeneralID,
|
|
'log' => $reqTo === null
|
|
? getBattleResultRecent($targetGeneralID, 30)
|
|
: getBattleResultMore($targetGeneralID, $reqTo, 30)
|
|
];
|
|
}
|
|
|
|
if ($reqType == static::BATTLE_DETAIL) {
|
|
return [
|
|
'result' => true,
|
|
'reqType' => $reqType,
|
|
'generalID' => $targetGeneralID,
|
|
'log' => $reqTo === null
|
|
? getBattleResultRecent($targetGeneralID, 30)
|
|
: getBattleDetailLogMore($targetGeneralID, $reqTo, 30)
|
|
];
|
|
}
|
|
|
|
return '잘못된 요청입니다: ' . $reqType;
|
|
}
|
|
}
|