Mercurial > hg > nnchat
comparison nnchat.c @ 24:78d260256450
Added two simple commands to simplify private chatting, "/to" and "/msg".
"/to foo" sets the prv target to username "foo" and "/msg blah" sends
messages to the set target.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 06 Jul 2008 13:51:48 +0300 |
parents | 40fecbab1dc1 |
children | 3b67a9a806a7 |
comparison
equal
deleted
inserted
replaced
23:40fecbab1dc1 | 24:78d260256450 |
---|---|
28 int optUserColor = 0x408060; | 28 int optUserColor = 0x408060; |
29 char *optServer = "www11.servemedata.com", | 29 char *optServer = "www11.servemedata.com", |
30 *optUserName = NULL, | 30 *optUserName = NULL, |
31 *optUserName2 = NULL, | 31 *optUserName2 = NULL, |
32 *optPassword = NULL, | 32 *optPassword = NULL, |
33 *optLogFilename = NULL; | 33 *optLogFilename = NULL, |
34 *setTarget = NULL; | |
34 BOOL optDaemon = FALSE; | 35 BOOL optDaemon = FALSE; |
35 FILE *optLogFile = NULL; | 36 FILE *optLogFile = NULL; |
36 | 37 |
37 | 38 |
38 /* Arguments | 39 /* Arguments |
638 //fprintf(stderr, "'%s'\n", buf); fflush(stderr); | 639 //fprintf(stderr, "'%s'\n", buf); fflush(stderr); |
639 | 640 |
640 /* Check command */ | 641 /* Check command */ |
641 if (*buf == 0) { | 642 if (*buf == 0) { |
642 return 1; | 643 return 1; |
643 } else if (*buf == '@') { | 644 } else if (!strncmp(buf, "/msg ", 5)) { |
644 /* Send 1-pass encoded 'RAW' */ | 645 char tmpBuf[4096]; |
645 buf++; | 646 if (setTarget) { |
646 printf("RAW>%s\n", buf); | 647 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf+5); |
647 fflush(stdout); | 648 buf = tmpBuf; |
648 | 649 } else { |
649 tmpStr = encodeStr1(buf); | 650 fprintf(stderr, "No target set!\n"); |
650 if (!tmpStr) return -2; | 651 return 1; |
651 | 652 } |
652 result = sendUserMsg(sock, optUserName2, "%s", tmpStr); | 653 } else if (!strncmp(buf, "/to ", 4)) { |
653 th_free(tmpStr); | 654 buf += 4; |
654 if (result) | 655 th_free(setTarget); |
655 return 0; | 656 setTarget = th_strdup(buf); |
656 else | 657 fprintf(stderr, "Set prv target to '%s'\n", setTarget); |
657 return -1; | 658 return 0; |
658 } else { | 659 } |
660 | |
661 { | |
659 /* Send double-encoded */ | 662 /* Send double-encoded */ |
660 //printf("ENC>%s\n", buf); | 663 //printf("ENC>%s\n", buf); |
661 //fflush(stdout); | 664 //fflush(stdout); |
662 | 665 |
663 tmpStr = encodeStr2(buf); | 666 tmpStr = encodeStr2(buf); |