From ccc555668210151db807f338ee619b9f9870f58b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 24 Sep 2018 20:18:21 +0200 Subject: [PATCH] adding code to export faction information. sqlite3 implementation only, not tied to anything yet. add faction.uid remove faction.subscription --- src/battle.c | 2 +- src/bind_faction.c | 6 +- src/bindings.c | 8 --- src/eressea.c | 12 ++++ src/eressea.h | 1 + src/gmtool.c | 3 +- src/kernel/CMakeLists.txt | 16 ++--- src/kernel/connection.c | 2 +- src/kernel/database.c | 5 ++ src/kernel/database.h | 2 + src/kernel/database.test.c | 16 +++++ src/kernel/db/berkeley.c | 5 ++ src/kernel/db/critbit.c | 5 ++ src/kernel/db/driver.h | 1 + src/kernel/db/sqlite.c | 137 ++++++++++++++++++++++++++++--------- src/kernel/faction.c | 8 +-- src/kernel/faction.h | 4 +- src/kernel/faction.test.c | 3 +- src/kernel/save.c | 8 ++- src/laws.c | 27 -------- src/laws.h | 1 - src/main.c | 1 + src/modules/autoseed.c | 12 ++-- src/modules/autoseed.h | 2 +- src/spells.c | 2 +- src/tests.c | 2 +- src/util/gamedata.h | 3 +- 27 files changed, 190 insertions(+), 104 deletions(-) diff --git a/src/battle.c b/src/battle.c index bf9df9b2b..aa5de9f71 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3659,7 +3659,7 @@ static bool is_calmed(const unit *u, const faction *f) { while (a && a->type == &at_curse) { curse *c = (curse *)a->data.v; - if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->subscription) { + if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->uid) { if (curse_active(c)) { return true; } diff --git a/src/bind_faction.c b/src/bind_faction.c index e113d924c..850679933 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -432,7 +432,7 @@ static int tolua_faction_create(lua_State * L) faction *f = NULL; const struct race *frace = rc_find(racename ? racename : "human"); if (frace != NULL) { - f = addfaction(email, NULL, frace, loc, 0); + f = addfaction(email, NULL, frace, loc); } if (!f) { log_error("cannot create %s faction for %s, unknown race.", racename, email); @@ -528,14 +528,14 @@ static int tolua_faction_set_name(lua_State * L) static int tolua_faction_get_uid(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); - lua_pushinteger(L, f->subscription); + lua_pushinteger(L, f->uid); return 1; } static int tolua_faction_set_uid(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); - f->subscription = (int)tolua_tonumber(L, 2, 0); + f->uid = (int)tolua_tonumber(L, 2, 0); return 0; } diff --git a/src/bindings.c b/src/bindings.c index 60519260a..c549a4801 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -339,13 +339,6 @@ static int tolua_update_owners(lua_State * L) return 0; } -static int tolua_update_subscriptions(lua_State * L) -{ - UNUSED_ARG(L); - update_subscriptions(); - return 0; -} - static int tolua_remove_empty_units(lua_State * L) { UNUSED_ARG(L); @@ -972,7 +965,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs); tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units); - tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions); tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores); tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners); tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill); diff --git a/src/eressea.c b/src/eressea.c index 0bf1454ee..67ab26af5 100644 --- a/src/eressea.c +++ b/src/eressea.c @@ -39,6 +39,18 @@ /* manually free() everything at exit? */ #undef CLEANUP_CODE +void game_write_dbstate(void) +{ + faction *f; + + for (f = factions; f; f = f->next) { + int uid = dblib_save_faction(f, turn); + if (uid > 0) { + f->uid = uid; + } + } +} + void game_done(void) { log_dead_factions(); diff --git a/src/eressea.h b/src/eressea.h index f3ea4d4a5..cfc1b12ef 100755 --- a/src/eressea.h +++ b/src/eressea.h @@ -6,6 +6,7 @@ extern "C" { void game_init(void); void game_done(void); + void game_write_dbstate(void); #ifdef __cplusplus } diff --git a/src/gmtool.c b/src/gmtool.c index e4eefd337..f841fa305 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -920,8 +920,7 @@ static void seed_player(state *st, const newfaction *player) { if (r) { faction *f; addplayer(r, f = addfaction(player->email, player->password, - player->race, player->lang, - player->subscription)); + player->race, player->lang)); } } } diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 86c2fb90c..db448bf11 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -1,6 +1,14 @@ cmake_minimum_required(VERSION 2.6) project(kernel C) +SET(_DBFILES db/critbit.c) + +IF(SQLITE3_FOUND) +SET(_DBFILES db/sqlite.c) +ELSEIF(DB_FOUND) +SET(_DBFILES db/berkeley.c) +ENDIF(SQLITE3_FOUND) + SET(_TEST_FILES alliance.test.c ally.test.c @@ -35,14 +43,6 @@ spell.test.c unit.test.c ) -SET(_DBFILES db/critbit.c) - -IF(SQLITE3_FOUND) -SET(_DBFILES db/sqlite.c) -ELSEIF(DB_FOUND) -SET(_DBFILES db/berkeley.c) -ENDIF(SQLITE3_FOUND) - SET(_FILES ${_DBFILES} alliance.c diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 213700fe1..ddaf163c1 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -440,7 +440,7 @@ static const char *b_nameillusionwall(const connection * b, const region * r, return (f && fno == f->no) ? "illusionwall" : "wall"; if (gflags & GF_ARTICLE) { return LOC(f->locale, mkname("border", (f - && fno == f->subscription) ? "an_illusionwall" : "a_wall")); + && fno == f->uid) ? "an_illusionwall" : "a_wall")); } return LOC(f->locale, mkname("border", (f && fno == f->no) ? "illusionwall" : "wall")); diff --git a/src/kernel/database.c b/src/kernel/database.c index eaf695613..c27ca21fc 100644 --- a/src/kernel/database.c +++ b/src/kernel/database.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -27,6 +28,10 @@ int dblib_save_order(order_data *od) return 0; } +int dblib_save_faction(const faction *f, int turn) { + return db_driver_faction_save(f->uid, f->no, turn, f->email, f->_password); +} + void dblib_open(void) { db_driver_open(); diff --git a/src/kernel/database.h b/src/kernel/database.h index 0dd5a70fb..e3bdf11d1 100644 --- a/src/kernel/database.h +++ b/src/kernel/database.h @@ -8,12 +8,14 @@ extern "C" { #endif struct order_data; + struct faction; void dblib_open(void); void dblib_close(void); struct order_data *dblib_load_order(int id); int dblib_save_order(struct order_data *od); + int dblib_save_faction(const struct faction *f, int turn); #ifdef __cplusplus } diff --git a/src/kernel/database.test.c b/src/kernel/database.test.c index 2e1104185..cde4edc11 100644 --- a/src/kernel/database.test.c +++ b/src/kernel/database.test.c @@ -1,5 +1,6 @@ #include #include +#include #include "database.h" #include "orderdb.h" @@ -7,6 +8,7 @@ #include #include +#include #include static void test_save_load_order(CuTest *tc) { @@ -31,10 +33,24 @@ static void test_save_load_order(CuTest *tc) { test_teardown(); } +static void test_update_faction(CuTest *tc) { + faction *f; + int uid; + + test_setup(); + f = test_create_faction(NULL); + uid = dblib_save_faction(f, 0); + f->uid = uid; + uid = dblib_save_faction(f, 0); + CuAssertIntEquals(tc, f->uid, uid); + test_teardown(); +} + CuSuite *get_db_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_save_load_order); + SUITE_ADD_TEST(suite, test_update_faction); return suite; } diff --git a/src/kernel/db/berkeley.c b/src/kernel/db/berkeley.c index 210c36f01..778e0bfe7 100644 --- a/src/kernel/db/berkeley.c +++ b/src/kernel/db/berkeley.c @@ -53,6 +53,11 @@ int db_driver_order_save(struct order_data *od) return (int)recno; } +int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password) +{ + return -1; +} + struct order_data *db_driver_order_load(int id) { int ret; diff --git a/src/kernel/db/critbit.c b/src/kernel/db/critbit.c index 9afb0926d..69bac159e 100644 --- a/src/kernel/db/critbit.c +++ b/src/kernel/db/critbit.c @@ -44,6 +44,11 @@ int db_driver_order_save(order_data *od) return ent.id; } +int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password) +{ + return -1; +} + static int free_data_cb(const void *match, const void *key, size_t keylen, void *udata) { diff --git a/src/kernel/db/driver.h b/src/kernel/db/driver.h index df839b93d..1e408e37e 100644 --- a/src/kernel/db/driver.h +++ b/src/kernel/db/driver.h @@ -6,3 +6,4 @@ void db_driver_open(void); void db_driver_close(void); int db_driver_order_save(struct order_data *od); struct order_data *db_driver_order_load(int id); +int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password); diff --git a/src/kernel/db/sqlite.c b/src/kernel/db/sqlite.c index b3090cca0..49dbd001e 100644 --- a/src/kernel/db/sqlite.c +++ b/src/kernel/db/sqlite.c @@ -15,9 +15,12 @@ #include #include -static sqlite3 *g_db; -static sqlite3_stmt * g_stmt_insert; -static sqlite3_stmt * g_stmt_select; +static sqlite3 *g_game_db; +static sqlite3 *g_temp_db; +static sqlite3_stmt * g_stmt_insert_order; +static sqlite3_stmt * g_stmt_select_order; +static sqlite3_stmt * g_stmt_update_faction; +static sqlite3_stmt * g_stmt_insert_faction; static int g_order_batchsize; static int g_order_tx_size; @@ -30,21 +33,21 @@ order_data *db_driver_order_load(int id) ERRNO_CHECK(); if (g_order_tx_size > 0) { g_order_tx_size = 0; - err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL); + err = sqlite3_exec(g_temp_db, "COMMIT", NULL, NULL, NULL); assert(err == SQLITE_OK); } - err = sqlite3_reset(g_stmt_select); + err = sqlite3_reset(g_stmt_select_order); assert(err == SQLITE_OK); - err = sqlite3_bind_int(g_stmt_select, 1, id); + err = sqlite3_bind_int(g_stmt_select_order, 1, id); assert(err == SQLITE_OK); do { - err = sqlite3_step(g_stmt_select); + err = sqlite3_step(g_stmt_select_order); if (err == SQLITE_ROW) { const unsigned char *text; int bytes; - bytes = sqlite3_column_bytes(g_stmt_select, 0); + bytes = sqlite3_column_bytes(g_stmt_select_order, 0); assert(bytes > 0); - text = sqlite3_column_text(g_stmt_select, 0); + text = sqlite3_column_text(g_stmt_select_order, 0); odata_create(&od, 1+(size_t)bytes, (const char *)text); ERRNO_CHECK(); return od; @@ -66,23 +69,23 @@ int db_driver_order_save(order_data *od) if (g_order_batchsize > 0) { if (g_order_tx_size == 0) { - err = sqlite3_exec(g_db, "BEGIN TRANSACTION", NULL, NULL, NULL); + err = sqlite3_exec(g_temp_db, "BEGIN TRANSACTION", NULL, NULL, NULL); assert(err == SQLITE_OK); } } - err = sqlite3_reset(g_stmt_insert); + err = sqlite3_reset(g_stmt_insert_order); assert(err == SQLITE_OK); - err = sqlite3_bind_text(g_stmt_insert, 1, od->_str, -1, SQLITE_STATIC); + err = sqlite3_bind_text(g_stmt_insert_order, 1, od->_str, -1, SQLITE_STATIC); assert(err == SQLITE_OK); - err = sqlite3_step(g_stmt_insert); + err = sqlite3_step(g_stmt_insert_order); assert(err == SQLITE_DONE); - id = sqlite3_last_insert_rowid(g_db); + id = sqlite3_last_insert_rowid(g_temp_db); assert(id <= INT_MAX); if (g_order_batchsize > 0) { if (++g_order_tx_size >= g_order_batchsize) { - err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL); + err = sqlite3_exec(g_temp_db, "COMMIT", NULL, NULL, NULL); assert(err == SQLITE_OK); g_order_tx_size = 0; } @@ -91,29 +94,89 @@ int db_driver_order_save(order_data *od) return (int)id; } + +int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password) +{ + sqlite3_int64 row_id; + int err; + + if (!g_game_db) { + return -1; + } + if (id != 0) { + int rows; + + err = sqlite3_reset(g_stmt_update_faction); + assert(err == SQLITE_OK); + err = sqlite3_bind_int(g_stmt_update_faction, 1, no); + assert(err == SQLITE_OK); + err = sqlite3_bind_int(g_stmt_update_faction, 2, turn); + assert(err == SQLITE_OK); + err = sqlite3_bind_text(g_stmt_update_faction, 3, email, -1, SQLITE_STATIC); + assert(err == SQLITE_OK); + err = sqlite3_bind_text(g_stmt_update_faction, 4, password, -1, SQLITE_STATIC); + assert(err == SQLITE_OK); + err = sqlite3_bind_int(g_stmt_update_faction, 5, id); + assert(err == SQLITE_OK); + err = sqlite3_step(g_stmt_update_faction); + assert(err == SQLITE_DONE); + rows = sqlite3_changes(g_game_db); + if (rows != 0) { + return id; + } + } + err = sqlite3_reset(g_stmt_insert_faction); + assert(err == SQLITE_OK); + err = sqlite3_bind_int(g_stmt_insert_faction, 1, no); + assert(err == SQLITE_OK); + err = sqlite3_bind_int(g_stmt_insert_faction, 2, turn); + assert(err == SQLITE_OK); + err = sqlite3_bind_text(g_stmt_insert_faction, 3, email, -1, SQLITE_STATIC); + assert(err == SQLITE_OK); + err = sqlite3_bind_text(g_stmt_insert_faction, 4, password, -1, SQLITE_STATIC); + assert(err == SQLITE_OK); + err = sqlite3_step(g_stmt_insert_faction); + assert(err == SQLITE_DONE); + ERRNO_CHECK(); + + row_id = sqlite3_last_insert_rowid(g_game_db); + assert(row_id <= INT_MAX); + return (int)row_id; +} + void db_driver_open(void) { int err; - const char *dbname; + const char *dbname, *dbtemp; ERRNO_CHECK(); - g_order_batchsize = config_get_int("game.dbbatch", 100); + dbname = config_get("game.dbname"); - if (!dbname) { - dbname = ""; - } - err = sqlite3_open(dbname, &g_db); + if (!dbname) dbname = ""; + err = sqlite3_open(dbname, &g_game_db); assert(err == SQLITE_OK); - err = sqlite3_exec(g_db, "PRAGMA journal_mode=OFF", NULL, NULL, NULL); + err = sqlite3_exec(g_game_db, "CREATE TABLE IF NOT EXISTS factions (id INTEGER PRIMARY KEY, no INTEGER NOT NULL, email VARCHAR(128), password VARCHAR(128), turn INTEGER NOT NULL)", NULL, NULL, NULL); assert(err == SQLITE_OK); - err = sqlite3_exec(g_db, "PRAGMA synchronous=OFF", NULL, NULL, NULL); + err = sqlite3_prepare_v2(g_game_db, "UPDATE factions SET no=?, turn=?, email=?, password=? WHERE id=?", -1, &g_stmt_update_faction, NULL); assert(err == SQLITE_OK); - err = sqlite3_exec(g_db, "CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY, data TEXT NOT NULL)", NULL, NULL, NULL); + err = sqlite3_prepare_v2(g_game_db, "INSERT INTO factions (no, turn, email, password) VALUES (?,?,?,?)", -1, &g_stmt_insert_faction, NULL); assert(err == SQLITE_OK); - err = sqlite3_prepare_v2(g_db, "INSERT INTO orders (data) VALUES (?)", -1, &g_stmt_insert, NULL); + + g_order_batchsize = config_get_int("game.dbbatch", 100); + dbtemp = config_get("game.db.temp"); + err = sqlite3_open(dbtemp ? dbtemp : dbname, &g_temp_db); assert(err == SQLITE_OK); - err = sqlite3_prepare_v2(g_db, "SELECT data FROM orders WHERE id = ?", -1, &g_stmt_select, NULL); + err = sqlite3_exec(g_temp_db, "PRAGMA journal_mode=OFF", NULL, NULL, NULL); assert(err == SQLITE_OK); + err = sqlite3_exec(g_temp_db, "PRAGMA synchronous=OFF", NULL, NULL, NULL); + assert(err == SQLITE_OK); + err = sqlite3_exec(g_temp_db, "CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY, data TEXT NOT NULL)", NULL, NULL, NULL); + assert(err == SQLITE_OK); + err = sqlite3_prepare_v2(g_temp_db, "INSERT INTO orders (data) VALUES (?)", -1, &g_stmt_insert_order, NULL); + assert(err == SQLITE_OK); + err = sqlite3_prepare_v2(g_temp_db, "SELECT data FROM orders WHERE id=?", -1, &g_stmt_select_order, NULL); + assert(err == SQLITE_OK); + ERRNO_CHECK(); } @@ -122,12 +185,22 @@ void db_driver_close(void) int err; ERRNO_CHECK(); - err = sqlite3_finalize(g_stmt_select); - assert(err == SQLITE_OK); - err = sqlite3_finalize(g_stmt_insert); - assert(err == SQLITE_OK); - err = sqlite3_close(g_db); - assert(err == SQLITE_OK); + if (g_temp_db) { + err = sqlite3_finalize(g_stmt_select_order); + assert(err == SQLITE_OK); + err = sqlite3_finalize(g_stmt_insert_order); + assert(err == SQLITE_OK); + err = sqlite3_close(g_temp_db); + assert(err == SQLITE_OK); + } + if (g_game_db) { + err = sqlite3_finalize(g_stmt_update_faction); + assert(err == SQLITE_OK); + err = sqlite3_finalize(g_stmt_insert_faction); + assert(err == SQLITE_OK); + err = sqlite3_close(g_game_db); + assert(err == SQLITE_OK); + } ERRNO_CHECK(); } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b4dfe51ca..8c77984ba 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -230,7 +230,7 @@ static int unused_faction_id(void) } faction *addfaction(const char *email, const char *password, - const struct race * frace, const struct locale * loc, int subscription) + const struct race * frace, const struct locale * loc) { faction *f = calloc(sizeof(faction), 1); char buf[128]; @@ -249,7 +249,7 @@ faction *addfaction(const char *email, const char *password, f->race = frace; f->magiegebiet = 0; f->locale = loc; - f->subscription = subscription; + f->uid = 0; f->flags = FFL_ISNEW|FFL_PWMSG; if (!password) password = itoa36(rng_int()); @@ -393,7 +393,7 @@ faction *get_or_create_monsters(void) if (!f) { const race *rc = rc_get_or_create("dragon"); const char *email = config_get("monster.email"); - f = addfaction(email, NULL, rc, default_locale, 0); + f = addfaction(email, NULL, rc, default_locale); renumber_faction(f, MONSTER_ID); faction_setname(f, "Monster"); fset(f, FFL_NPC | FFL_NOIDLEOUT); @@ -839,7 +839,7 @@ int writepasswd(void) for (f = factions; f; f = f->next) { fprintf(F, "%s:%s:%s:%d\n", - itoa36(f->no), faction_getemail(f), f->_password, f->subscription); + itoa36(f->no), faction_getemail(f), f->_password, f->uid); } fclose(F); return 0; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 8d13f64d1..63c5a9993 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -61,7 +61,7 @@ extern "C" { struct region *first; struct region *last; int no; - int subscription; + int uid; int flags; char *name; char *banner; @@ -112,7 +112,7 @@ extern "C" { const char *factionname(const struct faction *f); struct unit *addplayer(struct region *r, faction * f); struct faction *addfaction(const char *email, const char *password, - const struct race *frace, const struct locale *loc, int subscription); + const struct race *frace, const struct locale *loc); bool checkpasswd(const faction * f, const char *passwd); int writepasswd(void); void destroyfaction(faction ** f); diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 37ec70e50..6f3c5cfaf 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -112,7 +112,7 @@ static void test_addfaction(CuTest *tc) { test_setup(); rc = rc_get_or_create("human"); lang = test_create_locale(); - f = addfaction("test@eressea.de", "hurrdurr", rc, lang, 1234); + f = addfaction("test@eressea.de", "hurrdurr", rc, lang); CuAssertPtrNotNull(tc, f); CuAssertPtrNotNull(tc, f->name); CuAssertPtrEquals(tc, NULL, (void *)f->units); @@ -124,7 +124,6 @@ static void test_addfaction(CuTest *tc) { CuAssertStrEquals(tc, "test@eressea.de", f->email); CuAssertTrue(tc, checkpasswd(f, "hurrdurr")); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); - CuAssertIntEquals(tc, 1234, f->subscription); CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags); CuAssertIntEquals(tc, 0, f->age); CuAssertTrue(tc, faction_alive(f)); diff --git a/src/kernel/save.c b/src/kernel/save.c index 51585f26c..922fcc24f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -969,7 +969,10 @@ faction *read_faction(gamedata * data) a_remove(&f->attribs, f->attribs); } } - READ_INT(data->store, &f->subscription); + READ_INT(data->store, &f->uid); + if (data->version < FACTION_UID_VERSION) { + f->uid = 0; + } if (data->version >= SPELL_LEVEL_VERSION) { READ_INT(data->store, &f->max_spelllevel); @@ -1100,7 +1103,7 @@ void write_faction(gamedata *data, const faction * f) assert(f->_alive); assert(f->no > 0 && f->no <= MAX_UNIT_NR); WRITE_INT(data->store, f->no); - WRITE_INT(data->store, f->subscription); + WRITE_INT(data->store, f->uid); #if RELEASE_VERSION >= SPELL_LEVEL_VERSION WRITE_INT(data->store, f->max_spelllevel); #endif @@ -1681,6 +1684,5 @@ int write_game(gamedata *data) { WRITE_SECTION(store); write_borders(store); WRITE_SECTION(store); - return 0; } diff --git a/src/laws.c b/src/laws.c index 922f4c366..fe97931ad 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3974,33 +3974,6 @@ void turn_end(void) update_spells(); } -void update_subscriptions(void) -{ - FILE *F; - char zText[4096]; - - path_join(basepath(), "subscriptions", zText, sizeof(zText)); - F = fopen(zText, "r"); - if (F == NULL) { - log_warning(0, "could not open %s.\n", zText); - return; - } - for (;;) { - char zFaction[5]; - int subscription, fno; - faction *f; - - if (fscanf(F, "%4d %4s", &subscription, zFaction) <= 0) - break; - fno = atoi36(zFaction); - f = findfaction(fno); - if (f != NULL) { - f->subscription = subscription; - } - } - fclose(F); -} - /** determine if unit can be seen by faction * @param f -- the observiong faction * @param u -- the unit that is observed diff --git a/src/laws.h b/src/laws.h index b7958891f..383b099ae 100755 --- a/src/laws.h +++ b/src/laws.h @@ -41,7 +41,6 @@ extern "C" { void demographics(void); void immigration(void); void update_guards(void); - void update_subscriptions(void); void deliverMail(struct faction *f, struct region *r, struct unit *u, const char *s, struct unit *receiver); diff --git a/src/main.c b/src/main.c index 599fbdd67..eae7f440c 100644 --- a/src/main.c +++ b/src/main.c @@ -96,6 +96,7 @@ static const char * valid_keys[] = { "game.era", "game.sender", "game.dbname", + "game.db.", "game.dbbatch", "editor.color", "editor.codepage", diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 374b6379c..df4e543ce 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -95,7 +95,7 @@ newfaction *read_newfactions(const char *filename) faction *f; char race[20], email[64], lang[8], password[16]; newfaction *nf, **nfi; - int alliance = 0, subscription = 0; + int alliance = 0, uid = 0; if (fgets(buf, sizeof(buf), F) == NULL) break; @@ -104,7 +104,7 @@ newfaction *read_newfactions(const char *filename) password[0] = '\0'; if (sscanf(buf, "%54s %19s %7s %15s %4d %4d", email, race, lang, - password, &subscription, &alliance) < 3) { + password, &uid, &alliance) < 3) { break; } if (email[0] == '#') { @@ -137,13 +137,13 @@ newfaction *read_newfactions(const char *filename) if (check_email(email) == 0) { nf->email = str_strdup(email); } else { - log_error("Invalid email address for subscription %s: %s\n", itoa36(subscription), email); + log_error("Invalid email address for subscription %s: %s\n", itoa36(uid), email); free(nf); continue; } nf->password = str_strdup(password); nf->race = rc_find(race); - nf->subscription = subscription; + nf->uid = uid; if (alliances != NULL) { struct alliance *al = findalliance(alliance); if (al == NULL) { @@ -557,7 +557,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) ++tsize; assert(r->land && r->units == 0); u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race, - nextf->lang, nextf->subscription)); + nextf->lang)); f = u->faction; fset(f, FFL_ISNEW); f->alliance = nextf->allies; @@ -857,7 +857,7 @@ static void starting_region(newfaction ** players, region * r, region * rn[]) const struct race *rc = nf->race ? nf->race : races; const struct locale *lang = nf->lang ? nf->lang : default_locale; const char * passwd = nf->password ? nf->password : itoa36(rng_int()); - addplayer(r, addfaction(nf->email, passwd, rc, lang, 0)); + addplayer(r, addfaction(nf->email, passwd, rc, lang)); *players = nf->next; free_newfaction(nf); } diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h index 937a1f8b5..74c7409ad 100644 --- a/src/modules/autoseed.h +++ b/src/modules/autoseed.h @@ -24,7 +24,7 @@ extern "C" { char *password; const struct locale *lang; const struct race *race; - int subscription; + int uid; bool oldregions; struct alliance *allies; } newfaction; diff --git a/src/spells.c b/src/spells.c index 8caf29039..02cbe43b5 100644 --- a/src/spells.c +++ b/src/spells.c @@ -4192,7 +4192,7 @@ static int sp_calm_monster(castorder * co) return 0; } - effect = mage->faction->subscription; + effect = mage->faction->uid; c = create_curse(mage, &target->attribs, &ct_calmmonster, force, (int)force, effect, 0); if (c == NULL) { diff --git a/src/tests.c b/src/tests.c index ddd6f7cf5..2dc5bccc6 100644 --- a/src/tests.c +++ b/src/tests.c @@ -166,7 +166,7 @@ struct locale * test_create_locale(void) { struct faction *test_create_faction(const struct race *rc) { struct locale * loc = test_create_locale(); - faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), loc, 0); + faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), loc); test_clear_messages(f); return f; } diff --git a/src/util/gamedata.h b/src/util/gamedata.h index 2dd4e1342..191dab054 100644 --- a/src/util/gamedata.h +++ b/src/util/gamedata.h @@ -37,10 +37,11 @@ #define SKILLSORT_VERSION 360 /* u->skills is sorted */ #define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */ #define FIXATKEYS_VERSION 361 /* remove global.attribs, fix at_keys */ +#define FACTION_UID_VERSION 362 /* f->uid contains a database id */ /* unfinished: */ #define CRYPT_VERSION 400 /* passwords are encrypted */ -#define RELEASE_VERSION FIXATKEYS_VERSION /* current datafile */ +#define RELEASE_VERSION FACTION_UID_VERSION /* current datafile */ #define MIN_VERSION UIDHASH_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 */