4
0

msgcmds.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (C) 2000,2001 Florian Sander
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. static int validchan(char *chan)
  19. {
  20. struct chanset_t *ch;
  21. #ifndef OLDBOT
  22. ch = findchan_by_dname(chan);
  23. #else
  24. ch = findchan(chan);
  25. #endif
  26. if (ch)
  27. return 1;
  28. return 0;
  29. }
  30. static int msg_place(char *nick, char *uhost, struct userrec *u,
  31. char *rest)
  32. {
  33. char *chan, *reply;
  34. Context;
  35. // check for flood
  36. if (stat_flood())
  37. return 1;
  38. reset_global_vars();
  39. glob_nick = nick;
  40. chan = newsplit(&rest);
  41. glob_slang = slang_find(coreslangs, slang_chanlang_get(chanlangs, chan));
  42. putlog(LOG_CMDS, "*", "(%s!%s) !%s! place %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  43. if (!validchan(chan)) {
  44. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(2034));
  45. return 1;
  46. }
  47. reply = tell_place(nick, u ? u->handle : "*", chan, rest);
  48. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, reply);
  49. return 1;
  50. }
  51. static int msg_stat(char *nick, char *uhost, struct userrec *u,
  52. char *rest)
  53. {
  54. char *chan;
  55. Context;
  56. // check for flood
  57. if (stat_flood())
  58. return 1;
  59. reset_global_vars();
  60. glob_nick = nick;
  61. chan = newsplit(&rest);
  62. glob_slang = slang_find(coreslangs, slang_chanlang_get(chanlangs, chan));
  63. if (!validchan(chan)) {
  64. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(2036));
  65. return 1;
  66. }
  67. putlog(LOG_CMDS, "*", "(%s!%s) !%s! stat %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  68. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, tell_stat(nick, chan, rest));
  69. return 1;
  70. }
  71. static int msg_top(char *nick, char *uhost, struct userrec *u,
  72. char *rest)
  73. {
  74. char *chan, *toptext;
  75. Context;
  76. // check for flood
  77. if (stat_flood())
  78. return 1;
  79. reset_global_vars();
  80. glob_nick = nick;
  81. chan = newsplit(&rest);
  82. glob_slang = slang_find(coreslangs, slang_chanlang_get(chanlangs, chan));
  83. if (!validchan(chan)) {
  84. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(2036));
  85. return 1;
  86. }
  87. putlog(LOG_CMDS, "*", "(%s!%s) !%s! top %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  88. toptext = tell_ntop(chan, rest, 0);
  89. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, toptext ? toptext : "ERROR");
  90. return 1;
  91. }
  92. static int msg_last(char *nick, char *uhost, struct userrec *u,
  93. char *rest)
  94. {
  95. char *chan, *toptext;
  96. Context;
  97. // check for flood
  98. if (stat_flood())
  99. return 1;
  100. reset_global_vars();
  101. glob_nick = nick;
  102. chan = newsplit(&rest);
  103. glob_slang = slang_find(coreslangs, slang_chanlang_get(chanlangs, chan));
  104. if (!validchan(chan)) {
  105. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(2036));
  106. return 1;
  107. }
  108. putlog(LOG_CMDS, "*", "(%s!%s) !%s! last %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  109. toptext = tell_ntop(chan, rest, 1);
  110. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, toptext ? toptext : "ERROR");
  111. return 1;
  112. }
  113. static int msg_wordstats(char *nick, char *uhost, struct userrec *u,
  114. char *rest)
  115. {
  116. char *chan;
  117. Context;
  118. // check for flood
  119. if (stat_flood())
  120. return 1;
  121. glob_nick = nick;
  122. chan = newsplit(&rest);
  123. if (!validchan(chan)) {
  124. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(2038));
  125. return 1;
  126. }
  127. putlog(LOG_CMDS, "*", "(%s!%s) !%s! wordstats %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  128. tell_wordstats(nick, nick, u ? u->handle : "*", chan, rest);
  129. return 1;
  130. }
  131. static int msg_topwords(char *nick, char *uhost, struct userrec *u,
  132. char *rest)
  133. {
  134. char *chan;
  135. Context;
  136. // check for flood
  137. if (stat_flood())
  138. return 1;
  139. chan = newsplit(&rest);
  140. if (!validchan(chan)) {
  141. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(2039));
  142. return 1;
  143. }
  144. putlog(LOG_CMDS, "*", "(%s!%s) !%s! topwords %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  145. tell_topwords(nick, nick, u ? u->handle : "*", chan);
  146. return 1;
  147. }
  148. static int msg_statspass(char *nick, char *uhost, struct userrec *user, char *rest)
  149. {
  150. struct stats_userlist *u;
  151. char *pass, *host;
  152. putlog(LOG_CMDS, "*", "(%s!%s) !%s! STATSPASS %s", nick, uhost, user ? user->handle : "*", rest);
  153. reset_global_vars();
  154. glob_slang = slang_getbynick(coreslangs, nick);
  155. glob_nick = nick;
  156. if (user)
  157. u = findsuser_by_name(user->handle);
  158. else {
  159. host = nmalloc(strlen(nick) + 1 + strlen(uhost) + 1);
  160. sprintf(host, "%s!%s", nick, uhost);
  161. u = findsuser(host);
  162. nfree(host);
  163. }
  164. if (!u) {
  165. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, SLDONTRECOGNIZE);
  166. return 1;
  167. }
  168. glob_user = u;
  169. if (u->password) {
  170. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, SLPASSALREADYSET);
  171. return 1;
  172. }
  173. pass = newsplit(&rest);
  174. if (!pass[0]) {
  175. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, SLPASSUSAGE);
  176. return 1;
  177. }
  178. setpassword(u, pass);
  179. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, SLPASSSET);
  180. return 1;
  181. }
  182. static int msg_lastspoke(char *nick, char *uhost, struct userrec *u,
  183. char *rest)
  184. {
  185. char *chan, *reply;
  186. globstats gs;
  187. Context;
  188. // check for flood
  189. if (stat_flood())
  190. return 1;
  191. chan = newsplit(&rest);
  192. putlog(LOG_CMDS, "*", "(%s!%s) !%s! lastspoke %s %s", nick, uhost, u ? u->handle : "*", chan, rest);
  193. if (!validchan(chan)) {
  194. globstats_init(&gs);
  195. gs.chan = chan;
  196. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, getslang(222));
  197. return 1;
  198. }
  199. reply = cmd_lastspoke(chan, rest);
  200. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, reply);
  201. return 1;
  202. }
  203. static cmd_t stats_msg[] =
  204. {
  205. {"place", "", msg_place, 0},
  206. {"stat", "", msg_stat, 0},
  207. {"wordstats", "", msg_wordstats, 0},
  208. {"topwords", "", msg_topwords, 0},
  209. {"statspass", "", msg_statspass, 0},
  210. {"statpass", "", msg_statspass, 0},
  211. {"lastspoke", "", msg_lastspoke, 0},
  212. {"top", "", msg_top, 0},
  213. {"last", "", msg_last, 0},
  214. {0, 0, 0, 0}
  215. };