Eigener Block für BOTSCHAFTen im NR

Ausserdem den ungenutzten REPORT Befehl entfernt.
This commit is contained in:
Enno Rehling 2006-03-26 18:26:52 +00:00
parent a04cb3efbd
commit dda37aaee6
12 changed files with 132 additions and 168 deletions

View File

@ -2034,21 +2034,6 @@ mail_cmd(unit * u, struct order * ord)
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static void
report_option(unit * u, const char * sec, struct order * ord)
{
const messageclass * mc;
const char *s;
mc = mc_find(sec);
if (mc == NULL) {
cmistake(u, ord, 135, MSG_EVENT);
return;
}
s = getstrtoken();
}
static int static int
banner_cmd(unit * u, struct order * ord) banner_cmd(unit * u, struct order * ord)
{ {
@ -2123,28 +2108,6 @@ password_cmd(unit * u, struct order * ord)
return 0; return 0;
} }
static int
report_cmd(unit * u, struct order * ord)
{
const char * s;
int i;
init_tokens(ord);
skip_token();
s = getstrtoken();
i = atoi(s);
sprintf(buf, "%d", i);
if (!strcmp(buf, s)) {
/* int level;
level = geti();
not implemented yet. set individual levels for f->msglevels */
} else {
report_option(u, s, ord);
}
return 0;
}
static int static int
send_cmd(unit * u, struct order * ord) send_cmd(unit * u, struct order * ord)
{ {
@ -2225,10 +2188,6 @@ set_passw(void)
if (password_cmd(u, ord)!=0) ord = NULL; if (password_cmd(u, ord)!=0) ord = NULL;
break; break;
case K_REPORT:
if (report_cmd(u, ord)!=0) ord = NULL;
break;
case K_SEND: case K_SEND:
if (send_cmd(u, ord)!=0) ord = NULL; if (send_cmd(u, ord)!=0) ord = NULL;
break; break;

View File

@ -585,24 +585,24 @@ rpunit(FILE * F, const faction * f, const unit * u, int indent, int mode)
static void static void
rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, boolean categorized) rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, boolean categorized)
{ {
messageclass * category; nrsection * section;
if (!msgs) return; if (!msgs) return;
for (category=msgclasses; category; category=category->next) { for (section = sections; section; section=section->next) {
int k = 0; int k = 0;
struct mlist * m = msgs->begin; struct mlist * m = msgs->begin;
while (m) { while (m) {
/* messagetype * mt = m->type; */ /* messagetype * mt = m->type; */
if (strcmp(nr_section(m->msg), category->name)==0) { if (strcmp(nr_section(m->msg), section->name)==0) {
char lbuf[8192]; char lbuf[8192];
if (!k && categorized) { if (!k && categorized) {
const char * category_title; const char * section_title;
char cat_identifier[24]; char cat_identifier[24];
rnl(F); rnl(F);
sprintf(cat_identifier, "section_%s", category->name); sprintf(cat_identifier, "section_%s", section->name);
category_title = LOC(viewer->locale, cat_identifier); section_title = LOC(viewer->locale, cat_identifier);
centre(F, category_title, true); centre(F, section_title, true);
rnl(F); rnl(F);
k = 1; k = 1;
} }

View File

@ -381,7 +381,6 @@ const char *keywords[MAXKEYWORDS] =
"ZERSTOEREN", "ZERSTOEREN",
"ZUECHTEN", "ZUECHTEN",
"DEFAULT", "DEFAULT",
"REPORT",
"URSPRUNG", "URSPRUNG",
"EMAIL", "EMAIL",
"MEINUNG", "MEINUNG",

View File

@ -403,7 +403,6 @@ enum {
K_DESTROY, K_DESTROY,
K_BREED, K_BREED,
K_DEFAULT, K_DEFAULT,
K_REPORT,
K_URSPRUNG, K_URSPRUNG,
K_EMAIL, K_EMAIL,
K_VOTE, K_VOTE,

View File

@ -58,37 +58,6 @@ typedef struct msg_setting {
#include "region.h" #include "region.h"
#include "eressea.h" #include "eressea.h"
messageclass * msgclasses;
const messageclass *
mc_find(const char * name)
{
messageclass ** mcp = &msgclasses;
if (name==NULL) return NULL;
for (;*mcp;mcp=&(*mcp)->next) {
messageclass * mc = *mcp;
if (!strcmp(mc->name, name)) break;
}
return *mcp;
}
const messageclass *
mc_add(const char * name)
{
messageclass ** mcp = &msgclasses;
if (name==NULL) return NULL;
for (;*mcp;mcp=&(*mcp)->next) {
messageclass * mc = *mcp;
if (!strcmp(mc->name, name)) break;
}
if (!*mcp) {
messageclass * mc = calloc(sizeof(messageclass), 1);
mc->name = strdup(name);
*mcp = mc;
}
return *mcp;
}
static void static void
arg_set(variant args[], const message_type * mtype, const char * buffer, variant v) arg_set(variant args[], const message_type * mtype, const char * buffer, variant v)
{ {

View File

@ -21,7 +21,6 @@ extern "C" {
#include <util/message.h> #include <util/message.h>
struct message; struct message;
struct messageclass;
struct faction; struct faction;
struct msglevel; struct msglevel;
@ -36,11 +35,6 @@ typedef struct message_list {
extern void free_messagelist(message_list * msgs); extern void free_messagelist(message_list * msgs);
typedef struct messageclass {
struct messageclass * next;
const char * name;
} messageclass;
typedef struct msglevel { typedef struct msglevel {
/* used to set specialized msg-levels */ /* used to set specialized msg-levels */
struct msglevel *next; struct msglevel *next;
@ -53,11 +47,6 @@ extern struct message * msg_feedback(const struct unit *, struct order *cmd,
const char * name, const char* sig, ...); const char * name, const char* sig, ...);
extern struct message * add_message(struct message_list** pm, struct message * m); extern struct message * add_message(struct message_list** pm, struct message * m);
/* message sections */
extern struct messageclass * msgclasses;
extern const struct messageclass * mc_add(const char * name);
extern const struct messageclass * mc_find(const char * name);
#define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } } #define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } }
extern void cmistake(const struct unit * u, struct order *ord, int mno, int mtype); extern void cmistake(const struct unit * u, struct order *ord, int mno, int mtype);

View File

@ -1758,7 +1758,6 @@ parse_messages(xmlDocPtr doc)
section = xmlGetProp(node, BAD_CAST "section"); section = xmlGetProp(node, BAD_CAST "section");
if (section==NULL) section = BAD_CAST default_section; if (section==NULL) section = BAD_CAST default_section;
mc_add((const char*)section);
/* strings */ /* strings */
xpath->node = node; xpath->node = node;

View File

@ -6,9 +6,9 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#include <config.h> #include <config.h>
@ -31,101 +31,138 @@
#define NRT_MAXHASH 1021 #define NRT_MAXHASH 1021
static nrmessage_type * messagetypes[NRT_MAXHASH]; static nrmessage_type * messagetypes[NRT_MAXHASH];
const char * const char *
nrt_string(const struct nrmessage_type *type) nrt_string(const struct nrmessage_type *type)
{ {
return type->string; return type->string;
} }
nrmessage_type * nrmessage_type *
nrt_find(const struct locale * lang, const struct message_type * mtype) nrt_find(const struct locale * lang, const struct message_type * mtype)
{ {
nrmessage_type * found = NULL; nrmessage_type * found = NULL;
unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH;
nrmessage_type * type = messagetypes[hash]; nrmessage_type * type = messagetypes[hash];
while (type) { while (type) {
if (type->mtype==mtype) { if (type->mtype==mtype) {
if (found==NULL) found = type; if (found==NULL) found = type;
else if (type->lang==NULL) found = type; else if (type->lang==NULL) found = type;
if (lang==type->lang) { if (lang==type->lang) {
found = type; found = type;
break; break;
} }
} }
type = type->next; type = type->next;
} }
if (lang && found->lang!=lang) { if (lang && found->lang!=lang) {
log_warning(("could not find nr-type %s for locale %s, substituting with %s\n", log_warning(("could not find nr-type %s for locale %s, substituting with %s\n",
mtype->name, locale_name(lang), locale_name(found->lang))); mtype->name, locale_name(lang), locale_name(found->lang)));
} }
return found; return found;
} }
void nrsection * sections;
const nrsection *
section_find(const char * name)
{
nrsection ** mcp = &sections;
if (name==NULL) return NULL;
for (;*mcp;mcp=&(*mcp)->next) {
nrsection * mc = *mcp;
if (!strcmp(mc->name, name)) break;
}
return *mcp;
}
const nrsection *
section_add(const char * name)
{
nrsection ** mcp = &sections;
if (name==NULL) return NULL;
for (;*mcp;mcp=&(*mcp)->next) {
nrsection * mc = *mcp;
if (!strcmp(mc->name, name)) break;
}
if (!*mcp) {
nrsection * mc = calloc(sizeof(nrsection), 1);
mc->name = strdup(name);
*mcp = mc;
}
return *mcp;
}
void
nrt_register(const struct message_type * mtype, const struct locale * lang, const char * string, int level, const char * section) nrt_register(const struct message_type * mtype, const struct locale * lang, const char * string, int level, const char * section)
{ {
unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH;
nrmessage_type * nrt = messagetypes[hash]; nrmessage_type * nrt = messagetypes[hash];
while (nrt && (nrt->lang!=lang || nrt->mtype!=mtype)) { while (nrt && (nrt->lang!=lang || nrt->mtype!=mtype)) {
nrt = nrt->next; nrt = nrt->next;
} }
if (!nrt) { if (!nrt) {
int i; int i;
char zNames[256]; char zNames[256];
char * c = zNames; char * c = zNames;
nrt = malloc(sizeof(nrmessage_type)); nrt = malloc(sizeof(nrmessage_type));
nrt->lang = lang; nrt->lang = lang;
nrt->mtype = mtype; nrt->mtype = mtype;
nrt->next = messagetypes[hash]; nrt->next = messagetypes[hash];
nrt->level=level; nrt->level=level;
if (section) nrt->section = strdup(section); if (section) {
else nrt->section = NULL; const nrsection * s = section_find(section);
messagetypes[hash] = nrt; if (s==NULL) {
assert(string && *string); s = section_add(section);
nrt->string = strdup(string); }
nrt->section = s->name;
}
else nrt->section = NULL;
messagetypes[hash] = nrt;
assert(string && *string);
nrt->string = strdup(string);
*c = '\0'; *c = '\0';
for (i=0;i!=mtype->nparameters;++i) { for (i=0;i!=mtype->nparameters;++i) {
if (i!=0) *c++ = ' '; if (i!=0) *c++ = ' ';
c+= strlen(strcpy(c, mtype->pnames[i])); c+= strlen(strcpy(c, mtype->pnames[i]));
} }
nrt->vars = strdup(zNames); nrt->vars = strdup(zNames);
/* TODO: really necessary to strdup them all? here? better to extend the caller? hash? */ /* TODO: really necessary to strdup them all? here? better to extend the caller? hash? */
} }
} }
size_t size_t
nr_render(const struct message * msg, const struct locale * lang, char * buffer, size_t size, const void * userdata) nr_render(const struct message * msg, const struct locale * lang, char * buffer, size_t size, const void * userdata)
{ {
struct nrmessage_type * nrt = nrt_find(lang, msg->type); struct nrmessage_type * nrt = nrt_find(lang, msg->type);
if (nrt) { if (nrt) {
const char * m = translate(nrt->string, userdata, nrt->vars, msg->parameters); const char * m = translate(nrt->string, userdata, nrt->vars, msg->parameters);
if (m) { if (m) {
return strlcpy(buffer, m, size); return strlcpy(buffer, m, size);
} else { } else {
log_error(("Couldn't render message %s\n", nrt->mtype->name)); log_error(("Couldn't render message %s\n", nrt->mtype->name));
} }
} }
if (size>0 && buffer) buffer[0] = 0; if (size>0 && buffer) buffer[0] = 0;
return 0; return 0;
} }
int int
nr_level(const struct message *msg) nr_level(const struct message *msg)
{ {
nrmessage_type * nrt = nrt_find(NULL, msg->type); nrmessage_type * nrt = nrt_find(NULL, msg->type);
return nrt->level; return nrt->level;
} }
const char * const char *
nr_section(const struct message *msg) nr_section(const struct message *msg)
{ {
nrmessage_type * nrt = nrt_find(default_locale, msg->type); nrmessage_type * nrt = nrt_find(default_locale, msg->type);
return nrt->section; return nrt->section;
} }
const char * const char *
nrt_section(const nrmessage_type * nrt) nrt_section(const nrmessage_type * nrt)
{ {
return nrt->section; return nrt->section;
} }

View File

@ -6,7 +6,7 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
@ -21,11 +21,18 @@ struct message;
struct message_type; struct message_type;
struct nrmessage_type; struct nrmessage_type;
extern void nrt_register(const struct message_type * mtype, typedef struct nrsection {
const struct locale * lang, const char * script, char * name;
int level, const char * section); struct nrsection * next;
extern struct nrmessage_type * nrt_find(const struct locale *, } nrsection;
const struct message_type *);
extern nrsection * sections;
extern void nrt_register(const struct message_type * mtype,
const struct locale * lang, const char * script,
int level, const char * section);
extern struct nrmessage_type * nrt_find(const struct locale *,
const struct message_type *);
extern const char * nrt_string(const struct nrmessage_type *type); extern const char * nrt_string(const struct nrmessage_type *type);
extern const char * nrt_section(const struct nrmessage_type * mt); extern const char * nrt_section(const struct nrmessage_type * mt);

View File

@ -674,7 +674,10 @@
<!--Meldungssektionen --> <!--Meldungssektionen -->
<string name="section_events"> <string name="section_events">
<text locale="de">Meldungen und Ereignisse</text> <text locale="de">Ereignisse</text>
</string>
<string name="section_mail">
<text locale="de">Botschaften</text>
</string> </string>
<string name="section_errors"> <string name="section_errors">
<text locale="de">Warnungen und Fehler</text> <text locale="de">Warnungen und Fehler</text>

View File

@ -257,8 +257,11 @@
<text locale="en">an unknown unit</text> <text locale="en">an unknown unit</text>
</string> </string>
<string name="section_mail">
<text locale="en">Dispatches</text>
</string>
<string name="section_events"> <string name="section_events">
<text locale="en">Messages and Events</text> <text locale="en">Events</text>
</string> </string>
<string name="section_errors"> <string name="section_errors">
<text locale="en">Warnings and Errors</text> <text locale="en">Warnings and Errors</text>

View File

@ -611,7 +611,7 @@
<text locale="fr">"$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away."</text> <text locale="fr">"$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away."</text> <text locale="en">"$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away."</text>
</message> </message>
<message name="regionmessage" section="events"> <message name="regionmessage" section="mail">
<type> <type>
<arg name="sender" type="unit"/> <arg name="sender" type="unit"/>
<arg name="region" type="region"/> <arg name="region" type="region"/>
@ -620,7 +620,7 @@
<text locale="de">"Eine Botschaft von $unit($sender) aus $region($region): '$string'"</text> <text locale="de">"Eine Botschaft von $unit($sender) aus $region($region): '$string'"</text>
<text locale="en">"A message by $unit($sender) from $region($region): '$string'"</text> <text locale="en">"A message by $unit($sender) from $region($region): '$string'"</text>
</message> </message>
<message name="unitmessage" section="events"> <message name="unitmessage" section="mail">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>
<arg name="region" type="region"/> <arg name="region" type="region"/>