GM Kommandos

This commit is contained in:
Enno Rehling 2002-02-23 11:30:41 +00:00
parent cf0bdf6b7f
commit a7acaff1c4
4 changed files with 107 additions and 39 deletions

View File

@ -176,7 +176,7 @@ gm_gate(const char * str, void * data, const char * cmd)
/** /**
** GM: TERRAFORM <terrain> <x> <y> ** GM: TERRAFORM <x> <y> <terrain>
** requires: permission-key "gmterf" ** requires: permission-key "gmterf"
**/ **/
static void static void
@ -234,7 +234,70 @@ gm_teleport(const char * str, void * data, const char * cmd)
} }
/** /**
** GM: BROADCAST <x> <y> <string> ** GM: TELL PLANE <string>
** 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 <x> <y> <string>
** requires: permission-key "gmmsgr" ** requires: permission-key "gmmsgr"
**/ **/
static void 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_keys;
static tnode g_root;
static tnode g_tell;
static void static void
gm_command(const char * str, void * data, const char * cmd) 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); 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 void
init_gmcmd(void) init_gmcmd(void)
{ {
at_register(&at_gmcreate); at_register(&at_gmcreate);
at_register(&at_permissions); at_register(&at_permissions);
add_command(&g_keys, &g_cmds, "gm", &gm_command); add_command(&g_root, "gm", &gm_command);
add_command(&g_keys, &g_cmds, "terraform", &gm_terraform); add_command(&g_keys, "terraform", &gm_terraform);
add_command(&g_keys, &g_cmds, "create", &gm_create); add_command(&g_keys, "create", &gm_create);
add_command(&g_keys, &g_cmds, "gate", &gm_gate); add_command(&g_keys, "gate", &gm_gate);
add_command(&g_keys, &g_cmds, "give", &gm_give); add_command(&g_keys, "give", &gm_give);
add_command(&g_keys, &g_cmds, "take", &gm_take); add_command(&g_keys, "take", &gm_take);
add_command(&g_keys, &g_cmds, "teleport", &gm_teleport); add_command(&g_keys, "teleport", &gm_teleport);
add_command(&g_keys, &g_cmds, "skill", &gm_skill); add_command(&g_keys, "skill", &gm_skill);
add_command(&g_keys, &g_cmds, "broadcast", &gm_messageregion); add_command(&g_keys, "tell", &gm_tell);
add_command(&g_keys, &g_cmds, "tell", &gm_messageunit); 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; strlist * order;
for (order = u->orders; order; order = order->next) for (order = u->orders; order; order = order->next)
if (igetkeyword(order->s, u->faction->locale) == K_GM) { 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; if (u==*up) up = &u->next;
} }

View File

@ -100,7 +100,6 @@ info_vacation(const char * str, void * data, const char * cmd)
} }
} }
static struct command * g_cmds;
static tnode g_keys; static tnode g_keys;
void void
@ -133,11 +132,11 @@ info_command(const char * str, void * data, const char * cmd)
void void
init_info(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, "email", &info_email);
add_command(&g_keys, &g_cmds, "name", &info_name); add_command(&g_keys, "name", &info_name);
add_command(&g_keys, &g_cmds, "adresse", &info_address); add_command(&g_keys, "adresse", &info_address);
add_command(&g_keys, &g_cmds, "telefon", &info_phone); add_command(&g_keys, "telefon", &info_phone);
add_command(&g_keys, &g_cmds, "urlaub", &info_vacation); add_command(&g_keys, "urlaub", &info_vacation);
} }

View File

@ -22,30 +22,24 @@
#include <string.h> #include <string.h>
typedef struct command { typedef struct command {
struct command * next; void(*fun)(const char*, void *, const char*);
const char * key;
void (*perform)(const char *, void *, const char *);
} command; } command;
void 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); command * cmd = malloc(sizeof(command));
nc->key = str; cmd->fun = fun;
nc->perform = fun; addtoken(keys, str, (void*)cmd);
nc->next = *cmds;
*cmds = nc;
addtoken(keys, str, (void*)nc);
} }
void int
do_command(const struct tnode * keys, void * u, const char * str) do_command(const struct tnode * keys, void * u, const char * str)
{ {
int i; int i;
char zText[16]; char zText[16];
const char * c; const char * c;
command * cm; command * cmd;
while (isspace(*str)) ++str; while (isspace(*str)) ++str;
c = str; c = str;
@ -53,6 +47,9 @@ do_command(const struct tnode * keys, void * u, const char * str)
i = min(16, c-str); i = min(16, c-str);
strncpy(zText, str, i); strncpy(zText, str, i);
zText[i]=0; 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;
} }

View File

@ -13,11 +13,10 @@
#ifndef COMMAND_H #ifndef COMMAND_H
#define COMMAND_H #define COMMAND_H
struct command;
struct tnode; 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*)); 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 #endif