CnCNet / xna-cncnet-client

XNA / MonoGame based client for playing classic Command & Conquer games both online and offline with a CnCNet game spawner.
Other
223 stars 86 forks source link

Connection to GameSurge not working for some #481

Open GrantBartlett opened 1 year ago

GrantBartlett commented 1 year ago

Problem:

Some players from the RotE client are experiencing connection issues to GameSurge. They did not have this issue with the client before Net7 changes.

Client logs supplied from latest client:

Previous client.log working in cliente before all NET7 changes:

SadPencil commented 12 months ago

This exception is most likely raised by string.Substring method in Connection.cs file. https://stackoverflow.com/questions/5633661/length-cannot-be-less-than-zero-on-a-blank-line

Need to attach a debugger and observe which command raises the exception.

pzhlkj6612 commented 12 months ago

Need to attach a debugger and observe which command raises the exception.

+1.

Printing stacktrace might be also helpful:

https://github.com/CnCNet/xna-cncnet-client/blob/a8ed28433d444f40f63c6d99999417079ecebbaf/DXMainClient/Online/Connection.cs#L210

- Logger.Log("Unable to connect to the server. " + ex.Message);
+ Logger.Log("Unable to connect to the server. " + ex.Message + "\n" + ex.StackTrace);
Metadorius commented 11 months ago
21.07. 15:37:15.632    Unable to connect to the server. Length cannot be less than zero. (Parameter 'length')
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex, Int32 length)
at DTAClient.Online.Connection.HandleMessage(String message) in C:\Users\p\Desktop\CNCNET CLIENT STUFF\xna-cncnet-client\DXMainClient\Online\Connection.cs:line 515
   at DTAClient.Online.Connection.HandleComm() in C:\Users\p\Desktop\CNCNET CLIENT STUFF\xna-cncnet-client\DXMainClient\Online\Connection.cs:line 276
   at DTAClient.Online.Connection.ConnectToServer() in C:\Users\p\Desktop\CNCNET CLIENT STUFF\xna-cncnet-client\DXMainClient\Online\Connection.cs:line 204 
SadPencil commented 11 months ago
        private void HandleMessage(string message)
        {
            string msg = overMessage + message;
            overMessage = "";
            while (true)
            {
                int commandEndIndex = msg.IndexOf("\n");
                if (commandEndIndex == -1) whatever;
                else if (msg.Length != commandEndIndex + 1)
                {
                    // throw exception here? so commandEndIndex is 0?
                    string command = msg.Substring(0, commandEndIndex - 1);
SadPencil commented 11 months ago

Seems like HandleMessage(message) would fail when message ends up with "\n"

SadPencil commented 11 months ago
diff --git a/DXMainClient/Online/Connection.cs b/DXMainClient/Online/Connection.cs
index ba1341ba..f8e8c570 100644
--- a/DXMainClient/Online/Connection.cs
+++ b/DXMainClient/Online/Connection.cs
@@ -499,7 +499,7 @@ namespace DTAClient.Online
         /// <param name="message">The message.</param>
         private void HandleMessage(string message)
         {
-            string msg = overMessage + message;
+            string msg = overMessage + message.Trim();
             overMessage = "";
             while (true)
             {