Spksh/TentacleSoftware.TeamSpeakQuery

invalid host detecting

Jimmy062006 opened this issue · 8 comments

How are you supposed to detect if the port or hostname was entered incorrectly ? currently my task ends on the await client.Initialize(); section with no error anywhere

Spksh commented

Does the object returned by await client.Initialize(); have its Success property set to true, or is the entire object null?

Are you connecting to the TS3 server's ServerQuery port (this is 10011 by default)? You can't connect to the normal TS3 voice port.

The telnet client writes out to Trace, so if you run inside VS or attach a Trace listener you should see more verbose messaging.

Spksh commented

Ah, this is for https://github.com/Jimmy062006/Opux, right? You're looking for an exception or failure message.

Currently, the initialize task won't complete if it doesn't see the correct header and welcome message back from the server.

Problem code is in ServerQueryClient.cs:

        public Task<ServerQueryBaseResult> Initialize(Action<TelnetClient> connect)
        {
            bool headerReceived = false;
            bool welcomeReceived = false;

            return SendCommandAsync(connect, message =>
            {
                if (message.Equals("TS3", StringComparison.InvariantCultureIgnoreCase))
                {
                    headerReceived = true;
                }

                if (message.StartsWith("Welcome to the TeamSpeak 3 ServerQuery interface", StringComparison.InvariantCultureIgnoreCase))
                {
                    welcomeReceived = true;
                }

                if (headerReceived && welcomeReceived)
                {
                    return new ServerQueryBaseResult(true);
                }

                return null;
            });
        }

Returning null tells the command processing logic to keep waiting for the next message, so we don't want to change that. And if I recall correctly, we get a few interstitial messages as well.

What we probably want to do is throw an exception if we don't get the all the expected messages in the expected order.

I can use it fine its not a connection issue. I created the issue on purpose to simulate it. The object is never returned.

I'll download the github source and debug it as currently I'm using nuget version.

Spksh commented

Yeah, that's a "bug", kind of. Really it's an issue with the architecture of the way we're waiting for messages.

If we don't connect to a listening telnet endpoint at all, the telnet client should throw an exception (eventually, after a timeout). If we do connect to a telnet endpoint and get back an unexpected message, the ServerQueryClient is going to wait forever and cause this problem.

However, I didn't do any work in this library to handle retries or timeouts at all. Fixing this particular bug (where we don't receive the messages we expect) won't change that.

It might be a better idea for you as the consumer of the library to handle timeouts at your application layer. e.g. some kind of task timeout wrapper like the answers in https://stackoverflow.com/questions/4238345/asynchronously-wait-for-taskt-to-complete-with-timeout

I used a port that was firewalle'd and has nothing running on it. I left it for 10 mins with no timeout. I will download debug and try and see whats going on.

I've no issue handling them but they never happen.

Spksh commented

Cool. Source for the telnet client is https://github.com/Spksh/TentacleSoftware.Telnet if you need to go that deep.