Commit 3a9b2d64 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/match' into 'main'

错误处理

See merge request mycard/Neos!263
parents f6414f4d 4168249f
Pipeline #23134 passed with stages
in 9 minutes and 48 seconds
neos-protobuf @ 12f48aa7
Subproject commit d6c01dd88fd72f22c432a52ba74eee9ece267499
Subproject commit 12f48aa7901f81f4b356b968bc7a8281a1a2d848
This diff is collapsed.
......@@ -4,6 +4,7 @@ import {
STOC_CHAT,
STOC_DECK_COUNT,
STOC_DUEL_START,
STOC_ERROR_MSG,
STOC_GAME_MSG,
STOC_HAND_RESULT,
STOC_HS_PLAYER_CHANGE,
......@@ -18,6 +19,7 @@ import {
import StocChat from "./stoc/stocChat";
import StocDeckCount from "./stoc/stocDeckCount";
import StocDuelStart from "./stoc/stocDuelStart";
import StocErrorMsg from "./stoc/stocErrorMsg";
import StocGameMsg from "./stoc/stocGameMsg/mod";
import StocHandResult from "./stoc/stocHandResult";
import StocHsPlayerChange from "./stoc/stocHsPlayerChange";
......@@ -41,37 +43,30 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg {
switch (packet.proto) {
case STOC_JOIN_GAME: {
pb = new StocJoinGame(packet).upcast();
break;
}
case STOC_CHAT: {
pb = new StocChat(packet).upcast();
break;
}
case STOC_HS_PLAYER_ENTER: {
pb = new StocHsPlayerEnter(packet).upcast();
break;
}
case STOC_HS_PLAYER_CHANGE: {
pb = new StocHsPlayerChange(packet).upcast();
break;
}
case STOC_HS_WATCH_CHANGE: {
pb = new StocHsWatchChange(packet).upcast();
break;
}
case STOC_TYPE_CHANGE: {
pb = new StocTypeChange(packet).upcast();
break;
}
case STOC_SELECT_HAND: {
pb = new StocSelectHand(packet).upcast();
break;
}
case STOC_SELECT_TP: {
......@@ -80,27 +75,26 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg {
}
case STOC_HAND_RESULT: {
pb = new StocHandResult(packet).upcast();
break;
}
case STOC_DECK_COUNT: {
pb = new StocDeckCount(packet).upcast();
break;
}
case STOC_DUEL_START: {
pb = new StocDuelStart(packet).upcast();
break;
}
case STOC_GAME_MSG: {
pb = new StocGameMsg(packet).upcast();
break;
}
case STOC_TIME_LIMIT: {
pb = new StocTimeLimit(packet).upcast();
break;
}
case STOC_ERROR_MSG: {
pb = new StocErrorMsg(packet).upcast();
break;
}
default: {
......
......@@ -30,6 +30,7 @@ export const STOC_DECK_COUNT = 9;
export const STOC_DUEL_START = 21;
export const STOC_GAME_MSG = 1;
export const STOC_TIME_LIMIT = 24;
export const STOC_ERROR_MSG = 2;
export const MSG_START = 4;
export const MSG_DRAW = 90;
......
import { BufferReader } from "rust-src";
import { ygopro } from "../../idl/ocgcore";
import { StocAdapter, YgoProPacket } from "../packet";
/*
* STOC Error Msg
*
* @usage - 后端传来的错误信息
* */
export default class ErrorMsg implements StocAdapter {
packet: YgoProPacket;
constructor(packet: YgoProPacket) {
this.packet = packet;
}
upcast(): ygopro.YgoStocMsg {
const reader = new BufferReader(this.packet.exData);
const errorType = reader.readUint8();
reader.readUint8();
reader.readUint8();
reader.readUint8();
const errorCode = reader.readInt32();
return new ygopro.YgoStocMsg({
stoc_error_msg: new ygopro.StocErrorMsg({
error_type: errorType,
error_code: errorCode,
}),
});
}
}
......@@ -13,6 +13,7 @@ import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp";
import handleChat from "./room/chat";
import handleDuelStart from "./room/duelStart";
import handleErrorMsg from "./room/errorMsg";
import handleHandResult from "./room/handResult";
import handleHsPlayerChange from "./room/hsPlayerChange";
import handleHsPlayerEnter from "./room/hsPlayerEnter";
......@@ -32,57 +33,46 @@ export default async function handleSocketMessage(e: MessageEvent) {
switch (pb.msg) {
case "stoc_join_game": {
handleJoinGame(pb);
break;
}
case "stoc_chat": {
handleChat(pb);
break;
}
case "stoc_hs_player_change": {
handleHsPlayerChange(pb);
break;
}
case "stoc_hs_watch_change": {
handleHsWatchChange(pb);
break;
}
case "stoc_hs_player_enter": {
handleHsPlayerEnter(pb);
break;
}
case "stoc_type_change": {
handleTypeChange(pb);
break;
}
case "stoc_select_hand": {
handleSelectHand(pb);
break;
}
case "stoc_hand_result": {
handleHandResult(pb);
break;
}
case "stoc_select_tp": {
handleSelectTp(pb);
break;
}
case "stoc_deck_count": {
handleDeckCount(pb);
break;
}
case "stoc_duel_start": {
handleDuelStart(pb);
break;
}
case "stoc_game_msg": {
......@@ -97,7 +87,10 @@ export default async function handleSocketMessage(e: MessageEvent) {
}
case "stoc_time_limit": {
handleTimeLimit(pb.stoc_time_limit);
break;
}
case "stoc_error_msg": {
await handleErrorMsg(pb.stoc_error_msg);
break;
}
default: {
......
import { fetchCard, fetchStrings, Region, ygopro } from "@/api";
import { roomStore } from "@/stores";
import ErrorType = ygopro.StocErrorMsg.ErrorType;
// TODO: 是时候需要一个统一管理国际化文案的模块了
const DECKERROR_LFLIST = 0x1;
const DECKERROR_OCGONLY = 0x2;
const DECKERROR_TCGONLY = 0x3;
const DECKERROR_UNKNOWNCARD = 0x4;
const DECKERROR_CARDCOUNT = 0x5;
const DECKERROR_MAINCOUNT = 0x6;
const DECKERROR_EXTRACOUNT = 0x7;
const DECKERROR_SIDECOUNT = 0x8;
const DECKERROR_NOTAVAIL = 0x9;
export default async function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) {
const { error_type, error_code } = errorMsg;
switch (error_type) {
case ErrorType.JOINERROR: {
roomStore.errorMsg = fetchStrings(Region.System, 1403 + error_code);
break;
}
case ErrorType.DECKERROR: {
const flag = error_code >> 28;
const code = error_code && 0xfffffff;
const card = await fetchCard(code);
const baseMsg = `卡组非法,请检查:${card.text.name}`;
switch (flag) {
case DECKERROR_LFLIST: {
roomStore.errorMsg = baseMsg + "(数量不符合禁限卡表)";
break;
}
case DECKERROR_OCGONLY: {
roomStore.errorMsg = baseMsg + "(OCG独有卡,不能在当前设置使用)";
break;
}
case DECKERROR_TCGONLY: {
roomStore.errorMsg = baseMsg + "(TCG独有卡,不能在当前设置使用)";
break;
}
case DECKERROR_UNKNOWNCARD: {
if (code < 100000000) {
roomStore.errorMsg =
baseMsg + "(服务器无法识别此卡,可能是服务器未更新)";
} else {
roomStore.errorMsg =
baseMsg +
"(服务器无法识别此卡,可能是服务器不支持先行卡或此先行卡已正式更新)";
}
break;
}
case DECKERROR_CARDCOUNT: {
roomStore.errorMsg = baseMsg + "(数量过多)";
break;
}
case DECKERROR_MAINCOUNT: {
roomStore.errorMsg = "主卡组数量应为40-60张";
break;
}
case DECKERROR_EXTRACOUNT: {
roomStore.errorMsg = "额外卡组数量应为0-15张";
break;
}
case DECKERROR_SIDECOUNT: {
roomStore.errorMsg = "副卡组数量应为0-15张";
break;
}
case DECKERROR_NOTAVAIL: {
roomStore.errorMsg = `${card.text.name}不允许在当前设置下使用。`;
break;
}
default: {
roomStore.errorMsg = fetchStrings(Region.System, 1406);
break;
}
}
break;
}
case ErrorType.SIDEERROR: {
roomStore.errorMsg = "更换副卡组失败,请检查卡片张数是否一致。";
break;
}
case ErrorType.VERSIONERROR: {
roomStore.errorMsg = "版本不匹配,请联系技术人员解决";
break;
}
default:
break;
}
}
......@@ -41,8 +41,8 @@ class RoomStore implements NeosStore {
observerCount: number = 0; // 观战者数量
isHost: boolean = false; // 当前玩家是否是房主
selfType: SelfType = 0; // 当前玩家的类型
stage: RoomStage = RoomStage.WAITING;
errorMsg?: string = undefined; // 错误信息
getMePlayer() {
return this.players.find((player) => player?.isMe);
......@@ -57,6 +57,7 @@ class RoomStore implements NeosStore {
this.observerCount = 0;
this.isHost = false;
this.stage = RoomStage.WAITING;
this.errorMsg = undefined;
}
}
......
......@@ -29,7 +29,7 @@ export const matchStore = proxy<Props>(defaultProps);
export const MatchModal: React.FC = ({}) => {
const { open } = useSnapshot(matchStore);
const { user } = useSnapshot(accountStore);
const { joined } = useSnapshot(roomStore);
const { joined, errorMsg } = useSnapshot(roomStore);
const [player, setPlayer] = useState(user?.name ?? defaultPlayer);
const [passwd, setPasswd] = useState(defaultPassword);
const [server, setServer] = useState(
......@@ -67,6 +67,15 @@ export const MatchModal: React.FC = ({}) => {
}
}, [joined]);
useEffect(() => {
// 出现错误
if (errorMsg !== undefined && errorMsg !== "") {
alert(errorMsg);
setConfirmLoading(false);
roomStore.errorMsg = undefined;
}
}, [errorMsg]);
return (
<Modal
open={open}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment