diff options
author | Cara Salter <cara@devcara.com> | 2022-01-28 15:50:38 -0500 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-01-28 15:50:38 -0500 |
commit | 4585ec623286900898a09b1714b3b5de38be4fec (patch) | |
tree | cd08eef867164c3c998485063e2af1ec55c51c5a /src/data.c | |
parent | aa80bc22117d385474c8593560368adf6b57f074 (diff) | |
download | cmud-4585ec623286900898a09b1714b3b5de38be4fec.tar.gz cmud-4585ec623286900898a09b1714b3b5de38be4fec.zip |
login: Add password authentication for registrations
Diffstat (limited to 'src/data.c')
-rw-r--r-- | src/data.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -6,6 +6,7 @@ #include <stdio.h> #include <string.h> #include <sys/stat.h> +#include <unistd.h> int try_make_data_dirs() { int err = 0; @@ -39,7 +40,6 @@ int try_load_plr(char *player_name, playerc_t *plr) { FILE *fp; if (fp = fopen(fname, "rb")) { - printf("%p", fp); printf("Got fp\n"); @@ -59,17 +59,24 @@ int try_write_plr(player_t *plr) { err = try_make_data_dirs(); if (err) { - perror("creating data directories"); - printf("Could not create data/\n"); - return err; + switch (err) { + // 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"); + return -1; + default: /* Do nothing because this is fine****************************/ + break; + } } char *fname; - asprintf(&fname, "data/players/%s.plr", *plr->name); + asprintf(&fname, "data/players/%s.plr", plr->name); FILE *fp = fopen(fname, "wb"); fwrite(&plr, sizeof(player_t), 1, fp); + fsync(fp); return err; } |