Unstable v0.19.1.0

This commit is contained in:
Juan Pablo Arce
2022-08-19 13:59:08 -03:00
parent 6b55adcdd9
commit 1219615d64
192 changed files with 3875 additions and 2648 deletions
@@ -1,55 +1,14 @@
using System;
using System.Net;
using Lidgren.Network;
using Lidgren.Network;
namespace Barotrauma.Networking
{
public class LidgrenConnection : NetworkConnection
sealed class LidgrenConnection : NetworkConnection
{
public NetConnection NetConnection { get; private set; }
public readonly NetConnection NetConnection;
public IPEndPoint IPEndPoint => NetConnection.RemoteEndPoint;
public string IPString
public LidgrenConnection(NetConnection netConnection) : base(new LidgrenEndpoint(netConnection.RemoteEndPoint))
{
get
{
return IPEndPoint.Address.IsIPv4MappedToIPv6 ? IPEndPoint.Address.MapToIPv4NoThrow().ToString() : IPEndPoint.Address.ToString();
}
}
public UInt16 Port
{
get
{
return (UInt16)IPEndPoint.Port;
}
}
public LidgrenConnection(string name, NetConnection netConnection, UInt64 steamId)
{
Name = name;
NetConnection = netConnection;
SteamID = steamId;
EndPointString = IPString;
}
public override bool SetSteamIDIfUnknown(UInt64 id)
{
if (SteamID != 0) { return false; } //do not allow the SteamID to be set multiple times
SteamID = id;
return true;
}
public override bool EndpointMatches(string endPoint)
{
if (IPEndPoint?.Address == null) { return false; }
if (!IPAddress.TryParse(endPoint, out IPAddress addr)) { return false; }
IPAddress ip1 = IPEndPoint.Address.IsIPv4MappedToIPv6 ? IPEndPoint.Address.MapToIPv4() : IPEndPoint.Address;
IPAddress ip2 = addr.IsIPv4MappedToIPv6 ? addr.MapToIPv4() : addr;
return ip1.ToString() == ip2.ToString();
}
}
}
@@ -8,57 +8,37 @@ namespace Barotrauma.Networking
Disconnected = 0x2
}
public abstract class NetworkConnection
abstract class NetworkConnection
{
public const double TimeoutThreshold = 60.0; //full minute for timeout because loading screens can take quite a while
public const double TimeoutThresholdInGame = 10.0;
public string Name;
public AccountInfo AccountInfo { get; private set; } = AccountInfo.None;
public UInt64 SteamID
{
get;
protected set;
}
public UInt64 OwnerSteamID
{
get;
protected set;
}
public string EndPointString
{
get;
protected set;
}
public readonly Endpoint Endpoint;
[Obsolete("TODO: this doesn't belong in layer 1")]
public LanguageIdentifier Language
{
get; set;
}
public abstract bool EndpointMatches(string endPoint);
public NetworkConnection(Endpoint endpoint)
{
Endpoint = endpoint;
}
public bool EndpointMatches(Endpoint endPoint)
=> Endpoint == endPoint;
public NetworkConnectionStatus Status = NetworkConnectionStatus.Disconnected;
public virtual bool SetSteamIDIfUnknown(UInt64 id)
public void SetAccountInfo(AccountInfo newInfo)
{
//by default, don't allow setting the ID, this is only done
//with Lidgren connections since those are initialized before
//the SteamID can be known; it's set once the Steam auth ticket
//is received by the server.
return false;
}
public bool SetOwnerSteamIDIfUnknown(UInt64 id)
{
//we know that for both Lidgren and SteamP2P, the
//owner id isn't known until the auth ticket is
//processed, so this method is the same for both
if (OwnerSteamID != 0) { return false; }
OwnerSteamID = id;
return true;
AccountInfo = newInfo;
}
public sealed override string ToString()
=> Endpoint.StringRepresentation;
}
}
@@ -1,19 +1,33 @@
using Barotrauma.Steam;
#nullable enable
using System;
namespace Barotrauma.Networking
{
public class PipeConnection : NetworkConnection
sealed class PipeEndpoint : Endpoint
{
public PipeConnection(ulong steamId)
{
EndPointString = "PIPE";
SteamID = steamId;
}
public override string StringRepresentation => "PIPE";
public override LocalizedString ServerTypeString => throw new InvalidOperationException();
public override bool EndpointMatches(string endPoint)
public PipeEndpoint() : base(new PipeAddress()) { }
public override bool Equals(object? obj)
=> obj is PipeEndpoint;
public override int GetHashCode() => 1;
public static bool operator ==(PipeEndpoint a, PipeEndpoint b)
=> true;
public static bool operator !=(PipeEndpoint a, PipeEndpoint b)
=> !(a == b);
}
sealed class PipeConnection : NetworkConnection
{
public PipeConnection(AccountId accountId) : base(new PipeEndpoint())
{
return SteamManager.SteamIDStringToUInt64(endPoint) == SteamID || endPoint == "PIPE";
SetAccountInfo(new AccountInfo(Option<AccountId>.Some(accountId)));
}
}
}
@@ -1,18 +1,13 @@
using Barotrauma.Steam;
using System;
namespace Barotrauma.Networking
namespace Barotrauma.Networking
{
public class SteamP2PConnection : NetworkConnection
sealed class SteamP2PConnection : NetworkConnection
{
public double Timeout = 0.0;
public SteamP2PConnection(string name, UInt64 steamId)
public SteamP2PConnection(SteamId steamId) : this(new SteamP2PEndpoint(steamId)) { }
public SteamP2PConnection(SteamP2PEndpoint endpoint) : base(endpoint)
{
SteamID = steamId;
OwnerSteamID = 0;
EndPointString = SteamManager.SteamIDUInt64ToString(SteamID);
Name = name;
Heartbeat();
}
@@ -25,10 +20,5 @@ namespace Barotrauma.Networking
{
Timeout = TimeoutThreshold;
}
public override bool EndpointMatches(string endPoint)
{
return SteamManager.SteamIDStringToUInt64(endPoint) == SteamID;
}
}
}