Explorar o código

vcc: print your level (vip)

intirain %!s(int64=4) %!d(string=hai) anos
pai
achega
9629d9a7f6
Modificáronse 6 ficheiros con 55 adicións e 11 borrados
  1. 1 1
      Makefile
  2. 38 8
      cmd.c
  3. 1 0
      include/vcc/pretty.h
  4. 2 2
      include/vcc/version.h
  5. 2 0
      main.c
  6. 11 0
      pretty.c

+ 1 - 1
Makefile

@@ -1,5 +1,5 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 8
+VCC_MINOR 		= 9
 VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 

+ 38 - 8
cmd.c

@@ -50,6 +50,7 @@ int do_cmd_currs(char *);
 int do_cmd_swtch(char *);
 int do_cmd_lsse(char *);
 int do_cmd_uinfo(char *);
+int do_cmd_lself(char *);
 
 int read_msg(struct vcc_request *);
 int vcc_create_session(char *name);
@@ -59,6 +60,7 @@ int do_cmd_ls_bh(struct vcc_request *);
 extern char usrname[];
 extern int rate;
 extern int current_sid;
+extern int self_level;
 
 int get_users(void);
 int get_sessions(void);
@@ -78,6 +80,7 @@ struct cmdtable {
 	{ "-swtch", do_cmd_swtch, "Switch to another session. " }, 
 	{ "-lsse", do_cmd_lsse, "List all sessions created. " }, 
 	{ "-uinfo", do_cmd_uinfo, "Get one's information. " }, 
+	{ "-lself", do_cmd_lself, "Reload information of myself. " }, 
 
 	{ NULL, NULL, NULL }
 };
@@ -259,15 +262,24 @@ int do_cmd_swtch(char *s) {
 }
 
 
+int lself = 0;
+
 int do_cmd_uinfo(char *s) {
-	char usrname[USRNAME_SIZE];
+	char name[USRNAME_SIZE];
 
-	(void) s;
+	if (!lself) {
+		(void) s;
+
+		fprintf(stderr, "username: ");
+		scanf("%s", name);
+
+		get_user_info(name);
+	}
 
-	fprintf(stderr, "username: ");
-	scanf("%s", usrname);
+	else 
+		/* s is the usrname of myself */
 
-	get_user_info(usrname);
+		get_user_info(s);
 
 	return 0;
 }
@@ -295,12 +307,30 @@ int do_cmd_uinfo_bh(struct vcc_request *req) {
 		return 1;
 	}
 
-	printf("%s's info: \n", u->usrname);
-	printf("\tscore\tlevel\n");
-	printf("\t%d\t%d\n", ntohl(u->score), ntohl(u->level));
+	if (lself) {
+		lself = 0;
+		self_level = ntohl(u->level);
+
+		printf("Level of yourself: %d\n", self_level);
+	}
+
+	else {
+		printf("%s's info: \n", u->usrname);
+		printf("\tscore\tlevel\n");
+		printf("\t%d\t%d\n", ntohl(u->score), ntohl(u->level));
+	}
 
 	pretty_prompt(usrname);
+	
+	return 0;
+}
 
+int do_cmd_lself(char *s) {
+	(void) s;
+
+	lself = 1;
+	do_cmd_uinfo(usrname);
+	
 	return 0;
 }
 

+ 1 - 0
include/vcc/pretty.h

@@ -71,6 +71,7 @@ struct theme {
 			msg, 
 			sysmsg, 
 			sid, 
+			lvl, 
 			time, 
 			errmsg, 
 			helpcmd, 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.8.0 Tue Apr  5 14:33:49 CST 2022 root"
-#define VCC_SEMVER "vcc 1.8.0-rc "
+#define VCC_VERSION "VCC 1.9.0 Tue Apr  5 14:47:34 CST 2022 root"
+#define VCC_SEMVER "vcc 1.9.0-rc "

+ 2 - 0
main.c

@@ -54,6 +54,7 @@ int decrypt(char *);
 
 int do_cmd(char *s);
 int do_bh(struct vcc_request *);
+int do_cmd_lself(char *);
 
 int init_socket(const char *server_addr, int server_port);
 
@@ -94,6 +95,7 @@ static int login(int got_usrname) {
 	passwd = getpass("password: ");
 
 	vcc_login(usrname, passwd);
+	do_cmd_lself(NULL);
 
 	return 0;
 }

+ 11 - 0
pretty.c

@@ -62,6 +62,12 @@ struct theme theme_def = {
 		.mode = MODE_HIGHLIGHT
 	}, 
 
+	.lvl = {
+		.fg = FG_YELLOW, 
+		.bg = BG_BLACK, 
+		.mode = MODE_LINE
+	}, 
+
 	.time = {
 		.fg = FG_YELLOW, 
 		.bg = BG_BLACK, 
@@ -88,12 +94,14 @@ struct theme theme_def = {
 };
 
 struct theme *current_theme = &theme_def;
+int self_level;
 
 #define curr_usrname 		(&current_theme->usrname)
 #define curr_sysusername 	(&current_theme->sysusername)
 #define curr_msg 		(&current_theme->msg)
 #define curr_sysmsg 		(&current_theme->sysmsg)
 #define curr_sid 		(&current_theme->sid)
+#define curr_lvl 		(&current_theme->lvl)
 #define curr_time 		(&current_theme->time)
 #define curr_errmsg 		(&current_theme->errmsg)
 #define curr_helpcmd 		(&current_theme->helpcmd)
@@ -150,6 +158,9 @@ int pretty_prompt(char *usrname) {
 	setcolor(stderr, curr_sid);
 	fprintf(stderr, "#%03d ", current_sid);
 
+	setcolor(stderr, curr_lvl);
+	fprintf(stderr, "lvl%d", self_level);
+
 	setcolor(stderr, curr_usrname);
 	fprintf(stderr, "%s", usrname);