Compare commits
5 Commits
v1.4.1
...
v1.4.3-fix
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bb84daf03 | |||
| f1c5c99417 | |||
| e52e940fda | |||
| e78e8048ff | |||
| 5136f08dab |
@@ -65,6 +65,8 @@ namespace Ragon.Protocol
|
|||||||
{
|
{
|
||||||
public class RagonBuffer
|
public class RagonBuffer
|
||||||
{
|
{
|
||||||
|
private const int MaxBufferSize = 1024 * 1024; // 1MB max buffer size
|
||||||
|
|
||||||
private int _read;
|
private int _read;
|
||||||
private int _write;
|
private int _write;
|
||||||
private uint[] _buckets;
|
private uint[] _buckets;
|
||||||
@@ -331,6 +333,9 @@ namespace Ragon.Protocol
|
|||||||
var limit = (size + 32 - 1) / 32;
|
var limit = (size + 32 - 1) / 32;
|
||||||
var capacity = size;
|
var capacity = size;
|
||||||
|
|
||||||
|
if (index + limit >= _buckets.Length)
|
||||||
|
Resize(size);
|
||||||
|
|
||||||
for (int i = 0; i < limit; i++)
|
for (int i = 0; i < limit; i++)
|
||||||
{
|
{
|
||||||
var dataSize = capacity > 32 ? 32 : capacity;
|
var dataSize = capacity > 32 ? 32 : capacity;
|
||||||
@@ -401,6 +406,12 @@ namespace Ragon.Protocol
|
|||||||
public void FromArray(byte[] data)
|
public void FromArray(byte[] data)
|
||||||
{
|
{
|
||||||
var length = data.Length;
|
var length = data.Length;
|
||||||
|
|
||||||
|
if (length > MaxBufferSize)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Input data exceeds maximum buffer size: {length} bytes > {MaxBufferSize} bytes");
|
||||||
|
}
|
||||||
|
|
||||||
var bucketsCount = length / 4 + 1;
|
var bucketsCount = length / 4 + 1;
|
||||||
|
|
||||||
if (_buckets.Length < bucketsCount)
|
if (_buckets.Length < bucketsCount)
|
||||||
@@ -490,7 +501,14 @@ namespace Ragon.Protocol
|
|||||||
|
|
||||||
private void Resize(int capacity)
|
private void Resize(int capacity)
|
||||||
{
|
{
|
||||||
var buckets = new uint[_buckets.Length * 2 + capacity];
|
var newSize = _buckets.Length * 2 + capacity;
|
||||||
|
|
||||||
|
if (newSize * 4 > MaxBufferSize)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Buffer size limit exceeded: {newSize * 4} bytes > {MaxBufferSize} bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
var buckets = new uint[newSize];
|
||||||
Array.Copy(_buckets, buckets, _buckets.Length);
|
Array.Copy(_buckets, buckets, _buckets.Length);
|
||||||
_buckets = buckets;
|
_buckets = buckets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env
|
||||||
|
|
||||||
WORKDIR /App
|
WORKDIR /App
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ COPY . ./
|
|||||||
RUN dotnet restore
|
RUN dotnet restore
|
||||||
RUN dotnet publish -c Release -o out
|
RUN dotnet publish -c Release -o out
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/runtime:7.0
|
FROM mcr.microsoft.com/dotnet/runtime:9.0
|
||||||
|
|
||||||
WORKDIR /App
|
WORKDIR /App
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>Ragon.Relay</RootNamespace>
|
<RootNamespace>Ragon.Relay</RootNamespace>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
|||||||
@@ -56,9 +56,11 @@ namespace Ragon.Relay
|
|||||||
var serverConfiguration = new RagonServerConfiguration()
|
var serverConfiguration = new RagonServerConfiguration()
|
||||||
{
|
{
|
||||||
LimitConnections = configuration.LimitConnections,
|
LimitConnections = configuration.LimitConnections,
|
||||||
LimitRooms = configuration.LimitConnections,
|
LimitRooms = configuration.LimitRooms,
|
||||||
LimitBufferedEvents = configuration.LimitConnections,
|
LimitBufferedEvents = configuration.LimitBufferedEvents,
|
||||||
LimitPlayersPerRoom = configuration.LimitConnections,
|
LimitPlayersPerRoom = configuration.LimitPlayersPerRoom,
|
||||||
|
LimitUserDataSize = configuration.LimitUserDataSize,
|
||||||
|
LimitPropertySize = configuration.LimitPropertySize,
|
||||||
Port = configuration.Port,
|
Port = configuration.Port,
|
||||||
Protocol = configuration.Protocol,
|
Protocol = configuration.Protocol,
|
||||||
ServerKey = configuration.ServerKey,
|
ServerKey = configuration.ServerKey,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Ragon.Relay
|
|||||||
public int LimitPlayersPerRoom;
|
public int LimitPlayersPerRoom;
|
||||||
public int LimitRooms;
|
public int LimitRooms;
|
||||||
public int LimitBufferedEvents;
|
public int LimitBufferedEvents;
|
||||||
public int LimitUserData;
|
public int LimitUserDataSize;
|
||||||
|
public int LimitPropertySize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,12 @@
|
|||||||
"serverAddress": "*",
|
"serverAddress": "*",
|
||||||
"serverTickRate": 30,
|
"serverTickRate": 30,
|
||||||
"protocol": "1.0.0",
|
"protocol": "1.0.0",
|
||||||
"port": 5000,
|
"port": 8000,
|
||||||
"limitConnections": 4095,
|
"limitConnections": 4095,
|
||||||
"limitPlayersPerRoom": 20,
|
"limitPlayersPerRoom": 20,
|
||||||
"limitRooms": 200,
|
"limitRooms": 200,
|
||||||
"limitBufferedEvents": 50,
|
"limitBufferedEvents": 50,
|
||||||
"limitUserData": 1024
|
"limitUserDataSize": 1024,
|
||||||
|
"limitPropertySize": 512,
|
||||||
|
"limitConnectionsPerProject": 100
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System.Buffers;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
@@ -42,7 +43,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
_executor = new Executor();
|
_executor = new Executor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void StartAccept(CancellationToken cancellationToken)
|
public async ValueTask StartAccept(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
@@ -72,30 +73,40 @@ public class WebSocketServer : INetworkServer
|
|||||||
|
|
||||||
_connections[connection.Id] = connection;
|
_connections[connection.Id] = connection;
|
||||||
|
|
||||||
StartListen(connection, cancellationToken);
|
_ = StartListen(connection, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async void StartListen(WebSocketConnection connection, CancellationToken cancellationToken)
|
async ValueTask StartListen(WebSocketConnection connection, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_activeConnections.Add(connection);
|
_activeConnections.Add(connection);
|
||||||
_networkListener.OnConnected(connection);
|
_networkListener.OnConnected(connection);
|
||||||
|
|
||||||
var webSocket = connection.Socket;
|
var webSocket = connection.Socket;
|
||||||
var bytes = new byte[2048];
|
var rawData = new byte[2048];
|
||||||
var buffer = new Memory<byte>(bytes);
|
var rawDataBuffer = new Memory<byte>(rawData);
|
||||||
|
var data = new ArrayBufferWriter<byte>();
|
||||||
|
|
||||||
while (
|
while (webSocket.State == WebSocketState.Open || !cancellationToken.IsCancellationRequested)
|
||||||
webSocket.State == WebSocketState.Open ||
|
|
||||||
!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await webSocket.ReceiveAsync(buffer, cancellationToken);
|
while (true)
|
||||||
if (result.Count > 0)
|
|
||||||
{
|
{
|
||||||
var payload = buffer.Slice(0, result.Count);
|
var result = await webSocket.ReceiveAsync(rawDataBuffer, cancellationToken);
|
||||||
_networkListener.OnData(connection, NetworkChannel.RELIABLE, payload.ToArray());
|
var payload = rawDataBuffer.Slice(0, result.Count);
|
||||||
|
|
||||||
|
data.Write(payload.Span);
|
||||||
|
|
||||||
|
if (result.EndOfMessage)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.WrittenCount > 0)
|
||||||
|
{
|
||||||
|
_networkListener.OnData(connection, NetworkChannel.RELIABLE, data.WrittenMemory.ToArray());
|
||||||
|
|
||||||
|
data.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -114,7 +125,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
{
|
{
|
||||||
_executor.Update();
|
_executor.Update();
|
||||||
|
|
||||||
Flush();
|
_ = Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Broadcast(byte[] data, NetworkChannel channel)
|
public void Broadcast(byte[] data, NetworkChannel channel)
|
||||||
@@ -123,7 +134,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
activeConnection.Reliable.Send(data);
|
activeConnection.Reliable.Send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void Flush()
|
public async ValueTask Flush()
|
||||||
{
|
{
|
||||||
foreach (var conn in _activeConnections)
|
foreach (var conn in _activeConnections)
|
||||||
await conn.Flush();
|
await conn.Flush();
|
||||||
|
|||||||
@@ -12,13 +12,25 @@ public class RagonData
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Read(RagonBuffer buffer)
|
public void Read(RagonBuffer buffer, int maxSize = 0)
|
||||||
{
|
{
|
||||||
var len = buffer.ReadUShort();
|
var len = buffer.ReadUShort();
|
||||||
|
var totalSize = 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
var key = buffer.ReadString();
|
var key = buffer.ReadString();
|
||||||
var valueSize = buffer.ReadUShort();
|
var valueSize = buffer.ReadUShort();
|
||||||
|
|
||||||
|
if (maxSize > 0)
|
||||||
|
{
|
||||||
|
totalSize += valueSize;
|
||||||
|
if (totalSize > maxSize)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"User data exceeds limit: {totalSize} > {maxSize}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (valueSize > 0)
|
if (valueSize > 0)
|
||||||
{
|
{
|
||||||
var value = buffer.ReadBytes(valueSize);
|
var value = buffer.ReadBytes(valueSize);
|
||||||
@@ -59,8 +71,6 @@ public class RagonData
|
|||||||
buffer.WriteString(prop.Key);
|
buffer.WriteString(prop.Key);
|
||||||
buffer.WriteUShort((ushort)prop.Value.Length);
|
buffer.WriteUShort((ushort)prop.Value.Length);
|
||||||
buffer.WriteBytes(prop.Value);
|
buffer.WriteBytes(prop.Value);
|
||||||
|
|
||||||
Console.WriteLine($"Key: {prop.Key} Value: {prop.Value.Length}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,13 +27,13 @@ public class RagonProperty : RagonPayload
|
|||||||
|
|
||||||
private uint[] _data;
|
private uint[] _data;
|
||||||
|
|
||||||
public RagonProperty(int size, bool isFixed)
|
public RagonProperty(int size, bool isFixed, int limit)
|
||||||
{
|
{
|
||||||
Size = size;
|
Size = size;
|
||||||
IsFixed = isFixed;
|
IsFixed = isFixed;
|
||||||
IsDirty = false;
|
IsDirty = false;
|
||||||
|
|
||||||
_data = new uint[128];
|
_data = new uint[limit / 4 + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Read(RagonBuffer buffer)
|
public void Read(RagonBuffer buffer)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ using Ragon.Server.IO;
|
|||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
using Ragon.Server.Logging;
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.Project;
|
||||||
|
|
||||||
namespace Ragon.Server.Handler
|
namespace Ragon.Server.Handler
|
||||||
{
|
{
|
||||||
@@ -30,19 +31,22 @@ namespace Ragon.Server.Handler
|
|||||||
private readonly RagonContextObserver _observer;
|
private readonly RagonContextObserver _observer;
|
||||||
private readonly RagonServerConfiguration _configuration;
|
private readonly RagonServerConfiguration _configuration;
|
||||||
private readonly RagonBuffer _writer;
|
private readonly RagonBuffer _writer;
|
||||||
|
private readonly ProjectRegistry _projectRegistry;
|
||||||
|
|
||||||
public AuthorizationOperation(RagonBuffer reader,
|
public AuthorizationOperation(RagonBuffer reader,
|
||||||
RagonBuffer writer,
|
RagonBuffer writer,
|
||||||
IRagonServer server,
|
IRagonServer server,
|
||||||
IServerPlugin serverPlugin,
|
IServerPlugin serverPlugin,
|
||||||
RagonContextObserver observer,
|
RagonContextObserver observer,
|
||||||
RagonServerConfiguration configuration) : base(reader, writer)
|
RagonServerConfiguration configuration,
|
||||||
|
ProjectRegistry projectRegistry) : base(reader, writer)
|
||||||
{
|
{
|
||||||
_serverPlugin = serverPlugin;
|
_serverPlugin = serverPlugin;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_observer = observer;
|
_observer = observer;
|
||||||
_writer = writer;
|
_writer = writer;
|
||||||
_server = server;
|
_server = server;
|
||||||
|
_projectRegistry = projectRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
@@ -59,31 +63,45 @@ namespace Ragon.Server.Handler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var configuration = _configuration;
|
var projectKey = Reader.ReadString();
|
||||||
var key = Reader.ReadString();
|
|
||||||
var name = Reader.ReadString();
|
var name = Reader.ReadString();
|
||||||
var payload = Reader.ReadString();
|
var payload = Reader.ReadString();
|
||||||
|
|
||||||
if (key == configuration.ServerKey)
|
if (!_projectRegistry.ValidateKey(projectKey))
|
||||||
{
|
{
|
||||||
var authorizeViaPlugin = _serverPlugin.OnAuthorize(new ConnectionRequest(_server, context.Connection.Id, payload));
|
_logger.Warning($"Invalid project key from connection {context.Connection.Id}");
|
||||||
if (authorizeViaPlugin)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
Approve(context, new ConnectionResponse(id, name, payload));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Warning($"Invalid key for connection {context.Connection.Id}");
|
|
||||||
|
|
||||||
Reject(context);
|
Reject(context);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_projectRegistry.CanConnect(projectKey))
|
||||||
|
{
|
||||||
|
_logger.Warning($"Connection limit reached for project key: {projectKey}");
|
||||||
|
Reject(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var authorizeViaPlugin = _serverPlugin.OnAuthorize(new ConnectionRequest(_server, context.Connection.Id, payload));
|
||||||
|
if (authorizeViaPlugin)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var project = _projectRegistry.GetOrCreateProject(projectKey);
|
||||||
|
if (project == null)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Failed to create project for key: {projectKey}");
|
||||||
|
Reject(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
Approve(context, new ConnectionResponse(id, name, payload), project.Id);
|
||||||
|
|
||||||
|
_projectRegistry.RegisterConnection(project.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Approve(RagonContext context, ConnectionResponse result)
|
public void Approve(RagonContext context, ConnectionResponse result, int projectId)
|
||||||
{
|
{
|
||||||
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, result.Id, result.Name, result.Payload);
|
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, result.Id, result.Name, result.Payload, projectId);
|
||||||
context.SetPlayer(lobbyPlayer);
|
context.SetPlayer(lobbyPlayer);
|
||||||
context.ConnectionStatus = ConnectionStatus.Authorized;
|
context.ConnectionStatus = ConnectionStatus.Authorized;
|
||||||
|
|
||||||
@@ -102,7 +120,7 @@ namespace Ragon.Server.Handler
|
|||||||
var sendData = _writer.ToArray();
|
var sendData = _writer.ToArray();
|
||||||
context.Connection.Reliable.Send(sendData);
|
context.Connection.Reliable.Send(sendData);
|
||||||
|
|
||||||
_logger.Trace($"Approved {context.Connection.Id} as {playerId}|{context.LobbyPlayer.Name}");
|
_logger.Trace($"Approved {context.Connection.Id} as {playerId}|{context.LobbyPlayer.Name} for project {projectId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reject(RagonContext context)
|
public void Reject(RagonContext context)
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ namespace Ragon.Server.Handler;
|
|||||||
public sealed class EntityCreateOperation : BaseOperation
|
public sealed class EntityCreateOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityCreateOperation));
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityCreateOperation));
|
||||||
|
private RagonServerConfiguration _configuration;
|
||||||
|
|
||||||
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer, RagonServerConfiguration configuration) :
|
||||||
|
base(reader, writer)
|
||||||
{
|
{
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
@@ -53,7 +56,7 @@ public sealed class EntityCreateOperation : BaseOperation
|
|||||||
var propertyType = Reader.ReadBool();
|
var propertyType = Reader.ReadBool();
|
||||||
var propertySize = Reader.ReadUShort();
|
var propertySize = Reader.ReadUShort();
|
||||||
|
|
||||||
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
entity.AddProperty(new RagonProperty(propertySize, propertyType, _configuration.LimitPropertySize));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Reader.Capacity > 0)
|
if (Reader.Capacity > 0)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Ragon.Server.Handler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.UserData.Read(Reader);
|
context.UserData.Read(Reader, _userDataLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ namespace Ragon.Server.Handler
|
|||||||
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, lobbyPlayer.ProjectId);
|
||||||
|
|
||||||
room.Plugin.OnAttached(room);
|
room.Plugin.OnAttached(room);
|
||||||
roomPlayer.OnAttached(room);
|
roomPlayer.OnAttached(room);
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ public sealed class RoomJoinOperation : BaseOperation
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (existsRoom.ProjectId != lobbyPlayer.ProjectId)
|
||||||
|
{
|
||||||
|
JoinFailed(context, Writer);
|
||||||
|
_logger.Warning($"Player {context.Connection.Id}|{lobbyPlayer.Name} tried to join room from different project");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
|||||||
|
|
||||||
if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom))
|
if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom))
|
||||||
{
|
{
|
||||||
|
if (existsRoom.ProjectId != lobbyPlayer.ProjectId)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Player {context.Connection.Id}|{lobbyPlayer.Name} tried to join room from different project");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -81,7 +87,7 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
|||||||
|
|
||||||
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, lobbyPlayer.ProjectId);
|
||||||
|
|
||||||
_serverPlugin.OnRoomCreate(lobbyPlayer, room);
|
_serverPlugin.OnRoomCreate(lobbyPlayer, room);
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ public sealed class RoomUserDataOperation : BaseOperation
|
|||||||
|
|
||||||
var room = context.Room;
|
var room = context.Room;
|
||||||
if (room != null)
|
if (room != null)
|
||||||
room.UserData.Read(Reader);
|
room.UserData.Read(Reader, _userDataLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,9 +27,11 @@ namespace Ragon.Server.Handler
|
|||||||
public sealed class SceneLoadedOperation : BaseOperation
|
public sealed class SceneLoadedOperation : BaseOperation
|
||||||
{
|
{
|
||||||
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(SceneLoadedOperation));
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(SceneLoadedOperation));
|
||||||
|
private RagonServerConfiguration _configuration;
|
||||||
|
|
||||||
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer, RagonServerConfiguration serverConfiguration) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
_configuration = serverConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||||
@@ -40,6 +42,7 @@ namespace Ragon.Server.Handler
|
|||||||
var owner = context.Room.Owner;
|
var owner = context.Room.Owner;
|
||||||
var player = context.RoomPlayer;
|
var player = context.RoomPlayer;
|
||||||
var room = context.Room;
|
var room = context.Room;
|
||||||
|
|
||||||
if (player.IsLoaded)
|
if (player.IsLoaded)
|
||||||
{
|
{
|
||||||
_logger.Warning($"Player {player.Name}:{player.Connection.Id} already ready");
|
_logger.Warning($"Player {player.Name}:{player.Connection.Id} already ready");
|
||||||
@@ -70,10 +73,11 @@ namespace Ragon.Server.Handler
|
|||||||
{
|
{
|
||||||
var propertyType = Reader.ReadBool();
|
var propertyType = Reader.ReadBool();
|
||||||
var propertySize = Reader.ReadUShort();
|
var propertySize = Reader.ReadUShort();
|
||||||
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
entity.AddProperty(new RagonProperty(propertySize, propertyType, _configuration.LimitPropertySize));
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomPlugin = room.Plugin;
|
var roomPlugin = room.Plugin;
|
||||||
|
|
||||||
if (!roomPlugin.OnEntityCreate(player, entity)) continue;
|
if (!roomPlugin.OnEntityCreate(player, entity)) continue;
|
||||||
|
|
||||||
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
||||||
|
|||||||
@@ -12,12 +12,17 @@ public class RagonLobbyDispatcher
|
|||||||
_lobby = lobby;
|
_lobby = lobby;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(RagonBuffer writer)
|
public void Write(RagonBuffer writer, int projectId = 0)
|
||||||
{
|
{
|
||||||
writer.Clear();
|
writer.Clear();
|
||||||
writer.WriteOperation(RagonOperation.ROOM_LIST_UPDATED);
|
writer.WriteOperation(RagonOperation.ROOM_LIST_UPDATED);
|
||||||
var rooms = _lobby.Rooms;
|
var rooms = _lobby.Rooms;
|
||||||
|
|
||||||
|
if (projectId > 0)
|
||||||
|
{
|
||||||
|
rooms = rooms.Where(r => r.ProjectId == projectId).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
writer.WriteUShort((ushort)rooms.Count);
|
writer.WriteUShort((ushort)rooms.Count);
|
||||||
for (int i = 0; i < rooms.Count; i++)
|
for (int i = 0; i < rooms.Count; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,12 +32,14 @@ public class RagonLobbyPlayer
|
|||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public string Payload { get; private set; }
|
public string Payload { get; private set; }
|
||||||
|
public int ProjectId { get; private set; }
|
||||||
|
|
||||||
public RagonLobbyPlayer(INetworkConnection connection, string id, string name, string payload)
|
public RagonLobbyPlayer(INetworkConnection connection, string id, string name, string payload, int projectId)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Connection = connection;
|
Connection = connection;
|
||||||
Payload = payload;
|
Payload = payload;
|
||||||
|
ProjectId = projectId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ namespace Ragon.Server.Plugin
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var operation = (AuthorizationOperation)_server.ResolveHandler(RagonOperation.AUTHORIZE);
|
var operation = (AuthorizationOperation)_server.ResolveHandler(RagonOperation.AUTHORIZE);
|
||||||
operation.Approve(ctx, new ConnectionResponse(id, name, payload));
|
operation.Approve(ctx, new ConnectionResponse(id, name, payload), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reject()
|
public void Reject()
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Ragon.Server.Project;
|
||||||
|
|
||||||
|
public class ProjectRegistry
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, RagonProject> _projectsByKey;
|
||||||
|
private readonly Dictionary<int, RagonProject> _projectsById;
|
||||||
|
private readonly int _connectionLimitPerProject;
|
||||||
|
|
||||||
|
public ProjectRegistry(int connectionLimitPerProject)
|
||||||
|
{
|
||||||
|
_projectsByKey = new Dictionary<string, RagonProject>();
|
||||||
|
_projectsById = new Dictionary<int, RagonProject>();
|
||||||
|
_connectionLimitPerProject = connectionLimitPerProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ValidateKey(string key)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (key.Length < 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RagonProject? GetOrCreateProject(string projectKey)
|
||||||
|
{
|
||||||
|
if (!_projectsByKey.TryGetValue(projectKey, out var project))
|
||||||
|
{
|
||||||
|
project = new RagonProject(projectKey);
|
||||||
|
_projectsByKey[projectKey] = project;
|
||||||
|
_projectsById[project.Id] = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanConnect(string projectKey)
|
||||||
|
{
|
||||||
|
if (!_projectsByKey.TryGetValue(projectKey, out var project))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return project.ActiveConnections < _connectionLimitPerProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegisterConnection(int projectId)
|
||||||
|
{
|
||||||
|
if (_projectsById.TryGetValue(projectId, out var project))
|
||||||
|
{
|
||||||
|
project.IncrementConnections();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnregisterConnection(int projectId)
|
||||||
|
{
|
||||||
|
if (_projectsById.TryGetValue(projectId, out var project))
|
||||||
|
{
|
||||||
|
project.DecrementConnections();
|
||||||
|
|
||||||
|
if (project.ActiveConnections <= 0)
|
||||||
|
{
|
||||||
|
_projectsByKey.Remove(project.Key);
|
||||||
|
_projectsById.Remove(projectId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RagonProject? GetProjectById(int projectId)
|
||||||
|
{
|
||||||
|
return _projectsById.TryGetValue(projectId, out var project) ? project : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Ragon.Server.Project;
|
||||||
|
|
||||||
|
public class RagonProject
|
||||||
|
{
|
||||||
|
private static int _idGenerator = 0;
|
||||||
|
|
||||||
|
public int Id { get; }
|
||||||
|
public string Key { get; }
|
||||||
|
public int ActiveConnections { get; private set; }
|
||||||
|
|
||||||
|
public RagonProject(string key)
|
||||||
|
{
|
||||||
|
Id = Interlocked.Increment(ref _idGenerator);
|
||||||
|
Key = key;
|
||||||
|
ActiveConnections = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void IncrementConnections()
|
||||||
|
{
|
||||||
|
ActiveConnections++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DecrementConnections()
|
||||||
|
{
|
||||||
|
if (ActiveConnections > 0)
|
||||||
|
ActiveConnections--;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,13 +21,14 @@ using Ragon.Server.IO;
|
|||||||
using Ragon.Server.Lobby;
|
using Ragon.Server.Lobby;
|
||||||
using Ragon.Server.Logging;
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.Project;
|
||||||
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 const string ServerVersion = "1.4.1";
|
private const string ServerVersion = "1.4.3";
|
||||||
|
|
||||||
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RagonServer));
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(RagonServer));
|
||||||
private readonly INetworkServer _server;
|
private readonly INetworkServer _server;
|
||||||
@@ -40,12 +41,14 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
private readonly RagonScheduler _scheduler;
|
private readonly RagonScheduler _scheduler;
|
||||||
private readonly Dictionary<ushort, RagonContext> _contextsByConnection;
|
private readonly Dictionary<ushort, RagonContext> _contextsByConnection;
|
||||||
private readonly Dictionary<string, RagonContext> _contextsByPlayerId;
|
private readonly Dictionary<string, RagonContext> _contextsByPlayerId;
|
||||||
|
private readonly ProjectRegistry _projectRegistry;
|
||||||
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;
|
private bool _isRunning = false;
|
||||||
|
|
||||||
public bool IsRunning => _isRunning;
|
public bool IsRunning => _isRunning;
|
||||||
|
public ProjectRegistry ProjectRegistry => _projectRegistry;
|
||||||
|
|
||||||
public RagonServer(
|
public RagonServer(
|
||||||
INetworkServer server,
|
INetworkServer server,
|
||||||
@@ -57,6 +60,7 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_serverPlugin = plugin;
|
_serverPlugin = plugin;
|
||||||
_contextsByConnection = new Dictionary<ushort, RagonContext>();
|
_contextsByConnection = new Dictionary<ushort, RagonContext>();
|
||||||
_contextsByPlayerId = new Dictionary<string, RagonContext>();
|
_contextsByPlayerId = new Dictionary<string, RagonContext>();
|
||||||
|
_projectRegistry = new ProjectRegistry(configuration.LimitConnectionsPerProject);
|
||||||
_lobby = new LobbyInMemory();
|
_lobby = new LobbyInMemory();
|
||||||
_lobbySerializer = new RagonLobbyDispatcher(_lobby);
|
_lobbySerializer = new RagonLobbyDispatcher(_lobby);
|
||||||
_scheduler = new RagonScheduler();
|
_scheduler = new RagonScheduler();
|
||||||
@@ -73,14 +77,14 @@ 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, this, _serverPlugin, contextObserver, configuration);
|
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, this, _serverPlugin, contextObserver, configuration, _projectRegistry);
|
||||||
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin, _configuration);
|
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin, _configuration);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin, _configuration);
|
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin, _configuration);
|
||||||
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer);
|
_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, _configuration);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateOperation(_reader, _writer, _configuration);
|
||||||
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityDestroyOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityDestroyOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new EntityStateOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new EntityStateOperation(_reader, _writer);
|
||||||
@@ -89,8 +93,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampSyncOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampSyncOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventOperation(_reader, _writer);
|
||||||
_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.LimitUserDataSize);
|
||||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserData);
|
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserDataSize);
|
||||||
}
|
}
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
@@ -157,7 +161,10 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
||||||
|
{
|
||||||
_contextsByPlayerId.Remove(context.LobbyPlayer.Id);
|
_contextsByPlayerId.Remove(context.LobbyPlayer.Id);
|
||||||
|
_projectRegistry.UnregisterConnection(context.LobbyPlayer.ProjectId);
|
||||||
|
}
|
||||||
|
|
||||||
_logger.Trace($"Disconnected: {connection.Id}");
|
_logger.Trace($"Disconnected: {connection.Id}");
|
||||||
}
|
}
|
||||||
@@ -179,7 +186,10 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
||||||
|
{
|
||||||
_contextsByPlayerId.Remove(context.LobbyPlayer.Id);
|
_contextsByPlayerId.Remove(context.LobbyPlayer.Id);
|
||||||
|
_projectRegistry.UnregisterConnection(context.LobbyPlayer.ProjectId);
|
||||||
|
}
|
||||||
|
|
||||||
_logger.Trace($"Timeout: {connection.Id}|{context.LobbyPlayer.Name}|{context.LobbyPlayer.Id}");
|
_logger.Trace($"Timeout: {connection.Id}|{context.LobbyPlayer.Name}|{context.LobbyPlayer.Id}");
|
||||||
}
|
}
|
||||||
@@ -200,7 +210,14 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_reader.FromArray(data);
|
_reader.FromArray(data);
|
||||||
|
|
||||||
var operation = _reader.ReadByte();
|
var operation = _reader.ReadByte();
|
||||||
_handlers[operation]?.Handle(context, channel);
|
|
||||||
|
if (operation >= _handlers.Length || _handlers[operation] == null)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Invalid operation code: {operation} from connection {connection.Id}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_handlers[operation].Handle(context, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -228,13 +245,14 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
|
|
||||||
public void SendRoomList()
|
public void SendRoomList()
|
||||||
{
|
{
|
||||||
_lobbySerializer.Write(_writer);
|
foreach (var (_, context) in _contextsByPlayerId)
|
||||||
|
|
||||||
var sendData = _writer.ToArray();
|
|
||||||
foreach (var (_, value) in _contextsByPlayerId)
|
|
||||||
{
|
{
|
||||||
if (value.Room == null) // If only in lobby, then send room list data
|
if (context.Room == null) // If only in lobby, then send room list data
|
||||||
value.Connection.Reliable.Send(sendData);
|
{
|
||||||
|
_lobbySerializer.Write(_writer, context.LobbyPlayer.ProjectId);
|
||||||
|
var sendData = _writer.ToArray();
|
||||||
|
context.Connection.Reliable.Send(sendData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ public struct RagonServerConfiguration
|
|||||||
public int LimitPlayersPerRoom;
|
public int LimitPlayersPerRoom;
|
||||||
public int LimitRooms;
|
public int LimitRooms;
|
||||||
public int LimitBufferedEvents;
|
public int LimitBufferedEvents;
|
||||||
public int LimitUserData;
|
public int LimitUserDataSize;
|
||||||
|
public int LimitPropertySize;
|
||||||
|
public int LimitConnectionsPerProject;
|
||||||
|
|
||||||
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public interface IRagonRoom
|
|||||||
{
|
{
|
||||||
public string Id { get; }
|
public string Id { get; }
|
||||||
public string Scene { get; }
|
public string Scene { get; }
|
||||||
|
public int ProjectId { get; }
|
||||||
public int PlayerMin { get; }
|
public int PlayerMin { get; }
|
||||||
public int PlayerMax { get; }
|
public int PlayerMax { get; }
|
||||||
public int PlayerCount { get; }
|
public int PlayerCount { get; }
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
|||||||
public int PlayerMax { get; private set; }
|
public int PlayerMax { get; private set; }
|
||||||
public int PlayerMin { get; private set; }
|
public int PlayerMin { get; private set; }
|
||||||
public int PlayerCount => WaitPlayersList.Count;
|
public int PlayerCount => WaitPlayersList.Count;
|
||||||
|
public int ProjectId { get; private set; }
|
||||||
|
|
||||||
public bool IsDone { get; private set; }
|
public bool IsDone { get; private set; }
|
||||||
|
|
||||||
@@ -53,13 +54,14 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
|||||||
private readonly List<RagonEvent> _bufferedEvents;
|
private readonly List<RagonEvent> _bufferedEvents;
|
||||||
private readonly int _limitBufferedEvents;
|
private readonly int _limitBufferedEvents;
|
||||||
|
|
||||||
public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin)
|
public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin, int projectId)
|
||||||
{
|
{
|
||||||
Id = roomId;
|
Id = roomId;
|
||||||
Scene = info.Scene;
|
Scene = info.Scene;
|
||||||
PlayerMax = info.Max;
|
PlayerMax = info.Max;
|
||||||
PlayerMin = info.Min;
|
PlayerMin = info.Min;
|
||||||
Plugin = roomPlugin;
|
Plugin = roomPlugin;
|
||||||
|
ProjectId = projectId;
|
||||||
|
|
||||||
Players = new Dictionary<ushort, RagonRoomPlayer>(info.Max);
|
Players = new Dictionary<ushort, RagonRoomPlayer>(info.Max);
|
||||||
WaitPlayersList = new List<RagonRoomPlayer>(info.Max);
|
WaitPlayersList = new List<RagonRoomPlayer>(info.Max);
|
||||||
|
|||||||
Reference in New Issue
Block a user