Choose pipe number on initialize (#250)
* Choose pipe number on initialize * Get pipe from base connection instance * UE4 support * Warnings as errors yelling * Fix windows connection * Oops all variables * maybe this fixes it * This one actually works!!!! * Fix double function declaration
This commit is contained in:
@ -12,7 +12,7 @@ struct BaseConnection {
|
||||
static BaseConnection* Create();
|
||||
static void Destroy(BaseConnection*&);
|
||||
bool isOpen{false};
|
||||
bool Open();
|
||||
bool Open(int pipe);
|
||||
bool Close();
|
||||
bool Write(const void* data, size_t length);
|
||||
bool Read(void* data, size_t length);
|
||||
|
@ -49,7 +49,7 @@ static const char* GetTempPath()
|
||||
c = nullptr;
|
||||
}
|
||||
|
||||
bool BaseConnection::Open()
|
||||
bool BaseConnection::Open(int pipe)
|
||||
{
|
||||
const char* tempPath = GetTempPath();
|
||||
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||
@ -62,8 +62,7 @@ bool BaseConnection::Open()
|
||||
int optval = 1;
|
||||
setsockopt(self->sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
|
||||
#endif
|
||||
|
||||
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {
|
||||
for (int pipeNum = pipe; pipeNum < 10; ++pipeNum) {
|
||||
snprintf(
|
||||
PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
|
||||
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define NOIME
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
#include <sstream>
|
||||
|
||||
int GetProcessId()
|
||||
{
|
||||
@ -30,11 +31,11 @@ static BaseConnectionWin Connection;
|
||||
c = nullptr;
|
||||
}
|
||||
|
||||
bool BaseConnection::Open()
|
||||
bool BaseConnection::Open(int pipe)
|
||||
{
|
||||
wchar_t pipeName[]{L"\\\\?\\pipe\\discord-ipc-0"};
|
||||
const size_t pipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
||||
pipeName[pipeDigit] = L'0';
|
||||
pipeName[pipeDigit] += pipe;
|
||||
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
||||
for (;;) {
|
||||
self->pipe = ::CreateFileW(
|
||||
|
@ -273,7 +273,8 @@ static bool DeregisterForEvent(const char* evtName)
|
||||
extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||
DiscordEventHandlers* handlers,
|
||||
int autoRegister,
|
||||
const char* optionalSteamId)
|
||||
const char* optionalSteamId,
|
||||
int pipe)
|
||||
{
|
||||
IoThread = new (std::nothrow) IoThreadHolder();
|
||||
if (IoThread == nullptr) {
|
||||
@ -308,7 +309,7 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||
return;
|
||||
}
|
||||
|
||||
Connection = RpcConnection::Create(applicationId);
|
||||
Connection = RpcConnection::Create(applicationId, pipe);
|
||||
Connection->onConnect = [](JsonDocument& readyMessage) {
|
||||
Discord_UpdateHandlers(&QueuedHandlers);
|
||||
if (QueuedPresence.length > 0) {
|
||||
|
@ -6,10 +6,11 @@
|
||||
static const int RpcVersion = 1;
|
||||
static RpcConnection Instance;
|
||||
|
||||
/*static*/ RpcConnection* RpcConnection::Create(const char* applicationId)
|
||||
/*static*/ RpcConnection* RpcConnection::Create(const char* applicationId, int pipe)
|
||||
{
|
||||
Instance.connection = BaseConnection::Create();
|
||||
StringCopy(Instance.appId, applicationId);
|
||||
Instance.pipe = pipe;
|
||||
return &Instance;
|
||||
}
|
||||
|
||||
@ -26,7 +27,7 @@ void RpcConnection::Open()
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == State::Disconnected && !connection->Open()) {
|
||||
if (state == State::Disconnected && !connection->Open(Instance.pipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,12 @@ struct RpcConnection {
|
||||
void (*onConnect)(JsonDocument& message){nullptr};
|
||||
void (*onDisconnect)(int errorCode, const char* message){nullptr};
|
||||
char appId[64]{};
|
||||
int pipe;
|
||||
int lastErrorCode{0};
|
||||
char lastErrorMessage[256]{};
|
||||
RpcConnection::MessageFrame sendFrame;
|
||||
|
||||
static RpcConnection* Create(const char* applicationId);
|
||||
static RpcConnection* Create(const char* applicationId, int pipe);
|
||||
static void Destroy(RpcConnection*&);
|
||||
|
||||
inline bool IsOpen() const { return state == State::Connected; }
|
||||
|
Reference in New Issue
Block a user