SoftwareGuy / NodeListServer

Node List Server is a multi-purpose server list system. NodeJS powered and supports Docker.
Other
92 stars 33 forks source link

Can't register more than one server instance #23

Open AbdelNabut opened 2 years ago

AbdelNabut commented 2 years ago

Hi, I have 3 separate VPS's each acting as it's own separate server. I'm trying to use NodeListServer to display the player count for each of those servers, however I am getting a 400 error whenever I try to register a second server. First registers just fine. Is this by design? A limitation, bug? Or am I doing something incorrectly?

SoftwareGuy commented 2 years ago

Definitely not a limitation, might be a bug.

For each other server you are attempting to add, are you using a unique port? Say your server is at 10.0.0.100:31337. NodeLS will happily accept that. However, should server number 2 try to register that same address again, it will fail and spit back bad request. However, if your 2nd server is running on the same IP address but different port, then it should be accepted. Unless there's a bug in the code.

Can you please provide me with a snippet of the code that you're using to register the servers with? Also, what branch are you working with? Master branch or gen3?

AbdelNabut commented 2 years ago

Each server is using the same port, but they're on their own VPS's with their own addresses. For example, I have one of my worlds running on 66.29.157.140:7777, another one on 199.192.28.92:7777, and the third on 199.192.29.9:7777. Yeah they all use the same port 7777, but that should be fine with servers on different addresses, shouldn't it?

Also, my nodeLS is running on my first VPS (66.29.157.140:8889/list) alongside my first game world. I'm using the example package located here: https://github.com/SoftwareGuy/NodeListServer-Example

which uses this method to add servers:

private IEnumerator AddUpdateInternal()
        {
            WWWForm serverData = new WWWForm();
            print("NodeLS Communication Manager: Adding/Updating Server Entry");

            serverData.AddField("serverKey", AuthKey);

            serverData.AddField("serverUuid", InstanceServerId);
            serverData.AddField("serverName", CurrentServerInfo.Name);
            serverData.AddField("serverPort", CurrentServerInfo.Port);
            serverData.AddField("serverPlayers", CurrentServerInfo.PlayerCount);
            serverData.AddField("serverCapacity", CurrentServerInfo.PlayerCapacity);
            serverData.AddField("serverExtras", CurrentServerInfo.ExtraInformation);

            using (UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Post(Server + "/add", serverData))
            {
                yield return www.SendWebRequest();

                if (www.responseCode == 200)
                {
                    print("Successfully registered server with the NodeListServer instance!");
                }
                else
                {
                    Debug.LogError($"Failed to register the server with the NodeListServer instance: {www.error}");
                }
            }

            yield break;
        }
SoftwareGuy commented 2 years ago

Each server is using the same port, but they're on their own VPS's with their own addresses. For example, I have one of my worlds running on 66.29.157.140:7777, another one on 199.192.28.92:7777, and the third on 199.192.29.9:7777. Yeah they all use the same port 7777, but that should be fine with servers on different addresses, shouldn't it?

Okay, that should be supported; as long as either the IP or Port is unique (like in your case) then it should be fine.

Also, my nodeLS is running on my first VPS (66.29.157.140:8889/list) alongside my first game world. I'm using the example package located here: https://github.com/SoftwareGuy/NodeListServer-Example

which uses this method to add servers:

private IEnumerator AddUpdateInternal()
        {
            WWWForm serverData = new WWWForm();
            print("NodeLS Communication Manager: Adding/Updating Server Entry");

            serverData.AddField("serverKey", AuthKey);

            serverData.AddField("serverUuid", InstanceServerId);
            serverData.AddField("serverName", CurrentServerInfo.Name);
            serverData.AddField("serverPort", CurrentServerInfo.Port);
            serverData.AddField("serverPlayers", CurrentServerInfo.PlayerCount);
            serverData.AddField("serverCapacity", CurrentServerInfo.PlayerCapacity);
            serverData.AddField("serverExtras", CurrentServerInfo.ExtraInformation);

            using (UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Post(Server + "/add", serverData))
            {
                yield return www.SendWebRequest();

                if (www.responseCode == 200)
                {
                    print("Successfully registered server with the NodeListServer instance!");
                }
                else
                {
                    Debug.LogError($"Failed to register the server with the NodeListServer instance: {www.error}");
                }
            }

            yield break;
        }

I'm going to spin up a copy of virgin NodeLS Gen2 since my development copy is heavily tainted with experimental code and is also customized for my own shooter title and use curl to try to emulate this bug. NodeLS is publically exposed, no nginx reverse proxying or anything is being used, correct?

Labelling as a bug for now. Will update as I investigate further.

SoftwareGuy commented 2 years ago

Ahh - one thing I just found, is if the server exists already by name, then it'll reject that too. That might be part of the issue.

Lines 342 - 345 are responsible for that. At the moment my servers have a static string with a random number attached to the end of them, so when they boot and register they will say like "Game Server Instance 69", etc.

AbdelNabut commented 2 years ago

Each server is using the same port, but they're on their own VPS's with their own addresses. For example, I have one of my worlds running on 66.29.157.140:7777, another one on 199.192.28.92:7777, and the third on 199.192.29.9:7777. Yeah they all use the same port 7777, but that should be fine with servers on different addresses, shouldn't it?

Okay, that should be supported; as long as either the IP or Port is unique (like in your case) then it should be fine.

Also, my nodeLS is running on my first VPS (66.29.157.140:8889/list) alongside my first game world. I'm using the example package located here: https://github.com/SoftwareGuy/NodeListServer-Example which uses this method to add servers:

private IEnumerator AddUpdateInternal()
        {
            WWWForm serverData = new WWWForm();
            print("NodeLS Communication Manager: Adding/Updating Server Entry");

            serverData.AddField("serverKey", AuthKey);

            serverData.AddField("serverUuid", InstanceServerId);
            serverData.AddField("serverName", CurrentServerInfo.Name);
            serverData.AddField("serverPort", CurrentServerInfo.Port);
            serverData.AddField("serverPlayers", CurrentServerInfo.PlayerCount);
            serverData.AddField("serverCapacity", CurrentServerInfo.PlayerCapacity);
            serverData.AddField("serverExtras", CurrentServerInfo.ExtraInformation);

            using (UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Post(Server + "/add", serverData))
            {
                yield return www.SendWebRequest();

                if (www.responseCode == 200)
                {
                    print("Successfully registered server with the NodeListServer instance!");
                }
                else
                {
                    Debug.LogError($"Failed to register the server with the NodeListServer instance: {www.error}");
                }
            }

            yield break;
        }

I'm going to spin up a copy of virgin NodeLS Gen2 since my development copy is heavily tainted with experimental code and is also customized for my own shooter title and use curl to try to emulate this bug. NodeLS is publically exposed, no nginx reverse proxying or anything is being used, correct?

Labelling as a bug for now. Will update as I investigate further.

Yep, as far as I know there is no reverse proxying going on and yes NodeLS is publicly exposed. I can curl it just fine and return JSON just fine. Seems the only issue is registering servers after the first.

AbdelNabut commented 2 years ago

Ahh - one thing I just found, is if the server exists already by name, then it'll reject that too. That might be part of the issue.

Lines 342 - 345 are responsible for that. At the moment my servers have a static string with a random number attached to the end of them, so when they boot and register they will say like "Game Server Instance 69", etc.

Wonderful, that was a quick find! Sure hope it's the only thing causing the 400 error :)

SoftwareGuy commented 2 years ago

Shit, I just realized some stuff is outdated in the example NodeLS repository too.

I'll finish investigating this issue first and then I'll go about updating the example repository.

SoftwareGuy commented 2 years ago

Crap. The rabbit hole goes deeper than I was hoping for.

I'm gonna have to some surgery - this has actually revealed a glaring flaw in my logic handling.

SoftwareGuy commented 2 years ago

Okay, so I think I fixed the issue. I have to merge the branch into master, but the current fixes are in the fixing-allthethings branch. Tomorrow I will be updating the example project code.

AbdelNabut commented 2 years ago

Hahaha I had quite a bit of laughs over this, thanks for that :') Glad you were able to clean up and revise your code and fix the issue! Looking forward to the new build 👍🏻

AbdelNabut commented 2 years ago

@SoftwareGuy Hey! Did you manage to push the latest build?

SoftwareGuy commented 2 years ago

It's merged in master. Please give it a shot, there's also a new configuration file parameter that you must set if you want servers with the same name to be accepted. I also fixed an issue regarding the UUID it sends back, it sent back a wrong string instead of the UUID.

You'll need Node 16 or higher, as it's now using in-line if checks. Node 12 will fail with a syntax error.

AbdelNabut commented 2 years ago

When running "node serverList.js", I see it responded to my servers:

[2022-02-20T21:50:01.620] [INFO] NodeLS - Replying to ::ffff:199.192.29.9 with known server list. [2022-02-20T21:50:02.587] [INFO] NodeLS - ::ffff:71.47.162.96 accepted; communication key matched: 'NodeListServerDefaultKey' [2022-02-20T21:50:02.587] [INFO] NodeLS - Replying to ::ffff:71.47.162.96 with known server list. [2022-02-20T21:50:03.469] [INFO] NodeLS - ::ffff:199.192.28.92 accepted; communication key matched: 'NodeListServerDefaultKey' [2022-02-20T21:50:03.469] [INFO] NodeLS - Replying to ::ffff:199.192.28.92 with known server list.

But when I run curl, my server list shows empty. Did the unity side of this package get updated too? I only updated the nodelistserver

SoftwareGuy commented 2 years ago

Okay, so I'm taking a look at this and I'm not getting the same problem as yours:

Getting the server list (no servers registered at this point in time):

[coburn@uranami ~]$ curl -X POST -d "serverKey=NodeListServerDefaultKey" http://development.oiranstudio.internal:50650/list
{"count":0,"servers":[],"updateFrequency":"300"}
[coburn@uranami ~]$

Which is expected, since no servers are registered. So I went and registered a server:

[coburn@uranami ~]$ curl -X POST -d "serverKey=NodeListServerDefaultKey&serverName=Generic Test Server&serverPort=7778&serverPlayers=69&serverCapacity=420" http://development.oiranstudio.internal:50650/add
9c73b292-da7b-4282-8b54-ca93cf25f27d
[coburn@uranami ~]$

It returned the GUID of the newly added server. Okay, that's good. Let's query the stuff again:

[coburn@uranami ~]$ curl -X POST -d "serverKey=NodeListServerDefaultKey" http://development.oiranstudio.internal:50650/list
{"count":1,"servers":[{"ip":"::ffff:192.168.42.69","name":"Generic Test Server","port":7778,"players":69,"capacity":420,"extras":""}],"updateFrequency":"300"}
[coburn@uranami ~]$

As we can see, the server is still registered.

The NodeLS Example Project has not been updated as I've got that on my to-do list under moderate priority. Will be trying to get around to updating it either later today or sometime this week, depending on real life commitments.

AbdelNabut commented 2 years ago

No worries, then! Must be an error on my part. Thanks for updating the project, I really appreciate it :) you can go ahead and close this issue

~ Abdel Nabut


From: Coburn @.> Sent: Sunday, February 20, 2022 9:09:03 PM To: SoftwareGuy/NodeListServer @.> Cc: Abdel Nabut @.>; Author @.> Subject: Re: [SoftwareGuy/NodeListServer] Can't register more than one server instance (Issue #23)

Okay, so I'm taking a look at this and I'm not getting the same problem as yours:

Getting the server list (no servers registered at this point in time):

@. ~]$ curl -X POST -d "serverKey=NodeListServerDefaultKey" http://development.oiranstudio.internal:50650/list {"count":0,"servers":[],"updateFrequency":"300"} @. ~]$

Which is expected, since no servers are registered. So I went and registered a server:

@. ~]$ curl -X POST -d "serverKey=NodeListServerDefaultKey&serverName=Generic Test Server&serverPort=7778&serverPlayers=69&serverCapacity=420" http://development.oiranstudio.internal:50650/add 9c73b292-da7b-4282-8b54-ca93cf25f27d @. ~]$

It returned the GUID of the newly added server. Okay, that's good. Let's query the stuff again:

@. ~]$ curl -X POST -d "serverKey=NodeListServerDefaultKey" http://development.oiranstudio.internal:50650/list {"count":1,"servers":[{"ip":"::ffff:192.168.42.69","name":"Generic Test Server","port":7778,"players":69,"capacity":420,"extras":""}],"updateFrequency":"300"} @. ~]$

As we can see, the server is still registered.

The NodeLS Example Project has not been updated as I've got that on my to-do list under moderate priority. Will be trying to get around to updating it either later today or sometime this week, depending on real life commitments.

— Reply to this email directly, view it on GitHubhttps://github.com/SoftwareGuy/NodeListServer/issues/23#issuecomment-1046402344, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANYY6ZHXMVVO67O7QEO4JK3U4GND7ANCNFSM5OJOWCKQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

SoftwareGuy commented 2 years ago

All good - I'll leave this open as a reminder for me to update the example project. Otherwise I'll forget because I'm dumb at times like that... 😅

brendanrivers commented 1 year ago

Just leaving a note for future devs - the issue appears to be that there was an errant + symbol in the code in the validation.js file.

this line here in validators.js@110 const existingServer = serverArray.find( (server) => server.ip === req.ip && server.port === +req.body.serverPort ); has a + symbol that i believe was made in error? im not a JS wizard but it doesn't make sense to me that it's there.

after rebuilding the docker image with: const existingServer = serverArray.find( (server) => server.ip === req.ip && server.port === req.body.serverPort );

i will still get issues with name collision, which seems superfluous, but adding several different IPs with the same port no longer causes issues.