irc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * irc.h -- part of irc.mod
  3. *
  4. */
  5. #ifndef _EGG_MOD_IRC_IRC_H
  6. #define _EGG_MOD_IRC_IRC_H
  7. #include "src/auth.h"
  8. #include "src/chanprog.h"
  9. enum { BC_NOCOOKIE = 1, BC_SLACK, BC_HASH, BC_COUNTER };
  10. #define PRIO_DEOP 1
  11. #define PRIO_KICK 2
  12. /* For flushmodes */
  13. #define NORMAL 0
  14. #define QUICK 1
  15. #ifdef MAKING_IRC
  16. namespace bd {
  17. class String;
  18. }
  19. #ifdef CACHE
  20. typedef struct cache_chan_b {
  21. struct cache_chan_b *next;
  22. bool invite; /* set to invite on userhost */
  23. bool ban; /* set to ban on join */
  24. bool op; /* should we auto-op? */
  25. bool invited; /* set when we've called cache_invite, meaning we aren't hijacked */
  26. char dname[81];
  27. } cache_chan_t;
  28. typedef struct cache_b {
  29. struct cache_b *next;
  30. cache_chan_t *cchan;
  31. // struct chanset_t *chan;
  32. // struct userrec *user;
  33. time_t timeval;
  34. // bool invite; /* INVITE ON USERHOST */
  35. // bool ban; /* BAN ON USERHOST */
  36. // bool invited; /* INVITED - CLEARED */
  37. bool bot;
  38. char nick[NICKLEN];
  39. char handle[NICKLEN];
  40. char uhost[UHOSTLEN];
  41. } cache_t;
  42. static void cache_chan_del(char *, char *);
  43. //static cache_chan_t *cache_chan_find(cache_t *, char *, char *);
  44. static void cache_chan_find(cache_t *, cache_chan_t *, char *, char *);
  45. static cache_chan_t *cache_chan_add(cache_t *, char *);
  46. static cache_t *cache_find(char *);
  47. static cache_t *cache_new(char *);
  48. static void cache_del(char *, cache_t *);
  49. static void cache_debug(void);
  50. #endif /* CACHE */
  51. static void cache_invite(struct chanset_t *, char *, char *, char *, bool, bool);
  52. //static char *makecookie(const char *, const memberlist*, const memberlist*, const memberlist* = NULL, const memberlist* = NULL);
  53. void makecookie(char*, size_t, const char *, const memberlist*, const memberlist*, const memberlist* = NULL, const memberlist* = NULL);
  54. static int checkcookie(const char*, const memberlist*, const memberlist*, const char*, int);
  55. extern void counter_clear(const char*);
  56. static bool any_ops(struct chanset_t *);
  57. static char *getchanmode(struct chanset_t *);
  58. static void flush_mode(struct chanset_t *, int);
  59. static bool member_getuser(memberlist* m, bool act_on_lookup = 0);
  60. static void do_protect(struct chanset_t* chan, const char* reason);
  61. /* reset(bans|exempts|invites) are now just macros that call resetmasks
  62. * in order to reduce the code duplication. <cybah>
  63. */
  64. #define resetbans(chan) resetmasks((chan), (chan)->channel.ban, (chan)->bans, global_bans, 'b')
  65. #define resetexempts(chan) resetmasks((chan), (chan)->channel.exempt, (chan)->exempts, global_exempts, 'e')
  66. #define resetinvites(chan) resetmasks((chan), (chan)->channel.invite, (chan)->invites, global_invites, 'I')
  67. static int detect_offense(memberlist*, struct chanset_t *, char *);
  68. /* static int target_priority(struct chanset_t *, memberlist *, int); */
  69. static bool do_op(char *, struct chanset_t *, bool, bool);
  70. static void request_op(struct chanset_t *);
  71. static void request_in(struct chanset_t *);
  72. static bool detect_chan_flood(memberlist *m, const char* from, struct chanset_t *chan, int which, const char *msg = NULL);
  73. static bool new_mask(masklist *, char *, char *);
  74. static void do_closed_kick(struct chanset_t *, memberlist *);
  75. static char *quickban(struct chanset_t *, const char *);
  76. static bool killmember(struct chanset_t *chan, char *nick);
  77. static void check_lonely_channel(struct chanset_t *chan);
  78. static int gotmode(char *, char *);
  79. void unset_im(struct chanset_t* chan);
  80. void detected_drone_flood(struct chanset_t* chan, memberlist*);
  81. static void send_chan_who(int queue, struct chanset_t* chan, bool chain = 0);
  82. #define newban(chan, mask, who) new_mask((chan)->channel.ban, mask, who)
  83. #define newexempt(chan, mask, who) new_mask((chan)->channel.exempt, mask, who)
  84. #define newinvite(chan, mask, who) new_mask((chan)->channel.invite, mask, who)
  85. void resolve_to_member(struct chanset_t *chan, char *nick, char *host);
  86. typedef struct resolvstruct resolv_member;
  87. void resolve_to_rbl(struct chanset_t *chan, const char *host, struct resolvstruct *r = NULL);
  88. static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char Mode);
  89. static void get_channel_masks(struct chanset_t* chan);
  90. #endif /* MAKING_IRC */
  91. void my_setkey(struct chanset_t *, char *);
  92. void force_join_chan(struct chanset_t* chan, int idx = DP_MODE);
  93. void join_chan(struct chanset_t* chan, int idx = DP_MODE);
  94. int check_bind_authc(char *, Auth *, char *, char *);
  95. void notice_invite(struct chanset_t *, char *, char *, char *, bool);
  96. void real_add_mode(struct chanset_t *, const char, const char, const char *, bool);
  97. #define add_mode(chan, pls, mode, nick) real_add_mode(chan, pls, mode, nick, 0)
  98. #define add_cookie(chan, nick) real_add_mode(chan, '+', 'o', nick, 1)
  99. /* Check if I am a chanop. Returns boolean 1 or 0.
  100. */
  101. inline bool me_op(const struct chanset_t *chan)
  102. {
  103. const memberlist *mx = ismember(chan, botname);
  104. return mx && chan_hasop(mx);
  105. }
  106. bool me_voice(const struct chanset_t *);
  107. void check_this_ban(struct chanset_t *, char *, bool);
  108. void check_this_exempt(struct chanset_t *, char *, bool);
  109. void check_this_invite(struct chanset_t *, char *, bool);
  110. inline void check_this_mask(const char type, struct chanset_t *chan, char *mask, bool sticky)
  111. {
  112. if (channel_active(chan)) {
  113. if (type == 'b')
  114. check_this_ban(chan, mask, sticky);
  115. else if (type == 'e')
  116. check_this_exempt(chan, mask, sticky);
  117. else if (type == 'I')
  118. check_this_invite(chan, mask, sticky);
  119. }
  120. }
  121. void check_this_user(char *, int, char *);
  122. void raise_limit(struct chanset_t *);
  123. void enforce_closed(struct chanset_t *);
  124. void recheck_channel(struct chanset_t *, int);
  125. void recheck_channel_modes(struct chanset_t *);
  126. void irc_report(int, int);
  127. void flush_modes();
  128. void reset_chan_info(struct chanset_t *);
  129. char *getnick(const char *, struct chanset_t *);
  130. void check_shouldjoin(struct chanset_t* chan);
  131. extern int max_bans, max_exempts, max_invites, max_modes;
  132. extern bool use_354, include_lk;
  133. extern unsigned int modesperline;
  134. extern unsigned long my_cookie_counter;
  135. #endif /* _EGG_MOD_IRC_IRC_H */