Show / Hide Table of Contents

Class MtaServer

A highly-configurable implementation of an MTA Server.

Inheritance
object
MtaServer
MtaServer<TPlayer>
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: SlipeServer.Server
Assembly: SlipeServer.Server.dll
Syntax
public class MtaServer

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
Type Name Description
Action<ServerBuilder> builderAction
Func<ulong, INetWrapper, IClient> clientCreationMethod
| Edit this page View Source

MtaServer(IServiceProvider, Action<ServerBuilder>)

Declaration
public MtaServer(IServiceProvider serviceProvider, Action<ServerBuilder> builderAction)
Parameters
Type Name Description
IServiceProvider serviceProvider
Action<ServerBuilder> builderAction

Fields

| Edit this page View Source

clients

Declaration
protected readonly Dictionary<INetWrapper, Dictionary<ulong, IClient>> clients
Field Value
Type Description
Dictionary<INetWrapper, Dictionary<ulong, IClient>>
| Edit this page View Source

elementCollection

Declaration
protected readonly IElementCollection elementCollection
Field Value
Type Description
IElementCollection
| Edit this page View Source

packetReducer

Declaration
protected PacketReducer packetReducer
Field Value
Type Description
PacketReducer
| Edit this page View Source

resourceProvider

Declaration
protected IResourceProvider? resourceProvider
Field Value
Type Description
IResourceProvider
| Edit this page View Source

resourceServers

Declaration
protected readonly List<IResourceServer> resourceServers
Field Value
Type Description
List<IResourceServer>
| Edit this page View Source

serviceCollection

Declaration
protected readonly IServiceCollection? serviceCollection
Field Value
Type Description
IServiceCollection
| Edit this page View Source

serviceProvider

Declaration
protected readonly IServiceProvider serviceProvider
Field Value
Type Description
IServiceProvider

Properties

| Edit this page View Source

BuildFinalizer

Declaration
public Action? BuildFinalizer { get; }
Property Value
Type Description
Action
| Edit this page View Source

Configuration

Declaration
public Configuration Configuration { get; }
Property Value
Type Description
Configuration
| Edit this page View Source

GameType

Game type, as shown in the server browser

Declaration
public string GameType { get; set; }
Property Value
Type Description
string
| Edit this page View Source

HasPassword

Indicates whether a password is set

Declaration
public bool HasPassword { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsRunning

Indicates whether the server is currently accepting incoming packets

Declaration
public bool IsRunning { get; protected set; }
Property Value
Type Description
bool
| Edit this page View Source

MapName

Map name, as shown in the server browser

Declaration
public string MapName { get; set; }
Property Value
Type Description
string
| Edit this page View Source

Password

Current server password, to be entered when connecting

Declaration
public string? Password { get; set; }
Property Value
Type Description
string
| Edit this page View Source

Players

Declaration
public IEnumerable<Player> Players { get; }
Property Value
Type Description
IEnumerable<Player>
| Edit this page View Source

RootElement

Declaration
public RootElement RootElement { get; }
Property Value
Type Description
RootElement
| 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
Type Description
IServiceProvider
| Edit this page View Source

StartDatetime

The timestamp the server was started at

Declaration
public DateTime StartDatetime { get; protected set; }
Property Value
Type Description
DateTime
| Edit this page View Source

Uptime

The amount of time since the server has been started

Declaration
public TimeSpan Uptime { get; }
Property Value
Type Description
TimeSpan

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
Type Name Description
Resource resource
Dictionary<string, byte[]> files
| 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
Type Description
INetWrapper
| 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
Type Description
INetWrapper
| 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
Type Name Description
IResourceServer resourceServer
| 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
Name Description
T
| 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>)

Creates an MTA Server.

Declaration
public static MtaServer Create(Action<ServerBuilder> builderAction)
Parameters
Type Name Description
Action<ServerBuilder> builderAction

Action that allows you to configure the server

Returns
Type Description
MtaServer
| Edit this page View Source

Create(IServiceProvider, Action<ServerBuilder>)

Creates an MTA Server.

Declaration
public static MtaServer Create(IServiceProvider serviceProvider, Action<ServerBuilder> builderAction)
Parameters
Type Name Description
IServiceProvider serviceProvider
Action<ServerBuilder> builderAction

Action that allows you to configure the server

Returns
Type Description
MtaServer
| Edit this page View Source

CreateClient(ulong, INetWrapper)

Declaration
protected virtual IClient CreateClient(ulong binaryAddress, INetWrapper netWrapper)
Parameters
Type Name Description
ulong binaryAddress
INetWrapper netWrapper
Returns
Type Description
IClient
| 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
Type Name Description
Action<ServerBuilder> builderAction
Returns
Type Description
MtaServer<TPlayer>
Type Parameters
Name Description
TPlayer
| 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 Description
MtaServer<TPlayer>
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
Type Name Description
IClient client
PacketId packetId
byte[] data
| 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 Description
T
Type Parameters
Name Description
T
| 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 Description
T
Type Parameters
Name Description
T
| Edit this page View Source

GetService<T>()

Gets a registered service from the dependency injection conatiner

Declaration
public T? GetService<T>()
Returns
Type Description
T
Type Parameters
Name Description
T
| 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
Type Name Description
LuaEvent luaEvent
| 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
Type Description
object
| 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
Type Description
object
| 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 Description
T
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
Type Description
object
| 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 Description
T
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 Description
T
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 Description
T
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
Type Name Description
INetWrapper netWrapper
| 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
Name Description
T
| 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
Type Name Description
Resource resource
| 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
Type Name Description
Action<IServiceCollection> dependencyCallback
| 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
Type Description
Action<IClient>
| 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
Type Description
Action<Element>
| 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
Type Description
Action<LuaEvent>
| Edit this page View Source

MaxPlayerCountChanged

Triggered when max player count changes

Declaration
public event Action<ushort>? MaxPlayerCountChanged
Event Type
Type Description
Action<ushort>
| Edit this page View Source

PlayerJoined

Triggered when any player joins the server

Declaration
public event Action<Player>? PlayerJoined
Event Type
Type Description
Action<Player>
| Edit this page View Source

Started

Triggered when the server started

Declaration
public event Action<MtaServer>? Started
Event Type
Type Description
Action<MtaServer>
| Edit this page View Source

Stopped

Triggered when the server stopped

Declaration
public event Action<MtaServer>? Stopped
Event Type
Type Description
Action<MtaServer>

Extension Methods

ServiceCollectionExtensions.AddDefaultBehaviours(MtaServer, ServerBuilderDefaultBehaviours)
ServiceCollectionExtensions.AddDefaultPacketHandlers(MtaServer, ServerBuilderDefaultPacketHandlers)
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX