feat: added checks and new ragon serializer methods
This commit is contained in:
@@ -156,6 +156,30 @@ namespace Ragon.Common
|
|||||||
return value;
|
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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void WriteString(string value)
|
public void WriteString(string value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -278,6 +278,12 @@ namespace Ragon.Core
|
|||||||
var entityType = _serializer.ReadUShort();
|
var entityType = _serializer.ReadUShort();
|
||||||
var staticId = _serializer.ReadUShort();
|
var staticId = _serializer.ReadUShort();
|
||||||
var propertiesCount = _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);
|
var entity = new Entity(peerId, entityType, staticId, RagonAuthority.ALL, RagonAuthority.OWNER_ONLY, propertiesCount);
|
||||||
for (var i = 0; i < propertiesCount; i++)
|
for (var i = 0; i < propertiesCount; i++)
|
||||||
{
|
{
|
||||||
@@ -322,6 +328,12 @@ namespace Ragon.Core
|
|||||||
var entityType = _serializer.ReadUShort();
|
var entityType = _serializer.ReadUShort();
|
||||||
var propertiesCount = _serializer.ReadUShort();
|
var propertiesCount = _serializer.ReadUShort();
|
||||||
var entity = new Entity(peerId, entityType, 0, RagonAuthority.ALL, RagonAuthority.ALL, propertiesCount);
|
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++)
|
for (var i = 0; i < propertiesCount; i++)
|
||||||
{
|
{
|
||||||
var propertySize = _serializer.ReadUShort();
|
var propertySize = _serializer.ReadUShort();
|
||||||
|
|||||||
Reference in New Issue
Block a user