Explorar el Código

vccd: add session_name which can query the session's name

intirain hace 4 años
padre
commit
9cd895922f
Se han modificado 6 ficheros con 44 adiciones y 5 borrados
  1. 2 2
      Makefile
  2. 2 1
      include/vcc/vcc.h
  3. 1 0
      include/vcc/vccd.h
  4. 2 2
      include/vcc/version.h
  5. 32 0
      session.c
  6. 5 0
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 14
-VCCD_PATCH 		= 1
+VCCD_MINOR 		= 15
+VCCD_PATCH 		= 0
 VCCD_STR 		= -rc 
 
 VCCD_COMPILE_TIME 	= $(shell date)

+ 2 - 1
include/vcc/vcc.h

@@ -69,8 +69,9 @@
 
 /* client -> server. get server info. (root required) */
 #define REQ_SYS_INFO 	13
+#define REQ_CTL_SENAME 	14
 
-#define REQ_MAX 	14
+#define REQ_MAX 	15
 
 #define REQ_SIZE 	512
 #define USRNAME_SIZE 	32

+ 1 - 0
include/vcc/vccd.h

@@ -72,6 +72,7 @@ int create_session(int fd, char *name);
 int session_broadcast(int sid, char *msg, char *usr, int except_fd, int flags);
 int send_sessions(int fd);
 int join_session(int sid, int fd);
+int session_name(int fd, struct vcc_request *req);
 
 int get_user_info(int fd, struct vcc_request *);
 int incr_score(int fd, struct vcc_request *);

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.14.1 Sun Jun 12 08:17:07 PM CST 2022 root"
-#define VCCD_SEMVER "vccd 1.14.1-rc "
+#define VCCD_VERSION "vccd 1.15.0 Sun Jun 12 09:10:35 PM CST 2022 root"
+#define VCCD_SEMVER "vccd 1.15.0-rc "

+ 32 - 0
session.c

@@ -200,6 +200,38 @@ int session_broadcast(int sid, char *msg, char *usrname, int except, int flags)
 }
 
 
+int session_name(int fd, struct vcc_request *req) {
+	struct klist_node *n;
+	struct vcc_request *out;
+
+	if (unlikely(!(out = amalloc(sizeof(struct vcc_request))))) {
+		vcc_log("*** malloc() failed\n");
+
+		return 1;
+	}
+
+	out->magic = htonl(VCC_MAGIC);
+	out->reqtype = htonl(REQ_CTL_SENAME);
+
+	if (unlikely(!(n = find_session(ntohl(req->session))))) {
+		out->session = htonl(-1);
+		vcc_send_req(find_connection(fd), out);
+
+		vcc_log("%d sends a bad session number. \n", fd);
+
+		return 1;
+	}
+
+	out->session = req->session;
+	strcpy(out->msg, n->usrname);
+	vcc_send_req(find_connection(fd), out);
+
+	vcc_log("sename: %s sent to %d\n", n->usrname, fd);
+
+	return 0;
+}
+
+
 int send_sessions(int fd) {
 	struct klist_node 	*c, *n;
 	struct vcc_request 	*req;

+ 5 - 0
vcc.c

@@ -347,6 +347,11 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 		break;
 
+	case REQ_CTL_SENAME:
+		session_name(fd, req);
+
+		break;
+
 	default:
 		vcc_log("--- bad request type from %d\n", fd);