Commit 89cf7e40 authored by Chunchi Che's avatar Chunchi Che

add error msg service

parent 10f24524
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
STOC_CHAT, STOC_CHAT,
STOC_DECK_COUNT, STOC_DECK_COUNT,
STOC_DUEL_START, STOC_DUEL_START,
STOC_ERROR_MSG,
STOC_GAME_MSG, STOC_GAME_MSG,
STOC_HAND_RESULT, STOC_HAND_RESULT,
STOC_HS_PLAYER_CHANGE, STOC_HS_PLAYER_CHANGE,
...@@ -18,6 +19,7 @@ import { ...@@ -18,6 +19,7 @@ import {
import StocChat from "./stoc/stocChat"; import StocChat from "./stoc/stocChat";
import StocDeckCount from "./stoc/stocDeckCount"; import StocDeckCount from "./stoc/stocDeckCount";
import StocDuelStart from "./stoc/stocDuelStart"; import StocDuelStart from "./stoc/stocDuelStart";
import StocErrorMsg from "./stoc/stocErrorMsg";
import StocGameMsg from "./stoc/stocGameMsg/mod"; import StocGameMsg from "./stoc/stocGameMsg/mod";
import StocHandResult from "./stoc/stocHandResult"; import StocHandResult from "./stoc/stocHandResult";
import StocHsPlayerChange from "./stoc/stocHsPlayerChange"; import StocHsPlayerChange from "./stoc/stocHsPlayerChange";
...@@ -41,37 +43,30 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg { ...@@ -41,37 +43,30 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg {
switch (packet.proto) { switch (packet.proto) {
case STOC_JOIN_GAME: { case STOC_JOIN_GAME: {
pb = new StocJoinGame(packet).upcast(); pb = new StocJoinGame(packet).upcast();
break; break;
} }
case STOC_CHAT: { case STOC_CHAT: {
pb = new StocChat(packet).upcast(); pb = new StocChat(packet).upcast();
break; break;
} }
case STOC_HS_PLAYER_ENTER: { case STOC_HS_PLAYER_ENTER: {
pb = new StocHsPlayerEnter(packet).upcast(); pb = new StocHsPlayerEnter(packet).upcast();
break; break;
} }
case STOC_HS_PLAYER_CHANGE: { case STOC_HS_PLAYER_CHANGE: {
pb = new StocHsPlayerChange(packet).upcast(); pb = new StocHsPlayerChange(packet).upcast();
break; break;
} }
case STOC_HS_WATCH_CHANGE: { case STOC_HS_WATCH_CHANGE: {
pb = new StocHsWatchChange(packet).upcast(); pb = new StocHsWatchChange(packet).upcast();
break; break;
} }
case STOC_TYPE_CHANGE: { case STOC_TYPE_CHANGE: {
pb = new StocTypeChange(packet).upcast(); pb = new StocTypeChange(packet).upcast();
break; break;
} }
case STOC_SELECT_HAND: { case STOC_SELECT_HAND: {
pb = new StocSelectHand(packet).upcast(); pb = new StocSelectHand(packet).upcast();
break; break;
} }
case STOC_SELECT_TP: { case STOC_SELECT_TP: {
...@@ -80,27 +75,26 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg { ...@@ -80,27 +75,26 @@ export function adaptStoc(packet: YgoProPacket): ygopro.YgoStocMsg {
} }
case STOC_HAND_RESULT: { case STOC_HAND_RESULT: {
pb = new StocHandResult(packet).upcast(); pb = new StocHandResult(packet).upcast();
break; break;
} }
case STOC_DECK_COUNT: { case STOC_DECK_COUNT: {
pb = new StocDeckCount(packet).upcast(); pb = new StocDeckCount(packet).upcast();
break; break;
} }
case STOC_DUEL_START: { case STOC_DUEL_START: {
pb = new StocDuelStart(packet).upcast(); pb = new StocDuelStart(packet).upcast();
break; break;
} }
case STOC_GAME_MSG: { case STOC_GAME_MSG: {
pb = new StocGameMsg(packet).upcast(); pb = new StocGameMsg(packet).upcast();
break; break;
} }
case STOC_TIME_LIMIT: { case STOC_TIME_LIMIT: {
pb = new StocTimeLimit(packet).upcast(); pb = new StocTimeLimit(packet).upcast();
break;
}
case STOC_ERROR_MSG: {
pb = new StocErrorMsg(packet).upcast();
break; break;
} }
default: { default: {
......
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();
let errorCode = 0;
if (errorType != 3) {
reader.readUint8();
reader.readUint8();
reader.readUint8();
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"; ...@@ -13,6 +13,7 @@ import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp"; import handleSelectTp from "./mora/selectTp";
import handleChat from "./room/chat"; import handleChat from "./room/chat";
import handleDuelStart from "./room/duelStart"; import handleDuelStart from "./room/duelStart";
import handleErrorMsg from "./room/errorMsg";
import handleHandResult from "./room/handResult"; import handleHandResult from "./room/handResult";
import handleHsPlayerChange from "./room/hsPlayerChange"; import handleHsPlayerChange from "./room/hsPlayerChange";
import handleHsPlayerEnter from "./room/hsPlayerEnter"; import handleHsPlayerEnter from "./room/hsPlayerEnter";
...@@ -32,57 +33,46 @@ export default async function handleSocketMessage(e: MessageEvent) { ...@@ -32,57 +33,46 @@ export default async function handleSocketMessage(e: MessageEvent) {
switch (pb.msg) { switch (pb.msg) {
case "stoc_join_game": { case "stoc_join_game": {
handleJoinGame(pb); handleJoinGame(pb);
break; break;
} }
case "stoc_chat": { case "stoc_chat": {
handleChat(pb); handleChat(pb);
break; break;
} }
case "stoc_hs_player_change": { case "stoc_hs_player_change": {
handleHsPlayerChange(pb); handleHsPlayerChange(pb);
break; break;
} }
case "stoc_hs_watch_change": { case "stoc_hs_watch_change": {
handleHsWatchChange(pb); handleHsWatchChange(pb);
break; break;
} }
case "stoc_hs_player_enter": { case "stoc_hs_player_enter": {
handleHsPlayerEnter(pb); handleHsPlayerEnter(pb);
break; break;
} }
case "stoc_type_change": { case "stoc_type_change": {
handleTypeChange(pb); handleTypeChange(pb);
break; break;
} }
case "stoc_select_hand": { case "stoc_select_hand": {
handleSelectHand(pb); handleSelectHand(pb);
break; break;
} }
case "stoc_hand_result": { case "stoc_hand_result": {
handleHandResult(pb); handleHandResult(pb);
break; break;
} }
case "stoc_select_tp": { case "stoc_select_tp": {
handleSelectTp(pb); handleSelectTp(pb);
break; break;
} }
case "stoc_deck_count": { case "stoc_deck_count": {
handleDeckCount(pb); handleDeckCount(pb);
break; break;
} }
case "stoc_duel_start": { case "stoc_duel_start": {
handleDuelStart(pb); handleDuelStart(pb);
break; break;
} }
case "stoc_game_msg": { case "stoc_game_msg": {
...@@ -97,7 +87,10 @@ export default async function handleSocketMessage(e: MessageEvent) { ...@@ -97,7 +87,10 @@ export default async function handleSocketMessage(e: MessageEvent) {
} }
case "stoc_time_limit": { case "stoc_time_limit": {
handleTimeLimit(pb.stoc_time_limit); handleTimeLimit(pb.stoc_time_limit);
break;
}
case "stoc_error_msg": {
handleErrorMsg(pb.stoc_error_msg);
break; break;
} }
default: { default: {
......
import { ygopro } from "@/api";
export default function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) {
console.log(errorMsg);
}
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