chan.h 13 KB

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