changeset 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
files nnchat.c
diffstat 1 files changed, 20 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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);