From 1318c8976ab8201d116896e6643fb45527b496c2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 3 May 2014 19:53:59 +0200 Subject: [PATCH 1/3] e4 startup --- res/e4/main.lua | 61 ++++++++++++++++++++++++++++++++++++++++++++++ res/e4/modules.lua | 4 +++ 2 files changed, 65 insertions(+) create mode 100644 res/e4/main.lua create mode 100644 res/e4/modules.lua diff --git a/res/e4/main.lua b/res/e4/main.lua new file mode 100644 index 000000000..813e0f55a --- /dev/null +++ b/res/e4/main.lua @@ -0,0 +1,61 @@ +require "multis" +require "e3a.frost" + +function process(orders) + local confirmed_multis = { } + local suspected_multis = { } + + if open_game(get_turn())~=0 then + print("could not read game") + return -1 + end + init_summary() + + -- run the turn: + if read_orders(orders) ~= 0 then + print("could not read " .. orders) + return -1 + end + + -- plan_monsters() + local mon = get_faction(666) + if mon ~= nil then + mon.lastturn = get_turn() + end + + if nmr_check(config.maxnmrs or 30)~=0 then + return -1 + end + + process_orders() + if xmas2009~=nil then + xmas2009() + end + + -- create new monsters: + spawn_dragons() + spawn_undead() + + if get_turn()>=config.kill_after then + kill_nonstarters() + end + -- post-turn updates: + update_guards() + update_scores() + frost.update() + + local localechange = { en = { "L46o" } } + change_locales(localechange) + + -- use newfactions file to place out new players + -- autoseed(config.basepath .. "/newfactions", false) + + write_files(config.locales) + + file = "" .. get_turn() .. ".dat" + if eressea.write_game(file)~=0 then + print("could not write game") + return -1 + end + return 0 +end diff --git a/res/e4/modules.lua b/res/e4/modules.lua new file mode 100644 index 000000000..39a1d7ca0 --- /dev/null +++ b/res/e4/modules.lua @@ -0,0 +1,4 @@ +require "spells" +require "e3a.rules" +require "e3a.markets" +require "e3a.frost" From cb458db9a1b89721be4a47157d34c285977d2aef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 4 May 2014 22:49:06 +0200 Subject: [PATCH 2/3] updating eressea.db, not with a fixed game-id --- src/bind_sqlite.c | 5 +- src/kernel/config.c | 8 +- src/kernel/config.h | 1 + src/kernel/sqlite.c | 232 +++++++++++++++++++++++--------------------- 4 files changed, 130 insertions(+), 116 deletions(-) diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c index 6f6c5ea29..b164068aa 100644 --- a/src/bind_sqlite.c +++ b/src/bind_sqlite.c @@ -15,16 +15,17 @@ without prior permission by the authors of Eressea. #include "bind_unit.h" #include "bindings.h" +#include #include #include #define LTYPE_DB TOLUA_CAST "db" -extern int db_update_factions(sqlite3 * db, bool force); +extern int db_update_factions(sqlite3 * db, bool force, int game); static int tolua_db_update_factions(lua_State * L) { sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0); - db_update_factions(db, tolua_toboolean(L, 2, 0)); + db_update_factions(db, tolua_toboolean(L, 2, 0), global.game_id); return 0; } diff --git a/src/kernel/config.c b/src/kernel/config.c index 41e994e5c..6822d42d0 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -93,6 +93,7 @@ struct settings global = { "Eressea", /* gamename */ }; +bool lomem = false; FILE *logfile; FILE *updatelog; const struct race *new_race[MAXRACES]; @@ -1578,10 +1579,6 @@ void freestrlist(strlist * s) } } -/* - Meldungen und Fehler ------------------------------------------------- */ - -bool lomem = false; - /* - Namen der Strukturen -------------------------------------- */ typedef char name[OBJECTIDSIZE + 1]; static name idbuf[8]; @@ -3168,7 +3165,6 @@ void load_inifile(dictionary * d) make_locales(str); /* excerpt from [config] (the rest is used in bindings.c) */ - game_name = iniparser_getstring(d, "config:game", game_name); - + global.game_id = iniparser_getint(d, "config:game_id", 0); global.inifile = d; } diff --git a/src/kernel/config.h b/src/kernel/config.h index b7c7e053c..885684d99 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -393,6 +393,7 @@ extern "C" { void *vm_state; float producexpchance; int cookie; + int game_id; int data_version; /* TODO: eliminate in favor of gamedata.version */ struct _dictionary_ *inifile; diff --git a/src/kernel/sqlite.c b/src/kernel/sqlite.c index cb9e8b903..a84cea6b2 100644 --- a/src/kernel/sqlite.c +++ b/src/kernel/sqlite.c @@ -129,117 +129,133 @@ db_update_email(sqlite3 * db, const faction * f, const db_faction * dbstate, return SQLITE_OK; } - -int db_update_factions(sqlite3 * db, bool force) -{ - int game_id = 6; - const char sql_select[] = - "SELECT faction.id, faction.email_id, faction.code, email.email, faction.password_md5, faction.name, faction.lastturn FROM email, faction" - " WHERE email.id=faction.email_id AND faction.game_id=? AND (lastturn IS NULL OR lastturn>?)"; - sqlite3_stmt *stmt_select = stmt_cache_get(db, sql_select); - faction *f; - int res; - - res = sqlite3_bind_int(stmt_select, 1, game_id); - SQL_EXPECT(res, SQLITE_OK); - res = sqlite3_bind_int(stmt_select, 2, turn - 2); - SQL_EXPECT(res, SQLITE_OK); - for (;;) { - sqlite3_uint64 id_faction; - int lastturn; - +/* +int db_get_game(sqlite3 *db) { + int game_id = 0; + const char sql_game[] = + "SELECT id FROM game WHERE name=?"; + sqlite3_stmt *stmt_game = stmt_cache(db, sql_game); + res = sqlite3_bind_text(stmt_game, 1, gamename, -1, SQLITE_TRANSIENT); + SQL_EXPECT(res, SQLITE_OK); res = sqlite3_step(stmt_select); - if (res != SQLITE_ROW) - break; - - id_faction = sqlite3_column_int64(stmt_select, 0); - lastturn = sqlite3_column_int(stmt_select, 6); - f = get_faction_by_id((int)id_faction); - - if (f == NULL || !f->alive) { - if (lastturn == 0) { - const char sql_update[] = "UPDATE faction SET lastturn=? WHERE id=?"; - sqlite3_stmt *stmt = stmt_cache_get(db, sql_update); - - lastturn = f ? f->lastorders : turn - 1; - sqlite3_bind_int(stmt, 1, lastturn); - sqlite3_bind_int64(stmt, 2, id_faction); - res = sqlite3_step(stmt); - SQL_EXPECT(res, SQLITE_DONE); - } - } else { - md5_state_t ms; - md5_byte_t digest[16]; - int i; - char passwd_md5[MD5_LENGTH_0]; - sqlite3_uint64 id_email; - bool update = force; - db_faction dbstate; - const char *no_b36; - - fset(f, FFL_MARK); - dbstate.id_faction = id_faction; - dbstate.id_email = sqlite3_column_int64(stmt_select, 1); - no_b36 = (const char *)sqlite3_column_text(stmt_select, 2); - dbstate.no = no_b36 ? atoi36(no_b36) : -1; - dbstate.email = (const char *)sqlite3_column_text(stmt_select, 3); - dbstate.passwd_md5 = (const char *)sqlite3_column_text(stmt_select, 4); - dbstate.name = (const char *)sqlite3_column_text(stmt_select, 5); - - id_email = dbstate.id_email; - res = db_update_email(db, f, &dbstate, force, &id_email); - SQL_EXPECT(res, SQLITE_OK); - - md5_init(&ms); - md5_append(&ms, (md5_byte_t *) f->passw, (int)strlen(f->passw)); - md5_finish(&ms, digest); - for (i = 0; i != 16; ++i) - sprintf(passwd_md5 + 2 * i, "%.02x", digest[i]); - - if (!update) { - update = ((id_email != 0 && dbstate.id_email != id_email) - || dbstate.no != f->no || dbstate.passwd_md5 == NULL - || strcmp(passwd_md5, dbstate.passwd_md5) != 0 || dbstate.name == NULL - || strncmp(f->name, dbstate.name, MAX_FACTION_NAME) != 0); - } - if (update) { - const char sql_update_faction[] = - "UPDATE faction SET email_id=?, password_md5=?, code=?, name=?, firstturn=? WHERE id=?"; - sqlite3_stmt *stmt_update_faction = - stmt_cache_get(db, sql_update_faction); - - res = sqlite3_bind_int64(stmt_update_faction, 1, id_email); - SQL_EXPECT(res, SQLITE_OK); - res = - sqlite3_bind_text(stmt_update_faction, 2, passwd_md5, MD5_LENGTH, - SQLITE_TRANSIENT); - SQL_EXPECT(res, SQLITE_OK); - res = - sqlite3_bind_text(stmt_update_faction, 3, no_b36, -1, - SQLITE_TRANSIENT); - SQL_EXPECT(res, SQLITE_OK); - res = - sqlite3_bind_text(stmt_update_faction, 4, f->name, -1, - SQLITE_TRANSIENT); - SQL_EXPECT(res, SQLITE_OK); - res = sqlite3_bind_int(stmt_update_faction, 5, turn - f->age); - SQL_EXPECT(res, SQLITE_OK); - res = sqlite3_bind_int64(stmt_update_faction, 6, f->subscription); - SQL_EXPECT(res, SQLITE_OK); - res = sqlite3_step(stmt_update_faction); - SQL_EXPECT(res, SQLITE_DONE); - } + return game_id; +} +*/ +int db_update_factions(sqlite3 * db, bool force, int game_id) +{ + const char sql_select[] = + "SELECT faction.id, faction.email_id, faction.code, email.email, faction.password_md5, faction.name, faction.lastturn FROM email, faction" + " WHERE email.id=faction.email_id AND faction.game_id=? AND (lastturn IS NULL OR lastturn>?)"; + sqlite3_stmt *stmt_select = stmt_cache_get(db, sql_select); + faction *f; + int res; + + res = sqlite3_bind_int(stmt_select, 1, game_id); + SQL_EXPECT(res, SQLITE_OK); + res = sqlite3_bind_int(stmt_select, 2, turn - 2); + SQL_EXPECT(res, SQLITE_OK); + for (;;) { + sqlite3_uint64 id_faction; + int lastturn; + const char * no_b36; + + res = sqlite3_step(stmt_select); + if (res != SQLITE_ROW) + break; + + id_faction = sqlite3_column_int64(stmt_select, 0); + lastturn = sqlite3_column_int(stmt_select, 6); + no_b36 = (const char *)sqlite3_column_text(stmt_select, 2); + f = get_faction_by_id((int)id_faction); + if (!f) { + int no = atoi36(no_b36); + f = findfaction(no); + if (f) { + f->subscription = (int)id_faction; + } + } + if (!f || !f->alive) { + if (lastturn == 0) { + const char sql_update[] = "UPDATE faction SET lastturn=? WHERE id=?"; + sqlite3_stmt *stmt = stmt_cache_get(db, sql_update); + + lastturn = f ? f->lastorders : turn - 1; + sqlite3_bind_int(stmt, 1, lastturn); + sqlite3_bind_int64(stmt, 2, id_faction); + res = sqlite3_step(stmt); + SQL_EXPECT(res, SQLITE_DONE); + } + } else { + md5_state_t ms; + md5_byte_t digest[16]; + int i; + char passwd_md5[MD5_LENGTH_0]; + sqlite3_uint64 id_email; + bool update = force; + db_faction dbstate; + + fset(f, FFL_MARK); + dbstate.id_faction = id_faction; + dbstate.id_email = sqlite3_column_int64(stmt_select, 1); + dbstate.no = no_b36 ? atoi36(no_b36) : -1; + dbstate.email = (const char *)sqlite3_column_text(stmt_select, 3); + dbstate.passwd_md5 = (const char *)sqlite3_column_text(stmt_select, 4); + dbstate.name = (const char *)sqlite3_column_text(stmt_select, 5); + + id_email = dbstate.id_email; + res = db_update_email(db, f, &dbstate, force, &id_email); + SQL_EXPECT(res, SQLITE_OK); + + md5_init(&ms); + md5_append(&ms, (md5_byte_t *) f->passw, (int)strlen(f->passw)); + md5_finish(&ms, digest); + for (i = 0; i != 16; ++i) + sprintf(passwd_md5 + 2 * i, "%.02x", digest[i]); + + if (!update) { + update = ((id_email != 0 && dbstate.id_email != id_email) + || dbstate.no != f->no || dbstate.passwd_md5 == NULL + || strcmp(passwd_md5, dbstate.passwd_md5) != 0 || dbstate.name == NULL + || strncmp(f->name, dbstate.name, MAX_FACTION_NAME) != 0); + } + if (update) { + const char sql_update_faction[] = + "UPDATE faction SET email_id=?, password_md5=?, code=?, name=?, firstturn=? WHERE id=?"; + sqlite3_stmt *stmt_update_faction = + stmt_cache_get(db, sql_update_faction); + + res = sqlite3_bind_int64(stmt_update_faction, 1, id_email); + SQL_EXPECT(res, SQLITE_OK); + res = + sqlite3_bind_text(stmt_update_faction, 2, passwd_md5, MD5_LENGTH, + SQLITE_TRANSIENT); + SQL_EXPECT(res, SQLITE_OK); + res = + sqlite3_bind_text(stmt_update_faction, 3, no_b36, -1, + SQLITE_TRANSIENT); + SQL_EXPECT(res, SQLITE_OK); + res = + sqlite3_bind_text(stmt_update_faction, 4, f->name, -1, + SQLITE_TRANSIENT); + SQL_EXPECT(res, SQLITE_OK); + res = sqlite3_bind_int(stmt_update_faction, 5, turn - f->age); + SQL_EXPECT(res, SQLITE_OK); + res = sqlite3_bind_int64(stmt_update_faction, 6, f->subscription); + SQL_EXPECT(res, SQLITE_OK); + res = sqlite3_step(stmt_update_faction); + SQL_EXPECT(res, SQLITE_DONE); + } + } } - } - - for (f = factions; f; f = f->next) { - if (!fval(f, FFL_MARK)) { - log_error("%s (sub=%d, email=%s) has no entry in the database\n", factionname(f), f->subscription, f->email); - } else { - freset(f, FFL_MARK); + + for (f = factions; f; f = f->next) { + if (!fval(f, FFL_MARK)) { + log_error("%s (sub=%d, email=%s) has no entry in the database\n", factionname(f), f->subscription, f->email); + } else { + freset(f, FFL_MARK); + } } - } - return SQLITE_OK; + return SQLITE_OK; } int db_update_scores(sqlite3 * db, bool force) From 19a21772e483acd69caef7e13932fa1b609cdee0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 4 May 2014 15:54:56 -0700 Subject: [PATCH 3/3] stop tests from crashing --- cutest | 2 +- s/runtests | 4 ++-- src/bindings.c | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cutest b/cutest index 788659594..d83cec09a 160000 --- a/cutest +++ b/cutest @@ -1 +1 @@ -Subproject commit 788659594ef87e9f497b8039da764182adfd2943 +Subproject commit d83cec09a52835274ab8ed4849de16fb8658982a diff --git a/s/runtests b/s/runtests index 1ad5a0b0a..c56619db1 100755 --- a/s/runtests +++ b/s/runtests @@ -18,7 +18,7 @@ fi echo $ROOT $ROOT/$BIN_DIR/eressea/test_eressea pushd $ROOT/game-e2 -$ROOT/$BIN_DIR/eressea/eressea -e run_tests +$ROOT/$BIN_DIR/eressea/eressea runtests.lua cd $ROOT/game-e3 -$ROOT/$BIN_DIR/eressea/eressea -e run_tests +$ROOT/$BIN_DIR/eressea/eressea runtests.lua popd diff --git a/src/bindings.c b/src/bindings.c index 3bd2db543..3d8a83388 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1218,7 +1218,6 @@ int eressea_run(lua_State *L, const char *luafile) err = lua_pcall(L, 1, 1, -3); if (err != 0) { log_lua_error(L); - abort(); } else { if (lua_isnumber(L, -1)) { err = (int)lua_tonumber(L, -1);