-- Login DB: L2J Mobius / Essence (совместимость с клиентом protocol 520).
-- Пароль: Base64(SHA1(UTF-8 пароль)) — см. LoginController Mobius.

CREATE TABLE IF NOT EXISTS accounts (
  login VARCHAR(45) NOT NULL PRIMARY KEY,
  password VARCHAR(45),
  lastactive BIGINT,
  "accessLevel" INTEGER NOT NULL DEFAULT 0,
  "lastIP" VARCHAR(20),
  "lastServer" INTEGER DEFAULT 1,
  "pcIp" VARCHAR(20),
  hop1 VARCHAR(20),
  hop2 VARCHAR(20),
  hop3 VARCHAR(20),
  hop4 VARCHAR(20)
);

CREATE TABLE IF NOT EXISTS account_data (
  account_name VARCHAR(45) NOT NULL,
  var VARCHAR(20) NOT NULL,
  value VARCHAR(255),
  PRIMARY KEY (account_name, var),
  CONSTRAINT fk_account_data_login FOREIGN KEY (account_name)
    REFERENCES accounts (login) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS accounts_ipauth (
  login VARCHAR(45) NOT NULL,
  ip VARCHAR(15) NOT NULL,
  type VARCHAR(15) NOT NULL,
  PRIMARY KEY (login, ip)
);

CREATE TABLE IF NOT EXISTS gameservers (
  server_id INTEGER NOT NULL PRIMARY KEY,
  hexid VARCHAR(50) NOT NULL,
  host VARCHAR(50) NOT NULL
);
