Преглед изворни кода

* Fixed #633 compile warning. Thank @tmav94
* Move out `enum chrif_req_op` to socket.h so can be used too for `char_mapif.c`

Signed-off-by: Cydh Ramdh <cydh@pservero.com>

Cydh Ramdh пре 9 година
родитељ
комит
d301d1ecb3
5 измењених фајлова са 35 додато и 35 уклоњено
  1. 10 11
      src/char/char_mapif.c
  2. 18 0
      src/common/socket.h
  3. 5 6
      src/map/chrif.c
  4. 1 17
      src/map/chrif.h
  5. 1 1
      src/map/clif.c

+ 10 - 11
src/char/char_mapif.c

@@ -727,17 +727,16 @@ int chmapif_parse_fwlog_changestatus(int fd){
 		int result = 0; // 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline, 4-current group level > VIP group level
 		char esc_name[NAME_LENGTH*2+1];
 		char answer = true;
-
 		int aid = RFIFOL(fd,2); // account_id of who ask (-1 if server itself made this request)
 		const char* name = (char*)RFIFOP(fd,6); // name of the target character
-		int operation = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban, 5-changesex, 6-vip, 7-changecharsex
+		int operation = RFIFOW(fd,30); // type of operation @see enum chrif_req_op
 		int32 timediff = 0;
 		int val1 = 0, sex = SEX_MALE;
 
-		if (operation == 2 || operation == 6) {
+		if (operation == CHRIF_OP_LOGIN_BAN || operation == CHRIF_OP_LOGIN_VIP) {
 			timediff = RFIFOL(fd, 32);
 			val1 = RFIFOL(fd, 36);
-		} else if (operation == 7)
+		} else if (operation == CHRIF_OP_CHANGECHARSEX)
 			sex = RFIFOB(fd, 32);
 		RFIFOSKIP(fd,44);
 
@@ -767,45 +766,45 @@ int chmapif_parse_fwlog_changestatus(int fd){
 			else {
 				//! NOTE: See src/char/chrif.h::enum chrif_req_op for the number
 				switch( operation ) {
-					case 1: // block
+					case CHRIF_OP_LOGIN_BLOCK: // block
 						WFIFOHEAD(login_fd,10);
 						WFIFOW(login_fd,0) = 0x2724;
 						WFIFOL(login_fd,2) = t_aid;
 						WFIFOL(login_fd,6) = 5; // new account status
 						WFIFOSET(login_fd,10);
 						break;
-					case 2: // ban
+					case CHRIF_OP_LOGIN_BAN: // ban
 						WFIFOHEAD(login_fd,10);
 						WFIFOW(login_fd, 0) = 0x2725;
 						WFIFOL(login_fd, 2) = t_aid;
 						WFIFOL(login_fd, 6) = timediff;
 						WFIFOSET(login_fd,10);
 						break;
-					case 3: // unblock
+					case CHRIF_OP_LOGIN_UNBLOCK: // unblock
 						WFIFOHEAD(login_fd,10);
 						WFIFOW(login_fd,0) = 0x2724;
 						WFIFOL(login_fd,2) = t_aid;
 						WFIFOL(login_fd,6) = 0; // new account status
 						WFIFOSET(login_fd,10);
 						break;
-					case 4: // unban
+					case CHRIF_OP_LOGIN_UNBAN: // unban
 						WFIFOHEAD(login_fd,6);
 						WFIFOW(login_fd,0) = 0x272a;
 						WFIFOL(login_fd,2) = t_aid;
 						WFIFOSET(login_fd,6);
 						break;
-					case 5: // changesex
+					case CHRIF_OP_LOGIN_CHANGESEX: // changesex
 						answer = false;
 						WFIFOHEAD(login_fd,6);
 						WFIFOW(login_fd,0) = 0x2727;
 						WFIFOL(login_fd,2) = t_aid;
 						WFIFOSET(login_fd,6);
 						break;
-					case 6: // vip
+					case CHRIF_OP_LOGIN_VIP: // vip
 						answer = (val1&4); // vip_req val1=type, &1 login send return, &2 update timestamp, &4 map send answer
 						chlogif_reqvipdata(t_aid, val1, timediff, fd);
 						break;
-					case 7: // changecharsex
+					case CHRIF_OP_CHANGECHARSEX: // changecharsex
 						answer = false;
 						chlogif_parse_ackchangecharsex(t_cid, sex);
 						break;

+ 18 - 0
src/common/socket.h

@@ -130,6 +130,24 @@ extern void set_nonblocking(int fd, unsigned long yes);
 
 void set_defaultparse(ParseFunc defaultparse);
 
+
+/// Server operation request
+enum chrif_req_op {
+	// Char-server <-> login-server oepration
+	CHRIF_OP_LOGIN_BLOCK = 1,
+	CHRIF_OP_LOGIN_BAN,
+	CHRIF_OP_LOGIN_UNBLOCK,
+	CHRIF_OP_LOGIN_UNBAN,
+	CHRIF_OP_LOGIN_CHANGESEX,
+	CHRIF_OP_LOGIN_VIP,
+
+	// Char-server operation
+	CHRIF_OP_BAN,
+	CHRIF_OP_UNBAN,
+	CHRIF_OP_CHANGECHARSEX,
+};
+
+
 // hostname/ip conversion functions
 uint32 host2ip(const char* hostname);
 const char* ip2str(uint32 ip, char ip_str[16]);

+ 5 - 6
src/map/chrif.c

@@ -848,7 +848,7 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email) {
  * @val1 : extra data value to transfer for operation
  * @val2 : extra data value to transfer for operation
  */
-int chrif_req_login_operation(int aid, const char* character_name, unsigned short operation_type, int32 timediff, int val1, int val2) {
+int chrif_req_login_operation(int aid, const char* character_name, enum chrif_req_op operation_type, int32 timediff, int val1, int val2) {
 	chrif_check(-1);
 
 	WFIFOHEAD(char_fd,44);
@@ -877,7 +877,7 @@ int chrif_changesex(struct map_session_data *sd, bool change_account) {
 	WFIFOW(char_fd,0) = 0x2b0e;
 	WFIFOL(char_fd,2) = sd->status.account_id;
 	safestrncpy((char*)WFIFOP(char_fd,6), sd->status.name, NAME_LENGTH);
-	WFIFOW(char_fd,30) = (change_account ? CHRIF_OP_LOGIN_CHANGESEX : CHRIF_OP_LOGIN_CHANGECHARSEX);
+	WFIFOW(char_fd,30) = (change_account ? CHRIF_OP_LOGIN_CHANGESEX : CHRIF_OP_CHANGECHARSEX);
 	if (!change_account)
 		WFIFOB(char_fd,32) = sd->status.sex == SEX_MALE ? SEX_FEMALE : SEX_MALE;
 	WFIFOSET(char_fd,44);
@@ -917,14 +917,13 @@ static void chrif_ack_login_req(int aid, const char* player_name, uint16 type, u
 	}
 
 	switch (type) {
+		case CHRIF_OP_LOGIN_CHANGESEX:
+		case CHRIF_OP_CHANGECHARSEX:
+			type = CHRIF_OP_LOGIN_CHANGESEX; // So we don't have to create a new msgstring.
 		case CHRIF_OP_LOGIN_BLOCK:
 		case CHRIF_OP_LOGIN_BAN:
 		case CHRIF_OP_LOGIN_UNBLOCK:
 		case CHRIF_OP_LOGIN_UNBAN:
-		case CHRIF_OP_LOGIN_CHANGESEX:
-		case CHRIF_OP_LOGIN_CHANGECHARSEX:
-			if (type == CHRIF_OP_LOGIN_CHANGECHARSEX)
-				type--; // So we don't have to create a new msgstring.
 			snprintf(action,25,"%s",msg_txt(sd,427+type)); //block|ban|unblock|unban|change the sex of
 			break;
 		case CHRIF_OP_LOGIN_VIP:

+ 1 - 17
src/map/chrif.h

@@ -18,22 +18,6 @@ struct auth_node {
 	enum sd_state state; //To track whether player was login in/out or changing maps.
 };
 
-/// Char-server (to login-server) operation request
-enum chrif_req_op {
-	// Request to login-server
-	CHRIF_OP_LOGIN_BLOCK = 1,
-	CHRIF_OP_LOGIN_BAN,
-	CHRIF_OP_LOGIN_UNBLOCK,
-	CHRIF_OP_LOGIN_UNBAN,
-	CHRIF_OP_LOGIN_CHANGESEX,
-	CHRIF_OP_LOGIN_VIP,
-	CHRIF_OP_LOGIN_CHANGECHARSEX,
-
-	// Char-server operation
-	CHRIF_OP_BAN,
-	CHRIF_OP_UNBAN,
-};
-
 void chrif_setuserid(char* id);
 void chrif_setpasswd(char* pwd);
 void chrif_checkdefaultlogin(void);
@@ -64,7 +48,7 @@ int chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port);
 
 int chrif_searchcharid(uint32 char_id);
 int chrif_changeemail(int id, const char *actual_email, const char *new_email);
-int chrif_req_login_operation(int aid, const char* character_name, unsigned short operation_type, int timediff, int val1, int val2);
+int chrif_req_login_operation(int aid, const char* character_name, enum chrif_req_op operation_type, int32 timediff, int val1, int val2);
 int chrif_updatefamelist(struct map_session_data *sd);
 int chrif_buildfamelist(void);
 int chrif_save_scdata(struct map_session_data *sd);

+ 1 - 1
src/map/clif.c

@@ -1971,7 +1971,7 @@ void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
 #if PACKETVER >= 20131223
 	struct s_packet_db* info;
 	struct s_npc_buy_list *item_list;
-	uint16 cmd = RFIFOW(fd,0), len = 0, i = 0;
+	uint16 len = 0, i = 0;
 	uint8 res = 0, n = 0;
 
 	nullpo_retv(sd);