Class API
An class that can be used to interact with RageCoop server.
Inherited Members
Namespace: RageCoop.Server.Scripting
Assembly: RageCoop.Server.dll
Syntax
public class API
Fields
Events
Server side events
Declaration
public readonly ServerEvents Events
Field Value
Type | Description |
---|---|
ServerEvents |
Properties
Entities
All synchronized entities on this server.
Declaration
public ServerEntities Entities { get; }
Property Value
Type | Description |
---|---|
ServerEntities |
Host
Gets or sets the client that is resposible for synchronizing time and weather
Declaration
public Client Host { get; set; }
Property Value
Type | Description |
---|---|
Client |
LoadedResources
Get all currently loaded ServerResource as a dictionary indexed by their names
Declaration
public Dictionary<string, ServerResource> LoadedResources { get; }
Property Value
Type | Description |
---|---|
Dictionary<String, ServerResource> |
Remarks
Accessing this property from script constructor is stronly discouraged since other scripts and resources might have yet been loaded. Accessing from OnStart() is not recommended either. Although all script assemblies will have been loaded to memory and instantiated, OnStart() invocation of other scripts are not guaranteed.
Logger
Get a Logger that the server is currently using, you should use Logger to display resource-specific information.
Declaration
public Logger Logger { get; }
Property Value
Type | Description |
---|---|
Logger |
Methods
FindScript(String, String)
Find a script matching the specified type
Declaration
public dynamic FindScript(string scriptFullName, string resourceName = null)
Parameters
Type | Name | Description |
---|---|---|
String | scriptFullName | The full name of the script's type, e.g. RageCoop.Resources.Discord.Main |
String | resourceName | Which resource to search for this script. Will search in all loaded resources if unspecified |
Returns
Type | Description |
---|---|
Object | A langword_csharp_dynamic object reprensenting the script, or null if not found. |
Remarks
Explicitly casting the return value to orginal type will case a exception to be thrown due to the dependency isolation mechanism in resource system. You shouldn't reference the target resource assemblies either, since it causes the referenced assembly to be loaded and started in your resource.
GetAllClients()
Get a list of all Clients
Declaration
public Dictionary<int, Client> GetAllClients()
Returns
Type | Description |
---|---|
Dictionary<Int32, Client> | All clients as a dictionary indexed by their main character's id |
GetClientByUsername(String)
Get the client by its username
Declaration
public Client GetClientByUsername(string username)
Parameters
Type | Name | Description |
---|---|---|
String | username | The username to search for (non case-sensitive) |
Returns
Type | Description |
---|---|
Client | The Client from this user or null |
RegisterCommand(String, Action<CommandContext>)
Register a new command chat command (Example: "/test")
Declaration
public void RegisterCommand(string name, Action<CommandContext> callback)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the command (Example: "test" for "/test") |
Action<CommandContext> | callback | A callback to invoke when the command received. |
RegisterCommand(String, String, Int16, Action<CommandContext>)
Register a new command chat command (Example: "/test")
Declaration
public void RegisterCommand(string name, string usage, short argsLength, Action<CommandContext> callback)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the command (Example: "test" for "/test") |
String | usage | How to use this message (argsLength required!) |
Int16 | argsLength | The length of args (Example: "/message USERNAME MESSAGE" = 2) (usage required!) |
Action<CommandContext> | callback | A callback to invoke when the command received. |
RegisterCommands(Object)
Register all commands inside an class instance
Declaration
public void RegisterCommands(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The instance of type containing the commands |
RegisterCommands<T>()
Register all commands in a static class
Declaration
public void RegisterCommands<T>()
Type Parameters
Name | Description |
---|---|
T | Your static class with commands |
RegisterCustomEventHandler(Int32, Action<CustomEventReceivedArgs>)
Register an handler to the specifed event hash, one event can have multiple handlers.
Declaration
public void RegisterCustomEventHandler(int hash, Action<CustomEventReceivedArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
Int32 | hash | An unique identifier of the event, you can hash your event name with Hash(String) |
Action<CustomEventReceivedArgs> | handler | An handler to be invoked when the event is received from the server. |
RegisterCustomEventHandler(String, Action<CustomEventReceivedArgs>)
Register an event handler for specified event name.
Declaration
public void RegisterCustomEventHandler(string name, Action<CustomEventReceivedArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
String | name | This value will be hashed to an int to reduce overhead |
Action<CustomEventReceivedArgs> | handler | The handler to be invoked when the event is received |
RegisterSharedFile(String, ResourceFile)
Register a file to be shared with clients
Declaration
public void RegisterSharedFile(string name, ResourceFile file)
Parameters
Type | Name | Description |
---|---|---|
String | name | name of this file |
ResourceFile | file |
RegisterSharedFile(String, String)
Register a file to be shared with clients
Declaration
public void RegisterSharedFile(string name, string path)
Parameters
Type | Name | Description |
---|---|---|
String | name | name of this file |
String | path | path to this file |
SendChatMessage(String, List<Client>, String, Nullable<Boolean>)
Send a chat message to all players, use SendChatMessage(String, String) to send to an individual client.
Declaration
public void SendChatMessage(string message, List<Client> targets = null, string username = "Server", bool? raiseEvent = null)
Parameters
Type | Name | Description |
---|---|---|
String | message | The chat message |
List<Client> | targets | The clients to send message, leave it null to send to all clients |
String | username | The username which send this message (default = "Server") |
Nullable<Boolean> | raiseEvent | Weather to raise the OnChatMessage event defined in Events |
Remarks
When raiseEvent
is unspecified and targets
is null or unspecified, raiseEvent
will be set to true
SendCustomEvent(List<Client>, Int32, Object[])
Send an event and data to the specified clients. Use SendCustomEvent(Int32, Object[]) if you want to send event to individual client.
Declaration
public void SendCustomEvent(List<Client> targets, int eventHash, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
List<Client> | targets | The target clients to send. Leave it null to send to all clients |
Int32 | eventHash | An unique identifier of the event, you can use Hash(String) to get it from a string |
Object[] | args | The objects conataing your data, see Args for supported types. |
SendCustomEventQueued(List<Client>, Int32, Object[])
Send a CustomEvent that'll be queued at client side and invoked from script thread
Declaration
public void SendCustomEventQueued(List<Client> targets, int eventHash, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
List<Client> | targets | |
Int32 | eventHash | |
Object[] | args |
SendNativeCall(List<Client>, Hash, Object[])
Send native call specified clients.
Declaration
public void SendNativeCall(List<Client> clients, Hash hash, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
List<Client> | clients | Clients to send, null for all clients |
Hash | hash | |
Object[] | args |