Custom Scripts
Revision as of 12:54, 11 January 2013 by TCAWiki (talk | contribs) (→Capture values before executing the script)
TCAdmin supports the following scripting engines:
- Iron Python
- Batch/Shell script Object properties and variables are converted to environment variables.
- Use Linux environment variables like this: ${Object_Property}
- Use Windows environment variables like this: %Object_Property%
You can specify if you want to run your script on Windows servers, Linux servers, or both.
Contents
Script Events
The following events are supported:
- Before created
- Occurs before any files and folders have been created.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- After created
- Occurs after the service files have been created but before it has been configured as a service. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- Before deleted
- Occurs before the delete process is started. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- After deleted
- Occurs after the service files have been deleted and it has been removed from the database.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- Before reinstall
- Occurs before the service files have been deleted. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- After reinstall
- Occurs after the service has been reinstalled but before it has been configured as a service. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- Before move
- Occurs before the service has been moved. It is executed on the server where the service is currently located. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- After move
- Occurs after the service has been moved. It is executed on the server where the service was moved to. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- Custom Icon
- Allows the user to execute the script by clicking on an icon in the service's home page. The script can also be configured as a scheduled task. This requires the "Scheduled Script" feature permission in the game's settings. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- Custom Action
- Allows the user to execute the script by clicking on the link in the service's Actions tab. The script can also be configured as a scheduled task. This requires the "Scheduled Script" feature permission in the game's settings. The script is executed in the service's root directory.
- Available objects: ThisServer, ThisGame, ThisUser, ThisService
- Before started (executed by the Service Manager)
- Occurs before the service is started. The script is executed in the service's working directory. After creating or updating a script with this event go to the game's settings and click on Update Existing Services or go to a game server's service settings and click on Save.
- Available variables: Service Manager Scripting Variables
- After started (executed by the Service Manager)
- Occurs after the service is started. The script is executed in the service's working directory. After creating or updating a script with this event go to the game's settings and click on Update Existing Services or go to a game server's service settings and click on Save.
- Available variables: Service Manager Scripting Variables
- Before stopped (executed by the Service Manager)
- Occurs before the service is stopped. The script is executed in the service's working directory. After creating or updating a script with this event go to the game's settings and click on Update Existing Services or go to a game server's service settings and click on Save.
- Available variables: Service Manager Scripting Variables
- After stopped (executed by the Service Manager)
- Occurs after the service is stopped. The script is executed in the service's working directory. After creating or updating a script with this event go to the game's settings and click on Update Existing Services or go to a game server's service settings and click on Save.
- Available variables: Service Manager Scripting Variables
- External Download Script
- This script is executed when a game server has "Enable external download" checked and the local game files don't exist.
- Available variables: FilesFolderName, FilesFolderFullName, GameFilesPath, DownloadedFile, DownloadedFileWithoutExtension
Troubleshooting Scripts
- Enable debug mode on the server.
- Stop the Monitor or Service Manager service depending on the script's event.
- Start the Monitor or Service Manager console depending on the script's event.
- When the script is executed the console will show the output of the batch/shell script or any iron python error.
How To...
print messages from an Iron Python script
Use the "Script.WriteToConsole" function:
Script.WriteToConsole("Hello World");
Only show the output from the commands in a Window batch script
Add "@echo off" to the start of your script.
Get the TCAdmin installation folder
You can use the TCAdminFolder variable.
- Windows batch script: %TCAdminFolder%
- Linux shell script: ${TCAdminFolder}
- Iron Python: TCAdminFolder
Capture values before executing the script
- Define the variables in the game's custom variables. In the variable's Variable Options tab check "Script parameter". If you want TCAdmin to save the value entered by the user check "Save script parameter value".
- Use the variable in your script.
- When you execute the script it will ask for the variable values.
Important: Make sure you validate the user's input using the validation options provided by TCAdmin and from your script if possible. Use numeric textbox, checkbox and combobox instead of textbox whenever possible. An invalid value could cause your script to behave in a way that was not intended.
- For example
- You create a backup script for Minecraft. You want your user to enter the name of their world folder. You create a texbox for this.
- If you don't validate the input the user could enter "..". This will make your script create a backup of the game server root's parent folder. It could create a backup of all services.
- In this case the recommended way to capture a folder name is by using a combobox with Source=File System and FilterType=Directories. This way the user will be shown a list of folders in their game server's root folder. Any value that is not in the list is automatically detected as invalid.