tclstats.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 tcl_incrstats STDVAR
  19. {
  20. int set, type;
  21. Context;
  22. BADARGS(5, 6, " user chan type value ?set?");
  23. if (argc == 6)
  24. set = atoi(argv[5]);
  25. else
  26. set = 0;
  27. type = typetoi(argv[3]);
  28. if (type == -3) {
  29. Tcl_AppendResult(irp, "invalid type", NULL);
  30. return TCL_ERROR;
  31. }
  32. incrstats(argv[1], argv[2], type, atoi(argv[4]), set);
  33. Context;
  34. return TCL_OK;
  35. }
  36. static int tcl_getstats STDVAR
  37. {
  38. char s[30];
  39. int today = 0;
  40. Context;
  41. BADARGS(4, 5, " user chan type ?today?");
  42. if (typetoi(argv[3]) < 0) {
  43. Tcl_AppendResult(irp, "invalid type", NULL);
  44. return TCL_ERROR;
  45. }
  46. if (argc == 5)
  47. today = atoi(argv[4]);
  48. if ((today != 1) && (today != 0)) {
  49. Tcl_AppendResult(irp, "invalid today parameter. Must be 0 or 1.", NULL);
  50. return TCL_ERROR;
  51. }
  52. sprintf(s, "%d", getstats(argv[1], argv[2], argv[3], today));
  53. Tcl_AppendResult(irp, s, NULL);
  54. Context;
  55. return TCL_OK;
  56. }
  57. static int tcl_livestats STDVAR
  58. {
  59. int port;
  60. Context;
  61. BADARGS(2, 2, " port");
  62. if (!strcasecmp(argv[1], "off") || !strcasecmp(argv[1], "0")) {
  63. stop_httpd();
  64. return TCL_OK;
  65. }
  66. port = atoi(argv[1]);
  67. if (port < 1) {
  68. Tcl_AppendResult(irp, "invalid port", NULL);
  69. return TCL_ERROR;
  70. }
  71. start_httpd(port);
  72. return TCL_OK;
  73. }
  74. static int tcl_resetuser STDVAR
  75. {
  76. char *user, *chan;
  77. locstats *ls;
  78. Context;
  79. BADARGS(3, 3, " user channel");
  80. user = argv[1];
  81. chan = argv[2];
  82. ls = findlocstats(chan, user);
  83. if (!ls) {
  84. Tcl_AppendResult(irp, "couldn't find stats for user", NULL);
  85. return TCL_ERROR;
  86. }
  87. resetlocstats(ls);
  88. return TCL_OK;
  89. }
  90. static int tcl_resetslang STDVAR
  91. {
  92. Context;
  93. slang_free(coreslangs);
  94. coreslangs = NULL;
  95. return TCL_OK;
  96. }
  97. static int tcl_getslang STDVAR
  98. {
  99. Context;
  100. BADARGS(2, 2, " ID");
  101. Tcl_AppendResult(irp, getslang(atoi(argv[1])), NULL);
  102. return TCL_OK;
  103. }
  104. static int tcl_nick2suser STDVAR
  105. {
  106. struct stats_member *m;
  107. Context;
  108. BADARGS(3, 3, " nick channel");
  109. m = getschanmember(argv[1], argv[2]);
  110. if (m && m->user)
  111. Tcl_AppendResult(irp, m->user->user, NULL);
  112. else
  113. Tcl_AppendResult(irp, "*", NULL);
  114. return TCL_OK;
  115. }
  116. static int tcl_findsuser STDVAR
  117. {
  118. struct stats_userlist *u;
  119. struct userrec *ou;
  120. Context;
  121. BADARGS(2, 2, " nick!user@host");
  122. ou = get_user_by_host(argv[1]);
  123. if (ou)
  124. Tcl_AppendResult(irp, ou->handle, NULL);
  125. else {
  126. u = findsuser(argv[1]);
  127. if (u)
  128. Tcl_AppendResult(irp, u->user, NULL);
  129. else
  130. Tcl_AppendResult(irp, "*", NULL);
  131. }
  132. return TCL_OK;
  133. }
  134. static int tcl_loadstatsskin STDVAR
  135. {
  136. // char *name, *file, *skin, *lang;
  137. Context;
  138. BADARGS(2, 2, " skinfile");
  139. if (!loadskin(argv[1])) {
  140. Tcl_AppendResult(irp, "Couldn't load skin!!!", NULL);
  141. return TCL_ERROR;
  142. } else {
  143. return TCL_OK;
  144. }
  145. }
  146. static int tcl_setchanslang STDVAR
  147. {
  148. Context;
  149. BADARGS(3, 3, " channel language");
  150. chanlangs = slang_chanlang_add(chanlangs, argv[1], argv[2]);
  151. return TCL_OK;
  152. }
  153. static int tcl_loadstatslang STDVAR
  154. {
  155. // int ret = 0;
  156. char *shortname, *longname, *filename;
  157. struct slang_header *slang;
  158. Context;
  159. BADARGS(4, 4, " language description langfile");
  160. shortname = argv[1];
  161. longname = argv[2];
  162. filename = argv[3];
  163. coreslangs = slang_create(coreslangs, shortname, longname);
  164. slang = slang_find(coreslangs, shortname);
  165. Assert(slang);
  166. if (!slang_load(slang, filename)) {
  167. Tcl_AppendResult(irp, "Couldn't open slang file!!!", NULL);
  168. return TCL_ERROR;
  169. }
  170. return TCL_OK;
  171. }
  172. static int tcl_schattr STDVAR
  173. {
  174. struct stats_userlist *u;
  175. int i;
  176. char s[30];
  177. BADARGS(3, 99, " user [+/-list] [+/-addhosts] ...");
  178. u = findsuser_by_name(argv[1]);
  179. if (!u) {
  180. Tcl_AppendResult(irp, "Unknown user.", NULL);
  181. return TCL_ERROR;
  182. }
  183. for (i = 2; i < argc; i++) {
  184. if (!user_changeflag(u, argv[i])) {
  185. snprintf(s, sizeof(s), "Unknown flag: %s", argv[i]);
  186. Tcl_AppendResult(irp, s, NULL);
  187. return TCL_ERROR;
  188. }
  189. }
  190. return TCL_OK;
  191. }
  192. static int tcl_activeusers STDVAR
  193. {
  194. globstats *gs;
  195. locstats *ls;
  196. BADARGS(1, 2, " [channel]");
  197. for (gs = sdata; gs; gs = gs->next)
  198. {
  199. if (argc == 2)
  200. if (!rfc_casecmp(argv[1], gs->chan))
  201. continue;
  202. for (ls = gs->local; ls; ls = ls->next)
  203. {
  204. if (ls->values[S_TOTAL][T_WORDS] < 1)
  205. continue;
  206. Tcl_AppendElement(irp, ls->user);
  207. }
  208. }
  209. return TCL_OK;
  210. }
  211. static tcl_cmds mytcls[] =
  212. {
  213. {"incrstats", tcl_incrstats},
  214. {"getstats", tcl_getstats},
  215. {"livestats", tcl_livestats},
  216. {"resetuser", tcl_resetuser},
  217. {"nick2suser", tcl_nick2suser},
  218. {"resetslang", tcl_resetslang},
  219. {"getslang", tcl_getslang},
  220. {"setchanslang", tcl_setchanslang},
  221. {"findsuser", tcl_findsuser},
  222. {"loadstatsskin", tcl_loadstatsskin},
  223. {"loadstatslang", tcl_loadstatslang},
  224. {"schattr", tcl_schattr},
  225. {"activeusers", tcl_activeusers},
  226. {0, 0}
  227. };