fixup! Spawn PlayerInfo's if host is not authoritive

This commit is contained in:
miniduikboot committed 2024-06-22 13:07:54 +02:00
1 parent 5cac18723d
commit 94f30ef87d
2 files changed
+11 -2

No files matched your search

@@ -7,11 +7,14 @@ namespace Impostor.Server.Net.Inner.Objects
internal partial class InnerGameData : IInnerGameData
{
private readonly ConcurrentDictionary<byte, InnerPlayerInfo> _allPlayers = new();
private readonly ConcurrentDictionary<int, InnerPlayerInfo> _allPlayersByClientId = new();
public int PlayerCount => _allPlayers.Count;
public IReadOnlyDictionary<byte, InnerPlayerInfo> Players => _allPlayers;
internal IReadOnlyDictionary<int, InnerPlayerInfo> PlayersByClientId => _allPlayersByClientId;
public InnerPlayerInfo? GetPlayerById(byte id)
{
if (id == byte.MaxValue)
@@ -25,11 +28,17 @@ namespace Impostor.Server.Net.Inner.Objects
internal void AddPlayer(InnerPlayerInfo playerInfo)
{
_allPlayers.TryAdd(playerInfo.PlayerId, playerInfo);
_allPlayersByClientId.TryAdd(playerInfo.ClientId, playerInfo);
}
internal void RemovePlayer(byte playerId)
{
_allPlayers.TryRemove(playerId, out _);
_allPlayers.TryRemove(playerId, out var player);
if (player != null)
{
_allPlayersByClientId.TryRemove(player.ClientId, out _);
}
}
internal byte GetNextAvailablePlayerId()
+1 -1
View File
@@ -474,7 +474,7 @@ namespace Impostor.Server.Net.State
}
// If the host doesn't disable server authority, spawn a player info for it
if (!IsHostAuthoritive && sender.Character == null)
if (!IsHostAuthoritive && !GameNet.GameData.PlayersByClientId.ContainsKey(sender.Client.Id))
{
var playerInfo = (InnerPlayerInfo)ActivatorUtilities.CreateInstance(_serviceProvider, typeof(InnerPlayerInfo), this);
playerInfo.SpawnFlags = SpawnFlags.None;