Compare commits

...

4 Commits

Author SHA1 Message Date
edmand46 b793ca3e68 chore: update default socket typoe 2022-12-25 07:34:22 -08:00
edmand46 3936e5c95b chore: update version 2022-12-25 03:16:59 -08:00
edmand46 e9418f4b22 fixed: websocket server wrong execution thread 2022-12-25 03:13:01 -08:00
edmand46 f34b05e6ff chore: update version libs 2022-12-24 01:47:49 -08:00
15 changed files with 118 additions and 118 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ public struct Configuration
public int LimitRooms; public int LimitRooms;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly string ServerVersion = "1.1.0-rc"; private static readonly string ServerVersion = "1.0.31-rc";
private static void CopyrightInfo() private static void CopyrightInfo()
{ {
+3 -4
View File
@@ -5,16 +5,15 @@ namespace Ragon.Core.Game;
public class Entity public class Entity
{ {
private static ushort _idGenerator = 0; private static ushort _idGenerator = 0;
public ushort Id { get; private set; } public ushort Id { get; private set; }
public ushort Type { get; private set; }
public ushort StaticId { get; private set; }
public RoomPlayer Owner { get; private set; } public RoomPlayer Owner { get; private set; }
public RagonAuthority Authority { get; private set; } public RagonAuthority Authority { get; private set; }
public EntityState State { get; private set; } public EntityState State { get; private set; }
public byte[] Payload { get; private set; } public byte[] Payload { get; private set; }
public ushort StaticId { get; private set; }
public ushort Type { get; private set; }
private List<EntityEvent> _bufferedEvents; private readonly List<EntityEvent> _bufferedEvents;
public Entity(RoomPlayer owner, ushort type, ushort staticId, RagonAuthority eventAuthority) public Entity(RoomPlayer owner, ushort type, ushort staticId, RagonAuthority eventAuthority)
{ {
-1
View File
@@ -5,7 +5,6 @@ namespace Ragon.Core.Game;
public class EntityState public class EntityState
{ {
private Logger _logger = LogManager.GetCurrentClassLogger();
private List<EntityStateProperty> _properties; private List<EntityStateProperty> _properties;
private Entity _entity; private Entity _entity;
+2 -2
View File
@@ -24,8 +24,8 @@ public class EntityStateProperty
public ReadOnlySpan<byte> Read() public ReadOnlySpan<byte> Read()
{ {
var dataSpan = _data.AsSpan(); var dataSpan = _data.AsSpan();
var src = dataSpan.Slice(0, Size);
return dataSpan.Slice(0, Size); return src;
} }
public void Write(ref ReadOnlySpan<byte> src) public void Write(ref ReadOnlySpan<byte> src)
@@ -14,6 +14,7 @@ public sealed class EntityStateHandler: IHandler
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++) for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
{ {
var entityId = reader.ReadUShort(); var entityId = reader.ReadUShort();
if (room.Entities.TryGetValue(entityId, out var entity)) if (room.Entities.TryGetValue(entityId, out var entity))
{ {
entity.State.Read(reader); entity.State.Read(reader);
@@ -76,6 +76,6 @@ public sealed class JoinOrCreateHandler : IHandler
var sendData = writer.ToArray(); var sendData = writer.ToArray();
player.Connection.Reliable.Send(sendData); player.Connection.Reliable.Send(sendData);
_logger.Trace($"Joined to room {room.Id}"); _logger.Trace($"{player.Connection.Id}|{player.Name} joined to room {room.Id}");
} }
} }
+2 -1
View File
@@ -36,10 +36,11 @@ public sealed class SceneLoadedHandler : IHandler
entity.State.AddProperty(new EntityStateProperty(propertySize, propertyType)); entity.State.AddProperty(new EntityStateProperty(propertySize, propertyType));
} }
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} created entity {entity.Id}:{entity.Type}");
room.AttachEntity(player, entity); room.AttachEntity(player, entity);
} }
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} loaded with {statics} scene entities"); _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} loaded");
room.WaitPlayersList.Add(player); room.WaitPlayersList.Add(player);
+1 -1
View File
@@ -8,7 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="NLog" Version="5.0.5" /> <PackageReference Include="NLog" Version="5.1.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"serverKey": "defaultkey", "serverKey": "defaultkey",
"serverType": "websocket", "serverType": "enet",
"serverTickRate": 20, "serverTickRate": 20,
"gameProtocol": "1.0.0", "gameProtocol": "1.0.0",
"port": 5000, "port": 5000,
+1 -1
View File
@@ -35,7 +35,7 @@ namespace Ragon.Server.ENet
_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($"Network listening on {configuration.Port}"); _logger.Info($"Listen at 127.0.0.1:{configuration.Port}");
_logger.Info($"Protocol: {protocolDecoded}"); _logger.Info($"Protocol: {protocolDecoded}");
} }
@@ -12,7 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NLog" Version="5.0.5" /> <PackageReference Include="NLog" Version="5.1.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -19,17 +19,18 @@ public class NativeWebSocketServer : INetworkServer
private Executor _executor; private Executor _executor;
private HttpListener _httpListener; private HttpListener _httpListener;
private WebSocketConnection[] _connections; private WebSocketConnection[] _connections;
private ushort _lastPeerId; private List<WebSocketConnection> _activeConnections;
private CancellationTokenSource _cancellationTokenSource; private CancellationTokenSource _cancellationTokenSource;
public NativeWebSocketServer(Executor executor) public NativeWebSocketServer(Executor executor)
{ {
_sequencer = new Stack<ushort>(); _sequencer = new Stack<ushort>();
_connections = Array.Empty<WebSocketConnection>(); _connections = Array.Empty<WebSocketConnection>();
_activeConnections = new List<WebSocketConnection>();
_executor = executor; _executor = executor;
} }
public async Task StartAccept(CancellationToken cancellationToken) public async void StartAccept(CancellationToken cancellationToken)
{ {
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested)
{ {
@@ -42,15 +43,16 @@ public class NativeWebSocketServer : INetworkServer
var peerId = _sequencer.Pop(); var peerId = _sequencer.Pop();
var connection = new WebSocketConnection(webSocket, peerId); var connection = new WebSocketConnection(webSocket, peerId);
_lastPeerId = peerId;
_connections[peerId] = connection; _connections[peerId] = connection;
_networkListener.OnConnected(connection); StartListen(connection, cancellationToken);
_executor.Run(StartListen(connection, cancellationToken));
} }
} }
async Task StartListen(WebSocketConnection connection, CancellationToken cancellationToken) async void StartListen(WebSocketConnection connection, CancellationToken cancellationToken)
{ {
_activeConnections.Add(connection);
_networkListener.OnConnected(connection);
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);
@@ -72,19 +74,20 @@ public class NativeWebSocketServer : INetworkServer
} }
_sequencer.Push(connection.Id); _sequencer.Push(connection.Id);
_activeConnections.Remove(connection);
_networkListener.OnDisconnected(connection); _networkListener.OnDisconnected(connection);
} }
public async void Poll() public void Poll()
{ {
foreach (var conn in _connections) Flush();
{ }
if (conn != null)
public async void Flush()
{ {
foreach (var conn in _activeConnections)
await conn.Flush(); await conn.Flush();
} }
}
}
public void Start( public void Start(
INetworkListener listener, INetworkListener listener,
@@ -106,10 +109,10 @@ public class NativeWebSocketServer : INetworkServer
_httpListener.Prefixes.Add($"http://127.0.0.1:{configuration.Port}/"); _httpListener.Prefixes.Add($"http://127.0.0.1:{configuration.Port}/");
_httpListener.Start(); _httpListener.Start();
_executor.Run(StartAccept(_cancellationTokenSource.Token)); _executor.Run(() => StartAccept(_cancellationTokenSource.Token));
var protocolDecoded = RagonVersion.Parse(configuration.Protocol); var protocolDecoded = RagonVersion.Parse(configuration.Protocol);
_logger.Info($"Network listening on http://*:{configuration.Port}/"); _logger.Info($"Listen at http://*:{configuration.Port}/");
_logger.Info($"Protocol: {protocolDecoded}"); _logger.Info($"Protocol: {protocolDecoded}");
} }
+2 -2
View File
@@ -9,9 +9,9 @@ public class Executor: TaskScheduler
private Queue<Task> _pendingTasks; private Queue<Task> _pendingTasks;
private TaskFactory _taskFactory; private TaskFactory _taskFactory;
public void Run(Task task) public void Run(Action action)
{ {
_taskFactory.StartNew(() => task); _taskFactory.StartNew(action);
} }
public Executor() public Executor()
+2 -5
View File
@@ -6,14 +6,12 @@
Ragon is fully free, small and high perfomance room based game server with plugin based architecture. Ragon is fully free, small and high perfomance room based game server with plugin based architecture.
<a href="https://ragon-server.com/docs/category/basics">Documentation</a> <a href="http://localhost:3000/docs/installation">Documentation</a>
<br>
<a href="https://ragon-server.com/docs/get-started">Get started</a>
### Features: ### Features:
- Effective - Effective
- Free - Free
- Simple matchmaking - Lobby
- Room based architecture - Room based architecture
- Сustomizable authorization - Сustomizable authorization
- Сustomizable server-side logic via plugins with flexible API*(2) - Сustomizable server-side logic via plugins with flexible API*(2)
@@ -33,5 +31,4 @@ MIT
### Tips ### Tips
\* Limited to 4095 CCU by library ENet-Sharp (1) \* Limited to 4095 CCU by library ENet-Sharp (1)
\* Non finally (2) \* Non finally (2)