- *p = 0;
- for(++p; *p == ' '; p++);
- cmd = p;
- usr = &msg[1];
- if((p = strchr(msg, '!')))
- *p = 0;
- } else
- cmd = msg;
- /* remove CRLFs */
- for(p = cmd; p && *p != 0; p++)
- if(*p == '\r' || *p == '\n')
- *p = 0;
- if(!strncmp("PONG", cmd, 4))
- return;
- if(!strncmp("PRIVMSG", cmd, 7) || !strncmp("PING", cmd, 4)) {
- if(!(p = strchr(cmd, ' ')))
- return;
- *p = 0;
- chan = ++p;
- for(; *p && *p != ' '; p++);
- *p = 0;
- if(!(p = strchr(++p, ':')))
- return;
- *p = 0;
- txt = ++p;
- if(!strncmp("PRIVMSG", cmd, 8) && chan && txt) {
- snprintf(bufout, sizeof bufout, "<%s> %s", usr, txt);
- pout(chan, bufout);
- }
- else if(!strncmp("PING", cmd, 5) && txt) {
- snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt);
- write(srv, bufout, strlen(bufout));
- }