Advertisement
Guest User

akick command

a guest
Feb 28th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. static void do_akick(User *u)
  2. {
  3. char *chan = strtok(NULL, " ");
  4. char *cmd = strtok(NULL, " ");
  5. char *mask = strtok(NULL, " ");
  6. char *reason = strtok_remaining();
  7. ChannelInfo *ci = NULL;
  8. int i;
  9. int is_list = (cmd && (stricmp(cmd,"LIST") == 0
  10. || stricmp(cmd,"VIEW") == 0
  11. || stricmp(cmd,"COUNT") == 0));
  12.  
  13. if (!chan
  14. || !cmd
  15. || (!mask && (stricmp(cmd, "ADD") == 0 || stricmp(cmd, "DEL") == 0))
  16. ) {
  17. syntax_error(s_ChanServ, u, "AKICK", CHAN_AKICK_SYNTAX);
  18. } else if (!(ci = get_channelinfo(chan))) {
  19. notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
  20. } else if (ci->flags & CF_VERBOTEN) {
  21. notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
  22. } else if (!check_access_cmd(u, ci, "AKICK", is_list ? "LIST" : cmd)
  23. && !is_services_admin(u)) {
  24. if (ci->founder && valid_ngi(u) && ci->founder == u->ngi->id)
  25. notice_lang(s_ChanServ, u, CHAN_IDENTIFY_REQUIRED, s_ChanServ,
  26. chan);
  27. else
  28. notice_lang(s_ChanServ, u, ACCESS_DENIED);
  29.  
  30. } else if (stricmp(cmd, "ADD") == 0) {
  31.  
  32. char *mask2, *user, *host;
  33. const char *nick;
  34.  
  35. if (readonly) {
  36. notice_lang(s_ChanServ, u, CHAN_AKICK_DISABLED);
  37. put_channelinfo(ci);
  38. return;
  39. }
  40.  
  41. /* Make sure we have a valid nick!user@host mask (fill in missing
  42. * parts with "*"). Error out on @ in nick (also catches a@b!c),
  43. * missing host, or empty nick/user/host. */
  44. mask2 = sstrdup(mask);
  45. nick = mask2;
  46. user = strchr(mask2, '!');
  47. if (user) {
  48. *user++ = 0;
  49. } else {
  50. nick = "*";
  51. user = mask2;
  52. }
  53. host = strchr(user, '@');
  54. if (host)
  55. *host++ = 0;
  56. if (!*nick || !*user || !host || !*host || strchr(nick, '@')) {
  57. notice_lang(s_ChanServ, u, BAD_NICKUSERHOST_MASK);
  58. free(mask2);
  59. put_channelinfo(ci);
  60. return;
  61. }
  62. mask = smalloc(strlen(nick)+strlen(user)+strlen(host)+3);
  63. sprintf(mask, "%s!%s@%s", nick, user, host);
  64. free(mask2);
  65.  
  66. ARRAY_SEARCH(ci->akick, mask, mask, stricmp, i);
  67. if (i < ci->akick_count) {
  68. notice_lang(s_ChanServ, u, CHAN_AKICK_ALREADY_EXISTS,
  69. ci->akick[i].mask, chan);
  70. free(mask);
  71. } else if (ci->akick_count >= CSAutokickMax) {
  72. notice_lang(s_ChanServ, u, CHAN_AKICK_REACHED_LIMIT,
  73. CSAutokickMax);
  74. free(mask);
  75. } else {
  76. ARRAY_EXTEND(ci->akick);
  77. ci->akick[i].channel = ci; /* i points at new entry, from above */
  78. ci->akick[i].mask = mask;
  79. ci->akick[i].reason = reason ? sstrdup(reason) : NULL;
  80. time(&ci->akick[i].set);
  81. ci->akick[i].lastused = 0;
  82. memset(ci->akick[i].who, 0, NICKMAX); // Avoid leaking random data
  83. strbcpy(ci->akick[i].who, u->nick);
  84. notice_lang(s_ChanServ, u, CHAN_AKICK_ADDED, mask, chan);
  85. if (ci->flags & CF_OPNOTICE) {
  86. char *chan_tmp = smalloc(sizeof(char) * (strlen(chan)+2));
  87. chan_tmp[0] = '@';
  88. strcpy(&chan_tmp[1], chan);
  89. notice(s_ChanServ, chan_tmp, "AKICK command used for %s in %s by %s",
  90. mask, chan, u->nick);
  91. free(chan_tmp);
  92. }
  93. }
  94.  
  95. } else if (stricmp(cmd, "DEL") == 0) {
  96.  
  97. if (readonly) {
  98. notice_lang(s_ChanServ, u, CHAN_AKICK_DISABLED);
  99. put_channelinfo(ci);
  100. return;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement