tclstats.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_listen_livestats();
  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_listen_livestats(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_loadslang STDVAR
  91. {
  92. int ret;
  93. Context;
  94. BADARGS(2, 3, " [lang] slangfile");
  95. if (argc == 3)
  96. ret = loadslang(argv[1], argv[2]);
  97. else
  98. ret = loadslang(NULL, argv[1]);
  99. if (!ret) {
  100. Tcl_AppendResult(irp, "Couldn't open slang file!!!", NULL);
  101. return TCL_ERROR;
  102. }
  103. return TCL_OK;
  104. }
  105. static int tcl_resetslang STDVAR
  106. {
  107. Context;
  108. free_slang();
  109. slangs = NULL;
  110. slangchans = NULL;
  111. return TCL_OK;
  112. }
  113. static int tcl_getslang STDVAR
  114. {
  115. Context;
  116. BADARGS(2, 2, " ID");
  117. Tcl_AppendResult(irp, getslang(atoi(argv[1])), NULL);
  118. return TCL_OK;
  119. }
  120. static int tcl_nick2suser STDVAR
  121. {
  122. struct stats_memberlist *m;
  123. Context;
  124. BADARGS(3, 3, " nick channel");
  125. m = nick2suser(argv[1], argv[2]);
  126. if (m && m->user)
  127. Tcl_AppendResult(irp, m->user->user, NULL);
  128. else
  129. Tcl_AppendResult(irp, "*", NULL);
  130. return TCL_OK;
  131. }
  132. static int tcl_setchanslang STDVAR
  133. {
  134. Context;
  135. BADARGS(3, 3, " channel language");
  136. setchanlang(argv[1], argv[2]);
  137. return TCL_OK;
  138. }
  139. static int tcl_findsuser STDVAR
  140. {
  141. struct stats_userlist *u;
  142. struct userrec *ou;
  143. Context;
  144. BADARGS(2, 2, " nick!user@host");
  145. ou = get_user_by_host(argv[1]);
  146. if (ou)
  147. Tcl_AppendResult(irp, ou->handle, NULL);
  148. else {
  149. u = findsuser(argv[1]);
  150. if (u)
  151. Tcl_AppendResult(irp, u->user, NULL);
  152. else
  153. Tcl_AppendResult(irp, "*", NULL);
  154. }
  155. return TCL_OK;
  156. }
  157. static tcl_cmds mytcls[] =
  158. {
  159. {"incrstats", tcl_incrstats},
  160. {"getstats", tcl_getstats},
  161. {"livestats", tcl_livestats},
  162. {"resetuser", tcl_resetuser},
  163. {"nick2suser", tcl_nick2suser},
  164. {"loadslang", tcl_loadslang},
  165. {"resetslang", tcl_resetslang},
  166. {"getslang", tcl_getslang},
  167. {"setchanslang", tcl_setchanslang},
  168. {"findsuser", tcl_findsuser},
  169. {0, 0}
  170. };