mirror of
https://github.com/EnderIce2/rpc-bridge.git
synced 2025-05-25 22:14:38 +00:00
Update Discord socket search
* Test multiple instances * Add support for Discord Canary (Snap) * Add support for Vesktop (Flatpak)
This commit is contained in:
parent
a8904bf3f1
commit
39966d7149
56
bridge.c
56
bridge.c
@ -282,41 +282,53 @@ void ConnectToSocket(int fd)
|
|||||||
print("IPC directory: %s\n", runtime);
|
print("IPC directory: %s\n", runtime);
|
||||||
|
|
||||||
/* TODO: check for multiple discord instances and create a pipe for each */
|
/* TODO: check for multiple discord instances and create a pipe for each */
|
||||||
const char *discordUnixPipes[] = {
|
const char *discordUnixSockets[] = {
|
||||||
"/discord-ipc-0",
|
"%s/discord-ipc-%d",
|
||||||
"/snap.discord/discord-ipc-0",
|
"%s/app/com.discordapp.Discord/discord-ipc-%d",
|
||||||
"/app/com.discordapp.Discord/discord-ipc-0",
|
"%s/.flatpak/dev.vencord.Vesktop/xdg-run/discord-ipc-%d",
|
||||||
|
"%s/snap.discord/discord-ipc-%d",
|
||||||
|
"%s/snap.discord-canary/discord-ipc-%d",
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sockaddr_un socketAddr;
|
struct sockaddr_un socketAddr;
|
||||||
socketAddr.sun_family = AF_UNIX;
|
socketAddr.sun_family = AF_UNIX;
|
||||||
char *pipePath = NULL;
|
|
||||||
int sockRet = -1;
|
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(discordUnixPipes) / sizeof(discordUnixPipes[0]); i++)
|
int sockRet = 0;
|
||||||
|
for (int i = 0; i < sizeof(discordUnixSockets) / sizeof(discordUnixSockets[0]); i++)
|
||||||
{
|
{
|
||||||
pipePath = malloc(strlen(runtime) + strlen(discordUnixPipes[i]) + 1);
|
size_t pipePathLen = strlen(runtime) + strlen(discordUnixSockets[i]) + 1;
|
||||||
strcpy(pipePath, runtime);
|
char *pipePath = malloc(pipePathLen);
|
||||||
strcat(pipePath, discordUnixPipes[i]);
|
|
||||||
strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath);
|
|
||||||
|
|
||||||
print("Connecting to %s\n", pipePath);
|
for (int j = 0; j < 16; j++)
|
||||||
|
|
||||||
if (IsLinux)
|
|
||||||
{
|
{
|
||||||
unsigned long socketArgs[] = {
|
snprintf(pipePath, pipePathLen, discordUnixSockets[i], runtime, j);
|
||||||
(unsigned long)fd,
|
strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath);
|
||||||
(unsigned long)(intptr_t)&socketAddr,
|
print("Probing %s\n", pipePath);
|
||||||
sizeof(socketAddr)};
|
|
||||||
|
|
||||||
sockRet = sys_socketcall(SYS_CONNECT, socketArgs);
|
if (IsLinux)
|
||||||
|
{
|
||||||
|
unsigned long socketArgs[] = {
|
||||||
|
(unsigned long)fd,
|
||||||
|
(unsigned long)(intptr_t)&socketAddr,
|
||||||
|
sizeof(socketAddr)};
|
||||||
|
|
||||||
|
sockRet = sys_socketcall(SYS_CONNECT, socketArgs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sockRet = sys_connect(fd, (caddr_t)&socketAddr, sizeof(socketAddr));
|
||||||
|
|
||||||
|
print(" error: %d\n", sockRet);
|
||||||
|
if (sockRet >= 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
sockRet = sys_connect(fd, (caddr_t)&socketAddr, sizeof(socketAddr));
|
|
||||||
|
|
||||||
free(pipePath);
|
|
||||||
if (sockRet >= 0)
|
if (sockRet >= 0)
|
||||||
|
{
|
||||||
|
print("Connecting to %s\n", pipePath);
|
||||||
|
free(pipePath);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
free(pipePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sockRet < 0)
|
if (sockRet < 0)
|
||||||
|
@ -21,10 +21,10 @@ TEMP_PATH="$XDG_RUNTIME_DIR"
|
|||||||
TEMP_PATH=${TEMP_PATH:-"$TMPDIR"}
|
TEMP_PATH=${TEMP_PATH:-"$TMPDIR"}
|
||||||
|
|
||||||
VESSEL_PATH="$BRIDGE_PATH"
|
VESSEL_PATH="$BRIDGE_PATH"
|
||||||
IPC_PATHS="$TEMP_PATH /run/user/$UID $TEMP_PATH/snap.discord $TEMP_PATH/app/com.discordapp.Discord"
|
IPC_PATHS="$TEMP_PATH /run/user/$UID $TEMP_PATH/app/com.discordapp.Discord $TEMP_PATH/.flatpak/dev.vencord.Vesktop/xdg-run $TEMP_PATH/snap.discord $TEMP_PATH/snap.discord-canary"
|
||||||
for discord_ipc in $IPC_PATHS; do
|
for discord_ipc in $IPC_PATHS; do
|
||||||
if [ -S "$discord_ipc"/discord-ipc-0 ]; then
|
if [ -S "$discord_ipc"/discord-ipc-? ]; then
|
||||||
VESSEL_PATH="$BRIDGE_PATH:$(echo "$discord_ipc"/discord-ipc-0)"
|
VESSEL_PATH="$BRIDGE_PATH:$(echo "$discord_ipc"/discord-ipc-?)"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user