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)
|
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))
|
var lobbyCreate = new LobbyCreate()
|
||||||
{
|
{
|
||||||
(hash, salt) = PasswordHash.Hash(password);
|
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()
|
byte[] messageData = bufferRental.Rent();
|
||||||
{
|
var len = lobbyCreate.Serialize(messageData);
|
||||||
GameId = gameId,
|
await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData);
|
||||||
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); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestLobbyHostInfo(Guid lobbyId, string? password)
|
public void RequestLobbyHostInfo(Guid lobbyId, string? password)
|
||||||
{
|
{
|
||||||
byte[]? passwordHash = null;
|
_ = Task.Run(async () => {
|
||||||
if(!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null)
|
byte[]? passwordHash = null;
|
||||||
passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!);
|
if (!string.IsNullOrEmpty(password) && lobbyInformation.ContainsKey(lobbyId) && lobbyInformation[lobbyId].PasswordSalt != null)
|
||||||
|
passwordHash = PasswordHash.Hash(password, lobbyInformation[lobbyId].PasswordSalt!);
|
||||||
|
|
||||||
var lobbyCreate = new LobbyRequestHostInfo()
|
var lobbyCreate = new LobbyRequestHostInfo()
|
||||||
{
|
{
|
||||||
LobbyId = lobbyId,
|
LobbyId = lobbyId,
|
||||||
PasswordHash = passwordHash,
|
PasswordHash = passwordHash,
|
||||||
};
|
};
|
||||||
|
|
||||||
byte[] messageData = bufferRental.Rent();
|
byte[] messageData = bufferRental.Rent();
|
||||||
var len = lobbyCreate.Serialize(messageData);
|
var len = lobbyCreate.Serialize(messageData);
|
||||||
_ = Task.Run(async () => { await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData); });
|
await tcpClient.Send(messageData, 0, len); bufferRental.Return(messageData);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// <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)
|
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(() =>
|
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);
|
QueryExternalIpAndPort(sendUdpToGetExternalPortMappingCallback);
|
||||||
var lobbyRequestNatPunch = new LobbyRequestNatPunch()
|
var lobbyRequestNatPunch = new LobbyRequestNatPunch()
|
||||||
{
|
{
|
||||||
|
|
@ -179,15 +182,15 @@ namespace Lobbies
|
||||||
if(port < 0 && port > 65535)
|
if(port < 0 && port > 65535)
|
||||||
throw new ArgumentOutOfRangeException(nameof(port));
|
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();
|
var udpEchoServer = new UdpEchoServer();
|
||||||
udpEchoServer.Start(port);
|
udpEchoServer.Start(port);
|
||||||
|
|
||||||
Task.Run(() =>
|
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);
|
QueryExternalIpAndPort(udpEchoServer.Send);
|
||||||
udpEchoServer.Dispose();
|
udpEchoServer.Dispose();
|
||||||
var lobbyRequestNatPunch = new LobbyRequestNatPunch()
|
var lobbyRequestNatPunch = new LobbyRequestNatPunch()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace Lobbies
|
||||||
{
|
{
|
||||||
const int keySize = 64;
|
const int keySize = 64;
|
||||||
const int saltSize = 16;
|
const int saltSize = 16;
|
||||||
const int iterations = 350000;
|
const int iterations = 100000;
|
||||||
static HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA512;
|
static HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA512;
|
||||||
|
|
||||||
static internal (byte[] hash, byte[] salt) Hash(string text)
|
static internal (byte[] hash, byte[] salt) Hash(string text)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue