fix: 비동기 대응 로직 추가
This commit is contained in:
+16
-14
@@ -72,7 +72,6 @@
|
|||||||
declare const staticValues: {
|
declare const staticValues: {
|
||||||
serverName: string;
|
serverName: string;
|
||||||
serverNick: string;
|
serverNick: string;
|
||||||
serverCnt: number;
|
|
||||||
serverID: string;
|
serverID: string;
|
||||||
mapName: string;
|
mapName: string;
|
||||||
unitSet: string;
|
unitSet: string;
|
||||||
@@ -91,7 +90,7 @@ import { formatLog } from "@/utilGame/formatLog";
|
|||||||
import type { ExecuteResponse } from "./defs/API/Global";
|
import type { ExecuteResponse } from "./defs/API/Global";
|
||||||
import { delay } from "./util/delay";
|
import { delay } from "./util/delay";
|
||||||
|
|
||||||
const { serverName, serverNick, serverCnt, serverID } = staticValues;
|
const { serverName, serverNick, serverID } = staticValues;
|
||||||
|
|
||||||
const asyncReady = ref(false);
|
const asyncReady = ref(false);
|
||||||
const gameConstStore = ref<GameConstStore>();
|
const gameConstStore = ref<GameConstStore>();
|
||||||
@@ -108,21 +107,15 @@ const storeP = getGameConstStore().then((store) => {
|
|||||||
gameConstStore.value = store;
|
gameConstStore.value = store;
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseP = ref<
|
let responseLock = false;
|
||||||
Promise<
|
|
||||||
| ExecuteResponse
|
|
||||||
| (InvalidResponse & {
|
|
||||||
reqRefresh?: boolean;
|
|
||||||
})
|
|
||||||
>
|
|
||||||
>();
|
|
||||||
|
|
||||||
async function tryRefresh() {
|
async function tryRefresh() {
|
||||||
if (responseP.value !== undefined) {
|
if (responseLock) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
responseP.value = SammoAPI.Global.ExecuteEngine({ serverID }, true).then(
|
responseLock = true;
|
||||||
|
const responseP = SammoAPI.Global.ExecuteEngine({ serverID }, true).then(
|
||||||
(response) => {
|
(response) => {
|
||||||
if (response.result) {
|
if (response.result) {
|
||||||
lastExecuted.value = parseTime(response.lastExecuted);
|
lastExecuted.value = parseTime(response.lastExecuted);
|
||||||
@@ -133,8 +126,8 @@ async function tryRefresh() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
//TODO: 갱신 알림 띄우기
|
//TODO: 갱신 알림 띄우기
|
||||||
const response = await Promise.race([delay(3000), responseP.value]);
|
const response = await Promise.race([delay(3000), responseP]);
|
||||||
responseP.value = undefined;
|
responseLock = false;
|
||||||
|
|
||||||
if(response === undefined){
|
if(response === undefined){
|
||||||
//timeout이지만 일단 갱신한다.
|
//timeout이지만 일단 갱신한다.
|
||||||
@@ -164,6 +157,7 @@ async function tryRefresh() {
|
|||||||
|
|
||||||
//TODO: 서버와 클라이언트 버전이 다르다면 갱신 필요
|
//TODO: 서버와 클라이언트 버전이 다르다면 갱신 필요
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
responseLock = false;
|
||||||
//매우 심각한 버그
|
//매우 심각한 버그
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert(`서버 갱신 실패: ${e}`);
|
alert(`서버 갱신 실패: ${e}`);
|
||||||
@@ -182,12 +176,19 @@ const generalRecords = ref(new Denque<[number, string]>());
|
|||||||
const globalRecords = ref(new Denque<[number, string]>());
|
const globalRecords = ref(new Denque<[number, string]>());
|
||||||
const worldHistory = ref(new Denque<[number, string]>());
|
const worldHistory = ref(new Denque<[number, string]>());
|
||||||
|
|
||||||
|
let recordLock = false;
|
||||||
|
|
||||||
watch(refreshCounter, async () => {
|
watch(refreshCounter, async () => {
|
||||||
|
if(recordLock){
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
recordLock = true;
|
||||||
const response = await SammoAPI.Global.GetRecentRecord({
|
const response = await SammoAPI.Global.GetRecentRecord({
|
||||||
lastGeneralRecordID: lastGeneralRecordID.value,
|
lastGeneralRecordID: lastGeneralRecordID.value,
|
||||||
lastWorldHistoryID: lastWorldHistoryID.value,
|
lastWorldHistoryID: lastWorldHistoryID.value,
|
||||||
});
|
});
|
||||||
|
recordLock = false;
|
||||||
|
|
||||||
if (response.flushGeneral) {
|
if (response.flushGeneral) {
|
||||||
generalRecords.value = new Denque<[number, string]>();
|
generalRecords.value = new Denque<[number, string]>();
|
||||||
@@ -243,6 +244,7 @@ watch(refreshCounter, async () => {
|
|||||||
worldHistory.value.unshift([id, record]);
|
worldHistory.value.unshift([id, record]);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
recordLock = false;
|
||||||
console.error(e);
|
console.error(e);
|
||||||
toasts.danger({
|
toasts.danger({
|
||||||
title: "최근 기록 갱신 실패",
|
title: "최근 기록 갱신 실패",
|
||||||
|
|||||||
+3
-2
@@ -6,6 +6,8 @@ include "lib.php";
|
|||||||
include "func.php";
|
include "func.php";
|
||||||
//로그인 검사
|
//로그인 검사
|
||||||
|
|
||||||
|
Session::requireGameLogin()->setReadOnly();
|
||||||
|
|
||||||
//턴 실행 대기 및 갱신 증가는 API에서
|
//턴 실행 대기 및 갱신 증가는 API에서
|
||||||
|
|
||||||
//TODO: 내 정보도 API에서, 사망 여부도
|
//TODO: 내 정보도 API에서, 사망 여부도
|
||||||
@@ -29,8 +31,7 @@ include "func.php";
|
|||||||
<title><?= UniqueConst::$serverName ?>: 메인</title>
|
<title><?= UniqueConst::$serverName ?>: 메인</title>
|
||||||
<?= WebUtil::printStaticValues([
|
<?= WebUtil::printStaticValues([
|
||||||
'staticValues' => [
|
'staticValues' => [
|
||||||
'serverName' => $serverName,
|
'serverName' => UniqueConst::$serverName,
|
||||||
'serverCnt' => $serverCnt,
|
|
||||||
'serverNick' => DB::prefix(),
|
'serverNick' => DB::prefix(),
|
||||||
'serverID' => UniqueConst::$serverID,
|
'serverID' => UniqueConst::$serverID,
|
||||||
'mapName' => GameConst::$mapName,
|
'mapName' => GameConst::$mapName,
|
||||||
|
|||||||
Reference in New Issue
Block a user