From 95d0b2a41370a1aea4aa55999ff8b1bcc5079ecc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Jan 2015 01:23:47 +0100 Subject: [PATCH 1/7] add current version of processing scripts fix a crash in checkpasswd --- process/cron/backup-eressea | 31 +++++++++++++++++++++++++++++++ process/cron/create-orders | 16 ++++++++++++++++ process/cron/run-eressea | 5 +++-- process/cron/run-turn | 14 ++++++++++++++ src/build.h | 2 +- src/kernel/faction.c | 4 +--- 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100755 process/cron/backup-eressea create mode 100755 process/cron/create-orders create mode 100755 process/cron/run-turn diff --git a/process/cron/backup-eressea b/process/cron/backup-eressea new file mode 100755 index 000000000..4f1d42144 --- /dev/null +++ b/process/cron/backup-eressea @@ -0,0 +1,31 @@ +#!/bin/bash +if [ -z $ERESSEA ] ; then + ERESSEA=$HOME/eressea + echo "The ERESSEA environment variable is not set. Assuming $ERESSEA." +fi +GAME=$1 +if [ ! -d $ERESSEA/game-$GAME ]; then + echo "No such game: game-$GAME." + exit 1 +fi +cd $ERESSEA/game-$GAME +TURN=$2 +if [ -z $TURN ]; then + TURN=$(cat turn) +fi +if [ ! -e data/$TURN.dat ]; then + echo "No data for turn $TURN in game $GAME." + exit 2 +fi +if [ ! -d backup ] ; then + echo "creating missing backup directory for game $GAME." + mkdir -p ~/backup/eressea/game-$GAME + ln -sf ~/backup/eressea/game-$GAME backup +fi + +files="data/$TURN.dat parteien.full parteien" +if [ -e orders.$TURN ]; then +files="$files orders.$TURN" +fi +echo "backup turn $TURN, game $GAME, files: $files" +tar cjf backup/$TURN.tar.bz2 $files diff --git a/process/cron/create-orders b/process/cron/create-orders new file mode 100755 index 000000000..ff784f9aa --- /dev/null +++ b/process/cron/create-orders @@ -0,0 +1,16 @@ +GAME=$1 +TURN=$2 + +if [ ! -d $ERESSEA/game-$GAME ] ; then + echo "No such game: $GAME" + exit 1 +fi + +cd $ERESSEA/game-$GAME +if [ -d orders.dir.$TURN ]; then + echo "orders.dir.$TURN already exists" +else + mv orders.dir orders.dir.$TURN + mkdir -p orders.dir +fi +ls -1rt orders.dir.$TURN/turn-* | xargs cat > orders.$TURN diff --git a/process/cron/run-eressea b/process/cron/run-eressea index f31150c1a..e932378fc 100755 --- a/process/cron/run-eressea +++ b/process/cron/run-eressea @@ -12,14 +12,15 @@ if [ -d $REPORTS ]; then rm -rf $REPORTS fi mkdir $REPORTS -$BIN/backup-eressea $GAME $TURN cd $ERESSEA/game-$GAME if [ -d test ]; then touch test/execute.lock fi +$BIN/create-orders $GAME $TURN +$BIN/backup-eressea $GAME $TURN rm -f execute.lock -$BIN/run-turn $GAME +$BIN/run-turn $GAME $TURN touch execute.lock if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then diff --git a/process/cron/run-turn b/process/cron/run-turn new file mode 100755 index 000000000..80e12b093 --- /dev/null +++ b/process/cron/run-turn @@ -0,0 +1,14 @@ +GAME=$1 +TURN=$2 + +if [ ! -d $ERESSEA/game-$GAME ] ; then + echo "No such game: $GAME" + exit 1 +fi + +cd $ERESSEA/game-$GAME + +echo "running turn $TURN, game $GAME" +$ERESSEA/server/bin/eressea -v1 -t $TURN run-turn.lua +mkdir -p log +ln -f eressea.log log/eressea.log.$TURN diff --git a/src/build.h b/src/build.h index 1b880e8d1..46a2e1316 100644 --- a/src/build.h +++ b/src/build.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 3 -#define VERSION_BUILD 694 +#define VERSION_BUILD 695 diff --git a/src/kernel/faction.c b/src/kernel/faction.c index b46848e3c..958640862 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -274,9 +274,7 @@ unit *addplayer(region * r, faction * f) bool checkpasswd(const faction * f, const char *passwd, bool shortp) { - if (unicode_utf8_strcasecmp(f->passw, passwd) == 0) - return true; - return false; + return (passwd && unicode_utf8_strcasecmp(f->passw, passwd) == 0); } variant read_faction_reference(struct storage * store) From 798b3d6ad6555ac2e3cbe9b7d803b7a520101848 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Jan 2015 08:18:41 +0100 Subject: [PATCH 2/7] Implement tests for magicpath. They are failing (Bug 2066). Also move spell and race initialization code from being server-only into game_init, where tests can use it. --- src/eressea.c | 4 ++++ src/kernel/curse.test.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/kernel/unit.c | 16 +++++++++------- src/main.c | 2 -- src/test_eressea.c | 5 +++-- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/eressea.c b/src/eressea.c index 120ad573b..4bfe59daf 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -20,12 +20,14 @@ #include #include #include +#include #include "chaos.h" #include "report.h" #include "items.h" #include "creport.h" #include "names.h" #include "wormhole.h" +#include "spells.h" void game_done(void) { @@ -55,6 +57,8 @@ void game_init(void) register_nr(); register_cr(); + register_races(); + register_spells(); register_names(); register_resources(); register_buildings(); diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index a7f88218b..5ac34c479 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -2,7 +2,11 @@ #include "types.h" #include "curse.h" +#include +#include #include +#include +#include #include @@ -22,9 +26,46 @@ static void test_curse(CuTest * tc) CuAssertPtrEquals(tc, NULL, result); } +typedef struct { + curse *c; + region *r; + unit *u; +} curse_fixture; + +static void setup_curse(curse_fixture *fix, const char *name) { + test_cleanup(); + fix->r = test_create_region(0, 0, NULL); + fix->u = test_create_unit(test_create_faction(NULL), fix->r); + fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 0); +} + +static void test_magicstreet(CuTest *tc) { + curse_fixture fix; + message *msg; + setup_curse(&fix, "magicstreet"); + fix.c->duration = 3; + msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); + CuAssertStrEquals(tc, "curseinfo::magicstreet", (const char *)msg->parameters[0].v); + msg_release(msg); + test_cleanup(); +} + +static void test_magicstreet_warning(CuTest *tc) { + curse_fixture fix; + message *msg; + setup_curse(&fix, "magicstreet"); + fix.c->duration = 2; + msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); + CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", (const char *)msg->parameters[0].v); + msg_release(msg); + test_cleanup(); +} + CuSuite *get_curse_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_curse); + SUITE_ADD_TEST(suite, test_magicstreet); + SUITE_ADD_TEST(suite, test_magicstreet_warning); return suite; } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index efd39bab9..348a46437 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1725,21 +1725,23 @@ int unit_max_hp(const unit * u) get_param_int(global.parameters, "rules.stamina", STAMINA_AFFECTS_HP); } h = u_race(u)->hitpoints; - if (heal_ct == NULL) - heal_ct = ct_find("healingzone"); if (rules_stamina & 1) { p = pow(effskill(u, SK_STAMINA) / 2.0, 1.5) * 0.2; h += (int)(h * p + 0.5); } + /* der healing curse veraendert die maximalen hp */ - if (heal_ct) { - curse *c = get_curse(u->region->attribs, heal_ct); - if (c) { - h = (int)(h * (1.0 + (curse_geteffect(c) / 100))); + if (u->region) { + if (heal_ct == NULL) + heal_ct = ct_find("healingzone"); + if (heal_ct) { + curse *c = get_curse(u->region->attribs, heal_ct); + if (c) { + h = (int)(h * (1.0 + (curse_geteffect(c) / 100))); + } } } - return h; } diff --git a/src/main.c b/src/main.c index 6868d36e9..316c3c206 100644 --- a/src/main.c +++ b/src/main.c @@ -304,8 +304,6 @@ int main(int argc, char **argv) L = lua_init(); game_init(); - register_races(); - register_spells(); bind_monsters(L); err = eressea_run(L, luafile); if (err) { diff --git a/src/test_eressea.c b/src/test_eressea.c index d33f75fe8..b8ff259b6 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -30,7 +31,7 @@ int RunAllTests(void) int fail_count, flags = log_flags; log_flags = LOG_FLUSH | LOG_CPERROR; - kernel_init(); + game_init(); /* self-test */ RUN_TESTS(suite, tests); @@ -86,7 +87,7 @@ int RunAllTests(void) log_flags = flags; fail_count = suite->failCount; CuSuiteDelete(suite); - kernel_done(); + game_done(); return fail_count; } From 0bd1a8d6f49886c01d705c7518590b9e223e3bfa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Jan 2015 17:50:10 +0100 Subject: [PATCH 3/7] add a utility function to test for message types. --- src/give.test.c | 6 +++--- src/kernel/curse.test.c | 4 ++-- src/tests.c | 12 ++++++++++++ src/tests.h | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/give.test.c b/src/give.test.c index f4d929c31..5437dfa5b 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -106,7 +106,7 @@ static void test_give_men_none(CuTest * tc) { env.f2 = env.f1 = test_create_faction(0); setup_give(&env); msg = give_men(0, env.src, env.dst, NULL); - CuAssertStrEquals(tc, "error96", (const char *)msg->parameters[3].v); + CuAssertStrEquals(tc, "error96", test_get_messagetype(msg)); CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); test_cleanup(); @@ -137,7 +137,7 @@ static void test_give_men_requires_contact(CuTest * tc) { env.f2 = test_create_faction(0); setup_give(&env); msg = give_men(1, env.src, env.dst, NULL); - CuAssertStrEquals(tc, "feedback_no_contact", (const char *)msg->parameters[3].v); + CuAssertStrEquals(tc, "feedback_no_contact", test_get_messagetype(msg)); CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); test_cleanup(); @@ -150,7 +150,7 @@ static void test_give_men_not_to_self(CuTest * tc) { env.f2 = env.f1 = test_create_faction(0); setup_give(&env); msg = give_men(1, env.src, env.src, NULL); - CuAssertStrEquals(tc, "error10", (const char *)msg->parameters[3].v); + CuAssertStrEquals(tc, "error10", test_get_messagetype(msg)); CuAssertIntEquals(tc, 1, env.src->number); test_cleanup(); } diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 5ac34c479..d152061de 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -45,7 +45,7 @@ static void test_magicstreet(CuTest *tc) { setup_curse(&fix, "magicstreet"); fix.c->duration = 3; msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); - CuAssertStrEquals(tc, "curseinfo::magicstreet", (const char *)msg->parameters[0].v); + CuAssertStrEquals(tc, "curseinfo::magicstreet", test_get_messagetype(msg)); msg_release(msg); test_cleanup(); } @@ -56,7 +56,7 @@ static void test_magicstreet_warning(CuTest *tc) { setup_curse(&fix, "magicstreet"); fix.c->duration = 2; msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); - CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", (const char *)msg->parameters[0].v); + CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", test_get_messagetype(msg)); msg_release(msg); test_cleanup(); } diff --git a/src/tests.c b/src/tests.c index 79ff5ad38..499e9883d 100644 --- a/src/tests.c +++ b/src/tests.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -192,3 +193,14 @@ void test_create_world(void) test_create_shiptype("boat"); } +const char * test_get_messagetype(const message *msg) { + const char * name = msg->type->name; + if (strcmp(name, "missing_message") == 0) { + name = (const char *)msg->parameters[0].v; + } + else if (strcmp(name, "missing_feedback") == 0) { + name = (const char *)msg->parameters[3].v; + } + return name; +} + diff --git a/src/tests.h b/src/tests.h index 5a565076f..6bb1071df 100644 --- a/src/tests.h +++ b/src/tests.h @@ -35,6 +35,7 @@ extern "C" { int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text); + const char * test_get_messagetype(const struct message *msg); #ifdef __cplusplus } From fdac137c0c5ab95096eb5bbbf73bd3e9ed8837fd Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 12 Jan 2015 02:35:54 +0100 Subject: [PATCH 4/7] magic path warning was wrong way round --- src/spells/regioncurse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 71138ac2b..0b5b1cdb4 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -99,7 +99,7 @@ static message *cinfo_magicstreet(const void *obj, objtype_t typ, const curse * assert(typ == TYP_REGION); /* Warnung vor Auflösung */ - if (c->duration <= 2) { + if (c->duration >= 2) { return msg_message("curseinfo::magicstreet", "id", c->no); } return msg_message("curseinfo::magicstreetwarn", "id", c->no); From 27da082cc6b500a538d37f348ac5ecc247b88243 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 12 Jan 2015 02:36:56 +0100 Subject: [PATCH 5/7] corrected good dreams message --- src/spells/regioncurse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 0b5b1cdb4..e0c6d8bf7 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -74,10 +74,11 @@ static message *cinfo_dreamcurse(const void *obj, objtype_t typ, const curse * c unused_arg(obj); assert(typ == TYP_REGION); - if (curse_geteffect(c) > 0) { + if (c->effect > 0) { return msg_message("curseinfo::gooddream", "id", c->no); + } else { + return msg_message("curseinfo::baddream", "id", c->no); } - return msg_message("curseinfo::baddream", "id", c->no); } static struct curse_type ct_gbdream = { From e8650b5b4a510285435c6257b9d9281312be8c2c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Jan 2015 18:22:59 +0100 Subject: [PATCH 6/7] test good and bad dreams, fix magicstreet test. --- src/kernel/curse.test.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index d152061de..ecee69c24 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -43,7 +43,7 @@ static void test_magicstreet(CuTest *tc) { curse_fixture fix; message *msg; setup_curse(&fix, "magicstreet"); - fix.c->duration = 3; + fix.c->duration = 2; msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); CuAssertStrEquals(tc, "curseinfo::magicstreet", test_get_messagetype(msg)); msg_release(msg); @@ -54,18 +54,42 @@ static void test_magicstreet_warning(CuTest *tc) { curse_fixture fix; message *msg; setup_curse(&fix, "magicstreet"); - fix.c->duration = 2; + fix.c->duration = 1; msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", test_get_messagetype(msg)); msg_release(msg); test_cleanup(); } +static void test_good_dreams(CuTest *tc) { + curse_fixture fix; + message *msg; + setup_curse(&fix, "gbdream"); + fix.c->effect = 1; + msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); + CuAssertStrEquals(tc, "curseinfo::gooddream", test_get_messagetype(msg)); + msg_release(msg); + test_cleanup(); +} + +static void test_bad_dreams(CuTest *tc) { + curse_fixture fix; + message *msg; + setup_curse(&fix, "gbdream"); + fix.c->effect = -1; + msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); + CuAssertStrEquals(tc, "curseinfo::baddream", test_get_messagetype(msg)); + msg_release(msg); + test_cleanup(); +} + CuSuite *get_curse_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_curse); SUITE_ADD_TEST(suite, test_magicstreet); SUITE_ADD_TEST(suite, test_magicstreet_warning); + SUITE_ADD_TEST(suite, test_good_dreams); + SUITE_ADD_TEST(suite, test_bad_dreams); return suite; } From 34e7373be486e038fc4229fafb438e28f1b4c6bf Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Jan 2015 18:31:04 +0100 Subject: [PATCH 7/7] fix the CI build (struct declared inside parameter list). --- src/tests.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests.h b/src/tests.h index 6bb1071df..1780e4e74 100644 --- a/src/tests.h +++ b/src/tests.h @@ -13,6 +13,7 @@ extern "C" { struct faction; struct building; struct ship; + struct message; struct item_type; struct building_type; struct ship_type;