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

add stoc joinGame adapt

parent f61a55fb
import { ygopro } from "../idl/ocgcore";
import { ygoProPacket } from "./packet";
import { CTOS_JOIN_GAME } from "./protoDecl";
const littleEndian: boolean = true;
const CtosJoinGame = 18;
export default class joinGamePacket extends ygoProPacket {
export default class CtosJoinGamePacket extends ygoProPacket {
constructor(pb: ygopro.YgoCtosMsg) {
const encoder = new TextEncoder();
const joinGame = pb.ctos_join_game;
......@@ -25,6 +24,6 @@ export default class joinGamePacket extends ygoProPacket {
dataView.setUint8(5, (gameId >> 32) & 0xff);
exData.slice(6, exDataLen).set(passWd);
super(exData.length + 1, CtosJoinGame, exData);
super(exData.length + 1, CTOS_JOIN_GAME, exData);
}
}
import { ygopro } from "../idl/ocgcore";
import { ygoProPacket } from "./packet";
import { CTOS_PLAYER_INFO } from "./protoDecl";
const CtosPlayerInfo = 16; // todo: move protos in one place
export default class playerInfoPacket extends ygoProPacket {
export default class CtosPlayerInfoPacket extends ygoProPacket {
constructor(pb: ygopro.YgoCtosMsg) {
const encoder = new TextEncoder();
const player = pb.ctos_player_info.name;
const exData = encoder.encode(player);
super(exData.length + 1, CtosPlayerInfo, exData);
super(exData.length + 1, CTOS_PLAYER_INFO, exData);
}
}
import { ygopro } from "../idl/ocgcore";
const littleEndian: boolean = true;
const PACKET_MIN_LEN = 3;
......@@ -47,3 +49,9 @@ export class ygoArrayBuilder extends ygoProPacket {
}
}
}
export interface ygoProtobuf {
readonly packet: ygoProPacket;
adapt(): ygopro.YgoStocMsg;
}
export const CTOS_PLAYER_INFO = 16;
export const CTOS_JOIN_GAME = 18;
export const STOC_JOIN_GAME = 18;
import { ygopro } from "../idl/ocgcore";
import { ygoProPacket, ygoProtobuf } from "./packet";
export default class StocJoinGamePB implements ygoProtobuf {
packet: ygoProPacket;
constructor(packet: ygoProPacket) {
this.packet = packet;
}
adapt(): ygopro.YgoStocMsg {
// todo
return new ygopro.YgoStocMsg({
stoc_join_game: new ygopro.StocJoinGame({}),
});
}
}
......@@ -5,9 +5,24 @@ import handleHsPlayerEnter from "./room/hsPlayerEnter";
import handleJoinGame from "./room/joinGame";
import handleChat from "./room/chat";
import handleHsWatchChange from "./room/hsWatchChange";
import { ygoArrayBuilder } from "../api/ocgcore/ocgAdapter/packet";
import StocJoinGame from "../api/ocgcore/ocgAdapter/stocJoinGame";
import { STOC_JOIN_GAME } from "../api/ocgcore/ocgAdapter/protoDecl";
export default function handleSocketMessage(e: MessageEvent) {
const pb = ygopro.YgoStocMsg.deserializeBinary(e.data);
const packet = new ygoArrayBuilder(e.data);
let pb = new ygopro.YgoStocMsg({});
switch (packet.proto) {
case STOC_JOIN_GAME: {
pb = new StocJoinGame(packet).adapt();
break;
}
default: {
break;
}
}
switch (pb.msg) {
case "stoc_join_game": {
......
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