Authoring XA Modules
[edit] OverviewThis article discusses all of the things you need to do in order to develop a module for Extensible Admin. [edit] Name and location for you XA moduleYour module and all it's data files are stored inside the following folder: addons/eventscripts/xa/modules/yourmodule/ Your main Python file in this case would be: yourmodule.py [edit] Starting to code an XA moduleTo make use of xa you need to import the main library (which is unsurprisingly named xa!). from xa import xa [edit] Registering your module with XAThe first thing you need to do in the module load section is to register your module with XA. The xa.register(<name>) method returns a class providing access to XA functionality for use in the module. The class instance is also a required argument for some addition XA libraries / methods (notably the xa.setting library). # The register module allows you to connect yourself to the XA API xa.register(<name>)
Unregistering a module is done via xa.unregister(<name>), alternatively you can call unregister on your XA module instance (e.g. <my module>.unregister()). Example: from xa import xa def load(): global test # Register the module test = xa.register("test") def unload(): # Unregister the module test.unregister() Note that for now you should always use the base name of the module when registering it - due to the way XA tracks addons. In the future this may not be necessary but is probably recommended [edit] Settings and Server VariablesAny configuration variables needed in your script should be set via the xa.setting library. This creates server Cvars for your variables, handles Mani compatibility (see section below) and provides an interface for admins to edit these settings. The library interface is simple to use. The first time a module is loaded XA creates and stores the variables it creates, these can be edited by admins via menu's (this functionality is provided by a separate module) or in the server console. If the module is loaded again XA simply restores the previous settings from file.
[edit] xa.setting methodsxa.setting provides the following methods: # Server Variables # Note: All those methods automatically add the 'xa_' or 'mani_' prefixes! # Create a variable (returns the es.ServerVar instance of the variable) myvar = mymodule.setting.createVariable(<var name>, <default value>, <optional:description>) # Returns the es.ServerVar instance of the variable as stored by XA myvar = mymodule.setting.getVariable(<var name>) # Deletes the named variable from the module and sets it's es.ServerVar instance to 0 mymodule.setting.deleteVariable(<var name>) # KeyValues # Create a KeyValues object inside the XA data myvar = mymodule.setting.createKeyValues() # Returns the created KeyValues object as stored by XA myvar = mymodule.setting.useKeyValues() # Saves XA's data file with all the KeyValues objects of the modules xa.setting.deleteVariable()
[edit] Example usageimport es from xa import xa def load(): global mymodule # Register the module mymodule = xa.register("test") # Create the variable myvar = mymodule.setting.createVariable('test_var', '1', "A test variable!") def player_death(event_var) # Check the setting is greater than 0 (On if mymodule.setting.getVariable('test_var') != "0": es.tell(event_var["userid"], "Hello World!")
[edit] Displaying in the Admin Menu
This snippet from the xaplayers.py (Player Management) shows how to display a menu inside XA's main menu: def load(): #Load Function for Player Settings for XA. xaplayermenu = popuplib.easymenu("xaplayermenu", "_tempcore", _select_option) xaplayermenu.settitle(xalanguage["choose option"]) xaplayers.addMenu("xaplayermenu", xalanguage["manage players"], "xaplayermenu", "punish_player", "#admin")
[edit] Say and Console Commands
This snippet from the xasettings.py (Player Settings) shows how to register Say and Console commands with XA: def load(): #Load Function for Player Settings for XA. xasettingmenu = popuplib.easymenu("xasettingmenu", "_tempcore", _select_setting) xasettingmenu.settitle(xalanguage["player settings"]) xacommand = xasettings.addCommand("settings", _send_menu, "change_playersetting", "#all") xacommand.register(["console","say"]) [edit] Mani Compatibility
XA fully supports compatibility with the mani_server.cfg configuration file, the intention with XA is to provide Mani users with an easy upgrade option that can use their current setup and options. Mani cvar compatibility is managed via the xa.setting library (via a separate manilib library) and can be turned on and off at will by the server admin. If you wish to make your module backwards compatible with Mani then you must name your server variables appropriately, variables are created in the normal way (see above) but xa.settings is clever enough to use Mani substitutes if Mani mode is on.
To use Mani vars you must name your variables the same as the Mani equivalent you wish to use without the "mani_" prefix; eg: "blind_ghosters" NOT "mani_blind_ghosters". Try this example; shortened from the IP Ghosting module it checks a specific Mani var when a player dies. import es from xa import xa ghosting = xa.register('xaipghosting') def load(): # Create the variable you want to use (in this case we are wanting to use mani_blind_ghosters) # Note how the variable is set up EAXACTLY in the normal way - only the naming is important ghosting.setting.createVariable('blind_ghosters', '1', "XA: Blind IP Ghosters when they die (1=On, 0=Off)") def player_death(event_var): ''' Checks for the variable and if set fails to blind you :P .... ''' if ghosting.setting.getVariable('blind_ghosters') != "0": es.tell(event_var["userid"], "If you were a ghoster we could blind you now!") You can use this method for ANY of the variables in the cfg/mani_server.cfg file. In terms of admins XA supports the clients.txt file via a special Auth provider when Mani compatibility is turned on.
[edit] LoggingThe library xa.logging provides log capabilities for your modules. the log() method saves the text into a file in your XA logs folder (xa/logs/l<day><month>000.log). It does also forward the text to the server logs. Example: from xa import xa test = xa.register("test") test.logging.log("Testing the log capabilities") def player_jump(event_var): test.logging.log("The player jumped!", int(event_var['userid'])) [edit] Examples[edit] See Also |
|


