# HG changeset patch # User Matti Hamalainen # Date 1298227523 -7200 # Node ID 08d4355d6fc98f4f4dd648994d4ea9a32a8eb551 # Parent 744c277b57cfcfef4d15ec03e65ad5a967c5e35e Repair automatic PRV target setting. diff -r 744c277b57cf -r 08d4355d6fc9 nnchat.c --- a/nnchat.c Sun Feb 20 20:44:09 2011 +0200 +++ b/nnchat.c Sun Feb 20 20:45:23 2011 +0200 @@ -422,53 +422,66 @@ int handleUser(nn_conn_t *conn, const char *str) { const char *msg = "", *p = str; - BOOL isMine, isIgnored = FALSE;; - char *q, *s, *t, *h, *userName; + BOOL isMine, isIgnored = FALSE; + char *s, *t, *h, *userName; (void) conn; + /* Find start of the message */ s = strstr(str, msg); if (!s) return 1; *s = 0; s += strlen(msg); - q = strstr(s, ""); - if (!q) return 3; - *q = 0; - + /* Find end of the message */ + t = strstr(s, ""); + if (!t) return 3; + *t = 0; + + /* Decode message string */ s = nn_decode_str1(s); if (!s) return -1; - + + /* Decode username */ userName = nn_decode_str1(p); if (!userName) { th_free(s); return -2; } - + + /* Check if the username is on our ignore list and + * that it is not our OWN username! + */ isMine = strcmp(userName, optUserName) == 0; if (setIgnoreMode && !isMine) isIgnored = checkIgnoreList(userName); + /* Is it a special control message? */ if (*s == '/') { /* Ignore room join/leave messages */ if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) - goto error; + goto done; t = nn_strip_tags(s + 1); if (!strncmp(t, "BPRV", 4)) { h = nn_decode_str2(t + 1); if (!isIgnored && setTarget == NULL && !strncmp(h, "PRV from ", 9)) { - setTarget = th_strdup(userName); + char *q; + setTarget = th_strdup(h + 9); + for (q = setTarget; *q && *q != ':'; q++); + *q = 0; printMsg("PRV target autoset to '%s'\n", setTarget); } printMsgQ(isIgnored, "½11½%s½0½\n", h); } else { + /* It's an action (/me) */ h = nn_decode_str2(t); printMsgQ(isIgnored, "½9½* %s½0½\n", h); } th_free(h); th_free(t); } else { + /* It's a normal message */ t = nn_strip_tags(s); h = nn_decode_str2(t); printMsgQ(isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h); @@ -476,7 +489,7 @@ th_free(t); } -error: +done: th_free(s); th_free(userName); return 0;