Changeset 803 for trunk/ithildin/modules/ircd/channel.h
- Timestamp:
- 05/31/07 15:15:23 (5 years ago)
- File:
-
- 1 edited
-
trunk/ithildin/modules/ircd/channel.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ithildin/modules/ircd/channel.h
r801 r803 2 2 * channel.h: channel (mode) structures and prototypes 3 3 * 4 * Copyright 2002 the Ithildin Project.4 * Copyright 2002-2007 the Ithildin Project. 5 5 * See the COPYING file for more information on licensing and use. 6 6 * … … 10 10 #ifndef IRCD_CHANNEL_H 11 11 #define IRCD_CHANNEL_H 12 13 /*14 * channel mode fun. this is a lot like the usermode request/release system,15 * except that it's a bit more complicated. There are effectively six (yes,16 * six) types of channel modes. The first are types A-E, and work as follows:17 * Modes of type A add or remove an item from a list. They always have18 * parameters. Modes of type B change a setting. They always have a19 * parameter. Modes of type C change a setting, but only have a parameter when20 * being set. Modes of type E (yes E) change a setting, but only have a21 * parameter when being *unset*, and modes of type D change a boolean setting22 * and never take a parameter. Last but not least are 'PREFIX' modes which23 * change a flag on a user in the channel. All modes should take handler24 * functions which will be called when the mode is set/unset. The handler25 * functions should be:26 * int func(client *, channel *, unsigned char, int, char *, int *)27 * the first argument should be the client changing the mode (if any, there28 * won't always be one!) this is handy for passing errors or providing custom29 * behavior.30 * the next argument is the channel on which the mode is being set, the third31 * is the mode character given (this allows several modes to all coalesce into32 * one function if that behavior is desired), the fourth will be one of five33 * values:34 * - CHANMODE_SET to set the mode normally35 * - CHANMODE_UNSET to unset the * mode normally36 * - CHANMODE_CLEAR to clear any data held by the mode (free allocated data,37 * etc. called when a channel or mode is being destroyed/release)38 * the fifth argument is the next argument in the mode command. the final holds39 * a return value which specifies whether the argument was used or not. the40 * int should be set to 1 if the argument is used, and 0 if it isn't.41 *42 * return values:43 * CHANMODE_OK: Change/request was successfully made44 * CHANMODE_NOP: This was an n-op (nothing happened)45 * CHANMODE_FAIL: The change or request failed46 * CHANMODE_NONEX: The mode does not exist47 * CHANMODE_NOARG: The mode needed an argument and none was given48 * number > 0: Equivalent to CHANMODE_FAIL with the value of a numeric to49 * return to the user.50 */51 52 #define CHANMODE_FUNC(x) \53 int x(client_t *cli, channel_t *chan, unsigned char mode, int set, \54 char *arg __UNUSED, int *argused __UNUSED)55 typedef int (*chanmode_func)(client_t *, channel_t *, unsigned char,56 int, char *, int *);57 58 /*59 * Channel mode queries: These work a lot like the chanmode_func stuff but60 * do not expect a client. They exist simply to return state to people who61 * want to know. The important item is the fifth argument, a private state62 * variable. When querying begins the pointer value pointed to be state63 * must be NULL. The value may never be changed, and any memory allocations64 * occuring on behalf of the queryer will be freed on the final query when65 * no more data can be reset/queried.66 *67 * return values:68 * CHANMODE_OK: Change/request was successfully made69 * CHANMODE_FAIL: The change or request failed70 * CHANMODE_NONEX: The mode does not exist71 */72 #define CHANMODE_QUERY_FUNC(x) \73 int x(channel_t *chan, unsigned char mode, char *arg __UNUSED, \74 int *argused __UNUSED, void **state)75 typedef int (*chanmode_query_func)(channel_t *, unsigned char, char *,76 int *, void **);77 78 #define CHANMODE_FL_A 0x0179 #define CHANMODE_FL_B 0x0280 #define CHANMODE_FL_C 0x0481 #define CHANMODE_FL_D 0x0882 #define CHANMODE_FL_E 0x1083 #define CHANMODE_FL_PREFIX 0x2084 85 #define CHANMODE_SET 186 #define CHANMODE_UNSET 087 #define CHANMODE_CLEAR -188 89 #define CHANMODE_OK 090 #define CHANMODE_FAIL -191 #define CHANMODE_NOP -292 #define CHANMODE_NONEX -393 #define CHANMODE_NOARG -494 95 uint64_t chanmode_request(unsigned char, unsigned char *, int,96 chanmode_func, chanmode_query_func, size_t, void *);97 void chanmode_release(unsigned char);98 void chanmode_update_funcs(unsigned char, chanmode_func,99 chanmode_query_func);100 /* ways to set and unset channel modes. channel modes are typically set by101 * their mode character, but can also be set by prefix in the case of userflag102 * types. */103 int chanmode_set(unsigned char, client_t *, channel_t *, char *, int *);104 int chanmode_setprefix(unsigned char, channel_t *, char *, int *);105 106 int chanmode_unset(unsigned char, client_t *, channel_t *, char *, int *);107 int chanmode_unsetprefix(unsigned char, channel_t *, char *, int *);108 109 int chanmode_query(unsigned char, channel_t *, char *, int *, void **);110 111 #define chanmode_setflag(chan, themode) \112 (chan->modes |= ircd.cmodes.modes[themode].mask)113 #define chanmode_unsetflag(chan, themode) \114 (chan->modes &= ~ircd.cmodes.modes[themode].mask)115 116 /* various checks to see if channel modes are set in specific ways. you can117 * check to see if a flag-type mode is set on a channel, or you can check to118 * see if a user has a certain prefix. lastly, you can get the data for a119 * specific mode (data type) */120 #define chanmode_isset(chan, themode) \121 ((ircd.cmodes.modes[themode].avail == 0 && \122 ircd.cmodes.modes[themode].mask) ? \123 (chan->modes & ircd.cmodes.modes[themode].mask) : \124 0)125 126 int chanmode_isprefix(channel_t *, client_t *, unsigned char);127 128 #define chanlink_ismode(clp, mode) \129 (clp->flags & ircd.cmodes.modes[mode].umask)130 131 #define chanmode_getdata(chan, themode) \132 ((ircd.cmodes.modes[themode].avail == 0 && \133 ircd.cmodes.modes[themode].mdi != NULL) ? \134 (chan->mdext + ircd.cmodes.modes[themode].mdi->offset) : \135 NULL)136 137 #define chanmode_getintdata(chan, themode) \138 ((ircd.cmodes.modes[themode].avail == 0 && \139 ircd.cmodes.modes[themode].mdi != NULL) ? \140 *(((uint32_t *)(chan->mdext + \141 ircd.cmodes.modes[themode].mdi->offset))) : \142 0xFFFFFFFF)143 144 #define chanmode_getstrdata(chan, themode) \145 ((ircd.cmodes.modes[themode].avail == 0 && \146 ircd.cmodes.modes[themode].mdi != NULL) ? \147 ((char *)chan->mdext) + ircd.cmodes.modes[themode].mdi->offset : \148 NULL)149 150 /* this function returns a \0 terminated list of a client's prefixes in a151 * channel, in a static character array. */152 char *chanmode_getprefixes(channel_t *, client_t *);153 154 /* These two map prefixes to channel modes and vice versa. */155 #define chanmode_prefixtomode(c) \156 (ircd.cmodes.pfxmap[(unsigned char)c] != NULL ? \157 ircd.cmodes.pfxmap[(unsigned char)c]->mode : '\0')158 159 #define chanmode_modetoprefix(c) \160 (ircd.cmodes.modes[(unsigned char)c].umask ? \161 ircd.cmodes.modes[(unsigned char)c].prefix : '\0')162 163 const char **chanmode_getmodes(channel_t *);164 165 /* grab the offset of a mode. */166 #define modeoffset(mode) ircd.cmodes.modes[mode].mdi->offset167 168 struct chanmode {169 unsigned char mode; /* the mode character */170 char avail; /* whether it is available or not */171 172 uint64_t mask; /* the mask for this mode */173 short umask; /* the mask for a chanlink setting, if this is a174 chanuser mode */175 unsigned char prefix; /* if this is a user-flag, it has a prefix, this is176 the prefix (specified by the caller in extdata).177 no error checking is done on this value. */178 chanmode_func changefunc; /* the symbol/function to change the mode */179 chanmode_query_func queryfunc; /* the symbol/function to query the mode */180 int flags; /* flags given for this mode */181 struct mdext_item *mdi; /* the mdext_item which describes the channel mode.182 allocated automatically. */183 };184 12 185 13 LIST_HEAD(chanusers, chanlink); … … 207 35 208 36 unsigned int onchannel; /* number of people on channel */ 209 int flags;37 int flags; 210 38 struct chanusers users; /* list of users in channel */ 211 39 uint64_t modes; /* the flag-modes for the channel. */
Note: See TracChangeset
for help on using the changeset viewer.
