Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't register more than one server instance #23

Open
AbdelNabut opened this issue Feb 13, 2022 · 17 comments
Open

Can't register more than one server instance #23

AbdelNabut opened this issue Feb 13, 2022 · 17 comments
Labels
bug Something isn't working

Comments

@AbdelNabut
Copy link

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
Copy link
Owner

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
Copy link
Author

AbdelNabut commented Feb 14, 2022

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
Copy link
Owner

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
Copy link
Owner

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.

@SoftwareGuy SoftwareGuy added the bug Something isn't working label Feb 14, 2022
@AbdelNabut
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

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

@SoftwareGuy
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

AbdelNabut commented Feb 21, 2022 via email

@SoftwareGuy
Copy link
Owner

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
Copy link

brendanrivers commented Apr 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants