1 /* 2 * Copyright (C) 2005 William Pitcock, et al. 3 * Rights to this code are as documented in doc/LICENSE. 4 * 5 * Data structures for channel information. 6 * 7 */ 8 9 #ifndef CHANNELS_H 10 #define CHANNELS_H 11 12 #define VALID_GLOBAL_CHANNEL_PFX(name) (*(name) == '#' || *(name) == '+' || *(name) == '!') 13 #define VALID_CHANNEL_PFX(name) (VALID_GLOBAL_CHANNEL_PFX(name) || *(name) == '&') 14 15 struct channel_ 16 { 17 char *name; 18 19 unsigned int modes; 20 char *key; 21 unsigned int limit; 22 char **extmodes; /* non-standard simple modes with param eg +j */ 23 24 unsigned int nummembers; 25 unsigned int numsvcmembers; 26 27 time_t ts; 28 29 char *topic; 30 char *topic_setter; 31 time_t topicts; 32 33 mowgli_list_t members; 34 mowgli_list_t bans; 35 36 unsigned int flags; 37 38 mychan_t *mychan; 39 }; 40 41 /* struct for channel memberships */ 42 struct chanuser_ 43 { 44 channel_t *chan; 45 user_t *user; 46 unsigned int modes; 47 mowgli_node_t unode; 48 mowgli_node_t cnode; 49 }; 50 51 struct chanban_ 52 { 53 channel_t *chan; 54 char *mask; 55 int type; /* 'b', 'e', 'I', etc -- jilles */ 56 mowgli_node_t node; /* for channel_t.bans */ 57 unsigned int flags; 58 }; 59 60 /* channel_t.modes */ 61 #define CMODE_INVITE 0x00000001 62 #define CMODE_KEY 0x00000002 63 #define CMODE_LIMIT 0x00000004 64 #define CMODE_MOD 0x00000008 65 #define CMODE_NOEXT 0x00000010 66 #define CMODE_PRIV 0x00000040 /* AKA PARA */ 67 #define CMODE_SEC 0x00000080 68 #define CMODE_TOPIC 0x00000100 69 #define CMODE_CHANREG 0x00000200 70 71 /* channel_t.flags */ 72 #define CHAN_LOG 0x00000001 /* logs sent to here */ 73 74 /* chanuser_t.modes */ 75 #define CSTATUS_OP 0x00000001 76 #define CSTATUS_VOICE 0x00000002 77 #define CSTATUS_OWNER 0x00000004 /* unreal/inspircd +q */ 78 #define CSTATUS_PROTECT 0x00000008 /* unreal/inspircd +a */ 79 #define CSTATUS_HALFOP 0x00000010 /* unreal/inspircd +h */ 80 #define CSTATUS_IMMUNE 0x00000020 /* inspircd-style per-user immune */ 81 82 /* chanban_t.flags */ 83 #define CBAN_ANTIFLOOD 0x00000001 /* chanserv/antiflood set this */ 84 85 #define MTYPE_NUL 0 86 #define MTYPE_ADD 1 87 #define MTYPE_DEL 2 88 89 struct cmode_ 90 { 91 char mode; 92 unsigned int value; 93 }; 94 95 struct extmode 96 { 97 char mode; 98 bool (*check)(const char *, channel_t *, mychan_t *, user_t *, myuser_t *); 99 }; 100 101 /* channel related hooks */ 102 typedef struct { 103 chanuser_t *cu; /* Write NULL here if you kicked the user. 104 When kicking the last user, you must join a 105 service first, otherwise the channel may be 106 destroyed and crashes may occur. The service may 107 not part until you return; chanserv provides 108 MC_INHABIT to help with this. 109 This also prevents kick/rejoin floods. 110 If this is NULL, a previous function kicked 111 the user */ 112 } hook_channel_joinpart_t; 113 114 typedef struct { 115 user_t *u; 116 channel_t *c; 117 char *msg; 118 } hook_cmessage_data_t; 119 120 typedef struct { 121 user_t *u; /* Online user that changed the topic */ 122 server_t *s; /* Server that restored a topic */ 123 channel_t *c; /* Channel still has old topic */ 124 const char *setter; /* Stored setter string, can be nick, nick!user@host 125 or server */ 126 time_t ts; /* Time the topic was changed */ 127 const char *topic; /* New topic */ 128 int approved; /* Write non-zero here to cancel the change */ 129 } hook_channel_topic_check_t; 130 131 typedef struct { 132 user_t *u; 133 channel_t *c; 134 } hook_channel_mode_t; 135 136 typedef struct { 137 chanuser_t *cu; 138 const char mchar; 139 const unsigned int mvalue; 140 } hook_channel_mode_change_t; 141 142 /* cmode.c */ 143 E char *flags_to_string(unsigned int flags); 144 E int mode_to_flag(char c); 145 E void channel_mode(user_t *source, channel_t *chan, int parc, char *parv[]); 146 E void channel_mode_va(user_t *source, channel_t *chan, int parc, char *parv0, ...); 147 E void clear_simple_modes(channel_t *c); 148 E char *channel_modes(channel_t *c, bool doparams); 149 E void modestack_flush_channel(channel_t *channel); 150 E void modestack_forget_channel(channel_t *channel); 151 E void modestack_finalize_channel(channel_t *channel); 152 E void check_modes(mychan_t *mychan, bool sendnow); 153 154 E void modestack_mode_simple_real(const char *source, channel_t *channel, int dir, int flags); 155 E void modestack_mode_limit_real(const char *source, channel_t *channel, int dir, unsigned int limit); 156 E void modestack_mode_ext_real(const char *source, channel_t *channel, int dir, unsigned int i, const char *value); 157 E void modestack_mode_param_real(const char *source, channel_t *channel, int dir, char type, const char *value); 158 159 E void (*modestack_mode_simple)(const char *source, channel_t *channel, int dir, int flags); 160 E void (*modestack_mode_limit)(const char *source, channel_t *channel, int dir, unsigned int limit); 161 E void (*modestack_mode_ext)(const char *source, channel_t *channel, int dir, unsigned int i, const char *value); 162 E void (*modestack_mode_param)(const char *source, channel_t *channel, int dir, char type, const char *value); 163 164 E void modestack_flush_now(void); 165 166 /* channels.c */ 167 E mowgli_patricia_t *chanlist; 168 169 E void init_channels(void); 170 171 E channel_t *channel_add(const char *name, time_t ts, server_t *creator); 172 E void channel_delete(channel_t *c); 173 //inline channel_t *channel_find(const char *name); 174 175 E chanuser_t *chanuser_add(channel_t *chan, const char *user); 176 E void chanuser_delete(channel_t *chan, user_t *user); 177 E chanuser_t *chanuser_find(channel_t *chan, user_t *user); 178 179 E chanban_t *chanban_add(channel_t *chan, const char *mask, int type); 180 E void chanban_delete(chanban_t *c); 181 E chanban_t *chanban_find(channel_t *chan, const char *mask, int type); 182 //inline void chanban_clear(channel_t *chan); 183 184 #endif 185 186 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs 187 * vim:ts=8 188 * vim:sw=8 189 * vim:noexpandtab 190 */ 191