comparison nnchat.c @ 109:1323a7f88c21

Fix /w -command and add some comments.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 23 Oct 2010 02:55:45 +0300
parents f323b137ca08
children 8af4072dc31a
comparison
equal deleted inserted replaced
108:f323b137ca08 109:1323a7f88c21
550 /* Trim right */ 550 /* Trim right */
551 buf[--bufLen] = 0; 551 buf[--bufLen] = 0;
552 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) 552 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen])))
553 buf[bufLen--] = 0; 553 buf[bufLen--] = 0;
554 554
555 /* Check command */ 555 /* Check for special user commands */
556 if (*buf == 0) { 556 if (*buf == 0) {
557 return 1; 557 return 1;
558 } else if (!strncmp(buf, "/color ", 7)) { 558 } else if (!strncmp(buf, "/color ", 7)) {
559 /* Change color */
559 int tmpInt; 560 int tmpInt;
560 if ((tmpInt = getColor(buf+7)) < 0) { 561 if ((tmpInt = getColor(buf+7)) < 0) {
561 printMsg("Invalid color value '%s'\n", buf+7); 562 printMsg("Invalid color value '%s'\n", buf+7);
562 return 1; 563 return 1;
563 } 564 }
564 optUserColor = tmpInt; 565 optUserColor = tmpInt;
565 printMsg("Setting color to #%06x\n", optUserColor); 566 printMsg("Setting color to #%06x\n", optUserColor);
566 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); 567 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
567 return 0; 568 return 0;
568 } else if (!strncmp(buf, "/w ", 3)) { 569 } else if (!strncmp(buf, "/w ", 3)) {
570 /* Open given username's profile via firefox in a new tab */
569 char *name = buf + 3; 571 char *name = buf + 3;
570 pid_t pud; 572 pid_t pud;
571 tmpStr = nn_encode_str1(name); 573 tmpStr = nn_encode_str1(name);
572 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr); 574 snprintf(tmpBuf, sizeof(tmpBuf), "firefox -remote \"openurl(http://www.newbienudes.com/profile/%s/,new-tab)\"", tmpStr);
573 th_free(tmpStr); 575 th_free(tmpStr);
574 576
575 printMsg("Opening profile for: %s\n", name); 577 printMsg("Opening profile for: %s\n", name);
576 printMsg("%s\n", tmpBuf); 578 printMsg("%s\n", tmpBuf);
577 /* 579 system(tmpBuf);
578 if ((pud = fork()) < 0) return 0; 580 return 0;
579 if (getpid() == pud) {
580 execlp("firefox", "-remote", tmpBuf, (char *) NULL);
581 exit(0);
582 } else
583 */
584 return 0;
585 } else if (!strncmp(buf, "/to ", 4)) { 581 } else if (!strncmp(buf, "/to ", 4)) {
582 /* Set private messaging target */
586 th_free(setTarget); 583 th_free(setTarget);
587 setTarget = th_strdup(buf + 4); 584 setTarget = th_strdup(buf + 4);
588 printMsg("Set prv target to '%s'\n", setTarget); 585 printMsg("Set prv target to '%s'\n", setTarget);
589 return 0; 586 return 0;
590 } else if (!strncmp(buf, "/who", 4)) { 587 } else if (!strncmp(buf, "/who", 4)) {
588 /* Alias /who to /listallusers */
591 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers"); 589 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers");
592 buf = tmpBuf; 590 buf = tmpBuf;
593 } else if (setPrvMode) { 591 } else if (setPrvMode) {
592 /* Private chat mode, send as PRV */
594 if (setTarget != NULL) { 593 if (setTarget != NULL) {
595 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf); 594 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf);
596 buf = tmpBuf; 595 buf = tmpBuf;
597 } else { 596 } else {
598 printMsg("No target set, exiting prv mode.\n"); 597 printMsg("No target set, exiting prv mode.\n");
599 setPrvMode = FALSE; 598 setPrvMode = FALSE;
600 return 1; 599 return 1;
601 } 600 }
602 } 601 }
603
604 602
605 /* Send double-encoded */ 603 /* Send double-encoded */
606 tmpStr = nn_dblencode_str(buf); 604 tmpStr = nn_dblencode_str(buf);
607 if (tmpStr == 0) return -2; 605 if (tmpStr == 0) return -2;
608 result = nn_send_msg(sock, optUserName2, "%s", tmpStr); 606 result = nn_send_msg(sock, optUserName2, "%s", tmpStr);