chan.h 13 KB

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