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

Error 51 whilst trying to connect #7

Open
JustTemmie opened this issue Sep 19, 2023 · 12 comments
Open

Error 51 whilst trying to connect #7

JustTemmie opened this issue Sep 19, 2023 · 12 comments
Labels
bug Something isn't working windows

Comments

@JustTemmie
Copy link

JustTemmie commented Sep 19, 2023

I've implemented this project into my game built with Godot 3.5.2, running it on Linux works perfectly fine at works great! But whenever i try running the game on windows it errors out and gives me errors 51 and i was wondering what it meant?

this is the relevant code in case i just completely missed something

func _ready() -> void:
	add_child(discord_rpc)
	discord_rpc.connect("rpc_error", self, "_on_discord_error")
	discord_rpc.connect("rpc_ready", self, "_on_discord_ready")
	discord_rpc.establish_connection(APPLICATION_ID)

func _on_discord_error(error: int) -> void:
	print("RPC Connection ERROR: ", error)

func _on_discord_ready(user: Dictionary) -> void:
	print("yay")
@JustTemmie
Copy link
Author

JustTemmie commented Sep 19, 2023

alright nvm after a bit more searching i found out that it just can't find any clients connected

running thru and trying to understand what it's doing, it reaches this part of the code in DiscordRPC.gd

	for i in range(10):
		var path = IPC.get_pipe_path(i)

		for final_path in [path] if not is_linux else [path % "", path % FLATPAK, path % SNAP]:
			if _ipc.open(final_path) == OK:
				_handshake()
				return
			_ipc.close()

it loops 10 times, the final_path variable is set to \\?\pipe\discord-ipc-{loopCount}

the first check of _ipc.open(final_path) returns ERR_FILE_CANT_OPEN, subsequent checks returns ERR_FILE_NOT_FOUND

still have no idea what's going on as i'm not all that familiar with the discord RPC specification

@Abdera7mane
Copy link
Owner

Abdera7mane commented Sep 19, 2023

Discord RPC is done through a Unix socket on Linux/MacOS and a Named pipe on Windows (think of the latter as a file)

Each Discord instance creates the socket/named pipe on an endpoint named discord-ipc-{instance_id} where instance_id is zero indexed. So establishing a connection is done by finding the endpoint and ensuring that the current application has read & write access to it.

so here is what I think is a possible cause of failure on windows:

  • Discord is running with administrator privilege (the named pipe won't be accessible from programs with a lower privilege).
  • You aren't running Discord desktop client (very unlikely from what I can tell)

it is also good to note that my implementation for Godot 3.x is poor comparing to the rewrite for Godot 4.x, I just don't happen to have time to invest on refactoring the 3.x branch

@JustTemmie
Copy link
Author

I've handed out the executable to multiple others, and they all seem to get the same read/write permission error so i doubt it's a privilege thing?

Do you have any other possible ideas?

@Abdera7mane
Copy link
Owner

Interesting... will try to investigate when I get on Windows

@JustTemmie
Copy link
Author

thanks for your time!

@Abdera7mane
Copy link
Owner

Okay this is a bit odd, I have tried the 3.x branch and I was able to interface with Discord through RPC on Godot 3.5.1
image

Will try other means to troubleshoot

@JustTemmie
Copy link
Author

okay i seem to have got it working myself, it seems like my steam integration was blocking it?

idk if steam would just block file requests like that but it's possible?

@JustTemmie
Copy link
Author

Okay yea, steam itself does not block the file requests, however my integration layer with steam, "godotsteam" seems to be interfering

@Abdera7mane
Copy link
Owner

🤔 that's even weirder, are you using the GDNative version or as a Godot module ?

@JustTemmie
Copy link
Author

the godot module, more specifically the pre-compiled version

@JustTemmie
Copy link
Author

if it helps in any way, here's a minimum-reproducable-project.zip i made

@Abdera7mane Abdera7mane added bug Something isn't working windows labels Sep 19, 2023
@Abdera7mane
Copy link
Owner

Abdera7mane commented Sep 23, 2023

In my Windows implementation I used Godot's File object and was enough to connect to Discord RPC named pipe. I have tried vanilla Godot 3.5.1, 3.5.2 and 3.5.3-rc1 all of which have worked fine, so it is clear that the issue comes from the Steam integration.

So I have inspected Godot's source code and found that they are using _wfsopen to deal with files on windows:
https://github.com/godotengine/godot/blob/5271c971f346fcf3859f5872049f948afa4dba99/drivers/windows/file_access_windows.cpp#L115

And there seems to be a way to intercept _wfsopen calls, however it's kinda hard to confirm whether this is the case since SteamworksSDK is closed source

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

No branches or pull requests

2 participants