mirror of
https://github.com/EnderIce2/rpc-bridge.git
synced 2025-07-01 18:39:14 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
e9f6b969b6
|
|||
5d0e6c4026
|
|||
418e53e7f7
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2023 EnderIce2
|
||||
Copyright (c) 2024 EnderIce2
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
35
bridge.c
35
bridge.c
@ -164,13 +164,26 @@ static inline int sys_connect(int s, caddr_t name, socklen_t namelen)
|
||||
|
||||
char *native_getenv(const char *name)
|
||||
{
|
||||
static char lpBuffer[512];
|
||||
DWORD ret = GetEnvironmentVariable("BRIDGE_RPC_PATH", lpBuffer, sizeof(lpBuffer));
|
||||
if (ret != 0)
|
||||
return lpBuffer;
|
||||
|
||||
if (!IsLinux)
|
||||
{
|
||||
char *value = getenv(name);
|
||||
if (value == NULL)
|
||||
{
|
||||
print("Failed to get environment variable: %s\n", name);
|
||||
return NULL;
|
||||
|
||||
/* Use GetEnvironmentVariable as a last resort */
|
||||
DWORD ret = GetEnvironmentVariable(name, lpBuffer, sizeof(lpBuffer));
|
||||
if (ret == 0)
|
||||
{
|
||||
print("GetEnvironmentVariable(\"%s\", ...) failed: %d\n", name, ret);
|
||||
return NULL;
|
||||
}
|
||||
return lpBuffer;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -299,11 +312,13 @@ void ConnectToSocket(int fd)
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE hOut = NULL;
|
||||
void PipeBufferInThread(LPVOID lpParam)
|
||||
{
|
||||
bridge_thread *bt = (bridge_thread *)lpParam;
|
||||
print("In thread started using fd %d and pipe %#x\n",
|
||||
bt->fd, bt->hPipe);
|
||||
int EOFCount = 0;
|
||||
while (TRUE)
|
||||
{
|
||||
char buffer[1024];
|
||||
@ -317,12 +332,22 @@ void PipeBufferInThread(LPVOID lpParam)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (EOFCount > 4)
|
||||
{
|
||||
print("EOF count exceeded\n");
|
||||
RetryNewConnection = TRUE;
|
||||
TerminateThread(hOut, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(read == 0))
|
||||
{
|
||||
print("EOF\n");
|
||||
Sleep(1000);
|
||||
EOFCount++;
|
||||
continue;
|
||||
}
|
||||
EOFCount = 0;
|
||||
|
||||
print("Reading %d bytes from unix pipe: \"", read);
|
||||
for (int i = 0; i < read; i++)
|
||||
@ -523,10 +548,10 @@ NewConnection:
|
||||
(LPVOID)&bt,
|
||||
0, NULL);
|
||||
|
||||
HANDLE hOut = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE)PipeBufferOutThread,
|
||||
(LPVOID)&bt,
|
||||
0, NULL);
|
||||
hOut = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE)PipeBufferOutThread,
|
||||
(LPVOID)&bt,
|
||||
0, NULL);
|
||||
|
||||
if (hIn == NULL || hOut == NULL)
|
||||
{
|
||||
|
23
main.c
23
main.c
@ -259,6 +259,19 @@ void HandleArguments(int argc, char *argv[])
|
||||
RemoveService();
|
||||
ExitProcess(0);
|
||||
}
|
||||
else if (strcmp(argv[1], "--rpc") == 0)
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
print("No directory provided\n");
|
||||
ExitProcess(1);
|
||||
}
|
||||
|
||||
SetEnvironmentVariable("BRIDGE_RPC_PATH", argv[2]);
|
||||
print("BRIDGE_RPC_PATH has been set to \"%s\"\n", argv[2]);
|
||||
CreateBridge();
|
||||
ExitProcess(0);
|
||||
}
|
||||
else if (strcmp(argv[1], "--help") == 0)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
@ -269,17 +282,21 @@ void HandleArguments(int argc, char *argv[])
|
||||
|
||||
printf(" --install Install service\n");
|
||||
printf(" This will copy the binary to C:\\windows\\bridge.exe and register it as a service\n\n");
|
||||
|
||||
printf(" --uninstall Uninstall service\n");
|
||||
|
||||
printf(" This will remove the service and delete C:\\windows\\bridge.exe\n\n");
|
||||
|
||||
printf(" --steam Reserved for Steam\n");
|
||||
|
||||
printf(" This will start the service and exit (used with bridge.sh)\n\n");
|
||||
printf(" --no-service Do not run as service\n");
|
||||
|
||||
printf(" --no-service Do not run as service\n");
|
||||
printf(" (only for --steam)\n\n");
|
||||
|
||||
printf(" --service Reserved for service\n\n");
|
||||
|
||||
printf(" --rpc <dir> Set RPC_PATH environment variable\n");
|
||||
printf(" This is used to specify the directory where 'discord-ipc-0' is located\n\n");
|
||||
|
||||
printf("Note: If no arguments are provided, the GUI will be shown instead\n");
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user