refac: General/GetFrontInfo 정보 추가
- Global/GetRecentRecord 항목 포함
This commit is contained in:
@@ -32,12 +32,14 @@ use function sammo\getDed;
|
|||||||
use function sammo\getHonor;
|
use function sammo\getHonor;
|
||||||
use function sammo\getNationStaticInfo;
|
use function sammo\getNationStaticInfo;
|
||||||
use function sammo\getOfficerLevelText;
|
use function sammo\getOfficerLevelText;
|
||||||
|
use function sammo\increaseRefresh;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 통째로 메인페이지의 주요 정보를 반환하는 날로먹는 API
|
* 통째로 메인페이지의 주요 정보를 반환하는 날로먹는 API
|
||||||
*/
|
*/
|
||||||
class GetFrontInfo extends \sammo\BaseAPI
|
class GetFrontInfo extends \sammo\BaseAPI
|
||||||
{
|
{
|
||||||
|
const ROW_LIMIT = 15;
|
||||||
|
|
||||||
public function getRequiredSessionMode(): int
|
public function getRequiredSessionMode(): int
|
||||||
{
|
{
|
||||||
@@ -47,13 +49,110 @@ class GetFrontInfo extends \sammo\BaseAPI
|
|||||||
public function validateArgs(): ?string
|
public function validateArgs(): ?string
|
||||||
{
|
{
|
||||||
$v = new Validator($this->args);
|
$v = new Validator($this->args);
|
||||||
$v->rule('lengthMin', 'lastNationNoticeDate', 19);
|
$v->rule('lengthMin', 'lastNationNoticeDate', 19)
|
||||||
|
->rule('integer', 'lastGeneralRecordID')
|
||||||
|
->rule('integer', 'lastWorldHistoryID');
|
||||||
if (!$v->validate()) {
|
if (!$v->validate()) {
|
||||||
return $v->errorStr();
|
return $v->errorStr();
|
||||||
}
|
}
|
||||||
|
$this->args['lastGeneralRecordID'] = (int)($this->args['lastGeneralRecordID'] ?? 0);
|
||||||
|
$this->args['lastWorldHistoryID'] = (int)($this->args['lastWorldHistoryID'] ?? 0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getGlobalRecord(int $lastRecordID): array
|
||||||
|
{
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$globalRecord = $db->queryAllLists(
|
||||||
|
'SELECT id, `text` FROM general_record WHERE `general_id` = 0 AND log_type = %s AND id >= %i ORDER BY `id` DESC LIMIT %i',
|
||||||
|
'history',
|
||||||
|
$lastRecordID,
|
||||||
|
static::ROW_LIMIT + 1,
|
||||||
|
);
|
||||||
|
return $globalRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getGeneralRecord(int $generalID, int $lastRecordID): array
|
||||||
|
{
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$generalRecord = $db->queryAllLists(
|
||||||
|
'SELECT id, `text` FROM general_record WHERE `general_id` = %i AND log_type = %s AND id >= %i ORDER BY `id` DESC LIMIT %i',
|
||||||
|
$generalID,
|
||||||
|
'action',
|
||||||
|
$lastRecordID,
|
||||||
|
static::ROW_LIMIT + 1,
|
||||||
|
);
|
||||||
|
return $generalRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getHistory(int $lastHistoryID): array
|
||||||
|
{
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$history = $db->queryAllLists(
|
||||||
|
'SELECT id, `text` FROM world_history WHERE nation_id = 0 AND id >= %i ORDER BY `id` DESC LIMIT %i',
|
||||||
|
$lastHistoryID,
|
||||||
|
static::ROW_LIMIT + 1,
|
||||||
|
);
|
||||||
|
return $history;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateRecentRecord(int $generalID){
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
|
$gameStor->cacheValues(['isunited', 'opentime', 'refresh']);
|
||||||
|
|
||||||
|
$lastHistoryID = $this->args['lastWorldHistoryID'];
|
||||||
|
$lastRecordID = $this->args['lastGeneralRecordID'];
|
||||||
|
|
||||||
|
$history = $this->getHistory($lastHistoryID);
|
||||||
|
$globalRecord = $this->getGlobalRecord($lastRecordID);
|
||||||
|
$generalRecord = $this->getGeneralRecord($generalID, $lastRecordID);
|
||||||
|
|
||||||
|
$flushHistory = false;
|
||||||
|
$flushGlobalRecord = false;
|
||||||
|
$flushGeneralRecord = false;
|
||||||
|
|
||||||
|
if (!$history) {
|
||||||
|
$flushHistory = false;
|
||||||
|
} else if (Util::array_last($history)[0] <= $lastHistoryID) {
|
||||||
|
$flushHistory = false;
|
||||||
|
array_pop($history);
|
||||||
|
} else if (count($history) > static::ROW_LIMIT) {
|
||||||
|
array_pop($history);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$globalRecord) {
|
||||||
|
$flushGlobalRecord = false;
|
||||||
|
} else if (Util::array_last($globalRecord)[0] == $lastRecordID) {
|
||||||
|
$flushGlobalRecord = false;
|
||||||
|
array_pop($globalRecord);
|
||||||
|
} else if (count($globalRecord) > static::ROW_LIMIT) {
|
||||||
|
array_pop($globalRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$generalRecord) {
|
||||||
|
$flushGeneralRecord = false;
|
||||||
|
} else if (Util::array_last($generalRecord)[0] == $lastRecordID) {
|
||||||
|
$flushGeneralRecord = false;
|
||||||
|
array_pop($generalRecord);
|
||||||
|
} else if (count($generalRecord) > static::ROW_LIMIT) {
|
||||||
|
array_pop($generalRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'history' => $history,
|
||||||
|
'global' => $globalRecord,
|
||||||
|
'general' => $generalRecord,
|
||||||
|
'flushHistory' => $flushHistory ? 1 : 0,
|
||||||
|
'flushGlobal' => $flushGlobalRecord ? 1 : 0,
|
||||||
|
'flushGeneral' => $flushGeneralRecord ? 1 : 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
private function generateGlobalInfo(MeekroDB $db): array
|
private function generateGlobalInfo(MeekroDB $db): array
|
||||||
{
|
{
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
@@ -442,6 +541,8 @@ class GetFrontInfo extends \sammo\BaseAPI
|
|||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
$gameStor->cacheAll(true);
|
$gameStor->cacheAll(true);
|
||||||
|
|
||||||
|
increaseRefresh("General/GetFrontInfo", 1);
|
||||||
|
|
||||||
$rawCity = $db->queryFirstRow('SELECT * FROM city WHERE city = %i', $cityID);
|
$rawCity = $db->queryFirstRow('SELECT * FROM city WHERE city = %i', $cityID);
|
||||||
$general->setRawCity($rawCity);
|
$general->setRawCity($rawCity);
|
||||||
|
|
||||||
@@ -463,6 +564,7 @@ class GetFrontInfo extends \sammo\BaseAPI
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'result' => true,
|
'result' => true,
|
||||||
|
'recentRecord' => $this->generateRecentRecord($generalID),
|
||||||
'global' => $globalInfo,
|
'global' => $globalInfo,
|
||||||
'nation' => $nationInfo,
|
'nation' => $nationInfo,
|
||||||
'general' => $generalInfo,
|
'general' => $generalInfo,
|
||||||
|
|||||||
+39
-60
@@ -306,65 +306,6 @@ void Promise.all([storeP, tryRefresh()]).then(() => {
|
|||||||
asyncReady.value = true;
|
asyncReady.value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
const lastGeneralRecordID = ref(0);
|
|
||||||
const lastWorldHistoryID = ref(0);
|
|
||||||
|
|
||||||
const generalRecords = ref(new Denque<[number, string]>());
|
|
||||||
const globalRecords = ref(new Denque<[number, string]>());
|
|
||||||
const worldHistory = ref(new Denque<[number, string]>());
|
|
||||||
|
|
||||||
let recordLock = false;
|
|
||||||
|
|
||||||
watch(refreshCounter, async () => {
|
|
||||||
if (recordLock) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
recordLock = true;
|
|
||||||
|
|
||||||
|
|
||||||
const response = await SammoAPI.Global.GetRecentRecord({
|
|
||||||
lastGeneralRecordID: lastGeneralRecordID.value,
|
|
||||||
lastWorldHistoryID: lastWorldHistoryID.value,
|
|
||||||
});
|
|
||||||
recordLock = false;
|
|
||||||
|
|
||||||
|
|
||||||
const recordIter = [
|
|
||||||
['flushGeneral', generalRecords, 'general'],
|
|
||||||
['flushGlobal', globalRecords, 'global'],
|
|
||||||
['flushHistory', worldHistory, 'history'],
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
for(const [flushKey, recordRef, recordKey] of recordIter) {
|
|
||||||
if (response[flushKey]) {
|
|
||||||
recordRef.value = new Denque<[number, string]>();
|
|
||||||
}
|
|
||||||
if (response[recordKey].length) {
|
|
||||||
lastGeneralRecordID.value = Math.max(lastGeneralRecordID.value, response[recordKey][0][0]);
|
|
||||||
}
|
|
||||||
const subRecord = response[recordKey];
|
|
||||||
while(subRecord.length){
|
|
||||||
const [id, record] = unwrap(subRecord.pop());
|
|
||||||
if(!recordRef.value.isEmpty() && id <= unwrap(recordRef.value.get(0))[0]){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(recordRef.value.length >= 15){
|
|
||||||
recordRef.value.pop();
|
|
||||||
}
|
|
||||||
recordRef.value.unshift([id, formatLog(record)]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
recordLock = false;
|
|
||||||
console.error(e);
|
|
||||||
toasts.danger({
|
|
||||||
title: "최근 기록 갱신 실패",
|
|
||||||
body: `${e}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const globalMenu = ref<GetMenuResponse["menu"]>();
|
const globalMenu = ref<GetMenuResponse["menu"]>();
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -387,6 +328,14 @@ const generalInfo = ref<GetFrontInfoResponse["general"]>();
|
|||||||
const nationStaticInfo = ref<NationStaticItem>();
|
const nationStaticInfo = ref<NationStaticItem>();
|
||||||
const nationInfo = ref<GetFrontInfoResponse["nation"]>();
|
const nationInfo = ref<GetFrontInfoResponse["nation"]>();
|
||||||
|
|
||||||
|
const lastGeneralRecordID = ref(0);
|
||||||
|
const lastWorldHistoryID = ref(0);
|
||||||
|
|
||||||
|
const generalRecords = ref(new Denque<[number, string]>());
|
||||||
|
const globalRecords = ref(new Denque<[number, string]>());
|
||||||
|
const worldHistory = ref(new Denque<[number, string]>());
|
||||||
|
|
||||||
|
|
||||||
let generalInfoLock = false;
|
let generalInfoLock = false;
|
||||||
|
|
||||||
watch(refreshCounter, async () => {
|
watch(refreshCounter, async () => {
|
||||||
@@ -395,7 +344,10 @@ watch(refreshCounter, async () => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
generalInfoLock = true;
|
generalInfoLock = true;
|
||||||
const response = await SammoAPI.General.GetFrontInfo();
|
const response = await SammoAPI.General.GetFrontInfo({
|
||||||
|
lastGeneralRecordID: lastGeneralRecordID.value,
|
||||||
|
lastWorldHistoryID: lastWorldHistoryID.value,
|
||||||
|
});
|
||||||
generalInfoLock = false;
|
generalInfoLock = false;
|
||||||
|
|
||||||
frontInfo.value = response;
|
frontInfo.value = response;
|
||||||
@@ -419,6 +371,33 @@ watch(refreshCounter, async () => {
|
|||||||
gennum: rawNation.gennum,
|
gennum: rawNation.gennum,
|
||||||
power: rawNation.power,
|
power: rawNation.power,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const recentRecord = response.recentRecord;
|
||||||
|
const recordIter = [
|
||||||
|
['flushGeneral', generalRecords, 'general'],
|
||||||
|
['flushGlobal', globalRecords, 'global'],
|
||||||
|
['flushHistory', worldHistory, 'history'],
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
for(const [flushKey, recordRef, recordKey] of recordIter) {
|
||||||
|
if (recentRecord[flushKey]) {
|
||||||
|
recordRef.value = new Denque<[number, string]>();
|
||||||
|
}
|
||||||
|
if (recentRecord[recordKey].length) {
|
||||||
|
lastGeneralRecordID.value = Math.max(lastGeneralRecordID.value, recentRecord[recordKey][0][0]);
|
||||||
|
}
|
||||||
|
const subRecord = recentRecord[recordKey];
|
||||||
|
while(subRecord.length){
|
||||||
|
const [id, record] = unwrap(subRecord.pop());
|
||||||
|
if(!recordRef.value.isEmpty() && id <= unwrap(recordRef.value.get(0))[0]){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(recordRef.value.length >= 15){
|
||||||
|
recordRef.value.pop();
|
||||||
|
}
|
||||||
|
recordRef.value.unshift([id, formatLog(record)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
generalInfoLock = false;
|
generalInfoLock = false;
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
+5
-1
@@ -133,7 +133,11 @@ const apiRealPath = {
|
|||||||
DieOnPrestart: POST as APICallT<undefined>,
|
DieOnPrestart: POST as APICallT<undefined>,
|
||||||
BuildNationCandidate: POST as APICallT<undefined>,
|
BuildNationCandidate: POST as APICallT<undefined>,
|
||||||
GetCommandTable: GET as APICallT<undefined, CommandTableResponse>,
|
GetCommandTable: GET as APICallT<undefined, CommandTableResponse>,
|
||||||
GetFrontInfo: GET as APICallT<undefined, GetFrontInfoResponse>,
|
GetFrontInfo: GET as APICallT<{
|
||||||
|
lastNationNoticeDate?: string,
|
||||||
|
lastGeneralRecordID?: number,
|
||||||
|
lastWorldHistoryID?: number,
|
||||||
|
}, GetFrontInfoResponse>,
|
||||||
},
|
},
|
||||||
Global: {
|
Global: {
|
||||||
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ export type AutorunUserMode = "develop" | "warp" | "recruit" | "recruit_high" |
|
|||||||
|
|
||||||
export type GetFrontInfoResponse = {
|
export type GetFrontInfoResponse = {
|
||||||
result: true;
|
result: true;
|
||||||
|
recentRecord: Omit<GetRecentRecordResponse, "result">;
|
||||||
global: {
|
global: {
|
||||||
scenarioText: string;
|
scenarioText: string;
|
||||||
extendedGeneral: 1 | 0;
|
extendedGeneral: 1 | 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user