irc.h 6.0 KB

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