Unity ajt fix

This commit is contained in:
Chris Marsh 2017-11-02 11:59:45 -07:00 committed by GitHub
parent aa79c70bf9
commit 3bdb88d918
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View file

@ -50,14 +50,11 @@ public class DiscordRpc
public bool instance;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.Serializable]
public struct JoinRequest
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)]
public string userId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
public string username;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string avatar;
}

View file

@ -42,9 +42,9 @@ typedef struct DiscordRichPresence {
} DiscordRichPresence;
typedef struct DiscordJoinRequest {
char userId[24];
char username[48];
char avatar[128];
const char* userId;
const char* username;
const char* avatar;
} DiscordJoinRequest;
typedef struct DiscordEventHandlers {

View file

@ -32,6 +32,12 @@ struct QueuedMessage {
}
};
struct JoinRequest {
char userId[24];
char username[48];
char avatar[128];
};
static RpcConnection* Connection{nullptr};
static DiscordEventHandlers Handlers{};
static std::atomic_bool WasJustConnected{false};
@ -48,7 +54,7 @@ static char LastDisconnectErrorMessage[256];
static std::mutex PresenceMutex;
static QueuedMessage QueuedPresence{};
static MsgQueue<QueuedMessage, MessageQueueSize> SendQueue;
static MsgQueue<DiscordJoinRequest, JoinQueueSize> JoinAskQueue;
static MsgQueue<JoinRequest, JoinQueueSize> JoinAskQueue;
// We want to auto connect, and retry on failure, but not as fast as possible. This does expoential
// backoff from 0.5 seconds to 1 minute
@ -353,7 +359,8 @@ extern "C" DISCORD_EXPORT void Discord_RunCallbacks()
while (JoinAskQueue.HavePendingSends()) {
auto req = JoinAskQueue.GetNextSendMessage();
if (Handlers.joinRequest) {
Handlers.joinRequest(req);
DiscordJoinRequest djr{req->userId, req->username, req->avatar};
Handlers.joinRequest(&djr);
}
JoinAskQueue.CommitSend();
}