♻️ added checks in client sdk
This commit is contained in:
@@ -4,3 +4,5 @@
|
|||||||
obj
|
obj
|
||||||
bin
|
bin
|
||||||
*.user
|
*.user
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
@@ -105,6 +105,12 @@ namespace Ragon.Client
|
|||||||
public void ReplicateEvent<TEvent>(TEvent evnt, RagonPlayer target, RagonReplicationMode replicationMode)
|
public void ReplicateEvent<TEvent>(TEvent evnt, RagonPlayer target, RagonReplicationMode replicationMode)
|
||||||
where TEvent : IRagonEvent, new()
|
where TEvent : IRagonEvent, new()
|
||||||
{
|
{
|
||||||
|
if (!IsAttached)
|
||||||
|
{
|
||||||
|
RagonLog.Error("Entity not attached");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var evntId = _client.Event.GetEventCode(evnt);
|
var evntId = _client.Event.GetEventCode(evnt);
|
||||||
var buffer = _client.Buffer;
|
var buffer = _client.Buffer;
|
||||||
|
|
||||||
@@ -114,7 +120,7 @@ namespace Ragon.Client
|
|||||||
buffer.WriteUShort(evntId);
|
buffer.WriteUShort(evntId);
|
||||||
buffer.WriteByte((byte) replicationMode);
|
buffer.WriteByte((byte) replicationMode);
|
||||||
buffer.WriteByte((byte) RagonTarget.Player);
|
buffer.WriteByte((byte) RagonTarget.Player);
|
||||||
buffer.WriteUShort((ushort) target.PeerId);
|
buffer.WriteUShort(target.PeerId);
|
||||||
|
|
||||||
evnt.Serialize(buffer);
|
evnt.Serialize(buffer);
|
||||||
|
|
||||||
@@ -128,6 +134,12 @@ namespace Ragon.Client
|
|||||||
RagonReplicationMode replicationMode = RagonReplicationMode.Server)
|
RagonReplicationMode replicationMode = RagonReplicationMode.Server)
|
||||||
where TEvent : IRagonEvent, new()
|
where TEvent : IRagonEvent, new()
|
||||||
{
|
{
|
||||||
|
if (!IsAttached)
|
||||||
|
{
|
||||||
|
RagonLog.Error("Entity not attached");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (target != RagonTarget.ExceptOwner)
|
if (target != RagonTarget.ExceptOwner)
|
||||||
{
|
{
|
||||||
if (replicationMode == RagonReplicationMode.Local)
|
if (replicationMode == RagonReplicationMode.Local)
|
||||||
@@ -196,8 +208,10 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
internal void Event(ushort eventCode, RagonPlayer caller, RagonBuffer buffer)
|
internal void Event(ushort eventCode, RagonPlayer caller, RagonBuffer buffer)
|
||||||
{
|
{
|
||||||
if (_events.ContainsKey(eventCode))
|
if (_events.TryGetValue(eventCode, out var evnt))
|
||||||
_events[eventCode]?.Invoke(caller, buffer);
|
evnt?.Invoke(caller, buffer);
|
||||||
|
else
|
||||||
|
RagonLog.Warn($"Handler event on entity {Id} with eventCode {eventCode} not defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void TrackChangedProperty(RagonProperty property)
|
internal void TrackChangedProperty(RagonProperty property)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ internal class EntityEventHandler : Handler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.IsMe && executionMode == RagonReplicationMode.LocalAndServer)
|
if (player.IsLocal && executionMode == RagonReplicationMode.LocalAndServer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_entityCache.OnEvent(player, entityId, eventCode, buffer);
|
_entityCache.OnEvent(player, entityId, eventCode, buffer);
|
||||||
|
|||||||
@@ -26,8 +26,12 @@ public class RagonEventCache
|
|||||||
public ushort GetEventCode<TEvent>(TEvent _) where TEvent : IRagonEvent
|
public ushort GetEventCode<TEvent>(TEvent _) where TEvent : IRagonEvent
|
||||||
{
|
{
|
||||||
var type = typeof(TEvent);
|
var type = typeof(TEvent);
|
||||||
var evntCode = _eventsRegistryByType[type];
|
if (!_eventsRegistryByType.TryGetValue(type, out var eventCode))
|
||||||
return evntCode;
|
{
|
||||||
|
RagonLog.Error($"Event with type {type} not registered");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return eventCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Register<T>() where T : IRagonEvent, new()
|
public void Register<T>() where T : IRagonEvent, new()
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ namespace Ragon.Client
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public ushort PeerId { get; set; }
|
public ushort PeerId { get; set; }
|
||||||
public bool IsRoomOwner { get; set; }
|
public bool IsRoomOwner { get; set; }
|
||||||
public bool IsMe { get; set; }
|
public bool IsLocal { get; set; }
|
||||||
|
|
||||||
public RagonPlayer(ushort peerId, string playerId, string name, bool isRoomOwner, bool isMe)
|
public RagonPlayer(ushort peerId, string playerId, string name, bool isRoomOwner, bool isLocal)
|
||||||
{
|
{
|
||||||
PeerId = peerId;
|
PeerId = peerId;
|
||||||
IsRoomOwner = isRoomOwner;
|
IsRoomOwner = isRoomOwner;
|
||||||
IsMe = isMe;
|
IsLocal = isLocal;
|
||||||
Name = name;
|
Name = name;
|
||||||
Id = playerId;
|
Id = playerId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public sealed class RagonPlayerCache
|
|||||||
|
|
||||||
var player = new RagonPlayer(peerId, playerId, playerName, isOwner, isLocal);
|
var player = new RagonPlayer(peerId, playerId, playerName, isOwner, isLocal);
|
||||||
|
|
||||||
if (player.IsMe)
|
if (player.IsLocal)
|
||||||
LocalPlayer = player;
|
LocalPlayer = player;
|
||||||
|
|
||||||
if (player.IsRoomOwner)
|
if (player.IsRoomOwner)
|
||||||
|
|||||||
Reference in New Issue
Block a user