mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-07 15:03:13 +02:00
Converted commands to use module objects
This commit is contained in:
@@ -1234,4 +1234,4 @@ seen. gmtime warning still there
|
||||
various other people ..
|
||||
- Fixed a /mkpasswd typo and added the updated /mkpasswd syntax to doc/unrealircd.doc, both
|
||||
reported by peck
|
||||
|
||||
- Made the command system use module objects (haven't yet converted modules to use it)
|
||||
|
||||
+1
-1
@@ -440,7 +440,7 @@ char *Inet_ia2p(struct IN_ADDR *ia);
|
||||
*/
|
||||
extern aCommand *CommandHash[256];
|
||||
extern void init_CommandHash(void);
|
||||
extern void add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token, int flags);
|
||||
extern aCommand *add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token, int flags);
|
||||
extern void add_Command(char *cmd, char *token, int (*func)(), unsigned char parameters);
|
||||
extern void add_Command_to_list(aCommand *item, aCommand **list);
|
||||
extern aCommand *del_Command_from_list(aCommand *item, aCommand **list);
|
||||
|
||||
+9
-1
@@ -91,13 +91,18 @@ typedef struct {
|
||||
#define MOBJ_HOOK 0x0002
|
||||
#define MOBJ_COMMAND 0x0004
|
||||
|
||||
typedef struct _command {
|
||||
struct _command *prev, *next;
|
||||
aCommand *cmd, *tok;
|
||||
} Command;
|
||||
|
||||
typedef struct _ModuleObject {
|
||||
struct _ModuleObject *prev, *next;
|
||||
short type;
|
||||
union {
|
||||
Event *event;
|
||||
Hook *hook;
|
||||
aCommand *command;
|
||||
Command *command;
|
||||
} object;
|
||||
} ModuleObject;
|
||||
|
||||
@@ -222,6 +227,9 @@ Hook *HookDel(Hook *hook);
|
||||
#define RunHook2(hooktype,x,y) for (global_i = Hooks[hooktype]; global_i; global_i = global_i->next) (*(global_i->func.intfunc))(x,y)
|
||||
|
||||
|
||||
Command *CommandAdd(Module *module, char *cmd, char *tok, int (*func)(), unsigned char params, int flags);
|
||||
void CommandDel(Command *command);
|
||||
|
||||
/* Hook types */
|
||||
#define HOOKTYPE_LOCAL_QUIT 1
|
||||
#define HOOKTYPE_LOCAL_NICKCHANGE 2
|
||||
|
||||
+15
-14
@@ -655,20 +655,6 @@ struct Server {
|
||||
#define M_ALIAS 0x0020
|
||||
#define M_RESETIDLE 0x0040
|
||||
|
||||
struct Command {
|
||||
aCommand *prev, *next;
|
||||
char *cmd;
|
||||
int (*func) ();
|
||||
int flags;
|
||||
unsigned int count;
|
||||
unsigned parameters : 5;
|
||||
unsigned token : 1;
|
||||
unsigned long bytes;
|
||||
#ifdef DEBUGMODE
|
||||
unsigned long lticks;
|
||||
unsigned long rticks;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* tkl:
|
||||
@@ -1401,6 +1387,21 @@ extern char *gnulicense[];
|
||||
#define EVENT_HASHES EVENT_DRUGS
|
||||
#include "modules.h"
|
||||
#include "events.h"
|
||||
struct Command {
|
||||
aCommand *prev, *next;
|
||||
char *cmd;
|
||||
int (*func) ();
|
||||
int flags;
|
||||
unsigned int count;
|
||||
unsigned parameters : 5;
|
||||
unsigned token : 1;
|
||||
unsigned long bytes;
|
||||
Module *owner;
|
||||
#ifdef DEBUGMODE
|
||||
unsigned long lticks;
|
||||
unsigned long rticks;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* __struct_include__ */
|
||||
|
||||
|
||||
@@ -293,6 +293,9 @@ int Module_free(Module *mod)
|
||||
else if (objs->type == MOBJ_HOOK) {
|
||||
HookDel(objs->object.hook);
|
||||
}
|
||||
else if (objs->type == MOBJ_COMMAND) {
|
||||
CommandDel(objs->object.command);
|
||||
}
|
||||
}
|
||||
for (p = Modules; p; p = p->next)
|
||||
{
|
||||
|
||||
+43
-1
@@ -218,7 +218,7 @@ void init_CommandHash(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token, int flags)
|
||||
aCommand *add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token, int flags)
|
||||
{
|
||||
aCommand *newcmd = (aCommand *) MyMalloc(sizeof(aCommand));
|
||||
|
||||
@@ -232,6 +232,48 @@ void add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, uns
|
||||
|
||||
/* Add in hash with hash value = first byte */
|
||||
AddListItem(newcmd, CommandHash[toupper(*cmd)]);
|
||||
return newcmd;
|
||||
}
|
||||
|
||||
Command *CommandAdd(Module *module, char *cmd, char *tok, int (*func)(), unsigned char params, int flags) {
|
||||
Command *command = MyMallocEx(sizeof(Command));
|
||||
command->cmd = add_Command_backend(cmd,func,params, 0, flags);
|
||||
command->tok = NULL;
|
||||
command->cmd->owner = module;
|
||||
if (tok) {
|
||||
command->tok = add_Command_backend(tok,func,params,1,flags);
|
||||
command->tok->owner = module;
|
||||
}
|
||||
if (module) {
|
||||
ModuleObject *cmdobj = (ModuleObject *)MyMallocEx(sizeof(ModuleObject));
|
||||
cmdobj->object.command = command;
|
||||
cmdobj->type = MOBJ_COMMAND;
|
||||
AddListItem(cmdobj, module->objects);
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
void CommandDel(Command *command) {
|
||||
DelListItem(command->cmd, CommandHash[toupper(*command->cmd->cmd)]);
|
||||
if (command->tok)
|
||||
DelListItem(command->tok, CommandHash[toupper(*command->tok->cmd)]);
|
||||
if (command->cmd->owner) {
|
||||
ModuleObject *cmdobj;
|
||||
for (cmdobj = command->cmd->owner->objects; cmdobj; cmdobj = (ModuleObject *)cmdobj->next) {
|
||||
if (cmdobj->type == MOBJ_COMMAND && cmdobj->object.command == command) {
|
||||
DelListItem(cmdobj,command->cmd->owner->objects);
|
||||
MyFree(cmdobj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
MyFree(command->cmd->cmd);
|
||||
MyFree(command->cmd);
|
||||
if (command->tok) {
|
||||
MyFree(command->tok->cmd);
|
||||
MyFree(command->tok);
|
||||
}
|
||||
MyFree(command);
|
||||
}
|
||||
|
||||
void add_Command(char *cmd, char *token, int (*func)(), unsigned char parameters)
|
||||
|
||||
Reference in New Issue
Block a user