Forráskód Böngészése

* Fixed map-server crash possibily by using @channel ban/unban for offline player
* Fixed @channel ban/unban doesn't recognize player's name with space

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>

Cydh Ramdh 10 éve
szülő
commit
28601afa16
3 módosított fájl, 28 hozzáadás és 24 törlés
  1. 18 14
      src/map/atcommand.c
  2. 9 9
      src/map/channel.c
  3. 1 1
      src/map/channel.h

+ 18 - 14
src/map/atcommand.c

@@ -9234,21 +9234,15 @@ static inline void atcmd_channel_help(struct map_session_data *sd, const char *c
 }
 
 ACMD_FUNC(channel) {
-	char key[CHAN_NAME_LENGTH], sub1[CHAN_NAME_LENGTH], sub2[CHAN_NAME_LENGTH], sub3[CHAN_NAME_LENGTH];
-	sub1[0] = sub2[0] = sub3[0] = '\0';
+	char key[NAME_LENGTH], sub1[CHAN_NAME_LENGTH], sub2[64];
+	sub1[0] = sub2[0] = '\0';
 
-	if( !message || !*message || sscanf(message, "%19s %19s %19s %19s", key, sub1, sub2, sub3) < 1 ) {
+	if( !message || !*message || sscanf(message, "%23s %19s %63[^\n]", key, sub1, sub2) < 1 ) {
 		atcmd_channel_help(sd,command);
 		return 0;
 	}
 
-	if( strcmpi(key,"create") == 0 && ( channel_config.user_chenable || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) ) {
-		if(sub3[0] != '\0'){
-			clif_displaymessage(fd, msg_txt(sd,1408)); // Channel password may not contain spaces.
-			return -1;
-		}
-		return channel_pccreate(sd,sub1,sub2);
-	} else if( strcmpi(key,"delete") == 0 && pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) {
+	if( strcmpi(key,"delete") == 0 && pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) {
 		return channel_pcdelete(sd,sub1);
 	} else if ( strcmpi(key,"list") == 0 ) {
 		return channel_display_list(sd,sub1);
@@ -9263,16 +9257,26 @@ ACMD_FUNC(channel) {
 	} else if ( strcmpi(key,"unbind") == 0 ) {
 		return channel_pcunbind(sd);
 	} else if ( strcmpi(key,"ban") == 0 ) {
-		return channel_pcban(sd,sub1,map_nick2sd(sub2),0);
+		return channel_pcban(sd,sub1,sub2,0);
 	} else if ( strcmpi(key,"banlist") == 0 ) {
 		return channel_pcban(sd,sub1,NULL,3);
 	} else if ( strcmpi(key,"unban") == 0 ) {
-		return channel_pcban(sd,sub1,map_nick2sd(sub2),1);
+		return channel_pcban(sd,sub1,sub2,1);
 	} else if ( strcmpi(key,"unbanall") == 0 ) {
 		return channel_pcban(sd,sub1,NULL,2);
-	} else if ( strcmpi(key,"setopt") == 0 ) {
-		return channel_pcsetopt(sd,sub1,sub2,sub3);
 	} else {
+		char sub3[CHAN_NAME_LENGTH], sub4[CHAN_NAME_LENGTH];
+		sub3[0] = sub4[0] = '\0';
+		sscanf(sub2, "%19s %19s", sub3, sub4);
+		if( strcmpi(key,"create") == 0 && ( channel_config.user_chenable || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) ) {
+			if (sub4[0] != '\0') {
+				clif_displaymessage(fd, msg_txt(sd, 1408)); // Channel password may not contain spaces.
+				return -1;
+			}
+			return channel_pccreate(sd,sub1,sub3);
+		} else if ( strcmpi(key,"setopt") == 0 ) {
+			return channel_pcsetopt(sd,sub1,sub3,sub4);
+		}
 		atcmd_channel_help(sd,command);
 	}
 

+ 9 - 9
src/map/channel.c

@@ -813,9 +813,10 @@ int channel_pcunbind(struct map_session_data *sd){
  *  0 : success
  *  -1 : fail
  */
-int channel_pcban(struct map_session_data *sd, char *chname, struct map_session_data *tsd, int flag){
+int channel_pcban(struct map_session_data *sd, char *chname, char *pname, int flag){
 	struct Channel *channel;
 	char output[128];
+	struct map_session_data *tsd = map_nick2sd(pname);
 
 	if( channel_chk(chname,NULL,1) ) {
 		clif_displaymessage(sd->fd, msg_txt(sd,1405));// Channel name must start with '#'.
@@ -838,7 +839,7 @@ int channel_pcban(struct map_session_data *sd, char *chname, struct map_session_
 	if(flag != 2 && flag != 3){
 		char banned;
 		if(!tsd || pc_has_permission(tsd, PC_PERM_CHANNEL_ADMIN) ) {
-			sprintf(output, msg_txt(sd,1464), tsd->status.name);// Ban failed for player '%s'.
+			sprintf(output, msg_txt(sd,1464), pname);// Ban failed for player '%s'.
 			clif_displaymessage(sd->fd, output);
 			return -1;
 		}
@@ -867,6 +868,8 @@ int channel_pcban(struct map_session_data *sd, char *chname, struct map_session_
 	switch(flag){
 	case 0: {
 		struct chan_banentry *cbe;
+		if (!tsd)
+			return -1;
 		CREATE(cbe, struct chan_banentry, 1);
 		cbe->char_id = tsd->status.char_id;
 		strcpy(cbe->char_name,tsd->status.name);
@@ -876,6 +879,8 @@ int channel_pcban(struct map_session_data *sd, char *chname, struct map_session_
 		break;
 		}
 	case 1:
+		if (!tsd)
+			return -1;
 		idb_remove(channel->banned, tsd->status.char_id);
 		sprintf(output, msg_txt(sd,1441),tsd->status.name,chname); // Player '%s' is unbanned from the '%s' channel.
 		break;
@@ -938,15 +943,10 @@ int channel_pcsetopt(struct map_session_data *sd, char *chname, const char *opti
 		clif_displaymessage(sd->fd, output);
 		return -1;
 	}
-
-	if(!option || option[0] == '\0' ) {
-		clif_displaymessage(sd->fd, msg_txt(sd,1446));// You need to input an option.
-		return -1;
-	}
-
+	
 	s = ARRAYLENGTH(opt_str);
 	ARR_FIND(1,s,k,( strncmpi(option,opt_str[k],3) == 0 )); //we only cmp 3 letter atm
-	if( k >= s ) {
+	if(!option || option[0] == '\0' || k >= s ) {
 		sprintf(output, msg_txt(sd,1447), option);// Unknown channel option '%s'.
 		clif_displaymessage(sd->fd, output);
 		clif_displaymessage(sd->fd, msg_txt(sd,1414));// ---- Available options:

+ 1 - 1
src/map/channel.h

@@ -82,7 +82,7 @@ int channel_pcleave(struct map_session_data *sd, char *chname);
 int channel_pccolor(struct map_session_data *sd, char *chname, char *color);
 int channel_pcbind(struct map_session_data *sd, char *chname);
 int channel_pcunbind(struct map_session_data *sd);
-int channel_pcban(struct map_session_data *sd, char *chname, struct map_session_data *tsd, int flag);
+int channel_pcban(struct map_session_data *sd, char *chname, char *pname, int flag);
 int channel_pcsetopt(struct map_session_data *sd, char *chname, const char *option, const char *val);
 
 void do_init_channel(void);