Server-level Plugin

From EsWiki

Jump to: navigation, search

A server-level plugin is initialized when the server boots, and is always active. Any plugin that deals with logging in must be a server-level plugin. Games that use the Game Manager need a server-level plugin as well. Other plugins may be made server-level simply because it is less effort for a client to use a server-level plugin than it is to use a room-level plugin.

This article assumes that you are familiar with developing room-level plugins. See Extensions and Plugins for more details.

Contents

Extend BasePlugin

Create a Java class that extends BasePlugin. You need to override the init() method:

    @Override
    public void init(EsObjectRO parameters) {
        System.out.println("(name of plugin) initialized.");
    }

The init method of a server-level plugin is invoked by the server when the plugin is loaded, when the server boots. The parameters object will contain any variables specified in the Extension.xml file for this plugin. It's an extremely good idea to include the System.out.println line above at the end of your init method. It will display on the server console, so you can verify that the plugin has been set correctly as a server-level plugin. Alternatively, you can use Logging instead of System.out.println, which will write to the server log as well as the console.

The init method can also be used to test a method in the plugin class. Invoke the method in init, and have the output display using System.out.println.


Deploy the Extension

Finish writing the plugin in the same way you would do a room-level plugin.

The Extensions article gives details on how room-level extensions are structured and placed in the ES4InstallationFolder/server/extensions folder. Follow these steps first.

Add the Server-Level Component

After placing the needed files into the extensions folder, reboot the ElectroServer, then go to the web admin's Extensions tab. You should see your new extension listed, with no server-level component. Click the New Server-level Component button, and choose the plugin that needs to be server-level. Normally the name of the plugin is the same as the handle. Save, then reboot the server again.

Check the server console to see the line of text output that you placed at the bottom of your init method, to verify that your plugin was initialized. You are now ready to test!

Order of Plugins

It's important to note that if you have multiple plug-ins in your extension (as is often the case). And, some plug-ins depend on other plug-ins, you need to have the plug-ins load as components in order.

Example: TestDatabasePlugin depends on DatabasePlugin

Image:ExampleServerPluginOrder.jpg

Using a Server-level Plugin

From the client-side perspective, using a server-level plugin is easier than a room-level plugin. You do not have to add a plugin to the room you are in. Here is some sample code for the client to send a plugin request to a server-level plugin.

   var pm:PluginRequest = new PluginRequest();
   pm.setPluginName("InvokerPlugin");
   var esob:EsObject = new EsObject();
 
   //...fill the esob with whatever the plugin needs...
 
   pm.setEsObject(esob);
   es.send(pm)

Comparison to Room-level Plugins

Room-level plugins do not need a server component. After you add the plugin to the extension and reboot the server, it's available without doing anything with the web admin. The client side is more complicated. You can see an example of how this is done in the PluginPublicMessage example. When you create a room, you have to add each room-level plugin that this room will be using. When you need to make a plugin request, in addition to the lines the server-level plugin needs, you also need to set the roomId and zoneId for the PluginRequest.

Personal tools
download