diff --git a/Ragon.Common/Sources/RagonSerializer.cs b/Ragon.Common/Sources/RagonSerializer.cs index 6975863..059d976 100644 --- a/Ragon.Common/Sources/RagonSerializer.cs +++ b/Ragon.Common/Sources/RagonSerializer.cs @@ -156,6 +156,30 @@ namespace Ragon.Common return value; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void WriteString(string value, ushort size) + { + var stringRaw = Encoding.UTF8.GetBytes(value).AsSpan(); + ResizeIfNeed(2 + size); + + WriteUShort((ushort) stringRaw.Length); + + var data = _data.AsSpan().Slice(_offset, size); + stringRaw.CopyTo(data); + _offset += stringRaw.Length; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public string ReadString(ushort size) + { + var lenght = ReadUShort(); + var stringRaw = _data.AsSpan().Slice(_offset, size); + var strData = stringRaw.Slice(0, lenght); + var str = Encoding.UTF8.GetString(strData); + _offset += size; + return str; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void WriteString(string value) { diff --git a/Ragon/Sources/Game/GameRoom.cs b/Ragon/Sources/Game/GameRoom.cs index c3dbd99..8603201 100755 --- a/Ragon/Sources/Game/GameRoom.cs +++ b/Ragon/Sources/Game/GameRoom.cs @@ -278,6 +278,12 @@ namespace Ragon.Core var entityType = _serializer.ReadUShort(); var staticId = _serializer.ReadUShort(); var propertiesCount = _serializer.ReadUShort(); + if (propertiesCount > 63) + { + _logger.Warn($"Allowed only 64 properties per entity. EntityType(Static) {entityType}"); + return; + } + var entity = new Entity(peerId, entityType, staticId, RagonAuthority.ALL, RagonAuthority.OWNER_ONLY, propertiesCount); for (var i = 0; i < propertiesCount; i++) { @@ -322,6 +328,12 @@ namespace Ragon.Core var entityType = _serializer.ReadUShort(); var propertiesCount = _serializer.ReadUShort(); var entity = new Entity(peerId, entityType, 0, RagonAuthority.ALL, RagonAuthority.ALL, propertiesCount); + if (propertiesCount > 63) + { + _logger.Warn($"Allowed only 64 properties per entity. EntityType(Static) {entityType}"); + return; + } + for (var i = 0; i < propertiesCount; i++) { var propertySize = _serializer.ReadUShort();