forked from github/server
- Fixed assigning r->uid to regions that haven't got one
- restarted implementation of xml report
This commit is contained in:
parent
7cb18e90ea
commit
a761c686cd
2 changed files with 82 additions and 31 deletions
|
@ -20,6 +20,8 @@
|
||||||
#define ENCODE_SPECIAL 1
|
#define ENCODE_SPECIAL 1
|
||||||
#define RENDER_CRMESSAGES
|
#define RENDER_CRMESSAGES
|
||||||
|
|
||||||
|
#define XML_ATL_NAMESPACE (const xmlChar *) "http://www.eressea.de/XML/2008/atlantis"
|
||||||
|
|
||||||
/* modules include */
|
/* modules include */
|
||||||
#include <modules/score.h>
|
#include <modules/score.h>
|
||||||
|
|
||||||
|
@ -82,6 +84,12 @@
|
||||||
|
|
||||||
#define L10N(x) x
|
#define L10N(x) x
|
||||||
|
|
||||||
|
typedef struct xml_context {
|
||||||
|
xmlDocPtr doc;
|
||||||
|
xmlNsPtr ns_atl;
|
||||||
|
xmlNsPtr ns_xml;
|
||||||
|
} xml_context;
|
||||||
|
|
||||||
static const xmlChar *
|
static const xmlChar *
|
||||||
xml_s(const char * str)
|
xml_s(const char * str)
|
||||||
{
|
{
|
||||||
|
@ -104,55 +112,84 @@ xml_i(double number)
|
||||||
return (const xmlChar *)buffer;
|
return (const xmlChar *)buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static xmlNodePtr
|
||||||
|
report_unit(report_context * ctx, unit * u, int mode)
|
||||||
|
{
|
||||||
|
xml_context* xct = (xml_context*)ctx->userdata;
|
||||||
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "unit");
|
||||||
|
char unit_id[20];
|
||||||
|
|
||||||
|
sprintf(unit_id, "unit_%d", u->no);
|
||||||
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)unit_id);
|
||||||
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(u->no));
|
||||||
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)u->name);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
static xmlNodePtr
|
static xmlNodePtr
|
||||||
report_faction(report_context * ctx, faction * f)
|
report_faction(report_context * ctx, faction * f)
|
||||||
{
|
{
|
||||||
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "faction");
|
xml_context* xct = (xml_context*)ctx->userdata;
|
||||||
xmlNewProp(node, BAD_CAST "id", xml_i(f->no));
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
|
||||||
xmlNewProp(node, BAD_CAST "name", (const xmlChar *)f->name);
|
char faction_id[20];
|
||||||
xmlNewProp(node, BAD_CAST "email", xml_s(f->email));
|
|
||||||
if (f->banner && *f->banner) xmlNewProp(node, BAD_CAST "banner", (const xmlChar *)f->banner);
|
sprintf(faction_id, "faction_%d", f->no);
|
||||||
if (f==ctx->f) {
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)faction_id);
|
||||||
const char * s;
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(f->no));
|
||||||
xmlNewProp(node, BAD_CAST "locale", BAD_CAST locale_name(f->locale));
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)f->name);
|
||||||
xmlNewProp(node, BAD_CAST "age", xml_i(f->age));
|
|
||||||
xmlNewProp(node, BAD_CAST "options", xml_i(f->options));
|
|
||||||
xmlNewProp(node, BAD_CAST "race", xml_s(L10N(rc_name(f->race, 0))));
|
|
||||||
xmlNewProp(node, BAD_CAST "magic", xml_s(L10N(magietypen[f->magiegebiet])));
|
|
||||||
s = get_prefix(f->attribs);;
|
|
||||||
if (s) {
|
|
||||||
xmlNewProp(node, BAD_CAST "prefix", xml_s(L10N(s)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static xmlNodePtr
|
static xmlNodePtr
|
||||||
report_region(report_context * ctx, seen_region * sr)
|
report_region(report_context * ctx, seen_region * sr)
|
||||||
{
|
{
|
||||||
|
xml_context* xct = (xml_context*)ctx->userdata;
|
||||||
const region * r = sr->r;
|
const region * r = sr->r;
|
||||||
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "region");
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "region");
|
||||||
xmlNewProp(node, BAD_CAST "terrain", xml_s(L10N(terrain_name(r))));
|
xmlNodePtr child;
|
||||||
xmlNewProp(node, BAD_CAST "x", xml_i(r->x));
|
char region_id[20];
|
||||||
xmlNewProp(node, BAD_CAST "y", xml_i(r->y));
|
int stealthmod = stealth_modifier(sr->mode);
|
||||||
xmlNewProp(node, BAD_CAST "view", xml_s(visibility[sr->mode]));
|
unit * u;
|
||||||
|
|
||||||
|
sprintf(region_id, "region_%u", r->uid);
|
||||||
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, BAD_CAST region_id);
|
||||||
|
|
||||||
|
child = xmlNewNode(xct->ns_atl, BAD_CAST "coordinate");
|
||||||
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "x", xml_i(r->x));
|
||||||
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "y", xml_i(r->y));
|
||||||
if (r->planep) {
|
if (r->planep) {
|
||||||
xmlNewProp(node, BAD_CAST "plane", xml_s(r->planep->name));
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", xml_s(r->planep->name));
|
||||||
}
|
}
|
||||||
|
xmlAddChild(node, child);
|
||||||
|
|
||||||
if (r->land!=NULL) {
|
if (r->land!=NULL) {
|
||||||
xmlNewProp(node, BAD_CAST "name", (const xmlChar *)r->land->name);
|
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)r->land->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
child = xmlNewNode(xct->ns_atl, BAD_CAST "terrain");
|
||||||
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)terrain_name(r));
|
||||||
|
|
||||||
|
for (u=r->units;u;u=u->next) {
|
||||||
|
if (u->building || u->ship || (stealthmod>INT_MIN && cansee(ctx->f, r, u, stealthmod))) {
|
||||||
|
xmlAddChild(node, report_unit(ctx, u, sr->mode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* main function of the xmlreport. creates the header and traverses all regions */
|
static xmlNodePtr
|
||||||
static int
|
report_root(report_context * ctx)
|
||||||
report_xml(const char * filename, report_context * ctx, const char * encoding)
|
|
||||||
{
|
{
|
||||||
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
|
|
||||||
xmlNodePtr xmlReport = xmlNewNode(NULL, BAD_CAST "report");
|
|
||||||
const faction_list * address;
|
const faction_list * address;
|
||||||
region * r = ctx->first, * rend = ctx->last;
|
region * r = ctx->first, * rend = ctx->last;
|
||||||
|
xml_context* xct = (xml_context*)ctx->userdata;
|
||||||
|
xmlNodePtr xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis");
|
||||||
|
|
||||||
|
xct->ns_xml = xmlNewNs(xmlReport, XML_XML_NAMESPACE, BAD_CAST "xml");
|
||||||
|
xct->ns_atl = xmlNewNs(xmlReport, XML_ATL_NAMESPACE, NULL);
|
||||||
|
xmlSetNs(xmlReport, xct->ns_atl);
|
||||||
|
|
||||||
for (address=ctx->addresses;address;address=address->next) {
|
for (address=ctx->addresses;address;address=address->next) {
|
||||||
xmlAddChild(xmlReport, report_faction(ctx, address->data));
|
xmlAddChild(xmlReport, report_faction(ctx, address->data));
|
||||||
|
@ -162,7 +199,21 @@ report_xml(const char * filename, report_context * ctx, const char * encoding)
|
||||||
seen_region * sr = find_seen(ctx->seen, r);
|
seen_region * sr = find_seen(ctx->seen, r);
|
||||||
if (sr!=NULL) xmlAddChild(xmlReport, report_region(ctx, sr));
|
if (sr!=NULL) xmlAddChild(xmlReport, report_region(ctx, sr));
|
||||||
}
|
}
|
||||||
xmlDocSetRootElement(doc, xmlReport);
|
return xmlReport;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* main function of the xmlreport. creates the header and traverses all regions */
|
||||||
|
static int
|
||||||
|
report_xml(const char * filename, report_context * ctx, const char * encoding)
|
||||||
|
{
|
||||||
|
xml_context xct;
|
||||||
|
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
|
||||||
|
|
||||||
|
xct.doc = doc;
|
||||||
|
assert(ctx->userdata==NULL);
|
||||||
|
ctx->userdata = &xct;
|
||||||
|
|
||||||
|
xmlDocSetRootElement(doc, report_root(ctx));
|
||||||
xmlKeepBlanksDefault(0);
|
xmlKeepBlanksDefault(0);
|
||||||
xmlSaveFormatFileEnc(filename, doc, "utf-8", 1);
|
xmlSaveFormatFileEnc(filename, doc, "utf-8", 1);
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
|
|
|
@ -431,7 +431,7 @@ hash_uid(region * r)
|
||||||
}
|
}
|
||||||
assert(uidhash[key].r!=r || !"duplicate registration");
|
assert(uidhash[key].r!=r || !"duplicate registration");
|
||||||
}
|
}
|
||||||
uid = rng_int();
|
r->uid = uid = rng_int();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue