mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using Lidgren.Network;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Robust.Shared.Network.Messages
|
|
{
|
|
|
|
/// <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="RobustMappedStringSerializer.NetworkInitialize"/>
|
|
[UsedImplicitly]
|
|
internal sealed class MsgMapStrStrings : NetMessage
|
|
{
|
|
public override MsgGroups MsgGroup => 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, IRobustSerializer serializer)
|
|
{
|
|
var size = buffer.ReadVariableInt32();
|
|
buffer.ReadBytes(Package = new byte[size]);
|
|
}
|
|
|
|
public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer)
|
|
{
|
|
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.");
|
|
}
|
|
}
|
|
}
|
|
}
|