From 86b0febac0a5eeeb68f0672177006ceb942af8ef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Mar 2015 18:37:50 +0100 Subject: [PATCH 01/15] fix BSD string function detection --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index aaf07e2a1..7cfd54e3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ CHECK_SYMBOL_EXISTS (sleep "unistd.h" HAVE_SLEEP) CHECK_SYMBOL_EXISTS (usleep "unistd.h" HAVE_USLEEP) CHECK_SYMBOL_EXISTS (access "unistd.h" HAVE_ACCESS) ENDIF(HAVE_UNISTD_H) +CHECK_SYMBOL_EXISTS (strlcpy "string.h" HAVE_STRLCPY) +CHECK_SYMBOL_EXISTS (strlcat "string.h" HAVE_STRLCAT) +CHECK_SYMBOL_EXISTS (slprintf "string.h" HAVE_SLPRINTF) CHECK_SYMBOL_EXISTS (strcasecmp "string.h" HAVE_STRCASECMP) CHECK_SYMBOL_EXISTS (strncasecmp "string.h" HAVE_STRNCASECMP) CHECK_SYMBOL_EXISTS (_strlwr "string.h" HAVE__STRLWR) From 48ea310364d69cf8b9b53858bb4047ec5fcd5ae4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Mar 2015 22:56:35 +0100 Subject: [PATCH 02/15] don't call nproc if the system doesn't have it --- s/build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/s/build b/s/build index 40ab81283..068a669a1 100755 --- a/s/build +++ b/s/build @@ -1,7 +1,7 @@ #!/bin/sh -ROOT=$(pwd) +ROOT=`pwd` while [ ! -d $ROOT/.git ]; do - ROOT=$(dirname $ROOT) + ROOT=`dirname $ROOT` done [ -z $BUILD ] && BUILD=Debug @@ -11,7 +11,7 @@ MACHINE=`uname -m` [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" BIN_DIR="build-$MACHINE-$CC-$BUILD" -[ -z "$JOBS" ] && JOBS=$(nproc) +[ -z "$JOBS" ] && [ "" != "which nproc" ] && JOBS=`nproc` DISTCC=`which distcc` if [ ! -z "$DISTCC" ] ; then JOBS=`distcc -j` From 1ec7a68b0741eff1c2e41791b58b8fbeef1f3eb4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Mar 2015 23:12:02 +0100 Subject: [PATCH 03/15] fix terrible code to avoid gcc 4.9 warning --- src/kernel/region.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 7f5d65ef6..807fb3d76 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -611,8 +611,8 @@ int rpeasants(const region * r) void rsetpeasants(region * r, int value) { - ((r)->land ? ((r)->land->peasants = - (value)) : (assert((value) >= 0), (value)), 0); + if (r->land) r->land->peasants = value; + else assert(value>=0); } int rmoney(const region * r) @@ -634,8 +634,8 @@ int rhorses(const region * r) void rsetmoney(region * r, int value) { - ((r)->land ? ((r)->land->money = - (value)) : (assert((value) >= 0), (value)), 0); + if (r->land) r->land->money = value; + else assert(value >= 0); } void r_setdemand(region * r, const luxury_type * ltype, int value) From 6a5458c119b105c1e94b6d6497997353664936af Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Mar 2015 18:37:50 +0100 Subject: [PATCH 04/15] fix BSD string function detection --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index aaf07e2a1..7cfd54e3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ CHECK_SYMBOL_EXISTS (sleep "unistd.h" HAVE_SLEEP) CHECK_SYMBOL_EXISTS (usleep "unistd.h" HAVE_USLEEP) CHECK_SYMBOL_EXISTS (access "unistd.h" HAVE_ACCESS) ENDIF(HAVE_UNISTD_H) +CHECK_SYMBOL_EXISTS (strlcpy "string.h" HAVE_STRLCPY) +CHECK_SYMBOL_EXISTS (strlcat "string.h" HAVE_STRLCAT) +CHECK_SYMBOL_EXISTS (slprintf "string.h" HAVE_SLPRINTF) CHECK_SYMBOL_EXISTS (strcasecmp "string.h" HAVE_STRCASECMP) CHECK_SYMBOL_EXISTS (strncasecmp "string.h" HAVE_STRNCASECMP) CHECK_SYMBOL_EXISTS (_strlwr "string.h" HAVE__STRLWR) From 7ae7fa24d86a0420555c8d42f026717772161d09 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 Mar 2015 22:56:35 +0100 Subject: [PATCH 05/15] don't call nproc if the system doesn't have it --- s/build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/s/build b/s/build index 40ab81283..068a669a1 100755 --- a/s/build +++ b/s/build @@ -1,7 +1,7 @@ #!/bin/sh -ROOT=$(pwd) +ROOT=`pwd` while [ ! -d $ROOT/.git ]; do - ROOT=$(dirname $ROOT) + ROOT=`dirname $ROOT` done [ -z $BUILD ] && BUILD=Debug @@ -11,7 +11,7 @@ MACHINE=`uname -m` [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" BIN_DIR="build-$MACHINE-$CC-$BUILD" -[ -z "$JOBS" ] && JOBS=$(nproc) +[ -z "$JOBS" ] && [ "" != "which nproc" ] && JOBS=`nproc` DISTCC=`which distcc` if [ ! -z "$DISTCC" ] ; then JOBS=`distcc -j` From 658c7c9f96ac1d08329e50c37bd4900c5cdd52a7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 3 Mar 2015 07:04:04 +0100 Subject: [PATCH 06/15] forgot to declare cmakedefine variables for Mac build --- autoconf.h.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoconf.h.in b/autoconf.h.in index 5144d9ecc..1c151b6f9 100644 --- a/autoconf.h.in +++ b/autoconf.h.in @@ -26,6 +26,9 @@ #cmakedefine HAVE_MEMICMP 1 #cmakedefine HAVE__STRLWR 1 #cmakedefine HAVE_STRLWR 1 +#cmakedefine HAVE_STRLCPY 1 +#cmakedefine HAVE_STRLCAT 1 +#cmakedefine HAVE_SLPRINTF 1 #cmakedefine HAVE_SYS_STAT_MKDIR 1 #cmakedefine HAVE_DIRECT_MKDIR 1 #cmakedefine HAVE_DIRECT__MKDIR 1 From 4ce2429276d31b78c3a9de801caa31870d971401 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 4 Mar 2015 22:19:11 +0100 Subject: [PATCH 07/15] fix keyword-buffer overflow --- src/kernel/config.h | 1 - src/keyword.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/kernel/config.h b/src/kernel/config.h index a10186e6d..caffedb9e 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -81,7 +81,6 @@ extern "C" { #define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */ #define NAMESIZE 128 /* max. Länge eines Namens, incl trailing 0 */ #define IDSIZE 16 /* max. Länge einer no (als String), incl trailing 0 */ -#define KEYWORDSIZE 16 /* max. Länge eines Keyword, incl trailing 0 */ #define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. Länge der Strings, die * von struct unitname, etc. zurückgegeben werden. ohne die 0 */ diff --git a/src/keyword.c b/src/keyword.c index fde981bb9..1ffdc4c3c 100644 --- a/src/keyword.c +++ b/src/keyword.c @@ -12,7 +12,7 @@ const char * keyword(keyword_t kwd) { - static char result[KEYWORDSIZE]; // FIXME: static return value + static char result[32]; // FIXME: static return value if (!result[0]) { strcpy(result, "keyword::"); } From 02e43d27722e6cc13db36922a731acd76403c317 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 Mar 2015 22:38:27 +0100 Subject: [PATCH 08/15] fix a crash in the ancient wedding code? --- scripts/eressea/wedding.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua index f5575428b..da0c60eb1 100644 --- a/scripts/eressea/wedding.lua +++ b/scripts/eressea/wedding.lua @@ -45,7 +45,7 @@ function wedding.update() if peacegate and hellgate then wedding_exchange(peacegate, hellgate) else - eressea.log.error("hellgate or peacegate not found!", hellgate, peacegate) + eressea.log.error("hellgate or peacegate not found!") end end From 491f6f2cb324a6769e343c7298dc84ff1e40efc1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Mar 2015 13:56:31 +0100 Subject: [PATCH 09/15] re-enable silver weight --- res/core/common/items.xml | 2 +- scripts/tests/e3/rules.lua | 13 ++----------- scripts/tests/faction.lua | 1 + 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/res/core/common/items.xml b/res/core/common/items.xml index 9508653e7..c8910e695 100644 --- a/res/core/common/items.xml +++ b/res/core/common/items.xml @@ -2,7 +2,7 @@ - + diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index ca6206419..62bbd8758 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -712,7 +712,7 @@ function test_golem_use_four_iron() assert_equal(4, u1:get_item("towershield")) end -function skip_test_silver_weight_stops_movement() +function test_silver_weight_stops_movement() local r1 = region.create(1, 1, "plain") local r2 = region.create(2, 1, "plain") region.create(3, 1, "plain") @@ -729,7 +729,7 @@ function skip_test_silver_weight_stops_movement() assert_equal(r2, u1.region) end -function skip_test_silver_weight_stops_ship() +function test_silver_weight_stops_ship() local r1 = region.create(1, 1, "ocean") local r2 = region.create(2, 1, "ocean") region.create(3, 1, "ocean") @@ -771,15 +771,6 @@ function test_building_owner_can_enter_ship() assert_equal(null, u1.building, "owner of the building can not go into a ship") end -function test_weightless_silver() - local r1 = region.create(1, 2, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f1, r1, 1) - assert_equal(1000, u1.weight) - u1:add_item("money", 540) - assert_equal(1000, u1.weight) -end - function test_only_building_owner_can_set_not_paid() local r = region.create(0, 0, "plain") local f = faction.create("noreply@eressea.de", "human", "de") diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index a6265cde9..89387f777 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -6,6 +6,7 @@ local f function setup() f = faction.create("faction@eressea.de", "human", "de") + assert(f~=nil) end function test_faction_flags() From 677f0903cb76f50a48c7868063fe9549c52e8c72 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Mar 2015 14:11:32 +0100 Subject: [PATCH 10/15] fix broken tests (they were fixed in master, but not in develop?) --- scripts/tests/faction.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index 89387f777..f0cd9335c 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -5,6 +5,13 @@ module ('tests.eressea.faction', package.seeall, lunit.testcase) local f function setup() + conf = [[{ + "races": { + "human" : {} + } + }]] + eressea.config.reset() + assert(eressea.config.parse(conf)==0) f = faction.create("faction@eressea.de", "human", "de") assert(f~=nil) end From 654ee9e6bff505a7b6018ccab464f4f2ac023b35 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Mar 2015 14:33:38 +0100 Subject: [PATCH 11/15] minimal script to load configuration in an interactive session --- scripts/config.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/config.lua b/scripts/config.lua index 1251c1e1c..8b61bcad2 100644 --- a/scripts/config.lua +++ b/scripts/config.lua @@ -4,5 +4,5 @@ if config.install then end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' require 'eressea' -require 'eressea.xmlconf' -return require('eressea.rules') +require 'eressea.xmlconf' -- read xml data + From 8edafa19c5b7a98658f5502c98264ad77c42f483 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 20:39:36 +0100 Subject: [PATCH 12/15] fix faction.create locale handling --- scripts/run-tests-e2.lua | 2 +- src/bind_faction.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index aff15eb06..9f08b0f54 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -5,7 +5,7 @@ path = 'scripts' if config.install then path = config.install .. '/' .. path package.path = package.path .. ';' .. config.install .. '/lunit/?.lua' - --needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) + --needed to find lunit if not run from eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' diff --git a/src/bind_faction.c b/src/bind_faction.c index df89f9d5a..cfe57ebb4 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -344,14 +344,14 @@ static int tolua_faction_create(lua_State * L) const char *email = tolua_tostring(L, 1, 0); const char *racename = tolua_tostring(L, 2, 0); const char *lang = tolua_tostring(L, 3, 0); - struct locale *loc = get_locale(lang); + struct locale *loc = lang ? get_locale(lang) : default_locale; faction *f = NULL; - const struct race *frace = rc_find(racename); + const struct race *frace = rc_find(racename ? racename : "human"); if (frace != NULL) { f = addfaction(email, NULL, frace, loc, 0); } if (!f) { - log_error("faction.create(%s, %s, %s)\n", email, racename, lang); + log_error("faction.create(%s, %s, %s)\n", email, frace->_name, locale_name(loc)); } tolua_pushusertype(L, f, TOLUA_CAST "faction"); return 1; From 293190703fbc6fddd3025fc68c791cca5e71f0d1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 21:10:39 +0100 Subject: [PATCH 13/15] make maximum number of people transferred to a faction configurable make E2 transfers basically unlimited. --- conf/e2/config.xml | 1 + src/give.c | 9 ++++++--- src/give.test.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 170621b48..980671bcf 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -94,6 +94,7 @@ + diff --git a/src/give.c b/src/give.c index 7b9d2a3fb..22f05f34c 100644 --- a/src/give.c +++ b/src/give.c @@ -48,10 +48,13 @@ #include /* Wieviel Fremde eine Partei pro Woche aufnehmen kangiven */ -#define MAXNEWBIES 5 #define RESERVE_DONATIONS /* shall we reserve objects given to us by other factions? */ #define RESERVE_GIVE /* reserve anything that's given from one unit to another? */ +static int max_transfers() { + return get_param_int(global.parameters, "rules.give.max_men", 5); +} + static int GiveRestriction(void) { static int value = -1; @@ -300,7 +303,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) error = 96; } else if (u->faction != u2->faction) { - if (u2->faction->newbies + n > MAXNEWBIES) { + if (u2->faction->newbies + n > max_transfers()) { error = 129; } else if (u_race(u) != u2->faction->race) { @@ -473,7 +476,7 @@ void give_unit(unit * u, unit * u2, order * ord) cmistake(u, ord, 105, MSG_COMMERCE); return; } - if (u2->faction->newbies + n > MAXNEWBIES) { + if (u2->faction->newbies + n > max_transfers()) { cmistake(u, ord, 129, MSG_COMMERCE); return; } diff --git a/src/give.test.c b/src/give.test.c index 5437dfa5b..f1b13011d 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -72,6 +72,36 @@ static void test_give_men(CuTest * tc) { test_cleanup(); } +static void test_give_men_limit(CuTest * tc) { + struct give env; + message *msg; + test_cleanup(); + env.f2 = test_create_faction(0); + env.f1 = test_create_faction(0); + setup_give(&env); + set_param(&global.parameters, "rules.give.max_men", "1"); + + /* below the limit, give men, increase newbies counter */ + usetcontact(env.dst, env.src); + msg = give_men(1, env.src, env.dst, NULL); + CuAssertStrEquals(tc, "give_person", (const char *)msg->parameters[0].v); + CuAssertIntEquals(tc, 2, env.dst->number); + CuAssertIntEquals(tc, 0, env.src->number); + CuAssertIntEquals(tc, 1, env.f2->newbies); + msg_release(msg); + + /* beyond the limit, do nothing */ + usetcontact(env.src, env.dst); + msg = give_men(2, env.dst, env.src, NULL); + CuAssertStrEquals(tc, "error129", (const char *)msg->parameters[3].v); + CuAssertIntEquals(tc, 2, env.dst->number); + CuAssertIntEquals(tc, 0, env.src->number); + CuAssertIntEquals(tc, 0, env.f1->newbies); + msg_release(msg); + + test_cleanup(); +} + static void test_give_men_in_ocean(CuTest * tc) { struct give env; message * msg; @@ -247,6 +277,7 @@ CuSuite *get_give_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_give); SUITE_ADD_TEST(suite, test_give_men); + SUITE_ADD_TEST(suite, test_give_men_limit); SUITE_ADD_TEST(suite, test_give_men_in_ocean); SUITE_ADD_TEST(suite, test_give_men_none); SUITE_ADD_TEST(suite, test_give_men_too_many); From 4d18fe68f8144a85e40194655909b0642dec449d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 21:56:18 +0100 Subject: [PATCH 14/15] gcc language purity complaint. --- src/give.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/give.c b/src/give.c index 22f05f34c..d875dc34a 100644 --- a/src/give.c +++ b/src/give.c @@ -51,7 +51,7 @@ #define RESERVE_DONATIONS /* shall we reserve objects given to us by other factions? */ #define RESERVE_GIVE /* reserve anything that's given from one unit to another? */ -static int max_transfers() { +static int max_transfers(void) { return get_param_int(global.parameters, "rules.give.max_men", 5); } From a2a0bbad6a3b90d0329dc227fea892df04e8e712 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Mar 2015 22:14:01 +0100 Subject: [PATCH 15/15] bug 2068: select familiars by race of mage, not faction. https://bugs.eressea.de/view.php?id=2068 --- src/spells.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spells.c b/src/spells.c index 82aca3720..0826c7edf 100644 --- a/src/spells.c +++ b/src/spells.c @@ -545,7 +545,7 @@ static int sp_summon_familiar(castorder * co) cmistake(mage, co->order, 199, MSG_MAGIC); return 0; } - rc = select_familiar(mage->faction->race, mage->faction->magiegebiet); + rc = select_familiar(mage->_race, mage->faction->magiegebiet); if (rc == NULL) { log_error("could not find suitable familiar for %s.\n", mage->faction->race->_name); return 0;