Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cd912a1aa | |||
| c64cc61c78 | |||
| 2dcb047014 | |||
| 33f8bba2ed |
@@ -12,7 +12,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugType>none</DebugType>
|
||||
<OutputPath>/Users/edmand46/RagonProjects/ragon-oss-examples/Assets/Ragon/Runtime/Plugins</OutputPath>
|
||||
<OutputPath>/Users/edmand46/UnityProjects/itd-client/Assets/Ragon/Runtime/Plugins/</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
|
||||
@@ -39,8 +39,8 @@ namespace Ragon.Client
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_callbacks.Remove(_callback);
|
||||
_localCallbacks.Remove(_callback);
|
||||
_callbacks?.Remove(_callback);
|
||||
_localCallbacks?.Remove(_callback);
|
||||
|
||||
_callbacks = null!;
|
||||
_localCallbacks = null!;
|
||||
|
||||
@@ -51,6 +51,8 @@ internal class EntityCreateHandler : IHandler
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Warn($"Owner {ownerId}|{player.Name} not found in players");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ internal class EntityEventHandler : IHandler
|
||||
var player = _playerCache.GetPlayerByPeer(peerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Warn($"Player not found for event {eventCode}");
|
||||
RagonLog.Error($"Player with peerId:{peerId} not found as owner of event with code:{eventCode}");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,14 @@ internal class EntityOwnershipHandler: IHandler
|
||||
var entities = reader.ReadUShort();
|
||||
|
||||
var player = _playerCache.GetPlayerByPeer(newOwnerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Error($"Player with Id:{newOwnerId} not found in cache");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < entities; i++)
|
||||
{
|
||||
var entityId = reader.ReadUShort();
|
||||
|
||||
@@ -19,7 +19,7 @@ using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
internal class OwnershipRoomHandler: IHandler
|
||||
internal class OwnershipRoomHandler : IHandler
|
||||
{
|
||||
private readonly RagonListenerList _listenerList;
|
||||
private readonly RagonPlayerCache _playerCache;
|
||||
@@ -39,6 +39,13 @@ internal class OwnershipRoomHandler: IHandler
|
||||
{
|
||||
var newOwnerId = reader.ReadUShort();
|
||||
var player = _playerCache.GetPlayerByPeer(newOwnerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Warn($"Player with peerId:{newOwnerId} not found in cache");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
_playerCache.OnOwnershipChanged(newOwnerId);
|
||||
_listenerList.OnOwnershipChanged(player);
|
||||
|
||||
@@ -45,6 +45,6 @@ internal class PlayerJoinHandler : IHandler
|
||||
if (player != null)
|
||||
_listenerList.OnPlayerJoined(player);
|
||||
else
|
||||
RagonLog.Trace($"[Joined] {playerId}");
|
||||
RagonLog.Warn($"Player with Id:{playerId} not found in cache");
|
||||
}
|
||||
}
|
||||
@@ -57,5 +57,9 @@ internal class PlayerLeftHandler : IHandler
|
||||
foreach (var id in toDeleteIds)
|
||||
_entityCache.OnDestroy(id, emptyPayload);
|
||||
}
|
||||
else
|
||||
{
|
||||
RagonLog.Warn($"Player with Id:{playerId} not found in cache");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,15 @@ internal class RoomDataHandler: IHandler
|
||||
var rawData = reader.RawData;
|
||||
var peerId = (ushort)(rawData[1] + (rawData[2] << 8));
|
||||
var player = _playerCache.GetPlayerByPeer(peerId);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Error($"Player with peerId:{peerId} not found");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
var headerSize = 3;
|
||||
var payload = new byte[rawData.Length - headerSize];
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public class RoomEventHandler: IHandler
|
||||
public class RoomEventHandler : IHandler
|
||||
{
|
||||
private readonly RagonClient _client;
|
||||
private readonly RagonPlayerCache _playerCache;
|
||||
@@ -41,7 +41,9 @@ public class RoomEventHandler: IHandler
|
||||
var player = _playerCache.GetPlayerByPeer(peerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Warn($"Player not found for event {eventCode}");
|
||||
RagonLog.Error($"Player with peerId:{peerId} not found as owner of event with code:{eventCode}");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ 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++)
|
||||
@@ -70,7 +71,9 @@ internal class SnapshotHandler : IHandler
|
||||
var player = _playerCache.GetPlayerByPeer(ownerPeerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Error($"Player not found with peerId: ${ownerPeerId}");
|
||||
RagonLog.Error($"Player not found with peerId: {ownerPeerId}");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +91,8 @@ internal class SnapshotHandler : IHandler
|
||||
_entityListener.OnEntityCreated(entity);
|
||||
|
||||
entity.Read(buffer);
|
||||
entity.Attach();
|
||||
|
||||
entities.Add(entity);
|
||||
}
|
||||
|
||||
var staticEntities = buffer.ReadUShort();
|
||||
@@ -104,7 +108,9 @@ internal class SnapshotHandler : IHandler
|
||||
var player = _playerCache.GetPlayerByPeer(ownerPeerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Error($"Player not found with peerId: ${ownerPeerId}");
|
||||
RagonLog.Error($"Player not found with peerId: {ownerPeerId}");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,9 +118,9 @@ internal class SnapshotHandler : IHandler
|
||||
var entity = _entityCache.TryGetEntity(0, entityType, staticId, entityId, hasAuthority, out _);
|
||||
|
||||
entity.Prepare(_client, entityId, entityType, hasAuthority, player, RagonPayload.Empty);
|
||||
|
||||
entity.Read(buffer);
|
||||
entity.Attach();
|
||||
|
||||
entities.Add(entity);
|
||||
}
|
||||
|
||||
if (_client.Status == RagonStatus.LOBBY)
|
||||
@@ -123,6 +129,9 @@ internal class SnapshotHandler : IHandler
|
||||
_listenerList.OnJoined();
|
||||
}
|
||||
|
||||
foreach (var entity in entities)
|
||||
entity.Attach();
|
||||
|
||||
_listenerList.OnSceneLoaded();
|
||||
}
|
||||
}
|
||||
@@ -186,12 +186,10 @@ public sealed class RagonEntityCache
|
||||
}
|
||||
}
|
||||
|
||||
if (_pendingEntities.TryGetValue(attachId, out var pendingEntity))
|
||||
if (_pendingEntities.TryGetValue(attachId, out var pendingEntity) && hasAuthority)
|
||||
{
|
||||
_pendingEntities.Remove(attachId);
|
||||
_entityMap.Add(entityId, pendingEntity);
|
||||
|
||||
if (hasAuthority)
|
||||
_entityList.Add(pendingEntity);
|
||||
|
||||
hasCreated = false;
|
||||
@@ -199,7 +197,6 @@ public sealed class RagonEntityCache
|
||||
return pendingEntity;
|
||||
}
|
||||
|
||||
|
||||
var entity = new RagonEntity(entityType, sceneId);
|
||||
|
||||
_entityMap.Add(entityId, entity);
|
||||
@@ -217,7 +214,6 @@ public sealed class RagonEntityCache
|
||||
{
|
||||
if (_entityMap.TryGetValue(entityId, out var entity))
|
||||
{
|
||||
|
||||
_entityMap.Remove(entityId);
|
||||
_entityList.Remove(entity);
|
||||
|
||||
|
||||
@@ -27,8 +27,21 @@ public sealed class RagonPlayerCache
|
||||
public RagonPlayer Local { get; private set; }
|
||||
public bool IsRoomOwner => _ownerId == _localId;
|
||||
|
||||
public RagonPlayer? GetPlayerById(string playerId) => _playersById[playerId];
|
||||
public RagonPlayer? GetPlayerByPeer(ushort peerId) => _playersByConnection[peerId];
|
||||
public RagonPlayer? GetPlayerById(string playerId)
|
||||
{
|
||||
if (_playersById.TryGetValue(playerId, out var player))
|
||||
return player;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RagonPlayer? GetPlayerByPeer(ushort peerId)
|
||||
{
|
||||
if (_playersByConnection.TryGetValue(peerId, out var player))
|
||||
return player;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string _ownerId;
|
||||
private string _localId;
|
||||
@@ -91,4 +104,14 @@ public sealed class RagonPlayerCache
|
||||
_playersByConnection.Clear();
|
||||
_playersById.Clear();
|
||||
}
|
||||
|
||||
public void Dump()
|
||||
{
|
||||
RagonLog.Trace("Players: ");
|
||||
RagonLog.Trace("[Connection] [ID] [Name]");
|
||||
foreach (var player in _players)
|
||||
{
|
||||
RagonLog.Trace($"[{player.PeerId}] {player.Id} {player.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,9 +51,9 @@ namespace Ragon.Client
|
||||
Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||
}
|
||||
|
||||
public void Create(string roomId, string sceneNa, int minPlayers, int maxPlayers)
|
||||
public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers)
|
||||
{
|
||||
Create(roomId, new RagonRoomParameters() {Scene = sceneNa, Min = minPlayers, Max = maxPlayers});
|
||||
Create(roomId, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||
}
|
||||
|
||||
public void Create(string roomId, RagonRoomParameters parameters)
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Ragon.Protocol
|
||||
public int ReadOffset => _read;
|
||||
public int WriteOffset => _write;
|
||||
public int Length => ((_write - 1) >> 3) + 1;
|
||||
public int Capacity => _write - _read;
|
||||
public int Capacity => _write - _read - 1;
|
||||
|
||||
public RagonBuffer(int capacity = 128)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Ragon.Server;
|
||||
using Ragon.Server.Plugin;
|
||||
|
||||
namespace Ragon.Relay;
|
||||
@@ -21,4 +22,9 @@ public class RelayServerPlugin: BaseServerPlugin
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||
{
|
||||
return new RelayRoomPlugin();
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class RagonPayload
|
||||
|
||||
public void Read(RagonBuffer buffer)
|
||||
{
|
||||
_size = buffer.Capacity - 1;
|
||||
_size = buffer.Capacity;
|
||||
buffer.ReadArray(_data, _size);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RagonEvent
|
||||
|
||||
public void Read(RagonBuffer buffer)
|
||||
{
|
||||
_size = buffer.Capacity - 1;
|
||||
_size = buffer.Capacity;
|
||||
buffer.ReadArray(_data, _size);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Ragon.Server.Logging;
|
||||
|
||||
public interface IRagonLogger
|
||||
{
|
||||
public void Warning(string tag, string message);
|
||||
public void Info(string tag, string message);
|
||||
public void Error(string tag, string message);
|
||||
public void Trace(string tag, string message);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class BaseServerPlugin: IServerPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
public IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||
public virtual IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||
{
|
||||
return new BaseRoomPlugin();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user