Skip to content

Commit

Permalink
Fix spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesefon authored Dec 29, 2020
1 parent 3338c09 commit f270d84
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions cpp/GRPCTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,120 +11,117 @@ std::pair<int, char> cbError;
char cbJoinSecret;
char cbSpectateSecret;
DiscordUser cbJoinRequest;
bool cbConUserTriggerd, cbDisconnectedTriggerd, cbErrorTriggerd, cbJoinTriggerd,
cbSpectateTriggerd, cbJoinRequestTriggerd;
bool cbConUserTriggered, cbDisconnectedTriggered, cbErrorTriggered,
cbJoinTriggered, cbSpectateTriggered, cbJoinRequestTriggered;

static void HandleDiscordReady(const DiscordUser *connectedUser) {
cbConUser = *connectedUser;
cbConUserTriggerd = true;
cbConUserTriggered = true;
}

static void HandleDiscordDisconnected(int errcode, const char *message) {
cbDisconnected.first = errcode;
cbDisconnected.second = *message;
cbDisconnectedTriggerd = true;
cbDisconnectedTriggered = true;
}

static void HandleDiscordError(int errcode, const char *message) {
cbError.first = errcode;
cbError.second = *message;
cbConUserTriggerd = true;
cbConUserTriggered = true;
}

static void HandleDiscordJoin(const char *secret) {
cbJoinSecret = *secret;
cbJoinTriggerd = true;
cbJoinTriggered = true;
}

static void HandleDiscordSpectate(const char *secret) {
cbSpectateSecret = *secret;
cbSpectateTriggerd = true;
cbSpectateTriggered = true;
}

static void HandleDiscordJoinRequest(const DiscordUser *request) {
cbJoinRequest = *request;
cbJoinRequestTriggerd = true;
cbJoinRequestTriggered = true;
}

LUA_FUNCTION(StartDiscordStatus) {

const char *appid = LUA->GetString(1);
const char *discordAppId = LUA->GetString(1);

// Discord RPC
DiscordEventHandlers handlers{};

handlers.ready = HandleDiscordReady;
handlers.disconnected = HandleDiscordDisconnected;
handlers.errored = HandleDiscordError;
handlers.joinGame = HandleDiscordJoin;
handlers.spectateGame = HandleDiscordSpectate;
handlers.joinRequest = HandleDiscordJoinRequest;

Discord_Initialize(appid, &handlers, 1, 0);

Discord_Initialize(discordAppId, &handlers, 1, "4000");
return 0;
}

LUA_FUNCTION(RunDiscordCallbacks) {
Discord_RunCallbacks();
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
LUA->GetField(-1, "hook");
if (cbConUserTriggerd) {
if (cbConUserTriggered) {
LUA->GetField(-1, "Run");
LUA->PushString("DiscordReady");
LUA->PushString(cbConUser.userId);
LUA->PushString(cbConUser.username);
LUA->PushString(cbConUser.discriminator);
LUA->PushString(cbConUser.avatar);
LUA->PushString(cbConUser.username);
LUA->PushString(cbConUser.username); // wontfix; use upstream
LUA->Call(6, 0);
cbConUserTriggerd = false;
cbConUserTriggered = false;
}

if (cbDisconnectedTriggerd) {
if (cbDisconnectedTriggered) {
LUA->GetField(-1, "Run");
LUA->PushString("DiscordDisconnected");
LUA->PushNumber(cbDisconnected.first);
LUA->PushString(&cbDisconnected.second);
LUA->Call(3, 0);
cbDisconnectedTriggerd = false;
cbDisconnectedTriggered = false;
}

if (cbErrorTriggerd) {
if (cbErrorTriggered) {
LUA->GetField(-1, "Run");
LUA->PushString("DiscordError");
LUA->PushNumber(cbError.first);
LUA->PushString(&cbError.second);
LUA->Call(3, 0);
cbErrorTriggerd = false;
cbErrorTriggered = false;
}

if (cbJoinTriggerd) {
if (cbJoinTriggered) {
LUA->GetField(-1, "Run");
LUA->PushString("DiscordJoin");
LUA->PushString(&cbJoinSecret);
LUA->Call(2, 0);
cbJoinTriggerd = false;
cbJoinTriggered = false;
}

if (cbSpectateTriggerd) {
if (cbSpectateTriggered) {
LUA->GetField(-1, "Run");
LUA->PushString("DiscordSpectate");
LUA->PushString(&cbSpectateSecret);
LUA->Call(2, 0);
cbSpectateTriggerd = false;
cbSpectateTriggered = false;
}

if (cbJoinRequestTriggerd) {
if (cbJoinRequestTriggered) {
LUA->GetField(-1, "Run");
LUA->PushString("DiscordJoinRequest");
LUA->PushString(cbJoinRequest.userId);
LUA->PushString(cbJoinRequest.username);
LUA->PushString(cbJoinRequest.discriminator);
LUA->PushString(cbJoinRequest.avatar);
LUA->PushString(cbJoinRequest.username);
LUA->PushString(cbJoinRequest.username); // wontfix; use upstream
LUA->Call(6, 0);
cbJoinRequestTriggerd = false;
cbJoinRequestTriggered = false;
}

LUA->Pop(2);
Expand Down Expand Up @@ -233,7 +230,6 @@ LUA_FUNCTION(UpdateDiscordStatus_Elapsed) {
}

GMOD_MODULE_OPEN() {
// Create the functions
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
LUA->PushCFunction(StartDiscordStatus);
LUA->SetField(-2, "DiscordRPCInitialize");
Expand Down Expand Up @@ -270,4 +266,4 @@ GMOD_MODULE_OPEN() {
GMOD_MODULE_CLOSE() {
Discord_Shutdown();
return 0;
}
}

0 comments on commit f270d84

Please sign in to comment.