diff --git a/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll b/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll index 0e02e81..9e0bbe6 100644 Binary files a/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll and b/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll differ diff --git a/LobbyClient/LobbyClient.cs b/LobbyClient/LobbyClient.cs index b172cff..83ec8a3 100644 --- a/LobbyClient/LobbyClient.cs +++ b/LobbyClient/LobbyClient.cs @@ -78,49 +78,52 @@ namespace Lobbies public void HostLobby(Guid gameId, string name, int gameMode, int maxPlayerCount, string? password, int port) { - udpEchoServer.Start(0); + udpEchoServer.Start(0); + _ = Task.Run(async () => { + byte[]? hash = null, salt = null; - byte[]? hash = null, salt = null; + if (!string.IsNullOrEmpty(password)) + { + (hash, salt) = PasswordHash.Hash(password); + } - if(!string.IsNullOrEmpty(password)) - { - (hash, salt) = PasswordHash.Hash(password); - } + var lobbyCreate = new LobbyCreate() + { + GameId = gameId, + Name = name, + GameMode = gameMode, + MaxPlayerCount = maxPlayerCount, + PlayerCount = 0, + PasswordHash = hash, + PasswordSalt = salt, + HostIps = GatherLocalIpAddresses().ToArray(), + HostPort = port, + HostTryPort = udpEchoServer.Port + }; - var lobbyCreate = new LobbyCreate() - { - GameId = gameId, - Name = name, - GameMode = gameMode, - MaxPlayerCount = maxPlayerCount, - PlayerCount = 0, - PasswordHash = hash, - PasswordSalt = salt, - HostIps = GatherLocalIpAddresses().ToArray(), - HostPort = port, - HostTryPort = udpEchoServer.Port - }; - - byte[] messageData = bufferRental.Rent(); - var len = lobbyCreate.Serialize(messageData); - _ = Task.Run(async () => { await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData); }); + byte[] messageData = bufferRental.Rent(); + var len = lobbyCreate.Serialize(messageData); + await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData); + }); } public void RequestLobbyHostInfo(Guid lobbyId, string? password) - { - byte[]? passwordHash = null; - if(!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null) - passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!); + { + _ = Task.Run(async () => { + byte[]? passwordHash = null; + if (!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null) + passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!); - var lobbyCreate = new LobbyRequestHostInfo() - { - LobbyId = lobbyId, - PasswordHash = passwordHash, - }; + var lobbyCreate = new LobbyRequestHostInfo() + { + LobbyId = lobbyId, + PasswordHash = passwordHash, + }; - byte[] messageData = bufferRental.Rent(); - var len = lobbyCreate.Serialize(messageData); - _ = Task.Run(async () => { await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData); }); + byte[] messageData = bufferRental.Rent(); + var len = lobbyCreate.Serialize(messageData); + await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData); + }); } /// @@ -142,13 +145,13 @@ namespace Lobbies /// Optional password of lobby /// A callback to send udp data if you have a udp game client ready and bound public void RequestLobbyNatPunch(Guid lobbyId, string? password, SendUdpMessageCallback sendUdpToGetExternalPortMappingCallback) - { - byte[]? passwordHash = null; - if (!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null) - passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!); - + { Task.Run(() => { + byte[]? passwordHash = null; + if (!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null) + passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!); + QueryExternalIpAndPort(sendUdpToGetExternalPortMappingCallback); var lobbyRequestNatPunch = new LobbyRequestNatPunch() { @@ -179,15 +182,15 @@ namespace Lobbies if(port < 0 && port > 65535) throw new ArgumentOutOfRangeException(nameof(port)); - byte[]? passwordHash = null; - if (!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null) - passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!); - var udpEchoServer = new UdpEchoServer(); udpEchoServer.Start(port); Task.Run(() => - { + { + byte[]? passwordHash = null; + if (!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null) + passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!); + QueryExternalIpAndPort(udpEchoServer.Send); udpEchoServer.Dispose(); var lobbyRequestNatPunch = new LobbyRequestNatPunch() diff --git a/LobbyClient/PasswordHash.cs b/LobbyClient/PasswordHash.cs index 675bc5d..c0dc5ac 100644 --- a/LobbyClient/PasswordHash.cs +++ b/LobbyClient/PasswordHash.cs @@ -7,7 +7,7 @@ namespace Lobbies { const int keySize = 64; const int saltSize = 16; - const int iterations = 350000; + const int iterations = 100000; static HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA512; static internal (byte[] hash, byte[] salt) Hash(string text)