From 8054a145cc1d20ca01a26eee1332ddc3aeb2b3ae Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Feb 2016 18:21:39 +0100 Subject: [PATCH] hack to read passwords from an external file --- src/kernel/save.c | 23 ++++++++++++++++++++++- src/kernel/version.h | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 2f2b1ce29..cce5b0a61 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1156,6 +1156,23 @@ void write_spellbook(const struct spellbook *book, struct storage *store) WRITE_TOK(store, "end"); } +char * getpasswd(int fno) { + const char *prefix = itoa36(fno); + size_t len = strlen(prefix); + FILE * F = fopen("passwords.txt", "r"); + char line[80]; + if (F) { + while (!feof(F)) { + fgets(line, sizeof(line), F); + if (line[len+1]==':' && strncmp(prefix, line, len)==0) { + fclose(F); + return _strdup(line+len+1); + } + } + fclose(F); + } + return NULL; +} /** Reads a faction from a file. * This function requires no context, can be called in any state. The * faction may not already exist, however. @@ -1223,7 +1240,11 @@ faction *readfaction(struct gamedata * data) } READ_STR(data->store, name, sizeof(name)); - f->passw = _strdup(name); + if (data->version < CRYPT_VERSION) { + f->passw = _strdup(name); + } else { + f->passw = getpasswd(f->no); + } if (data->version < NOOVERRIDE_VERSION) { READ_STR(data->store, 0, 0); } diff --git a/src/kernel/version.h b/src/kernel/version.h index 19c564c1e..a7a913099 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -33,9 +33,9 @@ #define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */ #define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */ #define ATTRIBOWNER_VERSION 350 /* all attrib_type functions know who owns the attribute */ - +#define CRYPT_VERSION 351 /* passwords are encrypted */ #define RELEASE_VERSION ATTRIBOWNER_VERSION /* current datafile */ #define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */ -#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ +#define MAX_VERSION CRYPT_VERSION /* change this if we can need to read the future datafile, and we can do so */ #define STREAM_VERSION 2 /* internal encoding of binary files */