Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7dd693147 | |||
| fef1007c8c | |||
| e33c442a18 | |||
| 09b185a3ad | |||
| 7d154ea4d4 | |||
| d2577e5d1f |
@@ -19,8 +19,35 @@ using Ragon.Protocol;
|
|||||||
|
|
||||||
namespace Ragon.Client
|
namespace Ragon.Client
|
||||||
{
|
{
|
||||||
public sealed class RagonEntity: IDisposable
|
public sealed class RagonEntity : IDisposable
|
||||||
{
|
{
|
||||||
|
private class EventSubscription : IDisposable
|
||||||
|
{
|
||||||
|
private List<Action<RagonPlayer, IRagonEvent>> _callbacks;
|
||||||
|
private List<Action<RagonPlayer, IRagonEvent>> _localCallbacks;
|
||||||
|
private Action<RagonPlayer, IRagonEvent> _callback;
|
||||||
|
|
||||||
|
public EventSubscription(
|
||||||
|
List<Action<RagonPlayer, IRagonEvent>> callbacks,
|
||||||
|
List<Action<RagonPlayer, IRagonEvent>> localCallbacks,
|
||||||
|
Action<RagonPlayer, IRagonEvent> callback)
|
||||||
|
{
|
||||||
|
_callbacks = callbacks;
|
||||||
|
_localCallbacks = localCallbacks;
|
||||||
|
_callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_callbacks.Remove(_callback);
|
||||||
|
_localCallbacks.Remove(_callback);
|
||||||
|
|
||||||
|
_callbacks = null!;
|
||||||
|
_localCallbacks = null!;
|
||||||
|
_callback = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer);
|
private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer);
|
||||||
|
|
||||||
private RagonClient _client;
|
private RagonClient _client;
|
||||||
@@ -189,11 +216,10 @@ namespace Ragon.Client
|
|||||||
_client.Reliable.Send(sendData);
|
_client.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action<RagonPlayer, IRagonEvent> OnEvent<TEvent>(Action<RagonPlayer, TEvent> callback) where TEvent : IRagonEvent, new()
|
public IDisposable OnEvent<TEvent>(Action<RagonPlayer, TEvent> callback) where TEvent : IRagonEvent, new()
|
||||||
{
|
{
|
||||||
var t = new TEvent();
|
var t = new TEvent();
|
||||||
var eventCode = _client.Event.GetEventCode(t);
|
var eventCode = _client.Event.GetEventCode(t);
|
||||||
|
|
||||||
var action = (RagonPlayer player, IRagonEvent eventData) => callback.Invoke(player, (TEvent)eventData);
|
var action = (RagonPlayer player, IRagonEvent eventData) => callback.Invoke(player, (TEvent)eventData);
|
||||||
|
|
||||||
if (!_listeners.TryGetValue(eventCode, out var callbacks))
|
if (!_listeners.TryGetValue(eventCode, out var callbacks))
|
||||||
@@ -222,19 +248,7 @@ namespace Ragon.Client
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return action;
|
return new EventSubscription(callbacks, localCallbacks, action);
|
||||||
}
|
|
||||||
|
|
||||||
public void OffEvent<TEvent>(Action<RagonPlayer, IRagonEvent> callback) where TEvent : IRagonEvent, new()
|
|
||||||
{
|
|
||||||
var t = new TEvent();
|
|
||||||
var eventCode = _client.Event.GetEventCode(t);
|
|
||||||
|
|
||||||
if (_listeners.TryGetValue(eventCode, out var callbacks))
|
|
||||||
callbacks.Remove(callback);
|
|
||||||
|
|
||||||
if (_localListeners.TryGetValue(eventCode, out var localCallbacks))
|
|
||||||
localCallbacks.Remove(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Write(RagonBuffer buffer)
|
internal void Write(RagonBuffer buffer)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
<LangVersion>8</LangVersion>
|
<LangVersion>8</LangVersion>
|
||||||
<RootNamespace>Ragon.Common</RootNamespace>
|
<RootNamespace>Ragon.Common</RootNamespace>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Version>1.2.4-rc</Version>
|
|
||||||
<Title>Ragon.Protocol</Title>
|
<Title>Ragon.Protocol</Title>
|
||||||
<Copyright>Eduard Kargin</Copyright>
|
<Copyright>Eduard Kargin</Copyright>
|
||||||
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
var webSocket = connection.Socket;
|
var webSocket = connection.Socket;
|
||||||
var bytes = new byte[2048];
|
var bytes = new byte[2048];
|
||||||
var buffer = new Memory<byte>(bytes);
|
var buffer = new Memory<byte>(bytes);
|
||||||
|
|
||||||
while (
|
while (
|
||||||
webSocket.State == WebSocketState.Open ||
|
webSocket.State == WebSocketState.Open ||
|
||||||
!cancellationToken.IsCancellationRequested)
|
!cancellationToken.IsCancellationRequested)
|
||||||
@@ -84,7 +85,7 @@ public class WebSocketServer : INetworkServer
|
|||||||
var result = await webSocket.ReceiveAsync(buffer, cancellationToken);
|
var result = await webSocket.ReceiveAsync(buffer, cancellationToken);
|
||||||
if (result.Count > 0)
|
if (result.Count > 0)
|
||||||
{
|
{
|
||||||
var payload = buffer.Slice(0, buffer.Length);
|
var payload = buffer.Slice(0, result.Count);
|
||||||
_networkListener.OnData(connection, NetworkChannel.RELIABLE, payload.ToArray());
|
_networkListener.OnData(connection, NetworkChannel.RELIABLE, payload.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<RootNamespace>Ragon.Core</RootNamespace>
|
<RootNamespace>Ragon.Core</RootNamespace>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Version>1.2.4-rc</Version>
|
<Version>1.3.1</Version>
|
||||||
<Title>Ragon.Server</Title>
|
<Title>Ragon.Server</Title>
|
||||||
<Copyright>Eduard Kargin</Copyright>
|
<Copyright>Eduard Kargin</Copyright>
|
||||||
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class RagonEvent
|
|||||||
|
|
||||||
public void Write(RagonBuffer buffer)
|
public void Write(RagonBuffer buffer)
|
||||||
{
|
{
|
||||||
if (_size == 0) return;
|
if (_size <= 0) return;
|
||||||
buffer.WriteArray(_data, _size);
|
buffer.WriteArray(_data, _size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,18 +32,17 @@ public sealed class RoomDataOperation : BaseOperation
|
|||||||
var room = context.Room;
|
var room = context.Room;
|
||||||
|
|
||||||
var data = Reader.RawData;
|
var data = Reader.RawData;
|
||||||
|
var dataSize = data.Length - 1;
|
||||||
Writer.Clear();
|
var headerSize = 3;
|
||||||
Writer.WriteOperation(RagonOperation.REPLICATE_RAW_DATA);
|
var size = headerSize + dataSize;
|
||||||
Writer.WriteUShort(player.Connection.Id);
|
|
||||||
|
|
||||||
var playerData = Writer.ToArray();
|
|
||||||
var payloadData = data;
|
|
||||||
var size = playerData.Length + payloadData.Length;
|
|
||||||
var sendData = new byte[size];
|
var sendData = new byte[size];
|
||||||
|
var peerId = player.Connection.Id;
|
||||||
|
|
||||||
Array.Copy(playerData, 0, sendData, 0, playerData.Length);
|
sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA;
|
||||||
Array.Copy(payloadData, 1, sendData, playerData.Length, payloadData.Length - 1);
|
sendData[1] = (byte)peerId;
|
||||||
|
sendData[2] = (byte)(peerId >> 8);
|
||||||
|
|
||||||
|
Array.Copy(data, 1, sendData, headerSize, dataSize);
|
||||||
|
|
||||||
room.Broadcast(sendData, channel);
|
room.Broadcast(sendData, channel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,6 @@ public enum ServerType
|
|||||||
WEBSOCKET,
|
WEBSOCKET,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WebHook
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct RagonServerConfiguration
|
public struct RagonServerConfiguration
|
||||||
{
|
{
|
||||||
@@ -47,7 +42,7 @@ public struct RagonServerConfiguration
|
|||||||
public Dictionary<string, string> WebHooks;
|
public Dictionary<string, string> WebHooks;
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
private static readonly string ServerVersion = "1.2.9-rc";
|
private static readonly string ServerVersion = "1.3.1";
|
||||||
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
||||||
{
|
{
|
||||||
{"enet", Server.ServerType.ENET},
|
{"enet", Server.ServerType.ENET},
|
||||||
|
|||||||
Reference in New Issue
Block a user