Implement auto-account

This commit is contained in:
memetrollsXD 2022-08-04 10:52:16 +02:00
parent 1fb0f26796
commit 47fe6486d5
No known key found for this signature in database
GPG Key ID: 105C2F3417AC32CD
2 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import { Request, Response } from "express";
import Account from "../../../../../../db/Account";
import Config from "../../../../../../util/Config";
import Logger from "../../../../../../util/Logger";
const c = new Logger("Dispatch");
@ -20,6 +21,14 @@ export default async function handle(req: Request, res: Response) {
}
}
if (!acc) {
if (Config.AUTO_ACCOUNT) {
const account = await Account.create(req.body.account);
c.log(`Account ${account.name} with UID ${account.uid} auto-created.`);
dataObj.data.account = account;
res.send(dataObj);
return;
}
dataObj.retcode = -202;
dataObj.message = "Account not found";
c.warn(`Player ${req.body.account} not found (${req.ip})`);

View File

@ -27,7 +27,8 @@ const DEFAULT_CONFIG = {
SERVER_PORT: 22102,
MAINTENANCE: false,
MAINTENANCE_MSG: "Server is in maintenance mode."
}
},
AUTO_ACCOUNT: false
}
type DefaultConfig = typeof DEFAULT_CONFIG;
@ -80,6 +81,7 @@ export default class Config {
MAINTENANCE: boolean;
MAINTENANCE_MSG: string;
} = Config.config.GAMESERVER;
public static AUTO_ACCOUNT: boolean = Config.config.AUTO_ACCOUNT;
private constructor() { }
}