Compare commits

...

13 Commits

171 changed files with 1349 additions and 2170 deletions
+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");
* 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");
* 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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<RootNamespace>Ragon.Client.Simulation</RootNamespace>
<Authors>Eduard Kargin (Edmand46)</Authors>
<Authors>Eduard Kargin</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
</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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
@@ -71,15 +71,15 @@ namespace Ragon.Client
internal bool PropertiesChanged => _propertiesChanged;
internal ushort SceneId => _sceneId;
private ushort _sceneId;
private readonly ushort _sceneId;
private bool _propertiesChanged;
private RagonPayload _spawnPayload;
private RagonPayload _destroyPayload;
private readonly Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>();
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
private readonly Dictionary<int, OnEventDelegate> _events = new();
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new();
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new();
public RagonEntity(ushort type = 0, ushort sceneId = 0, bool replicated = true)
{
@@ -125,7 +125,14 @@ namespace Ragon.Client
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;
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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
@@ -39,8 +39,6 @@ public struct RoomParameters
internal class JoinSuccessHandler : IHandler
{
private readonly RagonListenerList _listenerList;
private readonly RagonPlayerCache _playerCache;
private readonly RagonEntityCache _entityCache;
@@ -62,19 +60,39 @@ internal class JoinSuccessHandler : IHandler
public void Handle(RagonBuffer reader)
{
var roomId = reader.ReadString();
var localId = reader.ReadString();
var ownerId = reader.ReadString();
var min = reader.ReadUShort();
var max = reader.ReadUShort();
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 roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
_playerCache.SetOwnerAndLocal(ownerId, localId);
_client.AssignRoom(room);
room.UserData.Read(reader);
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);
}
}
@@ -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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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 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)
{
RagonLog.Error($"Player with peerId:{peerId} not found");
@@ -45,6 +48,7 @@ internal class RoomDataHandler: IHandler
_playerCache.Dump();
return;
}
}
var headerSize = 3;
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");
* 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");
* 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)
{
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();
RagonLog.Trace("Dynamic Entities: " + dynamicEntities);
for (var i = 0; i < dynamicEntities; i++)
@@ -123,12 +110,6 @@ internal class SnapshotHandler : IHandler
entities.Add(entity);
}
if (_client.Status == RagonStatus.LOBBY)
{
_client.SetStatus(RagonStatus.ROOM);
_listenerList.OnJoined();
}
foreach (var entity in entities)
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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
@@ -18,5 +18,5 @@ namespace Ragon.Client;
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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
@@ -2,5 +2,5 @@ namespace Ragon.Client;
public interface IRagonRoomListListener
{
public void OnRoomListUpdate(IReadOnlyList<RagonRoomInformation> roomsInfos);
public void OnRoomListUpdate(RagonClient client, IReadOnlyList<RagonRoomInformation> roomsInfos);
}
@@ -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");
* 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");
* 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");
* 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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
+2 -2
View File
@@ -298,13 +298,13 @@ namespace Ragon.Client
public void OnData(RagonPlayer player, byte[] data)
{
foreach (var listener in _dataListeners)
listener.OnData(player, data);
listener.OnData(_client, player, data);
}
public void OnRoomList(RagonRoomInformation[] roomInfos)
{
foreach (var listListener in _roomListListeners)
listListener.OnRoomListUpdate(roomInfos);
listListener.OnRoomListUpdate(_client, roomInfos);
}
public void OnRoomUserData(IReadOnlyList<string> changes)
+4 -2
View File
@@ -52,10 +52,10 @@ public sealed class RagonPlayerCache
_localId = localId;
}
public void AddPlayer(ushort peerId, string playerId, string playerName)
public RagonPlayer AddPlayer(ushort peerId, string playerId, string playerName)
{
if (_playersById.ContainsKey(playerId))
return;
return null;
var isOwner = playerId == _ownerId;
var isLocal = playerId == _localId;
@@ -73,6 +73,8 @@ public sealed class RagonPlayerCache
_players.Add(player);
_playersById.Add(player.Id, player);
_playersByConnection.Add(player.PeerId, player);
return player;
}
public void RemovePlayer(string playerId)
+1 -1
View File
@@ -104,7 +104,7 @@ namespace Ragon.Client
if (_events.TryGetValue(eventCode, out var evnt))
evnt?.Invoke(caller, buffer);
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)
+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");
* 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)target);
evnt.Serialize(buffer);
var sendData = buffer.ToArray();
_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");
* 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)
{
var parameters = new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
CreateOrJoin(parameters);
}
public void CreateOrJoin(RagonRoomPayload parameters)
public void CreateOrJoin(RagonRoomParameters parameters)
{
_buffer.Clear();
_buffer.WriteOperation(RagonOperation.JOIN_OR_CREATE_ROOM);
@@ -48,15 +48,15 @@ namespace Ragon.Client
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)
{
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.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");
* you may not use this file except in compliance with the License.
-2
View File
@@ -55,7 +55,6 @@ namespace Ragon.Client
public RagonUserData()
{
}
public IReadOnlyList<string> Read(RagonBuffer buffer)
@@ -70,7 +69,6 @@ namespace Ragon.Client
{
var value = buffer.ReadBytes(valueSize);
_properties[key] = value;
}
else
{
+3 -1
View File
@@ -8,7 +8,9 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Ragon.Protocol</Title>
<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>
<RepositoryType>Source</RepositoryType>
<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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
namespace Ragon.Protocol
{
public class RagonRoomPayload: IRagonSerializable
public class RagonRoomParameters: IRagonSerializable
{
public string Scene { 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");
* 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");
* 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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
+5
View File
@@ -28,4 +28,9 @@
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.3.2" />
</ItemGroup>
</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();
}
}
}
+37 -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");
* you may not use this file except in compliance with the License.
@@ -14,27 +14,35 @@
* limitations under the License.
*/
using NLog;
using System;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
using Ragon.Server;
using Ragon.Server.ENetServer;
using Ragon.Server.WebSocketServer;
using Ragon.Server.IO;
using Ragon.Server.Logging;
using Ragon.Server.Plugin;
using Ragon.Server.WebSocketServer;
namespace Ragon.Relay;
namespace Ragon.Relay
{
public class Relay
{
public void Start()
{
var logger = LogManager.GetLogger("Ragon.Relay");
LoggerManager.SetLoggerFactory(new RelayLoggerFactory());
var logger = LoggerManager.GetLogger("Relay");
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);
INetworkServer networkServer = new ENetServer();
IServerPlugin plugin = new RelayServerPlugin();
switch (serverType)
{
case ServerType.ENET:
@@ -45,8 +53,28 @@ public class Relay
break;
}
var relay = new RagonServer(networkServer, plugin, configuration);
logger.Info("Started");
var serverConfiguration = new RagonServerConfiguration()
{
LimitConnections = configuration.LimitConnections,
LimitRooms = configuration.LimitConnections,
LimitBufferedEvents = configuration.LimitConnections,
LimitPlayersPerRoom = configuration.LimitConnections,
Port = configuration.Port,
Protocol = configuration.Protocol,
ServerKey = configuration.ServerKey,
ServerTickRate = configuration.ServerTickRate,
ServerAddress = configuration.ServerAddress,
};
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
relay.Start();
while (relay.IsRunning)
{
relay.Tick();
Thread.Sleep(1);
}
relay.Dispose();
}
}
}
+20
View File
@@ -0,0 +1,20 @@
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 LimitUserData;
}
}
-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();
}
}
+3 -11
View File
@@ -1,21 +1,13 @@
{
"serverKey": "defaultkey",
"serverType": "enet",
"serverAddress": "*",
"serverTickRate": 30,
"gameProtocol": "1.0.0",
"protocol": "1.0.0",
"port": 5000,
"httpPort": 5001,
"httpKey": "defaultkey",
"limitConnections": 4095,
"limitPlayersPerRoom": 20,
"limitRooms": 200,
"limitBufferedEvents": 50,
"limitUserData": 1024,
"webHooks":
{
"room-created": "http://127.0.0.1:3000/service/create-room",
"room-removed": "http://127.0.0.1:3000/service/remove-room",
"room-joined": "http://127.0.0.1:3000/service/join-room",
"room-leaved": "http://127.0.0.1:3000/service/leave-room"
}
"limitUserData": 1024
}
@@ -4,12 +4,21 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Ragon.ENet</RootNamespace>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.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>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
<PackageReference Include="NLog" Version="5.2.2" />
</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");
* 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
{
private static ushort _iterator = 0;
public ushort Id { get; }
public INetworkChannel Reliable { get; private set; }
public INetworkChannel Unreliable { get; private set; }
@@ -30,7 +31,8 @@ public sealed class ENetConnection: INetworkConnection
{
_peer = peer;
Id = (ushort) peer.ID;
// Id = (ushort) peer.ID;
Id = _iterator++;
Reliable = new ENetReliableChannel(peer, NetworkChannel.RELIABLE);
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");
* 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");
* you may not use this file except in compliance with the License.
@@ -15,26 +15,24 @@
*/
using ENet;
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
using Ragon.Server.Logging;
namespace Ragon.Server.ENetServer
{
public sealed class ENetServer : INetworkServer
{
public Executor Executor => _executor;
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 INetworkListener _listener;
private uint _protocol;
private ENet.Event _event;
private Executor _executor = new();
public void Start(INetworkListener listener, NetworkConfiguration configuration)
public void Listen(INetworkListener listener, NetworkConfiguration configuration)
{
Library.Initialize();
@@ -51,7 +49,7 @@ namespace Ragon.Server.ENetServer
_host.Create(address, _connections.Length, 2, 0, 0, 1024 * 1024);
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}");
}
@@ -79,7 +77,7 @@ namespace Ragon.Server.ENetServer
{
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);
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");
* you may not use this file except in compliance with the License.
@@ -4,13 +4,19 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Ragon.WebSockets</RootNamespace>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.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>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
</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");
* 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");
* 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");
* you may not use this file except in compliance with the License.
@@ -14,15 +14,15 @@
* limitations under the License.
*/
using NLog;
using System.Net.WebSockets;
using Ragon.Server.IO;
using Ragon.Server.Logging;
namespace Ragon.Server.WebSocketServer;
public sealed class WebSocketConnection : INetworkConnection
{
private Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(WebSocketConnection));
public ushort Id { get; }
public INetworkChannel Reliable { get; private set; }
public INetworkChannel Unreliable { get; private set; }
@@ -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");
* 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");
* you may not use this file except in compliance with the License.
@@ -16,17 +16,16 @@
using System.Net;
using System.Net.WebSockets;
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
using Ragon.Server.Logging;
namespace Ragon.Server.WebSocketServer;
public class WebSocketServer : INetworkServer
{
public Executor Executor => _executor;
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(WebSocketServer));
private ILogger _logger = LogManager.GetCurrentClassLogger();
private INetworkListener _networkListener;
private Stack<ushort> _sequencer;
private Executor _executor;
@@ -67,7 +66,7 @@ public class WebSocketServer : INetworkServer
}
catch (Exception ex)
{
_logger.Warn(ex);
_logger.Error(ex);
continue;
}
@@ -113,6 +112,8 @@ public class WebSocketServer : INetworkServer
public void Update()
{
_executor.Update();
Flush();
}
@@ -128,7 +129,7 @@ public class WebSocketServer : INetworkServer
await conn.Flush();
}
public void Start(
public void Listen(
INetworkListener listener,
NetworkConfiguration configuration
)
@@ -145,13 +146,13 @@ public class WebSocketServer : INetworkServer
_connections = new WebSocketConnection[configuration.LimitConnections];
_httpListener = new HttpListener();
_httpListener.Prefixes.Add($"http://+:{configuration.Port}/");
_httpListener.Prefixes.Add($"http://{configuration.Address}:{configuration.Port}/");
_httpListener.Start();
_executor.Run(() => StartAccept(_cancellationTokenSource.Token));
var protocolDecoded = RagonVersion.Parse(configuration.Protocol);
_logger.Info($"Listen at http://0.0.0.0:{configuration.Port}/");
_logger.Info($"Listen at http://{configuration.Address}:{configuration.Port}/");
_logger.Info($"Protocol: {protocolDecoded}");
}
+5 -9
View File
@@ -5,22 +5,18 @@
<Nullable>enable</Nullable>
<RootNamespace>Ragon.Core</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.3.1</Version>
<Version>1.4.0</Version>
<Title>Ragon.Server</Title>
<Copyright>Eduard Kargin</Copyright>
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
<Authors>Eduard Kargin</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<LangVersion>10</LangVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ragon.Protocol\Ragon.Protocol.csproj" />
</ItemGroup>
+52 -9
View File
@@ -4,20 +4,63 @@ namespace Ragon.Server.Data;
public class RagonData
{
private byte[] _data;
public bool IsDirty { get; set; }
public byte[] Data
private readonly Dictionary<string, byte[]> _data = new Dictionary<string, byte[]>();
public bool IsDirty { get; private set; }
public RagonData()
{
get => _data;
set
}
public void Read(RagonBuffer buffer)
{
_data = value;
IsDirty = true;
var len = buffer.ReadUShort();
for (int i = 0; i < len; i++)
{
var key = buffer.ReadString();
var valueSize = buffer.ReadUShort();
if (valueSize > 0)
{
var value = buffer.ReadBytes(valueSize);
_data[key] = value;
}
else
{
_data[key] = Array.Empty<byte>();
}
}
}
public RagonData(byte[] data)
public void Write(RagonBuffer buffer)
{
_data = data;
buffer.WriteUShort((ushort)_data.Count);
foreach (var prop in _data)
{
buffer.WriteString(prop.Key);
buffer.WriteUShort((ushort)prop.Value.Length);
buffer.WriteBytes(prop.Value);
}
var toDelete = _data
.Where(p => p.Value.Length == 0)
.Select(p => p.Key);
foreach (var prop in toDelete)
_data.Remove(prop);
IsDirty = false;
}
public void Snapshot(RagonBuffer buffer)
{
buffer.WriteUShort((ushort)_data.Count);
foreach (var prop in _data)
{
buffer.WriteString(prop.Key);
buffer.WriteUShort((ushort)prop.Value.Length);
buffer.WriteBytes(prop.Value);
Console.WriteLine($"Key: {prop.Key} Value: {prop.Value.Length}");
}
}
}
+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");
* 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");
* 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");
* 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