comparison nnchat.c @ 297:d34910f1b1e1

Print messages about user leaving or joining the chat in the specific buffer, too. Also, disable unhandled key warnings unless debug mode has been enabled.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 11 Jun 2011 03:56:01 +0300
parents ff39ebf05b40
children 0119bcc15f15
comparison
equal deleted inserted replaced
296:786205414e34 297:d34910f1b1e1
691 691
692 692
693 int handleAddUser(nn_conn_t *conn, const char *str) 693 int handleAddUser(nn_conn_t *conn, const char *str)
694 { 694 {
695 char *p, *s = strstr(str, "</ADD_USER>"); 695 char *p, *s = strstr(str, "</ADD_USER>");
696 nn_window_t *win;
696 697
697 (void) conn; 698 (void) conn;
698 699
699 if (!s) return 1; 700 if (!s) return 1;
700 *s = 0; 701 *s = 0;
701 702
702 p = nn_dbldecode_str(str); 703 p = nn_dbldecode_str(str);
703 if (!p) return -1; 704 if (!p) return -1;
704 705
706 win = nn_find_window(p);
705 nn_userhash_insert(nnUsers, nn_username_encode(p)); 707 nn_userhash_insert(nnUsers, nn_username_encode(p));
706 708
707 printMsg(NULL, "! ½3½%s½0½ ½2½ADDED.½0½\n", p); 709 printMsg(NULL, "! ½3½%s½0½ ½2½ADDED.½0½\n", p);
710 if (win != NULL)
711 printMsg(win, "! ½3½%s½0½ ½2½joined the chat.½0½\n", p);
712
708 th_free(p); 713 th_free(p);
709 return 0; 714 return 0;
710 } 715 }
711 716
712 717
713 int handleDeleteUser(nn_conn_t *conn, const char *str) 718 int handleDeleteUser(nn_conn_t *conn, const char *str)
714 { 719 {
715 char *p, *s = strstr(str, "</DELETE_USER>"); 720 char *p, *s = strstr(str, "</DELETE_USER>");
721 nn_window_t *win;
716 722
717 (void) conn; 723 (void) conn;
718 724
719 if (!s) return 1; 725 if (!s) return 1;
720 *s = 0; 726 *s = 0;
721 727
722 p = nn_dbldecode_str(str); 728 p = nn_dbldecode_str(str);
723 if (!p) return -1; 729 if (!p) return -1;
724 730
731 win = nn_find_window(p);
725 nn_userhash_delete(nnUsers, nn_username_encode(p)); 732 nn_userhash_delete(nnUsers, nn_username_encode(p));
726 733
727 printMsg(NULL, "! ½3½%s½0½ ½1½DELETED.½0½\n", p); 734 printMsg(NULL, "! ½3½%s½0½ ½1½DELETED.½0½\n", p);
735 if (win != NULL)
736 printMsg(win, "! ½3½%s½0½ ½1½left the chat.½0½\n", p);
737
728 th_free(p); 738 th_free(p);
729 return 0; 739 return 0;
730 } 740 }
731 741
732 742
1495 c = wgetch(stdscr); 1505 c = wgetch(stdscr);
1496 switch (c) { 1506 switch (c) {
1497 case 'd': c = 0x204; break; 1507 case 'd': c = 0x204; break;
1498 case 'c': c = 0x206; break; 1508 case 'c': c = 0x206; break;
1499 default: 1509 default:
1500 printMsg(currWin, "Unhandled ESC-O key sequence 0x%02x\n", c); 1510 if (optDebug)
1511 printMsg(currWin, "Unhandled ESC-O key sequence 0x%02x\n", c);
1501 break; 1512 break;
1502 } 1513 }
1503 } else 1514 } else
1504 if (c == '[') { 1515 if (c == '[') {
1505 c = wgetch(stdscr); 1516 c = wgetch(stdscr);
1520 1531
1521 case 0x37: c = KEY_HOME; break; 1532 case 0x37: c = KEY_HOME; break;
1522 case 0x38: c = KEY_END; break; 1533 case 0x38: c = KEY_END; break;
1523 1534
1524 default: 1535 default:
1525 printMsg(currWin, "Unhandled ESC-[*~ key sequence 0x%02x\n", c); 1536 if (optDebug)
1537 printMsg(currWin, "Unhandled ESC-[*~ key sequence 0x%02x\n", c);
1526 c = ERR; 1538 c = ERR;
1527 break; 1539 break;
1528 } 1540 }
1529 /* Get the trailing ~ */ 1541 /* Get the trailing ~ */
1530 if (c != ERR) 1542 if (c != ERR)
1538 update = updateMain = TRUE; 1550 update = updateMain = TRUE;
1539 } 1551 }
1540 c = ERR; 1552 c = ERR;
1541 } 1553 }
1542 else { 1554 else {
1543 printMsg(currWin, "Unhandled ESC key sequence 0x%02x\n", c); 1555 if (optDebug)
1556 printMsg(currWin, "Unhandled ESC key sequence 0x%02x\n", c);
1544 continue; 1557 continue;
1545 } 1558 }
1546 } 1559 }
1547 1560
1548 1561