Jelajahi Sumber

vccd: now you can get one's information

intirain 4 tahun lalu
induk
melakukan
907c6c802c
6 mengubah file dengan 48 tambahan dan 6 penghapusan
  1. 2 2
      Makefile
  2. 3 0
      include/vcc/vcc.h
  3. 2 2
      include/vcc/vccd.h
  4. 2 2
      include/vcc/version.h
  5. 34 0
      users.c
  6. 5 0
      vcc.c

+ 2 - 2
Makefile

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

+ 3 - 0
include/vcc/vcc.h

@@ -52,6 +52,9 @@
 /* client -> server. join session */
 #define REQ_CTL_JOINS 	7
 
+/* client -> server. get user info */
+#define REQ_CTL_UINFO 	8
+
 #define REQ_SIZE 	512
 #define USRNAME_SIZE 	32
 

+ 2 - 2
include/vcc/vccd.h

@@ -37,8 +37,6 @@ int amalloc_report(char *s);
 
 #define amalloc(n) 		__amalloc(n, __FUNCTION__)
 
-int monitor_cmd(void);
-
 int vcc_new_connection(int fd, struct in_addr *addr);
 int vcc_close_connection(int fd);
 
@@ -55,6 +53,8 @@ int session_broadcast(int sid, char *msg, char *usr, int except_fd);
 int send_sessions(int fd);
 int join_session(int sid, int fd);
 
+int get_user_info(int fd, struct vcc_request *);
+
 struct klist_node *find_connection(int fd);
 
 #define LJEST_LEVEL 	16

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.6.4 Tue Apr  5 14:04:38 CST 2022 root"
-#define VCCD_SEMVER "vccd 1.6.4-rc "
+#define VCCD_VERSION "vccd 1.7.0 Tue Apr  5 14:32:50 CST 2022 root"
+#define VCCD_SEMVER "vccd 1.7.0-rc "

+ 34 - 0
users.c

@@ -190,6 +190,40 @@ static struct klist_node *find_user(int fd) {
 }
 
 
+int get_user_info(int fd, struct vcc_request *req) {
+	struct vcc_request 	*out;
+	struct user 		*u;
+
+	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_UINFO);
+	u = (struct user *) out->msg;
+
+	if (get_user(req->msg, u) == -1) 
+		out->uid = htonl(-1);
+
+	else {
+		out->uid = 0;
+
+		u->score = htonl(u->score);
+		u->level = htonl(u->level);
+	}
+
+	memset(((struct user *) out->msg)->passwd, 0, PASSWD_SIZE);
+
+	vcc_send_req(find_connection(fd), out);
+
+	return 0;
+}
+
+
+
+
 int do_user_logout(int fd) {
 	struct klist_node 	*n;
 	struct user 		*usr;

+ 5 - 0
vcc.c

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