Ignore:
Timestamp:
05/31/07 15:15:23 (5 years ago)
Author:
wd
Message:

Many more changes:

  • Moved the 'core' addon code into various places in the main ircd module.
  • Split channel/user modes out of channel.c/client.c and into chanmode.c/usermode.c respectively.
  • Added init/teardown routines for channel/usermodes.
  • Changed the INVIS and OPER macros to have longer(:/) and more descriptive names.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ithildin/modules/ircd/channel.h

    r801 r803  
    22 * channel.h: channel (mode) structures and prototypes 
    33 *  
    4  * Copyright 2002 the Ithildin Project. 
     4 * Copyright 2002-2007 the Ithildin Project. 
    55 * See the COPYING file for more information on licensing and use. 
    66 *  
     
    1010#ifndef IRCD_CHANNEL_H 
    1111#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 have 
    18  * parameters.  Modes of type B change a setting.  They always have a 
    19  * parameter.  Modes of type C change a setting, but only have a parameter when 
    20  * being set.  Modes of type E (yes E) change a setting, but only have a 
    21  * parameter when being *unset*, and modes of type D change a boolean setting 
    22  * and never take a parameter.  Last but not least are 'PREFIX' modes which 
    23  * change a flag on a user in the channel.  All modes should take handler 
    24  * functions which will be called when the mode is set/unset.  The handler 
    25  * 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, there 
    28  * won't always be one!) this is handy for passing errors or providing custom 
    29  * behavior. 
    30  * the next argument is the channel on which the mode is being set, the third 
    31  * is the mode character given (this allows several modes to all coalesce into 
    32  * one function if that behavior is desired), the fourth will be one of five 
    33  * values: 
    34  * - CHANMODE_SET to set the mode normally 
    35  * - CHANMODE_UNSET to unset the * mode normally 
    36  * - 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 holds 
    39  * a return value which specifies whether the argument was used or not.  the 
    40  * 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 made 
    44  * CHANMODE_NOP: This was an n-op (nothing happened) 
    45  * CHANMODE_FAIL: The change or request failed 
    46  * CHANMODE_NONEX: The mode does not exist 
    47  * CHANMODE_NOARG: The mode needed an argument and none was given 
    48  * number > 0: Equivalent to CHANMODE_FAIL with the value of a numeric to 
    49  *             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 but 
    60  * do not expect a client.  They exist simply to return state to people who 
    61  * want to know.  The important item is the fifth argument, a private state 
    62  * variable.  When querying begins the pointer value pointed to be state 
    63  * must be NULL.  The value may never be changed, and any memory allocations 
    64  * occuring on behalf of the queryer will be freed on the final query when 
    65  * no more data can be reset/queried. 
    66  * 
    67  * return values: 
    68  * CHANMODE_OK: Change/request was successfully made 
    69  * CHANMODE_FAIL: The change or request failed 
    70  * CHANMODE_NONEX: The mode does not exist 
    71  */ 
    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            0x01 
    79 #define CHANMODE_FL_B            0x02 
    80 #define CHANMODE_FL_C            0x04 
    81 #define CHANMODE_FL_D            0x08 
    82 #define CHANMODE_FL_E            0x10 
    83 #define CHANMODE_FL_PREFIX  0x20 
    84  
    85 #define CHANMODE_SET            1 
    86 #define CHANMODE_UNSET            0 
    87 #define CHANMODE_CLEAR            -1 
    88  
    89 #define CHANMODE_OK         0 
    90 #define CHANMODE_FAIL       -1 
    91 #define CHANMODE_NOP        -2 
    92 #define CHANMODE_NONEX      -3 
    93 #define CHANMODE_NOARG      -4 
    94  
    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 by 
    101  * their mode character, but can also be set by prefix in the case of userflag 
    102  * 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 can 
    117  * check to see if a flag-type mode is set on a channel, or you can check to 
    118  * see if a user has a certain prefix.  lastly, you can get the data for a 
    119  * 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 a 
    151  * 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->offset 
    167  
    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 a 
    174                                    chanuser mode */ 
    175     unsigned char prefix;       /* if this is a user-flag, it has a prefix, this is 
    176                                    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 }; 
    18412 
    18513LIST_HEAD(chanusers, chanlink); 
     
    20735 
    20836    unsigned int onchannel;            /* number of people on channel */ 
    209     int            flags; 
     37    int     flags; 
    21038    struct chanusers users;            /* list of users in channel */ 
    21139    uint64_t modes;                    /* the flag-modes for the channel. */ 
Note: See TracChangeset for help on using the changeset viewer.