fixed: websocket server wrong execution thread

This commit is contained in:
2022-12-25 03:13:01 -08:00
parent f34b05e6ff
commit e9418f4b22
10 changed files with 110 additions and 109 deletions
+2 -2
View File
@@ -37,7 +37,7 @@ public class Application : INetworkListener
if (configuration.ServerType == "websocket")
_server = new NativeWebSocketServer(_executor);
Debug.Assert(_server != null, $"Socket type not supported: {configuration.ServerType}. Supported: [enet, websocket]");
}
@@ -48,7 +48,7 @@ public class Application : INetworkListener
_executor.Execute();
_loop.Tick();
_server.Poll();
Thread.Sleep((int)1000.0f / _configuration.ServerTickRate);
}
}
+2 -3
View File
@@ -3,9 +3,8 @@ using Ragon.Common;
namespace Ragon.Core.Game;
public class EntityState
public class EntityState
{
private Logger _logger = LogManager.GetCurrentClassLogger();
private List<EntityStateProperty> _properties;
private Entity _entity;
@@ -23,7 +22,7 @@ public class EntityState
public void Write(RagonSerializer serializer)
{
serializer.WriteUShort(_entity.Id);
for (int propertyIndex = 0; propertyIndex < _properties.Count; propertyIndex++)
{
var property = _properties[propertyIndex];
+2 -2
View File
@@ -24,8 +24,8 @@ public class EntityStateProperty
public ReadOnlySpan<byte> Read()
{
var dataSpan = _data.AsSpan();
return dataSpan.Slice(0, Size);
var src = dataSpan.Slice(0, Size);
return src;
}
public void Write(ref ReadOnlySpan<byte> src)
@@ -14,6 +14,7 @@ public sealed class EntityStateHandler: IHandler
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
{
var entityId = reader.ReadUShort();
if (room.Entities.TryGetValue(entityId, out var entity))
{
entity.State.Read(reader);
@@ -76,6 +76,6 @@ public sealed class JoinOrCreateHandler : IHandler
var sendData = writer.ToArray();
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));
}
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} created entity {entity.Id}:{entity.Type}");
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);