From 01fda5d3d793a64ddcf1765dcaa2b424010cd525 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Jun 2019 10:03:53 +0200 Subject: [PATCH 1/5] new sqlite schema has faction-no as string --- process/epasswd.py | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/process/epasswd.py b/process/epasswd.py index c5e1712b9..0f38fd593 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -3,34 +3,9 @@ from string import split from string import strip from string import lower -import subprocess import bcrypt import sqlite3 -def baseconvert(n, base): - """convert positive decimal integer n to equivalent in another base (2-36)""" - - digits = "0123456789abcdefghijkLmnopqrstuvwxyz" - - try: - n = int(n) - base = int(base) - except: - return "" - - if n < 0 or base < 2 or base > 36: - return "" - - s = "" - while True: - r = n % base - s = digits[r] + s - n = n / base - if n == 0: - break - - return s - class EPasswd: def __init__(self): self.data = {} @@ -47,7 +22,7 @@ class EPasswd: c = conn.cursor() for row in c.execute('SELECT `no`, `email`, `password` FROM `faction`'): (no, email, passwd) = row - self.set_data(baseconvert(no, 36), email, passwd) + self.set_data(no, email, passwd) conn.close() def load_file(self, file): From fdde7c8c448ed3f743a777ff2e8a5fe1ff9a75aa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 8 Jun 2019 12:18:26 +0200 Subject: [PATCH 2/5] insert language in orders.db --- process/orders-accept | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/process/orders-accept b/process/orders-accept index 99398e64f..8c810b1de 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -2,6 +2,7 @@ # example: orders-accept 2 de < mail.txt game="$1" +lang="$2" [ -z "$ERESSEA" ] && ERESSEA="$HOME/eressea" SCRIPT=$(readlink -f "$0") @@ -21,5 +22,5 @@ filename=$(basename "$ACCEPT_FILE") email="$ACCEPT_MAIL" if [ -d "$ERESSEA/orders-php" ] then - php "$ERESSEA/orders-php/cli.php" insert "$filename" "$email" + php "$ERESSEA/orders-php/cli.php" insert "$filename" "$email" "$lang" fi From 05b8477b8a0a11cdcecead3b5752210d47a72cb3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 4 Jul 2019 20:44:11 +0200 Subject: [PATCH 3/5] =?UTF-8?q?STIRB=20PARTEI=20hat=20immer=20nur=20eine?= =?UTF-8?q?=20Einheit=20=C3=BCbergeben.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/laws.c | 17 ++++++++++++----- src/laws.h | 1 + src/laws.test.c | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/laws.c b/src/laws.c index e8200c262..1041d72a8 100644 --- a/src/laws.c +++ b/src/laws.c @@ -963,7 +963,10 @@ void transfer_faction(faction *fsrc, faction *fdst) { } } - for (u = fsrc->units; u != NULL; u = u->nextF) { + u = fsrc->units; + while (u) { + unit *unext = u->nextF; + if (u_race(u) == fdst->race) { u->flags &= ~UFL_HERO; if (give_unit_allowed(u) == 0) { @@ -978,12 +981,14 @@ void transfer_faction(faction *fsrc, faction *fdst) { } } if (i != u->skill_size) { + u = u->nextF; continue; } } u_setfaction(u, fdst); } } + u = unext; } } @@ -1015,14 +1020,16 @@ int quit_cmd(unit * u, struct order *ord) else { unit *u2; for (u2 = u->region->units; u2; u2 = u2->next) { - if (u2->faction == f2 && ucontact(u2, u)) { - transfer_faction(u->faction, u2->faction); - break; + if (u2->faction == f2) { + if (ucontact(u2, u)) { + transfer_faction(u->faction, u2->faction); + break; + } } } if (u2 == NULL) { /* no target unit found */ - cmistake(u, ord, 0, MSG_EVENT); + cmistake(u, ord, 40, MSG_EVENT); flags = 0; } } diff --git a/src/laws.h b/src/laws.h index 1f9632c60..4738f56b8 100755 --- a/src/laws.h +++ b/src/laws.h @@ -93,6 +93,7 @@ extern "C" { int reserve_cmd(struct unit *u, struct order *ord); int reserve_self(struct unit *u, struct order *ord); int claim_cmd(struct unit *u, struct order *ord); + void transfer_faction(struct faction *fsrc, struct faction *fdst); void nmr_warnings(void); bool nmr_death(const struct faction * f, int turn, int timeout); diff --git a/src/laws.test.c b/src/laws.test.c index 33742f427..3e6d1a4fb 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -2012,6 +2012,29 @@ static void test_quit_transfer_hero(CuTest *tc) { test_teardown(); } +static void test_transfer_faction(CuTest *tc) { + faction *f1, *f2; + unit *u1, *u2, *u3, *u4; + region *r; + + test_setup(); + r = test_create_plain(0, 0); + f1 = test_create_faction(NULL); + f2 = test_create_faction(NULL); + u1 = test_create_unit(f1, r); + u2 = test_create_unit(f1, r); + u_setrace(u2, test_create_race("smurf")); + u3 = test_create_unit(f2, r); + u4 = test_create_unit(f1, r); + transfer_faction(f1, f2); + CuAssertPtrEquals(tc, f2, u1->faction); + CuAssertPtrEquals(tc, f1, u2->faction); + CuAssertPtrEquals(tc, f2, u3->faction); + CuAssertPtrEquals(tc, f2, u4->faction); + + test_teardown(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -2092,6 +2115,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_quit_transfer_limited); SUITE_ADD_TEST(suite, test_quit_transfer_migrants); SUITE_ADD_TEST(suite, test_quit_transfer_hero); + SUITE_ADD_TEST(suite, test_transfer_faction); return suite; } From f677a21541fa07ee29be358a5ff9a2cf5e591ba4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 Jul 2019 12:02:52 +0200 Subject: [PATCH 4/5] disable QUIT FACTION with ifdef QUIT_WITH_TRANSFER --- res/core/messages.xml | 6 ++++++ res/translations/messages.de.po | 3 +++ res/translations/messages.en.po | 3 +++ scripts/tests/e2/init.lua | 1 + scripts/tests/e2/quit.lua | 21 +++++++++++++++++++++ scripts/tests/init.lua | 2 +- src/kernel/faction.c | 4 +++- src/laws.c | 8 ++++++++ src/laws.test.c | 4 ++++ 9 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 scripts/tests/e2/quit.lua diff --git a/res/core/messages.xml b/res/core/messages.xml index 4de8b0299..fb6cd45bd 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -5196,6 +5196,12 @@ + + + + + + diff --git a/res/translations/messages.de.po b/res/translations/messages.de.po index 5623069d4..21586ac31 100644 --- a/res/translations/messages.de.po +++ b/res/translations/messages.de.po @@ -38,6 +38,9 @@ msgstr "\"$unit($mage) verwandelt $unit($target) in $race($race,0).\"" msgid "give_person" msgstr "\"$unit($unit) übergibt $int($amount) Person$if($eq($amount,1),\"\",\"en\") an $unit($target).\"" +msgid "transfer_unit" +msgstr "\"$unit($unit) schließt sich unserer Partei an.\"" + msgid "rust_effect_2" msgstr "\"$unit($mage) ruft ein fürchterliches Unwetter über seine Feinde. Der magischen Regen lässt alles Eisen rosten.\"" diff --git a/res/translations/messages.en.po b/res/translations/messages.en.po index 1f1db551c..095a83212 100644 --- a/res/translations/messages.en.po +++ b/res/translations/messages.en.po @@ -38,6 +38,9 @@ msgstr "\"$unit($mage) tranforms $unit($target) to $race($race,0).\"" msgid "give_person" msgstr "\"$unit($unit) transfers $int($amount) person$if($eq($amount,1),\"\",\"s\") to $unit($target).\"" +msgid "transfer_unit" +msgstr "\"$unit($unit) joins our faction.\"" + msgid "rust_effect_2" msgstr "\"$unit($mage) calls forth a terrible torment over the enemy. The magical rain makes all iron rusty.\"" diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index fde840f98..a7f6d8033 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +-- require 'tests.e2.quit' require 'tests.e2.movement' require 'tests.e2.astral' require 'tests.e2.spells' diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua new file mode 100644 index 000000000..437494833 --- /dev/null +++ b/scripts/tests/e2/quit.lua @@ -0,0 +1,21 @@ +require "lunit" + +module("tests.e2.quit", package.seeall, lunit.testcase) + +function test_quit_faction() + local r = region.create(0, 0, "plain") + local f1 = faction.create("human") + f1.password = "steamedhams" + local f2 = faction.create("human") + local u1 = unit.create(f1, r, 10) + local u2 = unit.create(f2, r, 10) + local u3 = unit.create(f1, r, 10) + u1:clear_orders() + u2:clear_orders() + u1:add_order("STIRB steamedhams PARTEI " .. itoa36(f2.id)) + u2:add_order("KONTAKTIERE " .. itoa36(u1.id)) + process_orders() + assert_equal(f2, u1.faction) + assert_equal(f2, u2.faction) + assert_equal(f2, u3.faction) +end diff --git a/scripts/tests/init.lua b/scripts/tests/init.lua index a01e1c75c..2c0786347 100644 --- a/scripts/tests/init.lua +++ b/scripts/tests/init.lua @@ -1,4 +1,5 @@ -- new tests 2014-06-11 +require 'tests.laws' require 'tests.faction' require 'tests.locale' require 'tests.movement' @@ -6,6 +7,5 @@ require 'tests.pool' require 'tests.regions' require 'tests.settings' require 'tests.study' -require 'tests.laws' require 'tests.bindings' require 'tests.hunger' diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 86f74dc03..460eb519e 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -216,6 +216,7 @@ faction *addfaction(const char *email, const char *password, const struct race * frace, const struct locale * loc) { faction *f = calloc(1, sizeof(faction)); + const char *fname; char buf[128]; if (!f) abort(); @@ -255,7 +256,8 @@ faction *addfaction(const char *email, const char *password, addlist(&factions, f); fhash(f); - slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no)); + fname = LOC(loc, "factiondefault"); + slprintf(buf, sizeof(buf), "%s %s", fname ? fname : "faction", itoa36(f->no)); f->name = str_strdup(buf); if (!f->race) { diff --git a/src/laws.c b/src/laws.c index 1041d72a8..a07c7d517 100644 --- a/src/laws.c +++ b/src/laws.c @@ -947,6 +947,8 @@ void transfer_faction(faction *fsrc, faction *fdst) { int skill_count[MAXSKILLS]; int skill_limit[MAXSKILLS]; + assert(fsrc != fdst); + for (sk = 0; sk != MAXSKILLS; ++sk) { skill_limit[sk] = faction_skill_limit(fdst, sk); } @@ -985,6 +987,7 @@ void transfer_faction(faction *fsrc, faction *fdst) { continue; } } + ADDMSG(&fdst->msgs, msg_message("transfer_unit", "unit", u)); u_setfaction(u, fdst); } } @@ -1008,6 +1011,7 @@ int quit_cmd(unit * u, struct order *ord) param_t p; p = getparam(f->locale); if (p == P_FACTION) { +#ifdef QUIT_WITH_TRANSFER faction *f2 = getfaction(); if (f2 == NULL) { cmistake(u, ord, 66, MSG_EVENT); @@ -1033,6 +1037,10 @@ int quit_cmd(unit * u, struct order *ord) flags = 0; } } +#else + log_error("faction %s: QUIT FACTION is disabled.", factionname(f)); + flags = 0; +#endif } } f->flags |= flags; diff --git a/src/laws.test.c b/src/laws.test.c index 3e6d1a4fb..f74728816 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1915,6 +1915,7 @@ static void test_quit_transfer(CuTest *tc) { test_teardown(); } +#ifdef QUIT_WITH_TRANSFER /** * Gifting units with limited skills to another faction. * @@ -2034,6 +2035,7 @@ static void test_transfer_faction(CuTest *tc) { test_teardown(); } +#endif CuSuite *get_laws_suite(void) { @@ -2111,11 +2113,13 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_long_orders); SUITE_ADD_TEST(suite, test_long_order_on_ocean); SUITE_ADD_TEST(suite, test_quit); +#ifdef QUIT_WITH_TRANSFER SUITE_ADD_TEST(suite, test_quit_transfer); SUITE_ADD_TEST(suite, test_quit_transfer_limited); SUITE_ADD_TEST(suite, test_quit_transfer_migrants); SUITE_ADD_TEST(suite, test_quit_transfer_hero); SUITE_ADD_TEST(suite, test_transfer_faction); +#endif return suite; } From 26521bcd2baa0c5657e951d63518ea3669bfa7a8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 Jul 2019 17:30:09 +0200 Subject: [PATCH 5/5] hide unused function --- src/laws.test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/laws.test.c b/src/laws.test.c index f74728816..adda8f5ab 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1891,6 +1891,7 @@ static void test_quit(CuTest *tc) { test_teardown(); } +#ifdef QUIT_WITH_TRANSFER /** * Gifting units to another faction upon voluntary death (QUIT). */ @@ -1915,7 +1916,6 @@ static void test_quit_transfer(CuTest *tc) { test_teardown(); } -#ifdef QUIT_WITH_TRANSFER /** * Gifting units with limited skills to another faction. *