Mercurial > hg > nnchat
comparison nnchat.c @ 25:3b67a9a806a7
Added /color command to change colour.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 09 Jul 2008 17:47:40 +0300 |
parents | 78d260256450 |
children | b84fc46c6035 |
comparison
equal
deleted
inserted
replaced
24:78d260256450 | 25:3b67a9a806a7 |
---|---|
626 } | 626 } |
627 | 627 |
628 | 628 |
629 int handleUserInput(int sock, char *buf, size_t bufLen) | 629 int handleUserInput(int sock, char *buf, size_t bufLen) |
630 { | 630 { |
631 char *tmpStr, *tmpStr2; | 631 char *tmpStr, *tmpStr2, tmpBuf[4096]; |
632 BOOL result; | 632 BOOL result; |
633 | 633 |
634 /* Trim right */ | 634 /* Trim right */ |
635 buf[--bufLen] = 0; | 635 buf[--bufLen] = 0; |
636 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) | 636 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) |
639 //fprintf(stderr, "'%s'\n", buf); fflush(stderr); | 639 //fprintf(stderr, "'%s'\n", buf); fflush(stderr); |
640 | 640 |
641 /* Check command */ | 641 /* Check command */ |
642 if (*buf == 0) { | 642 if (*buf == 0) { |
643 return 1; | 643 return 1; |
644 } else if (!strncmp(buf, "/color ", 7)) { | |
645 if (sscanf(buf+7, "%6x", &optUserColor) != 1) { | |
646 printMsg("Invalid color value '%s'\n", buf+7); | |
647 return 1; | |
648 } | |
649 printMsg("Setting color to %06X", optUserColor); | |
650 sendUserMsg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | |
651 return 0; | |
644 } else if (!strncmp(buf, "/msg ", 5)) { | 652 } else if (!strncmp(buf, "/msg ", 5)) { |
645 char tmpBuf[4096]; | |
646 if (setTarget) { | 653 if (setTarget) { |
647 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf+5); | 654 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf+5); |
648 buf = tmpBuf; | 655 buf = tmpBuf; |
649 } else { | 656 } else { |
650 fprintf(stderr, "No target set!\n"); | 657 printMsg("No target set!\n"); |
651 return 1; | 658 return 1; |
652 } | 659 } |
653 } else if (!strncmp(buf, "/to ", 4)) { | 660 } else if (!strncmp(buf, "/to ", 4)) { |
654 buf += 4; | 661 buf += 4; |
655 th_free(setTarget); | 662 th_free(setTarget); |
656 setTarget = th_strdup(buf); | 663 setTarget = th_strdup(buf); |
657 fprintf(stderr, "Set prv target to '%s'\n", setTarget); | 664 printMsg("Set prv target to '%s'\n", setTarget); |
658 return 0; | 665 return 0; |
659 } | 666 } |
660 | 667 |
661 { | 668 { |
662 /* Send double-encoded */ | 669 /* Send double-encoded */ |