# HG changeset patch # User Matti Hamalainen # Date 1215341508 -10800 # Node ID 78d26025645015cc727448d8d0178cb3e2aac8b6 # Parent 40fecbab1dc14c562e6281769f34ad5a7ca37931 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. diff -r 40fecbab1dc1 -r 78d260256450 nnchat.c --- a/nnchat.c Fri Jun 27 03:09:23 2008 +0300 +++ b/nnchat.c Sun Jul 06 13:51:48 2008 +0300 @@ -30,7 +30,8 @@ *optUserName = NULL, *optUserName2 = NULL, *optPassword = NULL, - *optLogFilename = NULL; + *optLogFilename = NULL, + *setTarget = NULL; BOOL optDaemon = FALSE; FILE *optLogFile = NULL; @@ -640,22 +641,24 @@ /* Check command */ if (*buf == 0) { return 1; - } else if (*buf == '@') { - /* Send 1-pass encoded 'RAW' */ - buf++; - printf("RAW>%s\n", buf); - fflush(stdout); - - tmpStr = encodeStr1(buf); - if (!tmpStr) return -2; - - result = sendUserMsg(sock, optUserName2, "%s", tmpStr); - th_free(tmpStr); - if (result) - return 0; - else - return -1; - } else { + } else if (!strncmp(buf, "/msg ", 5)) { + char tmpBuf[4096]; + if (setTarget) { + snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf+5); + buf = tmpBuf; + } else { + fprintf(stderr, "No target set!\n"); + return 1; + } + } else if (!strncmp(buf, "/to ", 4)) { + buf += 4; + th_free(setTarget); + setTarget = th_strdup(buf); + fprintf(stderr, "Set prv target to '%s'\n", setTarget); + return 0; + } + + { /* Send double-encoded */ //printf("ENC>%s\n", buf); //fflush(stdout);