Skip to content

Commit

Permalink
fix a number of crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
yourWaifu committed Oct 13, 2017
1 parent 15533b9 commit 218d2b9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions source/3ds_discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ void ThreeDSDiscordClient::switchChannel() {
}

void ThreeDSDiscordClient::loadMessages() {
if (servers.size() == 0) return;
std::vector<SleepyDiscord::Message> messages = getMessages(getCurrentChannel().id, limit, "", 8);
for (std::vector<SleepyDiscord::Message>::reverse_iterator i = messages.rbegin(), end = messages.rend(); i != end; ++i) {
addNewMessage(*i);
}
}

void ThreeDSDiscordClient::launchKeyboardAndSentMessage() {
if (servers.size() == 0) return;
//tell discord that we are typing
if (sendTyping(getCurrentChannel().id) == false) //error check
return;
Expand Down
1 change: 1 addition & 0 deletions source/3ds_discord.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class ThreeDSDiscordClient : public ThreeDSWebsocketClient {
public:
ThreeDSDiscordClient() {}
ThreeDSDiscordClient(const std::string token);
void switchServer();
void switchChannel();
Expand Down
1 change: 1 addition & 0 deletions source/3ds_websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ThreeDSWebsocketClient::ThreeDSWebsocketClient(const std::string token) {
NULL,
onMessageCallback
};
isRunning = true;
eventContext = nullptr;
start(token, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion source/3ds_websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ThreeDSWebsocketClient : public SleepyDiscord::BaseDiscordClient {
void disconnect(unsigned int code, const std::string reason);
void send(std::string message);
int sock;
bool isRunning = true;
bool isRunning = false;

std::vector<SleepyDiscord::Server> serverList;

Expand Down
18 changes: 14 additions & 4 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define DEBUGGING

#include <3ds.h>
#include <malloc.h>
#include <memory>
Expand Down Expand Up @@ -69,8 +67,20 @@ int main() {

//start the discord client
tokenFile token("discord token.txt");
if (token.getSize() < 0) printf("error can't find or read text file with discord token");
gfxFlushBuffers();
if (token.getSize() < 0) { //error check
printf("Error: could not find file called\n"
"discord token.txt in the root of your\n"
"SD card. Please place a bot token in\n"
"that file.");
gfxFlushBuffers();
while (aptMainLoop()) {
hidScanInput();
u32 keysPressedDown = hidKeysDown();
if (keysPressedDown)
return EXIT_SUCCESS;
gspWaitForVBlank();
}
}
ThreeDSDiscordClient client(token.getToken());
//clientPointer = &client;
token.close();
Expand Down
2 changes: 1 addition & 1 deletion source/token_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class tokenFile {
}

const std::string getToken() {
std::string buffer(size, 0);
std::string buffer(size + 1, 0);
fread(&buffer[0], 1, size, fileHandle);
return &buffer[0];
}
Expand Down

0 comments on commit 218d2b9

Please sign in to comment.