chan.h 14 KB

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