Class MtaServer
A highly-configurable implementation of an MTA Server.
Assembly: SlipeServer.Server.dll
Syntax
Constructors
|
Edit this page
View Source
MtaServer(Action<ServerBuilder>, Func<ulong, INetWrapper, IClient>?)
Declaration
public MtaServer(Action<ServerBuilder> builderAction, Func<ulong, INetWrapper, IClient>? clientCreationMethod = null)
Parameters
|
Edit this page
View Source
MtaServer(IServiceProvider, Action<ServerBuilder>)
Declaration
public MtaServer(IServiceProvider serviceProvider, Action<ServerBuilder> builderAction)
Parameters
Fields
|
Edit this page
View Source
clients
Declaration
protected readonly Dictionary<INetWrapper, Dictionary<ulong, IClient>> clients
Field Value
|
Edit this page
View Source
elementCollection
Declaration
protected readonly IElementCollection elementCollection
Field Value
|
Edit this page
View Source
packetReducer
Declaration
protected PacketReducer packetReducer
Field Value
|
Edit this page
View Source
resourceProvider
Declaration
protected IResourceProvider? resourceProvider
Field Value
|
Edit this page
View Source
resourceServers
Declaration
protected readonly List<IResourceServer> resourceServers
Field Value
|
Edit this page
View Source
serviceCollection
Declaration
protected readonly IServiceCollection? serviceCollection
Field Value
|
Edit this page
View Source
serviceProvider
Declaration
protected readonly IServiceProvider serviceProvider
Field Value
Properties
|
Edit this page
View Source
BuildFinalizer
Declaration
public Action? BuildFinalizer { get; }
Property Value
|
Edit this page
View Source
Configuration
Declaration
public Configuration Configuration { get; }
Property Value
|
Edit this page
View Source
GameType
Game type, as shown in the server browser
Declaration
public string GameType { get; set; }
Property Value
|
Edit this page
View Source
HasPassword
Indicates whether a password is set
Declaration
public bool HasPassword { get; }
Property Value
|
Edit this page
View Source
IsRunning
Indicates whether the server is currently accepting incoming packets
Declaration
public bool IsRunning { get; protected set; }
Property Value
|
Edit this page
View Source
MapName
Map name, as shown in the server browser
Declaration
public string MapName { get; set; }
Property Value
|
Edit this page
View Source
Password
Current server password, to be entered when connecting
Declaration
public string? Password { get; set; }
Property Value
|
Edit this page
View Source
Players
Declaration
public IEnumerable<Player> Players { get; }
Property Value
|
Edit this page
View Source
RootElement
Declaration
public RootElement RootElement { get; }
Property Value
|
Edit this page
View Source
Services
Returns the service provider, which can be used to instantiate / inject services
Declaration
public IServiceProvider Services { get; }
Property Value
|
Edit this page
View Source
StartDatetime
The timestamp the server was started at
Declaration
public DateTime StartDatetime { get; protected set; }
Property Value
|
Edit this page
View Source
Uptime
The amount of time since the server has been started
Declaration
public TimeSpan Uptime { get; }
Property Value
Methods
|
Edit this page
View Source
AddAdditionalResource(Resource, Dictionary<string, byte[]>)
Adds an additional resource to the server, which then gets registered with all resource servers.
Declaration
public void AddAdditionalResource(Resource resource, Dictionary<string, byte[]> files)
Parameters
|
Edit this page
View Source
AddNetWrapper(INetWrapper, AntiCheatConfiguration?)
Adds an arbitrary networking interface
Declaration
public INetWrapper AddNetWrapper(INetWrapper wrapper, AntiCheatConfiguration? configuration = null)
Parameters
Type |
Name |
Description |
INetWrapper |
wrapper |
the networking interface
|
AntiCheatConfiguration |
configuration |
anti cheat configuration to apply on this networking interface
|
Returns
|
Edit this page
View Source
AddNetWrapper(string, string, string, ushort, AntiCheatConfiguration?)
Adds a new networking interface using MTA's net.dll
Declaration
public INetWrapper AddNetWrapper(string directory, string netDllPath, string host, ushort port, AntiCheatConfiguration? configuration = null)
Parameters
Type |
Name |
Description |
string |
directory |
directory to run in
|
string |
netDllPath |
path to the net.dll, relative to the directory
|
string |
host |
host ip for the server
|
ushort |
port |
UDP port for incoming traffic to the server, this is what port players connect to
|
AntiCheatConfiguration |
configuration |
anti cheat configuration to apply on this networking interface
|
Returns
|
Edit this page
View Source
AddResourceServer(IResourceServer)
Adds a resource server, this is responsible for providing the files for client side resources to clients, over HTTP.
Declaration
public void AddResourceServer(IResourceServer resourceServer)
Parameters
|
Edit this page
View Source
AssociateElement<T>(T)
Associates an element with the entire server, meaning any player that connects to the server will be made aware of the element
and changes to the element will be relayed to all the players connected to the server.
Declaration
public T AssociateElement<T>(T element) where T : Element
Parameters
Type |
Name |
Description |
T |
element |
|
Returns
Type |
Description |
T |
Returns the element, allowing for method chaining
|
Type Parameters
|
Edit this page
View Source
BroadcastPacket(Packet)
Sends a packet to all players on the server.
Declaration
public void BroadcastPacket(Packet packet)
Parameters
Type |
Name |
Description |
Packet |
packet |
|
|
Edit this page
View Source
Create(Action<ServerBuilder>)
Declaration
public static MtaServer Create(Action<ServerBuilder> builderAction)
Parameters
Type |
Name |
Description |
Action<ServerBuilder> |
builderAction |
Action that allows you to configure the server
|
Returns
|
Edit this page
View Source
Create(IServiceProvider, Action<ServerBuilder>)
Declaration
public static MtaServer Create(IServiceProvider serviceProvider, Action<ServerBuilder> builderAction)
Parameters
Returns
|
Edit this page
View Source
CreateClient(ulong, INetWrapper)
Declaration
protected virtual IClient CreateClient(ulong binaryAddress, INetWrapper netWrapper)
Parameters
Returns
|
Edit this page
View Source
CreateWithDiSupport<TPlayer>(Action<ServerBuilder>)
Creates an MTA server using a specific type for connecting players.
This player type will be instantiated using the dependency injection container, allowing you to inject dependencies into the TPlayer class.
Declaration
public static MtaServer<TPlayer> CreateWithDiSupport<TPlayer>(Action<ServerBuilder> builderAction) where TPlayer : Player
Parameters
Returns
Type Parameters
|
Edit this page
View Source
Create<TPlayer>(Action<ServerBuilder>)
Creates an MTA server using a specific type for connecting players
Declaration
public static MtaServer<TPlayer> Create<TPlayer>(Action<ServerBuilder> builderAction) where TPlayer : Player, new()
Parameters
Type |
Name |
Description |
Action<ServerBuilder> |
builderAction |
Action that allows you to configure the server
|
Returns
Type Parameters
Name |
Description |
TPlayer |
The type to use for connecting players
|
|
Edit this page
View Source
EnqueuePacketToClient(IClient, PacketId, byte[])
Enqueues a packet as if it were received from a specific client
Declaration
public void EnqueuePacketToClient(IClient client, PacketId packetId, byte[] data)
Parameters
|
Edit this page
View Source
ForAny<TElement>(Action<TElement>)
Executes an action for every single element of a specific type on the server.
This includes both currently existing elements, and elements to be created in the future.
Declaration
public void ForAny<TElement>(Action<TElement> action) where TElement : Element
Parameters
Type |
Name |
Description |
Action<TElement> |
action |
The action to be executed for every element of the type
|
Type Parameters
Name |
Description |
TElement |
The type of element to execute the action for
|
|
Edit this page
View Source
GetAdditionalResource<TResource>()
Gets a registered additional resource of a certain type.
Declaration
public TResource GetAdditionalResource<TResource>() where TResource : Resource
Returns
Type |
Description |
TResource |
|
Type Parameters
Name |
Description |
TResource |
|
|
Edit this page
View Source
GetRequiredServiceScoped<T>()
Gets a registered service from the dependency injection conatiner, throwing an exception if there is no registered service for the specified type
Declaration
public T GetRequiredServiceScoped<T>() where T : notnull
Returns
Type Parameters
|
Edit this page
View Source
GetRequiredService<T>()
Gets a registered service from the dependency injection conatiner, throwing an exception if there is no registered service for the specified type
Declaration
public T GetRequiredService<T>() where T : notnull
Returns
Type Parameters
|
Edit this page
View Source
GetService<T>()
Gets a registered service from the dependency injection conatiner
Declaration
public T? GetService<T>()
Returns
Type Parameters
|
Edit this page
View Source
HandleLuaEvent(LuaEvent)
Handles a lua event, and triggers the appropriate event.
This method is generally intended to be called from packet handlers.
Declaration
public void HandleLuaEvent(LuaEvent luaEvent)
Parameters
|
Edit this page
View Source
HandlePlayerJoin(Player)
Handles a player joining the server, and triggers the appropriate event.
This method is generally intended to be called from packet handlers.
Declaration
public virtual void HandlePlayerJoin(Player player)
Parameters
Type |
Name |
Description |
Player |
player |
|
|
Edit this page
View Source
Instantiate(Type, params object[])
Instantiates a type using the dependency injection container
Declaration
public object Instantiate(Type type, params object[] parameters)
Parameters
Type |
Name |
Description |
Type |
type |
The type to instiantiate
|
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
|
Edit this page
View Source
InstantiatePersistent(Type, params object[])
Instantiates a type using the dependency injection container, and keeps a reference to it on the MTA server, making sure it does not get garbage collected
Declaration
public object InstantiatePersistent(Type type, params object[] parameters)
Parameters
Type |
Name |
Description |
Type |
type |
The type to instiantiate
|
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
|
Edit this page
View Source
InstantiatePersistent<T>(params object[])
Instantiates a type using the dependency injection container, and keeps a reference to it on the MTA server, making sure it does not get garbage collected
Declaration
public T InstantiatePersistent<T>(params object[] parameters)
Parameters
Type |
Name |
Description |
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
Type Parameters
Name |
Description |
T |
The type to instiantiate
|
|
Edit this page
View Source
InstantiateScoped(Type, params object[])
Instantiates a type using the dependency injection container, in a newly created scope.
Declaration
public object InstantiateScoped(Type type, params object[] parameters)
Parameters
Type |
Name |
Description |
Type |
type |
The type to instiantiate
|
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
|
Edit this page
View Source
InstantiateScopedPersistent<T>(params object[])
Instantiates a type using the dependency injection container with scoped lifetime, and keeps a reference to it on the MTA server, making sure it does not get garbage collected
Declaration
public T InstantiateScopedPersistent<T>(params object[] parameters)
Parameters
Type |
Name |
Description |
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
Type Parameters
Name |
Description |
T |
The type to instiantiate
|
|
Edit this page
View Source
InstantiateScoped<T>(params object[])
Instantiates a type using the dependency injection container, in a newly created scope.
Declaration
public T InstantiateScoped<T>(params object[] parameters)
Parameters
Type |
Name |
Description |
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
Type Parameters
Name |
Description |
T |
The type to instiantiate
|
|
Edit this page
View Source
Instantiate<T>(params object[])
Instantiates a type using the dependency injection container
Declaration
public T Instantiate<T>(params object[] parameters)
Parameters
Type |
Name |
Description |
object[] |
parameters |
Any constructor parameters that are not supplied by the dependency injection container
|
Returns
Type Parameters
Name |
Description |
T |
The type to instiantiate
|
|
Edit this page
View Source
RegisterNetWrapper(INetWrapper)
Registers a networking interface, meaning any packets received by this will be handled by registered packet handlers.
Declaration
public void RegisterNetWrapper(INetWrapper netWrapper)
Parameters
|
Edit this page
View Source
RegisterPacketHandler<T>(PacketId, IPacketQueueHandler<T>)
Registers a packet handler, to handle incoming packets from clients
Declaration
public void RegisterPacketHandler<T>(PacketId packetId, IPacketQueueHandler<T> queueHandler) where T : Packet, new()
Parameters
Type |
Name |
Description |
PacketId |
packetId |
The packet ID to handle, this identifies which packet types should be handled by this handler
|
IPacketQueueHandler<T> |
queueHandler |
The packet handler in question
|
Type Parameters
|
Edit this page
View Source
RegisterPacketHandler<TPacketHandler, TPacket>(params object[])
Registers a packet handler, to handle incoming packets from clients using default ( ScalingPacketQueueHandler ) handler
Declaration
public void RegisterPacketHandler<TPacketHandler, TPacket>(params object[] parameters) where TPacketHandler : IPacketHandler<TPacket> where TPacket : Packet, new()
Parameters
Type |
Name |
Description |
object[] |
parameters |
|
Type Parameters
Name |
Description |
TPacketHandler |
|
TPacket |
|
|
Edit this page
View Source
RegisterPacketHandler<TPacket, TPacketQueueHandler, TPacketHandler>(params object[])
Registers a packet handler, to handle incoming packets from clients
Declaration
public void RegisterPacketHandler<TPacket, TPacketQueueHandler, TPacketHandler>(params object[] parameters) where TPacket : Packet, new() where TPacketQueueHandler : class, IPacketQueueHandler<TPacket> where TPacketHandler : IPacketHandler<TPacket>
Parameters
Type |
Name |
Description |
object[] |
parameters |
Any parameters to pass to the constructor of the packet handler that are not injected by the dependency injection container
|
Type Parameters
Name |
Description |
TPacket |
The type of packet ot handle
|
TPacketQueueHandler |
The type of packet queue handler to handle the queue of packets
|
TPacketHandler |
The type of packet handler to instantiate
|
|
Edit this page
View Source
RemoveAdditionalResource(Resource)
Removes a registered additional resource.
Declaration
public void RemoveAdditionalResource(Resource resource)
Parameters
|
Edit this page
View Source
RemoveElement(Element)
Removes an element from being associated with the entire server, meaning the element will no longer be sync'd to all players
Declaration
public void RemoveElement(Element element)
Parameters
Type |
Name |
Description |
Element |
element |
|
|
Edit this page
View Source
SetMaxPlayers(ushort)
Sets the maximum amount of players on the server
Declaration
public void SetMaxPlayers(ushort slots)
Parameters
Type |
Name |
Description |
ushort |
slots |
|
|
Edit this page
View Source
SetupDependencies(Action<IServiceCollection>?)
Declaration
protected virtual void SetupDependencies(Action<IServiceCollection>? dependencyCallback)
Parameters
|
Edit this page
View Source
Start()
Starts the networking interfaces, allowing clients to connect and packets to be sent out to clients.
Declaration
public virtual void Start()
|
Edit this page
View Source
Stop()
Stops the networking interfaces.
Declaration
public virtual void Stop()
Events
|
Edit this page
View Source
ClientConnected
Triggered when a client connects to the server
Declaration
public event Action<IClient>? ClientConnected
Event Type
|
Edit this page
View Source
ElementCreated
Triggered when any element is created on the server through the .AssociateElement method
Declaration
public event Action<Element>? ElementCreated
Event Type
|
Edit this page
View Source
LuaEventTriggered
Triggered when a lua event has been triggered by a client
Declaration
public event Action<LuaEvent>? LuaEventTriggered
Event Type
|
Edit this page
View Source
MaxPlayerCountChanged
Triggered when max player count changes
Declaration
public event Action<ushort>? MaxPlayerCountChanged
Event Type
|
Edit this page
View Source
PlayerJoined
Triggered when any player joins the server
Declaration
public event Action<Player>? PlayerJoined
Event Type
|
Edit this page
View Source
Started
Triggered when the server started
Declaration
public event Action<MtaServer>? Started
Event Type
|
Edit this page
View Source
Stopped
Triggered when the server stopped
Declaration
public event Action<MtaServer>? Stopped
Event Type
Extension Methods