Skip to content

Conversation

@erwan-joly
Copy link
Collaborator

No description provided.

@erwan-joly erwan-joly merged commit 428bd19 into master Jan 19, 2026
2 checks passed
@erwan-joly erwan-joly deleted the Cleanup branch January 19, 2026 11:59
@@ -165,7 +152,7 @@
}

var channelcolor =
(int)Math.Round(connectedAccount.Count(x=>x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)
(int)Math.Round(connectedAccount.Count(x => x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)

Check failure

Code scanning / CodeQL

Possible loss of precision Error

Possible loss of precision: any fraction will be lost.

Copilot Autofix

AI about 20 hours ago

In general, to avoid loss of precision in this context, one of the operands of the division should be explicitly converted to a floating‑point type before the division so that C# performs floating‑point division instead of integer division. The result will then be a double, which can be safely multiplied by 20D, and Math.Round will round the result as intended.

The best, minimal change here is to cast either the numerator or the denominator to double before the division in line 155. For example, change:

(int)Math.Round(connectedAccount.Count(x => x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)

to:

(int)Math.Round(
    (double)connectedAccount.Count(x => x.ChannelId == server.ServerId)
        / (server.ConnectedAccountLimit + 1) * 20D)

or equivalently cast the denominator. This preserves the overall structure and semantics (still rounded and cast to int afterward) while ensuring the proportion is computed with fractional precision. No new methods or imports are required; System.Math is already available via using System;.

Suggested changeset 1
src/NosCore.GameObject/Services/LoginService/LoginService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NosCore.GameObject/Services/LoginService/LoginService.cs b/src/NosCore.GameObject/Services/LoginService/LoginService.cs
--- a/src/NosCore.GameObject/Services/LoginService/LoginService.cs
+++ b/src/NosCore.GameObject/Services/LoginService/LoginService.cs
@@ -152,7 +152,7 @@
                             }
 
                             var channelcolor =
-                                (int)Math.Round(connectedAccount.Count(x => x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)
+                                (int)Math.Round((double)connectedAccount.Count(x => x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)
                                 + 1;
                             subpacket.Add(new NsTeStSubPacket
                             {
EOF
@@ -152,7 +152,7 @@
}

var channelcolor =
(int)Math.Round(connectedAccount.Count(x => x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)
(int)Math.Round((double)connectedAccount.Count(x => x.ChannelId == server.ServerId) / (server.ConnectedAccountLimit + 1) * 20D)
+ 1;
subpacket.Add(new NsTeStSubPacket
{
Copilot is powered by AI and may make mistakes. Always verify output.

Check notice

Code scanning / CodeQL

Inefficient use of ContainsKey Note

Inefficient use of 'ContainsKey' and
indexer
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants