some changes

This commit is contained in:
Anselm R. Garbe 2007-02-09 14:40:11 +01:00
parent a3abf3b3ef
commit 1edd94af86

50
sic.c
View File

@ -102,45 +102,43 @@ parsesrv(char *msg) {
if(!msg || !(*msg)) if(!msg || !(*msg))
return; return;
pout("debug", msg); pout("debug", msg);
if(msg[0] == ':') { /* check prefix */ if(msg[0] != ':')
if(!(p = strchr(msg, ' '))) return; /* don't handle prefix-less server commands */
return; if(!(p = strchr(msg, ' ')))
return;
usr = &msg[1];
*p = 0;
cmd = ++p;
if((p = strchr(usr, '!')))
*p = 0; *p = 0;
usr = &msg[1];
cmd = ++p;
if((p = strchr(usr, '!')))
*p = 0;
} else
cmd = msg;
/* remove CRLFs */ /* remove CRLFs */
for(p = cmd; *p; p++) if(!(p = strchr(cmd, ':')))
return;
*p = 0;
txt = ++p;
for(p = txt; *p; p++)
if(*p == '\r' || *p == '\n') if(*p == '\r' || *p == '\n')
*p = 0; *p = 0;
if(!strncmp("PONG", cmd, 4)) if(!strncmp("PONG", cmd, 4))
return; return;
if(!strncmp("PRIVMSG", cmd, 7) || !strncmp("PING", cmd, 4)) { if(!strncmp("PRIVMSG", cmd, 7)) {
if(!(p = strchr(cmd, ' '))) if(!(p = strchr(cmd, ' ')))
return; return;
*p = 0; *p = 0;
chan = ++p; chan = ++p;
for(; *p && *p != ' '; p++); for(; *p && *p != ' '; p++);
*p = 0; *p = 0;
if(!(p = strchr(++p, ':'))) snprintf(bufout, sizeof bufout, "<%s> %s", usr, txt);
return; pout(chan, bufout);
*p = 0; }
txt = ++p; else if(!strncmp("PING", cmd, 4) && txt) {
if(!strncmp("PRIVMSG", cmd, 8) && chan && txt) { snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt);
snprintf(bufout, sizeof bufout, "<%s> %s", usr, txt); write(srv, bufout, strlen(bufout));
pout(chan, bufout); }
} else {
else if(!strncmp("PING", cmd, 5) && txt) { snprintf(bufout, sizeof bufout, "-!- %s", cmd);
snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt); pout(usr, bufout);
write(srv, bufout, strlen(bufout));
}
return;
} }
snprintf(bufout, sizeof bufout, "-!- %s", cmd);
pout(host, bufout);
} }
int int