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

View File

@@ -7,7 +7,7 @@ using FluentResults;
namespace Barotrauma.LuaCs.Services;
public partial class ConfigService
public sealed partial class ConfigService
{
public ImmutableArray<IDisplayableConfigBase> GetDisplayableConfigs()
{

View File

@@ -73,12 +73,12 @@ public class SettingEntry<T> : ISettingEntry<T> where T : IEquatable<T>
public Guid InstanceId { get; }
public NetSync SyncType { get; }
public ClientPermissions WritePermissions { get; }
public void ReadNetMessage(INetReadMessage message)
public void ReadNetMessage(IReadMessage message)
{
throw new NotImplementedException();
}
public void WriteNetMessage(INetWriteMessage message)
public void WriteNetMessage(IWriteMessage message)
{
throw new NotImplementedException();
}

View File

@@ -28,14 +28,14 @@ public interface INetworkSyncEntity
/// machine.
/// </summary>
/// <param name="message">Wrapper for the internal type: <see cref="IReadMessage"/></param>
void ReadNetMessage(INetReadMessage message);
void ReadNetMessage(IReadMessage message);
/// <summary>
/// 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.
/// </summary>
/// <param name="message">Wrapper for the internal type: <see cref="IWriteMessage"/></param>
void WriteNetMessage(INetWriteMessage message);
void WriteNetMessage(IWriteMessage message);
}
/// <summary>

View File

@@ -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

View File

@@ -5,7 +5,7 @@ using System.Linq;
namespace Barotrauma.Networking
{
[NetworkSerialize]
readonly struct AccountInfo : INetSerializableStruct
public readonly struct AccountInfo : INetSerializableStruct
{
public static readonly AccountInfo None = new AccountInfo(Option<AccountId>.None());
@@ -48,4 +48,4 @@ namespace Barotrauma.Networking
public static bool operator !=(AccountInfo a, AccountInfo b) => !(a == b);
}
}
}

View File

@@ -2,7 +2,7 @@
namespace Barotrauma.Networking
{
abstract class Endpoint
public abstract class Endpoint
{
public abstract string StringRepresentation { get; }

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Barotrauma.Networking
{
interface IReadMessage
public interface IReadMessage
{
bool ReadBoolean();
void ReadPadBits();

View File

@@ -2,7 +2,7 @@
namespace Barotrauma.Networking
{
interface IWriteMessage
public interface IWriteMessage
{
void WriteBoolean(bool val);
void WritePadBits();

View File

@@ -8,14 +8,14 @@ namespace Barotrauma.Networking
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) { }
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 TimeoutThresholdInGame => GameMain.NetworkMember?.ServerSettings?.TimeoutThresholdInGame ?? 10.0;