Skip to content

Commit

Permalink
fix(skymp5-client): de-hardcode server id and master url (#2326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Feb 9, 2025
1 parent e82760b commit 729ef34
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
34 changes: 22 additions & 12 deletions skymp5-client/src/services/services/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ export class AuthService extends ClientListener {
this.controller.once("update", () => this.onceUpdate());
}

// TODO: consider moving to a separate service called SettingsService
public getServerMasterKey() {
let masterKey = this.sp.settings["skymp5-client"]["server-master-key"];
if (!masterKey) {
masterKey = this.sp.settings["skymp5-client"]["master-key"];
}
if (!masterKey) {
masterKey = this.sp.settings["skymp5-client"]["server-ip"] + ":" + this.sp.settings["skymp5-client"]["server-port"];
}
return masterKey;
}

// TODO: consider moving to a separate service called SettingsService
public getMasterUrl() {
return this.normalizeUrl((this.sp.settings["skymp5-client"]["master"] as string) || "https://gateway.skymp.net");
}

public getMasterApiId() {
return authData?.masterApiId;
}

private onAuthNeeded(e: AuthNeededEvent) {
logTrace(this, `Received authNeeded event`);

Expand Down Expand Up @@ -223,15 +244,8 @@ export class AuthService extends ClientListener {

private createPlaySession(token: string, callback: (res: string, err: string) => void) {
const client = new this.sp.HttpClient(this.getMasterUrl());
let masterKey = this.sp.settings["skymp5-client"]["server-master-key"];
if (!masterKey) {
masterKey = this.sp.settings["skymp5-client"]["master-key"];
}
if (!masterKey) {
masterKey = this.sp.settings["skymp5-client"]["server-ip"] + ":" + this.sp.settings["skymp5-client"]["server-port"];
}

const route = `/api/users/me/play/${masterKey}`;
const route = `/api/users/me/play/${this.getServerMasterKey()}`;

logTrace(this, `Creating play session ${route}`);

Expand Down Expand Up @@ -357,10 +371,6 @@ export class AuthService extends ClientListener {
}
};

private getMasterUrl() {
return this.normalizeUrl((this.sp.settings["skymp5-client"]["master"] as string) || "https://gateway.skymp.net");
}

private normalizeUrl(url: string) {
if (url.endsWith('/')) {
return url.slice(0, url.length - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getScreenResolution } from "../../view/formView";
import { ClientListener, CombinedController, Sp } from "./clientListener";
import { Mod, ServerManifest } from "../messages_http/serverManifest";
import { logTrace } from "../../logging";
import { AuthService } from "./authService";

const STATE_KEY = 'loadOrderCheckState';

Expand Down Expand Up @@ -106,12 +107,15 @@ export class LoadOrderVerificationService extends ClientListener {
}

private getServerMods(retriesLeft: number): Promise<Mod[]> {
// TODO: unhardcode master address
// TODO: unhardcode serverId (sweetpie)
let addr = "https://gateway.skymp.net";
const authService = this.controller.lookupListener(AuthService);

const addr = authService.getMasterUrl();
const masterKey = authService.getServerMasterKey();
printConsole(addr);
printConsole(masterKey);

return new HttpClient(addr)
.get('/api/servers/sweetpie/manifest.json')
.get(`/api/servers/${masterKey}/manifest.json`)
.then((res) => {
if (res.status != 200) {
throw new Error(`Status code ${res.status}, error ${res.error}`);
Expand Down

0 comments on commit 729ef34

Please sign in to comment.