diff options
Diffstat (limited to 'src/data.c')
-rw-r--r-- | src/data.c | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -3,6 +3,7 @@ #include <stdlib.h> #include "data.h" #include "login.h" +#include "log.h" #include <errno.h> #include <stdio.h> #include <string.h> @@ -21,10 +22,10 @@ int try_make_data_dirs() { int try_load_plr(char *player_name, playerc_t *plr) { int err = 0; - printf("Trying to make data directories...\n"); + debug("Trying to make data directories...\n"); try_make_data_dirs(); - printf("Done, opening file.\n"); + debug("Done, opening file.\n"); char *fname; asprintf(&fname, "data/players/%s.plr", player_name); @@ -33,20 +34,20 @@ int try_load_plr(char *player_name, playerc_t *plr) { if (fp = fopen(fname, "r")) { - printf("Got fp\n"); + debug("Got fp\n"); if (deserialize_player(fp, &plr->plr) == EOF) { - printf("Couldn't deserialize player\n"); + error("Couldn't deserialize player\n"); return -1; } } else { - printf("Couldn't open file: %d\n", errno); + error("Couldn't open file: %d\n", errno); printf("%s", strerror(errno)); return -1; } - printf("Read file into plr\n"); + debug("Read file into plr\n"); fclose(fp); return err; @@ -61,7 +62,7 @@ int try_write_plr(player_t *plr) { // Now the errors that continue will be from I/O, which we can use to // figure out if the file exists in login case EACCES: /* No permissions***************************************/ - printf("No permissions to create directories\n"); + error("No permissions to create directories\n"); return -1; default: /* Do nothing because this is fine****************************/ break; @@ -76,8 +77,6 @@ int try_write_plr(player_t *plr) { char* buf = malloc(sizeof(player_t) + 1); serialize_player(plr, fp); - printf("serialized as: %s\n"); - fprintf(fp, "%s", buf); fclose(fp); @@ -98,9 +97,6 @@ int try_write_plr(player_t *plr) { */ int serialize_player(player_t *plr, FILE* fp) { int err = 0; - - printf("%s\n", plr->pw_hash); - err = fprintf(fp, "%d:%d:%d:%d:%d:%s %s", plr->xp, plr->hp, plr->max_hp, plr->level, plr->location_id, plr->pw_hash, plr->name); return err; @@ -119,6 +115,7 @@ int deserialize_player(FILE* fp, player_t* plr) { if (fp == NULL) { perror("can't open player file"); + error("Can't open player file"); return -1; } |