This commit is contained in:
BruceChen 2023-01-14 21:20:22 +08:00
parent ced65122f1
commit 1298654693
2 changed files with 20 additions and 9 deletions

View file

@ -1107,13 +1107,10 @@ namespace MinecraftClient
/// <returns>Player info</returns>
public PlayerInfo? GetPlayerInfo(Guid uuid)
{
lock (onlinePlayers)
{
if (onlinePlayers.ContainsKey(uuid))
return onlinePlayers[uuid];
else
return null;
}
if (onlinePlayers.TryGetValue(uuid, out PlayerInfo? player))
return player;
else
return null;
}
public PlayerKeyPair? GetPlayerKeyPair()

View file

@ -1351,6 +1351,7 @@ namespace MinecraftClient.Protocol.Handlers
{
Guid playerUuid = dataTypes.ReadNextUUID(packetData);
PlayerInfo player;
if ((actionBitset & (1 << 0)) > 0) // Actions bit 0: add player
{
string name = dataTypes.ReadNextString(packetData);
@ -1362,10 +1363,23 @@ namespace MinecraftClient.Protocol.Handlers
if (dataTypes.ReadNextBool(packetData))
dataTypes.SkipNextString(packetData);
}
handler.OnPlayerJoin(new(name, playerUuid));
player = new(name, playerUuid);
handler.OnPlayerJoin(player);
}
else
{
PlayerInfo? playerGet = handler.GetPlayerInfo(playerUuid);
if (playerGet == null)
{
player = new(string.Empty, playerUuid);
handler.OnPlayerJoin(player);
}
else
{
player = playerGet;
}
}
PlayerInfo player = handler.GetPlayerInfo(playerUuid)!;
if ((actionBitset & (1 << 1)) > 0) // Actions bit 1: initialize chat
{
bool hasSignatureData = dataTypes.ReadNextBool(packetData);