Skip to content

Alliance System

The Alliance system is a guild/clan feature for Tycoon that allows players to form groups, donate resources, and earn collective benefits.

Overview

  • Backend: MariaDB (SQL)
  • Main file: alliance.sk (2,862 lines)
  • Features: Roles, donations, audit logs, tag colors

Database Schema

alliances table

CREATE TABLE alliances (
    alliance_id INT AUTO_INCREMENT PRIMARY KEY,
    alliance_tag VARCHAR(4) UNIQUE NOT NULL,
    alliance_name VARCHAR(50),
    alliance_description TEXT,
    director_uuid VARCHAR(36),
    created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    grade INT DEFAULT 1,
    level INT DEFAULT 1,
    experience BIGINT DEFAULT 0,
    balance_credits BIGINT DEFAULT 0,
    balance_ethea INT DEFAULT 0,
    tax_rate DECIMAL(5,2) DEFAULT 0.05,
    tag_color VARCHAR(20) DEFAULT 'white',
    status ENUM('active', 'inactive') DEFAULT 'active'
);

alliance_members table

CREATE TABLE alliance_members (
    member_uuid VARCHAR(36),
    alliance_id INT,
    role ENUM('director', 'supervisor', 'member') DEFAULT 'member',
    joined_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    contribution_credits BIGINT DEFAULT 0,
    contribution_ethea INT DEFAULT 0,
    contribution_items BIGINT DEFAULT 0,
    PRIMARY KEY(member_uuid, alliance_id)
);

alliance_audit_log table

CREATE TABLE alliance_audit_log (
    log_id INT AUTO_INCREMENT PRIMARY KEY,
    alliance_id INT,
    actor_uuid VARCHAR(36),
    target_uuid VARCHAR(36),
    action_type VARCHAR(50),
    amount INT,
    item_type VARCHAR(50),
    old_value TEXT,
    new_value TEXT,
    action_details TEXT,
    timestamp BIGINT  -- Unix timestamp
);

Roles & Permissions

Role Invite Kick Promote Donate View Info
Director
Supervisor
Member

Commands

/alliance              # Open alliance menu
/alliance create       # Create new alliance
/alliance invite       # Invite player
/alliance kick         # Remove member
/alliance leave        # Leave alliance
/alliance disband      # Delete alliance (director only)
/alliance deposit      # Donate to alliance
/alliance log          # View audit log

Key Functions

Permission Check

function hasAlliancePermission(uuid: text, action: text) :: boolean:
    # Get player's role
    # Check if action is allowed for role
    # Return true/false

Broadcast to Members

function allianceBroadcast(allianceID: integer, message: text):
    # Query all online members
    # Send message to each

Audit Logging

function logAllianceAction(allianceID, actor, action, target, amount, ...):
    # Insert into audit_log table
    # Records all significant actions

Caching

Alliance data is cached in memory for performance:

{-alliance::%uuid%::id}        # Alliance ID
{-alliance::%uuid%::name}      # Alliance name
{-alliance::%uuid%::tag}       # Alliance tag
{-alliance::%uuid%::role}      # Player's role
{-alliance::%uuid%::ethea}     # Alliance Ethea balance
{-alliance::%uuid%::tag_color} # Tag color

Cache is refreshed: - On player join - After database modifications - Every 5 minutes (scheduled task)

GUI

Alliance uses SkGui for menu interfaces:

  • Main menu: Overview, members, settings
  • Members list: View all members with roles
  • Audit log: Recent activity history
  • Settings: Tag color, description

Troubleshooting

Alliance not loading

  1. Check database connection
  2. Verify {sql::db::alliance} handle exists
  3. Check for SQL errors in console

Members not seeing updates

  1. Force cache refresh: re-login
  2. Check cache variables directly
  3. Verify database sync

Audit log not recording

  1. Check logAllianceAction function
  2. Verify audit_log table exists
  3. Check for SQL insert errors