Skip to content

Commit

Permalink
Change SocketServer.Port to a u16 (y'know like ports are)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Jun 11, 2024
1 parent b742998 commit 044729c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/BizHawk.Client.Common/Api/SocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static byte[] PrefixWithLength(byte[] payload)

private readonly Func<byte[]> _takeScreenshotCallback;

private (string HostIP, int Port) _targetAddr;
private (string HostIP, ushort Port) _targetAddr;

public bool Connected { get; private set; }

Expand All @@ -38,7 +38,7 @@ public string IP
}
}

public int Port
public ushort Port
{
get => _targetAddr.Port;
set
Expand All @@ -48,7 +48,7 @@ public int Port
}
}

public (string HostIP, int Port) TargetAddress
public (string HostIP, ushort Port) TargetAddress
{
get => _targetAddr;
set
Expand All @@ -66,7 +66,7 @@ public int Port

public bool Successful { get; private set; }

public SocketServer(Func<byte[]> takeScreenshotCallback, ProtocolType protocol, string ip, int port)
public SocketServer(Func<byte[]> takeScreenshotCallback, ProtocolType protocol, string ip, ushort port)
{
_protocol = protocol;
ReinitSocket(out _soc);
Expand Down
6 changes: 3 additions & 3 deletions src/BizHawk.Client.Common/ArgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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="))
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Client.Common/ParsedCLIFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 044729c

Please sign in to comment.