PhlexPlexico / G5WS

Game Server Plugin for G5API
https://phlex.avidgamers.me
GNU General Public License v3.0
18 stars 8 forks source link

[BUG] Data Sent Before JSON Struct on Windows #21

Closed hoan111 closed 3 years ago

hoan111 commented 3 years ago

image

Hello! All functions of my G5V and G5API are working properly, except match stats. After I created and started the match, the stats didn't work. G5V only shows "No stats are found for the current match." when the match was stated. I also checked G5API to see if any update requests from my game server have been sent to G5API but none was sent. This is my debug log from my game server and get5_debuginfo. Game server: image

get5_debuginfo: https://pastebin.com/JpRrHRhC Thank you!

hoan111 commented 3 years ago

Currently, I'm using Nginx for webserver and reverse proxy.

PhlexPlexico commented 3 years ago

Hey! Just moving your issue over to G5API since it seems to be an issue with the API moreso than the front-end.

Are you able to get your logs from the API? If you're running production you should be able to go into the directory and type yarn pm2 logs G5API --lines 150. From what I can see, your API is working (navigating shows that it's working). The logs from the API are also located in ~/.pm2/logs if you want to browse the G5API-error.log and the other log file, you may be able to find out what exactly is going wrong.

Thanks!

PhlexPlexico commented 3 years ago

Also, what version of the API Plugin are you using on your game server? Just run sm plugins list and provide the version for the api_stats plugin.

Thanks!

hoan111 commented 3 years ago

First, I'm sorry for posting the issue in the wrong position! The main problem here is when I created a match using your G5V: https://phlex.avidgamers.me/ the playerstats was worked properly. I don't know why. This is my G5API error log: image

API plugin version: 2.0.2 PhlexPlexico version

kdev commented 3 years ago

You are trying to connect to a rcon server that does not exist

hoan111 commented 3 years ago

You are trying to connect to a rcon server that does not exist

Because of match stats not working so, G5V doesn't know when the match was finished. I turned off the game server before so it appeared that error.

PhlexPlexico commented 3 years ago

First, I'm sorry for posting the issue in the wrong position! The main problem here is when I created a match using your G5V: https://phlex.avidgamers.me/ the playerstats was worked properly. I don't know why. This is my G5API error log: image

API plugin version: 2.0.2 PhlexPlexico version

Did the same server work when you used the public API? Do you have RIPEXT installed on that server? I believe the extension is required in order to make the POST calls. If the game server isn't sending out the POST call (i.e. /api/match/10/map/0/player/.../update isn't being called on the API side, there may be some Windows firewall rules that you may have to adjust? I'm not sure, but I would take a stab at it being something network related that isn't allowing the call to go through.

I suppose the CallBack is only checking for internal server errors (5xx) as well: https://github.com/PhlexPlexico/get5-webapi/blob/e403387f7daebd7b55066d2b4ef9f8fb6c58b01e/scripting/get5_apistats.sp#L165-L173

So maybe it's unable to even contact the server. Do the vetoes go through as well? If it can only receive values (such as start match through RCON), and not send I feel that there may be a network issue there.

And it's no problem about putting it in the wrong repo, just was giving a heads up that it would be moved is all, just to avoid confusion :)

hoan111 commented 3 years ago

Yes, I used the same game server to contact with public API. And I'm sure that RIPEXT has been installed on my server. For the firewall part, I turned off Windows firewall on my game server and disabled iptables on the API server. Does the problem here come from my API config? Edit: The game server only receives rcon command from the API server.

hoan111 commented 3 years ago

production.json image

Nginx config: image

PhlexPlexico commented 3 years ago

For your nginx.conf maybe set it to your local IP, technically you don't need to have the API be public (i.e. you shouldn't be able to access http://g5api.ddns.net:3301 externally). So change that to your local IP instead of the DNS, that's the only difference I can see.

As for your json file... everything seems to be okay. I would maybe create a match and then just try using Postman and get the API key from the match and try updating stats by yourself as well. See if that works.

hoan111 commented 3 years ago

Hmmm. I changed my nginx.conf to my local IP (http://127.0.0.1:3301/) but it still not working.

PhlexPlexico commented 3 years ago

You could also try increasing the debug info for get5_debug and check the logs to see if it's being sent. If not, would you mind trying the latest (pending release) build of G5WS? G5WS.zip

hoan111 commented 3 years ago

I tried your new get5_apistats version but it still not working. I both checked Nginx access.log and G5API log while veto processing and I realize that no requests from the game server have been sent to Nginx while the debug from the game server said "Trying to create a request...." with no errors. I tried to make a manual veto update request to the API server ( using Postman) and it works. Also, I updated REST in PAWN extension but it still not working. Here is the log that I got from the game server while veto process, match start is the same, image

hoan111 commented 3 years ago

I don't know what causes the BUG because I used the same server to create a match from your public API, it worked. My own it didn't work. Edit: I changed my hostname to my domain. Currently, I'm using Cloudflare as DNS.

PhlexPlexico commented 3 years ago

Okay well let's take NGINX and Cloudflare out of the question. Unlike the old webpanel, G5API and the more up to date (latest build on get5 build actions (here)[https://github.com/splewis/get5/suites/2926842702/artifacts/65695247] can use just a public IP instead. This will remove any issues that NGINX or CloudFlare DNS could have.

1) We're going to run a development build of G5V, so first you need to stop your NGINX instance since you're running on port 8080. 2) In the G5V project, navigate to the vue.config.js file in the root of the project and change this line to your public IP https://github.com/PhlexPlexico/G5V/blob/cae3d7d46c423b3e833ae44b7582705b56bf1cb8/vue.config.js#L4 In your case it would be public: "http://10 3.98.15 2.22 8:8080", (without spaces of course) 3) Spin up the development build after saving that file. In that directory just run yarn serve and if you navigate to your IP address on port 8080, it should be living. To ensure the API is working as it should, just go to /api/matches and see if it loads (preferably in a private window/incognito, due to caching). 4) In your production.json file in G5API, you will also have to change your host and whatnot to your public IP that was listed above. and restart the API.

I've personally never used CloudFlare since I use Namecheap for domain/dns configs. So let's try and take out all of that and move back to basics and see if it works via direct IP connection.

Also, I noticed in the screenshot you gave me wasn't the plugin that I gave you above, since the debug is still outputting "get5_api" as its log name, and not "G5WS".

Thanks!

hoan111 commented 3 years ago

ok, this is the G5API log when I spin up the development server. In this case, G5API received requests from the game server to update stats but something goes wrong here. image image

the more up to date (latest build on get5 build actions (here)[https://github.com/splewis/get5/suites/2926842702/artifacts/65695247]

I also installed this get5 version ( this error still appear when I used my previous build )

Also, I noticed in the screenshot you gave me wasn't the plugin that I gave you above, since the debug is still outputting "get5_api" as its log name, and not "G5WS".

This "G5WS" plugin that you've sent to me is get5_apistats. Is it true? image

Thanks!

PhlexPlexico commented 3 years ago

The plugin I'm referencing is here

That one should be a different plugin at version 2.1.

So when you mean spin up the development server, you mean the front end specifically right? You should still be running the API per normal pm2 starting.

But it seems like the problem may rest in your connectionLimit. Up that to about 50 and give it a try and see if that works? You'll have to restart the API in order for those changes to take effect. But by the looks of it, it appears to being caught up on something during the calls. I would assume it would be a database connection, but that would also fail out and allow you to continue and provide a response time, not just 0ms.

hoan111 commented 3 years ago

ok. I used Wireshark to capture the packet that has been sent from the game server to the API server and it showed the error "400 bad request". So the problem here comes from the request that has been generated by theget5_apistats plugin, specifically by RIPEXT. I updated RIPEXT to the newest version (1.3.0). I'm trying to edit the request made by the get5_api plugin to a valid request. image

PhlexPlexico commented 3 years ago

If you try making the same request to the API it works in Postman I assume? I think I know what one of the issues is. In postman, use this exact URL with the trailing slash. image

And let me know if that call fails. I think this may be another issue that I had when trying to do URL downloads, and there may be a way to have NGINX strip that slash as well even with some rule magic.

hoan111 commented 3 years ago

Every request with the trailing slash is working in Postman. This is my request in Postman image Does get5_apistats need to change the way how it makes a request to the API server? Edit: Can you check the new version of RIPEXT? Does it affect the plugin? https://github.com/ErikMinekus/sm-ripext

PhlexPlexico commented 3 years ago

I was checking it and if you wouldn't mind using 1.2.3 we could see if there's an issue there. That being said, I've always used Linux servers as well, so I could also see this being a quirk of windows servers and how it interacts with cURL requests as well.

PhlexPlexico commented 3 years ago

Also, you shouldn't be using x-www-form-encoded when sending via postman, you should select "raw" and make sure it's JSON. That would directly emulate what's being done from G5WS. Like so: image

I currently do not have servers to test this, but in theory there wasn't anything I can see changed in 1.3.0 for ripext. The 400 error is being generated through the plugin though, since none of API calls return 400. It's always possible that it could be the OS that's causing issues? I'm unsure as I haven't tested on Windows servers for the game server.

hoan111 commented 3 years ago

I tried with RAW and it's still working. Also, I tried with sm-ripext version 1.2.3. It showed the same result

PhlexPlexico commented 3 years ago

Here, let me compile something with a bit more output on the game server response. Regardless of success or failure it should return something to the server console. One moment!

PhlexPlexico commented 3 years ago

G5WS.zip

There, this should provide some more insight as to why it's failing.

hoan111 commented 3 years ago

Thank you! I'll try and let you know

hoan111 commented 3 years ago

This is what I got. Still same before. And your G5WS plugin has an error. image image image

hoan111 commented 3 years ago

Edit: This is a valid request that has been made by Postman. image

PhlexPlexico commented 3 years ago

Seems to be erroring out when it's trying to get a value back on the callback. So I don't think it's hitting the server, since the server only returns JSON objects. There must be something up with the game server at this point. Are you able to test on a Linux server for the game server?

PhlexPlexico commented 3 years ago

And dumb question, but have you tried compiling G5WS on Windows as well to try and see if it works?

PhlexPlexico commented 3 years ago

G5WS.zip

Here's a G5WS that is compiled against windows, make sure you're using ripext if you have a windows gameserver as well and meet the requirements for it, too.

hoan111 commented 3 years ago

Seems to be erroring out when it's trying to get a value back on the callback. So I don't think it's hitting the server, since the server only returns JSON objects. There must be something up with the game server at this point. Are you able to test on a Linux server for the game server?

Yes. I can test on a Linux server. But I usually use Windows as game server because my public server is running Windows and I use it to host a tournament. I'll test on a linux server later

hoan111 commented 3 years ago

And dumb question, but have you tried compiling G5WS on Windows as well to try and see if it works?

You didn't send the G5WS.sp file so I can't complie it :D

PhlexPlexico commented 3 years ago

https://github.com/PhlexPlexico/get5-webapi/tree/utility-knife-dmg It's right here :)

But i've also compiled it above, here

hoan111 commented 3 years ago

image Now I got response "Not a correct API key"

PhlexPlexico commented 3 years ago

And in your wireshark capture it's the right key?

hoan111 commented 3 years ago

And in your wireshark capture it's the right key?

Yes. It's the right key

PhlexPlexico commented 3 years ago

G5WS.zip

Added in an API Key to print out on the server log when you veto. See what that outputs.

hoan111 commented 3 years ago

I already made that and complie :D and this is output I got image

PhlexPlexico commented 3 years ago

Okay so on the API. Right before this line: https://github.com/PhlexPlexico/G5API/blob/aaba7380256a92f390ddac183114e993ea55c32e/routes/legacy/api.js#L520

Just add in the following console.log("Our DB Key is: " + matchValues[0].api_key + " and gameserver sent: " + req.body.key);

For good measure, also do this: console.log(matchValues[0].api_key.localeCompare(req.body.key)) and let me know the output!

I think this may be a case where localeCompare is being thrown off because of OS differences. But we shall see :)

Make sure to restart the API after!

hoan111 commented 3 years ago

This is output I got image

hoan111 commented 3 years ago

I hope you can release a stable version for both Windows & Linux CSGO server. Thank for your hard work!

PhlexPlexico commented 3 years ago

Last thing to do, can you just output req.body as well and let me know what it outputs? I think it's just the windows game server not sending anything proper.

E: Are you also using NGINX/API on windows?

hoan111 commented 3 years ago

Last thing to do, can you just output req.body as well and let me know what it outputs? I think it's just the windows game server not sending anything proper.

E: Are you also using NGINX/API on windows?

Sorrry. I've just turned off my computer because too late and I feel sleepy. I'll test and let you know tomorrow :) At this time, I only use linux (Debian 10) for the API server and Windows (Sometime Linux) for the game server. I think I will not use Nginx/API on Windows in the future

PhlexPlexico commented 3 years ago

Oh hey, would you look at that. It seems to be an issue with RipExt. So I would think there may be an issue with RipExt right now.

https://forums.alliedmods.net/showpost.php?p=2749171&postcount=103

The related fix is here I think? https://github.com/ErikMinekus/sm-ripext/pull/51

It would make sense as to why you're not receiving anything in your body at least. If this is the reason, then you should be receiving data just fine after this is fixed...

As for right now, maybe just use the latest release of get5_apistats (or build from the master branch and make your debug statements) and use sm-ripext 1.2.3.

hoan111 commented 3 years ago

Oh hey, would you look at that. It seems to be an issue with RipExt. So I would think there may be an issue with RipExt right now.

https://forums.alliedmods.net/showpost.php?p=2749171&postcount=103

The related fix is here I think? ErikMinekus/sm-ripext#51

It would make sense as to why you're not receiving anything in your body at least. If this is the reason, then you should be receiving data just fine after this is fixed...

As for right now, maybe just use the latest release of get5_apistats (or build from the master branch and make your debug statements) and use sm-ripext 1.2.3.

Yes. I've read that comment in Ailledmodders but not search the fix yet :D So I told you to check the new version of RIPEXT if it affects to get5_apistats plugin. Thank you for finding the fix for me :D

As for right now, maybe just use the latest release of get5_apistats (or build from the master branch and make your debug statements) and use sm-ripext 1.2.3.

I'll try it and let you know. Thank!

hoan111 commented 3 years ago

UPDATE: I used the latest release of get5_apistats and use sm-ripext 1.2.3 but it's not working. I think I need to install the fix of sm-ripext 1.3.0 but I haven't known how to compile it yet...

hoan111 commented 3 years ago

UPDATE: I installed the fix of the sm-ripext 1.3.0, then both get5_apistats and G5WS not working ( sending an invalid request to G5API ). Edit: I'm trying with Linux CSGO server

hoan111 commented 3 years ago

UPDATE: Everything worked when I using Linux as a game server ( using the latest version of get5_apistats, sm-ripext version 1.2.3). Edit: sm-ripext 1.3.0 worked too. But I want it work on Windows :(

PhlexPlexico commented 3 years ago

So even with the same old plugins, is the API still picking up a blank body?