diff --git a/src/BizHawk.Client.Common/Api/SocketServer.cs b/src/BizHawk.Client.Common/Api/SocketServer.cs index ba8e7b7e64c..118ddf0f68c 100644 --- a/src/BizHawk.Client.Common/Api/SocketServer.cs +++ b/src/BizHawk.Client.Common/Api/SocketServer.cs @@ -24,7 +24,7 @@ public static byte[] PrefixWithLength(byte[] payload) private readonly Func _takeScreenshotCallback; - private (string HostIP, int Port) _targetAddr; + private (string HostIP, ushort Port) _targetAddr; public bool Connected { get; private set; } @@ -38,7 +38,7 @@ public string IP } } - public int Port + public ushort Port { get => _targetAddr.Port; set @@ -48,7 +48,7 @@ public int Port } } - public (string HostIP, int Port) TargetAddress + public (string HostIP, ushort Port) TargetAddress { get => _targetAddr; set @@ -66,7 +66,7 @@ public int Port public bool Successful { get; private set; } - public SocketServer(Func takeScreenshotCallback, ProtocolType protocol, string ip, int port) + public SocketServer(Func takeScreenshotCallback, ProtocolType protocol, string ip, ushort port) { _protocol = protocol; ReinitSocket(out _soc); diff --git a/src/BizHawk.Client.Common/ArgParser.cs b/src/BizHawk.Client.Common/ArgParser.cs index 0d8350edd3e..93320cbbdab 100644 --- a/src/BizHawk.Client.Common/ArgParser.cs +++ b/src/BizHawk.Client.Common/ArgParser.cs @@ -37,7 +37,7 @@ public static void ParseArguments(out ParsedCLIFlags parsed, string[] args) bool? startFullscreen = null; string? luaScript = null; bool? luaConsole = null; - int? socketPort = null; + ushort? socketPort = null; string? socketIP = null; string? mmfFilename = null; string? urlGet = null; @@ -131,7 +131,7 @@ public static void ParseArguments(out ParsedCLIFlags parsed, string[] args) } else if (argDowncased.StartsWithOrdinal("--socket_port=")) { - var port = int.TryParse(argDowncased.Substring(argDowncased.IndexOf('=') + 1), out var i1) ? i1 : default; + var port = ushort.TryParse(arg.Substring(14), out var i1) ? i1 : (ushort) 0; if (port > 0) socketPort = port; } else if (argDowncased.StartsWithOrdinal("--socket_ip=")) @@ -184,7 +184,7 @@ public static void ParseArguments(out ParsedCLIFlags parsed, string[] args) var httpAddresses = urlGet == null && urlPost == null ? ((string?, string?)?) null // don't bother : (urlGet, urlPost); - (string, int)? socketAddress; + (string, ushort)? socketAddress; if (socketIP == null && socketPort == null) { socketAddress = null; // don't bother diff --git a/src/BizHawk.Client.Common/ParsedCLIFlags.cs b/src/BizHawk.Client.Common/ParsedCLIFlags.cs index d2f0c0338f4..489585ea292 100644 --- a/src/BizHawk.Client.Common/ParsedCLIFlags.cs +++ b/src/BizHawk.Client.Common/ParsedCLIFlags.cs @@ -35,7 +35,7 @@ public readonly struct ParsedCLIFlags public readonly bool luaConsole; - public readonly (string IP, int Port)? SocketAddress; + public readonly (string IP, ushort Port)? SocketAddress; public readonly ProtocolType SocketProtocol; @@ -66,7 +66,7 @@ public ParsedCLIFlags( bool startFullscreen, string? luaScript, bool luaConsole, - (string IP, int Port)? socketAddress, + (string IP, ushort Port)? socketAddress, string? mmfFilename, (string? UrlGet, string? UrlPost)? httpAddresses, bool? audiosync, diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs index bc44d08d1cb..bbf72ce810a 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs @@ -93,7 +93,7 @@ public void SocketServerSetIp(string ip) } [LuaMethod("socketServerSetPort", "sets the port of the Lua socket server")] - public void SocketServerSetPort(int port) + public void SocketServerSetPort(ushort port) { CheckSocketServer(); APIs.Comm.Sockets.Port = port;