2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { HttpServerHelper } from "@spt-aki/helpers/HttpServerHelper";
|
|
|
|
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
|
|
|
|
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
|
|
|
|
import { IChangeRequestData } from "@spt-aki/models/eft/launcher/IChangeRequestData";
|
|
|
|
import { ILoginRequestData } from "@spt-aki/models/eft/launcher/ILoginRequestData";
|
|
|
|
import { IRegisterData } from "@spt-aki/models/eft/launcher/IRegisterData";
|
|
|
|
import { Info, ModDetails } from "@spt-aki/models/eft/profile/IAkiProfile";
|
|
|
|
import { IConnectResponse } from "@spt-aki/models/eft/profile/IConnectResponse";
|
|
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
|
|
import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig";
|
|
|
|
import { IPackageJsonData } from "@spt-aki/models/spt/mod/IPackageJsonData";
|
2023-11-15 12:16:56 +01:00
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
2023-10-19 19:21:17 +02:00
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { SaveServer } from "@spt-aki/servers/SaveServer";
|
|
|
|
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
|
|
|
import { HashUtil } from "@spt-aki/utils/HashUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class LauncherController
|
|
|
|
{
|
|
|
|
protected coreConfig: ICoreConfig;
|
|
|
|
|
|
|
|
constructor(
|
2023-11-15 12:16:56 +01:00
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
2023-03-03 16:23:46 +01:00
|
|
|
@inject("HashUtil") protected hashUtil: HashUtil,
|
|
|
|
@inject("SaveServer") protected saveServer: SaveServer,
|
|
|
|
@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper,
|
2023-08-10 15:29:09 +02:00
|
|
|
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
|
2023-03-03 16:23:46 +01:00
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
2023-03-15 15:18:55 +01:00
|
|
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
2023-08-10 15:29:09 +02:00
|
|
|
@inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader,
|
2023-11-10 22:49:29 +01:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
this.coreConfig = this.configServer.getConfig(ConfigTypes.CORE);
|
|
|
|
}
|
|
|
|
|
2023-03-15 15:18:55 +01:00
|
|
|
public connect(): IConnectResponse
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return {
|
|
|
|
backendUrl: this.httpServerHelper.getBackendUrl(),
|
2023-03-15 15:18:55 +01:00
|
|
|
name: this.coreConfig.serverName,
|
|
|
|
editions: Object.keys(this.databaseServer.getTables().templates.profiles),
|
2023-11-10 22:49:29 +01:00
|
|
|
profileDescriptions: this.getProfileDescriptions(),
|
2023-03-15 15:18:55 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-15 12:16:56 +01:00
|
|
|
* Get descriptive text for each of the profile edtions a player can choose, keyed by profile.json profile type e.g. "Edge Of Darkness"
|
|
|
|
* @returns Dictionary of profile types with related descriptive text
|
2023-03-15 15:18:55 +01:00
|
|
|
*/
|
|
|
|
protected getProfileDescriptions(): Record<string, string>
|
|
|
|
{
|
2023-11-15 12:16:56 +01:00
|
|
|
const result = {};
|
|
|
|
const dbProfiles = this.databaseServer.getTables().templates.profiles;
|
|
|
|
for (const profileKey in dbProfiles)
|
|
|
|
{
|
|
|
|
const localeKey = dbProfiles[profileKey]?.descriptionLocaleKey;
|
|
|
|
if (!localeKey)
|
|
|
|
{
|
|
|
|
this.logger.warning(this.localisationService.getText("launcher-missing_property", profileKey));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result[profileKey] = this.localisationService.getText(localeKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public find(sessionIdKey: string): Info
|
|
|
|
{
|
|
|
|
if (sessionIdKey in this.saveServer.getProfiles())
|
|
|
|
{
|
|
|
|
return this.saveServer.getProfile(sessionIdKey).info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
public login(info: ILoginRequestData): string
|
|
|
|
{
|
|
|
|
for (const sessionID in this.saveServer.getProfiles())
|
|
|
|
{
|
|
|
|
const account = this.saveServer.getProfile(sessionID).info;
|
|
|
|
if (info.username === account.username)
|
|
|
|
{
|
|
|
|
return sessionID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public register(info: IRegisterData): string
|
|
|
|
{
|
|
|
|
for (const sessionID in this.saveServer.getProfiles())
|
|
|
|
{
|
|
|
|
if (info.username === this.saveServer.getProfile(sessionID).info.username)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.createAccount(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected createAccount(info: IRegisterData): string
|
|
|
|
{
|
|
|
|
const sessionID = this.hashUtil.generate();
|
|
|
|
const newProfileDetails: Info = {
|
|
|
|
id: sessionID,
|
2023-10-10 13:03:20 +02:00
|
|
|
aid: this.hashUtil.generateAccountId(),
|
2023-03-03 16:23:46 +01:00
|
|
|
username: info.username,
|
|
|
|
password: info.password,
|
|
|
|
wipe: true,
|
2023-11-10 22:49:29 +01:00
|
|
|
edition: info.edition,
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
this.saveServer.createProfile(newProfileDetails);
|
|
|
|
|
|
|
|
this.saveServer.loadProfile(sessionID);
|
|
|
|
this.saveServer.saveProfile(sessionID);
|
2023-11-10 22:49:29 +01:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
return sessionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public changeUsername(info: IChangeRequestData): string
|
|
|
|
{
|
|
|
|
const sessionID = this.login(info);
|
|
|
|
|
|
|
|
if (sessionID)
|
|
|
|
{
|
|
|
|
this.saveServer.getProfile(sessionID).info.username = info.change;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sessionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public changePassword(info: IChangeRequestData): string
|
|
|
|
{
|
|
|
|
const sessionID = this.login(info);
|
|
|
|
|
|
|
|
if (sessionID)
|
|
|
|
{
|
|
|
|
this.saveServer.getProfile(sessionID).info.password = info.change;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sessionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public wipe(info: IRegisterData): string
|
|
|
|
{
|
|
|
|
const sessionID = this.login(info);
|
|
|
|
|
|
|
|
if (sessionID)
|
|
|
|
{
|
|
|
|
const profile = this.saveServer.getProfile(sessionID);
|
|
|
|
profile.info.edition = info.edition;
|
|
|
|
profile.info.wipe = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sessionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getCompatibleTarkovVersion(): string
|
|
|
|
{
|
|
|
|
return this.coreConfig.compatibleTarkovVersion;
|
|
|
|
}
|
2023-08-10 15:29:09 +02:00
|
|
|
|
2023-08-10 15:30:29 +02:00
|
|
|
/**
|
|
|
|
* Get the mods the server has currently loaded
|
|
|
|
* @returns Dictionary of mod name and mod details
|
|
|
|
*/
|
2023-08-10 15:29:09 +02:00
|
|
|
public getLoadedServerMods(): Record<string, IPackageJsonData>
|
|
|
|
{
|
|
|
|
return this.preAkiModLoader.getImportedModDetails();
|
|
|
|
}
|
|
|
|
|
2023-08-10 15:30:29 +02:00
|
|
|
/**
|
|
|
|
* Get the mods a profile has ever loaded into game with
|
|
|
|
* @param sessionId Player id
|
|
|
|
* @returns Array of mod details
|
|
|
|
*/
|
2023-08-10 15:29:09 +02:00
|
|
|
public getServerModsProfileUsed(sessionId: string): ModDetails[]
|
|
|
|
{
|
|
|
|
const profile = this.profileHelper.getFullProfile(sessionId);
|
2023-10-10 13:03:20 +02:00
|
|
|
|
2023-10-10 18:01:29 +02:00
|
|
|
if (profile?.aki?.mods)
|
|
|
|
{
|
|
|
|
return this.preAkiModLoader.getProfileModsGroupedByModName(profile?.aki?.mods);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
2023-08-10 15:29:09 +02:00
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|