XML reports - incomplete implementation, might finish it eventually.

This commit is contained in:
Enno Rehling 2005-11-18 23:23:47 +00:00
parent 4660c690a8
commit 357a73e826
14 changed files with 262 additions and 31 deletions

View File

@ -18,6 +18,7 @@ SOURCES =
report.c report.c
spy.c spy.c
study.c study.c
xmlreport.c
; ;
Library gamecode : $(SOURCES) ; Library gamecode : $(SOURCES) ;

View File

@ -1041,7 +1041,7 @@ cr_borders(seen_region ** seen, const region * r, const faction * f, int seemode
/* main function of the creport. creates the header and traverses all regions */ /* main function of the creport. creates the header and traverses all regions */
static int static int
report_computer(FILE * F, report_context * ctx) report_computer(const char * filename, report_context * ctx)
{ {
int i; int i;
faction * f = ctx->f; faction * f = ctx->f;
@ -1057,6 +1057,11 @@ report_computer(FILE * F, report_context * ctx)
#ifdef SCORE_MODULE #ifdef SCORE_MODULE
int score = 0, avgscore = 0; int score = 0, avgscore = 0;
#endif #endif
FILE * F = fopen(filename, "wt");
if (F==NULL) {
perror(filename);
return -1;
}
/* must call this to get all the neighbour regions */ /* must call this to get all the neighbour regions */
get_seen_interval(ctx->seen, &first, &last); get_seen_interval(ctx->seen, &first, &last);
@ -1229,17 +1234,8 @@ report_computer(FILE * F, report_context * ctx)
} }
fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname))); fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname)));
switch (sd->mode) { if (sd->mode!=see_unit) fprintf(F, "\"%s\";visibility\n", visibility[sd->mode]);
case see_far:
fputs("\"neighbourhood\";visibility\n", F);
break;
case see_lighthouse:
fputs("\"lighthouse\";visibility\n", F);
break;
case see_travel:
fputs("\"travel\";visibility\n", F);
break;
}
{ {
unit * owner = region_owner(r); unit * owner = region_owner(r);
if (owner) { if (owner) {
@ -1441,6 +1437,7 @@ report_computer(FILE * F, report_context * ctx)
log_error(("%s\n", strerror(errno))); log_error(("%s\n", strerror(errno)));
errno = 0; errno = 0;
} }
fclose(F);
return 0; return 0;
} }

View File

@ -203,6 +203,9 @@
<File <File
RelativePath=".\report.h"> RelativePath=".\report.h">
</File> </File>
<File
RelativePath=".\xmlreport.h">
</File>
</Filter> </Filter>
<File <File
RelativePath=".\creation.c"> RelativePath=".\creation.c">
@ -237,6 +240,9 @@
<File <File
RelativePath=".\study.c"> RelativePath=".\study.c">
</File> </File>
<File
RelativePath=".\xmlreport.c">
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@ -1417,12 +1417,17 @@ buildingmaintenance(const building * b, const resource_type * rtype)
} }
static int static int
report_template(FILE * F, report_context * ctx) report_template(const char * filename, report_context * ctx)
{ {
faction * f = ctx->f; faction * f = ctx->f;
region *r; region *r;
plane *pl; plane *pl;
region *last = lastregion(f); region *last = lastregion(f);
FILE * F = fopen(filename, "wt");
if (F==NULL) {
perror(filename);
return -1;
}
rps_nowrap(F, ""); rps_nowrap(F, "");
rnl(F); rnl(F);
@ -1538,6 +1543,7 @@ report_template(FILE * F, report_context * ctx)
sprintf(buf, LOC(f->locale, parameters[P_NEXT])); sprintf(buf, LOC(f->locale, parameters[P_NEXT]));
rps_nowrap(F, buf); rps_nowrap(F, buf);
rnl(F); rnl(F);
fclose(F);
return 0; return 0;
} }
@ -1894,7 +1900,7 @@ report_building(FILE *F, const region * r, const building * b, const faction * f
} }
int int
report_plaintext(FILE *F, report_context * ctx) report_plaintext(const char * filename, report_context * ctx)
{ {
int flag = 0; int flag = 0;
char ch; char ch;
@ -1912,6 +1918,11 @@ report_plaintext(FILE *F, report_context * ctx)
region * last = lastregion(f); region * last = lastregion(f);
int ix = Pow(O_STATISTICS); int ix = Pow(O_STATISTICS);
int wants_stats = (f->options & ix); int wants_stats = (f->options & ix);
FILE * F = fopen(filename, "wt");
if (F==NULL) {
perror(filename);
return -1;
}
strftime(pzTime, 64, "%A, %d. %B %Y, %H:%M", localtime(&ctx->report_time)); strftime(pzTime, 64, "%A, %d. %B %Y, %H:%M", localtime(&ctx->report_time));
m = msg_message("nr_header_date", "game date", global.gamename, pzTime); m = msg_message("nr_header_date", "game date", global.gamename, pzTime);
@ -2318,6 +2329,7 @@ report_plaintext(FILE *F, report_context * ctx)
list_address(F, f, ctx->addresses); list_address(F, f, ctx->addresses);
} }
} }
fclose(F);
return 0; return 0;
} }

View File

@ -0,0 +1,182 @@
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2003
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
#include <config.h>
#include <eressea.h>
#include "xmlreport.h"
/* tweakable features */
#define ENCODE_SPECIAL 1
#define RENDER_CRMESSAGES
/* modules include */
#include <modules/score.h>
/* attributes include */
#include <attributes/follow.h>
#include <attributes/racename.h>
#include <attributes/orcification.h>
#include <attributes/otherfaction.h>
#include <attributes/raceprefix.h>
/* gamecode includes */
#include "laws.h"
#include "economy.h"
/* kernel includes */
#include <kernel/alchemy.h>
#include <kernel/alliance.h>
#include <kernel/border.h>
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
#include <kernel/karma.h>
#include <kernel/magic.h>
#include <kernel/message.h>
#include <kernel/movement.h>
#include <kernel/order.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/reports.h>
#include <kernel/resources.h>
#include <kernel/ship.h>
#include <kernel/skill.h>
#include <kernel/teleport.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/save.h>
/* util includes */
#include <util/message.h>
#include <goodies.h>
#include <base36.h>
#include <language.h>
/* libxml2 includes */
#include <libxml/tree.h>
#include <iconv.h>
/* libc includes */
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define L10N(x) x
static iconv_t utf8;
static xmlChar*
xml_s(const char * str)
{
static char buffer[1024];
const char * inbuf = str;
char * outbuf = buffer;
size_t inbytes = strlen(str)+1;
size_t outbytes = sizeof(buffer);
iconv(utf8, (const char**)&inbuf, &inbytes, (char**)&outbuf, &outbytes);
return (xmlChar*)buffer;
}
static xmlChar*
xml_i(double number)
{
static char buffer[128];
sprintf(buffer, "%.0lf", number);
return (xmlChar*)buffer;
}
static xmlNodePtr
report_faction(report_context * ctx, faction * f)
{
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "faction");
xmlNewProp(node, BAD_CAST "id", xml_i(f->no));
xmlNewProp(node, BAD_CAST "name", xml_s(f->name));
xmlNewProp(node, BAD_CAST "email", xml_s(f->email));
if (f->banner && *f->banner) xmlNewProp(node, BAD_CAST "banner", xml_s(f->banner));
if (f==ctx->f) {
const char * s;
xmlNewProp(node, BAD_CAST "locale", BAD_CAST locale_name(f->locale));
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;
}
static xmlNodePtr
report_region(report_context * ctx, seen_region * sr)
{
const region * r = sr->r;
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "region");
xmlNewProp(node, BAD_CAST "terrain", xml_s(L10N(terrain_name(r))));
xmlNewProp(node, BAD_CAST "x", xml_i(r->x));
xmlNewProp(node, BAD_CAST "y", xml_i(r->y));
xmlNewProp(node, BAD_CAST "view", xml_s(visibility[sr->mode]));
if (r->planep) {
xmlNewProp(node, BAD_CAST "plane", xml_s(r->planep->name));
}
if (r->land!=NULL) {
xmlNewProp(node, BAD_CAST "name", xml_s(r->land->name));
}
return node;
}
/* main function of the xmlreport. creates the header and traverses all regions */
static int
report_xml(const char * filename, report_context * ctx)
{
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
xmlNodePtr xmlReport = xmlNewNode(NULL, BAD_CAST "report");
const faction_list * address;
region * r = firstregion(ctx->f), * rend = lastregion(ctx->f);
for (address=ctx->addresses;address;address=address->next) {
xmlAddChild(xmlReport, report_faction(ctx, address->data));
}
get_seen_interval(ctx->seen, &r, &rend);
for (;r!=rend;r=r->next) {
seen_region * sr = find_seen(ctx->seen, r);
if (sr!=NULL) xmlAddChild(xmlReport, report_region(ctx, sr));
}
xmlDocSetRootElement(doc, xmlReport);
xmlKeepBlanksDefault(0);
xmlSaveFormatFileEnc(filename, doc, "utf-8", 1);
xmlFreeDoc(doc);
return 0;
}
void
xmlreport_init(void)
{
register_reporttype("xml", &report_xml, 1<<O_XML);
utf8 = iconv_open("UTF-8", "");
}
void
xmlreport_cleanup(void)
{
iconv_close(utf8);
}

View File

@ -0,0 +1,27 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2005 | Enno Rehling <enno@eressea.de>
+-------------------+
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef H_GC_XMLREPORT
#define H_GC_XMLREPORT
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
extern void xmlreport_cleanup(void);
extern void xmlreport_init(void);
extern int crwritemap(const char * filename);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -447,7 +447,8 @@ const char *options[MAXOPTIONS] =
"ADRESSEN", "ADRESSEN",
"BZIP2", "BZIP2",
"PUNKTE", "PUNKTE",
"SHOWSKCHANGE" "SHOWSKCHANGE",
"XML"
}; };
static int static int

View File

@ -574,9 +574,10 @@ enum {
O_NEWS, /* 128 */ O_NEWS, /* 128 */
O_MATERIALPOOL, /* 256 */ O_MATERIALPOOL, /* 256 */
O_ADRESSEN, /* 512 */ O_ADRESSEN, /* 512 */
O_BZIP2, /* 1024 - crkurz compatible flag */ O_BZIP2, /* 1024 - compress as bzip2 */
O_SCORE, /* 2048 - punkte anzeigen? */ O_SCORE, /* 2048 - punkte anzeigen? */
O_SHOWSKCHANGE, /* 4096 - Skillveränderungen anzeigen? */ O_SHOWSKCHANGE, /* 4096 - Skillveränderungen anzeigen? */
O_XML, /* 8192 - XML report versenden */
MAXOPTIONS MAXOPTIONS
}; };

View File

@ -62,6 +62,15 @@
#include <attributes/viewrange.h> #include <attributes/viewrange.h>
const char * g_reportdir; const char * g_reportdir;
const char * visibility[] = {
"none",
"neighbour",
"lighthouse",
"travel",
"far",
"unit",
"battle"
};
const char *coasts[MAXDIRECTIONS] = const char *coasts[MAXDIRECTIONS] =
{ {
@ -1505,16 +1514,13 @@ write_reports(faction * f, time_t ltime)
for (;rtype!=NULL;rtype=rtype->next) { for (;rtype!=NULL;rtype=rtype->next) {
if (f->options & rtype->flag) { if (f->options & rtype->flag) {
FILE * F; char * filename;
sprintf(buf, "%s/%d-%s.%s", reportpath(), turn, factionid(f), rtype->extension); sprintf(buf, "%s/%d-%s.%s", reportpath(), turn, factionid(f), rtype->extension);
F = fopen(buf, "wt"); filename = strdup(buf);
if (F!=NULL) { if (rtype->write(filename, &ctx)==0) {
rtype->write(F, &ctx);
fclose(F);
gotit = true; gotit = true;
} else {
perror(buf);
} }
free(filename);
} }
} }

View File

@ -85,6 +85,7 @@ extern struct seen_region ** seen_init(void);
extern void seen_done(struct seen_region * seehash[]); extern void seen_done(struct seen_region * seehash[]);
extern void free_seen(void); extern void free_seen(void);
extern void get_seen_interval(struct seen_region ** seen, struct region ** first, struct region ** last); extern void get_seen_interval(struct seen_region ** seen, struct region ** first, struct region ** last);
extern const char * visibility[];
typedef struct report_context { typedef struct report_context {
struct faction * f; struct faction * f;

View File

@ -56,6 +56,7 @@
/* gamecode includes */ /* gamecode includes */
#include <gamecode/creport.h> #include <gamecode/creport.h>
#include <gamecode/xmlreport.h>
#include <gamecode/report.h> #include <gamecode/report.h>
#include <gamecode/economy.h> #include <gamecode/economy.h>
#include <gamecode/items.h> #include <gamecode/items.h>
@ -207,6 +208,7 @@ game_init(void)
reports_init(); reports_init();
report_init(); report_init();
creport_init(); creport_init();
xmlreport_init();
debug_language("locales.log"); debug_language("locales.log");
register_races(); register_races();

View File

@ -19,7 +19,7 @@
<xi:include href="dungeons.xml"/> <xi:include href="dungeons.xml"/>
<game name="Eressea" welcome="eressea"> <game name="Eressea" welcome="eressea">
<comment>Game specific</comment> <!-- Game specific settings -->
<order name="MEINUNG" disable="yes"/> <order name="MEINUNG" disable="yes"/>
<order name="MAGIEGEBIET" disable="yes"/> <order name="MAGIEGEBIET" disable="yes"/>
<param name="entertain.base" value="0"/> <param name="entertain.base" value="0"/>
@ -28,9 +28,7 @@
<param name="nmr.removenewbie" value="2"/> <param name="nmr.removenewbie" value="2"/>
<param name="GiveRestriction" value="3"/> <param name="GiveRestriction" value="3"/>
<param name="hunger.long" value="1"/> <param name="hunger.long" value="1"/>
<param name="database.gameid" value="0"/>
<param name="rules.check_overload" value="0"/> <param name="rules.check_overload" value="0"/>
<param name="report.mailit" value="/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin"/>
</game> </game>
<xi:include href="eressea/de/strings.xml"/> <xi:include href="eressea/de/strings.xml"/>
<xi:include href="eressea/en/strings.xml"/> <xi:include href="eressea/en/strings.xml"/>

View File

@ -19,7 +19,7 @@
<xi:include href="terrains.xml"/> <xi:include href="terrains.xml"/>
<game name="Tutorial" welcome="tutorial"> <game name="Tutorial" welcome="tutorial">
<comment>Game specific</comment> <!-- Game specific settings -->
<order name="EMAIL" disable="yes"></order> <order name="EMAIL" disable="yes"></order>
<order name="MEINUNG" disable="yes"></order> <order name="MEINUNG" disable="yes"></order>
<order name="MAGIEGEBIET" disable="yes"></order> <order name="MAGIEGEBIET" disable="yes"></order>
@ -28,10 +28,8 @@
<param name="nmr.timeout" value="2"></param> <param name="nmr.timeout" value="2"></param>
<param name="nmr.removenewbie" value="1"></param> <param name="nmr.removenewbie" value="1"></param>
<param name="GiveRestriction" value="3"></param> <param name="GiveRestriction" value="3"></param>
<param name="database.gameid" value="1"></param>
<param name="hunger.long" value="1"></param> <param name="hunger.long" value="1"></param>
<param name="MaxAge" value="8"></param> <param name="MaxAge" value="8"></param>
<param name="report.mailit" value="/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin"/>
</game> </game>
<xi:include file="tutorial/de/strings.xml"/> <xi:include file="tutorial/de/strings.xml"/>
<xi:include file="tutorial/en/strings.xml"/> <xi:include file="tutorial/en/strings.xml"/>

View File

@ -18,7 +18,7 @@
<xi:include href="terrains.xml"/> <xi:include href="terrains.xml"/>
<game name="Wettstreit der Weisen" unitsperalliance="yes" units="1000" welcome="vinyambar"> <game name="Wettstreit der Weisen" unitsperalliance="yes" units="1000" welcome="vinyambar">
<comment>Game specific</comment> <!-- Game specific settings -->
<order name="ARBEITEN" disable="yes"/> <order name="ARBEITEN" disable="yes"/>
<order name="MEINUNG" disable="yes"/> <order name="MEINUNG" disable="yes"/>
<order name="MAGIEGEBIET" disable="yes"/> <order name="MAGIEGEBIET" disable="yes"/>
@ -27,7 +27,6 @@
<param name="nmr.timeout" value="5"/> <param name="nmr.timeout" value="5"/>
<param name="nmr.removenewbie" value="0"/> <param name="nmr.removenewbie" value="0"/>
<param name="GiveRestriction" value="0"/> <param name="GiveRestriction" value="0"/>
<param name="database.gameid" value="3"/>
<param name="hunger.long" value="0"/> <param name="hunger.long" value="0"/>
<param name="atsroi.ats" value="2"/> <param name="atsroi.ats" value="2"/>
<param name="atsroi.roi" value="4"/> <param name="atsroi.roi" value="4"/>