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

add joinGame adapt

parent 89983f5a
import { ygopro } from "../idl/ocgcore";
import { ygoProPacket } from "./packet";
const littleEndian: boolean = true;
const CtosJoinGame = 18;
export default class joinGamePacket extends ygoProPacket {
constructor(pb: ygopro.YgoCtosMsg) {
const encoder = new TextEncoder();
const joinGame = pb.ctos_join_game;
const version = joinGame.version;
const gameId = joinGame.gameid;
const passWd = encoder.encode(joinGame.passwd);
const exDataLen = 2 + 4 + passWd.length;
const exData = new Uint8Array(exDataLen);
const dataView = new DataView(exData);
dataView.setUint16(0, version, littleEndian);
dataView.setUint8(2, gameId & 0xff);
dataView.setUint8(3, (gameId >> 8) & 0xff);
dataView.setUint8(4, (gameId >> 16) & 0xff);
dataView.setUint8(5, (gameId >> 32) & 0xff);
exData.slice(6, exDataLen).set(passWd);
super(exData.length + 1, CtosJoinGame, exData);
}
}
import { ygopro } from "../idl/ocgcore";
import { ygoProPacket } from "./packet";
const CtosPlayerInfo = 16;
const CtosPlayerInfo = 16; // todo: move protos in one place
export class playerInfoPacket extends ygoProPacket {
export default class playerInfoPacket extends ygoProPacket {
constructor(pb: ygopro.YgoCtosMsg) {
const encoder = new TextEncoder();
......
import { ygopro } from "./idl/ocgcore";
import socketMiddleWare, { socketCmd } from "../../middleware/socket";
import { IDeck } from "../Card";
import { playerInfoPacket } from "./ocgAdapter/playerInfo";
import playerInfoPacket from "./ocgAdapter/ctosPlayerInfo";
import joinGamePacket from "./ocgAdapter/ctosJoinGame";
export function sendUpdateDeck(deck: IDeck) {
const updateDeck = new ygopro.YgoCtosMsg({
......@@ -50,6 +51,7 @@ export function sendJoinGame(ws: WebSocket, version: number, passWd: string) {
passwd: passWd,
}),
});
const packet = new joinGamePacket(joinGame);
ws.send(joinGame.serialize());
ws.send(packet.serialize());
}
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