(thanks to the people reading git and excessively exploiting this bug... It was undet...
[NeonServV5.git] / src / modcmd.h
1 /* modcmd.h - NeonServ v5.6
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17 #ifndef _modcmd_h
18 #define _modcmd_h
19 #include "main.h"
20
21 #define MAXPARAMETERS 50
22
23 #define CMDFLAG_REQUIRE_CHAN            0x00001
24 #define CMDFLAG_REQUIRE_AUTH            0x00002
25 #define CMDFLAG_REQUIRE_GOD             0x00004
26 #define CMDFLAG_CHECK_AUTH              0x00008
27 #define CMDFLAG_REGISTERED_CHAN         0x00010
28 #define CMDFLAG_OVERRIDE_GLOBAL_ACCESS  0x00020
29 #define CMDFLAG_OVERRIDE_CHANNEL_ACCESS 0x00040
30 #define CMDFLAG_CHAN_PARAM              0x00080
31 #define CMDFLAG_LOG                     0x00100
32 #define CMDFLAG_OPLOG                   0x00200
33 #define CMDFLAG_EMPTY_ARGS              0x00400
34 #define CMDFLAG_REQUIRED                0x00800
35 #define CMDFLAG_TEMPONARY_BIND          0x01000
36 #define CMDFLAG_FUNCMD                  0x02000
37 #define CMDFLAG_ESCAPE_ARGS             0x04000
38 #define CMDFLAG_NO_CROSSCHAN            0x08000
39 #define CMDFLAG_SUB_LINKER              0x10000
40
41 struct ClientSocket;
42 struct UserNode;
43 struct ChanNode;
44 struct Event;
45
46 #define CMD_BIND(NAME) void NAME(UNUSED_ARG(struct ClientSocket *client), UNUSED_ARG(struct ClientSocket *textclient), UNUSED_ARG(struct UserNode *user), UNUSED_ARG(struct ChanNode *chan), UNUSED_ARG(char **argv), UNUSED_ARG(char argc), UNUSED_ARG(struct Event *event))
47 typedef void cmd_bind_t(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char **argv, char argc, struct Event *event);
48 typedef void trigger_callback_t(int clientid, struct ChanNode *chan, char *trigger);
49
50 struct cmd_function {
51     char *name;
52     int botid;
53     int module_id;
54     cmd_bind_t *func;
55     unsigned int flags;
56     int paramcount;
57     int global_access;
58     char *channel_access;
59     
60     struct cmd_function *next;
61 };
62
63 struct cmd_binding {
64     char *cmd;
65     int botid;
66     int clientid;
67     struct cmd_function *func;
68     unsigned int flags;
69     char *parameters[MAXPARAMETERS];
70     int paramcount;
71     int global_access;
72     char *channel_access;
73     int triggered;
74     
75     struct cmd_binding *next;
76 };
77
78 #define BIND_FLAGS(BIND) (BIND->flags | BIND->func->flags)
79
80 struct trigger_cache {
81     int botid;
82     int clientid;
83     char *trigger;
84     
85     struct trigger_cache *next;
86 };
87
88 #define get_prefered_bot(BOTID) get_botwise_prefered_bot(BOTID, 0)
89 #define changeChannelTrigger(BOTID,CHAN,NEW) changeBotwiseChannelTrigger(BOTID, 0, CHAN, NEW)
90 #define bind_cmd_to_function(BOTID,CMD,FUNC) bind_botwise_cmd_to_function(BOTID, 0, CMD, FUNC)
91 #define bind_cmd_to_command(BOTID,CMD,FUNC) bind_botwise_cmd_to_command(BOTID, 0, CMD, FUNC)
92 #define unbind_cmd(BOTID,CMD) unbind_botwise_cmd(BOTID, 0, CMD)
93 #define unbind_allcmd(BOTID) unbind_botwise_allcmd(BOTID, 0)
94 #define bind_set_parameters(BOTID,CMD,PARAMETERS) bind_botwise_set_parameters(BOTID, 0, CMD, PARAMETERS)
95 #define bind_set_global_access(BOTID,CMD,GACCESS) bind_botwise_set_global_access(BOTID, 0, CMD, GACCESS)
96 #define bind_set_channel_access(BOTID,CMD,CACCESS) bind_botwise_set_channel_access(BOTID, 0, CMD, CACCESS)
97 #define bind_set_bind_flags(BOTID,CMD,FLAGS) bind_botwise_set_bind_flags(BOTID, 0, CMD, FLAGS)
98 #define find_cmd_binding(BOTID,CMD) find_botwise_cmd_binding(BOTID, 0, CMD)
99 #define bind_unbound_required_functions(BOTID) bind_botwise_unbound_required_functions(BOTID, 0)
100
101
102 #ifndef DND_FUNCTIONS
103 extern int statistics_commands;
104
105 void init_modcmd();
106 void free_modcmd();
107
108 /* MODULAR ACCESSIBLE */ struct ClientSocket* get_botwise_prefered_bot(int botid, int clientid);
109
110 /* MODULAR ACCESSIBLE */ int register_command(int botid, char *name, int module_id, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags);
111 /* MODULAR ACCESSIBLE */ int set_trigger_callback(int botid, int module_id, trigger_callback_t *func);
112
113 /* MODULAR ACCESSIBLE */ int flush_trigger_cache(int botid, int clientid);
114 /* MODULAR ACCESSIBLE */ int changeBotwiseChannelTrigger(int botid, int clientid, struct ChanNode *chan, char *new_trigger);
115 /* MODULAR ACCESSIBLE */ int bind_botwise_cmd_to_function(int botid, int clientid, char *cmd, struct cmd_function *func);
116 /* MODULAR ACCESSIBLE */ int bind_botwise_cmd_to_command(int botid, int clientid, char *cmd, char *func);
117 /* MODULAR ACCESSIBLE */ int unbind_botwise_cmd(int botid, int clientid, char *cmd);
118 /* MODULAR ACCESSIBLE */ int unbind_botwise_allcmd(int botid, int clientid);
119 /* MODULAR ACCESSIBLE */ void bind_botwise_set_parameters(int botid, int clientid, char *cmd, char *parameters);
120 /* MODULAR ACCESSIBLE */ void bind_botwise_set_global_access(int botid, int clientid, char *cmd, int gaccess);
121 /* MODULAR ACCESSIBLE */ void bind_botwise_set_channel_access(int botid, int clientid, char *cmd, char *chanaccess);
122 /* MODULAR ACCESSIBLE */ void bind_botwise_set_bind_flags(int botid, int clientid, char *cmd, unsigned int flags);
123 /* MODULAR ACCESSIBLE */ struct cmd_binding *find_botwise_cmd_binding(int botid, int clientid, char *cmd);
124 /* MODULAR ACCESSIBLE */ void bind_botwise_unbound_required_functions(int botid, int clientid);
125 /* MODULAR ACCESSIBLE */ struct cmd_function *find_cmd_function(int botid, char *name);
126 /* MODULAR ACCESSIBLE */ void register_command_alias(int botid, char *alias);
127 /* MODULAR ACCESSIBLE */ struct cmd_binding *getAllBinds(struct cmd_binding *last);
128
129 void unregister_module_commands(int module_id);
130
131 #endif
132 #endif