More fixes
This commit is contained in:
14
Program.cs
14
Program.cs
@@ -332,6 +332,15 @@ public class Program
|
|||||||
|
|
||||||
static async Task HandleCreateLobbyAsync(ConnectedClient client, CreateLobby message)
|
static async Task HandleCreateLobbyAsync(ConnectedClient client, CreateLobby message)
|
||||||
{
|
{
|
||||||
|
// If the client supplied a fresh display name on the create call,
|
||||||
|
// adopt it as the connection's authoritative name. ClientHello-time
|
||||||
|
// names are stale because the handshake fires before the user has
|
||||||
|
// had a chance to type into the nickname field; without this
|
||||||
|
// override the server records the user as the prefab default
|
||||||
|
// ("Hrac") even when they typed a real name.
|
||||||
|
if (!string.IsNullOrWhiteSpace(message.DisplayName))
|
||||||
|
client.DisplayName = message.DisplayName.Trim();
|
||||||
|
|
||||||
var (lobby, joinCode, error) = await _lobbyManager.CreateLobbyAsync(
|
var (lobby, joinCode, error) = await _lobbyManager.CreateLobbyAsync(
|
||||||
client.ClientUuid, client.DisplayName, message);
|
client.ClientUuid, client.DisplayName, message);
|
||||||
|
|
||||||
@@ -360,6 +369,11 @@ public class Program
|
|||||||
|
|
||||||
static async Task HandleJoinLobbyAsync(ConnectedClient client, JoinLobby message)
|
static async Task HandleJoinLobbyAsync(ConnectedClient client, JoinLobby message)
|
||||||
{
|
{
|
||||||
|
// Mirror of HandleCreateLobbyAsync: adopt the freshly-typed name if
|
||||||
|
// the client supplied one. See that method's comment for rationale.
|
||||||
|
if (!string.IsNullOrWhiteSpace(message.DisplayName))
|
||||||
|
client.DisplayName = message.DisplayName.Trim();
|
||||||
|
|
||||||
var clientIp = client.Endpoint.Split(':')[0];
|
var clientIp = client.Endpoint.Split(':')[0];
|
||||||
var (lobby, error) = await _lobbyManager.JoinLobbyAsync(
|
var (lobby, error) = await _lobbyManager.JoinLobbyAsync(
|
||||||
clientIp, client.ClientUuid, client.DisplayName, message.JoinCode, message.Password);
|
clientIp, client.ClientUuid, client.DisplayName, message.JoinCode, message.Password);
|
||||||
|
|||||||
16
Protocol.cs
16
Protocol.cs
@@ -423,6 +423,16 @@ public class CreateLobby : Message
|
|||||||
public double PlayAreaRadius { get; set; } = 500; // metry
|
public double PlayAreaRadius { get; set; } = 500; // metry
|
||||||
public int ImpostorCount { get; set; } = 1;
|
public int ImpostorCount { get; set; } = 1;
|
||||||
public int TaskCount { get; set; } = 5;
|
public int TaskCount { get; set; } = 5;
|
||||||
|
/// <summary>
|
||||||
|
/// Optional. If present, server uses this as the host's display name
|
||||||
|
/// (and updates the connection's stored DisplayName so subsequent
|
||||||
|
/// operations also use it). Client sends the live value from the
|
||||||
|
/// nickname input field, which avoids the ClientHello-time staleness:
|
||||||
|
/// the original ClientHello fired at TCP connection (long before the
|
||||||
|
/// user typed anything), so the server would otherwise see the prefab
|
||||||
|
/// default ("Hrac") for users who type their name and immediately host.
|
||||||
|
/// </summary>
|
||||||
|
public string? DisplayName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CreateLobbyResponse : Message
|
public class CreateLobbyResponse : Message
|
||||||
@@ -440,6 +450,12 @@ public class JoinLobby : Message
|
|||||||
public override string Type => "JoinLobby";
|
public override string Type => "JoinLobby";
|
||||||
public required string JoinCode { get; set; }
|
public required string JoinCode { get; set; }
|
||||||
public string? Password { get; set; }
|
public string? Password { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Optional. If present, server uses this as the joiner's display name
|
||||||
|
/// instead of the ClientHello-time value. See CreateLobby.DisplayName
|
||||||
|
/// for the rationale (input-field commit race vs handshake-time name).
|
||||||
|
/// </summary>
|
||||||
|
public string? DisplayName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JoinLobbyResponse : Message
|
public class JoinLobbyResponse : Message
|
||||||
|
|||||||
Reference in New Issue
Block a user