Revert "Choose pipe number on initialize (#250)"
This reverts commit 4824b20f28
.
This commit is contained in:
parent
4824b20f28
commit
c59fd6df20
11 changed files with 19 additions and 25 deletions
|
@ -78,7 +78,7 @@ public class DiscordRpc
|
||||||
Ignore = 2
|
Ignore = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId, int pipe = 0)
|
public static void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId)
|
||||||
{
|
{
|
||||||
Callbacks = handlers;
|
Callbacks = handlers;
|
||||||
|
|
||||||
|
@ -90,11 +90,11 @@ public class DiscordRpc
|
||||||
staticEventHandlers.spectateCallback += DiscordRpc.SpectateCallback;
|
staticEventHandlers.spectateCallback += DiscordRpc.SpectateCallback;
|
||||||
staticEventHandlers.requestCallback += DiscordRpc.RequestCallback;
|
staticEventHandlers.requestCallback += DiscordRpc.RequestCallback;
|
||||||
|
|
||||||
InitializeInternal(applicationId, ref staticEventHandlers, autoRegister, optionalSteamId, pipe);
|
InitializeInternal(applicationId, ref staticEventHandlers, autoRegister, optionalSteamId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("discord-rpc", EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("discord-rpc", EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern void InitializeInternal(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId, int pipe);
|
static extern void InitializeInternal(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId);
|
||||||
|
|
||||||
[DllImport("discord-rpc", EntryPoint = "Discord_Shutdown", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("discord-rpc", EntryPoint = "Discord_Shutdown", CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void Shutdown();
|
public static extern void Shutdown();
|
||||||
|
|
|
@ -129,7 +129,7 @@ static void discordInit()
|
||||||
handlers.joinGame = handleDiscordJoin;
|
handlers.joinGame = handleDiscordJoin;
|
||||||
handlers.spectateGame = handleDiscordSpectate;
|
handlers.spectateGame = handleDiscordSpectate;
|
||||||
handlers.joinRequest = handleDiscordJoinRequest;
|
handlers.joinRequest = handleDiscordJoinRequest;
|
||||||
Discord_Initialize(APPLICATION_ID, &handlers, 1, NULL, 0);
|
Discord_Initialize(APPLICATION_ID, &handlers, 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gameLoop()
|
static void gameLoop()
|
||||||
|
|
|
@ -82,8 +82,7 @@ static void JoinRequestHandler(const DiscordUser* request)
|
||||||
|
|
||||||
void UDiscordRpc::Initialize(const FString& applicationId,
|
void UDiscordRpc::Initialize(const FString& applicationId,
|
||||||
bool autoRegister,
|
bool autoRegister,
|
||||||
const FString& optionalSteamId,
|
const FString& optionalSteamId)
|
||||||
int pipe)
|
|
||||||
{
|
{
|
||||||
self = this;
|
self = this;
|
||||||
IsConnected = false;
|
IsConnected = false;
|
||||||
|
@ -103,7 +102,7 @@ void UDiscordRpc::Initialize(const FString& applicationId,
|
||||||
auto appId = StringCast<ANSICHAR>(*applicationId);
|
auto appId = StringCast<ANSICHAR>(*applicationId);
|
||||||
auto steamId = StringCast<ANSICHAR>(*optionalSteamId);
|
auto steamId = StringCast<ANSICHAR>(*optionalSteamId);
|
||||||
Discord_Initialize(
|
Discord_Initialize(
|
||||||
(const char*)appId.Get(), &handlers, autoRegister, (const char*)steamId.Get(), pipe);
|
(const char*)appId.Get(), &handlers, autoRegister, (const char*)steamId.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDiscordRpc::Shutdown()
|
void UDiscordRpc::Shutdown()
|
||||||
|
|
|
@ -99,8 +99,7 @@ public:
|
||||||
Category = "Discord")
|
Category = "Discord")
|
||||||
void Initialize(const FString& applicationId,
|
void Initialize(const FString& applicationId,
|
||||||
bool autoRegister,
|
bool autoRegister,
|
||||||
const FString& optionalSteamId,
|
const FString& optionalSteamId);
|
||||||
int optionalPipeNumber);
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable,
|
UFUNCTION(BlueprintCallable,
|
||||||
meta = (DisplayName = "Shut down connection", Keywords = "Discord rpc"),
|
meta = (DisplayName = "Shut down connection", Keywords = "Discord rpc"),
|
||||||
|
|
|
@ -64,8 +64,7 @@ typedef struct DiscordEventHandlers {
|
||||||
DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||||
DiscordEventHandlers* handlers,
|
DiscordEventHandlers* handlers,
|
||||||
int autoRegister,
|
int autoRegister,
|
||||||
const char* optionalSteamId,
|
const char* optionalSteamId);
|
||||||
int optionalPipeNumber);
|
|
||||||
DISCORD_EXPORT void Discord_Shutdown(void);
|
DISCORD_EXPORT void Discord_Shutdown(void);
|
||||||
|
|
||||||
/* checks for incoming messages, dispatches callbacks */
|
/* checks for incoming messages, dispatches callbacks */
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct BaseConnection {
|
||||||
static BaseConnection* Create();
|
static BaseConnection* Create();
|
||||||
static void Destroy(BaseConnection*&);
|
static void Destroy(BaseConnection*&);
|
||||||
bool isOpen{false};
|
bool isOpen{false};
|
||||||
bool Open(int pipe);
|
bool Open();
|
||||||
bool Close();
|
bool Close();
|
||||||
bool Write(const void* data, size_t length);
|
bool Write(const void* data, size_t length);
|
||||||
bool Read(void* data, size_t length);
|
bool Read(void* data, size_t length);
|
||||||
|
|
|
@ -49,7 +49,7 @@ static const char* GetTempPath()
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Open(int pipe)
|
bool BaseConnection::Open()
|
||||||
{
|
{
|
||||||
const char* tempPath = GetTempPath();
|
const char* tempPath = GetTempPath();
|
||||||
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||||
|
@ -62,7 +62,8 @@ bool BaseConnection::Open(int pipe)
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
setsockopt(self->sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
|
setsockopt(self->sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
|
||||||
#endif
|
#endif
|
||||||
for (int pipeNum = pipe; pipeNum < 10; ++pipeNum) {
|
|
||||||
|
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {
|
||||||
snprintf(
|
snprintf(
|
||||||
PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
|
PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
|
||||||
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
|
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#define NOIME
|
#define NOIME
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
int GetProcessId()
|
int GetProcessId()
|
||||||
{
|
{
|
||||||
|
@ -31,11 +30,11 @@ static BaseConnectionWin Connection;
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Open(int pipe)
|
bool BaseConnection::Open()
|
||||||
{
|
{
|
||||||
wchar_t pipeName[]{L"\\\\?\\pipe\\discord-ipc-0"};
|
wchar_t pipeName[]{L"\\\\?\\pipe\\discord-ipc-0"};
|
||||||
const size_t pipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
const size_t pipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
||||||
pipeName[pipeDigit] += pipe;
|
pipeName[pipeDigit] = L'0';
|
||||||
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
self->pipe = ::CreateFileW(
|
self->pipe = ::CreateFileW(
|
||||||
|
|
|
@ -273,8 +273,7 @@ static bool DeregisterForEvent(const char* evtName)
|
||||||
extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||||
DiscordEventHandlers* handlers,
|
DiscordEventHandlers* handlers,
|
||||||
int autoRegister,
|
int autoRegister,
|
||||||
const char* optionalSteamId,
|
const char* optionalSteamId)
|
||||||
int pipe)
|
|
||||||
{
|
{
|
||||||
IoThread = new (std::nothrow) IoThreadHolder();
|
IoThread = new (std::nothrow) IoThreadHolder();
|
||||||
if (IoThread == nullptr) {
|
if (IoThread == nullptr) {
|
||||||
|
@ -309,7 +308,7 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection = RpcConnection::Create(applicationId, pipe);
|
Connection = RpcConnection::Create(applicationId);
|
||||||
Connection->onConnect = [](JsonDocument& readyMessage) {
|
Connection->onConnect = [](JsonDocument& readyMessage) {
|
||||||
Discord_UpdateHandlers(&QueuedHandlers);
|
Discord_UpdateHandlers(&QueuedHandlers);
|
||||||
if (QueuedPresence.length > 0) {
|
if (QueuedPresence.length > 0) {
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
static const int RpcVersion = 1;
|
static const int RpcVersion = 1;
|
||||||
static RpcConnection Instance;
|
static RpcConnection Instance;
|
||||||
|
|
||||||
/*static*/ RpcConnection* RpcConnection::Create(const char* applicationId, int pipe)
|
/*static*/ RpcConnection* RpcConnection::Create(const char* applicationId)
|
||||||
{
|
{
|
||||||
Instance.connection = BaseConnection::Create();
|
Instance.connection = BaseConnection::Create();
|
||||||
StringCopy(Instance.appId, applicationId);
|
StringCopy(Instance.appId, applicationId);
|
||||||
Instance.pipe = pipe;
|
|
||||||
return &Instance;
|
return &Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ void RpcConnection::Open()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == State::Disconnected && !connection->Open(Instance.pipe)) {
|
if (state == State::Disconnected && !connection->Open()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,12 +43,11 @@ struct RpcConnection {
|
||||||
void (*onConnect)(JsonDocument& message){nullptr};
|
void (*onConnect)(JsonDocument& message){nullptr};
|
||||||
void (*onDisconnect)(int errorCode, const char* message){nullptr};
|
void (*onDisconnect)(int errorCode, const char* message){nullptr};
|
||||||
char appId[64]{};
|
char appId[64]{};
|
||||||
int pipe;
|
|
||||||
int lastErrorCode{0};
|
int lastErrorCode{0};
|
||||||
char lastErrorMessage[256]{};
|
char lastErrorMessage[256]{};
|
||||||
RpcConnection::MessageFrame sendFrame;
|
RpcConnection::MessageFrame sendFrame;
|
||||||
|
|
||||||
static RpcConnection* Create(const char* applicationId, int pipe);
|
static RpcConnection* Create(const char* applicationId);
|
||||||
static void Destroy(RpcConnection*&);
|
static void Destroy(RpcConnection*&);
|
||||||
|
|
||||||
inline bool IsOpen() const { return state == State::Connected; }
|
inline bool IsOpen() const { return state == State::Connected; }
|
||||||
|
|
Loading…
Reference in a new issue