- } else if(!argv[Tnick] || !argv[Tuser]) { /* server command */
- snprintf(bufout, sizeof(bufout), "%s", argv[Ttext] ? argv[Ttext] : "");
- pout(server, bufout);
- return;
- } else if(!strncmp("ERROR", argv[Tcmd], 6))
- snprintf(bufout, sizeof(bufout), "-!- error %s",
- argv[Ttext] ? argv[Ttext] : "unknown");
- else if(!strncmp("JOIN", argv[Tcmd], 5)) {
- if(argv[Ttext]!=NULL){
- p = strchr(argv[Ttext], ' ');
- if(p)
- *p = 0;
- }
- argv[Tchan] = argv[Ttext];
- snprintf(bufout, sizeof(bufout), "-!- %s(%s) has joined %s",
- argv[Tnick], argv[Tuser], argv[Ttext]);
- } else if(!strncmp("PART", argv[Tcmd], 5)) {
- snprintf(bufout, sizeof(bufout), "-!- %s(%s) has left %s",
- argv[Tnick], argv[Tuser], argv[Tchan]);
- } else if(!strncmp("MODE", argv[Tcmd], 5))
- snprintf(bufout, sizeof(bufout), "-!- %s changed mode/%s -> %s %s",
- argv[Tnick], argv[Tcmd + 1],
- argv[Tcmd + 2], argv[Tcmd + 3]);
- else if(!strncmp("QUIT", argv[Tcmd], 5))
- snprintf(bufout, sizeof(bufout), "-!- %s(%s) has quit \"%s\"",
- argv[Tnick], argv[Tuser],
- argv[Ttext] ? argv[Ttext] : "");
- else if(!strncmp("NICK", argv[Tcmd], 5))
- snprintf(bufout, sizeof(bufout), "-!- %s changed nick to %s",
- argv[Tnick], argv[Ttext]);
- else if(!strncmp("TOPIC", argv[Tcmd], 6))
- snprintf(bufout, sizeof(bufout), "-!- %s changed topic to \"%s\"",
- argv[Tnick], argv[Ttext] ? argv[Ttext] : "");
- else if(!strncmp("KICK", argv[Tcmd], 5))
- snprintf(bufout, sizeof(bufout), "-!- %s kicked %s (\"%s\")",
- argv[Tnick], argv[Targ],
- argv[Ttext] ? argv[Ttext] : "");
- else if(!strncmp("NOTICE", argv[Tcmd], 7))
- snprintf(bufout, sizeof(bufout), "-!- \"%s\")",
- argv[Ttext] ? argv[Ttext] : "");
- else if(!strncmp("PRIVMSG", argv[Tcmd], 8)) snprintf(bufout, sizeof(bufout), "<%s> %s",
- argv[Tnick], argv[Ttext] ? argv[Ttext] : "");
- if(!argv[Tchan] || !strncmp(argv[Tchan], nick, strlen(nick)))
- pout(argv[Tnick], bufout);
- else
- pout(argv[Tchan], bufout);
+ if(strncmp("PRIVMSG", cmd, 7) == 0 && txt != NULL) {
+ if(!(p = strchr(cmd, ' ')))
+ return;
+ *p = '\0';
+ chan = ++p;
+ for(; *p != '\0' && *p != ' '; p++);
+ *p = '\0';
+ (void) snprintf(bufout, sizeof bufout, "<%s> %s", usr, txt);
+ printl(chan, bufout);
+ }
+ else if(strncmp("PING", cmd, 4) == 0 && txt != NULL) {
+ (void) snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt);
+ (void) write(srv, bufout, strlen(bufout));
+ }
+ else {
+ if (txt != NULL)
+ (void) snprintf(bufout, sizeof bufout, ">< %s: %s", cmd, txt);
+ else
+ (void) snprintf(bufout, sizeof bufout, ">< %s: ", cmd);
+ printl(usr, bufout);
+ if(strncmp("NICK", cmd, 4) == 0 && strncmp(usr, nick, sizeof nick) == 0 &&
+ txt != NULL)
+ (void) strncpy(nick, txt, sizeof nick);
+ }