Commit 3dd74577 authored by Chunchi Che's avatar Chunchi Che Committed by WANG HE

fix small

parent bfd6575b
...@@ -15,7 +15,7 @@ export default class CtosJoinGamePacket extends ygoProPacket { ...@@ -15,7 +15,7 @@ export default class CtosJoinGamePacket extends ygoProPacket {
const exDataLen = 2 + 4 + passWd.length; const exDataLen = 2 + 4 + passWd.length;
const exData = new Uint8Array(exDataLen); const exData = new Uint8Array(exDataLen);
const dataView = new DataView(exData); const dataView = new DataView(exData.buffer);
dataView.setUint16(0, version, littleEndian); dataView.setUint16(0, version, littleEndian);
dataView.setUint8(2, gameId & 0xff); dataView.setUint8(2, gameId & 0xff);
......
...@@ -20,7 +20,7 @@ export class ygoProPacket { ...@@ -20,7 +20,7 @@ export class ygoProPacket {
const exData = this.exData || new Uint8Array(); const exData = this.exData || new Uint8Array();
const array = new Uint8Array(packetLen + 2); const array = new Uint8Array(packetLen + 2);
const dataView = new DataView(array); const dataView = new DataView(array.buffer);
dataView.setUint16(0, packetLen, littleEndian); dataView.setUint16(0, packetLen, littleEndian);
dataView.setUint8(2, proto); dataView.setUint8(2, proto);
...@@ -31,22 +31,24 @@ export class ygoProPacket { ...@@ -31,22 +31,24 @@ export class ygoProPacket {
} }
export class ygoArrayBuilder extends ygoProPacket { export class ygoArrayBuilder extends ygoProPacket {
constructor(array: Uint8Array) { constructor(array: ArrayBuffer) {
try { try {
if (array.length < PACKET_MIN_LEN) { if (array.byteLength < PACKET_MIN_LEN) {
throw new Error("Packet length too short, length = " + array.length); throw new Error(
} else { "Packet length too short, length = " + array.byteLength
const dataView = new DataView(array); );
const packetLen = dataView.getInt16(0, littleEndian);
const proto = dataView.getInt8(2);
const exData = array.slice(3, packetLen + 2);
super(packetLen, proto, exData);
} }
} catch (e) { } catch (e) {
console.log("[e][ygoProPacket][constructor]" + e); console.log("[e][ygoProPacket][constructor]" + e);
} }
const dataView = new DataView(array);
const packetLen = dataView.getInt16(0, littleEndian);
const proto = dataView.getInt8(2);
const exData = array.slice(3, packetLen + 2);
super(packetLen, proto, new Uint8Array(exData));
} }
} }
......
...@@ -3,6 +3,8 @@ import { store } from "../../store"; ...@@ -3,6 +3,8 @@ import { store } from "../../store";
import { setJoined } from "../../reducers/joinSlice"; import { setJoined } from "../../reducers/joinSlice";
export default function handleJoinGame(pb: ygopro.YgoStocMsg) { export default function handleJoinGame(pb: ygopro.YgoStocMsg) {
console.log("Game joined!");
const dispatch = store.dispatch; const dispatch = store.dispatch;
const msg = pb.stoc_join_game; const msg = pb.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