swap faction.banner to database

This commit is contained in:
Enno Rehling 2018-10-24 19:54:07 +02:00
parent da3270517a
commit 516a53c0c7
7 changed files with 39 additions and 21 deletions

View File

@ -1057,12 +1057,15 @@ static void cr_find_address(FILE * F, const faction * uf, selist * addresses)
while (flist) {
const faction *f = (const faction *)selist_get(flist, i);
if (uf != f) {
const char *str;
fprintf(F, "PARTEI %d\n", f->no);
fprintf(F, "\"%s\";Parteiname\n", f->name);
if (strcmp(faction_getemail(f), "") != 0)
fprintf(F, "\"%s\";email\n", faction_getemail(f));
if (f->banner)
fprintf(F, "\"%s\";banner\n", f->banner);
str = faction_getbanner(f);
if (str) {
fprintf(F, "\"%s\";banner\n", str);
}
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
if (f->alliance && f->alliance == uf->alliance) {
fprintf(F, "%d;alliance\n", f->alliance->id);
@ -1534,7 +1537,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
static int era = -1;
int i;
faction *f = ctx->f;
const char *prefix;
const char *prefix, *str;
region *r;
const char *mailto = config_get("game.email");
const attrib *a;
@ -1628,8 +1631,10 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
fprintf(F, "\"%s\";Parteiname\n", f->name);
fprintf(F, "\"%s\";email\n", faction_getemail(f));
if (f->banner)
fprintf(F, "\"%s\";banner\n", f->banner);
str = faction_getbanner(f);
if (str) {
fprintf(F, "\"%s\";banner\n", str);
}
print_items(F, f->items, f->locale);
fputs("OPTIONEN\n", F);
for (i = 0; i != MAXOPTIONS; ++i) {

View File

@ -106,7 +106,6 @@ static void free_faction(faction * f)
freelist(f->allies);
free(f->email);
free(f->banner);
free(f->name);
if (f->seen_factions) {
selist_free(f->seen_factions);
@ -593,16 +592,17 @@ void faction_setemail(faction * self, const char *email)
self->email = NULL;
}
const char *faction_getbanner(const faction * self)
const char *faction_getbanner(const faction * f)
{
return self->banner ? self->banner : "";
if (f->banner_id > 0) {
return dbstring_load(f->banner_id, NULL);
}
return NULL;
}
void faction_setbanner(faction * self, const char *banner)
void faction_setbanner(faction * f, const char *banner)
{
free(self->banner);
if (banner)
self->banner = str_strdup(banner);
f->banner_id = dbstring_save(banner);
}
const char *faction_getpassword(const faction *f) {

View File

@ -71,7 +71,7 @@ extern "C" {
int uid;
int flags;
char *name;
char *banner;
dbrow_id banner_id;
char *email;
dbrow_id password_id;
int max_spelllevel;

View File

@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) {
CuAssertPtrNotNull(tc, f->name);
CuAssertPtrEquals(tc, NULL, (void *)f->units);
CuAssertPtrEquals(tc, NULL, (void *)f->next);
CuAssertPtrEquals(tc, NULL, (void *)f->banner);
CuAssertPtrEquals(tc, NULL, (void *)faction_getbanner(f));
CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
CuAssertPtrEquals(tc, NULL, (void *)f->origin);
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
@ -229,6 +229,18 @@ static void test_valid_race(CuTest *tc) {
test_teardown();
}
static void test_dbstrings(CuTest *tc) {
const char *lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
faction *f;
test_setup();
f = test_create_faction(NULL);
faction_setbanner(f, lipsum);
faction_setpassword(f, lipsum + 12);
CuAssertStrEquals(tc, lipsum, faction_getbanner(f));
CuAssertStrEquals(tc, lipsum + 12, faction_getpassword(f));
test_teardown();
}
static void test_set_email(CuTest *tc) {
faction *f;
char email[10];
@ -335,6 +347,7 @@ CuSuite *get_faction_suite(void)
SUITE_ADD_TEST(suite, test_check_passwd);
SUITE_ADD_TEST(suite, test_valid_race);
SUITE_ADD_TEST(suite, test_set_email);
SUITE_ADD_TEST(suite, test_dbstrings);
SUITE_ADD_TEST(suite, test_save_special_items);
return suite;
}

View File

@ -1007,7 +1007,7 @@ faction *read_faction(gamedata * data)
if (unicode_utf8_trim(name)!=0) {
log_warning("trim faction %s banner to '%s'", itoa36(f->no), name);
};
f->banner = str_strdup(name);
faction_setbanner(f, name);
log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no));
@ -1115,7 +1115,7 @@ void write_faction(gamedata *data, const faction * f)
WRITE_INT(data->store, f->alliance_joindate);
WRITE_STR(data->store, f->name);
WRITE_STR(data->store, f->banner);
WRITE_STR(data->store, faction_getbanner(f));
WRITE_STR(data->store, f->email?f->email:"");
write_password(data, f);
WRITE_TOK(data->store, locale_name(f->locale));

View File

@ -2086,12 +2086,10 @@ int banner_cmd(unit * u, struct order *ord)
{
const char * s;
free(u->faction->banner);
init_order_depr(ord);
s = getstrtoken();
u->faction->banner = s ? str_strdup(s) : 0;
add_message(&u->faction->msgs, msg_message("changebanner", "value",
u->faction->banner));
faction_setbanner(u->faction, s);
add_message(&u->faction->msgs, msg_message("changebanner", "value", s));
return 0;
}

View File

@ -1726,11 +1726,13 @@ static void list_address(struct stream *out, const faction * uf, selist * seenfa
while (flist != NULL) {
const faction *f = (const faction *)selist_get(flist, qi);
if (!is_monsters(f)) {
const char *str;
char buf[8192];
char label = '-';
str = faction_getbanner(f);
sprintf(buf, "%s: %s; %s", factionname(f), faction_getemail(f),
f->banner ? f->banner : "");
str ? str : "");
if (uf == f)
label = '*';
else if (is_allied(uf, f))