PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mod/server.mod/cmdsserv.c

https://github.com/eggheads/eggdrop-1.8
C | 168 lines | 136 code | 8 blank | 24 comment | 34 complexity | 304eea4eb082203d10ea5b0d49c4d13a MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * cmdsserv.c -- part of server.mod
  3. * handles commands from a user via dcc that cause server interaction
  4. *
  5. * $Id: cmdsserv.c,v 1.3 2010/11/01 22:38:34 pseudo Exp $
  6. */
  7. /*
  8. * Copyright (C) 1997 Robey Pointer
  9. * Copyright (C) 1999 - 2010 Eggheads Development Team
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. */
  25. static void cmd_servers(struct userrec *u, 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. if ((i == curserv) && realservername)
  38. #ifdef TLS
  39. egg_snprintf(s, sizeof s, " [%s]:%s%d (%s) <- I am here", x->name,
  40. x->ssl ? "+" : "", x->port ? x->port : default_port,
  41. realservername);
  42. else
  43. egg_snprintf(s, sizeof s, " [%s]:%s%d %s", x->name, x->ssl ? "+" : "",
  44. x->port ? x->port : default_port,
  45. (i == curserv) ? "<- I am here" : "");
  46. #else
  47. egg_snprintf(s, sizeof s, " [%s]:%d (%s) <- I am here", x->name,
  48. x->port ? x->port : default_port, realservername);
  49. else
  50. egg_snprintf(s, sizeof s, " [%s]:%d %s", x->name,
  51. x->port ? x->port : default_port,
  52. (i == curserv) ? "<- I am here" : "");
  53. #endif
  54. dprintf(idx, "%s\n", s);
  55. i++;
  56. }
  57. dprintf(idx, "End of server list.\n");
  58. }
  59. }
  60. static void cmd_dump(struct userrec *u, int idx, char *par)
  61. {
  62. if (!(isowner(dcc[idx].nick)) && (must_be_owner == 2)) {
  63. dprintf(idx, MISC_NOSUCHCMD);
  64. return;
  65. }
  66. if (!par[0]) {
  67. dprintf(idx, "Usage: dump <server stuff>\n");
  68. return;
  69. }
  70. putlog(LOG_CMDS, "*", "#%s# dump %s", dcc[idx].nick, par);
  71. dprintf(DP_SERVER, "%s\n", par);
  72. }
  73. static void cmd_jump(struct userrec *u, int idx, char *par)
  74. {
  75. char *other;
  76. #ifdef TLS
  77. char *sport;
  78. #endif
  79. int port;
  80. if (par[0]) {
  81. other = newsplit(&par);
  82. #ifdef TLS
  83. sport = newsplit(&par);
  84. if (*sport == '+')
  85. use_ssl = 1;
  86. else
  87. use_ssl = 0;
  88. port = atoi(sport);
  89. if (!port) {
  90. port = default_port;
  91. use_ssl = 0;
  92. }
  93. putlog(LOG_CMDS, "*", "#%s# jump %s %s%d %s", dcc[idx].nick, other,
  94. use_ssl ? "+" : "", port, par);
  95. #else
  96. port = atoi(newsplit(&par));
  97. if (!port)
  98. port = default_port;
  99. putlog(LOG_CMDS, "*", "#%s# jump %s %d %s", dcc[idx].nick, other,
  100. port, par);
  101. #endif
  102. strncpyz(newserver, other, sizeof newserver);
  103. newserverport = port;
  104. strncpyz(newserverpass, par, sizeof newserverpass);
  105. } else
  106. putlog(LOG_CMDS, "*", "#%s# jump", dcc[idx].nick);
  107. dprintf(idx, "%s...\n", IRC_JUMP);
  108. cycle_time = 0;
  109. nuke_server("changing servers");
  110. }
  111. static void cmd_clearqueue(struct userrec *u, int idx, char *par)
  112. {
  113. int msgs;
  114. if (!par[0]) {
  115. dprintf(idx, "Usage: clearqueue <mode|server|help|all>\n");
  116. return;
  117. }
  118. if (!egg_strcasecmp(par, "all")) {
  119. msgs = modeq.tot + mq.tot + hq.tot;
  120. msgq_clear(&modeq);
  121. msgq_clear(&mq);
  122. msgq_clear(&hq);
  123. double_warned = burst = 0;
  124. dprintf(idx, "Removed %d message%s from all queues.\n", msgs,
  125. (msgs != 1) ? "s" : "");
  126. } else if (!egg_strcasecmp(par, "mode")) {
  127. msgs = modeq.tot;
  128. msgq_clear(&modeq);
  129. if (mq.tot == 0)
  130. burst = 0;
  131. double_warned = 0;
  132. dprintf(idx, "Removed %d message%s from the mode queue.\n", msgs,
  133. (msgs != 1) ? "s" : "");
  134. } else if (!egg_strcasecmp(par, "help")) {
  135. msgs = hq.tot;
  136. msgq_clear(&hq);
  137. double_warned = 0;
  138. dprintf(idx, "Removed %d message%s from the help queue.\n", msgs,
  139. (msgs != 1) ? "s" : "");
  140. } else if (!egg_strcasecmp(par, "server")) {
  141. msgs = mq.tot;
  142. msgq_clear(&mq);
  143. if (modeq.tot == 0)
  144. burst = 0;
  145. double_warned = 0;
  146. dprintf(idx, "Removed %d message%s from the server queue.\n", msgs,
  147. (msgs != 1) ? "s" : "");
  148. } else {
  149. dprintf(idx, "Usage: clearqueue <mode|server|help|all>\n");
  150. return;
  151. }
  152. putlog(LOG_CMDS, "*", "#%s# clearqueue %s", dcc[idx].nick, par);
  153. }
  154. static cmd_t C_dcc_serv[] = {
  155. {"dump", "m", (IntFunc) cmd_dump, NULL},
  156. {"jump", "m", (IntFunc) cmd_jump, NULL},
  157. {"servers", "o", (IntFunc) cmd_servers, NULL},
  158. {"clearqueue", "m", (IntFunc) cmd_clearqueue, NULL},
  159. {NULL, NULL, NULL, NULL}
  160. };