Skip to main content
Version: V3

Script Objects

TCAdmin scripts have access to a set of built-in objects that provide information about the current context (server, service, task, etc.) and allow you to interact with TCAdmin's APIs.

Scripting Engines

TCAdmin supports the following scripting engines:

  • C#
  • JavaScript (Jint)
  • Python 3 (IronPython)
  • PowerShell
  • Batch (shell commands)

Accessing Script Objects

C# Scripts

In C# scripts, all objects are available through the Globals variable. Depending on the script type, Globals is an instance of:

  • Game scriptsCSharpGameGlobals
  • Docker scriptsCSharpDockerGlobals

You can access properties directly since Globals is the implicit scope:

var Globals = new TCAdmin.Scripting.Engines.Addons.CSharpGameGlobals();

// Access the current server
var server = Globals.ThisServer;

// Access the current service
var service = Globals.ThisService;

Globals.ScriptConsole.WriteLine($"Service: {service.Name}");

JavaScript and Python Scripts

The same objects listed below are available as global variables in JavaScript and Python scripts. To see which objects are available, refer to the properties of CSharpGameGlobals and CSharpDockerGlobals below — the same properties are exposed in all scripting engines.

// JavaScript example
ScriptConsole.WriteLine("Server: " + ThisServer.Name);
# Python example
ScriptConsole.WriteLine("Server: " + ThisServer.Name)

Common Objects

These objects are available in all script types (game and Docker).

Context Objects

ObjectTypeDescription
GlobalsCSharpGameGlobals / CSharpDockerGlobalsSelf-reference to the globals object (C# scripts only).
ThisServerServerThe server where the script is running.
ThisServiceServiceThe current service. In game scripts this is a GameService, in Docker scripts a DockerService.
ThisDatacenterDatacenterThe datacenter the server belongs to.
ThisTaskTCATaskThe current task being executed.
ThisTaskStepTCATaskStepThe current step within the task.
ThisTaskStepHandlerTCATaskStepHandlerThe handler processing the current task step.
ThisScriptIScriptEngineThe scripting engine executing the current script.
ThisCancellationTokenCancellationTokenToken to check if the script execution has been cancelled.
RootDirectorystringThe root directory path of the current service.

Managers

Managers provide database access to query and manage TCAdmin entities.

ObjectTypeDescription
DatacenterManagerDatacenterManagerQuery and manage datacenters.
ServerManagerServerManagerQuery and manage servers.
GameManagerGameManagerQuery and manage game configurations.
ServiceManagerServiceManagerQuery and manage services.
ServiceManagerServiceIServiceManagerServiceService management operations (start, stop, restart, etc.).
RecurringTaskManagerRecurringTaskManagerQuery and manage recurring/scheduled tasks.
TCATaskManagerTCATaskManagerQuery and manage tasks.

Utility Objects

ObjectTypeDescription
ScriptConsoleCSharpConsoleWrite output and read input from the script console.
VariablesTCAdminVarsDictionary of all variables passed to the script.
DynamicExpandoObjectDynamic object with all script variables as properties.
OperatingSystemIOperatingSystemOperating system utilities (CPU, memory, user management, file permissions).
TCAdminConfigTCAdminConfigThe TCAdmin configuration (server ID, database config, paths, etc.).
EncryptionServiceEncryptionServiceEncrypt and decrypt sensitive data.
ScriptingEnvironmentIScriptingEnvironmentExecute other scripts from within a script.
ReturnValueobjectSet this to return a value from the script.

Game Script Objects

These additional objects are available when the script runs in a game service context (CSharpGameGlobals).

ObjectTypeDescription
ThisGameGameThe game configuration for the current service.
ThisServiceGameServiceThe current game service (overrides the base Service type).
GameServiceManagerGameServiceManagerQuery and manage game services.

Game Entity

The Game entity (accessed via ThisGame) contains game configuration properties:

PropertyTypeDescription
GameIdlongThe game's unique ID.
NamestringGame name.
ShortNamestringShort name (e.g., cs2).
DescriptionstringGame description.
OperatingSystemEOperatingSystemTarget operating system.
MinSlotsintMinimum player slots.
MaxSlotsintMaximum player slots.
DefaultSlotsintDefault player slots.
CategoryIdlongCategory ID.

GameService Entity

The GameService entity (accessed via ThisService in game scripts) extends Service with:

PropertyTypeDescription
GameGameThe game configuration.
GameIdlongThe game ID.
SlotsintNumber of player slots.
GamePortintThe game port.
QueryPortintThe query port.
RconPortintThe RCON port.
ProcessIdint?OS process ID when the service is running.
Affinitylong?CPU core affinity mask.
PriorityProcessPriorityClassProcess priority.
CPULimitdouble?CPU usage limit.
MemoryLimitlong?Memory limit in bytes.

Docker Script Objects

These additional objects are available when the script runs in a Docker service context (CSharpDockerGlobals).

ObjectTypeDescription
ThisDockerBlueprintDockerBlueprintThe Docker blueprint configuration.
ThisServiceDockerServiceThe current Docker service (overrides the base Service type).
DockerServiceManagerDockerServiceManagerQuery and manage Docker services.
ThisContainerStartParametersCreateContainerParametersThe Docker container creation parameters. Available in container creation scripts.

DockerService Entity

The DockerService entity (accessed via ThisService in Docker scripts) extends Service with:

PropertyTypeDescription
ImagestringDocker image name.
TagstringDocker image tag.
LimitsDockerServiceLimitsResource limits for the container.

DockerBlueprint Entity

The DockerBlueprint entity (accessed via ThisDockerBlueprint) contains:

PropertyTypeDescription
NamestringBlueprint name.
ShortNamestringShort name.
DescriptionstringBlueprint description.
ImagesICollection<DockerBlueprintImage>Available Docker images.
VolumeBindsICollection<DockerBlueprintVolumeBind>Volume mount configurations.
LimitsDockerBlueprintLimitsDefault resource limits.
ExecConsoleTypeEExecConsoleTypeConsole type (Command or Shell).
ExecCommandstringCommand used for exec console (default: /bin/sh).

Service Entity (Base)

Both GameService and DockerService inherit from the Service entity, which provides these common properties:

PropertyTypeDescription
ServiceIdlongUnique service ID.
NamestringService display name.
StatusEServiceStatusCurrent status (Stopped, Starting, Running, etc.).
RootDirectorystringRoot directory path.
WorkingDirectorystringWorking directory path.
Executablestring?Executable file name.
Commandlinestring?Command-line arguments.
StartupEServiceStartupStartup type (Automatic, Manual, Disabled).
VariablesTCAdminVarsCustom variables dictionary.
ServerIdlongID of the server this service runs on.
ServerServerThe server entity.
OwnerIdlong?Owner user ID.
OwnerUserThe owner user entity.
IPAddressstringIP address of the service.
HostnameOrIPstringHostname if available, otherwise IP address.
PortsPortsPort assignments dictionary.
DiskSpacelong?Allocated disk space in bytes.
DiskUsagelong?Current disk usage in bytes.
BillingIdstring?External billing system ID.
BillingStatusEBillingStatusBilling status.
CreatedDateDateTimeWhen the service was created.

Server Entity

The Server entity (accessed via ThisServer) provides:

PropertyTypeDescription
ServerIdlongUnique server ID.
NamestringServer name.
PrimaryIPAddressstringPrimary IP address.
FirewallIPAddressstring?Public/firewall IP address.
PrivateNetworkIPAddressstring?Private network IP address.
OperatingSystemEOperatingSystemOperating system type.
IsMasterboolWhether this is the master server.
EnabledboolWhether the server is enabled.
DatacenterIdlongDatacenter ID.
DatacenterDatacenterThe datacenter entity.

Datacenter Entity

The Datacenter entity (accessed via ThisDatacenter) provides:

PropertyTypeDescription
DatacenterIdlongUnique datacenter ID.
NamestringDatacenter name.
Addressstring?Physical address.
Notesstring?Additional notes.
ServersICollection<Server>Servers in this datacenter.

ScriptConsole

The ScriptConsole object provides console I/O for scripts:

MethodDescription
WriteLine()Write an empty line.
WriteLine(object)Write a value to the console.
WriteLine(string, params object[])Write a formatted string to the console.
ReadLine()Read a line of input from the user.
// Example: Console output
ScriptConsole.WriteLine("Installing mod...");
ScriptConsole.WriteLine("Service {0} on server {1}", ThisService.Name, ThisServer.Name);

// Example: Read user input
ScriptConsole.WriteLine("Enter the map name:");
var mapName = ScriptConsole.ReadLine();