GodotSteam / GodotSteam

An open-source and fully functional Steamworks SDK / API module and plug-in for the Godot Game Engine.
http://godotsteam.com/
MIT License
2.57k stars 175 forks source link

Can I use the getPublicIP() function? #258

Closed AesynthGrey closed 1 year ago

AesynthGrey commented 2 years ago

https://gramps.github.io/GodotSteam/functions-game-server.html

So there's a getPublicIP() function, which I'm really interested in to get the IP address of the host.

So I'm trying to make a multiplayer that combines Godot's ENet and Steam's lobbying system. Is this function deprecated? When I try to use it, it doesn't come up with anything. Am I supposed to use it a certain way?

Gramps commented 2 years ago

The Steamworks documentation isn't super clear on what is required to make it work and the few times I tested it I haven't been able to get any usable information from it. But the function is super simple under-the-hood so it should work.

It is meant to be used for servers though, which is probably where I was going wrong before. And a server that Steam is aware of. I'm not 100% sure how you set that up to utilize it but I believe the server will have to be initialized with initGameServer() so that Steam knows what IP to send back.

I do not believe this will work with lobbies; just game servers.

AesynthGrey commented 2 years ago

Got it. Thanks for the quick response. So how do I exactly retrieve the host's ip address to use in Godot's ENet? I've read some other issues, but when I try to actually do those things it just doesn't work. Because first off...

Where do I put it? Like, how is the actual joiner of the lobby going to retrieve this? With... getLobbyData()? I've tried that, but I think it can only be called once. I want to say, Steam.getLobbyOwner().getPublicIP, but that doesn't really seem to work. What should I do to try and recreate this? Edit: If I try to use getPublicIP, it says: SCRIPT ERROR: Invalid call. Nonexistent function 'getPublicIP' in base 'Steam'.

AesynthGrey commented 2 years ago

Wait, what if I make the lobby id literally the IP address of the host and then make it so that Godot just connects to the lobby id?

Gramps commented 2 years ago

Welcome! That I'm not sure, I haven't used Godot's networking since Godot 2.x actually.

Yeah, it seems getPublicIP is commented out currently. Not sure why but I'll look at it. Might be a compiling error or crash.

There are a few projects that are trying to mix Godot's HL networking and Steamworks; not sure how well they work currently. A few people in our Discord have been discussing it recently.

Your Steam.getLobbyOwner().getPublicIP() wouldn't work because lobbies aren't servers. That function just gets the Steam ID of the lobby's owner.

As for the lobby ID, Steam generates those itself so there is no way to change it. You could pass it through setLobbyData I guess. You can call getLobbyData as often as you want actually.

Gramps commented 2 years ago

OK, getPublicIP is in the projects to-do list. Apparently Valve changed the integer to a struct so it completely borked the function for us. It should be fixed in the next update.

AesynthGrey commented 2 years ago

Thanks dude! When's the next update?

Gramps commented 2 years ago

Probably when Godot 3.5 comes out, which should be soon.

AesynthGrey commented 2 years ago

Oh okay. I could try that setLobbyData for now, though. Thanks so much! You've been very helpful.

Gramps commented 2 years ago

Welcome! Yeah, that might work out. It is an easy way to pass data back and forth. That and P2P messages. You can also check out JDare's repo for his mix of Godot's HL networking and Steamworks.

Do remember that getPublicIP only works with servers that are using Steamworks and have been initialized as servers. It won't work with anything else.

AesynthGrey commented 2 years ago

Aight. I'll keep that in mind as well. Thanks a lot! Been quite an honor to talk to a heck of a programmer.

Gramps commented 2 years ago

Very welcome! Feel free to join us in the Discord if you get stuck on anything; a lot of smart folks with good ideas on networking. I will close this issue when the getPublicIP function is fixed.

AesynthGrey commented 2 years ago

So I did figure out how to get the local ip address of the host, which works locally on the same network, but I really need that getPublicIP thing. When is Godot 3.5 destined to come out fully? I've looked but I still don't know when it's gonna get out.

Gramps commented 2 years ago

Here is the test build I made to see if the code changes worked. It is the version that will go live, minus any other changes we make before 3.5 releases: https://www.dropbox.com/s/lyyyb99m8yafun3/getPublicIP-test.zip?dl=0

I have no idea when they intend to release 3.5 actually. I just see updates on Twitter and Reddit every so often. It should be soon, I think, since it is in the release candidate phase.

AesynthGrey commented 2 years ago

Weird. It still says the command doesn't exist. I even ran your specific version in another folder (separate from the other editor I have) and it still gives me the error. editor_screenshot_2022-06-27T201343-0600

Gramps commented 2 years ago

My bad, I didn't actually uncomment the function bind. I'll make a new one tomorrow afternoon.

AesynthGrey commented 2 years ago

Hey! It's been a day and I've been working on achievements. Is that fixed build done?

Gramps commented 2 years ago

Sorry, been busy. Here is a test version with getPublicIP back in. Remember, this will not work unless you initialize a server through Steam.

AesynthGrey commented 2 years ago

Thanks! I'll definitely put you in the credits for this.

Gramps commented 2 years ago

Let me know how it goes!

AesynthGrey commented 2 years ago

Um wait noob question, how do I initialize a server through steam...? I have a lobby initiated but not a server.

Gramps commented 2 years ago

You'll want to check out the functions in the Game Server class: https://gramps.github.io/GodotSteam/functions-game-server.html Specifically initGameServer( dictionary connect_data, int app_id, string version_string ).

AesynthGrey commented 2 years ago

That's weird. It doesn't seem like that's even a viable command. editor_screenshot_2022-06-29T162339-0600

Gramps commented 2 years ago

Hmm, it does seem like it is missing. What the. I guess when we merged the server branch into the main some things didn't make it correctly. It'll need to be added back in or the server branch separated again, which is probably a better idea really.

Gramps commented 2 years ago

Oh, nevermind, it was renamed serverInit(const String& ip, uint16 game_port, uint16 query_port, int server_mode, const String& version_string) and dumped into the main class.

AesynthGrey commented 2 years ago

Ah I see. Thanks!

AesynthGrey commented 2 years ago

So one thing I didn't anticipate is the function (getPublicIP()) returns a dictionary, not an int like the documentation says. If this doesn't necessarily work, I could learn how to use an external source. In that case, I'd have to learn how to, theoretically, run a command in Godot. Edit: Correction: it returns a dictionary of an int, but it's always 0. I'm sorta wondering how, specifically, to use the last part of serverInit (version_string).

Gramps commented 2 years ago

Yeah, the documentation isn't updated for it as it technically hasn't been released in that state. I think the version string is just whatever version number the server is. That could be whatever you set it as.

Gramps commented 1 year ago

OK, this fix is added to the new GodotSteam 3.17. I accidentally overwrote my changes for this test so hopefully I recreated them correctly!