aboutsummaryrefslogtreecommitdiff
path: root/src/data.c
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-01-28 15:50:38 -0500
committerCara Salter <cara@devcara.com>2022-01-28 15:50:38 -0500
commit4585ec623286900898a09b1714b3b5de38be4fec (patch)
treecd08eef867164c3c998485063e2af1ec55c51c5a /src/data.c
parentaa80bc22117d385474c8593560368adf6b57f074 (diff)
downloadcmud-4585ec623286900898a09b1714b3b5de38be4fec.tar.gz
cmud-4585ec623286900898a09b1714b3b5de38be4fec.zip
login: Add password authentication for registrations
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/data.c b/src/data.c
index dabdee7..3884170 100644
--- a/src/data.c
+++ b/src/data.c
@@ -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;
}