Connections

The library handles some basic player connection stuff.

This is primarly used to get and set unique id's on users that join the server.

When a player joins a user_account is created for them if one does not already exist, here we can track things like the users vip levels, bans, permissions ranks and so on.

Connections functions are server side only.

Database Tables

The user_accounts table will be created automatically on load if one does not already exist. If you wish to add anything additional to the table you are free to do so.

local CREATE_TABLE = [[
    CREATE TABLE IF NOT EXISTS `user_accounts` (
        `id` int NOT NULL AUTO_INCREMENT,
        `name` varchar(255) NOT NULL,
        `unique_id` varchar(255) NOT NULL,
        `rank` varchar(255) NOT NULL DEFAULT 'civ',
        `vip` int(1) NOT NULL DEFAULT 0,
        `priority` int(11) NOT NULL DEFAULT 0,
        `character_slots` int(11) NOT NULL DEFAULT 2,
        `license` varchar(255) NOT NULL,
        `discord` varchar(255),
        `tokens` json NOT NULL,
        `ip` varchar(255) NOT NULL,
        `banned` boolean DEFAULT false,
        `banned_by` varchar(255) NOT NULL DEFAULT 'auto_ban',
        `reason` text DEFAULT NULL,
        `created` timestamp NOT NULL DEFAULT current_timestamp(),
        PRIMARY KEY (`unique_id`),
        KEY (`license`),
        KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
]]

Functions

utils.connections.get_users = get_users
utils.connections.get_user = get_user
utils.connections.get_identifier = get_identifier
utils.connections.get_unique_id = get_unique_id

get_users

The following can be used to retrieve all connected users registered by the connection logic.

local connected_users = utils.connections.get_users()

if connected_users then
    utils.tables.print(connected_users) 
end

get_user

The following can be used to retrieve a specific user from the connected users using their source id.

local _src = source
local user = utils.connections.get_user(_src)

get_identifier

The following can be used to retrieve a players identifier by specifying its string name.

local _src = source
local id = 'license'
local identifier = utils.connections.get_identifier(_src, id)

if identifier then
    print('ID: ' .. identifier)
end

get_unique_id

The following can be used to retrieve a players unique ID. To do this you should first retrieve the users license.

local _src = source
local identifier = utils.connections.get_identifier(_src, 'license')

local unique_id = utils.connections.get_unique_id(identifier)

if unique_id then
    print('ID: ' .. unique_id)
end

Last updated