forked from github/server
Messages benutzen alte Hashfunktion für Typ-Key.
This commit is contained in:
parent
522a0bd8a2
commit
3248053efe
3 changed files with 19 additions and 4 deletions
|
@ -454,7 +454,7 @@ report_crtypes(FILE * F, const struct locale* lang)
|
||||||
for (kmt=mtypehash[i];kmt;kmt=kmt->nexthash) {
|
for (kmt=mtypehash[i];kmt;kmt=kmt->nexthash) {
|
||||||
const struct nrmessage_type * nrt = nrt_find(lang, kmt->mtype);
|
const struct nrmessage_type * nrt = nrt_find(lang, kmt->mtype);
|
||||||
if (nrt) {
|
if (nrt) {
|
||||||
unsigned int hash = hashstring(mt_name(kmt->mtype));
|
unsigned int hash = kmt->mtype->key;
|
||||||
fprintf(F, "MESSAGETYPE %d\n", hash);
|
fprintf(F, "MESSAGETYPE %d\n", hash);
|
||||||
fputc('\"', F);
|
fputc('\"', F);
|
||||||
fputs(escape_string(nrt_string(nrt), NULL, 0), F);
|
fputs(escape_string(nrt_string(nrt), NULL, 0), F);
|
||||||
|
@ -478,7 +478,7 @@ render_messages(FILE * F, faction * f, message_list *msgs)
|
||||||
char crbuffer[1024*32]; /* gross, wegen spionage-messages :-( */
|
char crbuffer[1024*32]; /* gross, wegen spionage-messages :-( */
|
||||||
boolean printed = false;
|
boolean printed = false;
|
||||||
const struct message_type * mtype = m->msg->type;
|
const struct message_type * mtype = m->msg->type;
|
||||||
unsigned int hash = hashstring(mtype->name);
|
unsigned int hash = mtype->key;
|
||||||
#ifdef RENDER_CRMESSAGES
|
#ifdef RENDER_CRMESSAGES
|
||||||
char nrbuffer[1024*32];
|
char nrbuffer[1024*32];
|
||||||
nrbuffer[0] = '\0';
|
nrbuffer[0] = '\0';
|
||||||
|
|
|
@ -174,18 +174,32 @@ mt_find(const char * name)
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int
|
||||||
|
mt_id(const message_type * mtype)
|
||||||
|
{
|
||||||
|
unsigned int key = 0;
|
||||||
|
size_t i = strlen(mtype->name);
|
||||||
|
|
||||||
|
while (i>0) {
|
||||||
|
key = (mtype->name[--i] + key*37);
|
||||||
|
}
|
||||||
|
return key % 0x7FFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const message_type *
|
const message_type *
|
||||||
mt_register(const message_type * type)
|
mt_register(message_type * type)
|
||||||
{
|
{
|
||||||
unsigned int hash = hashstring(type->name) % MT_MAXHASH;
|
unsigned int hash = hashstring(type->name) % MT_MAXHASH;
|
||||||
messagetype_list * mtl = messagetypes[hash];
|
messagetype_list * mtl = messagetypes[hash];
|
||||||
|
|
||||||
while (mtl && mtl->data!=type) mtl=mtl->next;
|
while (mtl && mtl->data!=type) mtl=mtl->next;
|
||||||
if (mtl==NULL) {
|
if (mtl==NULL) {
|
||||||
mtl = (messagetype_list*)malloc(sizeof(messagetype_list));
|
mtl = (messagetype_list*)malloc(sizeof(messagetype_list));
|
||||||
mtl->data = type;
|
mtl->data = type;
|
||||||
mtl->next = messagetypes[hash];
|
mtl->next = messagetypes[hash];
|
||||||
messagetypes[hash] = mtl;
|
messagetypes[hash] = mtl;
|
||||||
|
type->key = mt_id(type);
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ typedef struct arg_type {
|
||||||
} arg_type;
|
} arg_type;
|
||||||
|
|
||||||
typedef struct message_type {
|
typedef struct message_type {
|
||||||
|
unsigned int key;
|
||||||
const char * name;
|
const char * name;
|
||||||
int nparameters;
|
int nparameters;
|
||||||
const char ** pnames;
|
const char ** pnames;
|
||||||
|
@ -56,7 +57,7 @@ extern struct message * msg_addref(struct message * msg);
|
||||||
extern const char * mt_name(const struct message_type* mtype);
|
extern const char * mt_name(const struct message_type* mtype);
|
||||||
|
|
||||||
/** message_type registry (optional): **/
|
/** message_type registry (optional): **/
|
||||||
extern const struct message_type * mt_register(const struct message_type *);
|
extern const struct message_type * mt_register(struct message_type *);
|
||||||
extern const struct message_type * mt_find(const char *);
|
extern const struct message_type * mt_find(const char *);
|
||||||
|
|
||||||
extern void register_argtype(const char * name, void(*free_arg)(variant), variant (*copy_arg)(variant), variant_type);
|
extern void register_argtype(const char * name, void(*free_arg)(variant), variant (*copy_arg)(variant), variant_type);
|
||||||
|
|
Loading…
Reference in a new issue