Skip to content

Database Structure

Database Schema Reference

BlackTek Server uses MySQL/MariaDB for persistent data storage. This document describes the database schema and table structures.

Table of Contents


Overview

The database is designed with foreign key constraints to maintain referential integrity. Most player-related tables cascade deletes from the players table.

Recommended Settings:

  • Engine: InnoDB (required for foreign keys)
  • Charset: utf8mb3 or utf8mb4
  • Collation: utf8_general_ci

Core Tables

accounts

Stores user account information.

ColumnTypeDefaultDescription
idintAUTO_INCREMENTPrimary key
namevarchar(32)-Account name (login)
passwordchar(40)-SHA1 hashed password
secretchar(16)NULLTwo-factor auth secret
typeint1Account type (1=normal, 6=god)
premium_ends_atint unsigned0Premium expiration timestamp
emailvarchar(255)Account email
creationint0Account creation timestamp

Account Types:

  • 1 = ACCOUNT_TYPE_NORMAL
  • 2 = ACCOUNT_TYPE_TUTOR
  • 3 = ACCOUNT_TYPE_SENIORTUTOR
  • 4 = ACCOUNT_TYPE_GAMEMASTER
  • 5 = ACCOUNT_TYPE_COMMUNITYMANAGER
  • 6 = ACCOUNT_TYPE_GOD

players

Stores character information.

ColumnTypeDefaultDescription
idintAUTO_INCREMENTPrimary key
namevarchar(255)-Character name
group_idint1Group ID for permissions
account_idint0Foreign key to accounts
levelint1Character level
vocationint0Vocation ID
healthint150Current health
healthmaxint150Maximum health
experiencebigint unsigned0Total experience
lookbodyint0Body color
lookfeetint0Feet color
lookheadint0Head color
looklegsint0Legs color
looktypeint136Outfit type
lookaddonsint0Outfit addons
directiontinyint unsigned2Facing direction
maglevelint0Magic level
manaint0Current mana
manamaxint0Maximum mana
manaspentbigint unsigned0Mana spent for magic level
soulint unsigned0Soul points
town_idint1Home town ID
posxint0Last position X
posyint0Last position Y
poszint0Last position Z
conditionsblob-Serialized conditions
capint400Capacity
sexint0Sex (0=female, 1=male)
lastloginbigint unsigned0Last login timestamp
lastipint unsigned0Last IP address
savetinyint1Save on logout
skulltinyint0Skull type
skulltimebigint0Skull expiration
lastlogoutbigint unsigned0Last logout timestamp
blessingstinyint0Blessings bitmask
onlinetimebigint0Total online time (seconds)
deletionbigint0Deletion timestamp (0=not deleted)
balancebigint unsigned0Bank balance
offlinetraining_timesmallint unsigned43200Offline training time
offlinetraining_skillint-1Offline training skill
staminasmallint unsigned2520Stamina minutes
skill_fistint unsigned10Fist fighting level
skill_fist_triesbigint unsigned0Fist fighting tries
skill_clubint unsigned10Club fighting level
skill_club_triesbigint unsigned0Club fighting tries
skill_swordint unsigned10Sword fighting level
skill_sword_triesbigint unsigned0Sword fighting tries
skill_axeint unsigned10Axe fighting level
skill_axe_triesbigint unsigned0Axe fighting tries
skill_distint unsigned10Distance fighting level
skill_dist_triesbigint unsigned0Distance fighting tries
skill_shieldingint unsigned10Shielding level
skill_shielding_triesbigint unsigned0Shielding tries
skill_fishingint unsigned10Fishing level
skill_fishing_triesbigint unsigned0Fishing tries

Trigger: ondelete_players - Sets house owner to 0 when player is deleted.


account_storage

Key-value storage for account data.

ColumnTypeDescription
account_idintForeign key to accounts
keyint unsignedStorage key
valueintStorage value

Primary Key: (account_id, key)


account_viplist

Account VIP list entries.

ColumnTypeDescription
account_idintAccount owning the VIP entry
player_idintTarget player ID
descriptionvarchar(128)Custom description
icontinyint unsignedVIP icon
notifytinyintNotify on login

player_items

Player inventory items.

ColumnTypeDescription
player_idintForeign key to players
pidintParent container slot
sidintSlot ID
itemtypesmallint unsignedItem type ID
countsmallintStack count
attributesblobItem attributes
augmentsblobItem augments
skillsblobItem custom skills
statsblobItem custom stats

player_depotitems

Player depot contents.

ColumnTypeDescription
player_idintForeign key to players
sidintSlot ID (0-100 reserved for lockers)
pidintParent container slot
itemtypesmallint unsignedItem type ID
countsmallintStack count
attributesblobItem attributes
augmentsblobItem augments
skillsblobItem custom skills
statsblobItem custom stats

player_inboxitems

Player inbox items.

ColumnTypeDescription
player_idintForeign key to players
sidintSlot ID
pidintParent container slot
itemtypesmallint unsignedItem type ID
countsmallintStack count
attributesblobItem attributes
augmentsblobItem augments
skillsblobItem custom skills
statsblobItem custom stats

player_rewarditems

Player reward chest items.

ColumnTypeDescription
player_idintForeign key to players
sidintSlot ID (0-100 for offline additions)
pidintParent container slot
itemtypesmallint unsignedItem type ID
countsmallintStack count
attributesblobItem attributes

player_storage

Player storage values (quest progress, etc.).

ColumnTypeDescription
player_idintForeign key to players
keyint unsignedStorage key
valueintStorage value

Primary Key: (player_id, key)


player_spells

Learned spells.

ColumnTypeDescription
player_idintForeign key to players
namevarchar(255)Spell name

player_deaths

Death records.

ColumnTypeDescription
player_idintForeign key to players
timebigint unsignedDeath timestamp
levelintLevel at death
killed_byvarchar(255)Killer name
is_playertinyintKiller is player
mostdamage_byvarchar(100)Most damage dealer
mostdamage_is_playertinyintMost damage is player
unjustifiedtinyintUnjustified kill
mostdamage_unjustifiedtinyintMost damage unjustified

player_namelocks

Name lock records.

ColumnTypeDescription
player_idintForeign key to players
reasonvarchar(255)Lock reason
namelocked_atbigintLock timestamp
namelocked_byintPlayer who locked

player_augments

Player augment data.

ColumnTypeDescription
player_idintForeign key to players
augmentsblobSerialized augment data

player_custom_skills

Custom skill data.

ColumnTypeDescription
player_idintForeign key to players
skillsblobSerialized skill data

player_custom_stats

Custom stat data.

ColumnTypeDescription
player_idintForeign key to players
statsblobSerialized stat data

players_online

Currently online players (MEMORY engine).

ColumnTypeDescription
player_idintPlayer ID currently online

Engine: MEMORY (cleared on server restart)


Guild Tables

guilds

Guild information.

ColumnTypeDescription
idintPrimary key
namevarchar(255)Guild name
owneridintForeign key to players (leader)
creationdataintCreation timestamp
motdvarchar(255)Message of the day
balancebigint unsignedGuild bank balance

Trigger: oncreate_guilds - Creates default ranks on guild creation.


guild_ranks

Guild rank definitions.

ColumnTypeDescription
idintPrimary key
guild_idintForeign key to guilds
namevarchar(255)Rank name
levelintRank level (3=leader, 2=vice, 1=member)

guild_membership

Guild member associations.

ColumnTypeDescription
player_idintForeign key to players
guild_idintForeign key to guilds
rank_idintForeign key to guild_ranks
nickvarchar(15)Guild nickname

guild_invites

Pending guild invitations.

ColumnTypeDescription
player_idintInvited player
guild_idintInviting guild

guild_wars

Guild war declarations.

ColumnTypeDescription
idintPrimary key
guild1intFirst guild ID
guild2intSecond guild ID
name1varchar(255)First guild name
name2varchar(255)Second guild name
statustinyintWar status
startedbigintStart timestamp
endedbigintEnd timestamp
frags_to_endintKills to win

guildwar_kills

Guild war kill records.

ColumnTypeDescription
idintPrimary key
killervarchar(50)Killer name
targetvarchar(50)Target name
killerguildintKiller’s guild
targetguildintTarget’s guild
waridintForeign key to guild_wars
timebigintKill timestamp

House Tables

houses

House definitions.

ColumnTypeDescription
idintPrimary key
ownerintOwner player ID (0=no owner)
paidint unsignedRent paid until
warningsintRent warnings
namevarchar(255)House name
rentintRent amount
town_idintTown ID
bidintCurrent bid
bid_endintAuction end time
last_bidintLast bid amount
highest_bidderintHighest bidder ID
sizeintHouse size (SQM)
bedsintNumber of beds

house_lists

House access lists.

ColumnTypeDescription
house_idintForeign key to houses
listidintList type
listtextAccess list content

tile_store

House tile items.

ColumnTypeDescription
house_idintForeign key to houses
datalongblobSerialized tile data

Market Tables

market_offers

Active market offers.

ColumnTypeDescription
idint unsignedPrimary key
player_idintForeign key to players
saletinyintIs sale offer
itemtypesmallint unsignedItem type ID
amountsmallint unsignedItem amount
createdbigint unsignedCreation timestamp
anonymoustinyintAnonymous offer
priceint unsignedPrice per item

market_history

Completed market transactions.

ColumnTypeDescription
idint unsignedPrimary key
player_idintForeign key to players
saletinyintWas sale offer
itemtypesmallint unsignedItem type ID
amountsmallint unsignedItem amount
priceint unsignedTransaction price
expires_atbigint unsignedOriginal expiration
insertedbigint unsignedTransaction timestamp
statetinyint unsignedTransaction state

Ban Tables

account_bans

Active account bans.

ColumnTypeDescription
account_idintForeign key to accounts
reasonvarchar(255)Ban reason
banned_atbigintBan start timestamp
expires_atbigintBan end timestamp
banned_byintBanning player ID

account_ban_history

Historical ban records.

ColumnTypeDescription
idint unsignedPrimary key
account_idintForeign key to accounts
reasonvarchar(255)Ban reason
banned_atbigintBan start timestamp
expired_atbigintBan end timestamp
banned_byintBanning player ID

ip_bans

IP address bans.

ColumnTypeDescription
ipint unsignedIP address (integer)
reasonvarchar(255)Ban reason
banned_atbigintBan start timestamp
expires_atbigintBan end timestamp
banned_byintBanning player ID

Utility Tables

server_config

Server configuration storage.

ColumnTypeDescription
configvarchar(50)Config key
valuevarchar(256)Config value

Entity Relationship Diagram

accounts (1) ──────────< (N) players
│ │
│ ├──< player_items
│ ├──< player_depotitems
│ ├──< player_inboxitems
│ ├──< player_rewarditems
│ ├──< player_storage
│ ├──< player_spells
│ ├──< player_deaths
│ ├──< player_augments
│ ├──< player_custom_skills
│ ├──< player_custom_stats
│ │
├──< account_storage └──< guild_membership ──> guilds
├──< account_viplist │
└──< account_bans ├──< guild_ranks
├──< guild_invites
└──< guild_wars
houses ──< house_lists └──< guildwar_kills
└──< tile_store
market_offers ──> players
market_history ──> players

Database Maintenance

Optimization

Run periodically to optimize tables:

OPTIMIZE TABLE players, player_items, player_depotitems;

Cleanup Queries

Remove deleted players:

DELETE FROM players WHERE deletion > 0 AND deletion < UNIX_TIMESTAMP();

Remove expired bans:

DELETE FROM account_bans WHERE expires_at < UNIX_TIMESTAMP();
DELETE FROM ip_bans WHERE expires_at < UNIX_TIMESTAMP();

Clean expired market offers:

DELETE FROM market_offers WHERE created + (30 * 24 * 60 * 60) < UNIX_TIMESTAMP();