Procházet zdrojové kódy

vcc: sessions are now ok

intirain před 4 roky
rodič
revize
9dffe21940
8 změnil soubory, kde provedl 33 přidání a 9 odebrání
  1. 1 1
      Makefile
  2. 2 2
      cmd.c
  3. 1 1
      include/vcc/pretty.h
  4. 3 0
      include/vcc/vcc.h
  5. 2 2
      include/vcc/version.h
  6. 4 2
      main.c
  7. 4 1
      pretty.c
  8. 16 0
      vcc.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
 VCC_MINOR 		= 5
-VCC_PATCH 		= 1
+VCC_PATCH 		= 2
 VCC_STR 		= -rc 
 
 VCC_COMPILE_TIME 	= $(shell date)

+ 2 - 2
cmd.c

@@ -60,6 +60,7 @@ extern int current_sid;
 
 int get_users(void);
 int get_sessions(void);
+int join_session(int sid);
 
 struct cmdtable {
 	char 		*cmd;
@@ -249,8 +250,7 @@ int do_cmd_swtch(char *s) {
 	scanf("%d", &sid);
 
 	current_sid = sid;
-
-	printf("We'll use this session from now on. \n");
+	join_session(current_sid);
 
 	return 0;
 }

+ 1 - 1
include/vcc/pretty.h

@@ -78,7 +78,7 @@ struct theme {
 };
 
 
-int pretty_new_msg(char *usrname, char *msg);
+int pretty_new_msg(char *usrname, char *msg, int sid);
 int pretty_prompt(char *usrname);
 int pretty_unknow_cmd(char *cmd);
 int pretty_cmd_help(char *cmd, char *msg);

+ 3 - 0
include/vcc/vcc.h

@@ -48,6 +48,9 @@
  * server -> client: response */
 #define REQ_CTL_SESS 	6
 
+/* client -> server. join session */
+#define REQ_CTL_JOINS 	7
+
 #define REQ_SIZE 	512
 #define USRNAME_SIZE 	32
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.5.1 Sat Mar 26 21:55:07 CST 2022 root"
-#define VCC_SEMVER "vcc 1.5.1-rc "
+#define VCC_VERSION "VCC 1.5.2 Sun Mar 27 15:14:12 CST 2022 root"
+#define VCC_SEMVER "vcc 1.5.2-rc "

+ 4 - 2
main.c

@@ -58,6 +58,8 @@ int rate;
 
 char usrname[USRNAME_SIZE];
 
+extern int current_sid;
+
 static int usage(void) {
 	fprintf(stderr, "Usage: vcc [server]\n");
 	fprintf(stderr, "As default, server is 124.223.105.230. \n");
@@ -162,7 +164,7 @@ int main(int argc, const char **argv) {
 			else if (*buf != '\n') {
 				send_msg(buf, usrname);
 
-				pretty_new_msg(usrname, buf);
+				pretty_new_msg(usrname, buf, current_sid);
 			}
 
 			pretty_prompt(usrname);
@@ -188,7 +190,7 @@ int main(int argc, const char **argv) {
 			if (!*msg || *(unsigned char *) msg == 0xffu) 
 				continue;
 
-			pretty_new_msg(req->usrname, msg);
+			pretty_new_msg(req->usrname, msg, ntohl(req->session));
 			pretty_prompt(usrname);
 		}
 	}

+ 4 - 1
pretty.c

@@ -100,7 +100,7 @@ struct theme *current_theme = &theme_def;
 #define curr_helpmsg 		(&current_theme->helpmsg)
 
 
-int pretty_new_msg(char *usrname, char *buf) {
+int pretty_new_msg(char *usrname, char *buf, int sid) {
 	time_t time_now;
 	struct tm *tm_now;
 
@@ -111,6 +111,9 @@ int pretty_new_msg(char *usrname, char *buf) {
 	tm_now = localtime(&time_now);
 	printf("\r[%02d:%02d] ", tm_now->tm_hour, tm_now->tm_min);
 
+	setcolor(stdout, curr_sid);
+	printf("#%d ", sid);
+
 	if (unlikely(!strcmp(usrname, "system"))) {
 		setcolor(stdout, curr_sysusername);
 		printf("system");

+ 16 - 0
vcc.c

@@ -242,3 +242,19 @@ int vcc_create_session(char *name) {
 }
 
 
+int join_session(int sid) {
+	struct vcc_request req;
+
+	clear_req(&req);
+
+	req.magic = htonl(VCC_MAGIC);
+	req.reqtype = htonl(REQ_CTL_JOINS);
+	req.session = htonl(sid);
+
+	write(fd, &req, REQ_SIZE);
+
+	return 0;
+
+}
+
+