refactoring: removed external dependencies from server, removed webhooks from server
This commit is contained in:
@@ -31,11 +31,11 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers)
|
public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers)
|
||||||
{
|
{
|
||||||
var parameters = new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
|
var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
|
||||||
CreateOrJoin(parameters);
|
CreateOrJoin(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateOrJoin(RagonRoomPayload parameters)
|
public void CreateOrJoin(RagonRoomParameters parameters)
|
||||||
{
|
{
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
_buffer.WriteOperation(RagonOperation.JOIN_OR_CREATE_ROOM);
|
_buffer.WriteOperation(RagonOperation.JOIN_OR_CREATE_ROOM);
|
||||||
@@ -48,15 +48,15 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void Create(string sceneName, int minPlayers, int maxPlayers)
|
public void Create(string sceneName, int minPlayers, int maxPlayers)
|
||||||
{
|
{
|
||||||
Create(null, new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers)
|
public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers)
|
||||||
{
|
{
|
||||||
Create(roomId, new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
Create(roomId, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(string roomId, RagonRoomPayload parameters)
|
public void Create(string roomId, RagonRoomParameters parameters)
|
||||||
{
|
{
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
_buffer.WriteOperation(RagonOperation.CREATE_ROOM);
|
_buffer.WriteOperation(RagonOperation.CREATE_ROOM);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
namespace Ragon.Protocol
|
namespace Ragon.Protocol
|
||||||
{
|
{
|
||||||
public class RagonRoomPayload: IRagonSerializable
|
public class RagonRoomParameters: IRagonSerializable
|
||||||
{
|
{
|
||||||
public string Scene { get; set; }
|
public string Scene { get; set; }
|
||||||
public int Min { get; set; }
|
public int Min { get; set; }
|
||||||
|
|||||||
@@ -28,4 +28,9 @@
|
|||||||
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="NLog" Version="5.3.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using NLog;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayLogger: IRagonLogger
|
||||||
|
{
|
||||||
|
private Logger _nlogger;
|
||||||
|
|
||||||
|
public RelayLogger(string tag)
|
||||||
|
{
|
||||||
|
_nlogger = LogManager.GetLogger(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warning(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Info(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(Exception ex)
|
||||||
|
{
|
||||||
|
_nlogger.Error(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Trace(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Trace(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayLoggerFactory: IRagonLoggerFactory
|
||||||
|
{
|
||||||
|
public IRagonLogger GetLogger(string tag)
|
||||||
|
{
|
||||||
|
return new RelayLogger(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using Ragon.Server;
|
||||||
|
using Ragon.Server.Entity;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayRoomPlugin: BaseRoomPlugin
|
||||||
|
{
|
||||||
|
public void Tick(float dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAttached()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Room attached");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDetached()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Room detached");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnEntityCreate(RagonRoomPlayer creator, RagonEntity entity)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Entity created: {entity.Id}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnEntityRemove(RagonRoomPlayer destroyer, RagonEntity entity)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Entity destroyed: {entity.Id}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,23 +14,30 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Ragon.Server;
|
using Ragon.Server;
|
||||||
using Ragon.Server.ENetServer;
|
using Ragon.Server.ENetServer;
|
||||||
using Ragon.Server.WebSocketServer;
|
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.WebSocketServer;
|
||||||
|
|
||||||
namespace Ragon.Relay;
|
namespace Ragon.Relay
|
||||||
|
|
||||||
public class Relay
|
|
||||||
{
|
{
|
||||||
|
public class Relay
|
||||||
|
{
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
var logger = LogManager.GetLogger("Ragon.Relay");
|
LoggerManager.SetLoggerFactory(new RelayLoggerFactory());
|
||||||
|
|
||||||
|
var logger = LoggerManager.GetLogger("Relay");
|
||||||
logger.Info("Relay Application");
|
logger.Info("Relay Application");
|
||||||
|
|
||||||
var configuration = RagonServerConfiguration.Load("relay.config.json");
|
var data = File.ReadAllText("relay.config.json");
|
||||||
|
var configuration = JsonConvert.DeserializeObject<RelayConfiguration>(data);
|
||||||
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
||||||
|
|
||||||
INetworkServer networkServer = new ENetServer();
|
INetworkServer networkServer = new ENetServer();
|
||||||
@@ -45,8 +52,26 @@ public class Relay
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var relay = new RagonServer(networkServer, plugin, configuration);
|
var serverConfiguration = new RagonServerConfiguration()
|
||||||
logger.Info("Started");
|
{
|
||||||
|
LimitConnections = configuration.LimitConnections,
|
||||||
|
LimitRooms = configuration.LimitConnections,
|
||||||
|
LimitBufferedEvents = configuration.LimitConnections,
|
||||||
|
LimitPlayersPerRoom = configuration.LimitConnections,
|
||||||
|
Port = configuration.Port,
|
||||||
|
Protocol = configuration.Protocol,
|
||||||
|
ServerKey = configuration.ServerKey,
|
||||||
|
ServerTickRate = configuration.ServerTickRate,
|
||||||
|
};
|
||||||
|
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
|
||||||
relay.Start();
|
relay.Start();
|
||||||
|
while (relay.IsRunning)
|
||||||
|
{
|
||||||
|
relay.Tick();
|
||||||
|
Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
relay.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ragon.Relay
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public struct RelayConfiguration
|
||||||
|
{
|
||||||
|
public string ServerKey;
|
||||||
|
public string ServerType;
|
||||||
|
public ushort ServerTickRate;
|
||||||
|
public string Protocol;
|
||||||
|
public ushort Port;
|
||||||
|
public int LimitConnections;
|
||||||
|
public int LimitPlayersPerRoom;
|
||||||
|
public int LimitRooms;
|
||||||
|
public int LimitBufferedEvents;
|
||||||
|
public int LimitUserData;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Server.Entity;
|
|
||||||
using Ragon.Server.IO;
|
|
||||||
using Ragon.Server.Plugin;
|
|
||||||
using Ragon.Server.Room;
|
|
||||||
|
|
||||||
namespace Ragon.Relay;
|
|
||||||
|
|
||||||
public class RelayRoomPlugin : BaseRoomPlugin
|
|
||||||
{
|
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
public override bool OnPlayerJoined(RagonRoomPlayer player)
|
|
||||||
{
|
|
||||||
// _logger.Trace($"Player {player.Name}|{player.Connection.Id} joined");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool OnPlayerLeaved(RagonRoomPlayer player)
|
|
||||||
{
|
|
||||||
// _logger.Trace($"Player {player.Name}|{player.Connection.Id} leaved");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool OnData(RagonRoomPlayer player, byte[] data)
|
|
||||||
{
|
|
||||||
// _logger.Trace($"Data received from {player.Name}|{player.Connection.Id}");
|
|
||||||
|
|
||||||
// All Players
|
|
||||||
// Room.ReplicateData(new Byte[] { 30, 40, 50 }, NetworkChannel.RELIABLE);
|
|
||||||
// Selected Player
|
|
||||||
// Room.ReplicateData(new byte[] { 10, 30, 40 }, new List<RagonRoomPlayer> { player }, NetworkChannel.RELIABLE);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,20 +2,11 @@
|
|||||||
"serverKey": "defaultkey",
|
"serverKey": "defaultkey",
|
||||||
"serverType": "enet",
|
"serverType": "enet",
|
||||||
"serverTickRate": 30,
|
"serverTickRate": 30,
|
||||||
"gameProtocol": "1.0.0",
|
"protocol": "1.0.0",
|
||||||
"port": 5000,
|
"port": 5000,
|
||||||
"httpPort": 5001,
|
|
||||||
"httpKey": "defaultkey",
|
|
||||||
"limitConnections": 4095,
|
"limitConnections": 4095,
|
||||||
"limitPlayersPerRoom": 20,
|
"limitPlayersPerRoom": 20,
|
||||||
"limitRooms": 200,
|
"limitRooms": 200,
|
||||||
"limitBufferedEvents": 50,
|
"limitBufferedEvents": 50,
|
||||||
"limitUserData": 1024,
|
"limitUserData": 1024
|
||||||
"webHooks":
|
|
||||||
{
|
|
||||||
"room-created": "http://127.0.0.1:3000/service/create-room",
|
|
||||||
"room-removed": "http://127.0.0.1:3000/service/remove-room",
|
|
||||||
"room-joined": "http://127.0.0.1:3000/service/join-room",
|
|
||||||
"room-leaved": "http://127.0.0.1:3000/service/leave-room"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
|
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
|
||||||
<PackageReference Include="NLog" Version="5.2.2" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -15,26 +15,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using ENet;
|
using ENet;
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.ENetServer
|
namespace Ragon.Server.ENetServer
|
||||||
{
|
{
|
||||||
public sealed class ENetServer : INetworkServer
|
public sealed class ENetServer : INetworkServer
|
||||||
{
|
{
|
||||||
public Executor Executor => _executor;
|
|
||||||
|
|
||||||
private readonly Host _host = new();
|
private readonly Host _host = new();
|
||||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(ENetServer));
|
||||||
|
|
||||||
private ENetConnection[] _connections = Array.Empty<ENetConnection>();
|
private ENetConnection[] _connections = Array.Empty<ENetConnection>();
|
||||||
private INetworkListener _listener;
|
private INetworkListener _listener;
|
||||||
private uint _protocol;
|
private uint _protocol;
|
||||||
private ENet.Event _event;
|
private ENet.Event _event;
|
||||||
private Executor _executor = new();
|
|
||||||
|
|
||||||
public void Start(INetworkListener listener, NetworkConfiguration configuration)
|
public void Listen(INetworkListener listener, NetworkConfiguration configuration)
|
||||||
{
|
{
|
||||||
Library.Initialize();
|
Library.Initialize();
|
||||||
|
|
||||||
@@ -79,7 +77,7 @@ namespace Ragon.Server.ENetServer
|
|||||||
{
|
{
|
||||||
if (!IsValidProtocol(_event.Data))
|
if (!IsValidProtocol(_event.Data))
|
||||||
{
|
{
|
||||||
_logger.Warn($"Mismatched protocol Server: {RagonVersion.Parse(_protocol)} Client: {RagonVersion.Parse(_event.Data)}, close connection");
|
_logger.Warning($"Mismatched protocol Server: {RagonVersion.Parse(_protocol)} Client: {RagonVersion.Parse(_event.Data)}, close connection");
|
||||||
_event.Peer.DisconnectNow(0);
|
_event.Peer.DisconnectNow(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,6 @@
|
|||||||
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
|
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="NLog" Version="5.2.2" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.WebSocketServer;
|
namespace Ragon.Server.WebSocketServer;
|
||||||
|
|
||||||
public sealed class WebSocketConnection : INetworkConnection
|
public sealed class WebSocketConnection : INetworkConnection
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(WebSocketConnection));
|
||||||
public ushort Id { get; }
|
public ushort Id { get; }
|
||||||
public INetworkChannel Reliable { get; private set; }
|
public INetworkChannel Reliable { get; private set; }
|
||||||
public INetworkChannel Unreliable { get; private set; }
|
public INetworkChannel Unreliable { get; private set; }
|
||||||
|
|||||||
@@ -16,17 +16,16 @@
|
|||||||
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.WebSocketServer;
|
namespace Ragon.Server.WebSocketServer;
|
||||||
|
|
||||||
public class WebSocketServer : INetworkServer
|
public class WebSocketServer : INetworkServer
|
||||||
{
|
{
|
||||||
public Executor Executor => _executor;
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(WebSocketServer));
|
||||||
|
|
||||||
private ILogger _logger = LogManager.GetCurrentClassLogger();
|
|
||||||
private INetworkListener _networkListener;
|
private INetworkListener _networkListener;
|
||||||
private Stack<ushort> _sequencer;
|
private Stack<ushort> _sequencer;
|
||||||
private Executor _executor;
|
private Executor _executor;
|
||||||
@@ -67,7 +66,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Warn(ex);
|
_logger.Error(ex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +112,8 @@ public class WebSocketServer : INetworkServer
|
|||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
|
_executor.Update();
|
||||||
|
|
||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
await conn.Flush();
|
await conn.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start(
|
public void Listen(
|
||||||
INetworkListener listener,
|
INetworkListener listener,
|
||||||
NetworkConfiguration configuration
|
NetworkConfiguration configuration
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,11 +16,6 @@
|
|||||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
<PackageReference Include="NLog" Version="5.2.2" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ragon.Protocol\Ragon.Protocol.csproj" />
|
<ProjectReference Include="..\Ragon.Protocol\Ragon.Protocol.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,47 +14,45 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
using Ragon.Server.Plugin.Web;
|
using Ragon.Server.Logging;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Handler
|
||||||
namespace Ragon.Server.Handler;
|
|
||||||
|
|
||||||
public sealed class AuthorizationOperation: BaseOperation
|
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
public sealed class AuthorizationOperation : BaseOperation
|
||||||
private readonly RagonWebHookPlugin _webhook;
|
|
||||||
private readonly RagonContextObserver _observer;
|
|
||||||
private readonly RagonBuffer _writer;
|
|
||||||
private readonly RagonServerConfiguration _configuration;
|
|
||||||
|
|
||||||
public AuthorizationOperation(
|
|
||||||
RagonBuffer reader,
|
|
||||||
RagonBuffer writer,
|
|
||||||
RagonWebHookPlugin webhook,
|
|
||||||
RagonContextObserver observer,
|
|
||||||
RagonServerConfiguration configuration): base(reader, writer)
|
|
||||||
{
|
{
|
||||||
_webhook = webhook;
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(AuthorizationOperation));
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly RagonContextObserver _observer;
|
||||||
|
private readonly RagonServerConfiguration _configuration;
|
||||||
|
private readonly RagonBuffer _writer;
|
||||||
|
|
||||||
|
public AuthorizationOperation(RagonBuffer reader,
|
||||||
|
RagonBuffer writer,
|
||||||
|
IServerPlugin serverPlugin,
|
||||||
|
RagonContextObserver observer,
|
||||||
|
RagonServerConfiguration configuration) : base(reader, writer)
|
||||||
|
{
|
||||||
|
_serverPlugin = serverPlugin;
|
||||||
|
_configuration = configuration;
|
||||||
_observer = observer;
|
_observer = observer;
|
||||||
_writer = writer;
|
_writer = writer;
|
||||||
_configuration = configuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
{
|
{
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
||||||
{
|
{
|
||||||
_logger.Warn("Player already authorized!");
|
_logger.Warning("Player already authorized!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.ConnectionStatus == ConnectionStatus.InProcess)
|
if (context.ConnectionStatus == ConnectionStatus.InProcess)
|
||||||
{
|
{
|
||||||
_logger.Warn("Player already request authorization!");
|
_logger.Warning("Player already request authorization!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +63,8 @@ public sealed class AuthorizationOperation: BaseOperation
|
|||||||
|
|
||||||
if (key == configuration.ServerKey)
|
if (key == configuration.ServerKey)
|
||||||
{
|
{
|
||||||
if (_webhook.RequestAuthorization(context, payload))
|
var authorizeViaWebHook = _serverPlugin.OnAuthorize(new ConnectionRequest() { PeerID = context.Connection.Id });
|
||||||
|
if (authorizeViaWebHook)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, Guid.NewGuid().ToString(), name, payload);
|
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, Guid.NewGuid().ToString(), name, payload);
|
||||||
@@ -113,6 +112,5 @@ public sealed class AuthorizationOperation: BaseOperation
|
|||||||
|
|
||||||
_logger.Trace($"Connection {context.Connection.Id}");
|
_logger.Trace($"Connection {context.Connection.Id}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Entity;
|
using Ragon.Server.Entity;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityCreateOperation : BaseOperation
|
public sealed class EntityCreateOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityCreateOperation));
|
||||||
|
|
||||||
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Event;
|
using Ragon.Server.Event;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityEventOperation : BaseOperation
|
public sealed class EntityEventOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityEventOperation));
|
||||||
|
|
||||||
public EntityEventOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public EntityEventOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ public sealed class EntityEventOperation : BaseOperation
|
|||||||
|
|
||||||
if (!room.Entities.TryGetValue(entityId, out var ent))
|
if (!room.Entities.TryGetValue(entityId, out var ent))
|
||||||
{
|
{
|
||||||
_logger.Warn($"Entity not found for event with Id {entityId}");
|
_logger.Warning($"Entity not found for event with Id {entityId}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityOwnershipOperation : BaseOperation
|
public sealed class EntityOwnershipOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityOwnershipOperation));
|
||||||
|
|
||||||
public EntityOwnershipOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public EntityOwnershipOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Entity;
|
using Ragon.Server.Entity;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityDestroyOperation: BaseOperation
|
public sealed class EntityDestroyOperation: BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityDestroyOperation));
|
||||||
|
|
||||||
public EntityDestroyOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public EntityDestroyOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityStateOperation: BaseOperation
|
public sealed class EntityStateOperation: BaseOperation
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityStateOperation));
|
||||||
|
|
||||||
public EntityStateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public EntityStateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler
|
namespace Ragon.Server.Handler
|
||||||
{
|
{
|
||||||
public class PlayerUserDataOperation : BaseOperation
|
public class PlayerUserDataOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(PlayerUserDataOperation));
|
||||||
private readonly int _userDataLimit;
|
private readonly int _userDataLimit;
|
||||||
|
|
||||||
public PlayerUserDataOperation(
|
public PlayerUserDataOperation(
|
||||||
@@ -23,7 +23,7 @@ namespace Ragon.Server.Handler
|
|||||||
{
|
{
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
_logger.Warning($"Player {context.Connection.Id} not authorized for this request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,34 +14,33 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
using Ragon.Server.Plugin.Web;
|
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler
|
||||||
|
|
||||||
public sealed class RoomCreateOperation : BaseOperation
|
|
||||||
{
|
{
|
||||||
private readonly RagonRoomPayload _roomPayload = new();
|
public sealed class RoomCreateOperation : BaseOperation
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
{
|
||||||
private readonly IServerPlugin _serverPlugin;
|
private IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomCreateOperation));
|
||||||
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
|
|
||||||
|
|
||||||
public RoomCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin, RagonWebHookPlugin ragonWebHook) : base(reader, writer)
|
private readonly RagonRoomParameters _roomParameters = new();
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
|
||||||
|
public RoomCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin) : base(reader,
|
||||||
|
writer)
|
||||||
{
|
{
|
||||||
_serverPlugin = serverPlugin;
|
_serverPlugin = serverPlugin;
|
||||||
_ragonWebHookPlugin = ragonWebHook;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
{
|
{
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
_logger.Warning($"Player {context.Connection.Id} not authorized for this request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,18 +59,19 @@ public sealed class RoomCreateOperation : BaseOperation
|
|||||||
var sendData = Writer.ToArray();
|
var sendData = Writer.ToArray();
|
||||||
context.Connection.Reliable.Send(sendData);
|
context.Connection.Reliable.Send(sendData);
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} join failed to room {roomId}, room already exist");
|
_logger.Trace(
|
||||||
|
$"Player {context.Connection.Id}|{context.LobbyPlayer.Name} join failed to room {roomId}, room already exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_roomPayload.Deserialize(Reader);
|
_roomParameters.Deserialize(Reader);
|
||||||
|
|
||||||
var information = new RoomInformation()
|
var information = new RoomInformation()
|
||||||
{
|
{
|
||||||
Scene = _roomPayload.Scene,
|
Scene = _roomParameters.Scene,
|
||||||
Max = _roomPayload.Max,
|
Max = _roomParameters.Max,
|
||||||
Min = _roomPayload.Min,
|
Min = _roomParameters.Min,
|
||||||
};
|
};
|
||||||
|
|
||||||
var lobbyPlayer = context.LobbyPlayer;
|
var lobbyPlayer = context.LobbyPlayer;
|
||||||
@@ -87,9 +87,8 @@ public sealed class RoomCreateOperation : BaseOperation
|
|||||||
context.Lobby.Persist(room);
|
context.Lobby.Persist(room);
|
||||||
context.SetRoom(room, roomPlayer);
|
context.SetRoom(room, roomPlayer);
|
||||||
|
|
||||||
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
|
_logger.Trace(
|
||||||
|
$"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
|
|
||||||
|
|
||||||
JoinSuccess(roomPlayer, room, Writer);
|
JoinSuccess(roomPlayer, room, Writer);
|
||||||
|
|
||||||
@@ -124,4 +123,5 @@ public sealed class RoomCreateOperation : BaseOperation
|
|||||||
var sendData = writer.ToArray();
|
var sendData = writer.ToArray();
|
||||||
player.Connection.Reliable.Send(sendData);
|
player.Connection.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Event;
|
using Ragon.Server.Event;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public class RoomEventOperation : BaseOperation
|
public class RoomEventOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomEventOperation));
|
||||||
|
|
||||||
public RoomEventOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public RoomEventOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -17,7 +18,7 @@ public class RoomEventOperation : BaseOperation
|
|||||||
{
|
{
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
_logger.Warning($"Player {context.Connection.Id} not authorized for this request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,25 +14,22 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Plugin.Web;
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomJoinOperation : BaseOperation
|
public sealed class RoomJoinOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomJoinOperation));
|
||||||
private readonly RagonWebHookPlugin _webHook;
|
|
||||||
|
|
||||||
public RoomJoinOperation(RagonBuffer reader, RagonBuffer writer, RagonWebHookPlugin plugin) : base(reader, writer)
|
public RoomJoinOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
_webHook = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
{
|
{
|
||||||
var roomId = Reader.ReadString();
|
var roomId = Reader.ReadString();
|
||||||
@@ -49,8 +46,6 @@ public sealed class RoomJoinOperation : BaseOperation
|
|||||||
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
context.SetRoom(existsRoom, player);
|
context.SetRoom(existsRoom, player);
|
||||||
|
|
||||||
_webHook.RoomJoined(context, existsRoom, player);
|
|
||||||
|
|
||||||
JoinSuccess(context, existsRoom, Writer);
|
JoinSuccess(context, existsRoom, Writer);
|
||||||
|
|
||||||
existsRoom.RestoreBufferedEvents(player);
|
existsRoom.RestoreBufferedEvents(player);
|
||||||
|
|||||||
@@ -14,50 +14,46 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
using Ragon.Server.Plugin.Web;
|
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomJoinOrCreateOperation : BaseOperation
|
public sealed class RoomJoinOrCreateOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly RagonRoomPayload _roomPayload = new();
|
private IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomJoinOrCreateOperation));
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
|
||||||
private readonly IServerPlugin _serverPlugin;
|
|
||||||
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
|
|
||||||
|
|
||||||
public RoomJoinOrCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin, RagonWebHookPlugin plugin): base(reader, writer)
|
private readonly RagonRoomParameters _roomParameters = new();
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
|
||||||
|
public RoomJoinOrCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin): base(reader, writer)
|
||||||
{
|
{
|
||||||
_serverPlugin = serverPlugin;
|
_serverPlugin = serverPlugin;
|
||||||
_ragonWebHookPlugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
{
|
{
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn("Player not authorized for this request");
|
_logger.Warning("Player not authorized for this request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomId = Guid.NewGuid().ToString();
|
var roomId = Guid.NewGuid().ToString();
|
||||||
var lobbyPlayer = context.LobbyPlayer;
|
var lobbyPlayer = context.LobbyPlayer;
|
||||||
|
|
||||||
_roomPayload.Deserialize(Reader);
|
_roomParameters.Deserialize(Reader);
|
||||||
|
|
||||||
if (context.Lobby.FindRoomByScene(_roomPayload.Scene, out var existsRoom))
|
if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom))
|
||||||
{
|
{
|
||||||
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
|
|
||||||
context.SetRoom(existsRoom, player);
|
context.SetRoom(existsRoom, player);
|
||||||
|
|
||||||
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
|
|
||||||
|
|
||||||
JoinSuccess(player, existsRoom, Writer);
|
JoinSuccess(player, existsRoom, Writer);
|
||||||
|
|
||||||
existsRoom.RestoreBufferedEvents(player);
|
existsRoom.RestoreBufferedEvents(player);
|
||||||
@@ -68,16 +64,16 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
|||||||
{
|
{
|
||||||
var information = new RoomInformation()
|
var information = new RoomInformation()
|
||||||
{
|
{
|
||||||
Scene = _roomPayload.Scene,
|
Scene = _roomParameters.Scene,
|
||||||
Max = _roomPayload.Max,
|
Max = _roomParameters.Max,
|
||||||
Min = _roomPayload.Min,
|
Min = _roomParameters.Min,
|
||||||
};
|
};
|
||||||
|
|
||||||
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
||||||
var room = new RagonRoom(roomId, information, roomPlugin);
|
var room = new RagonRoom(roomId, information, roomPlugin);
|
||||||
|
|
||||||
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
|
_serverPlugin.OnRoomCreate(lobbyPlayer, room);
|
||||||
|
|
||||||
room.Plugin.OnAttached(room);
|
room.Plugin.OnAttached(room);
|
||||||
|
|
||||||
|
|||||||
@@ -14,22 +14,18 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomLeaveOperation: BaseOperation
|
public sealed class RoomLeaveOperation: BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomLeaveOperation));
|
||||||
private readonly RagonWebHookPlugin _webHook;
|
|
||||||
|
|
||||||
public RoomLeaveOperation(RagonBuffer reader, RagonBuffer writer, RagonWebHookPlugin plugin): base(reader, writer)
|
public RoomLeaveOperation(RagonBuffer reader, RagonBuffer writer): base(reader, writer)
|
||||||
{
|
{
|
||||||
_webHook = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
@@ -44,8 +40,6 @@ public sealed class RoomLeaveOperation: BaseOperation
|
|||||||
plugin.OnPlayerLeaved(roomPlayer);
|
plugin.OnPlayerLeaved(roomPlayer);
|
||||||
room.DetachPlayer(roomPlayer);
|
room.DetachPlayer(roomPlayer);
|
||||||
|
|
||||||
_webHook.RoomLeaved(context, room, roomPlayer);
|
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomOwnershipOperation : BaseOperation
|
public sealed class RoomOwnershipOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomOwnershipOperation));
|
||||||
|
|
||||||
public RoomOwnershipOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public RoomOwnershipOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomUserDataOperation : BaseOperation
|
public sealed class RoomUserDataOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RoomUserDataOperation));
|
||||||
private readonly int _userDataLimit;
|
private readonly int _userDataLimit;
|
||||||
|
|
||||||
public RoomUserDataOperation(
|
public RoomUserDataOperation(
|
||||||
@@ -39,7 +39,7 @@ public sealed class RoomUserDataOperation : BaseOperation
|
|||||||
{
|
{
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
_logger.Warning($"Player {context.Connection.Id} not authorized for this request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public class SceneLoadOperation: BaseOperation
|
public class SceneLoadOperation: BaseOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(SceneLoadOperation));
|
||||||
|
|
||||||
public SceneLoadOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer) {}
|
public SceneLoadOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer) {}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class SceneLoadOperation: BaseOperation
|
|||||||
|
|
||||||
if (roomOwner.Connection.Id != currentPlayer.Connection.Id)
|
if (roomOwner.Connection.Id != currentPlayer.Connection.Id)
|
||||||
{
|
{
|
||||||
_logger.Warn("Only owner can change scene!");
|
_logger.Warning("Only owner can change scene!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,22 +14,22 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Entity;
|
using Ragon.Server.Entity;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler;
|
namespace Ragon.Server.Handler
|
||||||
|
|
||||||
public sealed class SceneLoadedOperation : BaseOperation
|
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
public sealed class SceneLoadedOperation : BaseOperation
|
||||||
|
|
||||||
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer): base(reader, writer)
|
|
||||||
{
|
{
|
||||||
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(SceneLoadedOperation));
|
||||||
|
|
||||||
|
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
@@ -42,7 +42,7 @@ public sealed class SceneLoadedOperation : BaseOperation
|
|||||||
var room = context.Room;
|
var room = context.Room;
|
||||||
if (player.IsLoaded)
|
if (player.IsLoaded)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Player {player.Name}:{player.Connection.Id} already ready");
|
_logger.Warning($"Player {player.Name}:{player.Connection.Id} already ready");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,4 +160,5 @@ public sealed class SceneLoadedOperation : BaseOperation
|
|||||||
foreach (var player in receviersList)
|
foreach (var player in receviersList)
|
||||||
player.Connection.Reliable.Send(sendData);
|
player.Connection.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.Json;
|
|
||||||
using Ragon.Server.IO;
|
|
||||||
using Ragon.Server.Plugin;
|
|
||||||
|
|
||||||
namespace Ragon.Server.Http;
|
|
||||||
|
|
||||||
public class RagonHttpServer
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
|
||||||
private readonly IExecutor _executor;
|
|
||||||
private readonly IServerPlugin _serverPlugin;
|
|
||||||
private HttpListener _httpListener;
|
|
||||||
private CancellationTokenSource _cancellationTokenSource;
|
|
||||||
|
|
||||||
public RagonHttpServer(IExecutor executor, IServerPlugin serverPlugin)
|
|
||||||
{
|
|
||||||
_serverPlugin = serverPlugin;
|
|
||||||
_executor = executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void StartAccept(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
var context = await _httpListener.GetContextAsync();
|
|
||||||
|
|
||||||
if (context.Request.HttpMethod != "POST")
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = 404;
|
|
||||||
context.Response.ContentLength64 = 0;
|
|
||||||
context.Response.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = context.Request;
|
|
||||||
var reader = new StreamReader(request.InputStream, request.ContentEncoding);
|
|
||||||
var rawJson = await reader.ReadToEndAsync();
|
|
||||||
var httpCommand = JsonDocument.Parse(rawJson);
|
|
||||||
if (httpCommand != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var command = httpCommand.RootElement.GetProperty("command");
|
|
||||||
var payload = httpCommand.RootElement.GetProperty("payload");
|
|
||||||
|
|
||||||
if (_serverPlugin.OnCommand(command.GetString() ?? "none", payload.GetRawText()))
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = 200;
|
|
||||||
context.Response.ContentLength64 = 0;
|
|
||||||
context.Response.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = 403;
|
|
||||||
context.Response.ContentLength64 = 0;
|
|
||||||
context.Response.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex);
|
|
||||||
|
|
||||||
context.Response.StatusCode = 505;
|
|
||||||
context.Response.ContentLength64 = 0;
|
|
||||||
context.Response.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Response.StatusCode = 403;
|
|
||||||
context.Response.ContentLength64 = 0;
|
|
||||||
context.Response.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Start(RagonServerConfiguration configuration)
|
|
||||||
{
|
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
|
||||||
_logger.Info($"Listen at http://0.0.0.0:{configuration.HttpPort}/");
|
|
||||||
|
|
||||||
_httpListener = new HttpListener();
|
|
||||||
_httpListener.Prefixes.Add($"http://127.0.0.1:{configuration.HttpPort}/");
|
|
||||||
_httpListener.Start();
|
|
||||||
|
|
||||||
_executor.Run(() => StartAccept(_cancellationTokenSource.Token), TaskCreationOptions.LongRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop()
|
|
||||||
{
|
|
||||||
_cancellationTokenSource.Cancel();
|
|
||||||
_httpListener.Stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,9 +18,8 @@ namespace Ragon.Server.IO;
|
|||||||
|
|
||||||
public interface INetworkServer
|
public interface INetworkServer
|
||||||
{
|
{
|
||||||
public Executor Executor { get; }
|
|
||||||
public void Stop();
|
public void Stop();
|
||||||
public void Update();
|
public void Update();
|
||||||
public void Broadcast(byte[] data, NetworkChannel channel);
|
public void Broadcast(byte[] data, NetworkChannel channel);
|
||||||
public void Start(INetworkListener listener, NetworkConfiguration configuration);
|
public void Listen(INetworkListener listener, NetworkConfiguration configuration);
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using NLog;
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Lobby;
|
namespace Ragon.Server.Lobby;
|
||||||
@@ -23,7 +23,7 @@ namespace Ragon.Server.Lobby;
|
|||||||
public class LobbyInMemory : IRagonLobby
|
public class LobbyInMemory : IRagonLobby
|
||||||
{
|
{
|
||||||
private readonly List<RagonRoom> _rooms = new();
|
private readonly List<RagonRoom> _rooms = new();
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(LobbyInMemory));
|
||||||
|
|
||||||
public IReadOnlyList<IRagonRoom> Rooms => _rooms.AsReadOnly();
|
public IReadOnlyList<IRagonRoom> Rooms => _rooms.AsReadOnly();
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class LobbyInMemory : IRagonLobby
|
|||||||
{
|
{
|
||||||
if (existRagonRoom.PlayerCount >= existRagonRoom.PlayerMax)
|
if (existRagonRoom.PlayerCount >= existRagonRoom.PlayerMax)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Room with id {roomId} fulfilled");
|
_logger.Warning($"Room with id {roomId} fulfilled");
|
||||||
|
|
||||||
room = default;
|
room = default;
|
||||||
return false;
|
return false;
|
||||||
@@ -58,7 +58,7 @@ public class LobbyInMemory : IRagonLobby
|
|||||||
{
|
{
|
||||||
if (existsRoom.PlayerCount >= existsRoom.PlayerMax)
|
if (existsRoom.PlayerCount >= existsRoom.PlayerMax)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Room with scene {sceneName} fulfilled");
|
_logger.Warning($"Room with scene {sceneName} fulfilled");
|
||||||
|
|
||||||
room = default;
|
room = default;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -18,10 +18,23 @@ using Ragon.Server.IO;
|
|||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin;
|
namespace Ragon.Server.Plugin
|
||||||
|
|
||||||
public class BaseServerPlugin: IServerPlugin
|
|
||||||
{
|
{
|
||||||
|
public class ConnectionRequest
|
||||||
|
{
|
||||||
|
public int PeerID { get; set; }
|
||||||
|
|
||||||
|
public void Approve()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BaseServerPlugin : IServerPlugin
|
||||||
|
{
|
||||||
public IRagonServer Server { get; protected set; }
|
public IRagonServer Server { get; protected set; }
|
||||||
|
|
||||||
public virtual void OnAttached(IRagonServer server)
|
public virtual void OnAttached(IRagonServer server)
|
||||||
@@ -34,6 +47,11 @@ public class BaseServerPlugin: IServerPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool OnAuthorize(ConnectionRequest request)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room)
|
public virtual bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -44,6 +62,16 @@ public class BaseServerPlugin: IServerPlugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool OnRoomJoined(RagonRoomPlayer player, RagonRoom room)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnRoomLeaved(RagonRoomPlayer player, RagonRoom room)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool OnCommand(string command, string payload)
|
public virtual bool OnCommand(string command, string payload)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -53,4 +81,5 @@ public class BaseServerPlugin: IServerPlugin
|
|||||||
{
|
{
|
||||||
return new BaseRoomPlugin();
|
return new BaseRoomPlugin();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,18 +14,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Ragon.Server.Http;
|
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
using Ragon.Server.Room;
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin;
|
namespace Ragon.Server.Plugin
|
||||||
|
|
||||||
public interface IServerPlugin
|
|
||||||
{
|
{
|
||||||
|
public interface IServerPlugin
|
||||||
|
{
|
||||||
void OnAttached(IRagonServer server);
|
void OnAttached(IRagonServer server);
|
||||||
void OnDetached();
|
void OnDetached();
|
||||||
|
bool OnAuthorize(ConnectionRequest request);
|
||||||
bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room);
|
bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room);
|
||||||
bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room);
|
bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room);
|
||||||
|
bool OnRoomJoined(RagonRoomPlayer player, RagonRoom room);
|
||||||
|
bool OnRoomLeaved(RagonRoomPlayer player, RagonRoom room);
|
||||||
bool OnCommand(string command, string payload);
|
bool OnCommand(string command, string payload);
|
||||||
IRoomPlugin CreateRoomPlugin(RoomInformation information);
|
IRoomPlugin CreateRoomPlugin(RoomInformation information);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using Ragon.Server.Room;
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class PlayerDto
|
|
||||||
{
|
|
||||||
public string Id { get; set;}
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public PlayerDto(RagonRoomPlayer ragonRoomPlayer)
|
|
||||||
{
|
|
||||||
Id = ragonRoomPlayer.Id;
|
|
||||||
Name = ragonRoomPlayer.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using Ragon.Server.Room;
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class RoomDto
|
|
||||||
{
|
|
||||||
public string Id { get; set;}
|
|
||||||
public int PlayerMin { get; set; }
|
|
||||||
public int PlayerMax { get; set; }
|
|
||||||
public int PlayerCount { get; set; }
|
|
||||||
public PlayerDto[] Players { get; set; }
|
|
||||||
|
|
||||||
public RoomDto(RagonRoom room)
|
|
||||||
{
|
|
||||||
Id = room.Id;
|
|
||||||
PlayerMin = room.PlayerMin;
|
|
||||||
PlayerMax = room.PlayerMax;
|
|
||||||
PlayerCount = room.PlayerCount;
|
|
||||||
|
|
||||||
Players = room.PlayerList.Select(p => new PlayerDto(p)).ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
using System.Text;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Ragon.Protocol;
|
|
||||||
using Ragon.Server.Handler;
|
|
||||||
using Ragon.Server.Lobby;
|
|
||||||
using Ragon.Server.Room;
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
public class RagonWebHookPlugin
|
|
||||||
{
|
|
||||||
private Dictionary<string, string> _webHooks;
|
|
||||||
|
|
||||||
private IRagonServer _server;
|
|
||||||
private HttpClient _httpClient;
|
|
||||||
|
|
||||||
public RagonWebHookPlugin(IRagonServer server, RagonServerConfiguration configuration)
|
|
||||||
{
|
|
||||||
_webHooks = new Dictionary<string, string>(configuration.WebHooks);
|
|
||||||
_httpClient = new HttpClient();
|
|
||||||
_server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool RequestAuthorization(RagonContext context, string payload)
|
|
||||||
{
|
|
||||||
if (_webHooks.TryGetValue("authorization-request", out var value))
|
|
||||||
{
|
|
||||||
var httpContent = new StringContent(payload, Encoding.UTF8, "application/json");
|
|
||||||
var executor = context.Executor;
|
|
||||||
executor.Run(async () =>
|
|
||||||
{
|
|
||||||
var authorizationOperation = (AuthorizationOperation) _server.ResolveHandler(RagonOperation.AUTHORIZE);
|
|
||||||
var response = await _httpClient.PostAsync(new Uri(value), httpContent);
|
|
||||||
if (response.StatusCode != HttpStatusCode.OK)
|
|
||||||
{
|
|
||||||
authorizationOperation.Reject(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var content = await response.Content.ReadAsStringAsync();
|
|
||||||
var authorizationResponse = JsonConvert.DeserializeObject<AuthorizationResponse>(content);
|
|
||||||
if (authorizationResponse != null)
|
|
||||||
{
|
|
||||||
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, authorizationResponse.Id, authorizationResponse.Name, authorizationResponse.Payload);
|
|
||||||
|
|
||||||
context.SetPlayer(lobbyPlayer);
|
|
||||||
authorizationOperation.Approve(context);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
authorizationOperation.Reject(context);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RoomCreated(RagonContext context, RagonRoom room, RagonRoomPlayer player)
|
|
||||||
{
|
|
||||||
if (_webHooks.TryGetValue("room-created", out var value) && !string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
var request = new RoomCreatedRequest()
|
|
||||||
{
|
|
||||||
Room = new RoomDto(room),
|
|
||||||
Player = new PlayerDto(player)
|
|
||||||
};
|
|
||||||
var content = JsonContent.Create(request);
|
|
||||||
var executor = context.Executor;
|
|
||||||
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RoomRemoved(RagonContext context, RagonRoom ragonRoom)
|
|
||||||
{
|
|
||||||
if (_webHooks.TryGetValue("room-removed", out var value) && !string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
var request = new RoomRemovedRequest()
|
|
||||||
{
|
|
||||||
Room = new RoomDto(ragonRoom)
|
|
||||||
};
|
|
||||||
var content = JsonContent.Create(request);
|
|
||||||
var executor = context.Executor;
|
|
||||||
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RoomJoined(RagonContext context, RagonRoom existsRoom, RagonRoomPlayer player)
|
|
||||||
{
|
|
||||||
if (_webHooks.TryGetValue("room-joined", out var value) && !string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
var request = new RoomJoinedRequest()
|
|
||||||
{
|
|
||||||
Room = new RoomDto(existsRoom),
|
|
||||||
Player = new PlayerDto(player)
|
|
||||||
};
|
|
||||||
var content = JsonContent.Create(request);
|
|
||||||
var executor = context.Executor;
|
|
||||||
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RoomLeaved(RagonContext context, RagonRoom room, RagonRoomPlayer roomPlayer)
|
|
||||||
{
|
|
||||||
if (_webHooks.TryGetValue("room-leaved", out var value) && !string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
var request = new RoomLeavedRequest()
|
|
||||||
{
|
|
||||||
Room = new RoomDto(room),
|
|
||||||
Player = new PlayerDto(roomPlayer)
|
|
||||||
};
|
|
||||||
var content = JsonContent.Create(request);
|
|
||||||
var executor = context.Executor;
|
|
||||||
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class AuthorizationRequest
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
public string Token;
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class RoomCreatedRequest
|
|
||||||
{
|
|
||||||
public RoomDto Room { get; set; }
|
|
||||||
public PlayerDto Player { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
public class RoomJoinedRequest
|
|
||||||
{
|
|
||||||
public RoomDto Room { get; set; }
|
|
||||||
public PlayerDto Player { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class RoomLeavedRequest
|
|
||||||
{
|
|
||||||
public RoomDto Room { get; set; }
|
|
||||||
public PlayerDto Player { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class RoomRemovedRequest
|
|
||||||
{
|
|
||||||
public RoomDto Room { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Ragon.Server.Plugin.Web;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class AuthorizationResponse
|
|
||||||
{
|
|
||||||
public string Id;
|
|
||||||
public string Name;
|
|
||||||
public string Payload;
|
|
||||||
}
|
|
||||||
@@ -26,8 +26,6 @@ public class RagonContext
|
|||||||
{
|
{
|
||||||
public ConnectionStatus ConnectionStatus { get; set; }
|
public ConnectionStatus ConnectionStatus { get; set; }
|
||||||
public INetworkConnection Connection { get; }
|
public INetworkConnection Connection { get; }
|
||||||
public IExecutor Executor { get; private set; }
|
|
||||||
public int LimitBufferedEvents { get; private set; }
|
|
||||||
public IRagonLobby Lobby { get; private set; }
|
public IRagonLobby Lobby { get; private set; }
|
||||||
public RagonLobbyPlayer? LobbyPlayer { get; private set; }
|
public RagonLobbyPlayer? LobbyPlayer { get; private set; }
|
||||||
public RagonRoom Room { get; private set; }
|
public RagonRoom Room { get; private set; }
|
||||||
@@ -35,9 +33,10 @@ public class RagonContext
|
|||||||
public RagonData UserData { get; private set; }
|
public RagonData UserData { get; private set; }
|
||||||
public RagonScheduler Scheduler { get; private set; }
|
public RagonScheduler Scheduler { get; private set; }
|
||||||
|
|
||||||
|
public int LimitBufferedEvents { get; private set; }
|
||||||
|
|
||||||
public RagonContext(
|
public RagonContext(
|
||||||
INetworkConnection connection,
|
INetworkConnection connection,
|
||||||
IExecutor executor,
|
|
||||||
IRagonLobby lobby,
|
IRagonLobby lobby,
|
||||||
RagonScheduler scheduler,
|
RagonScheduler scheduler,
|
||||||
int limitBufferedEvents)
|
int limitBufferedEvents)
|
||||||
@@ -45,7 +44,6 @@ public class RagonContext
|
|||||||
ConnectionStatus = ConnectionStatus.Unauthorized;
|
ConnectionStatus = ConnectionStatus.Unauthorized;
|
||||||
LimitBufferedEvents = limitBufferedEvents;
|
LimitBufferedEvents = limitBufferedEvents;
|
||||||
Connection = connection;
|
Connection = connection;
|
||||||
Executor = executor;
|
|
||||||
Lobby = lobby;
|
Lobby = lobby;
|
||||||
Scheduler = scheduler;
|
Scheduler = scheduler;
|
||||||
UserData = new RagonData();
|
UserData = new RagonData();
|
||||||
|
|||||||
@@ -15,30 +15,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Handler;
|
using Ragon.Server.Handler;
|
||||||
using Ragon.Server.Http;
|
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
using Ragon.Server.Plugin.Web;
|
|
||||||
using Ragon.Server.Time;
|
using Ragon.Server.Time;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server;
|
||||||
|
|
||||||
public class RagonServer : IRagonServer, INetworkListener
|
public class RagonServer : IRagonServer, INetworkListener
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private const string ServerVersion = "1.4.0";
|
||||||
|
|
||||||
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RagonServer));
|
||||||
private readonly INetworkServer _server;
|
private readonly INetworkServer _server;
|
||||||
private readonly BaseOperation[] _handlers;
|
private readonly BaseOperation[] _handlers;
|
||||||
private readonly IRagonLobby _lobby;
|
private readonly IRagonLobby _lobby;
|
||||||
private readonly IServerPlugin _serverPlugin;
|
private readonly IServerPlugin _serverPlugin;
|
||||||
private readonly Thread _dedicatedThread;
|
private readonly Thread _dedicatedThread;
|
||||||
private readonly Executor _executor;
|
|
||||||
private readonly RagonServerConfiguration _configuration;
|
private readonly RagonServerConfiguration _configuration;
|
||||||
private readonly RagonWebHookPlugin _webhooks;
|
|
||||||
private readonly RagonHttpServer _httpServer;
|
|
||||||
private readonly RagonBuffer _reader;
|
private readonly RagonBuffer _reader;
|
||||||
private readonly RagonBuffer _writer;
|
private readonly RagonBuffer _writer;
|
||||||
private readonly RagonScheduler _scheduler;
|
private readonly RagonScheduler _scheduler;
|
||||||
@@ -47,6 +44,9 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
private readonly Stopwatch _timer;
|
private readonly Stopwatch _timer;
|
||||||
private readonly RagonLobbyDispatcher _lobbySerializer;
|
private readonly RagonLobbyDispatcher _lobbySerializer;
|
||||||
private readonly long _tickRate = 0;
|
private readonly long _tickRate = 0;
|
||||||
|
private bool _isRunning = false;
|
||||||
|
|
||||||
|
public bool IsRunning => _isRunning;
|
||||||
|
|
||||||
public RagonServer(
|
public RagonServer(
|
||||||
INetworkServer server,
|
INetworkServer server,
|
||||||
@@ -54,7 +54,6 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
RagonServerConfiguration configuration)
|
RagonServerConfiguration configuration)
|
||||||
{
|
{
|
||||||
_server = server;
|
_server = server;
|
||||||
_executor = _server.Executor;
|
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_serverPlugin = plugin;
|
_serverPlugin = plugin;
|
||||||
_contextsByConnection = new Dictionary<ushort, RagonContext>();
|
_contextsByConnection = new Dictionary<ushort, RagonContext>();
|
||||||
@@ -62,10 +61,6 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_lobby = new LobbyInMemory();
|
_lobby = new LobbyInMemory();
|
||||||
_lobbySerializer = new RagonLobbyDispatcher(_lobby);
|
_lobbySerializer = new RagonLobbyDispatcher(_lobby);
|
||||||
_scheduler = new RagonScheduler();
|
_scheduler = new RagonScheduler();
|
||||||
_webhooks = new RagonWebHookPlugin(this, configuration);
|
|
||||||
_dedicatedThread = new Thread(Execute);
|
|
||||||
_dedicatedThread.IsBackground = true;
|
|
||||||
_httpServer = new RagonHttpServer(_executor, plugin);
|
|
||||||
_reader = new RagonBuffer();
|
_reader = new RagonBuffer();
|
||||||
_writer = new RagonBuffer();
|
_writer = new RagonBuffer();
|
||||||
_tickRate = 1000 / _configuration.ServerTickRate;
|
_tickRate = 1000 / _configuration.ServerTickRate;
|
||||||
@@ -80,11 +75,11 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_serverPlugin.OnAttached(this);
|
_serverPlugin.OnAttached(this);
|
||||||
|
|
||||||
_handlers = new BaseOperation[byte.MaxValue];
|
_handlers = new BaseOperation[byte.MaxValue];
|
||||||
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, _webhooks, contextObserver, configuration);
|
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, _serverPlugin, contextObserver, configuration);
|
||||||
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin, _webhooks);
|
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin, _webhooks);
|
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin);
|
||||||
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer, _webhooks);
|
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer, _webhooks);
|
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.SCENE_LOADED] = new SceneLoadedOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.SCENE_LOADED] = new SceneLoadedOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateOperation(_reader, _writer);
|
||||||
@@ -98,51 +93,43 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomUserDataOperation(_reader, _writer, _configuration.LimitUserData);
|
_handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomUserDataOperation(_reader, _writer, _configuration.LimitUserData);
|
||||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserData);
|
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserData);
|
||||||
|
|
||||||
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
|
||||||
}
|
}
|
||||||
|
public void Tick()
|
||||||
public void Execute()
|
|
||||||
{
|
|
||||||
_timer.Start();
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
if (_timer.ElapsedMilliseconds > _tickRate * 2)
|
if (_timer.ElapsedMilliseconds > _tickRate * 2)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Slow perfomance: {_timer.ElapsedMilliseconds}");
|
_logger.Warning($"Slow performance: {_timer.ElapsedMilliseconds}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_timer.ElapsedMilliseconds > _tickRate)
|
if (_timer.ElapsedMilliseconds > _tickRate)
|
||||||
{
|
{
|
||||||
_timer.Restart();
|
_timer.Restart();
|
||||||
_scheduler.Update(_tickRate);
|
_scheduler.Update(_timer.ElapsedMilliseconds / 1000.0f);
|
||||||
|
|
||||||
SendTimestamp();
|
SendTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
_executor.Update();
|
|
||||||
_server.Update();
|
_server.Update();
|
||||||
Thread.Sleep(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start(bool executeInDedicatedThread = false)
|
public void Start(bool executeInDedicatedThread = false)
|
||||||
{
|
{
|
||||||
|
CopyrightInfo();
|
||||||
|
|
||||||
var networkConfiguration = new NetworkConfiguration()
|
var networkConfiguration = new NetworkConfiguration()
|
||||||
{
|
{
|
||||||
LimitConnections = _configuration.LimitConnections,
|
LimitConnections = _configuration.LimitConnections,
|
||||||
Protocol = RagonVersion.Parse(_configuration.GameProtocol),
|
Protocol = RagonVersion.Parse(_configuration.Protocol),
|
||||||
Address = "0.0.0.0",
|
Address = "0.0.0.0",
|
||||||
Port = _configuration.Port,
|
Port = _configuration.Port,
|
||||||
};
|
};
|
||||||
|
|
||||||
_httpServer.Start(_configuration);
|
_server.Listen(this, networkConfiguration);
|
||||||
_server.Start(this, networkConfiguration);
|
_serverPlugin.OnAttached(this);
|
||||||
|
|
||||||
if (executeInDedicatedThread)
|
_timer.Start();
|
||||||
_dedicatedThread.Start();
|
|
||||||
else
|
_isRunning = true;
|
||||||
Execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -154,7 +141,7 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
|
|
||||||
public void OnConnected(INetworkConnection connection)
|
public void OnConnected(INetworkConnection connection)
|
||||||
{
|
{
|
||||||
var context = new RagonContext(connection, _executor, _lobby, _scheduler, _configuration.LimitBufferedEvents);
|
var context = new RagonContext(connection, _lobby, _scheduler, _configuration.LimitBufferedEvents);
|
||||||
|
|
||||||
_logger.Trace($"Connected: {connection.Id}");
|
_logger.Trace($"Connected: {connection.Id}");
|
||||||
_contextsByConnection.Add(connection.Id, context);
|
_contextsByConnection.Add(connection.Id, context);
|
||||||
@@ -168,8 +155,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
if (room != null)
|
if (room != null)
|
||||||
{
|
{
|
||||||
room.DetachPlayer(context.RoomPlayer);
|
room.DetachPlayer(context.RoomPlayer);
|
||||||
if (_lobby.RemoveIfEmpty(room))
|
|
||||||
_webhooks.RoomRemoved(context, room);
|
_lobby.RemoveIfEmpty(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Trace($"Disconnected: {connection.Id}");
|
_logger.Trace($"Disconnected: {connection.Id}");
|
||||||
@@ -297,4 +284,14 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
{
|
{
|
||||||
return _contextsByPlayerId.TryGetValue(playerId, out var context) ? context.LobbyPlayer : null;
|
return _contextsByPlayerId.TryGetValue(playerId, out var context) ? context.LobbyPlayer : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CopyrightInfo()
|
||||||
|
{
|
||||||
|
_logger.Info($"Ragon Server Version: {ServerVersion}");
|
||||||
|
_logger.Info($"Machine Name: {Environment.MachineName}");
|
||||||
|
_logger.Info($"OS: {Environment.OSVersion}");
|
||||||
|
_logger.Info($"Processors: {Environment.ProcessorCount}");
|
||||||
|
_logger.Info($"Runtime Version: {Environment.Version}");
|
||||||
|
_logger.Info($"Server Tick Rate: {_configuration.ServerTickRate}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using NLog;
|
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server;
|
||||||
|
|
||||||
public enum ServerType
|
public enum ServerType
|
||||||
@@ -29,50 +26,20 @@ public enum ServerType
|
|||||||
public struct RagonServerConfiguration
|
public struct RagonServerConfiguration
|
||||||
{
|
{
|
||||||
public string ServerKey;
|
public string ServerKey;
|
||||||
public string ServerType;
|
|
||||||
public ushort ServerTickRate;
|
public ushort ServerTickRate;
|
||||||
public string GameProtocol;
|
public string Protocol;
|
||||||
public ushort Port;
|
public ushort Port;
|
||||||
public ushort HttpPort;
|
|
||||||
public string HttpKey;
|
|
||||||
public int LimitConnections;
|
public int LimitConnections;
|
||||||
public int LimitPlayersPerRoom;
|
public int LimitPlayersPerRoom;
|
||||||
public int LimitRooms;
|
public int LimitRooms;
|
||||||
public int LimitBufferedEvents;
|
public int LimitBufferedEvents;
|
||||||
public int LimitUserData;
|
public int LimitUserData;
|
||||||
public Dictionary<string, string> WebHooks;
|
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
private static readonly string ServerVersion = "1.3.2";
|
|
||||||
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
||||||
{
|
{
|
||||||
{"enet", Server.ServerType.ENET},
|
{ "enet", Server.ServerType.ENET },
|
||||||
{"websocket", Server.ServerType.WEBSOCKET}
|
{ "websocket", Server.ServerType.WEBSOCKET }
|
||||||
};
|
};
|
||||||
|
|
||||||
public static RagonServerConfiguration Load(string filePath)
|
|
||||||
{
|
|
||||||
CopyrightInfo();
|
|
||||||
|
|
||||||
var data = File.ReadAllText(filePath);
|
|
||||||
var configuration = JsonConvert.DeserializeObject<RagonServerConfiguration>(data);
|
|
||||||
return configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CopyrightInfo()
|
|
||||||
{
|
|
||||||
Logger.Info($"Server Version: {ServerVersion}");
|
|
||||||
Logger.Info($"Machine Name: {Environment.MachineName}");
|
|
||||||
Logger.Info($"OS: {Environment.OSVersion}");
|
|
||||||
Logger.Info($"Processors: {Environment.ProcessorCount}");
|
|
||||||
Logger.Info($"Runtime Version: {Environment.Version}");
|
|
||||||
Logger.Info("==================================");
|
|
||||||
Logger.Info(@" ___ _ ___ ___ _ _ ");
|
|
||||||
Logger.Info(@" | _ \ /_\ / __|/ _ \| \| |");
|
|
||||||
Logger.Info(@" | / / _ \ (_ | (_) | .` |");
|
|
||||||
Logger.Info(@" |_|_\/_/ \_\___|\___/|_|\_|");
|
|
||||||
Logger.Info("==================================");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServerType GetServerType(string type) => _serverTypes[type];
|
public static ServerType GetServerType(string type) => _serverTypes[type];
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user