cmdsserv.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 1997 Robey Pointer
  3. * Copyright (C) 1999 - 2002 Eggheads Development Team
  4. * Copyright (C) 2002 - 2008 Bryan Drewery
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /*
  21. * cmdsserv.c -- part of server.mod
  22. * handles commands from a user via dcc that cause server interaction
  23. *
  24. */
  25. static void cmd_servers(int idx, char *par)
  26. {
  27. struct server_list *x = serverlist;
  28. int i;
  29. char s[1024] = "";
  30. putlog(LOG_CMDS, "*", "#%s# servers", dcc[idx].nick);
  31. if (!x) {
  32. dprintf(idx, "There are no servers in the server list.\n");
  33. } else {
  34. dprintf(idx, "Server list:\n");
  35. i = 0;
  36. for (; x; x = x->next) {
  37. simple_snprintf(s, sizeof s, " %s:%d %s", x->name,
  38. x->port ? x->port : default_port,
  39. (i == curserv) ? "<- I am here" : "");
  40. dprintf(idx, "%s\n", s);
  41. i++;
  42. }
  43. dprintf(idx, "End of server list.\n");
  44. }
  45. }
  46. static void cmd_dump(int idx, char *par)
  47. {
  48. putlog(LOG_CMDS, "*", "#%s# dump %s", dcc[idx].nick, par);
  49. if (!isowner(dcc[idx].nick)) {
  50. putlog(LOG_WARN, "*", "%s attempted 'dump' %s", dcc[idx].nick, par);
  51. dprintf(idx, "dump is only available to permanent owners.\n");
  52. return;
  53. }
  54. if (!par[0]) {
  55. dprintf(idx, "Usage: dump <server stuff>\n");
  56. return;
  57. }
  58. dprintf(DP_DUMP, "%s\n", replace_vars(par));
  59. }
  60. static void cmd_umode(int idx, char *par)
  61. {
  62. putlog(LOG_CMDS, "*", "#%s# umode %s", dcc[idx].nick, par);
  63. if (!par[0]) {
  64. dprintf(idx, "Usage: umode <+flags>\n");
  65. return;
  66. }
  67. dprintf(DP_SERVER, "MODE %s %s\n", botname, par);
  68. }
  69. static void cmd_jump(int idx, char *par)
  70. {
  71. char *other = NULL, *p = NULL;
  72. int port;
  73. if (par[0]) {
  74. other = newsplit(&par);
  75. port = atoi(newsplit(&par));
  76. if ((p = strchr(other, ':'))) {
  77. *p = 0;
  78. p++;
  79. if (!port)
  80. port = atoi(p);
  81. }
  82. if (!port)
  83. port = default_port;
  84. putlog(LOG_CMDS, "*", "#%s# jump %s %d %s", dcc[idx].nick, other, port, par);
  85. strlcpy(newserver, other, sizeof newserver);
  86. newserverport = port;
  87. strlcpy(newserverpass, par, sizeof newserverpass);
  88. } else
  89. putlog(LOG_CMDS, "*", "#%s# jump", dcc[idx].nick);
  90. dprintf(idx, "Jumping servers...\n");
  91. nuke_server("changing servers");
  92. cycle_time = 0;
  93. }
  94. static void cmd_clearqueue(int idx, char *par)
  95. {
  96. int msgs;
  97. putlog(LOG_CMDS, "*", "#%s# clearqueue %s", dcc[idx].nick, par);
  98. if (!par[0]) {
  99. dprintf(idx, "Usage: clearqueue <mode|server|help|all>\n");
  100. return;
  101. }
  102. if (!strcasecmp(par, "all")) {
  103. msgs = modeq.tot + mq.tot + hq.tot;
  104. msgq_clear(&modeq);
  105. msgq_clear(&mq);
  106. msgq_clear(&hq);
  107. burst = 0;
  108. double_warned = 0;
  109. dprintf(idx, "Removed %d message%s from all queues.\n", msgs,
  110. (msgs != 1) ? "s" : "");
  111. } else if (!strcasecmp(par, "mode")) {
  112. msgs = modeq.tot;
  113. msgq_clear(&modeq);
  114. if (mq.tot == 0)
  115. burst = 0;
  116. double_warned = 0;
  117. dprintf(idx, "Removed %d message%s from the mode queue.\n", msgs,
  118. (msgs != 1) ? "s" : "");
  119. } else if (!strcasecmp(par, "help")) {
  120. msgs = hq.tot;
  121. msgq_clear(&hq);
  122. double_warned = 0;
  123. dprintf(idx, "Removed %d message%s from the help queue.\n", msgs,
  124. (msgs != 1) ? "s" : "");
  125. } else if (!strcasecmp(par, "server")) {
  126. msgs = mq.tot;
  127. msgq_clear(&mq);
  128. if (modeq.tot == 0)
  129. burst = 0;
  130. double_warned = 0;
  131. dprintf(idx, "Removed %d message%s from the server queue.\n", msgs,
  132. (msgs != 1) ? "s" : "");
  133. } else {
  134. dprintf(idx, "Usage: clearqueue <mode|server|help|all>\n");
  135. return;
  136. }
  137. }
  138. /* Function call should be:
  139. * int cmd_whatever(idx,"parameters");
  140. *
  141. * As with msg commands, function is responsible for any logging.
  142. */
  143. static cmd_t C_dcc_serv[] =
  144. {
  145. {"clearqueue", "m", (Function) cmd_clearqueue, NULL, LEAF},
  146. {"dump", "a", (Function) cmd_dump, NULL, LEAF},
  147. {"jump", "m", (Function) cmd_jump, NULL, LEAF},
  148. {"servers", "m", (Function) cmd_servers, NULL, LEAF},
  149. {"umode", "m", (Function) cmd_umode, NULL, LEAF},
  150. {NULL, NULL, NULL, NULL, 0}
  151. };