Skip to content

Commit

Permalink
version 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Niyaz Kashafutdinov committed Mar 30, 2024
1 parent bbddd22 commit 162984f
Show file tree
Hide file tree
Showing 52 changed files with 470 additions and 229 deletions.
2 changes: 1 addition & 1 deletion ReDI/ReDI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
19 changes: 19 additions & 0 deletions Remouse.Database/Remouse.Database.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReDI\ReDI.csproj" />
<ProjectReference Include="..\Remouse.Infrastructure\Remouse.Infrastructure.csproj" />
<ProjectReference Include="..\Remouse.Math\Remouse.Math.csproj" />
<ProjectReference Include="..\Remouse.Utils\Remouse.Utils.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion Remouse.GameClient/PackedSimulationListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private async void HandlePackedSimulationMessage(SimulationStateMessage message)
{
_simulationLoader.LoadSerialized(message.WorldState, message.Tick);
_networkEntityRegistry.SetLastUsedNetworkId(message.LastNetworkId);
await UniTask.WaitForSeconds(0.1f);
_simulationLoop.Start();

LLogger.Current.LogTrace(this, $"Setted and initialized simulation on host from packed simulation [StartTick:{message.Tick}]");
Expand Down
17 changes: 17 additions & 0 deletions Remouse.GameClient/Remouse.GameClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReDI\ReDI.csproj" />
<ProjectReference Include="..\Remouse.Infrastructure\Remouse.Infrastructure.csproj" />
<ProjectReference Include="..\Remouse.Network.Client\Remouse.Network.Client.csproj" />
<ProjectReference Include="..\Remouse.Simulation.Network\Remouse.Simulation.Network.csproj" />
<ProjectReference Include="..\Remouse.Simulation\Remouse.Simulation.csproj" />
<ProjectReference Include="..\Remouse.Utils\Remouse.Utils.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Remouse.GameServer/PlayerInputController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void HandleInputMessage(IPlayer player, BasePlayerInputMessage playerInp
var command = playerInput.AsCommand();
command.playerGameId = player.GameId;
_commandRunner.EnqueueCommand(command);

LLogger.Current.LogPlayerTrace(this, player, $"Enqueued command [WorldCommand:{command}]");
}
}
Expand Down
15 changes: 15 additions & 0 deletions Remouse.GameServer/Remouse.GameServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReDI\ReDI.csproj" />
<ProjectReference Include="..\Remouse.Database\Remouse.Database.csproj" />
<ProjectReference Include="..\Remouse.Network.Server\Remouse.Network.Server.csproj" />
<ProjectReference Include="..\Remouse.Simulation.Network\Remouse.Simulation.Network.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions Remouse.Infrastructure/Remouse.Infrastructure.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions Remouse.Math/Remouse.Math.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 1 addition & 4 deletions Remouse.Network.Client/Implementations/ClientTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public async UniTask<ClientConnectResult> ConnectAsync(IPEndPoint endPoint,

var authenticationCredentials = await _authorizeProvider.ProvideCredentialsAsync(cancellationToken);

_bytesWriter.Clear();
authenticationCredentials.Serialize(_bytesWriter);

var result = await _socket.ConnectAsync(endPoint, _bytesWriter, cancellationToken);
var result = await _socket.ConnectAsync(endPoint, authenticationCredentials.AuthorizationString, cancellationToken);

switch (result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ public class DummyAuthorizeProvider : IAuthorizeProvider
{
public async UniTask<AuthenticationCredentials> ProvideCredentialsAsync(CancellationToken cancellationToken)
{
return new AuthenticationCredentials()
{
authData = Encoding.UTF8.GetBytes("as"),
method = AuthenticationCredentials.Method.Debug
};
return new AuthenticationCredentials("Somecode");
}
}
}
19 changes: 19 additions & 0 deletions Remouse.Network.Client/Remouse.Network.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReDI\ReDI.csproj" />
<ProjectReference Include="..\Remouse.Network.Models\Remouse.Network.Models.csproj" />
<ProjectReference Include="..\Remouse.Network.Sockets\Remouse.Network.Sockets.csproj" />
<ProjectReference Include="..\Remouse.Utils\Remouse.Utils.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="UniTask" Version="2.5.3" />
</ItemGroup>

</Project>
24 changes: 3 additions & 21 deletions Remouse.Network.Models/AuthenticationCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,9 @@

namespace Remouse.Network.Models
{
public class AuthenticationCredentials : IBytesSerializable
public class AuthenticationCredentials
{
public byte[] authData;
public Method method;

public enum Method
{
Debug,
JWT
};

public void Serialize(IBytesWriter writer)
{
writer.WriteByteArray(authData);
writer.WriteString(method.ToString());
}

public void Deserialize(IBytesReader reader)
{
authData = reader.ReadByteArray();
method = Enum.Parse<Method>(reader.ReadString());
}
public AuthenticationCredentials(string authorizationString) { AuthorizationString = authorizationString; }
public string AuthorizationString { get; }
}
}
19 changes: 0 additions & 19 deletions Remouse.Network.Models/AuthenticationRequest.cs

This file was deleted.

12 changes: 12 additions & 0 deletions Remouse.Network.Models/Remouse.Network.Models.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Remouse.Serialization\Remouse.Serialization.csproj" />
</ItemGroup>

</Project>
14 changes: 1 addition & 13 deletions Remouse.Network.Server/Implementations/ServerTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,8 @@ private async void HandleConnectionRequest(ConnectionRequest request)
{
LLogger.Current.LogInfo(this, $"Connection request [Ip:{request.EndPoint}]");

var authRequest = new AuthenticationCredentials();
var reader = new BytesReader(request.Data);
var authRequest = new AuthenticationCredentials(request.Authorization);

try
{
authRequest.Deserialize(reader);
}
catch (Exception exception)
{
LLogger.Current.LogInfo(this, $"Exception on deserializing received authorization request [Ip:{request.EndPoint} connection request reject]. Message: {exception.Message}");
request.Reject();
return;
}

AuthorizeResult result;
try
{
Expand Down
18 changes: 18 additions & 0 deletions Remouse.Network.Server/Remouse.Network.Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Remouse.Network.Models\Remouse.Network.Models.csproj" />
<ProjectReference Include="..\Remouse.Network.Sockets\Remouse.Network.Sockets.csproj" />
<ProjectReference Include="..\Remouse.Utils\Remouse.Utils.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="UniTask" Version="2.5.3" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions Remouse.Network.Sockets/ConnectionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace Remouse.Network.Sockets
{
public abstract class ConnectionRequest
{
public byte[] Data { get; }
public string Authorization { get; }
public IPEndPoint EndPoint { get; }

internal ConnectionRequest(byte[] data, IPEndPoint endPoint)
internal ConnectionRequest(string authorization, IPEndPoint endPoint)
{
Data = data;
Authorization = authorization;
EndPoint = endPoint;
}

Expand Down
9 changes: 3 additions & 6 deletions Remouse.Network.Sockets/IClientSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

namespace Remouse.Network.Sockets
{
public interface IClientSocket : IClientSocketEvents, IDisposable
public interface IClientSocket
{
bool IsConnected { get; }
public int PingInMilliseconds { get; }
Task<SocketConnectResult> ConnectAsync(IPEndPoint host, IBytesWriter connectData = null, CancellationToken cancellationToken = default);
Task<SocketConnectResult> ConnectAsync(IPEndPoint host, string authorizationString = "", CancellationToken cancellationToken = default);
void Disconnect();
void Send(IBytesWriter data, DeliveryMethod deliveryMethod);
void PollEvents();
}

public interface IClientSocketEvents
{

event Action Connected;
event Action Disconnected;
event Action<IBytesReader> DataReceived;
Expand Down
7 changes: 2 additions & 5 deletions Remouse.Network.Sockets/IServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

namespace Remouse.Network.Sockets
{
public interface IServerSocket : IServerSocketEvents, IDisposable
public interface IServerSocket
{
void Start(ushort port, int maxConnections);
void Stop();
void PollEvents();
}

public interface IServerSocketEvents
{

event Action<ConnectionRequest> GotConnectionRequest;
event Action<Connection> Connected;
event Action<Connection> Disconnected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using LiteNetLib.Utils;
using Remouse.Serialization;
using Remouse.Utils;
Expand Down Expand Up @@ -66,7 +67,7 @@ private void HandleReceive(NetPeer peer, NetPacketReader reader, byte channel, L
{
LLogger.Current.LogTrace(this, $"Received data [ByteSize:{reader.AvailableBytes}]");

DataReceived?.Invoke(new LiteNetLibReader(reader));
DataReceived?.Invoke(new BytesReader(reader.GetRemainingBytes()));
}

private void HandleConnect(NetPeer peer)
Expand All @@ -89,26 +90,24 @@ private void HandleNetworkError(IPEndPoint endPoint, SocketError socketError)
Disconnected?.Invoke();
}

public async Task<SocketConnectResult> ConnectAsync(IPEndPoint host, IBytesWriter connectData,
public async Task<SocketConnectResult> ConnectAsync(IPEndPoint host, string authorizationString,
CancellationToken cancellationToken = default)
{
LLogger.Current.LogInfo(this, $"Start connecting [ServerIp:{host}]");

_connectingTcs = new TaskCompletionSource<SocketConnectResult>(cancellationToken);

cancellationToken.Register(() => _connectingTcs?.TrySetResult(SocketConnectResult.Cancelled));

if (!_netManager.IsRunning)
{
_netManager.Start();
}

_connectingTcs = new TaskCompletionSource<SocketConnectResult>(cancellationToken);

cancellationToken.Register(() => _connectingTcs?.TrySetResult(SocketConnectResult.Cancelled));

if (connectData != null)
if (authorizationString != null)
{

var bytes = connectData.GetBytes().ToArray();
LLogger.Current.LogInfo(this, $"Connecting with connection data [ByteSize:{bytes.Length}]");
_netManager.Connect(host, NetDataWriter.FromBytes(bytes, true));
LLogger.Current.LogInfo(this, $"Connecting with connection string [AuthorizationString:{authorizationString}]");
_netManager.Connect(host, authorizationString);
}
else
{
Expand Down Expand Up @@ -156,16 +155,5 @@ public void PollEvents()
{
_netManager.PollEvents();
}

public void Dispose()
{
Disconnected = null;
Connected = null;
DataReceived = null;

TrySetConnectResult(SocketConnectResult.Cancelled);

_netManager.Stop();
}
}
}
Loading

0 comments on commit 162984f

Please sign in to comment.