Mercurial > hg > nnchat
comparison nnchat.c @ 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 |
comparison
equal
deleted
inserted
replaced
228:744c277b57cf | 229:08d4355d6fc9 |
---|---|
420 | 420 |
421 | 421 |
422 int handleUser(nn_conn_t *conn, const char *str) | 422 int handleUser(nn_conn_t *conn, const char *str) |
423 { | 423 { |
424 const char *msg = "</USER><MESSAGE>", *p = str; | 424 const char *msg = "</USER><MESSAGE>", *p = str; |
425 BOOL isMine, isIgnored = FALSE;; | 425 BOOL isMine, isIgnored = FALSE; |
426 char *q, *s, *t, *h, *userName; | 426 char *s, *t, *h, *userName; |
427 | 427 |
428 (void) conn; | 428 (void) conn; |
429 | 429 |
430 /* Find start of the message */ | |
430 s = strstr(str, msg); | 431 s = strstr(str, msg); |
431 if (!s) return 1; | 432 if (!s) return 1; |
432 *s = 0; | 433 *s = 0; |
433 s += strlen(msg); | 434 s += strlen(msg); |
434 | 435 |
435 q = strstr(s, "</MESSAGE>"); | 436 /* Find end of the message */ |
436 if (!q) return 3; | 437 t = strstr(s, "</MESSAGE>"); |
437 *q = 0; | 438 if (!t) return 3; |
438 | 439 *t = 0; |
440 | |
441 /* Decode message string */ | |
439 s = nn_decode_str1(s); | 442 s = nn_decode_str1(s); |
440 if (!s) return -1; | 443 if (!s) return -1; |
441 | 444 |
445 /* Decode username */ | |
442 userName = nn_decode_str1(p); | 446 userName = nn_decode_str1(p); |
443 if (!userName) { | 447 if (!userName) { |
444 th_free(s); | 448 th_free(s); |
445 return -2; | 449 return -2; |
446 } | 450 } |
447 | 451 |
452 /* Check if the username is on our ignore list and | |
453 * that it is not our OWN username! | |
454 */ | |
448 isMine = strcmp(userName, optUserName) == 0; | 455 isMine = strcmp(userName, optUserName) == 0; |
449 if (setIgnoreMode && !isMine) | 456 if (setIgnoreMode && !isMine) |
450 isIgnored = checkIgnoreList(userName); | 457 isIgnored = checkIgnoreList(userName); |
451 | 458 |
459 /* Is it a special control message? */ | |
452 if (*s == '/') { | 460 if (*s == '/') { |
453 /* Ignore room join/leave messages */ | 461 /* Ignore room join/leave messages */ |
454 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) | 462 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) |
455 goto error; | 463 goto done; |
456 | 464 |
457 t = nn_strip_tags(s + 1); | 465 t = nn_strip_tags(s + 1); |
458 if (!strncmp(t, "BPRV", 4)) { | 466 if (!strncmp(t, "BPRV", 4)) { |
459 h = nn_decode_str2(t + 1); | 467 h = nn_decode_str2(t + 1); |
460 if (!isIgnored && setTarget == NULL && !strncmp(h, "PRV from ", 9)) { | 468 if (!isIgnored && setTarget == NULL && !strncmp(h, "PRV from ", 9)) { |
461 setTarget = th_strdup(userName); | 469 char *q; |
470 setTarget = th_strdup(h + 9); | |
471 for (q = setTarget; *q && *q != ':'; q++); | |
472 *q = 0; | |
462 printMsg("PRV target autoset to '%s'\n", setTarget); | 473 printMsg("PRV target autoset to '%s'\n", setTarget); |
463 } | 474 } |
464 printMsgQ(isIgnored, "½11½%s½0½\n", h); | 475 printMsgQ(isIgnored, "½11½%s½0½\n", h); |
465 } else { | 476 } else { |
477 /* It's an action (/me) */ | |
466 h = nn_decode_str2(t); | 478 h = nn_decode_str2(t); |
467 printMsgQ(isIgnored, "½9½* %s½0½\n", h); | 479 printMsgQ(isIgnored, "½9½* %s½0½\n", h); |
468 } | 480 } |
469 th_free(h); | 481 th_free(h); |
470 th_free(t); | 482 th_free(t); |
471 } else { | 483 } else { |
484 /* It's a normal message */ | |
472 t = nn_strip_tags(s); | 485 t = nn_strip_tags(s); |
473 h = nn_decode_str2(t); | 486 h = nn_decode_str2(t); |
474 printMsgQ(isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h); | 487 printMsgQ(isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h); |
475 th_free(h); | 488 th_free(h); |
476 th_free(t); | 489 th_free(t); |
477 } | 490 } |
478 | 491 |
479 error: | 492 done: |
480 th_free(s); | 493 th_free(s); |
481 th_free(userName); | 494 th_free(userName); |
482 return 0; | 495 return 0; |
483 } | 496 } |
484 | 497 |