Skip to content

Commit b3ee990

Browse files
authored
1.4.10
Fix issues with chalk from 1.4.9
2 parents 7bea115 + 95de840 commit b3ee990

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

Cove/GodotFormat/GDClasses.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ public override string ToString()
139139
{
140140
return $"({x}, {y})";
141141
}
142+
143+
public override bool Equals(object? obj)
144+
{
145+
if (obj is Vector2 other)
146+
{
147+
return x == other.x && y == other.y;
148+
}
149+
return false;
150+
}
151+
152+
public override int GetHashCode()
153+
{
154+
return HashCode.Combine(x, y);
155+
}
142156
}
143157

144158
public class Quat

Cove/Server/Chalk/ChalkCanvas.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,49 @@ public Dictionary<int, object> getChalkPacket()
4242

4343
return packet;
4444
}
45+
46+
// The ammount of chalk pixels needed to trigger the fallback process
47+
const int TRIGGER_FALLBACK_CHALK_SIZE = 100000; // around .3mb worth of chalk data
48+
4549
public void chalkUpdate(Dictionary<int, object> packet)
4650
{
47-
foreach (KeyValuePair<int, object> entry in packet)
51+
// This callback is made when there is too much chalk data
52+
// it runs under the assumption that the newest chalk data is at the end of the packet
53+
// Webfishing will set pixels multiple times in the chalk data
54+
// assuming that the chalk data is in order, we can just take the last value
55+
// Because the newest data is at the end of the packet we update till we reach the point
56+
// of a pixel being set multiple times
57+
if (packet.Count >= TRIGGER_FALLBACK_CHALK_SIZE)
4858
{
49-
Dictionary<int, object> arr = (Dictionary<int, object>)entry.Value;
50-
Vector2 vector2 = (Vector2)arr[0];
51-
Vector2 pos = new Vector2((int)Math.Round(vector2.x), (int)Math.Round(vector2.y));
52-
Int64 color = (Int64)arr[1];
53-
54-
55-
// YES, I know this is inefficient
56-
// I dont want to break compatibility with the old code
57-
// It should be fine, its per canvas
58-
// but if it becomes a problem, I hope someone files a issue and
59-
// I'll put a performance fix in
60-
for (int i = 0; i < chalkImage.Count; i++)
59+
List<Vector2> expendedPixels = new List<Vector2>(chalkImage.Keys);
60+
for (int i = packet.Count; i >= 0; i--)
6161
{
62-
Vector2 key = chalkImage.ElementAt(i).Key;
63-
if (key.x == pos.x && key.y == pos.y)
62+
Dictionary<int, object> arr = (Dictionary<int, object>)packet[i-1];
63+
Vector2 vector2 = (Vector2)arr[0];
64+
Vector2 pos = new Vector2((int)Math.Round(vector2.x), (int)Math.Round(vector2.y));
65+
66+
if (expendedPixels.Contains(pos))
6467
{
65-
chalkImage.Remove(key);
6668
break;
6769
}
70+
71+
expendedPixels.Add(pos);
72+
chalkImage[pos] = (int)((Int64)arr[1]);
6873
}
6974

70-
chalkImage[pos] = (int)color;
75+
Console.WriteLine("A packet that was passed to the Fallback function was processed successfully");
76+
77+
}
78+
else
79+
{
80+
for (int i = 0; i < packet.Count; i++)
81+
{
82+
Dictionary<int, object> arr = (Dictionary<int, object>)packet[i];
83+
Vector2 vector2 = (Vector2)arr[0];
84+
Vector2 pos = new Vector2((int)Math.Round(vector2.x), (int)Math.Round(vector2.y));
85+
86+
chalkImage[pos] = (int)((Int64)arr[1]);
87+
}
7188
}
7289
}
7390

Cove/Server/Server.Packet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void OnNetworkPacket(byte[] packet, CSteamID sender)
175175

176176
if (canvas == null)
177177
{
178-
Log($"Creating new canvas: {canvasID}");
178+
179179
canvas = new Chalk.ChalkCanvas(canvasID);
180180
chalkCanvas.Add(canvas);
181181
}

Cove/Server/Server.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ void RunNetwork()
532532
didWork = true;
533533
for (int j = 0; j < messages.Count; j++)
534534
{
535+
if (i == 3 && messages[j].size > 50000)
536+
{
537+
string UserName = SteamFriends.GetFriendPersonaName(new CSteamID(messages[j].identity));
538+
Log($"[{UserName}] Sent a chalk packet of size {messages[j].size} bytes");
539+
Log($"Due to the size of this packet, there is a chance it will not be processed correctly.");
540+
}
535541
OnNetworkPacket(messages[j].payload, new CSteamID(messages[j].identity));
536542
}
537543
}

0 commit comments

Comments
 (0)