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 |
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
GetAllClients()
Get a list of all Clients
Declaration
public Dictionary<long, Client> GetAllClients()
Returns
Type | Description |
---|---|
Dictionary<Int64, Client> | All clients as a dictionary indexed by NetID |
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>)
Send CleanUpWorld to all players to delete all objects created by the server
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 |
SendChatMessage(String, List<Client>, String)
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")
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") |
SendCustomEvent(Int32, List<Object>, List<Client>)
Send an event and data to the specified clients. Use SendCustomEvent(Int32, List<Object>) if you want to send event to individual client.
Declaration
public void SendCustomEvent(int eventHash, List<object> args = null, List<Client> targets = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | eventHash | An unique identifier of the event, you can use Hash(String) to get it from a string |
List<Object> | args | The objects conataing your data, see Args for supported types. |
List<Client> | targets | The target clients to send. Leave it null to send to all clients |
SendCustomEvent(String, List<Object>, List<Client>)
Send an event and data to the specified clients. Use SendCustomEvent(Int32, List<Object>) if you want to send event to individual client.
Declaration
public void SendCustomEvent(string name, List<object> args = null, List<Client> targets = null)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the event, will be hashed to an int. For optimal performence, you should hash it in a static contructor inside the shared library, then call SendCustomEvent(Int32, List<Object>, List<Client>). |
List<Object> | args | See CustomEventReceivedArgs for a list of supported types. |
List<Client> | targets | The target clients to send. Leave it null to send to all clients |