Table of Contents

Struct INetwork

Namespace
SampSharp.OpenMp.Core.Api
Assembly
SampSharp.OpenMp.Core.dll

This type represents a pointer to an unmanaged open.mp INetwork interface.

[OpenMpApi(new Type[] { typeof(IExtensible) })]
public readonly struct INetwork : IEquatable<INetwork>, INetwork.IManagedInterface, IExtensible.IManagedInterface, IUnmanagedInterface
Implements
Inherited Members

Constructors

INetwork(nint)

Initializes a new instance of the INetwork struct.

public INetwork(nint handle)

Parameters

handle nint

A pointer to the unmanaged interface.

Properties

Handle

Gets the handle to the unmanaged interface instance.

public nint Handle { get; }

Property Value

nint

HasValue

Gets a value indicating whether the pointer has a value.

public bool HasValue { get; }

Property Value

bool

Methods

AddExtension<T>(T)

Adds the specified managed extension to this extensible.

public void AddExtension<T>(T extension) where T : Extension

Parameters

extension T

An instance of the extension to add. The extension will be disposed if the extension could not be added to this extensible.

Type Parameters

T

The type of the managed extension.

Remarks

A managed extension can only be added to one extensible.

Exceptions

ArgumentException

Throw when an instance of the extension type was already added to this extensible.

Ban(BanEntry, TimeSpan)

Bans a peer from the network.

public void Ban(BanEntry entry, TimeSpan expire)

Parameters

entry BanEntry

The ban entry containing details about the ban.

expire TimeSpan

The duration of the ban before it expires.

BroadcastPacket(SpanLite<byte>, int, IPlayer, bool)

Broadcasts a packet to all peers on this network.

public bool BroadcastPacket(SpanLite<byte> data, int channel, IPlayer exceptPeer = default, bool dispatchEvents = true)

Parameters

data SpanLite<byte>

The data span with the length in bits.

channel int

The channel to use for broadcasting the packet.

exceptPeer IPlayer

The peer to exclude from the broadcast.

dispatchEvents bool

Whether to dispatch packet-related events.

Returns

bool

true if the packet was broadcast successfully; otherwise, false.

BroadcastRPC(int, SpanLite<byte>, int, IPlayer, bool)

Broadcasts an RPC to all peers on this network.

public bool BroadcastRPC(int id, SpanLite<byte> data, int channel, IPlayer exceptPeer = default, bool dispatchEvents = true)

Parameters

id int

The RPC ID for the current network.

data SpanLite<byte>

The data span with the length in bits.

channel int

The channel to use for broadcasting the RPC.

exceptPeer IPlayer

The peer to exclude from the broadcast.

dispatchEvents bool

Whether to dispatch RPC-related events.

Returns

bool

true if the RPC was broadcast successfully; otherwise, false.

Disconnect(IPlayer)

Disconnects a peer from the network.

public void Disconnect(IPlayer peer)

Parameters

peer IPlayer

The network peer to disconnect.

Equals(INetwork)

public bool Equals(INetwork other)

Parameters

other INetwork

Returns

bool

Equals(object?)

public override bool Equals(object? other)

Parameters

other object

Returns

bool

GetEventDispatcher()

Gets the dispatcher which dispatches network events.

public IEventDispatcher<INetworkEventHandler> GetEventDispatcher()

Returns

IEventDispatcher<INetworkEventHandler>

An event dispatcher for network events.

GetExtension(UID)

Gets the extension with the specified id.

public IExtension GetExtension(UID id)

Parameters

id UID

The identifier of the extension type.

Returns

IExtension

The extension or null if the extension could not be found.

GetExtension<T>()

Gets the specified managed extension from this extensible.

public T GetExtension<T>() where T : Extension

Returns

T

An instance of the extension with type T.

Type Parameters

T

The type of the managed extension.

Exceptions

ArgumentException

Thrown if the extension could not be found.

GetHashCode()

public override int GetHashCode()

Returns

int

GetInEventDispatcher()

Gets the dispatcher which dispatches incoming network events.

public IEventDispatcher<INetworkInEventHandler> GetInEventDispatcher()

Returns

IEventDispatcher<INetworkInEventHandler>

An event dispatcher for incoming network events.

GetNetworkType()

Gets the network type of the network.

public ENetworkType GetNetworkType()

Returns

ENetworkType

The network type of the network.

GetOutEventDispatcher()

Gets the dispatcher which dispatches outgoing network events.

public IEventDispatcher<INetworkOutEventHandler> GetOutEventDispatcher()

Returns

IEventDispatcher<INetworkOutEventHandler>

An event dispatcher for outgoing network events.

GetPerPacketInEventDispatcher()

Gets the dispatcher which dispatches incoming network events bound to a specific packet ID.

public IIndexedEventDispatcher<ISingleNetworkInEventHandler> GetPerPacketInEventDispatcher()

Returns

IIndexedEventDispatcher<ISingleNetworkInEventHandler>

An indexed event dispatcher for incoming packet events.

GetPerPacketOutEventDispatcher()

Gets the dispatcher which dispatches outgoing network events bound to a specific packet ID.

public IIndexedEventDispatcher<ISingleNetworkOutEventHandler> GetPerPacketOutEventDispatcher()

Returns

IIndexedEventDispatcher<ISingleNetworkOutEventHandler>

An indexed event dispatcher for outgoing packet events.

GetPerRPCInEventDispatcher()

Gets the dispatcher which dispatches incoming network events bound to a specific RPC ID.

public IIndexedEventDispatcher<ISingleNetworkInEventHandler> GetPerRPCInEventDispatcher()

Returns

IIndexedEventDispatcher<ISingleNetworkInEventHandler>

An indexed event dispatcher for incoming RPC events.

GetPerRPCOutEventDispatcher()

Gets the dispatcher which dispatches outgoing network events bound to a specific RPC ID.

public IIndexedEventDispatcher<ISingleNetworkOutEventHandler> GetPerRPCOutEventDispatcher()

Returns

IIndexedEventDispatcher<ISingleNetworkOutEventHandler>

An indexed event dispatcher for outgoing RPC events.

GetPing(IPlayer)

Gets the last ping for a peer on this network.

public uint GetPing(IPlayer peer)

Parameters

peer IPlayer

The network peer to get the ping for.

Returns

uint

The last ping value, or 0 if the peer is not on this network.

GetStatistics(IPlayer)

Gets network statistics for a specific player or the entire network.

public NetworkStats GetStatistics(IPlayer player = default)

Parameters

player IPlayer

The player to get statistics for, or default for the entire network.

Returns

NetworkStats

The network statistics.

QueryExtension<T>()

Gets the specified unmanaged extension from this extensible.

public T QueryExtension<T>() where T : unmanaged, IExtension.IManagedInterface

Returns

T

The unmanaged extension or null if the extension could not be found.

Type Parameters

T

The type of the unmanaged extension.

RemoveExtension(IExtension)

Removes the specified extension from this extensible.

public void RemoveExtension(IExtension extension)

Parameters

extension IExtension

The extension to remove.

Exceptions

ArgumentException

Thrown if the extension could not be found.

RemoveExtension(UID)

Removes the extension with the specified id from this extensible.

public void RemoveExtension(UID id)

Parameters

id UID

The identifier of the extension.

Exceptions

ArgumentException

Thrown if the extension could not be found.

RemoveExtension<T>(T)

Removes the specified managed extension from this extensible.

public void RemoveExtension<T>(T extension) where T : Extension

Parameters

extension T

The managed extension to remove.

Type Parameters

T

The type of the managed extension.

Exceptions

ArgumentException

Thrown if the extension could not be found.

SendPacket(IPlayer, SpanLite<byte>, int, bool)

Sends a packet to a network peer.

public bool SendPacket(IPlayer peer, SpanLite<byte> data, int channel, bool dispatchEvents = true)

Parameters

peer IPlayer

The network peer to send the packet to.

data SpanLite<byte>

The data span with the length in bits.

channel int

The channel to use for sending the packet.

dispatchEvents bool

Whether to dispatch packet-related events.

Returns

bool

true if the packet was sent successfully; otherwise, false.

SendRPC(IPlayer, int, SpanLite<byte>, int, bool)

Sends an RPC to a network peer.

public bool SendRPC(IPlayer peer, int id, SpanLite<byte> data, int channel, bool dispatchEvents = true)

Parameters

peer IPlayer

The network peer to send the RPC to.

id int

The RPC ID for the current network.

data SpanLite<byte>

The data span with the length in bits.

channel int

The channel to use for sending the RPC.

dispatchEvents bool

Whether to dispatch RPC-related events.

Returns

bool

true if the RPC was sent successfully; otherwise, false.

TryGetExtension<T>()

Tries to get the specified managed extension from this extensible.

public T? TryGetExtension<T>() where T : Extension

Returns

T

An instance of the extension with type T or null if no extension with the specified type could be found.

Type Parameters

T

The type of the managed extension.

TryQueryExtension<T>(out T)

Tries to get the specified unmanaged extension from this extensible.

public bool TryQueryExtension<T>(out T extension) where T : unmanaged, IExtension.IManagedInterface

Parameters

extension T

The extension if found, otherwise null.

Returns

bool

true if the extension was found; false otherwise.

Type Parameters

T

The type of the unmanaged extension.

Unban(BanEntry)

Unbans a peer from the network.

public void Unban(BanEntry entry)

Parameters

entry BanEntry

The ban entry to remove.

Update()

Updates server parameters.

public void Update()

Operators

operator ==(INetwork, object?)

Determines whether the specified values are equal.

public static bool operator ==(INetwork lhs, object? rhs)

Parameters

lhs INetwork

The value on the left side of the operator.

rhs object

The value on the right side of the operator.

Returns

bool

true if the values are equal; otherwise, false.

explicit operator INetwork(IExtensible)

Casts the IExtensible to a INetwork.

public static explicit operator INetwork(IExtensible value)

Parameters

value IExtensible

The IExtensible to cast.

Returns

INetwork

The converted INetwork.

explicit operator IExtensible(INetwork)

Casts the INetwork to a IExtensible.

public static explicit operator IExtensible(INetwork value)

Parameters

value INetwork

The INetwork to cast.

Returns

IExtensible

The converted IExtensible.

operator !=(INetwork, object?)

Determines whether the specified values are not equal.

public static bool operator !=(INetwork lhs, object? rhs)

Parameters

lhs INetwork

The value on the left side of the operator.

rhs object

The value on the right side of the operator.

Returns

bool

true if the values are not equal; otherwise, false.