planetteamspeak / ts3phpframework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
https://www.planetteamspeak.com
GNU General Public License v3.0
211 stars 59 forks source link

serverquery questions #124

Closed Mickroz closed 4 years ago

Mickroz commented 5 years ago

Just updated to the latest, and i read (#106 ) that i can use client_name instead of nickname in the factory url so that the nickname is set before its visible to the server? I used to see this in my logs clientupdate client_nickname=Username, but now i don't see anything nickname related anymore. So which should is use? &nickname=, &client_name= or &client_nickname=?

same for teamspeak-servers.org, i used to see the ip address in the client_nickname, and then replace it with teamspeak-servers.org, now i only see Unknown or Unknown1 or Unknown2 as client_nickname, now it could be anyone connecting as a serverquery, any way to see the ip address of a serverquery client?

And is there anyway to logout the user running as a bot when there is a exception? When my bot chrashes, i doesn't restart for a while cause the user is still logged in, was hoping to fix that with that client_name adjustment.

ronindesign commented 5 years ago

Apologies for the long delay in responding here.

107 may also be of interest, which discusses this further.

You should be able to use &client_name=Username in the factory. I'm not exactly sure which logs you're referring to. If you mean the TS3 server logs, I would think this makes sense as the nickname is updated before the client connects to the virtual server, but I could be mistaken.

If you're referring to the server query client's log, it's possible the logging was not updated when the functionality was reworked, and this could very well be a bug.

As long as you have ServerQuery view enabled on a server for your client, you should always be able to see the client's IP.

Yes, the client hanging is a common issue that needs to be handled correctly. The client can stay connected up to a maximum of the "keepalive" time for clients before it times out. If you can catch your exceptions, you should be able to call the shutdown / disconnect logic and get the client to quit the server gracefully before exiting. Additionally, I would agree with your approach, you should be able to change the client name to something different on crash, so that the new client can connect with a new name, this is how I've handled this in the past as well (at least for testing purposes.)

Mickroz commented 5 years ago

np, i read that first, before posting this.

I'm referring to the *_1.log files which says issued: clientupdate client_nickname=Username. If i use &client_name=Username it would start a lot of new bots and just add a number to the nickname, for example i had 26 bots running all with nickname Bot1 to Bot26.

I don't want to view the ip with the client, but with my bot script, so i can rename them properly, im getting serverquery connections from unknown ip wich issue query from 595 195.154.79.24:669 issued: /* this crashes the server, so i want to block them on connect.

in the past the ip address was given in the nickname so i could check it like:

if ($event->offsetGet('client_type') == 1)
{
    $client_nickname = $event->offsetGet('client_nickname');
    if (strpos($client_nickname, '37.187.252.194') !== false)
    {
        $client_nickname = str_replace("Unknown", "teamspeak-server.org", $client_nickname);
    }
    echo udate('Y-m-d H:i:s:u') . "\t[INFO]\tQueryClient connected from " . $client_nickname . "\n";
    return;
}

what is the maximum of the keepalive time? i see it connects again after an hour or more sometimes. this is from my bot log:

2019-05-21 23:00:02:300351      [SIG]   connected to TeamSpeak 3 Server on myserver
2019-05-21 23:00:02:301589      [INFO]  server is running with version 3.7.1 on Linux
2019-05-21 23:00:02:305258      [SIG]   authenticated as user serveradmin
2019-05-21 23:00:02:309173      [SIG]   selected virtual server with ID 1
2019-05-21 23:00:12:321488      [SIG]   no reply from the server for 10 seconds
2019-05-21 23:00:22:331479      [SIG]   no reply from the server for 20 seconds
2019-05-21 23:00:32:341465      [SIG]   no reply from the server for 30 seconds
2019-05-21 23:00:42:351467      [SIG]   no reply from the server for 40 seconds
2019-05-21 23:00:52:361492      [SIG]   no reply from the server for 50 seconds
2019-05-21 23:01:02:374489      [SIG]   connected to TeamSpeak 3 Server on myserver
2019-05-21 23:01:02:375604      [INFO]  server is running with version 3.7.1 on Linux
2019-05-21 23:01:02:379247      [SIG]   authenticated as user serveradmin
2019-05-21 23:01:02:382121      [ERROR] 513: nickname is already in use on line 316 in /home/teamspeak/index_html/libraries/TeamSpeak3/Adapter/ServerQuery/Reply.php
2019-05-21 23:01:02:221034      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:01:02:221414      [INFO]  QueryClient connected from serveradmin1
2019-05-21 23:01:02:221729      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:01:02:222135      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:01:02:381658      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:01:12:392511      [SIG]   no reply from the server for 10 seconds
2019-05-21 23:01:15:127716      [INFO]  QueryClient connected from Unknown
2019-05-21 23:01:15:141755      [INFO]  QueryClient connected from Unknown1
2019-05-21 23:01:15:153013      [INFO]  QueryClient connected from Unknown2
2019-05-21 23:01:27:153488      [SIG]   no reply from the server for 10 seconds
2019-05-21 23:01:37:163483      [SIG]   no reply from the server for 20 seconds
2019-05-21 23:01:47:173500      [SIG]   no reply from the server for 30 seconds
2019-05-21 23:01:57:183484      [SIG]   no reply from the server for 40 seconds
2019-05-21 23:02:02:225787      [SIG]   connected to TeamSpeak 3 Server on myserver
2019-05-21 23:02:02:226850      [INFO]  server is running with version 3.7.1 on Linux
2019-05-21 23:02:02:230347      [SIG]   authenticated as user serveradmin
2019-05-21 23:02:02:233056      [ERROR] 513: nickname is already in use on line 316 in /home/teamspeak/index_html/libraries/TeamSpeak3/Adapter/ServerQuery/Reply.php
2019-05-21 23:02:01:869658      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:02:01:897644      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:02:01:906134      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:02:01:917820      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:02:02:232374      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:02:12:386511      [SIG]   no reply from the server for 10 seconds
2019-05-21 23:02:22:396477      [SIG]   no reply from the server for 20 seconds
2019-05-21 23:02:32:406493      [SIG]   no reply from the server for 30 seconds
2019-05-21 23:02:42:416476      [SIG]   no reply from the server for 40 seconds
2019-05-21 23:02:52:426508      [SIG]   no reply from the server for 50 seconds
2019-05-21 23:03:02:991829      [SIG]   connected to TeamSpeak 3 Server on myserver
2019-05-21 23:03:02:992973      [INFO]  server is running with version 3.7.1 on Linux
2019-05-21 23:03:02:996596      [SIG]   authenticated as user serveradmin
2019-05-21 23:03:02:999316      [ERROR] 513: nickname is already in use on line 316 in /home/teamspeak/index_html/libraries/TeamSpeak3/Adapter/ServerQuery/Reply.php
2019-05-21 23:03:02:436457      [SIG]   no reply from the server for 60 seconds
2019-05-21 23:03:02:536843      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:03:02:549147      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:03:02:830503      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:03:02:830896      [INFO]  QueryClient connected from serveradmin1
2019-05-21 23:03:02:839016      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:03:02:998620      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:03:13:9468        [SIG]   no reply from the server for 10 seconds
2019-05-21 23:03:23:19461       [SIG]   no reply from the server for 20 seconds
2019-05-21 23:03:33:29454       [SIG]   no reply from the server for 30 seconds
2019-05-21 23:03:43:39486       [SIG]   no reply from the server for 40 seconds
2019-05-21 23:03:53:49547       [SIG]   no reply from the server for 50 seconds
2019-05-21 23:04:01:610052      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:04:01:616807      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:04:01:685545      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:04:01:687266      [INFO]  QueryClient connected from serveradmin1
2019-05-21 23:04:01:705076      [INFO]  QueryClient connected from serveradmin
2019-05-21 23:14:02:191608      [SIG]   connected to TeamSpeak 3 Server on myserver

After an hour, it stays connected.

Now im killing my bot process every night to get small log files using screen, can i monitor the php timestamp to log the bot out before restarting my bot? And how would i approach this?

ronindesign commented 4 years ago

Not sure if you're still having issues with this, I realize it's been a long while.

They may have changed how the server logs, but otherwise, if a query client connects with a username, you won't see the IP in the log. The IP you usually see is just the generic default username given to the query client if no nickname is set before connecting.

According to the TS3 ServerQuery Manual, client properties include CONNECTION_CLIENT_IP. I'm not sure if you're able to get client properties for query clients, but if you can then I would think the IP would be listed there.

Last I checked, the default timeout for server query connections was 10 minutes [ref]

I suppose you could monitor the log or set a timing variable like $lastLoginCycleTimestamp and then check how long it's been since that timestamp, and before it reaches 10 minutes, do a logout and then restart the bot.

Mickroz commented 4 years ago

Thanks, still have problems with it, so i will check the connection_client_ip. I only have the problem still that it doesn't let me connect for an hour after i kill the script. Maybe i can change it so that i kill it from within the script instead of via cron.

ronindesign commented 4 years ago

Yeah, it seems like maybe your bot isn't fully disconnected or something. The server definitely shouldn't be stopping connection for an hour. Maybe add some tests / checkpoints and logging into your bot so you know where it's hanging. Then build in a few checks for hanging in the loop that auto kill / disconnect itself.

If you host your code somewhere like in a repo or gist or something I can take a closer look when I have a free moment.

ronindesign commented 4 years ago

Closing this due to inactivity, let me know if you're still having trouble and we can revisit this.

Mickroz commented 4 years ago

Kinda forgot about this, and my server isn't that busy that its a problem, will try the new version and see if i can get a repo up with my code.