Compare commits

..

23 Commits

Author SHA1 Message Date
edmand46 9da397dd8c chore: update .net version 2025-10-04 17:43:57 +03:00
edmand46 6bb84daf03 chore: update Dockerfile 2025-10-04 17:41:02 +03:00
edmand46 f1c5c99417 chore: update version 2025-10-04 17:33:58 +03:00
edmand46 e52e940fda feat: multi project support, maintaince 2025-10-04 16:21:30 +03:00
edmand46 e78e8048ff feat: multi project support, maintaince 2025-10-04 16:17:41 +03:00
edmand46 5136f08dab feat: config for size of property
fix: websocket server now can receive large messages
fix: buffer resize on read array
2024-08-17 10:29:27 +03:00
edmand46 f7719e1bca chore: update server version 2024-08-15 23:27:53 +03:00
edmand46 211b24fe2b feat: added server address in relay.config.json 2024-08-15 23:20:23 +03:00
edmand46 bdf7d4f94a fix: connection key is invalid 2024-07-21 09:46:01 +03:00
edmand46 3bec19c2b2 chore: updated copyright 2024-05-19 12:26:42 +03:00
edmand46 0f2d316523 chore: updated projects properties for nuget 2024-05-19 12:25:56 +03:00
edmand46 7cf1353869 feat: improved server plugin api 2024-05-19 11:28:36 +03:00
edmand46 6199af3d1e fix: added checking max players per room from config 2024-05-19 08:59:36 +03:00
edmand46 e9dc45265a refactoring: removed external dependencies from server, removed webhooks from server 2024-05-19 08:56:21 +03:00
edmand46 b84538b238 fix: stop tick room on delete 2024-05-19 08:00:56 +03:00
edmand46 7a2196ff50 feat: improved api for plugins 2024-05-18 17:24:57 +03:00
edmand46 5634a182e6 feat: plugin api for replication of data 2024-05-16 21:28:47 +03:00
edmand46 0ede864f40 refactor: updated order of plugins callbacks 2024-05-12 11:37:44 +03:00
edmand46 646744c9a1 feat: player/room user data now available on joined event 2024-05-12 10:57:46 +03:00
edmand46 a9e6a3e853 feat: Room Properties and Player Properties 2024-05-09 21:26:32 +03:00
edmand46 c74ce0f00f Merge pull request #16 from edmand46/feat/room_property
Feat Room/Player Properties
2024-05-09 10:55:54 +03:00
edmand46 b39bd8bd0a fix: updated workflows 2024-04-14 19:23:08 +03:00
edmand46 12b80c546c fix: updated workflows 2024-04-14 19:14:57 +03:00
181 changed files with 1691 additions and 2229 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ jobs:
- name: Setup dotnet - name: Setup dotnet
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 7.0.x dotnet-version: 8.0.x
- name: Build - name: Build
shell: bash shell: bash
run: | run: |
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<RootNamespace>Ragon.Client.Simulation</RootNamespace> <RootNamespace>Ragon.Client.Simulation</RootNamespace>
<Authors>Eduard Kargin (Edmand46)</Authors> <Authors>Eduard Kargin</Authors>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+13 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -71,15 +71,15 @@ namespace Ragon.Client
internal bool PropertiesChanged => _propertiesChanged; internal bool PropertiesChanged => _propertiesChanged;
internal ushort SceneId => _sceneId; internal ushort SceneId => _sceneId;
private ushort _sceneId; private readonly ushort _sceneId;
private bool _propertiesChanged; private bool _propertiesChanged;
private RagonPayload _spawnPayload; private RagonPayload _spawnPayload;
private RagonPayload _destroyPayload; private RagonPayload _destroyPayload;
private readonly Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>(); private readonly Dictionary<int, OnEventDelegate> _events = new();
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>(); private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new();
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>(); private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new();
public RagonEntity(ushort type = 0, ushort sceneId = 0, bool replicated = true) public RagonEntity(ushort type = 0, ushort sceneId = 0, bool replicated = true)
{ {
@@ -125,7 +125,14 @@ namespace Ragon.Client
return payload; return payload;
} }
public void Prepare(RagonClient client, ushort entityId, ushort entityType, bool hasAuthority, RagonPlayer player, RagonPayload payload) public void Prepare(
RagonClient client,
ushort entityId,
ushort entityType,
bool hasAuthority,
RagonPlayer player,
RagonPayload payload
)
{ {
Type = entityType; Type = entityType;
Id = entityId; Id = entityId;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -39,8 +39,6 @@ public struct RoomParameters
internal class JoinSuccessHandler : IHandler internal class JoinSuccessHandler : IHandler
{ {
private readonly RagonListenerList _listenerList; private readonly RagonListenerList _listenerList;
private readonly RagonPlayerCache _playerCache; private readonly RagonPlayerCache _playerCache;
private readonly RagonEntityCache _entityCache; private readonly RagonEntityCache _entityCache;
@@ -62,19 +60,39 @@ internal class JoinSuccessHandler : IHandler
public void Handle(RagonBuffer reader) public void Handle(RagonBuffer reader)
{ {
var roomId = reader.ReadString(); var roomId = reader.ReadString();
var localId = reader.ReadString();
var ownerId = reader.ReadString();
var min = reader.ReadUShort(); var min = reader.ReadUShort();
var max = reader.ReadUShort(); var max = reader.ReadUShort();
var sceneName = reader.ReadString(); var sceneName = reader.ReadString();
var localId = reader.ReadString();
var ownerId = reader.ReadString();
_playerCache.SetOwnerAndLocal(ownerId, localId);
var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName); var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max); var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene); var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
_playerCache.SetOwnerAndLocal(ownerId, localId); room.UserData.Read(reader);
_client.AssignRoom(room);
var playersCount = reader.ReadUShort();
RagonLog.Trace("Players: " + playersCount);
for (var i = 0; i < playersCount; i++)
{
var playerPeerId = reader.ReadUShort();
var playerId = reader.ReadString();
var playerName = reader.ReadString();
var player = _playerCache.AddPlayer(playerPeerId, playerId, playerName);
player.UserData.Read(reader);
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
}
_client.AssignRoom(room);
_client.SetStatus(RagonStatus.ROOM);
_listenerList.OnJoined();
_listenerList.OnSceneRequest(sceneName); _listenerList.OnSceneRequest(sceneName);
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -39,9 +39,9 @@ namespace Ragon.Client
if (player != null) if (player != null)
{ {
player.UserData.Read(reader); var changes = player.UserData.Read(reader);
_listenerList.OnPlayerUserData(player); _listenerList.OnPlayerUserData(player, changes);
return; return;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -36,8 +36,11 @@ internal class RoomDataHandler: IHandler
{ {
var rawData = reader.RawData; var rawData = reader.RawData;
var peerId = (ushort)(rawData[1] + (rawData[2] << 8)); var peerId = (ushort)(rawData[1] + (rawData[2] << 8));
var player = _playerCache.GetPlayerByPeer(peerId);
RagonPlayer player = null;
if (peerId != 10000)
{
player = _playerCache.GetPlayerByPeer(peerId);
if (player == null) if (player == null)
{ {
RagonLog.Error($"Player with peerId:{peerId} not found"); RagonLog.Error($"Player with peerId:{peerId} not found");
@@ -45,6 +48,7 @@ internal class RoomDataHandler: IHandler
_playerCache.Dump(); _playerCache.Dump();
return; return;
} }
}
var headerSize = 3; var headerSize = 3;
var payload = new byte[rawData.Length - headerSize]; var payload = new byte[rawData.Length - headerSize];
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -31,8 +31,8 @@ namespace Ragon.Client
public void Handle(RagonBuffer reader) public void Handle(RagonBuffer reader)
{ {
_client.Room?.HandleUserData(reader); var changes = _client.Room?.UserData.Read(reader);
_listenerList.OnRoomUserData(); _listenerList.OnRoomUserData(changes);
} }
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -46,19 +46,6 @@ internal class SnapshotHandler : IHandler
public void Handle(RagonBuffer buffer) public void Handle(RagonBuffer buffer)
{ {
var entities = new List<RagonEntity>(); var entities = new List<RagonEntity>();
var playersCount = buffer.ReadUShort();
RagonLog.Trace("Players: " + playersCount);
for (var i = 0; i < playersCount; i++)
{
var playerPeerId = buffer.ReadUShort();
var playerId = buffer.ReadString();
var playerName = buffer.ReadString();
_playerCache.AddPlayer(playerPeerId, playerId, playerName);
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
}
var dynamicEntities = buffer.ReadUShort(); var dynamicEntities = buffer.ReadUShort();
RagonLog.Trace("Dynamic Entities: " + dynamicEntities); RagonLog.Trace("Dynamic Entities: " + dynamicEntities);
for (var i = 0; i < dynamicEntities; i++) for (var i = 0; i < dynamicEntities; i++)
@@ -123,12 +110,6 @@ internal class SnapshotHandler : IHandler
entities.Add(entity); entities.Add(entity);
} }
if (_client.Status == RagonStatus.LOBBY)
{
_client.SetStatus(RagonStatus.ROOM);
_listenerList.OnJoined();
}
foreach (var entity in entities) foreach (var entity in entities)
entity.Attach(); entity.Attach();
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -22,6 +22,6 @@ public interface IUserData
{ {
public byte[] this[string key] { get; set; } public byte[] this[string key] { get; set; }
bool Dirty { get; } bool Dirty { get; }
void Read(RagonBuffer buffer); IReadOnlyList<string> Read(RagonBuffer buffer);
void Write(RagonBuffer buffer); void Write(RagonBuffer buffer);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -18,5 +18,5 @@ namespace Ragon.Client;
public interface IRagonDataListener public interface IRagonDataListener
{ {
public void OnData(RagonPlayer player, byte[] data); public void OnData(RagonClient client, RagonPlayer player, byte[] data);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -18,5 +18,5 @@ namespace Ragon.Client;
public interface IRagonPlayerUserDataListener public interface IRagonPlayerUserDataListener
{ {
void OnPlayerUserDataUpdated(RagonClient client, RagonPlayer player); void OnPlayerUserDataUpdated(RagonClient client, RagonPlayer player, IReadOnlyList<string> changes);
} }
@@ -2,5 +2,5 @@ namespace Ragon.Client;
public interface IRagonRoomListListener public interface IRagonRoomListListener
{ {
public void OnRoomListUpdate(IReadOnlyList<RagonRoomInformation> roomsInfos); public void OnRoomListUpdate(RagonClient client, IReadOnlyList<RagonRoomInformation> roomsInfos);
} }
@@ -2,5 +2,5 @@ namespace Ragon.Client;
public interface IRagonRoomUserDataListener public interface IRagonRoomUserDataListener
{ {
public void OnUserDataUpdated(RagonClient client); public void OnUserDataUpdated(RagonClient client, IReadOnlyList<string> changes);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+6 -6
View File
@@ -298,25 +298,25 @@ namespace Ragon.Client
public void OnData(RagonPlayer player, byte[] data) public void OnData(RagonPlayer player, byte[] data)
{ {
foreach (var listener in _dataListeners) foreach (var listener in _dataListeners)
listener.OnData(player, data); listener.OnData(_client, player, data);
} }
public void OnRoomList(RagonRoomInformation[] roomInfos) public void OnRoomList(RagonRoomInformation[] roomInfos)
{ {
foreach (var listListener in _roomListListeners) foreach (var listListener in _roomListListeners)
listListener.OnRoomListUpdate(roomInfos); listListener.OnRoomListUpdate(_client, roomInfos);
} }
public void OnRoomUserData() public void OnRoomUserData(IReadOnlyList<string> changes)
{ {
foreach (var userDataListener in _roomUserDataListeners) foreach (var userDataListener in _roomUserDataListeners)
userDataListener.OnUserDataUpdated(_client); userDataListener.OnUserDataUpdated(_client, changes);
} }
public void OnPlayerUserData(RagonPlayer player) public void OnPlayerUserData(RagonPlayer player, IReadOnlyList<string> changes)
{ {
foreach(var playerUserDataListener in _playerUserDataListeners) foreach(var playerUserDataListener in _playerUserDataListeners)
playerUserDataListener.OnPlayerUserDataUpdated(_client, player); playerUserDataListener.OnPlayerUserDataUpdated(_client, player, changes);
} }
} }
} }
+4 -2
View File
@@ -52,10 +52,10 @@ public sealed class RagonPlayerCache
_localId = localId; _localId = localId;
} }
public void AddPlayer(ushort peerId, string playerId, string playerName) public RagonPlayer AddPlayer(ushort peerId, string playerId, string playerName)
{ {
if (_playersById.ContainsKey(playerId)) if (_playersById.ContainsKey(playerId))
return; return null;
var isOwner = playerId == _ownerId; var isOwner = playerId == _ownerId;
var isLocal = playerId == _localId; var isLocal = playerId == _localId;
@@ -73,6 +73,8 @@ public sealed class RagonPlayerCache
_players.Add(player); _players.Add(player);
_playersById.Add(player.Id, player); _playersById.Add(player.Id, player);
_playersByConnection.Add(player.PeerId, player); _playersByConnection.Add(player.PeerId, player);
return player;
} }
public void RemovePlayer(string playerId) public void RemovePlayer(string playerId)
+1 -1
View File
@@ -104,7 +104,7 @@ namespace Ragon.Client
if (_events.TryGetValue(eventCode, out var evnt)) if (_events.TryGetValue(eventCode, out var evnt))
evnt?.Invoke(caller, buffer); evnt?.Invoke(caller, buffer);
else else
RagonLog.Warn($"Handler event on entity {Id} with eventCode {eventCode} not defined"); RagonLog.Warn($"Handler event {Id} with eventCode {eventCode} not defined");
} }
internal void HandleUserData(RagonBuffer buffer) internal void HandleUserData(RagonBuffer buffer)
+3 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -80,6 +80,8 @@ public class RagonScene
buffer.WriteByte((byte)replicationMode); buffer.WriteByte((byte)replicationMode);
buffer.WriteByte((byte)target); buffer.WriteByte((byte)target);
evnt.Serialize(buffer);
var sendData = buffer.ToArray(); var sendData = buffer.ToArray();
_client.Reliable.Send(sendData); _client.Reliable.Send(sendData);
} }
+6 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -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);
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+47 -13
View File
@@ -27,44 +27,78 @@ namespace Ragon.Client
{ {
_properties[key] = value; _properties[key] = value;
_dirty = true; if (!_changesCache.ContainsKey(key))
{
_localChanges.Add(key);
_changesCache.Add(key, true);
}
} }
} }
public bool Dirty => _dirty;
private bool _dirty = false; public void Remove(string key)
{
if (_properties.Remove(key))
{
if (!_changesCache.ContainsKey(key))
{
_localChanges.Add(key);
_changesCache.Add(key, true);
}
}
}
public bool Dirty => _localChanges.Count > 0;
private readonly List<string> _localChanges = new();
private readonly Dictionary<string, bool> _changesCache = new();
private readonly Dictionary<string, byte[]> _properties = new(); private readonly Dictionary<string, byte[]> _properties = new();
public RagonUserData() public RagonUserData()
{ {
} }
public void Read(RagonBuffer buffer) public IReadOnlyList<string> Read(RagonBuffer buffer)
{ {
_properties.Clear();
var len = buffer.ReadUShort(); var len = buffer.ReadUShort();
var changes = new List<string>(len);
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 (valueSize > 0)
{
var value = buffer.ReadBytes(valueSize); var value = buffer.ReadBytes(valueSize);
_properties[key] = value; _properties[key] = value;
} }
else
{
_properties.Remove(key);
}
changes.Add(key);
}
return changes;
} }
public void Write(RagonBuffer buffer) public void Write(RagonBuffer buffer)
{ {
buffer.WriteUShort((ushort)_properties.Count); buffer.WriteUShort((ushort)_localChanges.Count);
foreach (var property in _properties) foreach (var propertyChanged in _localChanges)
{ {
buffer.WriteString(property.Key); buffer.WriteString(propertyChanged);
buffer.WriteUShort((ushort) property.Value.Length); if (_properties.TryGetValue(propertyChanged, out var property))
buffer.WriteBytes(property.Value); {
buffer.WriteUShort((ushort)property.Length);
buffer.WriteBytes(property);
}
else
{
buffer.WriteUShort(0);
}
} }
_dirty = false; _localChanges.Clear();
} }
} }
} }
+16 -14
View File
@@ -37,29 +37,31 @@ public class RagonUserDataReadOnly : IUserData
public void Write(RagonBuffer buffer) public void Write(RagonBuffer buffer)
{ {
buffer.WriteUShort((ushort)_properties.Count);
foreach (var property in _properties)
{
buffer.WriteString(property.Key);
buffer.WriteUShort((ushort)property.Value.Length);
buffer.WriteBytes(property.Value);
} }
_dirty = false; public IReadOnlyList<string> Read(RagonBuffer buffer)
}
public void Read(RagonBuffer buffer)
{ {
_properties.Clear();
var len = buffer.ReadUShort(); var len = buffer.ReadUShort();
var changes = new List<string>(len);
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 (valueSize > 0)
{
var value = buffer.ReadBytes(valueSize); var value = buffer.ReadBytes(valueSize);
_properties[key] = value; _properties[key] = value;
}
}
else
{
_properties.Remove(key);
}
changes.Add(key);
}
return changes;
} }
} }
+3 -1
View File
@@ -8,7 +8,9 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Ragon.Protocol</Title> <Title>Ragon.Protocol</Title>
<Copyright>Eduard Kargin</Copyright> <Copyright>Eduard Kargin</Copyright>
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl> <Version>1.4.0</Version>
<Authors>Eduard Kargin</Authors>
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl> <RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType> <RepositoryType>Source</RepositoryType>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+19 -1
View File
@@ -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 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -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; }
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+2 -2
View File
@@ -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
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
+6 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Ragon.Relay</RootNamespace> <RootNamespace>Ragon.Relay</RootNamespace>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
@@ -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>
+40
View File
@@ -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,32 @@
using System;
using Newtonsoft.Json;
using Ragon.Server;
using Ragon.Server.Plugin;
namespace Ragon.Relay
{
public class RelayServerPlugin : BaseServerPlugin
{
public override bool OnCommand(string command, string payload)
{
Console.WriteLine(command);
if (command == "kick-player")
{
var commandPayload = JsonConvert.DeserializeObject<KickPlayerCommand>(payload);
var player = Server.GetContextById(commandPayload.Id);
if (player != null)
player.Connection.Close();
else
Console.WriteLine($"Player not found with Id {commandPayload.Id}");
}
return true;
}
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
{
return new RelayRoomPlugin();
}
}
}
+39 -9
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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,27 +14,35 @@
* 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();
IServerPlugin plugin = new RelayServerPlugin(); IServerPlugin plugin = new RelayServerPlugin();
switch (serverType) switch (serverType)
{ {
case ServerType.ENET: case ServerType.ENET:
@@ -45,8 +53,30 @@ public class Relay
break; break;
} }
var relay = new RagonServer(networkServer, plugin, configuration); var serverConfiguration = new RagonServerConfiguration()
logger.Info("Started"); {
LimitConnections = configuration.LimitConnections,
LimitRooms = configuration.LimitRooms,
LimitBufferedEvents = configuration.LimitBufferedEvents,
LimitPlayersPerRoom = configuration.LimitPlayersPerRoom,
LimitUserDataSize = configuration.LimitUserDataSize,
LimitPropertySize = configuration.LimitPropertySize,
Port = configuration.Port,
Protocol = configuration.Protocol,
ServerKey = configuration.ServerKey,
ServerTickRate = configuration.ServerTickRate,
ServerAddress = configuration.ServerAddress,
};
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
relay.Start(); relay.Start();
while (relay.IsRunning)
{
relay.Tick();
Thread.Sleep(1);
}
relay.Dispose();
}
} }
} }
+21
View File
@@ -0,0 +1,21 @@
using System;
namespace Ragon.Relay
{
[Serializable]
public struct RelayConfiguration
{
public string ServerKey;
public string ServerType;
public string ServerAddress;
public ushort ServerTickRate;
public string Protocol;
public ushort Port;
public int LimitConnections;
public int LimitPlayersPerRoom;
public int LimitRooms;
public int LimitBufferedEvents;
public int LimitUserDataSize;
public int LimitPropertySize;
}
}
-30
View File
@@ -1,30 +0,0 @@
using System;
using Newtonsoft.Json;
using Ragon.Server;
using Ragon.Server.Plugin;
namespace Ragon.Relay;
public class RelayServerPlugin: BaseServerPlugin
{
public override bool OnCommand(string command, string payload)
{
Console.WriteLine(command);
if (command == "kick-player")
{
var commandPayload = JsonConvert.DeserializeObject<KickPlayerCommand>(payload);
var player = Server.GetPlayerById(commandPayload.Id);
if (player != null)
player.Connection.Close();
else
Console.WriteLine($"Player not found with Id {commandPayload.Id}");
}
return true;
}
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
{
return new RelayRoomPlugin();
}
}
+6 -12
View File
@@ -1,21 +1,15 @@
{ {
"serverKey": "defaultkey", "serverKey": "defaultkey",
"serverType": "enet", "serverType": "enet",
"serverAddress": "*",
"serverTickRate": 30, "serverTickRate": 30,
"gameProtocol": "1.0.0", "protocol": "1.0.0",
"port": 5000, "port": 8000,
"httpPort": 5001,
"httpKey": "defaultkey",
"limitConnections": 4095, "limitConnections": 4095,
"limitPlayersPerRoom": 20, "limitPlayersPerRoom": 20,
"limitRooms": 200, "limitRooms": 200,
"limitBufferedEvents": 50, "limitBufferedEvents": 50,
"limitUserData": 1024, "limitUserDataSize": 1024,
"webHooks": "limitPropertySize": 512,
{ "limitConnectionsPerProject": 100
"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"
}
} }
@@ -4,12 +4,21 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Ragon.ENet</RootNamespace> <RootNamespace>Ragon.ENet</RootNamespace>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Eduard Kargin</Copyright>
<Authors>Eduard Kargin</Authors>
<Version>1.4.0</Version>
<Title>Ragon Server ENet</Title>
<Description>Ragon Server ENet transport</Description>
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<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>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -21,6 +21,7 @@ namespace Ragon.Server.ENetServer;
public sealed class ENetConnection: INetworkConnection public sealed class ENetConnection: INetworkConnection
{ {
private static ushort _iterator = 0;
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; }
@@ -30,7 +31,8 @@ public sealed class ENetConnection: INetworkConnection
{ {
_peer = peer; _peer = peer;
Id = (ushort) peer.ID; // Id = (ushort) peer.ID;
Id = _iterator++;
Reliable = new ENetReliableChannel(peer, NetworkChannel.RELIABLE); Reliable = new ENetReliableChannel(peer, NetworkChannel.RELIABLE);
Unreliable = new ENetUnreliableChannel(peer, NetworkChannel.UNRELIABLE); Unreliable = new ENetUnreliableChannel(peer, NetworkChannel.UNRELIABLE);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -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();
@@ -51,7 +49,7 @@ namespace Ragon.Server.ENetServer
_host.Create(address, _connections.Length, 2, 0, 0, 1024 * 1024); _host.Create(address, _connections.Length, 2, 0, 0, 1024 * 1024);
var protocolDecoded = RagonVersion.Parse(_protocol); var protocolDecoded = RagonVersion.Parse(_protocol);
_logger.Info($"Listen at 127.0.0.1:{configuration.Port}"); _logger.Info($"Listen at {configuration.Address}:{configuration.Port}");
_logger.Info($"Protocol: {protocolDecoded}"); _logger.Info($"Protocol: {protocolDecoded}");
} }
@@ -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;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -4,13 +4,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Ragon.WebSockets</RootNamespace> <RootNamespace>Ragon.WebSockets</RootNamespace>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <Copyright>Eduard Kargin</Copyright>
<Authors>Eduard Kargin</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.4.0</Version>
<Title>Ragon Server WebSocket</Title>
<Description>Ragon Server WebSocket transport</Description>
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType>
<TargetFramework>net9.0</TargetFramework>
</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>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com> * Copyright 2023-2024 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.

Some files were not shown because too many files have changed in this diff Show More