Commit e24bbe73 authored by Chunchi Che's avatar Chunchi Che Committed by WANG HE

add StocHsPlayerChange adapt

parent 3be528f2
......@@ -6,3 +6,4 @@ export const CTOS_HS_READY = 34;
export const STOC_JOIN_GAME = 18;
export const STOC_CHAT = 25;
export const STOC_HS_PLAYER_ENTER = 32;
export const STOC_HS_PLAYER_CHANGE = 33;
import { ygopro } from "../../idl/ocgcore";
import { ygoProPacket, ygoProtobuf } from "../packet";
export default class StocHsPlayerChange implements ygoProtobuf {
packet: ygoProPacket;
constructor(packet: ygoProPacket) {
this.packet = packet;
}
adapt(): ygopro.YgoStocMsg {
const pb = new ygopro.StocHsPlayerChange({});
pb.state = ygopro.StocHsPlayerChange.State.UNKNOWN;
const Status = new DataView(this.packet.exData.buffer).getUint8(0);
const pos = (Status >> 4) & 0xf;
const state = Status & 0xf;
if (pos < 4) {
if (state < 8) {
pb.state = ygopro.StocHsPlayerChange.State.MOVE;
pb.moved_pos = state;
} else if (state === 0x9) {
pb.state = ygopro.StocHsPlayerChange.State.READY;
} else if (state === 0xa) {
pb.state = ygopro.StocHsPlayerChange.State.NO_READY;
} else if (state === 0xb) {
pb.state = ygopro.StocHsPlayerChange.State.LEAVE;
} else if (state === 0x8) {
pb.state = ygopro.StocHsPlayerChange.State.TO_OBSERVER;
}
}
return new ygopro.YgoStocMsg({
stoc_hs_player_change: pb,
});
}
}
......@@ -20,7 +20,8 @@ export default class StocHsPlayerEnter implements ygoProtobuf {
);
const dataView = new DataView(exData.buffer);
const pos = dataView.getInt8(UTF16_BUFFER_MAX_LEN * UINT8_PER_UINT16) & 0x3;
const pos =
dataView.getUint8(UTF16_BUFFER_MAX_LEN * UINT8_PER_UINT16) & 0x3;
return new ygopro.YgoStocMsg({
stoc_hs_player_enter: new ygopro.StocHsPlayerEnter({
......
......@@ -9,11 +9,13 @@ import { ygoArrayBuilder } from "../api/ocgcore/ocgAdapter/packet";
import StocJoinGame from "../api/ocgcore/ocgAdapter/stoc/stocJoinGame";
import {
STOC_CHAT,
STOC_HS_PLAYER_CHANGE,
STOC_HS_PLAYER_ENTER,
STOC_JOIN_GAME,
} from "../api/ocgcore/ocgAdapter/protoDecl";
import StocChat from "../api/ocgcore/ocgAdapter/stoc/stocChat";
import StocHsPlayerEnter from "../api/ocgcore/ocgAdapter/stoc/stocHsPlayerEnter";
import StocHsPlayerChange from "../api/ocgcore/ocgAdapter/stoc/stocHsPlayerChange";
export default function handleSocketMessage(e: MessageEvent) {
const packet = new ygoArrayBuilder(e.data);
......@@ -36,6 +38,11 @@ export default function handleSocketMessage(e: MessageEvent) {
break;
}
case STOC_HS_PLAYER_CHANGE: {
pb = new StocHsPlayerChange(packet).adapt();
break;
}
default: {
break;
}
......
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