feat: 여러턴 예약을 ReserveBulkdCommand로 대체
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\Command;
|
||||||
|
|
||||||
|
use sammo\Session;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use sammo\GameConst;
|
||||||
|
use sammo\Util;
|
||||||
|
use sammo\Validator;
|
||||||
|
|
||||||
|
use function sammo\setGeneralCommand;
|
||||||
|
|
||||||
|
class ReserveBulkCommand extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
foreach ($this->args as $idx => $turn) {
|
||||||
|
$v = new Validator($turn);
|
||||||
|
$v->rule('required', [
|
||||||
|
'action',
|
||||||
|
'turnList'
|
||||||
|
])
|
||||||
|
->rule('lengthMin', 'action', 1)
|
||||||
|
->rule('integerArray', 'turnList');
|
||||||
|
|
||||||
|
if (!$v->validate()) {
|
||||||
|
return "{$idx}:{$v->errorStr()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||||
|
{
|
||||||
|
$briefList = [];
|
||||||
|
foreach ($this->args as $idx => $turn) {
|
||||||
|
$action = $turn['action'];
|
||||||
|
$turnList = $turn['turnList'];
|
||||||
|
$arg = $turn['arg'] ?? [];
|
||||||
|
|
||||||
|
if (!$turnList) {
|
||||||
|
return "{$idx}: 턴이 입력되지 않았습니다";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($action, Util::array_flatten(GameConst::$availableGeneralCommand))) {
|
||||||
|
return "{$idx}: 사용할 수 없는 커맨드입니다.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($arg)) {
|
||||||
|
return "{$idx}: 올바른 arg 형태가 아닙니다.";
|
||||||
|
}
|
||||||
|
$partialResult = setGeneralCommand($session->generalID, $turnList, $action, $arg);
|
||||||
|
if(!$partialResult['result']){
|
||||||
|
return [
|
||||||
|
'result' => false,
|
||||||
|
'briefList' => $briefList,
|
||||||
|
'errorIdx' => $idx,
|
||||||
|
'reason' => $partialResult['reason']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$briefList[$idx] = $partialResult['brief'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'result' => true,
|
||||||
|
'briefList' => $briefList,
|
||||||
|
'reason' => 'success'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -319,12 +319,13 @@ import { parseTime } from "@util/parseTime";
|
|||||||
import { parseYearMonth } from "@util/parseYearMonth";
|
import { parseYearMonth } from "@util/parseYearMonth";
|
||||||
import DragSelect from "@/components/DragSelect.vue";
|
import DragSelect from "@/components/DragSelect.vue";
|
||||||
import { SammoAPI, type InvalidResponse } from "./SammoAPI";
|
import { SammoAPI, type InvalidResponse } from "./SammoAPI";
|
||||||
import type { CommandItem, ReserveCommandResponse } from "@/defs";
|
import type { CommandItem, ReserveBulkCommandResponse, ReserveCommandResponse } from "@/defs";
|
||||||
import CommandSelectForm from "@/components/CommandSelectForm.vue";
|
import CommandSelectForm from "@/components/CommandSelectForm.vue";
|
||||||
import { BButton, BButtonGroup, BDropdownItem, BDropdown, BDropdownText, BDropdownDivider } from "bootstrap-vue-3";
|
import { BButton, BButtonGroup, BDropdownItem, BDropdown, BDropdownText, BDropdownDivider } from "bootstrap-vue-3";
|
||||||
import { StoredActionsHelper } from "./util/StoredActionsHelper";
|
import { StoredActionsHelper } from "./util/StoredActionsHelper";
|
||||||
import type { TurnObj } from '@/defs';
|
import type { TurnObj } from '@/defs';
|
||||||
import { unwrap } from "./util/unwrap";
|
import { unwrap } from "./util/unwrap";
|
||||||
|
import type { Args } from "./processing/args";
|
||||||
|
|
||||||
type TurnObjWithTime = TurnObj & {
|
type TurnObjWithTime = TurnObj & {
|
||||||
time: string;
|
time: string;
|
||||||
@@ -620,37 +621,33 @@ async function reloadCommandList() {
|
|||||||
|
|
||||||
async function reserveCommandDirect(args: [number[], TurnObj][], reload = true): Promise<boolean> {
|
async function reserveCommandDirect(args: [number[], TurnObj][], reload = true): Promise<boolean> {
|
||||||
const waiterList: Promise<ReserveCommandResponse | InvalidResponse>[] = [];
|
const waiterList: Promise<ReserveCommandResponse | InvalidResponse>[] = [];
|
||||||
|
|
||||||
|
const query: {
|
||||||
|
turnList: number[],
|
||||||
|
action: string,
|
||||||
|
arg: Args
|
||||||
|
}[] = [];
|
||||||
for (const [turnList, { action, arg }] of args) {
|
for (const [turnList, { action, arg }] of args) {
|
||||||
waiterList.push(
|
query.push({
|
||||||
SammoAPI.Command.ReserveCommand<ReserveCommandResponse, InvalidResponse>({
|
turnList,
|
||||||
turnList,
|
action,
|
||||||
action,
|
arg
|
||||||
arg,
|
});
|
||||||
}, true)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let success = true;
|
try {
|
||||||
for (const [idx, waiter] of waiterList.entries()) {
|
await SammoAPI.Command.ReserveBulkCommand<ReserveBulkCommandResponse>(query);
|
||||||
try {
|
releaseSelectedTurnList();
|
||||||
const response = await waiter;
|
} catch (e) {
|
||||||
if (!response.result) {
|
console.error(e);
|
||||||
const message = `${args[idx][0].join(',')}을 예약하지 못했습니다: ${response.reason}`
|
alert(`실패했습니다: ${e}`);
|
||||||
console.error(message, args[idx][1]);
|
return false;
|
||||||
alert(message);
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
const message = `${args[idx][0].join(',')}을 예약하지 못했습니다: ${e}`
|
|
||||||
console.error(message, args[idx][1]);
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reload) {
|
if (reload) {
|
||||||
await reloadCommandList();
|
await reloadCommandList();
|
||||||
}
|
}
|
||||||
return success;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedTurnList(): number[] {
|
function getSelectedTurnList(): number[] {
|
||||||
|
|||||||
+7
-6
@@ -3,17 +3,17 @@ import { APIPathGen } from "./util/APIPathGen";
|
|||||||
import { callSammoAPI, type ValidResponse } from "./util/callSammoAPI";
|
import { callSammoAPI, type ValidResponse } from "./util/callSammoAPI";
|
||||||
export type { ValidResponse, InvalidResponse };
|
export type { ValidResponse, InvalidResponse };
|
||||||
|
|
||||||
async function done<ResultType extends ValidResponse>(args?: Record<string, unknown>): Promise<ResultType>;
|
async function done<ResultType extends ValidResponse>(args?: Record<string, unknown> | Record<string, unknown>[]): Promise<ResultType>;
|
||||||
async function done<ResultType extends ValidResponse>(args: Record<string, unknown> | undefined, returnError: false): Promise<ResultType>;
|
async function done<ResultType extends ValidResponse>(args: Record<string, unknown> | Record<string, unknown>[] | undefined, returnError: false): Promise<ResultType>;
|
||||||
async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args: Record<string, unknown> | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args: Record<string, unknown> | Record<string, unknown>[] | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
||||||
|
|
||||||
async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args?: Record<string, unknown>, returnError = false): Promise<ResultType | ErrorType> {
|
async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args?: Record<string, unknown> | Record<string, unknown>[], returnError = false): Promise<ResultType | ErrorType> {
|
||||||
console.error(`Can't directly call. ${args}, ${returnError}. Use auto-generated path API.`);
|
console.error(`Can't directly call. ${args}, ${returnError}. Use auto-generated path API.`);
|
||||||
return callSammoAPI<ResultType, ErrorType>([], args, true);
|
return callSammoAPI<ResultType, ErrorType>([], args, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiRealPath = {
|
const apiRealPath = {
|
||||||
Betting:{
|
Betting: {
|
||||||
Bet: done,
|
Bet: done,
|
||||||
GetBettingDetail: done,
|
GetBettingDetail: done,
|
||||||
GetBettingList: done,
|
GetBettingList: done,
|
||||||
@@ -23,6 +23,7 @@ const apiRealPath = {
|
|||||||
PushCommand: done,
|
PushCommand: done,
|
||||||
RepeatCommand: done,
|
RepeatCommand: done,
|
||||||
ReserveCommand: done,
|
ReserveCommand: done,
|
||||||
|
ReserveBulkCommand: done,
|
||||||
},
|
},
|
||||||
General: {
|
General: {
|
||||||
Join: done,
|
Join: done,
|
||||||
@@ -54,7 +55,7 @@ const apiRealPath = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const SammoAPI = APIPathGen<typeof done, typeof apiRealPath>(apiRealPath, (path: string[]) => {
|
export const SammoAPI = APIPathGen<typeof done, typeof apiRealPath>(apiRealPath, (path: string[]) => {
|
||||||
return (args?: Record<string, unknown>, returnError?: boolean) => {
|
return (args?: Record<string, unknown> | Record<string, unknown>[], returnError?: boolean) => {
|
||||||
if (returnError) {
|
if (returnError) {
|
||||||
return callSammoAPI(path.join('/'), args, true);
|
return callSammoAPI(path.join('/'), args, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ export type ReserveCommandResponse = {
|
|||||||
brief: string,
|
brief: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ReserveBulkCommandResponse = {
|
||||||
|
result: true,
|
||||||
|
briefList: string[],
|
||||||
|
}
|
||||||
|
|
||||||
export type NationLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
export type NationLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
||||||
export const NationLevelText: Record<NationLevel, string> = {
|
export const NationLevelText: Record<NationLevel, string> = {
|
||||||
0: '방랑군',
|
0: '방랑군',
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ export type ValidResponse = {
|
|||||||
result: true
|
result: true
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function callSammoAPI<ResultType extends ValidResponse>(path: string | string[], args?: Record<string, unknown>): Promise<ResultType>;
|
export async function callSammoAPI<ResultType extends ValidResponse>(path: string | string[], args?: Record<string, unknown> | Record<string, unknown>[]): Promise<ResultType>;
|
||||||
export async function callSammoAPI<ResultType extends ValidResponse>(path: string | string[], args: Record<string, unknown> | undefined, returnError: false): Promise<ResultType>;
|
export async function callSammoAPI<ResultType extends ValidResponse>(path: string | string[], args: Record<string, unknown> | Record<string, unknown>[] | undefined, returnError: false): Promise<ResultType>;
|
||||||
export async function callSammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args: Record<string, unknown> | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
export async function callSammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args: Record<string, unknown> | Record<string, unknown>[] | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
||||||
|
|
||||||
export async function callSammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args?: Record<string, unknown>, returnError = false): Promise<ResultType | ErrorType> {
|
export async function callSammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args?: Record<string, unknown> | Record<string, unknown>[], returnError = false): Promise<ResultType | ErrorType> {
|
||||||
if (isArray(path)) {
|
if (isArray(path)) {
|
||||||
path = path.join('/');
|
path = path.join('/');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user