CynCeyd / TS3BridgeTTT

A simple bridge between TeamSpeak 3 and GMod TTT
GNU General Public License v3.0
6 stars 6 forks source link

"Your api key is invalid." #11

Open Fargope opened 3 years ago

Fargope commented 3 years ago

I'm having an issue with the plugin validating the API key for the server. I've tried leaving the key as the default "abc" value, and setting my own custom one. I've verified that the key matches both the TS3Bridge.php file in the webserver, and the convar set in server.cfg on the Gmod Server. When I run the convar in the server console, it's spitting out the correct value, in this case "abc" I've also tried uninstalling the workshop addon and manually inserting ts3bridge.lua in the autorun folder for the server.

I've tried manually running the php file on the webserver and this is the error I'm getting.

Warning: Undefined variable $apiKey in C:\xampp\htdocs\TS3Bridge.php on line 397 Your api key is invalid.

I've gone and looked at line 397 and it's above my level of coding, but I can't see anything that would be causing an issue.

CynCeyd commented 3 years ago

That particular issue at that position in the code will occur if the key wasn't passed as a query parameter to the .php file. Could have handled that scenario better to be more precise on whats the issue.

For why it's occuring I'm not quite sure right now. I'll try to have a look tomorrow. What might be the problem is that I basically re-wrote the whole addon a year or two ago and haven't had the time to update the Steam plugin unfortunately.

I'm not quite sure which ts3bridge.lua you have manually added - was it the one in the GitHub repository? If you extracted it from the old Steam plugin there might be an incompatibility between my rewritten version and the previous one.

If you haven't already, please try to use the ts3bridge.lua from the GitHub repository. If you already did this, please let me know and I'll try to have a look into it as soon as I have some spare time.

Greetings

Fargope commented 3 years ago

Yeah I tried the one from the GitHub, I saw you mention that in another issue. I appreciate you looking into it for me!

CynCeyd commented 3 years ago

Alright, let's have a look into this.

You'll receive the error message when you manually open the url and do not add the key for auth. E.g. you call https://domain.tld/ts3bridge.php in your browser. Since ts3bridge.php expects a key (e.g. https://domain.tld/ts3bridge.php?key=abc), it will cause the error you received, if you didn't supply ?key=abc.

In the ts3bridge.php please change define("DEBUG_MODE", false); to define("DEBUG_MODE", true); temporarily. This will generate some debug output and store it in a file on the webserver, whenever the a request to the file is made.

May I ask what your setup is? You seem to use XAMPP as a webserver. Are you hosting both the web server and the GMod server locally?

Fargope commented 3 years ago

Forgive me, I'm new to XAMPP and webservers in general. I've enabled debug mode, but I can't seem to find where the file is being generated. I tried searching the XAMPP directory for "log" and "debug" but the only things being created are for apache and MySql. What should I be looking for?

Currently I have the GMOD server hosted on my main pc, and the XAMPP webserver hosted on my dedicated server box. It's all on the same network. The dedicated server has a static ip while my pc has a dynamic ip, but the correct ports should be forwarded for GMOD.

As far as the webserver goes, I'm able to access it from outside my network so that's not the issue.

CynCeyd commented 3 years ago

No worries. The debug log should be created within the same directory as the ts3bridge.php file. It will only create the log when requests are made and the directory is writable, though.

Is there any firewall inbetween that might interfere? Could you try to call the ts3bridge.php with ?key=abc at the end of the url (abc being the key you specified at the top of the php file), please?

That should allow you to call the api manually from your browser and generate a log file.

Are there any errors shown within GMod?

Fargope commented 3 years ago

So I ran both the GMOD server, and my apache webserver via XAMPP, used "http://192.XXX.X.XXX:XXXX/ts3bridge.php?key=abc" and got: Warning: Undefined variable $action in C:\xampp\htdocs\TS3Bridge.php on line 408 Your requested action does not exist.

No log file was generated in C:\xampp\htdocs which is where the ts3bridge.php file is located. There are no references to your plugin at all in my gmod console during all this, unless I check the bridge link and the api key using the console.

Is it possible I messed something up with the webserver? I can access it from both computers on my network, and out of my network. Theres no firewall that should be in the way as far as I know, but I suppose I could try hosting the XAMPP server on the same machine as the gmod server?

CynCeyd commented 3 years ago

Alright, that error is actually fine. We just didn't supply the action parameter.

If no log file is generated with DEBUG_MODE true, the script probably doesn't have write permissions for that folder. You could probably try to add write permissions to that folder, but let's try something easier for now.

Please also change define("ALLOW_DEBUG_IN_RESPONSE", false); to define("ALLOW_DEBUG_IN_RESPONSE", true);. This will allow the debug data to be displayed, whenever you manually call the api in your browser.

My first goal would be to find out whether the .lua plugin or the ts3bridge.php (or both) make trouble here. I would suggest you try to call the ts3bridge.php fully parameterized and actually do the same thing the .lua plugin would for us. If everything works calling the api manually, we should take a look into the .lua file, if not, there's probably something going on in the .php file.

Please call the api as follows: "http://192.XXX.X.XXX:XXXX/ts3bridge.php?key=abc&steamID=[steamID]&ip_address=[ip_address]&user_name=[user_name]&action=[action]", where:

[action] can be replaced by anything in this array: private $_allowedMethods = array( "connect", "disconnect", "mute", "unmute", "unmute_all", "_unlink", "show", "request", "activate", "version" );

For testing I would recommend trying connect, disconnect, mute, unmute and maybe version. Please try some of these actions and check if anything happens to you on the TeamSpeak server. Connect should move you to the correct channel, disconnect should usually kick you back out, mute & unmute are pretty self-explanatory I guess.

I currently don't really think this has something to do with a messed up web server configuration. Feel free to test it though, definitely doesn't hurt.

Fargope commented 3 years ago

Ok somethings happening... It seems like it can't link me to my steam id and ip. The webserver throws this error when I enter any of the action commands (connect, disconnect, mute etc) Just so were all on the same page, here's the url I was entering.

"http://192.168.X.XXX:XXXX/ts3bridge.php?key=abc&steamID=76561198062816762&ip_address=192.168.X.XXX&user_name=Juice&action=connect"

ip_address=the ipv4 of my machine that's running my GMOD client, and Teamspeak client. The GMOD server is being run off the same ipv4, the teamspeak server is not.

Fatal error: Uncaught Error: Undefined constant "TEAMSPEAK_CONNECTION_PARAMS" in C:\xampp\htdocs\TS3Bridge.php:336 Stack trace: #0 C:\xampp\htdocs\TS3Bridge.php(521): TS3Bridge->getTeamSpeakClient('765611980628167...', '0.0.0.0', 'Juice') #1 C:\xampp\htdocs\TS3Bridge.php(410): TS3Bridge->mute(Array) #2 C:\xampp\htdocs\TS3Bridge.php(759): TS3Bridge->handleRequest() #3 {main} thrown in C:\xampp\htdocs\TS3Bridge.php on line 336

I also have a log file now being generated. I'll paste the contents below:

[2021-10-09T17:52:44+02:00] There have been 0 users with the same ip for user Juice using the ip address 192.168.X.XXX and Steam id 76561198062816762. [2021-10-09T17:52:52+02:00] There have been 0 users with the same ip for user Juice using the ip address 192.168.X.XXX and Steam id 76561198062816762. [2021-10-09T17:53:14+02:00] There have been 0 users with the same ip for user Juice using the ip address 192.168.X.XXX and Steam id 76561198062816762. [2021-10-09T17:54:58+02:00] There have been 0 users with the same ip for user Juice using the ip address 192.168.X.XXX and Steam id 76561198062816762.

The ip being logged here is my local machine's ipv4, and the same one I used in the URL.

/edit: I redacted your public ip address for privacy.

CynCeyd commented 3 years ago

Would the log file also generate output when you try to use the plugin in GMod?

It seems like I was somewhat tired when I wrote the TS3Bridge.php. There definitely were some bugs causing this problem. I fixed them and updated the file in the GitHub repository. Please download it again and test with this new updated file.

Furthermore what might be an issue: There are two main ways for this script to automatically link users. The first would be by using your ip address. This might not work with your current setup, because you are using a local ip addresses.

If you take a look into the error message, you'll see that getTeamSpeakClient is called using a public ip address. I'm not sure if this will only occur when you call the script manually, since I don't know what ip address GMod is using by default.

This might cause GMod and TeamSpeak to use different ip addresses (say GMod uses your external ip and TeamSpeak your local ip), meaning the script cannot automatically compare both successfully.

The other method for automatic linking is using the TeamSpeak and Steam Display Name. If both of these match by a percentage (default 90%) an automatic link will be established. If the names used on these differ to much, this might also cause an issue.

If this continues to be a problem using your setup, you could also write a manual link in the json file. Please try to update the script first, though. While these issues might occur, the script actually could not have worked with these bugs.

Fargope commented 3 years ago

If you mean being in the server while calling commands via the webserver, I made sure I was.

I'll download and test the new php in a bit here and let you know the results!

Both my TS3 name and Steam name are the same, so it should be able to pick me up.

Fargope commented 3 years ago

Here's the new log.txt
The only edit I made was redacting the ipv4

log.txt

CynCeyd commented 3 years ago

That's great, we're progressing.

It says invalid channelID in the error message, which means the TeamSpeak PHP framework probably can't find the channel or lacks permission to look for it.

Does a channel called "Trouble in Terrorist Town" exist on the server and does the server query account have sufficient permissions?

Fargope commented 3 years ago

Yeah that's my mistake. On the old php file I changed the server to TTT instead of Trouble in Terrorist Town and forgot to change it with the new php file... oops!

Either way, that works! The plugin moves me, unmutes, mutes and kicks while running the commands through the web server.

I hopped in game and can't get it to work automatically. I presume it's because the api key still isn't valid for some reason?

CynCeyd commented 3 years ago

Does the api key you put into the server.cfg match the one in the ts3bridge.php?

When you try to use the GMod server, does anything new appear in the log file? Are there any error messages in the GMod console? Is GMod correctly parametrized? (E.g. is the url correct and is the GMod server able to connect to the web server)

Fargope commented 3 years ago

The API is still the default "abc" on both

I tried joining the server, and nothing appeared in the log file. The only error was in the console. The Bridge url in server.cfg is "http://192.168.X.XXX:XXXX/TS3Bridge.php" and when I click on the link it takes me to the webserver giving the "invalid api" error. When I run "ttt_ts3_bridge_url" in console it spits out the correct link.

I tried joining the server, and nothing appeared in the log file. The only error was in the console. When I join the Gmod server now I get a "ServerLog: [TS3 Bridge TTT] HTTP request failed: invalid url" error in console. I'm using the correct link right? ttt_ts3_bridge_url in the server.cfg is supposed to be pointing to the TS3Bridge.php file right?

And just for laughs I tried disabling my firewall on both machines, but it didnt change anything.

CynCeyd commented 3 years ago

Yes, that's the way it should be. The error means the lua script cannot execute the http request for some reason, probably some part of the url is malformed.

Could you add in line 157 of the .lua file log(encoded_url) please? That should print the url into the GMod console. It would be great if you could tell me what the output url will be, so we can have a look into that.

Fargope commented 3 years ago

Here's what I got:

ServerLog: [TS3 Bridge TTT] http://192.168.X.XXX:XXXX/TS3Bridge.php?key=abc&action=version ServerLog: [TS3 Bridge TTT] HTTP request failed: invalid url

CynCeyd commented 3 years ago

It seems like local http requesrs are disabled by default in GMod: https://wiki.facepunch.com/gmod/http.Fetch

To allow the local requests you need to start the server with the -allowlocalhttp command line parameter.

Fargope commented 3 years ago

That worked! ...kind of

The initial load in will move me and grant talk power, but thats where it ends. I wasn't ever muted on death, and when I had a friend join they were neither moved or granted talk power. We tried disconnecting and reconnecting neither of us were moved. I restarted the gmod server and apache server with no change, and then the gmod server, apache server, and ts server. After rejoining, I was moved by my friend was not, and then it stopped functioning all together like before.

Looking at the server console, it looks like it found my friend's IP and steam ID, but the commands didnt work for some reason. server console.txt

Here's the log log.txt

CynCeyd commented 3 years ago

From what I can see in the log.txt, the TS3Bridge.php TeamSpeak Client has been banned for flooding. Thats pretty normal, as the rate limit for this is very low.

You need to add the webserver ip address to the query_ip_whitelist file in the TeamSpeak server folder and restart afterwards.

Fargope commented 3 years ago

That did it! Initially it was only working for me, but after a few rounds it started working for my friend too. I'm assuming it may have taken a few minutes for the plugin to match his player info or something? In the future if it's not working for one person, how can I input their info to the plugin? I tried looking for links.json but came up short.

Thank you so much for your help by the way, do you have a paypal or venmo I could use to buy you a coffee?

CynCeyd commented 3 years ago

If USE_LINK_CACHE is set to true a file called LinkCache.json should be created in the same directory as the TS3Bridge.php. Any automatic assignments would be stored here, but you can also manually enter assignments.

The content should be built like this: { "[steamID_1]": "[teamSpeakUid_1]", "[steamID_2]": "[teamSpeakUid_2]", "[steamID_3]": "[teamSpeakUid_3]" }

.. and so on (no square brackets). The Steam ID can be acquired on e.g. steamidfinder.com (you need to use the SteamID, not SteamID64; what you need looks like this: STEAM_0:0:11101). The TeamSpeak Unique ID can be acquired from the Identities window in TeamSpeak itself.

Does the LinkCache.json exist? If not you might need to edit some permissions, but I guess when the log file is created, this shouldn't be too much of a problem.

You're very welcome. That's very generous of you, but no, unfortunately I don't. If you'd like to though, I would be very grateful if you donated a coffee to a charity of your choice ;-).

Fargope commented 3 years ago

Yes LinkCache.json has been generated, and it appears to be working, though I've only been able to test with one other person. For now I'll just assume it works until I can get a larger group together to test, and if we run into more issues I'll let you know!

Thanks again for the help, and I'll do that in your name :)

Fargope commented 2 years ago

Hey there, I'm back :(

Tonight we had our first real test of the plugin and ran into a couple of issues. Some of them aren't a big deal but for whatever reason after the third map change the plugin stops working. After changing maps, the console says "ServerLog: [TS3 Bridge TTT] Loading TeamSpeak 3 bridge" and then never loads hooks like it normally does. It always works on the first map when we load in, it works on the second map after a change, but it always fails to work on the third map. Any ideas?

Edit: It seems like it it will reinitialize hooks once someone joins the server. Its a bandaid fix but it would be nice if it worked like intended.

CynCeyd commented 2 years ago

Hi there,

yes, I think I know what might cause this issue. @Creyox has kindly submitted some bug fixes a while ago. One of the modifications was to initialize the .lua file only once.

While this modification definitely made the code cleaner and reduced some overhead I was previously generating, the initialization is now dependent on a user joining. This wouldn't cause a problem when you first connect to the server, since the script would definitely get initialized, but I guess the map change unloads the hooks and makes a reinitialization necessary.

I will take a look into this and create a fix.

CynCeyd commented 2 years ago

Would you be so kind and test whether this fix #13 works for you?

Shortcut to the changed file.

Fargope commented 2 years ago

I replaced the old ts3bridge.lua and now the only thing I get in console is the "ServerLog: [TS3 Bridge TTT] Loading TeamSpeak 3 bridge" and nothing seems to happen.

When calling the api using "http://192.168.X.XXX:XXXX/ts3bridge.php?key=abc&steamID=76561198062816762&ip_address=192.168.X.XXX&user_name=Juice&action=connect" I dont get anything either.

And just to make sure I'm using the correct file, it was updated on the main page? When going to the link you provided I didn't see any way to download the ts3bridge.lua It seems like the one I downloaded has the changes you made but I just want to be 100% sure

Fargope commented 2 years ago

I went back and found an error I made. The new version is working perfectly!