Skip to main content

What are Plugins?

The CoD4 Unleashed Server plugin system uses the IceOps Plugin API to provide powerful extensions for your game server. Plugins are shared library files (.so files on Linux) that can hook into server events, add custom commands, and interact with game state.
Plugins are based on the IceOps Plugin API developed by Ninja and TheKelm of the IceOps-Team.

Architecture

The plugin system is built with performance and security in mind:
  • Maximum of 25 plugins can be loaded simultaneously
  • Each plugin can register up to 20 commands
  • Each plugin can have up to 36 script functions and 36 script methods
  • Plugins can export up to 50 functions for use by other plugins
  • Each plugin has isolated memory management with up to 50 malloc allocations tracked

Plugin Structure

Every plugin must implement two core functions:
#include "../pinc.h"

PCL int OnInit() {
    // Initialize your plugin here
    Com_Printf("Plugin loaded successfully!\n");
    return 0; // Return 0 for success, negative for failure
}

PCL void OnInfoRequest(pluginInfo_t *info) {
    // MANDATORY: Set handler version
    info->handlerVersion.major = PLUGIN_HANDLER_VERSION_MAJOR;
    info->handlerVersion.minor = PLUGIN_HANDLER_VERSION_MINOR;
    
    // OPTIONAL: Plugin metadata
    info->pluginVersion.major = 1;
    info->pluginVersion.minor = 0;
    strncpy(info->fullName, "My Plugin", sizeof(info->fullName));
    strncpy(info->shortDescription, "Does awesome things", sizeof(info->shortDescription));
}

Plugin Events

Plugins can hook into various server events by implementing callback functions. All event callbacks are optional except OnInit and OnInfoRequest.

Available Events

EventDescriptionFrequency
OnFrameCalled every server frame~20ms
OnOneSecondCalled every second1s
OnTenSecondsCalled every 10 seconds10s
OnPlayerConnectPlayer connects to serverPer connection
OnPlayerDCPlayer disconnectsPer disconnect
OnClientAuthorizedClient passes authorizationPer client
OnClientSpawnClient spawns in gamePer spawn
OnClientEnterWorldClient enters game worldPer client
OnMessageSentChat message sentPer message
OnExitLevelMap is changingPer map change
OnSpawnServerServer startsOnce
OnPreFastRestartBefore fast_restartPer restart
OnPostFastRestartAfter fast_restartPer restart
OnClientUserinfoChangedClient info updatedPer change
OnClientMoveCommandClient movement commandPer frame/client
OnPlayerWantReservedSlotReserved slot checkPer connection
OnTcpServerPacketTCP packet receivedPer packet
OnUdpNetEventUDP network eventPer event
OnUdpNetSendUDP packet sendPer send
OnFilesystemStartedFilesystem initializedOnce
Most plugin functions are not thread-safe. Always call plugin API functions from within event callbacks or registered commands.

Memory Management

Always use Plugin_Malloc() and Plugin_Free() instead of standard C malloc() and free().
The plugin handler tracks all memory allocations to prevent memory leaks when plugins are unloaded:
void* buffer = Plugin_Malloc(1024);
if (buffer == NULL) {
    Plugin_Error(P_ERROR_DISABLE, "Failed to allocate memory");
    return;
}

// Use the buffer...

Plugin_Free(buffer);

Why Use Plugin Memory Functions?

  1. Automatic cleanup: Memory is freed when plugin unloads
  2. Double-free protection: Safe to call Plugin_Free() multiple times
  3. Tracking: Server monitors memory usage per plugin

Plugin Types

Regular Plugins

Standard plugins that can be loaded and unloaded at runtime:
loadPlugin myplugin
unloadPlugin myplugin

Library Plugins

Plugins that export functions for other plugins cannot be unloaded:
// Exporting functions makes a plugin a "library plugin"
PCL void MyExportedFunction() {
    // This function can be called by other plugins
}
Library plugins and script-library plugins (those that add script functions/methods) cannot be unloaded during runtime for safety reasons.

Secure Mode

When the server runs in secure mode (com_securemode enabled), only plugins with verified checksums will load. This prevents unauthorized plugins from running on production servers.
// From plugin_handler.c:178-240
#define PLUGINCENSOR_HASH "bfb496df0acc1bd01a0789b8d35d8081143db883297206aa"
#define PLUGINANTISPAM_HASH "7fc95f3902bd809a1e50a783fbb482044f67ad8927259a36"
#define PLUGINGAMERANGER_HASH "6609a69715a41b486611fa1c461f90acfed836eac0e699d8"

Commands

The server provides built-in commands for managing plugins:

loadPlugin

Load a plugin from the plugins/ directory
loadPlugin myplugin

unloadPlugin

Unload a running plugin
unloadPlugin myplugin

plugins

List all loaded plugins
plugins

pluginInfo

Show detailed info about a plugin
pluginInfo myplugin

Next Steps

Installation

Learn how to install plugins

Development

Start developing your own plugins

API Reference

Explore the complete plugin API

Examples

See real plugin examples

Build docs developers (and LLMs) love