chan.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * chan.h
  3. * stuff common to chan.c and mode.c
  4. * users.h needs to be loaded too
  5. *
  6. */
  7. #ifndef _EGG_CHAN_H
  8. #define _EGG_CHAN_H
  9. typedef struct memstruct {
  10. struct memstruct *next;
  11. struct userrec *user;
  12. time_t joined;
  13. time_t split; /* in case they were just netsplit */
  14. time_t last; /* for measuring idle time */
  15. interval_t delay; /* for delayed autoop */
  16. int hops;
  17. int tried_getuser;
  18. unsigned short flags;
  19. char nick[NICKLEN];
  20. char userhost[UHOSTLEN];
  21. char userip[UHOSTLEN];
  22. bool is_me;
  23. } memberlist;
  24. #define CHAN_FLAG_OP 1
  25. #define CHAN_FLAG_VOICE 2
  26. #define CHAN_FLAG_USER 3
  27. #define CHANMETA "#&!+"
  28. #define NICKVALID "[{}]^`|\\_-"
  29. #define CHANOP BIT0 /* channel +o */
  30. #define CHANVOICE BIT1 /* channel +v */
  31. #define FAKEOP BIT2 /* op'd by server */
  32. #define SENTOP BIT3 /* a mode +o was already sent out for this user */
  33. #define SENTDEOP BIT4 /* a mode -o was already sent out for this user */
  34. #define SENTKICK BIT5 /* a kick was already sent out for this user */
  35. #define SENTVOICE BIT6 /* a mode +v was already sent out for this user */
  36. #define SENTDEVOICE BIT7 /* a devoice has been sent */
  37. #define WASOP BIT8 /* was an op before a split */
  38. //#define STOPWHO BIT9
  39. #define FULL_DELAY BIT10
  40. #define STOPCHECK BIT11
  41. #define EVOICE BIT12 /* keeps people -v */
  42. #define OPER BIT13
  43. #define chan_hasvoice(x) (x->flags & CHANVOICE)
  44. #define chan_hasop(x) (x->flags & CHANOP)
  45. #define chan_fakeop(x) (x->flags & FAKEOP)
  46. #define chan_sentop(x) (x->flags & SENTOP)
  47. #define chan_sentdeop(x) (x->flags & SENTDEOP)
  48. #define chan_sentkick(x) (x->flags & SENTKICK)
  49. #define chan_sentvoice(x) (x->flags & SENTVOICE)
  50. #define chan_sentdevoice(x) (x->flags & SENTDEVOICE)
  51. #define chan_issplit(x) (x->split > 0)
  52. #define chan_wasop(x) (x->flags & WASOP)
  53. #define chan_stopcheck(x) (x->flags & STOPCHECK)
  54. #define P_IGNORE 0
  55. #define P_DEOP 1
  56. #define P_KICK 2
  57. #define P_DELETE 3
  58. /* Why duplicate this struct for exempts and invites only under another
  59. * name? <cybah>
  60. */
  61. typedef struct maskstruct {
  62. struct maskstruct *next;
  63. time_t timer;
  64. char *mask;
  65. char *who;
  66. } masklist;
  67. /* Used for temporary bans, exempts and invites */
  68. typedef struct maskrec {
  69. struct maskrec *next;
  70. time_t expire,
  71. added,
  72. lastactive;
  73. int flags;
  74. char *mask,
  75. *desc,
  76. *user;
  77. } maskrec;
  78. extern maskrec *global_bans, *global_exempts, *global_invites;
  79. #define MASKREC_STICKY 1
  80. #define MASKREC_PERM 2
  81. /* For every channel i join */
  82. struct chan_t {
  83. memberlist *member;
  84. masklist *ban;
  85. masklist *exempt;
  86. masklist *invite;
  87. time_t jointime;
  88. time_t parttime;
  89. time_t no_op;
  90. time_t drone_jointime;
  91. time_t last_eI; /* this will stop +e and +I from being checked over and over if the bot is stuck in a
  92. * -o+o loop for some reason, hence possibly causing a SENDQ kill
  93. */
  94. int fighting;
  95. int drone_set_mode;
  96. int drone_joins;
  97. #ifdef G_BACKUP
  98. int backup_time; /* If non-0, set +backup when now>backup_time */
  99. #endif /* G_BACKUP */
  100. int maxmembers;
  101. int members;
  102. int splitmembers;
  103. int do_opreq;
  104. char *topic;
  105. char *key;
  106. unsigned short int mode;
  107. };
  108. #define CHANINV BIT0 /* +i */
  109. #define CHANPRIV BIT1 /* +p */
  110. #define CHANSEC BIT2 /* +s */
  111. #define CHANMODER BIT3 /* +m */
  112. #define CHANTOPIC BIT4 /* +t */
  113. #define CHANNOMSG BIT5 /* +n */
  114. #define CHANLIMIT BIT6 /* -l -- used only for protecting modes */
  115. #define CHANKEY BIT7 /* +k */
  116. #define CHANANON BIT8 /* +a -- ircd 2.9 */
  117. #define CHANQUIET BIT9 /* +q -- ircd 2.9 */
  118. #define CHANNOCLR BIT10 /* +c -- bahamut */
  119. #define CHANREGON BIT11 /* +R -- bahamut */
  120. #define CHANMODR BIT12 /* +M -- bahamut */
  121. #define CHANNOCTCP BIT13 /* +C -- QuakeNet's ircu 2.10 */
  122. #define CHANLONLY BIT14 /* +r -- ircu 2.10.11 */
  123. #define MODES_PER_LINE_MAX 6
  124. /* For every channel i'm supposed to be active on */
  125. struct chanset_t {
  126. struct chanset_t *next;
  127. struct chan_t channel; /* current information */
  128. maskrec *bans, /* temporary channel bans */
  129. *exempts, /* temporary channel exempts */
  130. *invites; /* temporary channel invites */
  131. time_t added_ts; /* ..and when? */
  132. struct {
  133. char *op;
  134. int type;
  135. } cmode[MODES_PER_LINE_MAX]; /* parameter-type mode changes - */
  136. struct {
  137. char *op;
  138. } ccmode[MODES_PER_LINE_MAX]; /* parameter-type mode changes - */
  139. /* detect floods */
  140. time_t floodtime[FLOOD_CHAN_MAX];
  141. uint32_t status;
  142. uint32_t ircnet_status;
  143. int flood_pub_thr;
  144. interval_t flood_pub_time;
  145. int flood_join_thr;
  146. interval_t flood_join_time;
  147. int flood_deop_thr;
  148. interval_t flood_deop_time;
  149. int flood_kick_thr;
  150. interval_t flood_kick_time;
  151. int flood_ctcp_thr;
  152. interval_t flood_ctcp_time;
  153. int flood_nick_thr;
  154. interval_t flood_nick_time;
  155. interval_t flood_lock_time;
  156. interval_t flood_mjoin_time;
  157. int flood_mjoin_thr;
  158. int limitraise;
  159. int checklimit;
  160. int closed_ban;
  161. int closed_private;
  162. int closed_invite;
  163. int bad_cookie;
  164. int manop;
  165. int mdop;
  166. int mop;
  167. int voice_non_ident;
  168. int ban_type;
  169. interval_t auto_delay;
  170. int knock_flags;
  171. int protect_backup;
  172. /* Chanint template
  173. *int temp;
  174. */
  175. int flood_exempt_mode;
  176. #ifdef REVENGE
  177. int revenge_mode;
  178. #endif
  179. interval_t ban_time;
  180. interval_t invite_time;
  181. interval_t exempt_time;
  182. /* desired channel modes: */
  183. int mode_pls_prot; /* modes to enforce */
  184. int mode_mns_prot; /* modes to reject */
  185. int limit_prot; /* desired limit */
  186. /* queued mode changes: */
  187. int limit; /* new limit to set */
  188. size_t bytes; /* total bytes so far */
  189. size_t cbytes;
  190. int compat; /* to prevent mixing old/new modes */
  191. int floodnum[FLOOD_CHAN_MAX];
  192. int opreqtime[5]; /* remember when ops was requested */
  193. char *key; /* new key to set */
  194. char *rmkey; /* old key to remove */
  195. char pls[21]; /* positive mode changes */
  196. char mns[21]; /* negative mode changes */
  197. char key_prot[121]; /* desired password */
  198. /* Chanchar template
  199. *char temp[121];
  200. */
  201. char topic[121];
  202. char added_by[HANDLEN + 1]; /* who added the channel? */
  203. char floodwho[FLOOD_CHAN_MAX][128];
  204. char deopd[NICKLEN]; /* last person deop'd (must change */
  205. char dname[81]; /* what the users know the channel as like !eggdev */
  206. char name[81]; /* what the servers know the channel as, like !ABCDEeggdev */
  207. };
  208. /* behavior modes for the channel */
  209. /* Chanflag template
  210. * #define CHAN_TEMP 0x0000
  211. */
  212. #define CHAN_ENFORCEBANS BIT0 /* kick people who match channel bans */
  213. #define CHAN_DYNAMICBANS BIT1 /* only activate bans when needed */
  214. #define CHAN_NOUSERBANS BIT2 /* don't let non-bots place bans */
  215. #define CHAN_CLOSED BIT3 /* Only users +o can join */
  216. #define CHAN_BITCH BIT4 /* be a tightwad with ops */
  217. #define CHAN_TAKE BIT5 /* When a bot gets opped, take the chan */
  218. #define CHAN_PROTECT BIT6 /* Go +bitch and mass deop if anyone mass ops or mass deops */
  219. #define CHAN_BOTBITCH BIT7 /* only let bots be opped? */
  220. #define CHAN_BACKUP BIT8 /* Join the BOT_BACKUP bots when set */
  221. #define CHAN_SECRET BIT9 /* don't advertise channel on botnet */
  222. #define CHAN_RBL BIT10 /* Lookup users in RBL (requires +r) */
  223. #define CHAN_CYCLE BIT11 /* cycle the channel if possible */
  224. #define CHAN_INACTIVE BIT12 /* no irc support for this channel */
  225. #define CHAN_VOICE BIT13 /* a bot +y|y will voice *, except +q */
  226. #define CHAN_NOMASSJOIN BIT14 /* watch for mass join for flood nets and react */
  227. #define CHAN_NODESYNCH BIT15
  228. #define CHAN_FASTOP BIT16 /* Bots will not use +o-b to op (no cookies) */
  229. #define CHAN_PRIVATE BIT17 /* users need |o to access chan */
  230. #define CHAN_DYNAMICEXEMPTS BIT18
  231. #define CHAN_NOUSEREXEMPTS BIT19
  232. #define CHAN_DYNAMICINVITES BIT20
  233. #define CHAN_NOUSERINVITES BIT21
  234. #define CHAN_FLAGGED BIT22 /* flagged during rehash for delete */
  235. #define CHAN_AUTOOP BIT23
  236. #define CHAN_MEANKICKS BIT24 /* use mean/offensive kicks/bans */
  237. #define CHAN_VOICEBITCH BIT25
  238. #define CHAN_ASKED_EXEMPTS BIT0
  239. #define CHAN_ASKED_INVITES BIT1
  240. #define CHAN_HAVEBANS BIT2 /* have been opped and received the ban list */
  241. #define CHAN_ASKEDBANS BIT3
  242. #define CHAN_ASKEDMODES BIT4 /* find out key-info on IRCu */
  243. #define CHAN_ACTIVE BIT5 /* like i'm actually on the channel and stuff */
  244. #define CHAN_PEND BIT6 /* just joined; waiting for end of WHO list */
  245. #define CHAN_JOINING BIT7 /* attempting to join, dont flood with JOIN #chan */
  246. #define CHAN_JUPED BIT8 /* Is channel juped */
  247. #define CHAN_STOP_CYCLE BIT9 /* Some efnetservers have defined NO_CHANOPS_WHEN_SPLIT */
  248. /* prototypes */
  249. memberlist *ismember(struct chanset_t *, const char *);
  250. struct chanset_t *findchan(const char *name);
  251. struct chanset_t *findchan_by_dname(const char *name);
  252. /* is this channel +s/+p? */
  253. #define channel_hidden(chan) (chan->channel.mode & (CHANPRIV | CHANSEC))
  254. /* is this channel +t? */
  255. #define channel_optopic(chan) (chan->channel.mode & CHANTOPIC)
  256. #define channel_active(chan) (chan->ircnet_status & CHAN_ACTIVE)
  257. #define channel_joining(chan) (chan->ircnet_status & CHAN_JOINING)
  258. #define channel_pending(chan) (chan->ircnet_status & CHAN_PEND)
  259. #define channel_juped(chan) (chan->ircnet_status & CHAN_JUPED)
  260. #define channel_stop_cycle(chan) (chan->ircnet_status & CHAN_STOP_CYCLE)
  261. #define channel_dynamicexempts(chan) (chan->status & CHAN_DYNAMICEXEMPTS)
  262. #define channel_nouserexempts(chan) (chan->status & CHAN_NOUSEREXEMPTS)
  263. #define channel_dynamicinvites(chan) (chan->status & CHAN_DYNAMICINVITES)
  264. #define channel_nouserinvites(chan) (chan->status & CHAN_NOUSERINVITES)
  265. #define channel_backup(chan) (chan->status & CHAN_BACKUP)
  266. #define channel_bitch(chan) (chan->status & CHAN_BITCH)
  267. #define chan_bitch(chan) (chan->status & (CHAN_BITCH|CHAN_BOTBITCH))
  268. #define channel_botbitch(chan) (chan->status & CHAN_BOTBITCH)
  269. #define channel_nodesynch(chan) (chan->status & CHAN_NODESYNCH)
  270. #define channel_enforcebans(chan) (chan->status & CHAN_ENFORCEBANS)
  271. #define channel_dynamicbans(chan) (chan->status & CHAN_DYNAMICBANS)
  272. #define channel_nouserbans(chan) (chan->status & CHAN_NOUSERBANS)
  273. #define channel_secret(chan) (chan->status & CHAN_SECRET)
  274. #define channel_cycle(chan) (chan->status & CHAN_CYCLE)
  275. #define channel_inactive(chan) (chan->status & CHAN_INACTIVE)
  276. #ifdef REVENGE
  277. #define channel_revenge(chan) (chan->status & CHAN_REVENGE)
  278. #define channel_revengebot(chan) (chan->status & CHAN_REVENGEBOT)
  279. #endif
  280. #define channel_closed(chan) (chan->status & CHAN_CLOSED)
  281. #define channel_take(chan) (chan->status & CHAN_TAKE)
  282. #define channel_voice(chan) (chan->status & CHAN_VOICE)
  283. #define channel_fastop(chan) (chan->status & CHAN_FASTOP)
  284. #define channel_privchan(chan) (chan->status & CHAN_PRIVATE)
  285. #define channel_autoop(chan) (chan->status & CHAN_AUTOOP)
  286. #define channel_nomassjoin(chan) (chan->status & CHAN_NOMASSJOIN)
  287. #define channel_meankicks(chan) (chan->status & CHAN_MEANKICKS)
  288. #define channel_rbl(chan) (chan->status & CHAN_RBL)
  289. #define channel_voicebitch(chan) (chan->status & CHAN_VOICEBITCH)
  290. #define channel_protect(chan) (chan->status & CHAN_PROTECT)
  291. /* Chanflag template
  292. *#define channel_temp(chan) (chan->status & CHAN_PRIVATE)
  293. */
  294. struct msgq_head {
  295. struct msgq *head;
  296. struct msgq *last;
  297. size_t tot;
  298. bool warned;
  299. };
  300. /* Used to queue a lot of things */
  301. struct msgq {
  302. struct msgq *next;
  303. size_t len;
  304. char *msg;
  305. };
  306. #endif /* _EGG_CHAN_H */