From 53bf59bbfd4880fe85f6fa591adf1e2332667843 Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Sun, 15 Dec 2024 20:21:35 +0000 Subject: [PATCH] fix client --- skymp5-client/src/services/events/events.ts | 6 ++-- .../src/services/services/authService.ts | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/skymp5-client/src/services/events/events.ts b/skymp5-client/src/services/events/events.ts index 6473fb0e3a..e136b48b6d 100644 --- a/skymp5-client/src/services/events/events.ts +++ b/skymp5-client/src/services/events/events.ts @@ -15,7 +15,6 @@ import { SetInventoryMessage } from "../messages/setInventoryMessage"; import { OpenContainerMessage } from "../messages/openContainerMessage"; import { ChangeValuesMessage } from "../messages/changeValuesMessage"; import { CreateActorMessage } from "../messages/createActorMessage"; -import { CustomPacketMessage2 } from "../messages/customPacketMessage2"; import { DestroyActorMessage } from "../messages/destroyActorMessage"; import { SetRaceMenuOpenMessage } from "../messages/setRaceMenuOpenMessage"; import { SpSnippetMessage } from "../messages/spSnippetMessage"; @@ -36,6 +35,7 @@ import { QueryBlockSetInventoryEvent } from "./queryBlockSetInventoryEvent"; import { QueryKeyCodeBindings } from "./queryKeyCodeBindings"; import { SpellCastMessage } from "../messages/spellCastMessage"; import { UpdateAnimVariablesMessage } from "../messages/updateAnimVariablesMessage"; +import { CustomPacketMessage } from "../messages/customPacketMessage"; type EventTypes = { @@ -64,14 +64,14 @@ type EventTypes = { 'hostStopMessage': [ConnectionMessage], 'setInventoryMessage': [ConnectionMessage], 'createActorMessage': [ConnectionMessage], - 'customPacketMessage2': [ConnectionMessage], 'destroyActorMessage': [ConnectionMessage], 'setRaceMenuOpenMessage': [ConnectionMessage], 'spSnippetMessage': [ConnectionMessage], 'updateGamemodeDataMessage': [ConnectionMessage], 'updatePropertyMessage': [ConnectionMessage], 'deathStateContainerMessage': [ConnectionMessage], - 'teleportMessage2': [ConnectionMessage] + 'teleportMessage2': [ConnectionMessage], + 'customPacketMessage': [ConnectionMessage] 'browserWindowLoaded': [BrowserWindowLoadedEvent], 'authAttempt': [AuthAttemptEvent], diff --git a/skymp5-client/src/services/services/authService.ts b/skymp5-client/src/services/services/authService.ts index 198a72d58e..d45561283d 100644 --- a/skymp5-client/src/services/services/authService.ts +++ b/skymp5-client/src/services/services/authService.ts @@ -11,7 +11,6 @@ import { ConnectionMessage } from "../events/connectionMessage"; import { CreateActorMessage } from "../messages/createActorMessage"; import { CustomPacketMessage } from "../messages/customPacketMessage"; import { NetworkingService } from "./networkingService"; -import { CustomPacketMessage2 } from "../messages/customPacketMessage2"; import { MsgType } from "../../messages"; import { ConnectionDenied } from "../events/connectionDenied"; @@ -46,7 +45,7 @@ export class AuthService extends ClientListener { this.controller.emitter.on("createActorMessage", (e) => this.onCreateActorMessage(e)); this.controller.emitter.on("connectionAccepted", () => this.handleConnectionAccepted()); this.controller.emitter.on("connectionDenied", (e) => this.handleConnectionDenied(e)); - this.controller.emitter.on("customPacketMessage2", (e) => this.onCustomPacketMessage2(e)); + this.controller.emitter.on("customPacketMessage", (e) => this.onCustomPacketMessage(e)); this.controller.on("browserMessage", (e) => this.onBrowserMessage(e)); this.controller.on("tick", () => this.onTick()); this.controller.once("update", () => this.onceUpdate()); @@ -96,10 +95,24 @@ export class AuthService extends ClientListener { this.authAttemptProgressIndicator = false; } - private onCustomPacketMessage2(event: ConnectionMessage): void { + private onCustomPacketMessage(event: ConnectionMessage): void { const msg = event.message; - switch (msg.content["customPacketType"]) { + let msgContent: Record = {}; + + try { + msgContent = JSON.parse(msg.contentJsonDump); + } catch (e) { + if (e instanceof SyntaxError) { + logError(this, "onCustomPacketMessage failed to parse JSON", e.message, "json:", msg.contentJsonDump); + return; + } + else { + throw e; + } + } + + switch (msgContent["customPacketType"]) { // case 'loginRequired': // logTrace(this, 'loginRequired received'); // this.loginWithSkympIoCredentials(); @@ -541,12 +554,12 @@ export class AuthService extends ClientListener { ); const message: CustomPacketMessage = { t: MsgType.CustomPacket, - content: { + contentJsonDump: JSON.stringify({ customPacketType: 'loginWithSkympIo', gameData: { profileId: authData.local.profileId, }, - }, + }), }; this.controller.emitter.emit("sendMessage", { message: message, @@ -559,12 +572,12 @@ export class AuthService extends ClientListener { logTrace(this, 'Logging in as a master API user'); const message: CustomPacketMessage = { t: MsgType.CustomPacket, - content: { + contentJsonDump: JSON.stringify({ customPacketType: 'loginWithSkympIo', gameData: { session: authData.remote.session, }, - }, + }), }; this.controller.emitter.emit("sendMessage", { message: message,