diff --git a/README.md b/README.md index 41f4588..266e269 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,16 @@ The original repo for NPWD TODO -## Production Server Installation +### Production Server Installation + +**Database** + +NPWD uses its own database driver compatible with `mysql-async` and `ghmattimysql`'s connection string. If you +don't utilize these resources, ensure you have this set in your console. + +``` +set mysql_connection_string "server=127.0.0.1;database=es_extended;userid=user;password=pass" +``` ### Configuration diff --git a/resources/server/db_utils.test.ts b/resources/server/db_utils.test.ts index 7fa20eb..2d04f34 100644 --- a/resources/server/db_utils.test.ts +++ b/resources/server/db_utils.test.ts @@ -8,14 +8,13 @@ describe("parseSemiColonFormat", () => { }); it("Correctly parses configuration options", () => { - const test = - "server=127.0.0.1;database=es_extended;userid=user;password=pass"; + const test = "server=127.0.0.1;database=es_extended;userid=user;"; const result = db.parseSemiColonFormat(test); expect(result.server).toEqual("127.0.0.1"); expect(result.database).toEqual("es_extended"); expect(result.userid).toEqual("user"); - expect(result.password).toEqual("pass"); + expect(result.password).toEqual(undefined); }); }); @@ -80,9 +79,9 @@ describe("getUserId", () => { }); describe("getPassword", () => { - it("returns default", () => { - expect(() => db.getPassword({})).toThrowError(); - }); + // it("returns default", () => { + // expect(() => db.getPassword({})).toThrowError(); + // }); it("Correctly returns password", () => { expect(db.getPassword({ password: t })).toEqual(t); diff --git a/resources/server/db_utils.ts b/resources/server/db_utils.ts index 827a38c..a370d0a 100644 --- a/resources/server/db_utils.ts +++ b/resources/server/db_utils.ts @@ -15,7 +15,7 @@ export function parseSemiColonFormat(connectionString: string): Map { const parts = connectionString.split(";"); if (parts.length === 1) { throw new Error( - `Connection string ${connectionString} is in the incorrect format.` + `Connection string ${connectionString} is in the incorrect format. Please follow the README.` ); } @@ -59,13 +59,12 @@ export function getUserId(config: Map): string { } /** + * Note: We are allowing no password as many FiveM servers love to not use one for an ungodly reason. * allowed variable names: password | pwd * @param config - database config variables parsed from mysql_connection_string */ -export function getPassword(config: Map): string { +export function getPassword(config: Map): string | undefined { const password = config.password || config.pwd; - if (!password) { - throw new Error("Password is a required field"); - } + if (!password) return undefined; return password; }