00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 static int tcl_isbotnick STDVAR
00026 {
00027 BADARGS(2, 2, " nick");
00028
00029 if (match_my_nick(argv[1]))
00030 Tcl_AppendResult(irp, "1", NULL);
00031 else
00032 Tcl_AppendResult(irp, "0", NULL);
00033 return TCL_OK;
00034 }
00035
00036 static int tcl_putnow STDVAR
00037 {
00038 int len;
00039 char buf[512], *p, *q, *r;
00040
00041 BADARGS(2, 3, " text ?options?");
00042
00043 if ((argc == 3) && egg_strcasecmp(argv[2], "-oneline")) {
00044 Tcl_AppendResult(irp, "unknown putnow option: should be ",
00045 "-oneline", NULL);
00046 return TCL_ERROR;
00047 }
00048 if (!serv)
00049 return TCL_OK;
00050
00051 for (p = r = argv[1], q = buf; ; p++) {
00052 if (*p && *p != '\r' && *p != '\n')
00053 continue;
00054 if (p == r) {
00055 if (*p) {
00056 r++;
00057 continue;
00058 } else
00059 break;
00060 }
00061 if ((p - r) > (sizeof(buf) - 2 - (q - buf)))
00062 break;
00063 len = p - r + 1;
00064 strncpyz(q, r, len);
00065 if (check_tcl_out(0, q, 0)) {
00066 if (!*p || ((argc == 3) && !egg_strcasecmp(argv[2], "-oneline")))
00067 break;
00068 r = p + 1;
00069 continue;
00070 }
00071 check_tcl_out(0, q, 1);
00072 if (q == buf)
00073 putlog(LOG_SRVOUT, "*", "[r->] %s", q);
00074 else
00075 putlog(LOG_SRVOUT, "*", "[+r->] %s", q);
00076 q += len - 1;
00077 *q++ = '\r';
00078 *q++ = '\n';
00079 if (!*p || ((argc == 3) && !egg_strcasecmp(argv[2], "-oneline")))
00080 break;
00081 r = p + 1;
00082 }
00083 tputs(serv, buf, q - buf);
00084 return TCL_OK;
00085 }
00086
00087 static int tcl_putquick STDVAR
00088 {
00089 char s[511], *p;
00090
00091 BADARGS(2, 3, " text ?options?");
00092
00093 if ((argc == 3) && egg_strcasecmp(argv[2], "-next") &&
00094 egg_strcasecmp(argv[2], "-normal")) {
00095 Tcl_AppendResult(irp, "unknown putquick option: should be one of: ",
00096 "-normal -next", NULL);
00097 return TCL_ERROR;
00098 }
00099 strncpy(s, argv[1], 510);
00100
00101 s[510] = 0;
00102 p = strchr(s, '\n');
00103 if (p != NULL)
00104 *p = 0;
00105 p = strchr(s, '\r');
00106 if (p != NULL)
00107 *p = 0;
00108 if (argc == 3 && !egg_strcasecmp(argv[2], "-next"))
00109 dprintf(DP_MODE_NEXT, "%s\n", s);
00110 else
00111 dprintf(DP_MODE, "%s\n", s);
00112 return TCL_OK;
00113 }
00114
00115 static int tcl_putserv STDVAR
00116 {
00117 char s[511], *p;
00118
00119 BADARGS(2, 3, " text ?options?");
00120
00121 if ((argc == 3) && egg_strcasecmp(argv[2], "-next") &&
00122 egg_strcasecmp(argv[2], "-normal")) {
00123 Tcl_AppendResult(irp, "unknown putserv option: should be one of: ",
00124 "-normal -next", NULL);
00125 return TCL_ERROR;
00126 }
00127 strncpy(s, argv[1], 510);
00128
00129 s[510] = 0;
00130 p = strchr(s, '\n');
00131 if (p != NULL)
00132 *p = 0;
00133 p = strchr(s, '\r');
00134 if (p != NULL)
00135 *p = 0;
00136 if (argc == 3 && !egg_strcasecmp(argv[2], "-next"))
00137 dprintf(DP_SERVER_NEXT, "%s\n", s);
00138 else
00139 dprintf(DP_SERVER, "%s\n", s);
00140 return TCL_OK;
00141 }
00142
00143 static int tcl_puthelp STDVAR
00144 {
00145 char s[511], *p;
00146
00147 BADARGS(2, 3, " text ?options?");
00148
00149 if ((argc == 3) && egg_strcasecmp(argv[2], "-next") &&
00150 egg_strcasecmp(argv[2], "-normal")) {
00151 Tcl_AppendResult(irp, "unknown puthelp option: should be one of: ",
00152 "-normal -next", NULL);
00153 return TCL_ERROR;
00154 }
00155 strncpy(s, argv[1], 510);
00156
00157 s[510] = 0;
00158 p = strchr(s, '\n');
00159 if (p != NULL)
00160 *p = 0;
00161 p = strchr(s, '\r');
00162 if (p != NULL)
00163 *p = 0;
00164 if (argc == 3 && !egg_strcasecmp(argv[2], "-next"))
00165 dprintf(DP_HELP_NEXT, "%s\n", s);
00166 else
00167 dprintf(DP_HELP, "%s\n", s);
00168 return TCL_OK;
00169 }
00170
00171 static int tcl_jump STDVAR
00172 {
00173 BADARGS(1, 4, " ?server? ?port? ?pass?");
00174
00175 if (argc >= 2) {
00176 strncpyz(newserver, argv[1], sizeof newserver);
00177 if (argc >= 3)
00178 newserverport = atoi(argv[2]);
00179 else
00180 newserverport = default_port;
00181 if (argc == 4)
00182 strncpyz(newserverpass, argv[3], sizeof newserverpass);
00183 }
00184 cycle_time = 0;
00185
00186 nuke_server("changing servers\n");
00187 return TCL_OK;
00188 }
00189
00190 static int tcl_clearqueue STDVAR
00191 {
00192 struct msgq *q, *qq;
00193 int msgs = 0;
00194 char s[20];
00195
00196 BADARGS(2, 2, " queue");
00197
00198 if (!strcmp(argv[1], "all")) {
00199 msgs = (int) (modeq.tot + mq.tot + hq.tot);
00200 for (q = modeq.head; q; q = qq) {
00201 qq = q->next;
00202 nfree(q->msg);
00203 nfree(q);
00204 }
00205 for (q = mq.head; q; q = qq) {
00206 qq = q->next;
00207 nfree(q->msg);
00208 nfree(q);
00209 }
00210 for (q = hq.head; q; q = qq) {
00211 qq = q->next;
00212 nfree(q->msg);
00213 nfree(q);
00214 }
00215 modeq.tot = mq.tot = hq.tot = modeq.warned = mq.warned = hq.warned = 0;
00216 mq.head = hq.head = modeq.head = mq.last = hq.last = modeq.last = 0;
00217 double_warned = 0;
00218 burst = 0;
00219 simple_sprintf(s, "%d", msgs);
00220 Tcl_AppendResult(irp, s, NULL);
00221 return TCL_OK;
00222 } else if (!strncmp(argv[1], "serv", 4)) {
00223 msgs = mq.tot;
00224 for (q = mq.head; q; q = qq) {
00225 qq = q->next;
00226 nfree(q->msg);
00227 nfree(q);
00228 }
00229 mq.tot = mq.warned = 0;
00230 mq.head = mq.last = 0;
00231 if (modeq.tot == 0)
00232 burst = 0;
00233 double_warned = 0;
00234 mq.tot = mq.warned = 0;
00235 mq.head = mq.last = 0;
00236 simple_sprintf(s, "%d", msgs);
00237 Tcl_AppendResult(irp, s, NULL);
00238 return TCL_OK;
00239 } else if (!strcmp(argv[1], "mode")) {
00240 msgs = modeq.tot;
00241 for (q = modeq.head; q; q = qq) {
00242 qq = q->next;
00243 nfree(q->msg);
00244 nfree(q);
00245 }
00246 if (mq.tot == 0)
00247 burst = 0;
00248 double_warned = 0;
00249 modeq.tot = modeq.warned = 0;
00250 modeq.head = modeq.last = 0;
00251 simple_sprintf(s, "%d", msgs);
00252 Tcl_AppendResult(irp, s, NULL);
00253 return TCL_OK;
00254 } else if (!strcmp(argv[1], "help")) {
00255 msgs = hq.tot;
00256 for (q = hq.head; q; q = qq) {
00257 qq = q->next;
00258 nfree(q->msg);
00259 nfree(q);
00260 }
00261 double_warned = 0;
00262 hq.tot = hq.warned = 0;
00263 hq.head = hq.last = 0;
00264 simple_sprintf(s, "%d", msgs);
00265 Tcl_AppendResult(irp, s, NULL);
00266 return TCL_OK;
00267 }
00268 Tcl_AppendResult(irp, "bad option \"", argv[1],
00269 "\": must be mode, server, help, or all", NULL);
00270 return TCL_ERROR;
00271 }
00272
00273 static int tcl_queuesize STDVAR
00274 {
00275 char s[20];
00276 int x;
00277
00278 BADARGS(1, 2, " ?queue?");
00279
00280 if (argc == 1) {
00281 x = (int) (modeq.tot + hq.tot + mq.tot);
00282 simple_sprintf(s, "%d", x);
00283 Tcl_AppendResult(irp, s, NULL);
00284 return TCL_OK;
00285 } else if (!strncmp(argv[1], "serv", 4)) {
00286 x = (int) (mq.tot);
00287 simple_sprintf(s, "%d", x);
00288 Tcl_AppendResult(irp, s, NULL);
00289 return TCL_OK;
00290 } else if (!strcmp(argv[1], "mode")) {
00291 x = (int) (modeq.tot);
00292 simple_sprintf(s, "%d", x);
00293 Tcl_AppendResult(irp, s, NULL);
00294 return TCL_OK;
00295 } else if (!strcmp(argv[1], "help")) {
00296 x = (int) (hq.tot);
00297 simple_sprintf(s, "%d", x);
00298 Tcl_AppendResult(irp, s, NULL);
00299 return TCL_OK;
00300 }
00301
00302 Tcl_AppendResult(irp, "bad option \"", argv[1],
00303 "\": must be mode, server, or help", NULL);
00304 return TCL_ERROR;
00305 }
00306
00307 static tcl_cmds my_tcl_cmds[] = {
00308 {"jump", tcl_jump},
00309 {"isbotnick", tcl_isbotnick},
00310 {"clearqueue", tcl_clearqueue},
00311 {"queuesize", tcl_queuesize},
00312 {"puthelp", tcl_puthelp},
00313 {"putserv", tcl_putserv},
00314 {"putquick", tcl_putquick},
00315 {"putnow", tcl_putnow},
00316 {NULL, NULL}
00317 };