40ad373ea3a403691ec341e43d9fb627e269f9da
[NeonServV5.git] / src / modcmd.h
1 /* modcmd.h - NeonServ v5.2
2  * Copyright (C) 2011  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            0x0001
24 #define CMDFLAG_REQUIRE_AUTH            0x0002
25 #define CMDFLAG_REQUIRE_GOD             0x0004
26 #define CMDFLAG_CHECK_AUTH              0x0008
27 #define CMDFLAG_REGISTERED_CHAN         0x0010
28 #define CMDFLAG_OVERRIDE_GLOBAL_ACCESS  0x0020
29 #define CMDFLAG_OVERRIDE_CHANNEL_ACCESS 0x0040
30 #define CMDFLAG_CHAN_PARAM              0x0080
31 #define CMDFLAG_LOG                     0x0100
32 #define CMDFLAG_OPLOG                   0x0200
33 #define CMDFLAG_EMPTY_ARGS              0x0400
34 #define CMDFLAG_REQUIRED                0x0800
35 #define CMDFLAG_TEMPONARY_BIND          0x1000
36
37 struct ClientSocket;
38 struct UserNode;
39 struct ChanNode;
40 struct Event;
41
42 #define CMD_BIND(NAME) void NAME(UNUSED_ARG(struct ClientSocket *client), UNUSED_ARG(struct UserNode *user), UNUSED_ARG(struct ChanNode *chan), UNUSED_ARG(char **argv), UNUSED_ARG(char argc), UNUSED_ARG(struct Event *event))
43 typedef void cmd_bind_t(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char **argv, char argc, struct Event *event);
44 typedef void trigger_callback_t(struct ChanNode *chan, char *trigger);
45
46 struct cmd_function {
47     char *name;
48     int botid;
49     cmd_bind_t *func;
50     unsigned int flags;
51     int paramcount;
52     int global_access;
53     char *channel_access;
54     
55     struct cmd_function *next;
56 };
57
58 struct cmd_binding {
59     char *cmd;
60     int botid;
61     struct cmd_function *func;
62     unsigned int flags;
63     char *parameters[MAXPARAMETERS];
64     int paramcount;
65     int global_access;
66     char *channel_access;
67     
68     struct cmd_binding *next;
69 };
70
71 struct trigger_cache {
72     int botid;
73     char *trigger;
74     
75     struct trigger_cache *next;
76 };
77
78 void init_modcmd();
79 void free_modcmd();
80 struct ClientSocket* get_prefered_bot(int botid);
81 int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags);
82 int set_trigger_callback(int botid, trigger_callback_t *func);
83 int changeChannelTrigger(int botid, struct ChanNode *chan, char *new_trigger);
84 int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func);
85 int bind_cmd_to_command(int botid, char *cmd, char *func);
86 int unbind_cmd(int botid, char *cmd);
87 struct cmd_function *find_cmd_function(int botid, char *name);
88 struct ClientSocket *getTextBot();
89 void bind_set_parameters(int botid, char *cmd, char *parameters);
90 void bind_set_global_access(int botid, char *cmd, int gaccess);
91 void bind_set_channel_access(int botid, char *cmd, char *chanaccess);
92 struct cmd_binding *find_cmd_binding(int botid, char *cmd);
93 void bind_unbound_required_functions(int botid);
94
95 void register_bot_alias(int botid, char *alias);
96 struct cmd_binding *getAllBinds(struct cmd_binding *last);
97
98 #endif