Class NetworkServer<TNetworkClient, TServerConnection>
Base class for a network server listening on an in-game computer.
Inherited Members
Namespace: SociallyDistant.Core.OS.Network
Assembly: SociallyDistant.Framework.dll
Syntax
public abstract class NetworkServer<TNetworkClient, TServerConnection> : INetworkServer, IDisposable, IAcceptNetworkClient<TNetworkClient> where TNetworkClient : INetworkClient where TServerConnection : IServerConnection
Type Parameters
Name | Description |
---|---|
TNetworkClient | An implementation of INetworkClient that can be used to interact with this server. |
TServerConnection | An implementation of IServerConnection that can be used to interact with clients connected to this server. |
Constructors
NetworkServer(IDisposable, IComputer, ushort)
Creates a new instance of the NetworkServer<TNetworkClient, TServerConnection> class.
Declaration
protected NetworkServer(IDisposable listenHandle, IComputer computer, ushort port)
Parameters
Type | Name | Description |
---|---|---|
IDisposable | listenHandle | A disposable object whose Dispose method will be called when the server stops listening. |
IComputer | computer | The device on which this server runs. |
ushort | port | The port on which the server is listening. |
Properties
Name
Gets a value indicating the server's name.
Declaration
public string Name { get; protected set; }
Property Value
Type | Description |
---|---|
string |
Port
Gets a value indicating the server's listening port.
Declaration
public ushort Port { get; }
Property Value
Type | Description |
---|---|
ushort |
ServerDevice
Gets an instance of IComputer representing the server.
Declaration
public IComputer ServerDevice { get; }
Property Value
Type | Description |
---|---|
IComputer |
Methods
CreateClient(IComputer)
establishes a connection between the given device and the server.
Declaration
public TNetworkClient CreateClient(IComputer clientDevice)
Parameters
Type | Name | Description |
---|---|---|
IComputer | clientDevice | The device connecting to the server. |
Returns
Type | Description |
---|---|
TNetworkClient | An instance of TNetworkClient representing the connection. The connection is closed when the client instance is disposed of. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
GetHackable(IWorldManager)
Gets an implementation of IHackable based on this server.
Declaration
public IHackable GetHackable(IWorldManager world)
Parameters
Type | Name | Description |
---|---|---|
IWorldManager | world | The world where hackable data is stored. |
Returns
Type | Description |
---|---|
IHackable | The created hackable. |
GetPossibleVulnerabilities()
Get a set of vulnerabilities that make sense for this type of server.
Declaration
protected virtual IEnumerable<Vulnerability> GetPossibleVulnerabilities()
Returns
Type | Description |
---|---|
IEnumerable<Vulnerability> | An iteration of Vulnerability objects describing security threats that make sense to exist on servers of this type. |
OnClientDisconnect(TNetworkClient)
In a derived type, handles clients disconnecting.
Declaration
protected abstract void OnClientDisconnect(TNetworkClient client)
Parameters
Type | Name | Description |
---|---|---|
TNetworkClient | client | The client that disconnected from the server. |
OnConnected(TNetworkClient)
In a derived type, responds to incoming connections.
Declaration
protected abstract TServerConnection OnConnected(TNetworkClient client)
Parameters
Type | Name | Description |
---|---|---|
TNetworkClient | client | The client connecting to the server. |
Returns
Type | Description |
---|---|
TServerConnection | An instance of |
OnCreateClient(IComputer, IConnectionHandle)
In a derived type, creates the instance of TNetworkClient
for a given device
connecting to the server.
Declaration
protected abstract TNetworkClient OnCreateClient(IComputer clientDevice, IConnectionHandle connectionId)
Parameters
Type | Name | Description |
---|---|---|
IComputer | clientDevice | The computer connecting to the server. |
IConnectionHandle | connectionId | A handle to the connection being established. |
Returns
Type | Description |
---|---|
TNetworkClient | An instance of |
WaitForNextConnectionAsync()
Wait for an icoming connection and accept it.
Declaration
public Task<TServerConnection> WaitForNextConnectionAsync()
Returns
Type | Description |
---|---|
Task<TServerConnection> | The |
Events
ClientConnected
An event that fires when a new client connects to the server.
Declaration
public event Action<TServerConnection>? ClientConnected
Event Type
Type | Description |
---|---|
Action<TServerConnection> |