mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* 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>
73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using System;
|
|
using System.IO;
|
|
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 meat of the string-exchange handshake sandwich. Sent by the
|
|
/// server after the client requests an updated copy of the mapping.
|
|
/// Contains the updated string mapping.
|
|
/// </summary>
|
|
/// <seealso cref="NetworkInitialize"/>
|
|
[UsedImplicitly]
|
|
private class MsgStrings : NetMessage
|
|
{
|
|
|
|
public MsgStrings(INetChannel ch)
|
|
: base($"{nameof(RobustSerializer)}.{nameof(MappedStringSerializer)}.{nameof(MsgStrings)}", MsgGroups.Core)
|
|
{
|
|
}
|
|
|
|
/// <value>
|
|
/// The raw bytes of the string mapping held by the server.
|
|
/// </value>
|
|
public byte[]? Package { get; set; }
|
|
|
|
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
|
{
|
|
var l = buffer.ReadVariableInt32();
|
|
var success = buffer.ReadBytes(l, out var buf);
|
|
if (!success)
|
|
{
|
|
throw new InvalidDataException("Not all of the bytes were available in the message.");
|
|
}
|
|
|
|
Package = buf;
|
|
}
|
|
|
|
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
|
{
|
|
if (Package == null)
|
|
{
|
|
throw new InvalidOperationException("Package has not been specified.");
|
|
}
|
|
|
|
buffer.WriteVariableInt32(Package.Length);
|
|
var start = buffer.LengthBytes;
|
|
buffer.Write(Package);
|
|
var added = buffer.LengthBytes - start;
|
|
if (added != Package.Length)
|
|
{
|
|
throw new InvalidOperationException("Not all of the bytes were written to the message.");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|