Files
RobustToolbox/Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.MsgServerHandshake.cs
Tyler Young 0d52def877 Have RobustSerializer use a shared string dictionary (#1117)
* implements shared string dictionary and handshake from net-code-2

* fix unit test

switch to szr sawmill

* try to silence some warnings around ZipEntry

* rebase and use system zip instead of icsharplib

fix rebase artifacts

* Update Robust.Shared/Interfaces/GameObjects/IComponentFactory.cs

* Update Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.cs

* Update Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.cs

* Apply suggestions from code review

* Apply suggestions from code review

* Update Robust.Shared/Serialization/RobustSerializer.cs

* since no longer gathering from paths, make string splitting more robust

* make string gathering ignore strings under 4 chars long

make string gathering yet more robust

* add limit to size of mapped strings

* add more string data to feed into shared string dictionary from YAML files

add JSON importer but don't parse RSI metadata yet

fix typo that breaks nulls in MappedStringSerializer

minor refactoring

make string splitting more robust

add WriteUnsignedInt / ReadUnsignedInt for validating WriteCompressedUnsignedInt / ReadCompressedUnsignedInt aren't bogus

* comment out some log statements

* minor refactor, reorder logging

add null check due to smart typing NRT checks

* Add doc comments, readability improvements to MappedStringSerializer

The protocol, handshake, and internal logic are now more documented.

The main area that could still be improved is the documentation of how
the cache system works, but the code is readable enough for now that it
isn't immediately necessary.

* add documentation, organization

* update some more doc comments

* add flows to doc comment for NetworkInitialize

* more documentation and organization

* more docs

* instead of retrieving INetManager by IoC, assign when NetworkInitialize is invoked

* "document" the regex

* Update Robust.Shared/Network/NetManager.cs

* add missing check for LockMappedStrings

* Update Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.cs

Co-authored-by: ComicIronic <comicironic@gmail.com>

* change to warning instead of throw for unlocked string mapping

Co-authored-by: ComicIronic <comicironic@gmail.com>
2020-06-12 04:09:55 +02:00

66 lines
1.9 KiB
C#

using System;
using JetBrains.Annotations;
using Lidgren.Network;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Network;
namespace Robust.Shared.Serialization
{
public partial class RobustSerializer
{
public partial class MappedStringSerializer
{
/// <summary>
/// The server part of the string-exchange handshake. Sent as the
/// first message in the handshake. Tells the client the hash of
/// the current string mapping, so the client can check if it has
/// a local copy.
/// </summary>
/// <seealso cref="NetworkInitialize"/>
[UsedImplicitly]
private class MsgServerHandshake : NetMessage
{
public MsgServerHandshake(INetChannel ch)
: base($"{nameof(RobustSerializer)}.{nameof(MappedStringSerializer)}.{nameof(MsgServerHandshake)}", MsgGroups.Core)
{
}
/// <value>
/// The hash of the current string mapping held by the server.
/// </value>
public byte[]? Hash { get; set; }
public override void ReadFromBuffer(NetIncomingMessage buffer)
{
var len = buffer.ReadVariableInt32();
if (len > 64)
{
throw new InvalidOperationException("Hash too long.");
}
Hash = buffer.ReadBytes(len);
}
public override void WriteToBuffer(NetOutgoingMessage buffer)
{
if (Hash == null)
{
throw new InvalidOperationException("Package has not been specified.");
}
buffer.WriteVariableInt32(Hash.Length);
buffer.Write(Hash);
}
}
}
}
}