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

fix and succeed in joining room

parent 610fcd05
......@@ -3,8 +3,6 @@ import { ygoProPacket } from "../packet";
import { CTOS_JOIN_GAME } from "../protoDecl";
import { strEncodeUTF16 } from "../util";
const littleEndian: boolean = true;
export default class CtosJoinGamePacket extends ygoProPacket {
constructor(pb: ygopro.YgoCtosMsg) {
const joinGame = pb.ctos_join_game;
......@@ -13,16 +11,19 @@ export default class CtosJoinGamePacket extends ygoProPacket {
const gameId = joinGame.gameid;
const passWd = strEncodeUTF16(joinGame.passwd);
const exDataLen = 2 + 4 + passWd.length;
const exDataLen = 4 + 4 + passWd.length;
const exData = new Uint8Array(exDataLen);
const dataView = new DataView(exData.buffer);
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);
dataView.setUint8(0, version & 0xff);
dataView.setUint8(1, (version >> 8) & 0xff);
dataView.setUint8(2, 0);
dataView.setUint8(3, 0);
dataView.setUint8(4, gameId & 0xff);
dataView.setUint8(5, (gameId >> 8) & 0xff);
dataView.setUint8(6, (gameId >> 16) & 0xff);
dataView.setUint8(7, (gameId >> 32) & 0xff);
exData.set(passWd, 3);
super(exData.length + 1, CTOS_JOIN_GAME, exData);
}
......
......@@ -20,7 +20,7 @@ export class ygoProPacket {
dataView.setUint16(0, this.packetLen, littleEndian);
dataView.setUint8(2, this.proto);
array.slice(3, this.packetLen + 2).set(this.exData);
array.set(this.exData, 3);
return array;
}
......
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