Browse Source

- Modified @commands to use Meruru's code which is faster and does a fair attempt at tabulating the commands presented.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6541 54d463be-8e91-2dee-dedb-b68131a5f0ec
skotlex 19 years ago
parent
commit
0b8b0ffa96
2 changed files with 38 additions and 24 deletions
  1. 2 0
      Changelog-Trunk.txt
  2. 36 24
      src/map/atcommand.c

+ 2 - 0
Changelog-Trunk.txt

@@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2006/05/09
+	* Modified @commands to use Meruru's code which is faster and does a fair
+	  attempt at tabulating the commands presented. [Skotlex]
 	* Updated SKA to return a random value between 0 and 99 each time
 	  status_get_def is invoked. [Skotlex]
 	* Updated Making Arrow to not include unidentified items in the list.

+ 36 - 24
src/map/atcommand.c

@@ -1162,37 +1162,49 @@ int duel_reject(
  */
 
 /*==========================================
- * @commands Lists available @ commands to you.
+ * @commands Lists available @ commands to you (code 98% from Meruru)
  *------------------------------------------
  */
-int atcommand_commands(const int fd, struct map_session_data* sd,
+int atcommand_commands(
+	const int fd, struct map_session_data* sd,
 	const char* command, const char* message)
 {
-	int i,count=0,level;
-	nullpo_retr(-1, sd);
-	level = pc_isGM(sd);
-	
+	char cz_line_buff[MESSAGE_SIZE+1];
+
+	register char *lpcz_cur = cz_line_buff;
+	register unsigned int ui_slen;
+
+	int i_cur_cmd,gm_lvl = pc_isGM(sd), count = 0;
+
+	memset(cz_line_buff,' ',MESSAGE_SIZE);
+	cz_line_buff[MESSAGE_SIZE] = 0;
+
 	clif_displaymessage(fd, msg_txt(273));
-	memset(atcmd_output, 0, sizeof atcmd_output);
-	for (i = 0; atcommand_info[i].type != AtCommand_Unknown; i++)
-		if (atcommand_info[i].level <= level && atcommand_info[i].command) {
-			count++;
-			strcat(atcmd_output, atcommand_info[i].command);
-			strcat(atcmd_output, " ");
-			if (!(count%10)) {
-				clif_displaymessage(fd, atcmd_output);
-				memset(atcmd_output, 0, sizeof atcmd_output);
-			}
+
+	for (i_cur_cmd = 0;atcommand_info[i_cur_cmd].type != AtCommand_Unknown;i_cur_cmd++)
+	{
+		if(gm_lvl  < atcommand_info[i_cur_cmd].level)
+		continue;
+
+		count++;
+		ui_slen = (unsigned int)strlen(atcommand_info[i_cur_cmd].command);
+
+		//rember not <= bc we need null terminator
+		if(((MESSAGE_SIZE+(int)cz_line_buff)-(int)lpcz_cur) < (int)ui_slen)
+		{
+			clif_displaymessage(fd,(char*)cz_line_buff);
+			lpcz_cur = cz_line_buff;
+			memset(cz_line_buff,' ',MESSAGE_SIZE);
+			cz_line_buff[MESSAGE_SIZE] = 0;
 		}
-	if (count%10)
-		clif_displaymessage(fd, atcmd_output);
 
-	if (count) {
-		sprintf(atcmd_output, msg_txt(274), count);
-		clif_displaymessage(fd, atcmd_output);
-	} else
-		clif_displaymessage(fd, msg_txt(275));
-		
+		memcpy(lpcz_cur,atcommand_info[i_cur_cmd].command,ui_slen);
+		lpcz_cur += ui_slen+(10-ui_slen%10);
+	}
+
+	clif_displaymessage(fd,(char*)cz_line_buff);
+	sprintf(atcmd_output, msg_txt(274), count); //There will always be at least 1 command (@commands)
+	clif_displaymessage(fd, atcmd_output);	
 	return 0;
 }