Skip to content

Commit

Permalink
fix chalk crash *again*
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMeepso committed Nov 28, 2024
1 parent a4023b2 commit 596dbd9
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions Cove/Server/Server.Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,42 @@ void OnNetworkPacket(byte[] packet, CSteamID sender)

internal void SendStagedChalkPackets(CSteamID recipient)
{
// send the player all the canvas data
foreach (Chalk.ChalkCanvas canvas in chalkCanvas)
try
{
Dictionary<int, object> allChalk = canvas.getChalkPacket();
// send the player all the canvas data
foreach (Chalk.ChalkCanvas canvas in chalkCanvas)
{
Dictionary<int, object> allChalk = canvas.getChalkPacket();

// split the dictionary into chunks of 100
List<Dictionary<int, object>> chunks = new List<Dictionary<int, object>>();
Dictionary<int, object> chunk = new Dictionary<int, object>();
// split the dictionary into chunks of 100
List<Dictionary<int, object>> chunks = new List<Dictionary<int, object>>();
Dictionary<int, object> chunk = new Dictionary<int, object>();

int i = 0;
foreach (var kvp in allChalk)
{
if (i >= 1000)
int i = 0;
foreach (var kvp in allChalk)
{
chunks.Add(chunk);
chunk = new Dictionary<int, object>();
i = 0;
if (i >= 1000)
{
chunks.Add(chunk);
chunk = new Dictionary<int, object>();
i = 0;
}
chunk.Add(i, kvp.Value);
i++;
}
chunk.Add(i, kvp.Value);
i++;
}

for (int index = 0; index < chunks.Count; index++)
{
Dictionary<string, object> chalkPacket = new Dictionary<string, object> { { "type", "chalk_packet" }, { "canvas_id", canvas.canvasID }, { "data", chunks[index] } };
sendPacketToPlayer(chalkPacket, recipient);
Thread.Sleep(10);
for (int index = 0; index < chunks.Count; index++)
{
Dictionary<string, object> chalkPacket = new Dictionary<string, object> { { "type", "chalk_packet" }, { "canvas_id", canvas.canvasID }, { "data", chunks[index] } };
sendPacketToPlayer(chalkPacket, recipient);
Thread.Sleep(10);
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}

0 comments on commit 596dbd9

Please sign in to comment.