Account and Character Database and Config Improvements (#317)

* Create Account/DB abstraction

* Fix crash when removing boomers from deconstructed player

* Extend config to include database and worldserver info

* Improve ConfigParser tests

* Add database setup documentation

* Add xTriad to THANKS file

**

* Increase bcrypt rounds and fix readme link
This commit is contained in:
pschord 2020-01-10 11:13:37 -05:00 committed by Fate-JH
parent ae768e1e42
commit d08911d07c
29 changed files with 1757 additions and 225 deletions

69
schema.sql Normal file
View file

@ -0,0 +1,69 @@
CREATE TABLE IF NOT EXISTS "accounts" (
"id" SERIAL PRIMARY KEY NOT NULL,
"username" VARCHAR(64) NOT NULL UNIQUE,
"passhash" VARCHAR(64) NOT NULL,
"created" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"inactive" BOOLEAN NOT NULL DEFAULT FALSE,
"gm" BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS "characters" (
"id" SERIAL PRIMARY KEY NOT NULL,
"name" VARCHAR(64) NOT NULL,
"account_id" INT NOT NULL REFERENCES accounts (id),
"faction_id" INT NOT NULL,
"gender_id" INT NOT NULL,
"head_id" INT NOT NULL,
"voice_id" INT NOT NULL,
"created" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_login" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted" BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS "logins" (
"id" SERIAL PRIMARY KEY NOT NULL,
"account_id" INT NOT NULL REFERENCES accounts (id),
"login_time" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"ip_address" VARCHAR(32) NOT NULL,
"canonical_hostname" VARCHAR(132) NOT NULL,
"hostname" VARCHAR(132) NOT NULL,
"port" INT NOT NULL
);
CREATE TABLE IF NOT EXISTS "loadouts" (
"id" SERIAL PRIMARY KEY NOT NULL,
"characters_id" INT NOT NULL REFERENCES characters (id),
"loadout_number" INT NOT NULL,
"exosuit_id" INT NOT NULL,
"name" VARCHAR(36) NOT NULL,
"items" TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "lockers" (
"id" SERIAL PRIMARY KEY NOT NULL,
"characters_id" INT NOT NULL REFERENCES characters (id),
"items" TEXT NOT NULL
);
--These triggers update the last_modified timestamp column when a table is updated
CREATE OR REPLACE FUNCTION fn_set_last_modified_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.last_modified = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS trigger_accounts_set_last_modified on accounts;
CREATE TRIGGER trigger_accounts_set_last_modified
BEFORE UPDATE ON accounts
FOR EACH ROW
EXECUTE PROCEDURE fn_set_last_modified_timestamp();
DROP TRIGGER IF EXISTS trigger_players_set_last_modified on characters;
CREATE TRIGGER trigger_players_set_last_modified
BEFORE UPDATE ON characters
FOR EACH ROW
EXECUTE PROCEDURE fn_set_last_modified_timestamp();