mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-03-04 01:15:21 +03:00
Fix deprecation and nullability warnings.
This commit is contained in:
parent
63691f897b
commit
b4e6433545
@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Syroot.Worms.Mgame.GameServer
|
||||
{
|
||||
@ -33,8 +34,9 @@ namespace Syroot.Worms.Mgame.GameServer
|
||||
// Retrieve external IP if not yet done and given IP is invalid.
|
||||
if (_ipAddress == null && (IP == null || !IPAddress.TryParse(IP, out _ipAddress)))
|
||||
{
|
||||
using WebClient webClient = new WebClient();
|
||||
_ipAddress = IPAddress.Parse(webClient.DownloadString("https://ip.syroot.com"));
|
||||
using HttpClient httpClient = new HttpClient();
|
||||
_ipAddress = IPAddress.Parse(
|
||||
httpClient.GetStringAsync("https://ip.syroot.com").GetAwaiter().GetResult());
|
||||
}
|
||||
return _ipAddress;
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
Stream stream = client.GetStream();
|
||||
_reader = PipeReader.Create(stream);
|
||||
_writer = PipeWriter.Create(stream);
|
||||
RemoteEndPoint = (IPEndPoint)client.Client.RemoteEndPoint;
|
||||
RemoteEndPoint = client.Client.RemoteEndPoint as IPEndPoint
|
||||
?? throw new ArgumentException("TCP client is not connected.", nameof(client));
|
||||
}
|
||||
|
||||
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
|
||||
|
@ -23,9 +23,11 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
|
||||
private static IPEndPoint ParseEndPoint(string? s, IPEndPoint fallback)
|
||||
{
|
||||
if (UInt16.TryParse(s, out ushort port))
|
||||
if (s == null)
|
||||
return fallback;
|
||||
else if (UInt16.TryParse(s, out ushort port))
|
||||
return new IPEndPoint(fallback.Address, port);
|
||||
else if (IPEndPoint.TryParse(s, out IPEndPoint endPoint))
|
||||
else if (IPEndPoint.TryParse(s, out IPEndPoint? endPoint))
|
||||
return endPoint;
|
||||
else
|
||||
return fallback;
|
||||
|
@ -405,7 +405,7 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
return;
|
||||
|
||||
// Require valid room ID and IP.
|
||||
if (IPAddress.TryParse(packet.Data, out IPAddress ip) && connection.RemoteEndPoint.Address.Equals(ip))
|
||||
if (IPAddress.TryParse(packet.Data, out IPAddress? ip) && connection.RemoteEndPoint.Address.Equals(ip))
|
||||
{
|
||||
Game newGame = new Game(++_lastID, fromUser.Name, fromUser.Session.Nation, fromUser.RoomID,
|
||||
connection.RemoteEndPoint.Address, // do not use bad NAT IP reported by users here
|
||||
|
Loading…
x
Reference in New Issue
Block a user