Event Hooks

GSP-Panel has a hook system that allows developers to bind to core events. In order to use hooks you will need to create a plugin and place it in includes\plugins\plugin_name\plugin_name.php. A skeleton hook plugin can be found in includes\plugins\skeletons\hooks.php.

Hook Points

Hook Variables Return Description
servermon_start None None This is called when the server monitor is started
servermon_end None None This is called at the end of the server monitor
maintenance_optimize None None
maintenance_optimize_override None None This overrides our standard maintenance procedures
game_query_replace Array of game information Array of game information This is called when a game is queried for the status
addon_installed Users game ID, Addon ID None This is called after an add install has completed
game_suspended Users game ID None This is called after a game server is suspended
game_unsuspended Users game ID None This is called after a game server is unsuspended
gameinstall_finished Users game ID None This is called after the user's game has been installed
backup_completed Users game ID None This is called after a user's game has been backed up
loadbalance See below for more information
rcon_override Same as RCON::SendCommand Same as RCON::SendCommand This is called when a game is issued an rcon command from the console

loadbalance

This is called when a new game server is being added or moved to a new host. This allows you to over-ride the default load balance algorithm.

Variables (Passed as a key-value pair)

  • params - An array of information that was passed to Games::FindSuitableHost
  • servers - An array of servers with quota utilization already calculated

Return

  • An array of servers with the same information that was in the array that was passed. This array should be sorted in preference (0 being higher preference)

Example

Here is our hook file that will be placed in includes\hooks\example.php

<?php
 
use GSPPanel\{Plugins, Email};
 
class Hooks
{
    // Plugin meta data
    private $name = "Skelton Hook Plugin";
    private $url = "http://gsp-panel.com";
    private $description = "This is an example plugin that binds to hooks";
    private $version = "1.0";
    private $author = "GSP-Panel";
    private $type = "hook";
 
    // Returns an array of plugin details
    public function PluginDetails()
    {
        return array("name" => $this->name, "type" => $this->type, "url" => $this->url, "description" => $this->description, "version" => $this->version, "author" => $this->author);
    }
 
    // Initialize the plugin
    public function Init()
    {
        // This is called when the plugin is loaded
        // This is a good place to check any custom databases, bind events, setup variables, etc
 
        // Bind to the addon_installed event which will call the addon_email function with a priority of 1 (first addon_installed hook to get called)
        Plugins::getInstance()->bindEvent("addon_installed", get_class(), "addon_email", 1);
    }
 
    public function Install()
    {
        // This is called when the plugin is enabled
        // return true for a successful install or false for a failed install
        return array("status" => true);
    }
 
    public function Uninstall()
    {
        // This is called when the plugin is disabled
        // return true for a successful uninstall or false for a failed uninstall
        return array("status" => false, "error" => "Unable to install plugin");
    }
 
    /**
     * This function is called when addon_installed event is triggered
     */
    public function addon_email($ugid, $addonid)
    {
        $addons = array("4");
        // If the addon is in the above array, send an email
        if(in_array($addonid, $addons))
        {
            Emails::SendMail(array("subject" => "test", "content" => "your content", "email" => "[email protected]"));
        }
    }
 
}
?>