Format WHOIS replies properly (311/312/317/319/320/318)

This commit is contained in:
2026-04-30 08:54:45 +02:00
parent 58a058a783
commit a9e7f144bc
+60
View File
@@ -721,6 +721,66 @@ static void handle_line(char *line)
}
}
}
} else if (strcmp(cmd, "311") == 0 && params) {
/* RPL_WHOISUSER: <me> <nick> <user> <host> * :<realname> */
char *p = params;
char *sp = strchr(p, ' '); if (sp) p = sp + 1; /* skip our nick */
char *wnick = p;
sp = strchr(p, ' '); if (sp) { *sp = '\0'; p = sp + 1; }
char *wuser = p;
sp = strchr(p, ' '); if (sp) { *sp = '\0'; p = sp + 1; }
char *whost = p;
sp = strchr(p, ' '); if (sp) { *sp = '\0'; p = sp + 1; }
/* skip the * */
sp = strchr(p, ':'); char *real = sp ? sp + 1 : p;
wprintf(WL_STATUS, "*** %s is %s@%s (%s)\n", wnick, wuser, whost, real);
} else if (strcmp(cmd, "319") == 0 && params) {
/* RPL_WHOISCHANNELS: <me> <nick> :<channels> */
char *p = params;
char *sp = strchr(p, ' '); if (sp) p = sp + 1;
char *wnick = p;
sp = strchr(p, ' '); if (sp) *sp = '\0';
char *chans = strchr(params, ':');
if (chans) chans++;
wprintf(WL_STATUS, "*** %s on channels: %s\n", wnick, chans ? chans : "");
} else if (strcmp(cmd, "312") == 0 && params) {
/* RPL_WHOISSERVER: <me> <nick> <server> :<info> */
char *p = params;
char *sp = strchr(p, ' '); if (sp) p = sp + 1;
char *wnick = p;
sp = strchr(p, ' '); if (sp) { *sp = '\0'; p = sp + 1; }
char *server = p;
sp = strchr(p, ' '); if (sp) *sp = '\0';
char *info = strchr(params, ':');
if (info) info++;
wprintf(WL_STATUS, "*** %s on irc via server %s (%s)\n",
wnick, server, info ? info : "");
} else if (strcmp(cmd, "317") == 0 && params) {
/* RPL_WHOISIDLE: <me> <nick> <idle> <signon> :<text> */
char *p = params;
char *sp = strchr(p, ' '); if (sp) p = sp + 1;
char *wnick = p;
sp = strchr(p, ' '); if (sp) { *sp = '\0'; p = sp + 1; }
int idle_secs = atoi(p);
int mins = idle_secs / 60;
int secs = idle_secs % 60;
if (mins > 0)
wprintf(WL_STATUS, "*** %s has been idle %d min %d sec\n",
wnick, mins, secs);
else
wprintf(WL_STATUS, "*** %s has been idle %d sec\n", wnick, secs);
} else if (strcmp(cmd, "320") == 0 && params) {
/* RPL_WHOISSPECIAL: <me> <nick> :<text> */
char *p = params;
char *sp = strchr(p, ' '); if (sp) p = sp + 1;
char *wnick = p;
sp = strchr(p, ' '); if (sp) *sp = '\0';
char *text = strchr(params, ':');
if (text) text++;
wprintf(WL_STATUS, "*** %s %s\n", wnick, text ? text : "");
} else if (strcmp(cmd, "318") == 0 && params) {
/* RPL_ENDOFWHOIS — suppress or show subtle */
wprintf(WL_STATUS, "*** End of WHOIS\n");
} else if (strcmp(cmd, "332") == 0 && params) {
/* RPL_TOPIC: <nick> <channel> :<topic> */
char *p = params;