Mercurial > hg > nnchat
changeset 229:08d4355d6fc9
Repair automatic PRV target setting.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 20 Feb 2011 20:45:23 +0200 |
parents | 744c277b57cf |
children | b64500bb7fbe |
files | nnchat.c |
diffstat | 1 files changed, 24 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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 = "</USER><MESSAGE>", *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, "</MESSAGE>"); - if (!q) return 3; - *q = 0; - + /* Find end of the message */ + t = strstr(s, "</MESSAGE>"); + 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;