Skip to content

Commit

Permalink
fix server crash because of players thread
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMeepso committed Nov 29, 2024
1 parent e609aa0 commit 088ec91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Cove/Server/Server.Utils.Networking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void sendPacketToPlayers(Dictionary<string, object> packet)
{
byte[] packetBytes = writePacket(packet);

foreach (CSteamID player in getAllPlayers().ToList())
foreach (CSteamID player in getAllPlayers())
{
if (player == SteamUser.GetSteamID())
continue;
Expand All @@ -56,12 +56,14 @@ public void sendPacketToPlayer(Dictionary<string, object> packet, CSteamID id)

public CSteamID[] getAllPlayers()
{
int playerCount = AllPlayers.Count;
WFPlayer[] AllPlayersNow = AllPlayers.ToArray();

int playerCount = AllPlayersNow.Length;
CSteamID[] players = new CSteamID[playerCount];

for (int i = 0; i < playerCount; i++)
{
players[i] = AllPlayers[i].SteamId;
players[i] = AllPlayersNow[i].SteamId;
}

return players;
Expand Down
2 changes: 1 addition & 1 deletion Cove/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
using Cove.Server.HostedServices;
using Microsoft.Extensions.Logging;
using Vector3 = Cove.GodotFormat.Vector3;
using System.Reflection;

namespace Cove.Server
{
Expand Down Expand Up @@ -303,7 +304,6 @@ public void Init()
Console.WriteLine("This will cause issues, please run the server on a different account!");
Console.ResetColor();
}

}

if (stateChange.HasFlag(EChatMemberStateChange.k_EChatMemberStateChangeLeft) || stateChange.HasFlag(EChatMemberStateChange.k_EChatMemberStateChangeDisconnected))
Expand Down

0 comments on commit 088ec91

Please sign in to comment.