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

add error msg service

parent 10f24524
Pipeline #23128 passed with stages
in 11 minutes and 52 seconds
......@@ -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: {
......
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";
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": {
handleErrorMsg(pb.stoc_error_msg);
break;
}
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