forked from github/server
swap faction.banner to database
This commit is contained in:
parent
da3270517a
commit
516a53c0c7
7 changed files with 39 additions and 21 deletions
|
@ -1057,12 +1057,15 @@ static void cr_find_address(FILE * F, const faction * uf, selist * addresses)
|
||||||
while (flist) {
|
while (flist) {
|
||||||
const faction *f = (const faction *)selist_get(flist, i);
|
const faction *f = (const faction *)selist_get(flist, i);
|
||||||
if (uf != f) {
|
if (uf != f) {
|
||||||
|
const char *str;
|
||||||
fprintf(F, "PARTEI %d\n", f->no);
|
fprintf(F, "PARTEI %d\n", f->no);
|
||||||
fprintf(F, "\"%s\";Parteiname\n", f->name);
|
fprintf(F, "\"%s\";Parteiname\n", f->name);
|
||||||
if (strcmp(faction_getemail(f), "") != 0)
|
if (strcmp(faction_getemail(f), "") != 0)
|
||||||
fprintf(F, "\"%s\";email\n", faction_getemail(f));
|
fprintf(F, "\"%s\";email\n", faction_getemail(f));
|
||||||
if (f->banner)
|
str = faction_getbanner(f);
|
||||||
fprintf(F, "\"%s\";banner\n", f->banner);
|
if (str) {
|
||||||
|
fprintf(F, "\"%s\";banner\n", str);
|
||||||
|
}
|
||||||
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
|
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
|
||||||
if (f->alliance && f->alliance == uf->alliance) {
|
if (f->alliance && f->alliance == uf->alliance) {
|
||||||
fprintf(F, "%d;alliance\n", f->alliance->id);
|
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;
|
static int era = -1;
|
||||||
int i;
|
int i;
|
||||||
faction *f = ctx->f;
|
faction *f = ctx->f;
|
||||||
const char *prefix;
|
const char *prefix, *str;
|
||||||
region *r;
|
region *r;
|
||||||
const char *mailto = config_get("game.email");
|
const char *mailto = config_get("game.email");
|
||||||
const attrib *a;
|
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\";Parteiname\n", f->name);
|
||||||
fprintf(F, "\"%s\";email\n", faction_getemail(f));
|
fprintf(F, "\"%s\";email\n", faction_getemail(f));
|
||||||
if (f->banner)
|
str = faction_getbanner(f);
|
||||||
fprintf(F, "\"%s\";banner\n", f->banner);
|
if (str) {
|
||||||
|
fprintf(F, "\"%s\";banner\n", str);
|
||||||
|
}
|
||||||
print_items(F, f->items, f->locale);
|
print_items(F, f->items, f->locale);
|
||||||
fputs("OPTIONEN\n", F);
|
fputs("OPTIONEN\n", F);
|
||||||
for (i = 0; i != MAXOPTIONS; ++i) {
|
for (i = 0; i != MAXOPTIONS; ++i) {
|
||||||
|
|
|
@ -106,7 +106,6 @@ static void free_faction(faction * f)
|
||||||
freelist(f->allies);
|
freelist(f->allies);
|
||||||
|
|
||||||
free(f->email);
|
free(f->email);
|
||||||
free(f->banner);
|
|
||||||
free(f->name);
|
free(f->name);
|
||||||
if (f->seen_factions) {
|
if (f->seen_factions) {
|
||||||
selist_free(f->seen_factions);
|
selist_free(f->seen_factions);
|
||||||
|
@ -593,16 +592,17 @@ void faction_setemail(faction * self, const char *email)
|
||||||
self->email = NULL;
|
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);
|
f->banner_id = dbstring_save(banner);
|
||||||
if (banner)
|
|
||||||
self->banner = str_strdup(banner);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *faction_getpassword(const faction *f) {
|
const char *faction_getpassword(const faction *f) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ extern "C" {
|
||||||
int uid;
|
int uid;
|
||||||
int flags;
|
int flags;
|
||||||
char *name;
|
char *name;
|
||||||
char *banner;
|
dbrow_id banner_id;
|
||||||
char *email;
|
char *email;
|
||||||
dbrow_id password_id;
|
dbrow_id password_id;
|
||||||
int max_spelllevel;
|
int max_spelllevel;
|
||||||
|
|
|
@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) {
|
||||||
CuAssertPtrNotNull(tc, f->name);
|
CuAssertPtrNotNull(tc, f->name);
|
||||||
CuAssertPtrEquals(tc, NULL, (void *)f->units);
|
CuAssertPtrEquals(tc, NULL, (void *)f->units);
|
||||||
CuAssertPtrEquals(tc, NULL, (void *)f->next);
|
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->spellbook);
|
||||||
CuAssertPtrEquals(tc, NULL, (void *)f->origin);
|
CuAssertPtrEquals(tc, NULL, (void *)f->origin);
|
||||||
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
|
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
|
||||||
|
@ -229,6 +229,18 @@ static void test_valid_race(CuTest *tc) {
|
||||||
test_teardown();
|
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) {
|
static void test_set_email(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
char email[10];
|
char email[10];
|
||||||
|
@ -335,6 +347,7 @@ CuSuite *get_faction_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_check_passwd);
|
SUITE_ADD_TEST(suite, test_check_passwd);
|
||||||
SUITE_ADD_TEST(suite, test_valid_race);
|
SUITE_ADD_TEST(suite, test_valid_race);
|
||||||
SUITE_ADD_TEST(suite, test_set_email);
|
SUITE_ADD_TEST(suite, test_set_email);
|
||||||
|
SUITE_ADD_TEST(suite, test_dbstrings);
|
||||||
SUITE_ADD_TEST(suite, test_save_special_items);
|
SUITE_ADD_TEST(suite, test_save_special_items);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1007,7 +1007,7 @@ faction *read_faction(gamedata * data)
|
||||||
if (unicode_utf8_trim(name)!=0) {
|
if (unicode_utf8_trim(name)!=0) {
|
||||||
log_warning("trim faction %s banner to '%s'", itoa36(f->no), name);
|
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));
|
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_INT(data->store, f->alliance_joindate);
|
||||||
|
|
||||||
WRITE_STR(data->store, f->name);
|
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_STR(data->store, f->email?f->email:"");
|
||||||
write_password(data, f);
|
write_password(data, f);
|
||||||
WRITE_TOK(data->store, locale_name(f->locale));
|
WRITE_TOK(data->store, locale_name(f->locale));
|
||||||
|
|
|
@ -2086,12 +2086,10 @@ int banner_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
const char * s;
|
const char * s;
|
||||||
|
|
||||||
free(u->faction->banner);
|
|
||||||
init_order_depr(ord);
|
init_order_depr(ord);
|
||||||
s = getstrtoken();
|
s = getstrtoken();
|
||||||
u->faction->banner = s ? str_strdup(s) : 0;
|
faction_setbanner(u->faction, s);
|
||||||
add_message(&u->faction->msgs, msg_message("changebanner", "value",
|
add_message(&u->faction->msgs, msg_message("changebanner", "value", s));
|
||||||
u->faction->banner));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1726,11 +1726,13 @@ static void list_address(struct stream *out, const faction * uf, selist * seenfa
|
||||||
while (flist != NULL) {
|
while (flist != NULL) {
|
||||||
const faction *f = (const faction *)selist_get(flist, qi);
|
const faction *f = (const faction *)selist_get(flist, qi);
|
||||||
if (!is_monsters(f)) {
|
if (!is_monsters(f)) {
|
||||||
|
const char *str;
|
||||||
char buf[8192];
|
char buf[8192];
|
||||||
char label = '-';
|
char label = '-';
|
||||||
|
|
||||||
|
str = faction_getbanner(f);
|
||||||
sprintf(buf, "%s: %s; %s", factionname(f), faction_getemail(f),
|
sprintf(buf, "%s: %s; %s", factionname(f), faction_getemail(f),
|
||||||
f->banner ? f->banner : "");
|
str ? str : "");
|
||||||
if (uf == f)
|
if (uf == f)
|
||||||
label = '*';
|
label = '*';
|
||||||
else if (is_allied(uf, f))
|
else if (is_allied(uf, f))
|
||||||
|
|
Loading…
Reference in a new issue