Made most of the networking interfaces public.

This commit is contained in:
MapleWheels
2026-02-03 19:43:49 -05:00
committed by Maplewheels
parent 80555ef933
commit cae3741953
9 changed files with 12 additions and 173 deletions
@@ -7,7 +7,7 @@ using FluentResults;
namespace Barotrauma.LuaCs.Services; namespace Barotrauma.LuaCs.Services;
public partial class ConfigService public sealed partial class ConfigService
{ {
public ImmutableArray<IDisplayableConfigBase> GetDisplayableConfigs() public ImmutableArray<IDisplayableConfigBase> GetDisplayableConfigs()
{ {
@@ -73,12 +73,12 @@ public class SettingEntry<T> : ISettingEntry<T> where T : IEquatable<T>
public Guid InstanceId { get; } public Guid InstanceId { get; }
public NetSync SyncType { get; } public NetSync SyncType { get; }
public ClientPermissions WritePermissions { get; } public ClientPermissions WritePermissions { get; }
public void ReadNetMessage(INetReadMessage message) public void ReadNetMessage(IReadMessage message)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void WriteNetMessage(INetWriteMessage message) public void WriteNetMessage(IWriteMessage message)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -28,14 +28,14 @@ public interface INetworkSyncEntity
/// machine. /// machine.
/// </summary> /// </summary>
/// <param name="message">Wrapper for the internal type: <see cref="IReadMessage"/></param> /// <param name="message">Wrapper for the internal type: <see cref="IReadMessage"/></param>
void ReadNetMessage(INetReadMessage message); void ReadNetMessage(IReadMessage message);
/// <summary> /// <summary>
/// Called when a network send-event involving this entity is triggered. Any data expected to be read by the recipient /// Called when a network send-event involving this entity is triggered. Any data expected to be read by the recipient
/// network object on the other instance(s) should be written to the packet. /// network object on the other instance(s) should be written to the packet.
/// </summary> /// </summary>
/// <param name="message">Wrapper for the internal type: <see cref="IWriteMessage"/></param> /// <param name="message">Wrapper for the internal type: <see cref="IWriteMessage"/></param>
void WriteNetMessage(INetWriteMessage message); void WriteNetMessage(IWriteMessage message);
} }
/// <summary> /// <summary>
@@ -1,161 +0,0 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
namespace Barotrauma.LuaCs.Services;
#region Wrapper-IWriteMessage
/// <summary>
/// Literally just exists because Barotrauma.IWriteMessage is internal only.
/// </summary>
public interface INetWriteMessage
{
internal IWriteMessage Message { get; }
internal INetWriteMessage SetMessage(IWriteMessage msg);
void WriteBoolean(bool val) => Message.WriteBoolean(val);
void WritePadBits() => Message.WritePadBits();
void WriteByte(byte val) => Message.WriteByte(val);
void WriteInt16(short val) => Message.WriteInt16(val);
void WriteUInt16(ushort val) => Message.WriteUInt16(val);
void WriteInt32(int val) => Message.WriteInt32(val);
void WriteUInt32(uint val) => Message.WriteUInt32(val);
void WriteInt64(long val) => Message.WriteInt64(val);
void WriteUInt64(ulong val) => Message.WriteUInt64(val);
void WriteSingle(float val) => Message.WriteSingle(val);
void WriteDouble(double val) => Message.WriteDouble(val);
void WriteColorR8G8B8(Color val) => Message.WriteColorR8G8B8(val);
void WriteColorR8G8B8A8(Color val) => Message.WriteColorR8G8B8A8(val);
void WriteVariableUInt32(uint val) => Message.WriteVariableUInt32(val);
void WriteString(string val) => Message.WriteString(val);
void WriteIdentifier(Identifier val) => Message.WriteIdentifier(val);
void WriteRangedInteger(int val, int min, int max) => Message.WriteRangedInteger(val, min, max);
void WriteRangedSingle(float val, float min, float max, int bitCount) =>
Message.WriteRangedSingle(val, min, max, bitCount);
void WriteBytes(byte[] val, int startIndex, int length) => Message.WriteBytes(val, startIndex, length);
byte[] PrepareForSending(bool compressPastThreshold, out bool isCompressed, out int outLength) =>
Message.PrepareForSending(compressPastThreshold, out isCompressed, out outLength);
int BitPosition
{
get => Message.BitPosition;
set => Message.BitPosition = value;
}
int BytePosition => Message.BytePosition;
byte[] Buffer => Message.Buffer;
int LengthBits
{
get => Message.LengthBits;
set => Message.LengthBits = value;
}
int LengthBytes => Message.LengthBytes;
}
#endregion
#region Wrapper-IReadMessage
/// <summary>
/// Literally just exists because Barotrauma.IReadMessage is internal only.
/// </summary>
public interface INetReadMessage
{
internal IReadMessage Message { get; }
internal INetReadMessage SetMessage(IReadMessage msg);
bool ReadBoolean() => Message.ReadBoolean();
void ReadPadBits() => Message.ReadPadBits();
byte ReadByte() => Message.ReadByte();
byte PeekByte() => Message.PeekByte();
ushort ReadUInt16() => Message.ReadUInt16();
short ReadInt16() => Message.ReadInt16();
uint ReadUInt32() => Message.ReadUInt32();
int ReadInt32() => Message.ReadInt32();
ulong ReadUInt64() => Message.ReadUInt64();
long ReadInt64() => Message.ReadInt64();
float ReadSingle() => Message.ReadSingle();
double ReadDouble() => Message.ReadDouble();
uint ReadVariableUInt32() => Message.ReadVariableUInt32();
string ReadString() => Message.ReadString();
Identifier ReadIdentifier() => Message.ReadIdentifier();
Color ReadColorR8G8B8() => Message.ReadColorR8G8B8();
Color ReadColorR8G8B8A8() => Message.ReadColorR8G8B8A8();
int ReadRangedInteger(int min, int max) => Message.ReadRangedInteger(min, max);
float ReadRangedSingle(float min, float max, int bitCount) => Message.ReadRangedSingle(min, max, bitCount);
byte[] ReadBytes(int numberOfBytes) => Message.ReadBytes(numberOfBytes);
int BitPosition
{
get => Message.BitPosition;
set => Message.BitPosition = value;
}
int BytePosition => Message.BytePosition;
byte[] Buffer => Message.Buffer;
int LengthBits
{
get => Message.LengthBits;
set => Message.LengthBits = value;
}
int LengthBytes => Message.LengthBytes;
}
#endregion
#region HelperImplementations
public class NetWriteMessage : INetWriteMessage
{
private IWriteMessage Message { get; set; }
IWriteMessage INetWriteMessage.Message => Message;
INetWriteMessage INetWriteMessage.SetMessage(IWriteMessage msg)
{
Message = msg;
return this;
}
}
internal static class NetHelperExtensions
{
internal static INetWriteMessage ToNetWriteMessage(this IWriteMessage msg) =>
((INetWriteMessage)new NetWriteMessage()).SetMessage(msg);
internal static INetReadMessage ToNetReadMessage(this IReadMessage msg) =>
((INetReadMessage)new NetReadMessage()).SetMessage(msg);
}
public class NetReadMessage : INetReadMessage
{
private IReadMessage Message { get; set; }
IReadMessage INetReadMessage.Message => Message;
INetReadMessage INetReadMessage.SetMessage(IReadMessage msg)
{
Message = msg;
return this;
}
}
#endregion
@@ -5,7 +5,7 @@ using System.Linq;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
[NetworkSerialize] [NetworkSerialize]
readonly struct AccountInfo : INetSerializableStruct public readonly struct AccountInfo : INetSerializableStruct
{ {
public static readonly AccountInfo None = new AccountInfo(Option<AccountId>.None()); public static readonly AccountInfo None = new AccountInfo(Option<AccountId>.None());
@@ -2,7 +2,7 @@
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
abstract class Endpoint public abstract class Endpoint
{ {
public abstract string StringRepresentation { get; } public abstract string StringRepresentation { get; }
@@ -4,7 +4,7 @@ using System.Text;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
interface IReadMessage public interface IReadMessage
{ {
bool ReadBoolean(); bool ReadBoolean();
void ReadPadBits(); void ReadPadBits();
@@ -2,7 +2,7 @@
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
interface IWriteMessage public interface IWriteMessage
{ {
void WriteBoolean(bool val); void WriteBoolean(bool val);
void WritePadBits(); void WritePadBits();
@@ -8,14 +8,14 @@ namespace Barotrauma.Networking
Disconnected = 0x2 Disconnected = 0x2
} }
abstract class NetworkConnection<T> : NetworkConnection where T : Endpoint public abstract class NetworkConnection<T> : NetworkConnection where T : Endpoint
{ {
protected NetworkConnection(T endpoint) : base(endpoint) { } protected NetworkConnection(T endpoint) : base(endpoint) { }
public new T Endpoint => (base.Endpoint as T)!; public new T Endpoint => (base.Endpoint as T)!;
} }
abstract class NetworkConnection public abstract class NetworkConnection
{ {
public static double TimeoutThresholdNotInGame => GameMain.NetworkMember?.ServerSettings?.TimeoutThresholdNotInGame ?? 60.0; //full minute for timeout because loading screens can take quite a while public static double TimeoutThresholdNotInGame => GameMain.NetworkMember?.ServerSettings?.TimeoutThresholdNotInGame ?? 60.0; //full minute for timeout because loading screens can take quite a while
public static double TimeoutThresholdInGame => GameMain.NetworkMember?.ServerSettings?.TimeoutThresholdInGame ?? 10.0; public static double TimeoutThresholdInGame => GameMain.NetworkMember?.ServerSettings?.TimeoutThresholdInGame ?? 10.0;