diff --git a/src/common/modules/gmcmd.c b/src/common/modules/gmcmd.c index 5321a8438..b685afb2f 100644 --- a/src/common/modules/gmcmd.c +++ b/src/common/modules/gmcmd.c @@ -176,7 +176,7 @@ gm_gate(const char * str, void * data, const char * cmd) /** - ** GM: TERRAFORM + ** GM: TERRAFORM ** requires: permission-key "gmterf" **/ static void @@ -234,7 +234,70 @@ gm_teleport(const char * str, void * data, const char * cmd) } /** - ** GM: BROADCAST + ** GM: TELL PLANE + ** requires: permission-key "gmmsgr" + **/ +static void +gm_messageplane(const char * str, void * data, const char * cmd) +{ + unit * u = (unit*)data; + const struct plane * p = rplane(u->region); + const char * msg = igetstrtoken(str); + if (p==NULL) { + mistake(u, cmd, "In diese Ebene kann keine Nachricht gesandt werden.\n", 0); + } else { + /* checking permissions */ + attrib * permissions = a_find(u->faction->attribs, &at_permissions); + if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) { + mistake(u, cmd, "Unzureichende Rechte für diesen Befehl.\n", 0); + } + else { + faction * f; + region * r; + for (f=factions;f;f=f->next) { + freset(f, FL_DH); + } + for (r=regions;r;r=r->next) { + unit * u; + if (rplane(r)!=p) continue; + for (u=r->units;u;u=u->next) if (!fval(u->faction, FL_DH)) { + f = u->faction; + fset(f, FL_DH); + add_message(&f->msgs, msg_message("msg_event", "string", msg)); + } + } + } + } +} + +static void +gm_messagefaction(const char * str, void * data, const char * cmd) +{ + unit * u = (unit*)data; + int n = atoi36(igetstrtoken(str)); + faction * f = findfaction(n); + const char * msg = getstrtoken(); + plane * p = rplane(u->region); + attrib * permissions = a_find(u->faction->attribs, &at_permissions); + if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) { + mistake(u, cmd, "Unzureichende Rechte für diesen Befehl.\n", 0); + return; + } + if (f!=NULL) { + region * r; + for (r=regions;r;r=r->next) if (rplane(r)==p) { + unit * u; + for (u=r->units;u;u=u->next) if (u->faction==f) { + add_message(&f->msgs, msg_message("msg_event", "string", msg)); + return; + } + } + } + mistake(u, cmd, "An diese Partei kann keine Nachricht gesandt werden.\n", 0); +} + +/** + ** GM: TELL REGION ** requires: permission-key "gmmsgr" **/ static void @@ -397,8 +460,9 @@ gm_skill(const char * str, void * data, const char * cmd) } } -static struct command * g_cmds; static tnode g_keys; +static tnode g_root; +static tnode g_tell; static void gm_command(const char * str, void * data, const char * cmd) @@ -406,21 +470,30 @@ gm_command(const char * str, void * data, const char * cmd) do_command(&g_keys, data, str); } +static void +gm_tell(const char * str, void * data, const char * cmd) +{ + do_command(&g_tell, data, str); +} + void init_gmcmd(void) { at_register(&at_gmcreate); at_register(&at_permissions); - add_command(&g_keys, &g_cmds, "gm", &gm_command); - add_command(&g_keys, &g_cmds, "terraform", &gm_terraform); - add_command(&g_keys, &g_cmds, "create", &gm_create); - add_command(&g_keys, &g_cmds, "gate", &gm_gate); - add_command(&g_keys, &g_cmds, "give", &gm_give); - add_command(&g_keys, &g_cmds, "take", &gm_take); - add_command(&g_keys, &g_cmds, "teleport", &gm_teleport); - add_command(&g_keys, &g_cmds, "skill", &gm_skill); - add_command(&g_keys, &g_cmds, "broadcast", &gm_messageregion); - add_command(&g_keys, &g_cmds, "tell", &gm_messageunit); + add_command(&g_root, "gm", &gm_command); + add_command(&g_keys, "terraform", &gm_terraform); + add_command(&g_keys, "create", &gm_create); + add_command(&g_keys, "gate", &gm_gate); + add_command(&g_keys, "give", &gm_give); + add_command(&g_keys, "take", &gm_take); + add_command(&g_keys, "teleport", &gm_teleport); + add_command(&g_keys, "skill", &gm_skill); + add_command(&g_keys, "tell", &gm_tell); + add_command(&g_tell, "region", &gm_messageregion); + add_command(&g_tell, "unit", &gm_messageunit); + add_command(&g_tell, "plane", &gm_messageplane); + add_command(&g_tell, "faction", &gm_messagefaction); } /* @@ -439,7 +512,7 @@ gmcommands(void) strlist * order; for (order = u->orders; order; order = order->next) if (igetkeyword(order->s, u->faction->locale) == K_GM) { - do_command(&g_keys, u, order->s); + do_command(&g_root, u, order->s); } if (u==*up) up = &u->next; } diff --git a/src/common/modules/infocmd.c b/src/common/modules/infocmd.c index 8113e362f..ad8f3cb32 100644 --- a/src/common/modules/infocmd.c +++ b/src/common/modules/infocmd.c @@ -100,7 +100,6 @@ info_vacation(const char * str, void * data, const char * cmd) } } -static struct command * g_cmds; static tnode g_keys; void @@ -133,11 +132,11 @@ info_command(const char * str, void * data, const char * cmd) void init_info(void) { - add_command(&g_keys, &g_cmds, "info", &info_command); + add_command(&g_keys, "info", &info_command); - add_command(&g_keys, &g_cmds, "email", &info_email); - add_command(&g_keys, &g_cmds, "name", &info_name); - add_command(&g_keys, &g_cmds, "adresse", &info_address); - add_command(&g_keys, &g_cmds, "telefon", &info_phone); - add_command(&g_keys, &g_cmds, "urlaub", &info_vacation); + add_command(&g_keys, "email", &info_email); + add_command(&g_keys, "name", &info_name); + add_command(&g_keys, "adresse", &info_address); + add_command(&g_keys, "telefon", &info_phone); + add_command(&g_keys, "urlaub", &info_vacation); } diff --git a/src/common/util/command.c b/src/common/util/command.c index 761a81b1b..3ac282632 100644 --- a/src/common/util/command.c +++ b/src/common/util/command.c @@ -22,30 +22,24 @@ #include typedef struct command { - struct command * next; - const char * key; - void (*perform)(const char *, void *, const char *); + void(*fun)(const char*, void *, const char*); } command; void -add_command(struct tnode * keys, command ** cmds, const char * str, void(*fun)(const char*, void *, const char*)) +add_command(struct tnode * keys, const char * str, void(*fun)(const char*, void *, const char*)) { - command * nc = calloc(sizeof(command), 1); - nc->key = str; - nc->perform = fun; - nc->next = *cmds; - *cmds = nc; - - addtoken(keys, str, (void*)nc); + command * cmd = malloc(sizeof(command)); + cmd->fun = fun; + addtoken(keys, str, (void*)cmd); } -void +int do_command(const struct tnode * keys, void * u, const char * str) { int i; char zText[16]; const char * c; - command * cm; + command * cmd; while (isspace(*str)) ++str; c = str; @@ -53,6 +47,9 @@ do_command(const struct tnode * keys, void * u, const char * str) i = min(16, c-str); strncpy(zText, str, i); zText[i]=0; - if (findtoken(keys, zText, (void**)&cm)==E_TOK_SUCCESS && cm->perform) cm->perform(++c, u, str); + if (findtoken(keys, zText, (void**)&cmd)==E_TOK_SUCCESS) { + cmd->fun(++c, u, str); + return 0; + } + return 1; } - diff --git a/src/common/util/command.h b/src/common/util/command.h index ae6986102..19a1ecc1d 100644 --- a/src/common/util/command.h +++ b/src/common/util/command.h @@ -13,11 +13,10 @@ #ifndef COMMAND_H #define COMMAND_H -struct command; struct tnode; -extern void add_command(struct tnode * keys, struct command ** cmds, const char * str, +extern void add_command(struct tnode * keys, const char * str, void(*fun)(const char*, void *, const char*)); -extern void do_command(const struct tnode * keys, void * u, const char * cmd); +extern int do_command(const struct tnode * keys, void * u, const char * cmd); #endif