Skip to content

Commit

Permalink
Chaos.Networking Update
Browse files Browse the repository at this point in the history
  • Loading branch information
FallenDev committed Jul 19, 2024
1 parent 306fbb0 commit 8e2830f
Show file tree
Hide file tree
Showing 351 changed files with 8,134 additions and 3,724 deletions.
71 changes: 71 additions & 0 deletions Chaos.Networking/Abstractions/ConnectedClientBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Net.Sockets;
using Chaos.Cryptography.Abstractions;
using Chaos.Networking.Entities.Server;
using Chaos.Packets;
using Chaos.Packets.Abstractions;
using Microsoft.Extensions.Logging;

namespace Chaos.Networking.Abstractions;

/// <summary>
/// Represents a client that is connected to an <see cref="IServer{T}" />. This class defines the methods used to
/// communicate with the client.
/// </summary>
public abstract class ConnectedClientBase : SocketClientBase, IConnectedClient
{
/// <inheritdoc />
protected ConnectedClientBase(
Socket socket,
ICrypto crypto,
IPacketSerializer packetSerializer,
ILogger<ConnectedClientBase> logger)
: base(
socket,
crypto,
packetSerializer,
logger) { }

/// <inheritdoc />
public virtual void SendAcceptConnection(string message)
{
var args = new AcceptConnectionArgs
{
Message = message
};

Send(args);
}

/// <inheritdoc />
public virtual void SendHeartBeat(byte first, byte second)
{
var args = new HeartBeatResponseArgs
{
First = first,
Second = second
};

Send(args);
}

/// <inheritdoc />
public virtual void SendRedirect(IRedirect redirect)
{
var args = new RedirectArgs
{
EndPoint = redirect.EndPoint,
Seed = redirect.Seed,
Key = redirect.Key,
Name = redirect.Name,
Id = redirect.Id
};

Send(args);
}

/// <inheritdoc />
public override void Encrypt(ref Packet packet) => Crypto.ServerEncrypt(ref packet.Buffer, packet.OpCode, packet.Sequence);

/// <inheritdoc />
public override bool IsEncrypted(byte opCode) => Crypto.IsServerEncrypted(opCode);
}
26 changes: 26 additions & 0 deletions Chaos.Networking/Abstractions/ILobbyClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Chaos.Networking.Entities.Server;
using Chaos.Packets.Abstractions.Definitions;

namespace Chaos.Networking.Abstractions;

/// <summary>
/// Defines a pattern for an object that represents a client connected to a lobby server.
/// </summary>
public interface ILobbyClient : IConnectedClient
{
/// <summary>
/// Sends the connection information to the client.
/// </summary>
/// <remarks>
/// Opcode: <see cref="ServerOpCode.ConnectionInfo" />
/// </remarks>
void SendConnectionInfo(ConnectionInfoArgs args);

/// <summary>
/// Sends the server table response to the client.
/// </summary>
/// <remarks>
/// Opcode: <see cref="ServerOpCode.ServerTableResponse" />
/// </remarks>
void SendServerTableResponse(ServerTableResponseArgs args);
}
42 changes: 42 additions & 0 deletions Chaos.Networking/Abstractions/ILoginClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Chaos.Networking.Entities.Server;
using Chaos.Packets.Abstractions.Definitions;

namespace Chaos.Networking.Abstractions;

/// <summary>
/// Represents a client that is connected to the login server.
/// </summary>
public interface ILoginClient : IConnectedClient
{
/// <summary>
/// Sends a login control message to the client.
/// </summary>
/// <remarks>
/// Opcode: <see cref="ServerOpCode.LoginControl" />
/// </remarks>
void SendLoginControl(LoginControlArgs args);

/// <summary>
/// Sends a login message to the client.
/// </summary>
/// <remarks>
/// Opcode: <see cref="ServerOpCode.LoginMessage" />
/// </remarks>
void SendLoginMessage(LoginMessageArgs args);

/// <summary>
/// Sends a login notice to the client.
/// </summary>
/// <remarks>
/// Opcode: <see cref="ServerOpCode.LoginNotice" />
/// </remarks>
void SendLoginNotice(LoginNoticeArgs args);

/// <summary>
/// Sends meta data to the client.
/// </summary>
/// <remarks>
/// Opcode: <see cref="ServerOpCode.MetaData" />
/// </remarks>
void SendMetaData(MetaDataArgs args);
}
Loading

0 comments on commit 8e2830f

Please sign in to comment.