Selaa lähdekoodia

vcc: support to-u-only. prepare for 2.0.0

intirain 4 vuotta sitten
vanhempi
sitoutus
0fdf777d93
7 muutettua tiedostoa jossa 43 lisäystä ja 15 poistoa
  1. 2 2
      Makefile
  2. 1 1
      cmd.c
  3. 4 1
      include/vcc/pretty.h
  4. 2 2
      include/vcc/version.h
  5. 13 8
      main.c
  6. 19 1
      pretty.c
  7. 2 0
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 20
-VCC_PATCH 		= 1
+VCC_MINOR 		= 21
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 1 - 1
cmd.c

@@ -750,7 +750,7 @@ int do_cmd_rl(int argc, char **argv) {
 	}
 
 	send_relay_msg(msg, usrname, !strcmp(argv[1], "-") ? NULL : argv[1]);
-	pretty_new_msg(usrname, msg, current_sid);
+	pretty_new_msg(usrname, msg, current_sid, MSG_NEW_RELAY);
 
 	free(msg);
 

+ 4 - 1
include/vcc/pretty.h

@@ -58,6 +58,8 @@
 #define setcolor(strm, c) 		\
 	ansi_csi_st(strm, (c)->mode, (c)->fg, (c)->bg)
 
+#define MSG_NEW_RELAY 		1
+#define MSG_NEW_ONLY_VISIBLE 	2
 
 struct color {
 	int 		fg;
@@ -74,6 +76,7 @@ struct theme {
 			sid, 
 			lvl, 
 			time, 
+			relay, 
 			errmsg, 
 			helpcmd, 
 			helpmsg, 
@@ -81,7 +84,7 @@ struct theme {
 };
 
 
-int pretty_new_msg(char *usrname, char *msg, int sid);
+int pretty_new_msg(char *usrname, char *msg, int sid, int flags);
 int pretty_prompt(char *usrname);
 int pretty_unknown_cmd(char *cmd);
 int pretty_cmd_help(char *cmd, char *msg);

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.20.1 Sun May 22 10:33:13 AM CST 2022 root"
-#define VCC_SEMVER "vcc 1.20.1-rc "
+#define VCC_VERSION "VCC 1.21.0 Sun May 22 11:09:06 AM CST 2022 root"
+#define VCC_SEMVER "vcc 1.21.0-rc "

+ 13 - 8
main.c

@@ -255,7 +255,7 @@ int handle_command(char *buf) {
 				return 1;
 
 		send_msg(buf, usrname);
-		pretty_new_msg(usrname, buf, current_sid);
+		pretty_new_msg(usrname, buf, current_sid, 0);
 
 		if (msg_hook) 
 			free(buf);
@@ -281,7 +281,7 @@ void sigint_handler(int signr) {
 }
 
 
-int new_msg(char *msg, char *name, int session) {
+int new_msg(char *msg, char *name, int session, int flags) {
 	char *p;
 
 	if (!strcmp(msg, "CQD")) {
@@ -298,7 +298,7 @@ int new_msg(char *msg, char *name, int session) {
 		if (unlikely(!(p = recv_hook(msg)))) 
 			return 1;
 
-	pretty_new_msg(name, msg, session);
+	pretty_new_msg(name, msg, session, flags);
 	pretty_prompt(usrname);
 
 	if (recv_hook) 
@@ -326,7 +326,7 @@ int main(int argc, char **argv) {
 	struct vcc_relay_header *hdr;
 	char 			*buf, *msg, *ip = VCC_DEFSERV;
 	char 			key[64], iv[64];
-	int 			n, size, port = VCC_PORT, got_usrname;
+	int 			n, size, port = VCC_PORT, flags;
 
 	(void) argc;
 
@@ -337,7 +337,7 @@ int main(int argc, char **argv) {
 
 	printf(VCC_VERSION "\n");
 
-	got_usrname = parse_args(argc, argv, &port, &ip);
+	n = parse_args(argc, argv, &port, &ip);
 	init_socket(ip, port);
 
 	printf(_("Connected to server. \n"));
@@ -348,7 +348,7 @@ int main(int argc, char **argv) {
 	if (!vos_login()) {
 		/* normally startup */
 
-		login(got_usrname);
+		login(n);
 		show_algo_info();
 
 		memset(key, 0, 64);
@@ -431,7 +431,7 @@ int main(int argc, char **argv) {
 					if (ntohl(req->flags) & FLAG_ENCRYPTED) 
 						decrypt(req->msg);
 
-					new_msg(req->msg, req->usrname, req->session);
+					new_msg(req->msg, req->usrname, req->session, 0);
 				}
 
 				else 
@@ -441,8 +441,13 @@ int main(int argc, char **argv) {
 			}
 
 			else {
+				flags = MSG_NEW_RELAY;
+
+				if (hdr->uid) 
+					flags |= MSG_NEW_ONLY_VISIBLE;
+
 				msg = relay_get_msg(fd, hdr);
-				new_msg(msg, hdr->usrname, hdr->session);
+				new_msg(msg, hdr->usrname, hdr->session, flags);
 
 				free(msg);
 			}

+ 19 - 1
pretty.c

@@ -77,6 +77,12 @@ struct theme theme_def = {
 		.bg = BG_BLACK, 
 		.mode = MODE_HIGHLIGHT
 	}, 
+
+	.relay = {
+		.fg = FG_BLUE, 
+		.bg = BG_BLACK, 
+		.mode = MODE_HIGHLIGHT
+	}, 
 	
 	.errmsg = {
 		.fg = FG_RED, 
@@ -113,13 +119,14 @@ int self_level;
 #define curr_sid 		(&current_theme->sid)
 #define curr_lvl 		(&current_theme->lvl)
 #define curr_time 		(&current_theme->time)
+#define curr_relay 		(&current_theme->relay)
 #define curr_errmsg 		(&current_theme->errmsg)
 #define curr_helpcmd 		(&current_theme->helpcmd)
 #define curr_helpmsg 		(&current_theme->helpmsg)
 #define curr_cqd 		(&current_theme->cqd)
 
 
-int pretty_new_msg(char *usrname, char *buf, int sid) {
+int pretty_new_msg(char *usrname, char *buf, int sid, int flags) {
 	time_t time_now;
 	struct tm *tm_now;
 
@@ -133,6 +140,17 @@ int pretty_new_msg(char *usrname, char *buf, int sid) {
 	setcolor(stdout, curr_sid);
 	printf("#%d ", sid);
 
+	if (flags & MSG_NEW_RELAY) {
+		setcolor(stdout, curr_relay);
+		printf("[relay] ");
+
+		if (flags & MSG_NEW_ONLY_VISIBLE) 
+			printf("[to-u-only] ");
+
+		else 
+			printf("[broadcast] ");
+	}
+
 	if (unlikely(!strcmp(usrname, "system"))) {
 		setcolor(stdout, curr_sysusername);
 		printf("system");

+ 2 - 0
vcc.c

@@ -140,6 +140,8 @@ int send_relay_msg(const char *msg, const char *usrname, const char *visible) {
 
 	if (visible) 
 		strncpy(req.visible, visible, USRNAME_SIZE);
+	else 
+		memset(req.visible, 0, USRNAME_SIZE);
 
 	write(fd, &req, sizeof(struct vcc_relay_header));
 	write(fd, msg, len);