Merge pull request #632 from ennorehling/develop

configurable starting equipment
This commit is contained in:
Enno Rehling 2017-01-22 18:58:25 +01:00 committed by GitHub
commit 4598bdf917
17 changed files with 112 additions and 72 deletions

View file

@ -29,7 +29,7 @@
<xi:include href="config://game/strings.xml"/> <xi:include href="config://game/strings.xml"/>
<xi:include href="config://default/adamantium.xml"/> <xi:include href="config://default/adamantium.xml"/>
<equipment> <equipment>
<set name="first_unit"> <set name="autoseed_unit">
<item name="log" amount="50"/> <item name="log" amount="50"/>
<item name="stone" amount="50"/> <item name="stone" amount="50"/>
<item name="iron" amount="50"/> <item name="iron" amount="50"/>

View file

@ -3306,11 +3306,10 @@
</message> </message>
<message name="wrongpasswd" section="events"> <message name="wrongpasswd" section="events">
<type> <type>
<arg name="faction" type="int"/>
<arg name="password" type="string"/> <arg name="password" type="string"/>
</type> </type>
<text locale="de">"ERESSEA $int36($faction) \"${password}\" - Deine Befehle hatten ein falsches Passwort."</text> <text locale="de">"Deine Befehle hatten ein falsches Passwort (${password})."</text>
<text locale="en">"ERESSEA $int36($faction) \"${password}\" - Your orders had the wrong password."</text> <text locale="en">"Your orders had the wrong password (${password})."</text>
</message> </message>
<message name="changepasswd" section="events"> <message name="changepasswd" section="events">
<type> <type>

View file

@ -27,13 +27,15 @@ end
local function dbupdate() local function dbupdate()
update_scores() update_scores()
dbname = config.dbname or 'eressea.db' if config.dbname then
edb = db.open(config.basepath..'/'..dbname) dbname = config.basepath..'/'..config.dbname
edb = db.open(dbame)
if edb~=nil then if edb~=nil then
edb:update_factions() edb:update_factions()
edb:update_scores() edb:update_scores()
else else
eressea.log.error("could not open "..config.basepath..'/'..dbname) eressea.log.error("could not open "..dbname)
end
end end
end end

View file

@ -17,7 +17,7 @@ function setup()
end end
function test_faction_flags() function test_faction_flags()
assert_equal(2, f.flags) -- FFL_ISNEW assert_equal(6, f.flags) -- FFL_ISNEW|FFL_PWMSG
f.flags = 42 f.flags = 42
assert_equal(42, f.flags) assert_equal(42, f.flags)
end end

View file

@ -80,9 +80,10 @@ without prior permission by the authors of Eressea.
#include <lauxlib.h> #include <lauxlib.h>
#include <time.h> #include <time.h>
#include <errno.h>
#include <assert.h> #include <assert.h>
#define TOLUA_PKG(NAME) extern void tolua_##NAME##_open(lua_State * L) #define TOLUA_PKG(NAME) void tolua_##NAME##_open(lua_State * L)
TOLUA_PKG(eressea); TOLUA_PKG(eressea);
TOLUA_PKG(process); TOLUA_PKG(process);
@ -318,23 +319,6 @@ static int tolua_dice_rand(lua_State * L)
return 1; return 1;
} }
static int tolua_addequipment(lua_State * L)
{
const char *eqname = tolua_tostring(L, 1, 0);
const char *iname = tolua_tostring(L, 2, 0);
const char *value = tolua_tostring(L, 3, 0);
int result = -1;
if (iname != NULL) {
const struct item_type *itype = it_find(iname);
if (itype != NULL) {
equipment_setitem(create_equipment(eqname), itype, value);
result = 0;
}
}
lua_pushinteger(L, result);
return 1;
}
static int tolua_get_season(lua_State * L) static int tolua_get_season(lua_State * L)
{ {
int turnno = (int)tolua_tonumber(L, 1, 0); int turnno = (int)tolua_tonumber(L, 1, 0);
@ -460,7 +444,7 @@ static int tolua_equipment_setitem(lua_State * L)
if (iname != NULL) { if (iname != NULL) {
const struct item_type *itype = it_find(iname); const struct item_type *itype = it_find(iname);
if (itype != NULL) { if (itype != NULL) {
equipment_setitem(create_equipment(eqname), itype, value); equipment_setitem(get_or_create_equipment(eqname), itype, value);
result = 0; result = 0;
} }
} }
@ -1111,7 +1095,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, TOLUA_CAST "get_season", tolua_get_season); tolua_function(L, TOLUA_CAST "get_season", tolua_get_season);
tolua_function(L, TOLUA_CAST "equipment_setitem", tolua_equipment_setitem); tolua_function(L, TOLUA_CAST "equipment_setitem", tolua_equipment_setitem);
tolua_function(L, TOLUA_CAST "equip_unit", tolua_equipunit); tolua_function(L, TOLUA_CAST "equip_unit", tolua_equipunit);
tolua_function(L, TOLUA_CAST "add_equipment", tolua_addequipment);
tolua_function(L, TOLUA_CAST "atoi36", tolua_atoi36); tolua_function(L, TOLUA_CAST "atoi36", tolua_atoi36);
tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36); tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36);
tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand);
@ -1168,21 +1151,21 @@ lua_State *lua_init(const dictionary *inifile) {
return L; return L;
} }
int eressea_run(lua_State *L, const char *luafile) static int run_script(lua_State *L, const char *luafile) {
{ int err;
int err = 0; FILE *F;
global.vm_state = L; F = fopen(luafile, "r");
/* run the main script */ if (!F) {
if (luafile) { log_debug("dofile('%s'): %s", luafile, strerror(errno));
log_debug("executing script %s\n", luafile); return errno;
}
fclose(F);
lua_getglobal(L, "debug"); log_debug("executing script %s", luafile);
lua_getfield(L, -1, "traceback");
lua_remove(L, -2);
lua_getglobal(L, "dofile"); lua_getglobal(L, "dofile");
lua_pushstring(L, luafile); lua_pushstring(L, luafile);
err = lua_pcall(L, 1, 1, -3); err = lua_pcall(L, 1, 1, -3); /* error handler (debug.traceback) is now at stack -3 */
if (err != 0) { if (err != 0) {
log_lua_error(L); log_lua_error(L);
assert(!"Lua syntax error? check log."); assert(!"Lua syntax error? check log.");
@ -1195,5 +1178,29 @@ int eressea_run(lua_State *L, const char *luafile)
} }
return err; return err;
} }
return lua_console(L);
int eressea_run(lua_State *L, const char *luafile)
{
int err;
global.vm_state = L;
/* push an error handling function on the stack: */
lua_getglobal(L, "debug");
lua_getfield(L, -1, "traceback");
lua_remove(L, -2);
/* try to run configuration scripts: */
err = run_script(L, "config.lua");
err = run_script(L, "custom.lua");
/* run the main script */
if (luafile) {
err = run_script(L, luafile);
}
else {
err = lua_console(L);
}
/* pop error handler off the stack: */
lua_pop(L, 1);
return err;
} }

View file

@ -39,7 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static equipment *equipment_sets; static equipment *equipment_sets;
equipment *create_equipment(const char *eqname) equipment *get_or_create_equipment(const char *eqname)
{ {
equipment **eqp = &equipment_sets; equipment **eqp = &equipment_sets;
for (;;) { for (;;) {

View file

@ -56,7 +56,7 @@ extern "C" {
void equipment_done(void); void equipment_done(void);
struct equipment *create_equipment(const char *eqname); struct equipment *get_or_create_equipment(const char *eqname);
struct equipment *get_equipment(const char *eqname); struct equipment *get_equipment(const char *eqname);
void equipment_setitem(struct equipment *eq, void equipment_setitem(struct equipment *eq,

View file

@ -29,7 +29,7 @@ void test_equipment(CuTest * tc)
CuAssertPtrNotNull(tc, sp); CuAssertPtrNotNull(tc, sp);
CuAssertPtrEquals(tc, 0, get_equipment("herpderp")); CuAssertPtrEquals(tc, 0, get_equipment("herpderp"));
eq = create_equipment("herpderp"); eq = get_or_create_equipment("herpderp");
CuAssertPtrEquals(tc, eq, get_equipment("herpderp")); CuAssertPtrEquals(tc, eq, get_equipment("herpderp"));
equipment_setitem(eq, it_horses, "1"); equipment_setitem(eq, it_horses, "1");

View file

@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "alliance.h" #include "alliance.h"
#include "ally.h" #include "ally.h"
#include "curse.h" #include "curse.h"
#include "equipment.h"
#include "group.h" #include "group.h"
#include "item.h" #include "item.h"
#include "messages.h" #include "messages.h"
@ -246,10 +247,6 @@ faction *addfaction(const char *email, const char *password,
log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email); log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
} }
if (!password) password = itoa36(rng_int());
faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT));
ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
f->alliance_joindate = turn; f->alliance_joindate = turn;
f->lastorders = turn; f->lastorders = turn;
f->_alive = true; f->_alive = true;
@ -258,7 +255,11 @@ faction *addfaction(const char *email, const char *password,
f->magiegebiet = 0; f->magiegebiet = 0;
f->locale = loc; f->locale = loc;
f->subscription = subscription; f->subscription = subscription;
f->flags = FFL_ISNEW; f->flags = FFL_ISNEW|FFL_PWMSG;
if (!password) password = itoa36(rng_int());
faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT));
ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
f->options = f->options =
want(O_REPORT) | want(O_ZUGVORLAGE) | want(O_COMPUTER) | want(O_COMPRESS) | want(O_REPORT) | want(O_ZUGVORLAGE) | want(O_COMPUTER) | want(O_COMPRESS) |
@ -285,10 +286,15 @@ faction *addfaction(const char *email, const char *password,
unit *addplayer(region * r, faction * f) unit *addplayer(region * r, faction * f)
{ {
unit *u; unit *u;
const struct equipment* eq;
assert(f->units == NULL); assert(f->units == NULL);
faction_setorigin(f, 0, r->x, r->y); faction_setorigin(f, 0, r->x, r->y);
u = create_unit(r, f, 1, f->race, 0, NULL, NULL); u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
eq = get_equipment("first_unit");
if (eq) {
equip_items(&u->items, eq);
}
u->hp = unit_max_hp(u) * u->number; u->hp = unit_max_hp(u) * u->number;
fset(u, UFL_ISNEW); fset(u, UFL_ISNEW);
if (f->race == get_race(RC_DAEMON)) { if (f->race == get_race(RC_DAEMON)) {

View file

@ -37,10 +37,11 @@ extern "C" {
extern struct attrib_type at_maxmagicians; extern struct attrib_type at_maxmagicians;
/* faction flags */ /* faction flags */
#define FFL_NEWID (1<<0) /* Die Partei hat bereits einmal ihre no gewechselt */ #define FFL_NEWID (1<<0) // Die Partei hat bereits einmal ihre no gewechselt
#define FFL_ISNEW (1<<1) #define FFL_ISNEW (1<<1)
#define FFL_PWMSG (1<<2) // received a "new password" message
#define FFL_QUIT (1<<3) #define FFL_QUIT (1<<3)
#define FFL_CURSED (1<<4) /* you're going to have a bad time */ #define FFL_CURSED (1<<4) // you're going to have a bad time
#define FFL_DEFENDER (1<<10) #define FFL_DEFENDER (1<<10)
#define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */ #define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */
#define FFL_NOAID (1<<21) /* Hilfsflag Kampf */ #define FFL_NOAID (1<<21) /* Hilfsflag Kampf */

View file

@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) {
CuAssertTrue(tc, checkpasswd(f, "hurrdurr")); CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
CuAssertIntEquals(tc, 1234, f->subscription); CuAssertIntEquals(tc, 1234, f->subscription);
CuAssertIntEquals(tc, FFL_ISNEW, f->flags); CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags);
CuAssertIntEquals(tc, 0, f->age); CuAssertIntEquals(tc, 0, f->age);
CuAssertTrue(tc, faction_alive(f)); CuAssertTrue(tc, faction_alive(f));
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);

View file

@ -235,8 +235,7 @@ static faction *factionorders(void)
if (!checkpasswd(f, (const char *)pass)) { if (!checkpasswd(f, (const char *)pass)) {
log_debug("Invalid password for faction %s", itoa36(fid)); log_debug("Invalid password for faction %s", itoa36(fid));
ADDMSG(&f->msgs, msg_message("wrongpasswd", "faction password", ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", pass));
f->no, pass));
return 0; return 0;
} }
/* Die Partei hat sich zumindest gemeldet, so dass sie noch /* Die Partei hat sich zumindest gemeldet, so dass sie noch

View file

@ -44,7 +44,6 @@ extern "C" {
extern int enc_gamedata; extern int enc_gamedata;
int readorders(const char *filename); int readorders(const char *filename);
int creategame(void);
int readgame(const char *filename); int readgame(const char *filename);
int writegame(const char *filename); int writegame(const char *filename);

View file

@ -1266,7 +1266,7 @@ add_subsets(xmlDocPtr doc, equipment * eq, xmlNodeSetPtr nsetSubsets)
assert(propValue != NULL); assert(propValue != NULL);
eq->subsets[i].sets[set].chance = chance; eq->subsets[i].sets[set].chance = chance;
eq->subsets[i].sets[set].set = eq->subsets[i].sets[set].set =
create_equipment((const char *)propValue); get_or_create_equipment((const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
} }
} }
@ -1296,7 +1296,7 @@ static int parse_equipment(xmlDocPtr doc)
xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); xmlChar *propName = xmlGetProp(node, BAD_CAST "name");
if (propName != NULL) { if (propName != NULL) {
equipment *eq = create_equipment((const char *)propName); equipment *eq = get_or_create_equipment((const char *)propName);
xmlXPathObjectPtr xpathResult; xmlXPathObjectPtr xpathResult;
xpath->node = node; xpath->node = node;

View file

@ -2214,6 +2214,7 @@ int password_cmd(unit * u, struct order *ord)
faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT)); faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT));
ADDMSG(&u->faction->msgs, msg_message("changepasswd", ADDMSG(&u->faction->msgs, msg_message("changepasswd",
"value", pwbuf)); "value", pwbuf));
u->faction->flags |= FFL_PWMSG;
return 0; return 0;
} }

View file

@ -1336,6 +1336,14 @@ void prepare_report(report_context *ctx, faction *f)
rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name); rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name);
} }
if (f->age<=2) {
if ((f->flags&FFL_PWMSG)==0) {
// TODO: this assumes unencrypted passwords
f->flags |= FFL_PWMSG;
ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->_password));
}
}
ctx->f = f; ctx->f = f;
ctx->report_time = time(NULL); ctx->report_time = time(NULL);
ctx->addresses = NULL; ctx->addresses = NULL;

View file

@ -226,6 +226,23 @@ static void test_arg_resources(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_newbie_password_message(CuTest *tc) {
report_context ctx;
faction *f;
test_setup();
f = test_create_faction(0);
f->age = 5;
f->flags = 0;
prepare_report(&ctx, f);
CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd"));
f->age=2;
prepare_report(&ctx, f);
CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
test_cleanup();
}
static void test_prepare_travelthru(CuTest *tc) { static void test_prepare_travelthru(CuTest *tc) {
report_context ctx; report_context ctx;
faction *f, *f2; faction *f, *f2;
@ -465,6 +482,7 @@ static void test_seen_travelthru(CuTest *tc) {
CuSuite *get_reports_suite(void) CuSuite *get_reports_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_newbie_password_message);
SUITE_ADD_TEST(suite, test_prepare_report); SUITE_ADD_TEST(suite, test_prepare_report);
SUITE_ADD_TEST(suite, test_seen_neighbours); SUITE_ADD_TEST(suite, test_seen_neighbours);
SUITE_ADD_TEST(suite, test_seen_travelthru); SUITE_ADD_TEST(suite, test_seen_travelthru);