Score upload interface added
This commit is contained in:
parent
8a449ac7cd
commit
a369855a27
29
highscores.c
29
highscores.c
@ -9,6 +9,7 @@
|
||||
#include "highscores.h"
|
||||
|
||||
#define HIGHSCORES_FontFile "assets/fonts/monofur.ttf"
|
||||
#define HIGHSCORES_OutputFilePath "output.txt"
|
||||
|
||||
int HIGHSCORES_EntriesGot = 0;
|
||||
User * HIGHSCORES_UserList;
|
||||
@ -103,6 +104,32 @@ void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){
|
||||
tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
|
||||
}
|
||||
|
||||
bool HIGHSCORES_UploadScore(char * username, int score){
|
||||
char buffer[200];
|
||||
char * line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
char * name, * scorestring;
|
||||
|
||||
sprintf(buffer, "bhi upload %s %s %d", HIGHSCORES_OutputFilePath, username, score);
|
||||
printf("BHI called with \"%s\"\n", buffer);
|
||||
printf("Call BHI interface:\n");
|
||||
system(buffer);
|
||||
printf("BHI interface quit!\nBHI output handling...\n");
|
||||
FILE * fp = fopen(HIGHSCORES_OutputFilePath, "r");
|
||||
if (fp == NULL) {
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
if ((read = getline(&line, &len, fp)) != -1)
|
||||
if (line[0] == '0') {
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
} /* HIGHSCORES_UploadScore */
|
||||
|
||||
void HIGHSCORES_ReloadList(){
|
||||
printf("Call BHI interface:\n");
|
||||
system("bhi top output.txt");
|
||||
@ -121,7 +148,7 @@ void HIGHSCORES_ReloadList(){
|
||||
if (fp == NULL)
|
||||
return;
|
||||
if ((read = getline(&line, &len, fp)) != -1)
|
||||
if (line[0] == 0)
|
||||
if (line[0] == '0')
|
||||
return;
|
||||
int counter = 0;
|
||||
while ((read = getline(&line, &len, fp)) != -1) {
|
||||
|
@ -14,6 +14,7 @@ void HIGHSCORES_Draw(SDL_Renderer * renderer);
|
||||
void HIGHSCORES_Deinitialize();
|
||||
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer);
|
||||
void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect);
|
||||
bool HIGHSCORES_UploadScore(char * username, int score);
|
||||
void HIGHSCORES_ReloadList();
|
||||
// End Prototypes
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user