parent
9a25ee86e8
commit
b7f44b5215
Binary file not shown.
|
|
@ -79,48 +79,51 @@ namespace Lobbies
|
|||
public void HostLobby(Guid gameId, string name, int gameMode, int maxPlayerCount, string? password, int port)
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -143,12 +146,12 @@ namespace Lobbies
|
|||
/// <param name="sendUdpToGetExternalPortMappingCallback">A callback to send udp data if you have a udp game client ready and bound</param>
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue