Plugin info and interop

uint32_t PluginFuncs.GetServerVersion(void)
Returns:The netcode version of the server.
Return type:uint32_t

The server version returned by the plugin API does not correspond to release versions like “0.4.6,” but is a number that increases monotonically with each netcode revision.

Differences in the hundreds place (e.g. 64500, 64600, 64750) indicate breaking changes. Clients with different netcode versions will not be able to connect. For example, clients with netcode versions 64400 or 64600 cannot connect to servers with netcode versions 64500-64599.

vcmpError PluginFuncs.ExportFunctions(int32_t pluginId, const void** functionList, size_t size)

Exports a list of function pointers so that other plugins can call into functions provided by the current plugin.

Parameters:
  • pluginId (int32_t) – The ID of the plugin providing the exported functions. Should be the same as the plugin ID you specify in VcmpPluginInit().
  • functionList (const void**) – A pointer to an array or struct of data; typically should be function pointers, but can have its own struct elements.
  • size (size_t) – The size of the data being exported.
Raises:

vcmpErrorNoSuchEntity if a plugin matching the given pluginId cannot be found.

Example

Exporting plugin
typedef struct {
    uint32_t structSize;

    void (*MyExportedPluginFunction)(char* szMessage);
} MyPluginExports;

void MyPluginFunction(char* szMessage) {
    if (szMessage != NULL) {
        printf("%s\n", szMessage);
    }
}

MyPluginExports exports;

uint32_t VcmpPluginInit(PluginFuncs* funcs, PluginCallbacks* callbacks, PluginInfo* info) {
    info->name[0] = '\0';
    strncat(info->name, "MySpecialPlugin", sizeof(info->name) - 1);

    exports.structSize = sizeof(MyPluginExports);
    exports.MyExportedPluginFunction = MyPluginFunction;
    funcs->ExportFunctions(info->pluginId, (void**)&exports, sizeof(exports));

    return 1;
}
Importing plugin
typedef struct {
    uint32_t structSize;

    void (*MyExportedPluginFunction)(char* szMessage);
} MyPluginImports;

uint32_t VcmpPluginInit(PluginFuncs* funcs, PluginCallbacks* callbacks, PluginInfo* info) {
    int32_t exportPluginId = funcs->FindPlugin("MySpecialPlugin");
    if (exportPluginId != -1) {
        size_t exportSize;
        const void** exports = funcs->GetPluginExports(exportPluginId, &exportSize);

        if (exports != NULL && exportSize == sizeof(MyPluginImports)) {
            const MyPluginImports* imports = (const MyPluginImports*)exports;
            imports->MyExportedPluginFunction("Hello, world!");
        }
    }

    return 1;
}
uint32_t PluginFuncs.GetNumberOfPlugins(void)
Returns:The number of plugins loaded on the server
vcmpError PluginFuncs.GetPluginInfo(int32_t pluginId, PluginInfo* pluginInfo)

Gets information about a plugin given its ID.

Parameters:
  • pluginId (int32_t) – The ID of the plugin to get info for
  • pluginInfo (PluginInfo*) – A pointer to a PluginInfo struct to store the plugin info in.
Raises:

vcmpErrorNoSuchEntity if no plugin with the given ID can be found.

vcmpErrorNullArgument if the pluginInfo argument is null.

int32_t PluginFuncs.FindPlugin(const char* pluginName)
Parameters:
  • pluginName (const char*) – The name of the plugin to find the ID of
Returns:

The ID of the plugin, or -1 if no plugin with that name can be found

const void** PluginFuncs.GetPluginExports(int32_t pluginId, size_t* exportSize)

Gets an exported list of functions from another plugin.

Parameters:
  • pluginId (int32_t) – The ID of the plugin providing the exported functions.
  • size (size_t*) – A pointer to a size_t that will hold the size of the plugin’s exports if found.
Returns:

NULL if no exports are present, a pointer to the exports otherwise.

Raises:

vcmpErrorNoSuchEntity if a plugin matching the given pluginId cannot be found.

See also:

PluginFuncs.ExportFunctions()

Note

You must call PluginFuncs.GetLastError() to check if an error condition was raised.

vcmpError PluginFuncs.SendPluginCommand(uint32_t commandIdentifier, const char* format, ...)

Broadcasts a command message to all plugins.

Parameters:
  • commandIdentifier (uint32_t) – A unique 32-bit integer identifying what kind of command is being sent.
  • format (const char*) – A printf format string.
  • ... – The data to substitute into the format string, if needed.
Raises:

vcmpErrorNullArgument if format is null.

vcmpErrorTooLargeInput if the resulting string is longer than 8192 bytes (8KiB).

See also:

PluginCallbacks.OnPluginCommand()

uint64_t PluginFuncs.GetTime(void)
Returns:The number of milliseconds elapsed since the system started. Not suitable for getting wall time.
vcmpError PluginFuncs.LogMessage(const char* format, ...)

Logs a message to the server console and to serverlog.txt.

Parameters:
  • format (const char*) – A printf format string.
  • ... – The values to substitute into the format string, if needed.
Raises:

vcmpErrorNullArgument if format is null.

vcmpErrorTooLargeInput if the resulting string is longer than 8192 bytes (8KiB).

vcmpError PluginFuncs.GetLastError(void)
Returns:The last error raised by a plugin function call.