User Database & Utility API

Overview

The User Database & Utility API provides comprehensive functions for user management, database operations, and cross-resource communication. This system handles user creation, lookups, ban management, and unique identifier generation, utilizing the Tunnel/Proxy pattern for seamless client-server communication.

Tunnel & Proxy System

The API utilizes a modified vRP-style Tunnel and Proxy system for inter-resource communication:

  • Tunnel: Provides two-way communication between server and clients with async support

  • Proxy: Enables function calls between different resources on the same side

Basic Usage

To enable the library inside of your resource just add @frp_lib/library/linker.lua as a shared_script in your fxmanifest.lua file.

shared_scripts {
    '@frp_lib/library/linker.lua',
}

Or if the library is the only shared script you use you can do:

shared_script '@frp_lib/library/linker.lua'
-- Import the API using Proxy
local API = Proxy.getInterface("API")

-- Or using Tunnel for client-server communication
local cAPI = Tunnel.getInterface("API")

User Creation & Management

API.CreateUser

Creates a new user account with credentials in the database.

Parameters

  • playerId (number): The player's server source ID

  • mappedIdentifiers (table): Mapped player identifiers containing all platform identifiers

Returns

  • userId (number): The newly created user ID

  • nil: If creation failed

Example

What it does

  • Creates user record with player name

  • Stores all platform credentials (Steam, Discord, License, etc.)

  • Integrates with external systems (prime_api)

  • Logs user creation for auditing

Database Structure


User Lookup Functions

API.GetUserIdentifiersByIdentifier

Retrieves all identifiers for a user by a specific identifier.

Parameters

  • identifier (string): The identifier value to search for

  • identifierKey (string): The type of identifier ("steam", "discord", "license", etc.)

Returns

  • credentials (table): Complete user credentials record

  • nil: If no user found

Example


API.GetUserIdByIdentifier

Gets a user ID by a specific identifier.

Parameters

  • identifier (string): The identifier value to search for

  • identifierKey (string): The type of identifier

Returns

  • userId (number): The user's database ID

  • nil: If no user found

Example


API.GetUserIdByIdentifiers

Gets a user ID using the primary identifier from a list of identifiers.

Parameters

  • identifiers (table): Array of player identifiers

  • name (string): Player name (currently unused)

Returns

  • userId (number): The user's database ID

  • nil: If no user found

Example


Character & User Data Retrieval

API.GetCharacterFromCitizenIdOffline

Retrieves character data by citizen ID from the database (offline lookup).

Parameters

  • citizenId (string): The character's citizen ID

Returns

  • character (table): Complete character database record

  • nil: If character not found

Example


API.GetCharacterFromCharId

Retrieves character data by character ID from the database.

Parameters

  • charId (number): The character's database ID

Returns

  • character (table): Complete character database record

  • nil: If character not found

Example


API.GetUserFromUserIdOffline

Retrieves user data by user ID from the database (offline lookup).

Parameters

  • userId (number): The user's database ID

Returns

  • user (table): Complete user database record

  • nil: If user not found

Example


API.GetUserCharactersOffline

Retrieves all characters for a user (offline lookup).

Parameters

  • userId (number): The user's database ID

Returns

  • characters (table): Array of character records

  • {}: Empty array if no characters found

Example


Active User Management

API.GetUserFromUserId

Gets an active user object by user ID.

Parameters

  • userId (number): The user's database ID

Returns

  • User (table): The active user object

  • nil: If user is not online

Example


API.GetUserIdFromServerId

Gets a user ID from a server source ID.

Parameters

  • source (number): The player's server source ID

Returns

  • userId (number): The user's database ID

  • nil: If user not found

Example


API.GetUserFromSource

Gets an active user object by server source ID.

Parameters

  • source (number): The player's server source ID

Returns

  • User (table): The active user object

  • nil: If user not found

Example


API.GetUserFromCharId

Gets an active user object by character ID.

Parameters

  • charId (number): The character's database ID

Returns

  • User (table): The active user object

  • nil: If user not online or character not found

Example


API.GetUserFromCitizenId

Gets an active user object by citizen ID.

Parameters

  • citizenId (string): The character's citizen ID

Returns

  • User (table): The active user object

  • nil: If user not online or character not found

Example


API.GetUserFromDiscordId

Gets an active user object by Discord ID.

Parameters

  • discordId (string): The user's Discord ID (without "discord:" prefix)

Returns

  • User (table): The active user object

  • nil: If user not online

Example


API.GetUserIdFromCharId

Gets a user ID from a character ID (with fallback to database).

Parameters

  • charId (number): The character's database ID

Returns

  • userId (number): The user's database ID

  • nil: If character not found

Example


API.GetUsers

Gets all currently active user objects.

Returns

  • users (table): Table of all active users indexed by user ID

Example


Ban Management System

API.SetBanned

Bans a user and kicks them from the server.

Parameters

  • source (number): The player's server source ID (for kicking)

  • userId (number): The user's database ID to ban

  • reason (string): Reason for the ban

Returns

  • None

Example


API.UnBan

Removes a ban from a user account.

Parameters

  • source (number): Command source (not used currently)

  • userId (number): The user's database ID to unban

Returns

  • None

Example


API.IsBanned

Checks if a user is currently banned.

Parameters

  • userId (number): The user's database ID to check

Returns

  • banned (boolean): True if user is banned, false otherwise

Example


Cache Management

API.ClearUserFromCache

Removes a user from all caches and tracking tables.

Parameters

  • source (number): The player's server source ID

  • userId (number): The user's database ID

Returns

  • None

Example

Console Command

Clears a specific user from cache (console only).


Unique ID Generation

API.CreateCitizenId

Generates a unique citizen ID for new characters.

Returns

  • citizenId (string): A unique citizen ID (format: A1234)

Example

Algorithm

  • Combines random string (1 char) + random number (4 digits)

  • Ensures uniqueness by checking against existing characters

  • Uppercase format for consistency


API.GenerateCharFingerPrint

Generates a unique fingerprint for new characters.

Returns

  • fingerprint (string): A unique fingerprint string

Example

Algorithm

  • Complex pattern: String(2) + Number(3) + String(1) + Number(2) + String(3) + Number(4)

  • Stored in character metadata as JSON

  • Ensures uniqueness against existing character fingerprints


Usage Examples

Complete User Connection Flow

Admin User Management Commands

Character Management Integration

Ban Management System

Performance Monitoring

Tunnel/Proxy Integration Examples

Server-Side API Export

Client-Side Usage

Cross-Resource Server Usage

Best Practices

Error Handling

Performance Optimization

Database Safety

Security Considerations

  1. Input Validation: Always validate user inputs before database queries

  2. Rate Limiting: Implement rate limits for user creation and lookups

  3. Permission Checks: Verify permissions before sensitive operations

  4. Audit Logging: Log all user management operations

  5. Cache Management: Regularly clean up disconnected users from memory

This comprehensive API provides robust user management capabilities with efficient caching, cross-resource communication, and database safety features.

Last updated