2017-06-30 22:31:48 +01:00
|
|
|
/*
|
2017-07-07 17:40:50 +01:00
|
|
|
This is a simple example in C of using the rich presence API syncronously, just sending presence.
|
2017-06-30 22:31:48 +01:00
|
|
|
*/
|
2017-06-30 20:00:45 +01:00
|
|
|
|
2017-06-30 22:31:48 +01:00
|
|
|
#define _CRT_SECURE_NO_WARNINGS /* thanks Microsoft */
|
2017-06-30 20:00:45 +01:00
|
|
|
|
2017-06-30 22:31:48 +01:00
|
|
|
#include <stdint.h>
|
2017-06-30 20:00:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "discord-rpc.h"
|
|
|
|
|
|
|
|
static const char* APPLICATION_ID = "12345678910";
|
|
|
|
static int FrustrationLevel = 0;
|
|
|
|
|
|
|
|
static void updateDiscordPresence() {
|
|
|
|
char buffer[256];
|
2017-06-30 22:31:48 +01:00
|
|
|
DiscordRichPresence discordPresence;
|
|
|
|
memset(&discordPresence, 0, sizeof(discordPresence));
|
|
|
|
discordPresence.state = "West of House";
|
2017-06-30 20:00:45 +01:00
|
|
|
sprintf(buffer, "Frustration level: %d", FrustrationLevel);
|
|
|
|
discordPresence.details = buffer;
|
|
|
|
Discord_UpdatePresence(&discordPresence);
|
|
|
|
}
|
|
|
|
|
2017-06-30 22:31:48 +01:00
|
|
|
static int prompt(char* line, size_t size) {
|
|
|
|
int res;
|
|
|
|
char* nl;
|
2017-06-30 20:00:45 +01:00
|
|
|
printf("\n> ");
|
|
|
|
fflush(stdout);
|
2017-06-30 22:31:48 +01:00
|
|
|
res = fgets(line, size, stdin) ? 1 : 0;
|
2017-06-30 20:00:45 +01:00
|
|
|
line[size - 1] = 0;
|
2017-06-30 22:31:48 +01:00
|
|
|
nl = strchr(line, '\n');
|
2017-06-30 20:00:45 +01:00
|
|
|
if (nl) {
|
|
|
|
*nl = 0;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gameLoop() {
|
|
|
|
char line[512];
|
2017-06-30 22:31:48 +01:00
|
|
|
char* space;
|
|
|
|
|
|
|
|
printf("You are standing in an open field west of a white house.\n");
|
2017-06-30 20:00:45 +01:00
|
|
|
while (prompt(line, sizeof(line))) {
|
|
|
|
if (time(NULL) & 1) {
|
|
|
|
printf("I don't understand that.\n");
|
|
|
|
} else {
|
2017-06-30 22:31:48 +01:00
|
|
|
space = strchr(line, ' ');
|
2017-06-30 20:00:45 +01:00
|
|
|
if (space) {
|
|
|
|
*space = 0;
|
|
|
|
}
|
|
|
|
printf("I don't know the word \"%s\".\n", line);
|
|
|
|
}
|
|
|
|
|
|
|
|
++FrustrationLevel;
|
|
|
|
|
|
|
|
updateDiscordPresence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2017-06-30 22:31:48 +01:00
|
|
|
DiscordEventHandlers handlers;
|
|
|
|
memset(&handlers, 0, sizeof(handlers));
|
2017-06-30 20:00:45 +01:00
|
|
|
Discord_Initialize(APPLICATION_ID, &handlers);
|
|
|
|
|
|
|
|
gameLoop();
|
|
|
|
|
|
|
|
Discord_Shutdown();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|