viewing paste Unknown #651 | Text

Posted on the
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3.  
  4. #include "../common/cbasetypes.h"
  5. #include "../common/mmo.h"
  6. #include "../common/timer.h"
  7. #include "../common/nullpo.h"
  8. #include "../common/core.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/malloc.h"
  11. #include "../common/random.h"
  12. #include "../common/socket.h"
  13. #include "../common/strlib.h"
  14. #include "../common/utils.h"
  15. #include "../common/conf.h"
  16.  
  17. #include "atcommand.h"
  18. #include "battle.h"
  19. #include "chat.h"
  20. #include "clif.h"
  21. #include "chrif.h"
  22. #include "duel.h"
  23. #include "intif.h"
  24. #include "itemdb.h"
  25. #include "log.h"
  26. #include "map.h"
  27. #include "pc.h"
  28. #include "pc_groups.h" // groupid2name
  29. #include "status.h"
  30. #include "skill.h"
  31. #include "mob.h"
  32. #include "npc.h"
  33. #include "pet.h"
  34. #include "homunculus.h"
  35. #include "mail.h"
  36. #include "mercenary.h"
  37. #include "elemental.h"
  38. #include "party.h"
  39. #include "guild.h"
  40. #include "script.h"
  41. #include "storage.h"
  42. #include "trade.h"
  43. #include "unit.h"
  44. #include "mapreg.h"
  45.  
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <math.h>
  50.  
  51.  
  52. #define ATCOMMAND_LENGTH 50
  53. #define ACMD_FUNC(x) static int atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
  54. #define MAX_MSG 1000
  55.  
  56.  
  57. typedef struct AtCommandInfo AtCommandInfo;
  58. typedef struct AliasInfo AliasInfo;
  59.  
  60. struct AtCommandInfo {
  61. 	char command[ATCOMMAND_LENGTH]; 
  62. 	AtCommandFunc func;
  63. };
  64.  
  65. struct AliasInfo {
  66. 	AtCommandInfo *command;
  67. 	char alias[ATCOMMAND_LENGTH];
  68. };
  69.  
  70.  
  71. char atcommand_symbol = '@'; // first char of the commands
  72. char charcommand_symbol = '#';
  73.  
  74. static char* msg_table[MAX_MSG]; // Server messages (0-499 reserved for GM commands, 500-999 reserved for others)
  75. static DBMap* atcommand_db = NULL; //name -> AtCommandInfo
  76. static DBMap* atcommand_alias_db = NULL; //alias -> AtCommandInfo
  77. static config_t atcommand_config;
  78.  
  79. static char atcmd_output[CHAT_SIZE_MAX];
  80. static char atcmd_player_name[NAME_LENGTH];
  81.  
  82. static AtCommandInfo* get_atcommandinfo_byname(const char *name); // @help
  83. static const char* atcommand_checkalias(const char *aliasname); // @help
  84. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand); // @help
  85.  
  86. //-----------------------------------------------------------
  87. // Return the message string of the specified number by [Yor]
  88. //-----------------------------------------------------------
  89. const char* msg_txt(int msg_number)
  90. {
  91. 	if (msg_number >= 0 && msg_number < MAX_MSG &&
  92. 	    msg_table[msg_number] != NULL && msg_table[msg_number][0] != '\0')
  93. 		return msg_table[msg_number];
  94.  
  95. 	return "??";
  96. }
  97.  
  98. /*==========================================
  99.  * Read Message Data
  100.  *------------------------------------------*/
  101. int msg_config_read(const char* cfgName)
  102. {
  103. 	int msg_number;
  104. 	char line[1024], w1[1024], w2[1024];
  105. 	FILE *fp;
  106. 	static int called = 1;
  107.  
  108. 	if ((fp = fopen(cfgName, "r")) == NULL) {
  109. 		ShowError("Messages file not found: %s\n", cfgName);
  110. 		return 1;
  111. 	}
  112.  
  113. 	if ((--called) == 0)
  114. 		memset(msg_table, 0, sizeof(msg_table[0]) * MAX_MSG);
  115.  
  116. 	while(fgets(line, sizeof(line), fp))
  117. 	{
  118. 		if (line[0] == '/' && line[1] == '/')
  119. 			continue;
  120. 		if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
  121. 			continue;
  122.  
  123. 		if (strcmpi(w1, "import") == 0)
  124. 			msg_config_read(w2);
  125. 		else
  126. 		{
  127. 			msg_number = atoi(w1);
  128. 			if (msg_number >= 0 && msg_number < MAX_MSG)
  129. 			{
  130. 				if (msg_table[msg_number] != NULL)
  131. 					aFree(msg_table[msg_number]);
  132. 				msg_table[msg_number] = (char *)aMalloc((strlen(w2) + 1)*sizeof (char));
  133. 				strcpy(msg_table[msg_number],w2);
  134. 			}
  135. 		}
  136. 	}
  137.  
  138. 	fclose(fp);
  139.  
  140. 	return 0;
  141. }
  142.  
  143. /*==========================================
  144.  * Cleanup Message Data
  145.  *------------------------------------------*/
  146. void do_final_msg(void)
  147. {
  148. 	int i;
  149. 	for (i = 0; i < MAX_MSG; i++)
  150. 		aFree(msg_table[i]);
  151. }
  152.  
  153. /**
  154.  * retrieves the help string associated with a given command.
  155.  *
  156.  * @param name the name of the command to retrieve help information for
  157.  * @return the string associated with the command, or NULL
  158.  */
  159. static const char* atcommand_help_string(const char* name)
  160. {
  161. 	const char* str = NULL;
  162. 	config_setting_t* info;
  163.  
  164. 	if( *name == atcommand_symbol || *name == charcommand_symbol )
  165. 	{// remove the prefix symbol for the raw name of the command
  166. 		name ++;
  167. 	}
  168.  
  169. 	// attept to find the first default help command
  170. 	info = config_lookup(&atcommand_config, "help");
  171.  
  172. 	if( info == NULL )
  173. 	{// failed to find the help property in the configuration file
  174. 		return NULL;
  175. 	}
  176.  
  177. 	if( !config_setting_lookup_string( info, name, &str ) )
  178. 	{// failed to find the matching help string
  179. 		return NULL;
  180. 	}
  181.  
  182. 	// push the result from the method
  183. 	return str;
  184. }
  185.  
  186.  
  187. /*==========================================
  188.  * @send (used for testing packet sends from the client)
  189.  *------------------------------------------*/
  190. ACMD_FUNC(send)
  191. {
  192. 	int len=0,off,end,type;
  193. 	long num;
  194.  
  195. 	// read message type as hex number (without the 0x)
  196. 	if(!message || !*message ||
  197. 			!((sscanf(message, "len %x", &type)==1 && (len=1))
  198. 			|| sscanf(message, "%x", &type)==1) )
  199. 	{
  200. 		clif_displaymessage(fd, "Usage:");
  201. 		clif_displaymessage(fd, "	@send len <packet hex number>");
  202. 		clif_displaymessage(fd, "	@send <packet hex number> {<value>}*");
  203. 		clif_displaymessage(fd, "	Value: <type=B(default),W,L><number> or S<length>\"<string>\"");
  204. 		return -1;
  205. 	}
  206.  
  207. #define PARSE_ERROR(error,p) \
  208. 	{\
  209. 		clif_displaymessage(fd, (error));\
  210. 		sprintf(atcmd_output, ">%s", (p));\
  211. 		clif_displaymessage(fd, atcmd_output);\
  212. 	}
  213. //define PARSE_ERROR
  214.  
  215. #define CHECK_EOS(p) \
  216. 	if(*(p) == 0){\
  217. 		clif_displaymessage(fd, "Unexpected end of string");\
  218. 		return -1;\
  219. 	}
  220. //define CHECK_EOS
  221.  
  222. #define SKIP_VALUE(p) \
  223. 	{\
  224. 		while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
  225. 		while(*(p) && ISSPACE(*(p)))  ++(p); /* space */\
  226. 	}
  227. //define SKIP_VALUE
  228.  
  229. #define GET_VALUE(p,num) \
  230. 	{\
  231. 		if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
  232. 			PARSE_ERROR("Invalid number in:",(p));\
  233. 			return -1;\
  234. 		}\
  235. 	}
  236. //define GET_VALUE
  237.  
  238. 	if (type > 0 && type < MAX_PACKET_DB) {
  239.  
  240. 		if(len)
  241. 		{// show packet length
  242. 			sprintf(atcmd_output, "Packet 0x%x length: %d", type, packet_db[sd->packet_ver][type].len);
  243. 			clif_displaymessage(fd, atcmd_output);
  244. 			return 0;
  245. 		}
  246.  
  247. 		len=packet_db[sd->packet_ver][type].len;
  248. 		off=2;
  249. 		if(len == 0)
  250. 		{// unknown packet - ERROR
  251. 			sprintf(atcmd_output, "Unknown packet: 0x%x", type);
  252. 			clif_displaymessage(fd, atcmd_output);
  253. 			return -1;
  254. 		} else if(len == -1)
  255. 		{// dynamic packet
  256. 			len=SHRT_MAX-4; // maximum length
  257. 			off=4;
  258. 		}
  259. 		WFIFOHEAD(fd, len);
  260. 		WFIFOW(fd,0)=TOW(type);
  261.  
  262. 		// parse packet contents
  263. 		SKIP_VALUE(message);
  264. 		while(*message != 0 && off < len){
  265. 			if(ISDIGIT(*message) || *message == '-' || *message == '+')
  266. 			{// default (byte)
  267. 				GET_VALUE(message,num);
  268. 				WFIFOB(fd,off)=TOB(num);
  269. 				++off;
  270. 			} else if(TOUPPER(*message) == 'B')
  271. 			{// byte
  272. 				++message;
  273. 				GET_VALUE(message,num);
  274. 				WFIFOB(fd,off)=TOB(num);
  275. 				++off;
  276. 			} else if(TOUPPER(*message) == 'W')
  277. 			{// word (2 bytes)
  278. 				++message;
  279. 				GET_VALUE(message,num);
  280. 				WFIFOW(fd,off)=TOW(num);
  281. 				off+=2;
  282. 			} else if(TOUPPER(*message) == 'L')
  283. 			{// long word (4 bytes)
  284. 				++message;
  285. 				GET_VALUE(message,num);
  286. 				WFIFOL(fd,off)=TOL(num);
  287. 				off+=4;
  288. 			} else if(TOUPPER(*message) == 'S')
  289. 			{// string - escapes are valid
  290. 				// get string length - num <= 0 means not fixed length (default)
  291. 				++message;
  292. 				if(*message == '"'){
  293. 					num=0;
  294. 				} else {
  295. 					GET_VALUE(message,num);
  296. 					while(*message != '"')
  297. 					{// find start of string
  298. 						if(*message == 0 || ISSPACE(*message)){
  299. 							PARSE_ERROR("Not a string:",message);
  300. 							return -1;
  301. 						}
  302. 						++message;
  303. 					}
  304. 				}
  305.  
  306. 				// parse string
  307. 				++message;
  308. 				CHECK_EOS(message);
  309. 				end=(num<=0? 0: min(off+((int)num),len));
  310. 				for(; *message != '"' && (off < end || end == 0); ++off){
  311. 					if(*message == '\\'){
  312. 						++message;
  313. 						CHECK_EOS(message);
  314. 						switch(*message){
  315. 							case 'a': num=0x07; break; // Bell
  316. 							case 'b': num=0x08; break; // Backspace
  317. 							case 't': num=0x09; break; // Horizontal tab
  318. 							case 'n': num=0x0A; break; // Line feed
  319. 							case 'v': num=0x0B; break; // Vertical tab
  320. 							case 'f': num=0x0C; break; // Form feed
  321. 							case 'r': num=0x0D; break; // Carriage return
  322. 							case 'e': num=0x1B; break; // Escape
  323. 							default:  num=*message; break;
  324. 							case 'x': // Hexadecimal
  325. 							{
  326. 								++message;
  327. 								CHECK_EOS(message);
  328. 								if(!ISXDIGIT(*message)){
  329. 									PARSE_ERROR("Not a hexadecimal digit:",message);
  330. 									return -1;
  331. 								}
  332. 								num=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  333. 								if(ISXDIGIT(*message)){
  334. 									++message;
  335. 									CHECK_EOS(message);
  336. 									num<<=8;
  337. 									num+=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  338. 								}
  339. 								WFIFOB(fd,off)=TOB(num);
  340. 								++message;
  341. 								CHECK_EOS(message);
  342. 								continue;
  343. 							}
  344. 							case '0':
  345. 							case '1':
  346. 							case '2':
  347. 							case '3':
  348. 							case '4':
  349. 							case '5':
  350. 							case '6':
  351. 							case '7': // Octal
  352. 							{
  353. 								num=*message-'0'; // 1st octal digit
  354. 								++message;
  355. 								CHECK_EOS(message);
  356. 								if(ISDIGIT(*message) && *message < '8'){
  357. 									num<<=3;
  358. 									num+=*message-'0'; // 2nd octal digit
  359. 									++message;
  360. 									CHECK_EOS(message);
  361. 									if(ISDIGIT(*message) && *message < '8'){
  362. 										num<<=3;
  363. 										num+=*message-'0'; // 3rd octal digit
  364. 										++message;
  365. 										CHECK_EOS(message);
  366. 									}
  367. 								}
  368. 								WFIFOB(fd,off)=TOB(num);
  369. 								continue;
  370. 							}
  371. 						}
  372. 					} else
  373. 						num=*message;
  374. 					WFIFOB(fd,off)=TOB(num);
  375. 					++message;
  376. 					CHECK_EOS(message);
  377. 				}//for
  378. 				while(*message != '"')
  379. 				{// ignore extra characters
  380. 					++message;
  381. 					CHECK_EOS(message);
  382. 				}
  383.  
  384. 				// terminate the string
  385. 				if(off < end)
  386. 				{// fill the rest with 0's
  387. 					memset(WFIFOP(fd,off),0,end-off);
  388. 					off=end;
  389. 				}
  390. 			} else
  391. 			{// unknown
  392. 				PARSE_ERROR("Unknown type of value in:",message);
  393. 				return -1;
  394. 			}
  395. 			SKIP_VALUE(message);
  396. 		}
  397.  
  398. 		if(packet_db[sd->packet_ver][type].len == -1)
  399. 		{// send dynamic packet
  400. 			WFIFOW(fd,2)=TOW(off);
  401. 			WFIFOSET(fd,off);
  402. 		} else
  403. 		{// send static packet
  404. 			if(off < len)
  405. 				memset(WFIFOP(fd,off),0,len-off);
  406. 			WFIFOSET(fd,len);
  407. 		}
  408. 	} else {
  409. 		clif_displaymessage(fd, msg_txt(259)); // Invalid packet
  410. 		return -1;
  411. 	}
  412. 	sprintf (atcmd_output, msg_txt(258), type, type); // Sent packet 0x%x (%d)
  413. 	clif_displaymessage(fd, atcmd_output);
  414. 	return 0;
  415. #undef PARSE_ERROR
  416. #undef CHECK_EOS
  417. #undef SKIP_VALUE
  418. #undef GET_VALUE
  419. }
  420.  
  421. /*==========================================
  422.  * @rura, @warp, @mapmove
  423.  *------------------------------------------*/
  424. ACMD_FUNC(mapmove)
  425. {
  426.         char map_name[MAP_NAME_LENGTH_EXT];
  427.         unsigned short mapindex;
  428.         short x = 0, y = 0;
  429.         int m = -1;
  430.  
  431.         nullpo_retr(-1, sd);
  432.  
  433.         memset(map_name, '\0', sizeof(map_name));
  434.  
  435.         if (!message || !*message ||
  436.                 (sscanf(message, "%15s %hd %hd", map_name, &x, &y) < 3 &&
  437.                  sscanf(message, "%15[^,],%hd,%hd", map_name, &x, &y) < 1)) {
  438.  
  439.                         clif_displaymessage(fd, "Please, enter a map (usage: @warp/@rura/@mapmove <mapname> <x> <y>).");
  440.                         return -1;
  441.         }
  442.  
  443.         mapindex = mapindex_name2id(map_name);
  444.         if (mapindex)
  445.                 m = map_mapindex2mapid(mapindex);
  446.  
  447.         if ( status_isdead(&sd->bl) ) {
  448.                 clif_displaymessage(fd,"You can not use @warp while dead.");
  449.                 return 0;
  450.         }
  451.  
  452.         if (!mapindex) { // m < 0 means on different server! [Kevin]
  453.                 clif_displaymessage(fd, msg_txt(1)); // Map not found.
  454.                 return -1;
  455.         }
  456.  
  457.         if ((x || y) && map_getcell(m, x, y, CELL_CHKNOPASS))
  458.           {     //This is to prevent the pc_setpos call from printing an error.
  459.                 clif_displaymessage(fd, msg_txt(2));
  460.                 if (!map_search_freecell(NULL, m, &x, &y, 10, 10, 1))
  461.                         x = y = 0; //Invalid cell, use random spot.
  462.         }
  463.         if (map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  464.                 clif_displaymessage(fd, msg_txt(247));
  465.                 return -1;
  466.         }
  467.         if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  468.                 clif_displaymessage(fd, msg_txt(248));
  469.                 return -1;
  470.         }
  471.         if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != 0) {
  472.                 clif_displaymessage(fd, msg_txt(1)); // Map not found.
  473.                 return -1;
  474.         }
  475.  
  476.         clif_displaymessage(fd, msg_txt(0)); // Warped.
  477.         return 0;
  478. }
  479.  
  480. ACMD_FUNC(jumpto)
  481. {
  482. 	struct map_session_data *pl_sd = NULL;
  483.  
  484. 	nullpo_retr(-1, sd);
  485.  
  486. 	if (!message || !*message) {
  487. 		clif_displaymessage(fd, "Please, enter a player name (usage: @jumpto/@warpto/@goto <player name/id>).");
  488. 		return -1;
  489. 	}
  490.  
  491. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  492. 	{
  493. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  494. 		return -1;
  495. 	}
  496.  
  497. 	if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  498. 	{
  499. 		clif_displaymessage(fd, msg_txt(247));	// You are not authorized to warp to this map.
  500. 		return -1;
  501. 	}
  502.  
  503. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  504. 	{
  505. 		clif_displaymessage(fd, msg_txt(248));	// You are not authorized to warp from your current map.
  506. 		return -1;
  507. 	}
  508.  
  509. 	if( pc_isdead(sd) )
  510. 	{
  511. 		clif_displaymessage(fd, "You cannot use this command when dead.");
  512. 		return -1;
  513. 	}
  514.  
  515. 	pc_setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  516. 	sprintf(atcmd_output, msg_txt(4), pl_sd->status.name); // Jumped to %s
  517.  	clif_displaymessage(fd, atcmd_output);
  518.  
  519. 	return 0;
  520. }
  521.  
  522. /*==========================================
  523.  *
  524.  *------------------------------------------*/
  525. ACMD_FUNC(jump)
  526. {
  527. 	short x = 0, y = 0;
  528.  
  529. 	nullpo_retr(-1, sd);
  530.  
  531. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  532.  
  533. 	sscanf(message, "%hd %hd", &x, &y);
  534.  
  535. 	if (map[sd->bl.m].flag.noteleport && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  536. 		clif_displaymessage(fd, msg_txt(248));	// You are not authorized to warp from your current map.
  537. 		return -1;
  538. 	}
  539.  
  540. 	if( pc_isdead(sd) )
  541. 	{
  542. 		clif_displaymessage(fd, "You cannot use this command when dead.");
  543. 		return -1;
  544. 	}
  545.  
  546. 	if ((x || y) && map_getcell(sd->bl.m, x, y, CELL_CHKNOPASS))
  547.   	{	//This is to prevent the pc_setpos call from printing an error.
  548. 		clif_displaymessage(fd, msg_txt(2));
  549. 		if (!map_search_freecell(NULL, sd->bl.m, &x, &y, 10, 10, 1))
  550. 			x = y = 0; //Invalid cell, use random spot.
  551. 	}
  552.  
  553. 	pc_setpos(sd, sd->mapindex, x, y, CLR_TELEPORT);
  554. 	sprintf(atcmd_output, msg_txt(5), sd->bl.x, sd->bl.y); // Jumped to %d %d
  555. 	clif_displaymessage(fd, atcmd_output);
  556. 	return 0;
  557. }
  558.  
  559. /*==========================================
  560.  * Display list of online characters with
  561.  * various info.
  562.  *------------------------------------------*/
  563. ACMD_FUNC(who)
  564. {
  565. 	struct map_session_data *pl_sd = NULL;
  566. 	struct s_mapiterator *iter = NULL;
  567. 	char map_name[MAP_NAME_LENGTH_EXT] = "";
  568. 	char player_name[NAME_LENGTH] = "";
  569. 	int count = 0;
  570. 	int level = 0;
  571. 	StringBuf buf;
  572. 	/**
  573. 	 * 1 = @who  : Player name, [Title], [Party name], [Guild name]
  574. 	 * 2 = @who2 : Player name, [Title], BLvl, JLvl, Job
  575. 	 * 3 = @who3 : [CID/AID] Player name [Title], Map, X, Y
  576. 	 */
  577. 	int display_type = 1;
  578. 	int map_id = -1;
  579.  
  580. 	nullpo_retr(-1, sd);
  581.  
  582. 	if (strstr(command, "map") != NULL) {
  583. 		if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map_mapname2mapid(map_name)) < 0)
  584. 			map_id = sd->bl.m;
  585. 	} else {
  586. 		sscanf(message, "%23s", player_name);
  587. 	}
  588.  
  589. 	if (strstr(command, "2") != NULL)
  590. 		display_type = 2;
  591. 	else if (strstr(command, "3") != NULL)
  592. 		display_type = 3;
  593.  
  594. 	level = pc_get_group_level(sd);
  595. 	StringBuf_Init(&buf);
  596.  
  597. 	iter = mapit_getallusers();
  598. 	for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter))	{
  599. 		if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || (pl_sd->sc.option & OPTION_INVISIBLE)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level
  600. 			if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive
  601. 				|| (map_id >= 0 && pl_sd->bl.m != map_id))
  602. 				continue;
  603. 			switch (display_type) {
  604. 				case 2: {
  605. 					StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  606. 					if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  607. 						StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  608. 					StringBuf_Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level,
  609. 						job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s"
  610. 					break;
  611. 				}
  612. 				case 3: {
  613. 					if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  614. 						StringBuf_Printf(&buf, "(CID:%d/AID:%d) ", pl_sd->status.char_id, pl_sd->status.account_id);
  615. 					StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  616. 					if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  617. 						StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  618. 					StringBuf_Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d"
  619. 					break;
  620. 				}
  621. 				default: {
  622. 					struct party_data *p = party_search(pl_sd->status.party_id);
  623. 					struct guild *g = guild_search(pl_sd->status.guild_id);
  624.  
  625. 					StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  626. 					if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  627. 						StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  628. 					if (p != NULL)
  629. 						StringBuf_Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'"
  630. 					if (g != NULL)
  631. 						StringBuf_Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'"
  632. 					break;
  633. 				}
  634. 			}
  635. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  636. 			StringBuf_Clear(&buf);
  637. 			count++;
  638. 		}
  639. 	}
  640. 	mapit_free(iter);
  641.  
  642. 	if (map_id < 0) {
  643. 		if (count == 0)
  644. 			StringBuf_Printf(&buf, msg_txt(28)); // No player found.
  645. 		else if (count == 1)
  646. 			StringBuf_Printf(&buf, msg_txt(29)); // 1 player found.
  647. 		else
  648. 			StringBuf_Printf(&buf, msg_txt(30), count); // %d players found.
  649. 	} else {
  650. 		if (count == 0)
  651. 			StringBuf_Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'.
  652. 		else if (count == 1)
  653. 			StringBuf_Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'.
  654. 		else
  655. 			StringBuf_Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'.
  656. 	}
  657. 	clif_displaymessage(fd, StringBuf_Value(&buf));
  658. 	StringBuf_Destroy(&buf);
  659. 	return 0;
  660. }
  661.  
  662. /*==========================================
  663.  *
  664.  *------------------------------------------*/
  665. ACMD_FUNC(whogm)
  666. {
  667. 	struct map_session_data* pl_sd;
  668. 	struct s_mapiterator* iter;
  669. 	int j, count;
  670. 	int pl_level, level;
  671. 	char match_text[CHAT_SIZE_MAX];
  672. 	char player_name[NAME_LENGTH];
  673. 	struct guild *g;
  674. 	struct party_data *p;
  675.  
  676. 	nullpo_retr(-1, sd);
  677.  
  678. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  679. 	memset(match_text, '\0', sizeof(match_text));
  680. 	memset(player_name, '\0', sizeof(player_name));
  681.  
  682. 	if (sscanf(message, "%199[^\n]", match_text) < 1)
  683. 		strcpy(match_text, "");
  684. 	for (j = 0; match_text[j]; j++)
  685. 		match_text[j] = TOLOWER(match_text[j]);
  686.  
  687. 	count = 0;
  688. 	level = pc_get_group_level(sd);
  689.  
  690. 	iter = mapit_getallusers();
  691. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  692. 	{
  693. 		pl_level = pc_get_group_level(pl_sd);
  694. 		if (!pl_level)
  695. 			continue;
  696.  
  697. 		if (match_text[0])
  698. 		{
  699. 			memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
  700. 			for (j = 0; player_name[j]; j++)
  701. 				player_name[j] = TOLOWER(player_name[j]);
  702. 		  	// search with no case sensitive
  703. 			if (strstr(player_name, match_text) == NULL)
  704. 				continue;
  705. 		}
  706. 		if (pl_level > level) {
  707. 			if (pl_sd->sc.option & OPTION_INVISIBLE)
  708. 				continue;
  709. 			sprintf(atcmd_output, "Name: %s (GM)", pl_sd->status.name);
  710. 			clif_displaymessage(fd, atcmd_output);
  711. 			count++;
  712. 			continue;
  713. 		}
  714.  
  715. 		sprintf(atcmd_output, "Name: %s (GM:%d) | Location: %s %d %d",
  716. 			pl_sd->status.name, pl_level,
  717. 			mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  718. 		clif_displaymessage(fd, atcmd_output);
  719.  
  720. 		sprintf(atcmd_output, "       BLvl: %d | Job: %s (Lvl: %d)",
  721. 			pl_sd->status.base_level,
  722. 			job_name(pl_sd->status.class_), pl_sd->status.job_level);
  723. 		clif_displaymessage(fd, atcmd_output);
  724.  
  725. 		p = party_search(pl_sd->status.party_id);
  726. 		g = guild_search(pl_sd->status.guild_id);
  727.  
  728. 		sprintf(atcmd_output,"       Party: '%s' | Guild: '%s'",
  729. 			p?p->party.name:"None", g?g->name:"None");
  730.  
  731. 		clif_displaymessage(fd, atcmd_output);
  732. 		count++;
  733. 	}
  734. 	mapit_free(iter);
  735.  
  736. 	if (count == 0)
  737. 		clif_displaymessage(fd, msg_txt(150)); // No GM found.
  738. 	else if (count == 1)
  739. 		clif_displaymessage(fd, msg_txt(151)); // 1 GM found.
  740. 	else {
  741. 		sprintf(atcmd_output, msg_txt(152), count); // %d GMs found.
  742. 		clif_displaymessage(fd, atcmd_output);
  743. 	}
  744.  
  745. 	return 0;
  746. }
  747.  
  748. /*==========================================
  749.  *
  750.  *------------------------------------------*/
  751. ACMD_FUNC(save)
  752. {
  753. 	nullpo_retr(-1, sd);
  754.  
  755. 	pc_setsavepoint(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  756. 	if (sd->status.pet_id > 0 && sd->pd)
  757. 		intif_save_petdata(sd->status.account_id, &sd->pd->pet);
  758.  
  759. 	chrif_save(sd,0);
  760.  
  761. 	clif_displaymessage(fd, msg_txt(6)); // Your save point has been changed.
  762.  
  763. 	return 0;
  764. }
  765.  
  766. /*==========================================
  767.  *
  768.  *------------------------------------------*/
  769. ACMD_FUNC(load)
  770. {
  771. 	int m;
  772.  
  773. 	nullpo_retr(-1, sd);
  774.  
  775. 	m = map_mapindex2mapid(sd->status.save_point.map);
  776. 	if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  777. 		clif_displaymessage(fd, msg_txt(249));	// You are not authorized to warp to your save map.
  778. 		return -1;
  779. 	}
  780. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  781. 		clif_displaymessage(fd, msg_txt(248));	// You are not authorized to warp from your current map.
  782. 		return -1;
  783. 	}
  784.  
  785. 	pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_OUTSIGHT);
  786. 	clif_displaymessage(fd, msg_txt(7)); // Warping to save point..
  787.  
  788. 	return 0;
  789. }
  790.  
  791. /*==========================================
  792.  *
  793.  *------------------------------------------*/
  794. ACMD_FUNC(speed)
  795. {
  796. 	int speed;
  797.  
  798. 	nullpo_retr(-1, sd);
  799.  
  800. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  801.  
  802. 	if (!message || !*message || sscanf(message, "%d", &speed) < 1) {
  803. 		sprintf(atcmd_output, "Please, enter a speed value (usage: @speed <%d-%d>).", MIN_WALK_SPEED, MAX_WALK_SPEED);
  804. 		clif_displaymessage(fd, atcmd_output);
  805. 		return -1;
  806. 	}
  807.  
  808. 	sd->base_status.speed = cap_value(speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
  809. 	status_calc_bl(&sd->bl, SCB_SPEED);
  810. 	clif_displaymessage(fd, msg_txt(8)); // Speed changed.
  811. 	return 0;
  812. }
  813.  
  814. /*==========================================
  815.  *
  816.  *------------------------------------------*/
  817. ACMD_FUNC(storage)
  818. {
  819. 	nullpo_retr(-1, sd);
  820.  
  821. 	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
  822. 		return -1;
  823.  
  824. 	if (storage_storageopen(sd) == 1)
  825. 	{	//Already open.
  826. 		clif_displaymessage(fd, msg_txt(250));
  827. 		return -1;
  828. 	}
  829.  
  830. 	clif_displaymessage(fd, "Storage opened.");
  831.  
  832. 	return 0;
  833. }
  834.  
  835.  
  836. /*==========================================
  837.  *
  838.  *------------------------------------------*/
  839. ACMD_FUNC(guildstorage)
  840. {
  841. 	nullpo_retr(-1, sd);
  842.  
  843. 	if (!sd->status.guild_id) {
  844. 		clif_displaymessage(fd, msg_txt(252));
  845. 		return -1;
  846. 	}
  847.  
  848. 	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading)
  849. 		return -1;
  850.  
  851. 	if (sd->state.storage_flag == 1) {
  852. 		clif_displaymessage(fd, msg_txt(250));
  853. 		return -1;
  854. 	}
  855.  
  856. 	if (sd->state.storage_flag == 2) {
  857. 		clif_displaymessage(fd, msg_txt(251));
  858. 		return -1;
  859. 	}
  860.  
  861. 	storage_guild_storageopen(sd);
  862. 	clif_displaymessage(fd, "Guild storage opened.");
  863. 	return 0;
  864. }
  865.  
  866. /*==========================================
  867.  *
  868.  *------------------------------------------*/
  869. ACMD_FUNC(option)
  870. {
  871. 	int param1 = 0, param2 = 0, param3 = 0;
  872. 	nullpo_retr(-1, sd);
  873.  
  874. 	if (!message || !*message || sscanf(message, "%d %d %d", &param1, &param2, &param3) < 1 || param1 < 0 || param2 < 0 || param3 < 0)
  875. 	{// failed to match the parameters so inform the user of the options
  876. 		const char* text = NULL;
  877.  
  878. 		// attempt to find the setting information for this command
  879. 		text = atcommand_help_string( command );
  880.  
  881. 		// notify the user of the requirement to enter an option
  882. 		clif_displaymessage(fd, "Please, enter at least one option..");
  883.  
  884. 		if( text )
  885. 		{// send the help text associated with this command
  886. 			clif_displaymessage( fd, text );
  887. 		}
  888.  
  889. 		return -1;
  890. 	}
  891.  
  892. 	sd->sc.opt1 = param1;
  893. 	sd->sc.opt2 = param2;
  894. 	pc_setoption(sd, param3);
  895.  
  896. 	clif_displaymessage(fd, msg_txt(9)); // Options changed.
  897.  
  898. 	return 0;
  899. }
  900.  
  901. /*==========================================
  902.  *
  903.  *------------------------------------------*/
  904. ACMD_FUNC(hide)
  905. {
  906. 	nullpo_retr(-1, sd);
  907. 	if (sd->sc.option & OPTION_INVISIBLE) {
  908. 		sd->sc.option &= ~OPTION_INVISIBLE;
  909. 		if (sd->disguise)
  910. 			status_set_viewdata(&sd->bl, sd->disguise);
  911. 		else
  912. 			status_set_viewdata(&sd->bl, sd->status.class_);
  913. 		clif_displaymessage(fd, msg_txt(10)); // Invisible: Off
  914.  
  915. 		// increment the number of pvp players on the map
  916. 		map[sd->bl.m].users_pvp++;
  917.  
  918. 		if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank )
  919. 		{// register the player for ranking calculations
  920. 			sd->pvp_timer = add_timer( gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0 );
  921. 		}
  922. 		//bugreport:2266
  923. 		map_foreachinmovearea(clif_insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl);
  924. 	} else {
  925. 		sd->sc.option |= OPTION_INVISIBLE;
  926. 		sd->vd.class_ = INVISIBLE_CLASS;
  927. 		clif_displaymessage(fd, msg_txt(11)); // Invisible: On
  928.  
  929. 		// decrement the number of pvp players on the map
  930. 		map[sd->bl.m].users_pvp--;
  931.  
  932. 		if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER )
  933. 		{// unregister the player for ranking
  934. 			delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  935. 			sd->pvp_timer = INVALID_TIMER;
  936. 		}
  937. 	}
  938. 	clif_changeoption(&sd->bl);
  939.  
  940. 	return 0;
  941. }
  942.  
  943. /*==========================================
  944.  * Changes a character's class
  945.  *------------------------------------------*/
  946. ACMD_FUNC(jobchange)
  947. {
  948. 	//FIXME: redundancy, potentially wrong code, should use job_name() or similar instead of hardcoding the table [ultramage]
  949. 	int job = 0, upper = 0;
  950. 	nullpo_retr(-1, sd);
  951.  
  952. 	if (!message || !*message || sscanf(message, "%d %d", &job, &upper) < 1)
  953. 	{
  954. 		int i, found = 0;
  955. 		const struct { char name[24]; int id; } jobs[] = {
  956. 			{ "novice",		0 },
  957. 			{ "swordman",	1 },
  958. 			{ "swordsman",	1 },
  959. 			{ "magician",	2 },
  960. 			{ "mage",		2 },
  961. 			{ "archer",		3 },
  962. 			{ "acolyte",	4 },
  963. 			{ "merchant",	5 },
  964. 			{ "thief",		6 },
  965. 			{ "knight",		7 },
  966. 			{ "priest",		8 },
  967. 			{ "priestess",	8 },
  968. 			{ "wizard",		9 },
  969. 			{ "blacksmith",	10 },
  970. 			{ "hunter",		11 },
  971. 			{ "assassin",	12 },
  972. 			{ "crusader",	14 },
  973. 			{ "monk",		15 },
  974. 			{ "sage",		16 },
  975. 			{ "rogue",		17 },
  976. 			{ "alchemist",	18 },
  977. 			{ "bard",		19 },
  978. 			{ "dancer",		20 },
  979. 			{ "super novice",	23 },
  980. 			{ "supernovice",	23 },
  981. 			{ "gunslinger",	24 },
  982. 			{ "gunner",	24 },
  983. 			{ "ninja",	25 },
  984. 			{ "novice high",	4001 },
  985. 			{ "high novice",	4001 },
  986. 			{ "swordman high",	4002 },
  987. 			{ "swordsman high",	4002 },
  988. 			{ "magician high",	4003 },
  989. 			{ "mage high",		4003 },
  990. 			{ "archer high",	4004 },
  991. 			{ "acolyte high",	4005 },
  992. 			{ "merchant high",	4006 },
  993. 			{ "thief high",		4007 },
  994. 			{ "lord knight",	4008 },
  995. 			{ "high priest",	4009 },
  996. 			{ "high priestess",	4009 },
  997. 			{ "high wizard",	4010 },
  998. 			{ "whitesmith",		4011 },
  999. 			{ "sniper",		4012 },
  1000. 			{ "assassin cross",	4013 },
  1001. 			{ "paladin",	4015 },
  1002. 			{ "champion",	4016 },
  1003. 			{ "professor",	4017 },
  1004. 			{ "stalker",	4018 },
  1005. 			{ "creator",	4019 },
  1006. 			{ "clown",		4020 },
  1007. 			{ "gypsy",		4021 },
  1008. 			{ "baby novice",	4023 },
  1009. 			{ "baby swordman",	4024 },
  1010. 			{ "baby swordsman",	4024 },
  1011. 			{ "baby magician",	4025 },
  1012. 			{ "baby mage",		4025 },
  1013. 			{ "baby archer",	4026 },
  1014. 			{ "baby acolyte",	4027 },
  1015. 			{ "baby merchant",	4028 },
  1016. 			{ "baby thief",		4029 },
  1017. 			{ "baby knight",	4030 },
  1018. 			{ "baby priest",	4031 },
  1019. 			{ "baby priestess",	4031 },
  1020. 			{ "baby wizard",	4032 },
  1021. 			{ "baby blacksmith",4033 },
  1022. 			{ "baby hunter",	4034 },
  1023. 			{ "baby assassin",	4035 },
  1024. 			{ "baby crusader",	4037 },
  1025. 			{ "baby monk",		4038 },
  1026. 			{ "baby sage",		4039 },
  1027. 			{ "baby rogue",		4040 },
  1028. 			{ "baby alchemist",	4041 },
  1029. 			{ "baby bard",		4042 },
  1030. 			{ "baby dancer",	4043 },
  1031. 			{ "super baby",		4045 },
  1032. 			{ "taekwon",		4046 },
  1033. 			{ "taekwon boy",	4046 },
  1034. 			{ "taekwon girl",	4046 },
  1035. 			{ "star gladiator",	4047 },
  1036. 			{ "soul linker",	4049 },
  1037. 			{ "gangsi",		4050 },
  1038. 			{ "bongun",		4050 },
  1039. 			{ "munak",		4050 },
  1040. 			{ "death knight",	4051 },
  1041. 			{ "dark collector",	4052 },
  1042. 			{ "rune knight",	4054 },
  1043. 			{ "warlock",		4055 },
  1044. 			{ "ranger",		4056 },
  1045. 			{ "arch bishop",	4057 },
  1046. 			{ "mechanic",		4058 },
  1047. 			{ "guillotine",		4059 },
  1048. 			{ "rune knight2",	4060 },
  1049. 			{ "warlock2",		4061 },
  1050. 			{ "ranger2",		4062 },
  1051. 			{ "arch bishop2",	4063 },
  1052. 			{ "mechanic2",		4064 },
  1053. 			{ "guillotine2",	4065 },
  1054. 			{ "royal guard",	4066 },
  1055. 			{ "sorcerer",		4067 },
  1056. 			{ "minstrel",		4068 },
  1057. 			{ "wanderer",		4069 },
  1058. 			{ "sura",		4070 },
  1059. 			{ "genetic",		4071 },
  1060. 			{ "shadow chaser",	4072 },
  1061. 			{ "royal guard2",	4073 },
  1062. 			{ "sorcerer2",		4074 },
  1063. 			{ "minstrel2",		4075 },
  1064. 			{ "wanderer2",		4076 },
  1065. 			{ "sura2",		4077 },
  1066. 			{ "genetic2",		4078 },
  1067. 			{ "shadow chaser2",	4079 },
  1068. 			{ "baby rune",		4096 },
  1069. 			{ "baby warlock",	4097 },
  1070. 			{ "baby ranger",	4098 },
  1071. 			{ "baby bishop",	4099 },
  1072. 			{ "baby mechanic",	4100 },
  1073. 			{ "baby cross",		4101 },
  1074. 			{ "baby guard",		4102 },
  1075. 			{ "baby sorcerer",	4103 },
  1076. 			{ "baby minstrel",	4104 },
  1077. 			{ "baby wanderer",	4105 },
  1078. 			{ "baby sura",		4106 },
  1079. 			{ "baby genetic",	4107 },
  1080. 			{ "baby chaser",	4108 },
  1081. 			{ "super novice e",	4190 },
  1082. 			{ "super baby e",	4191 },
  1083. 			{ "kagerou",		4211 },
  1084. 			{ "oboro",		4212 },
  1085. 		};
  1086.  
  1087. 		for (i=0; i < ARRAYLENGTH(jobs); i++) {
  1088. 			if (strncmpi(message, jobs[i].name, 16) == 0) {
  1089. 				job = jobs[i].id;
  1090. 				upper = 0;
  1091. 				found = 1;
  1092. 				break;
  1093. 			}
  1094. 		}
  1095.  
  1096. 		// TODO: convert this to use atcommand_help_string()
  1097. 		if (!found) {
  1098. 			clif_displaymessage(fd, "Please, enter a job ID (usage: @job/@jobchange <job name/ID>).");
  1099. 			clif_displaymessage(fd, "----- Novice / 1st Class -----");
  1100. 			clif_displaymessage(fd, "   0 Novice              1 Swordman            2 Magician            3 Archer");
  1101. 			clif_displaymessage(fd, "   4 Acolyte             5 Merchant            6 Thief");
  1102. 			clif_displaymessage(fd, "----- 2nd Class -----");
  1103. 			clif_displaymessage(fd, "   7 Knight              8 Priest              9 Wizard             10 Blacksmith");
  1104. 			clif_displaymessage(fd, "  11 Hunter             12 Assassin           14 Crusader           15 Monk");
  1105. 			clif_displaymessage(fd, "  16 Sage               17 Rogue              18 Alchemist          19 Bard");
  1106. 			clif_displaymessage(fd, "  20 Dancer");
  1107. 			clif_displaymessage(fd, "----- High Novice / High 1st Class -----");
  1108. 			clif_displaymessage(fd, "4001 Novice High      4002 Swordman High    4003 Magician High    4004 Archer High");
  1109. 			clif_displaymessage(fd, "4005 Acolyte High     4006 Merchant High    4007 Thief High");
  1110. 			clif_displaymessage(fd, "----- Transcendent 2nd Class -----");
  1111. 			clif_displaymessage(fd, "4008 Lord Knight      4009 High Priest      4010 High Wizard      4011 Whitesmith");
  1112. 			clif_displaymessage(fd, "4012 Sniper           4013 Assassin Cross   4015 Paladin          4016 Champion");
  1113. 			clif_displaymessage(fd, "4017 Professor        4018 Stalker          4019 Creator          4020 Clown");
  1114. 			clif_displaymessage(fd, "4021 Gypsy");
  1115. 			clif_displaymessage(fd, "----- 3rd Class (Regular) -----");
  1116. 			clif_displaymessage(fd, "4054 Rune Knight      4055 Warlock          4056 Ranger           4057 Arch Bishop");
  1117. 			clif_displaymessage(fd, "4058 Mechanic         4059 Guillotine Cross 4066 Royal Guard      4067 Sorcerer");
  1118. 			clif_displaymessage(fd, "4068 Minstrel         4069 Wanderer         4070 Sura             4071 Genetic");
  1119. 			clif_displaymessage(fd, "4072 Shadow Chaser");
  1120. 			clif_displaymessage(fd, "----- 3rd Class (Transcendent) -----");
  1121. 			clif_displaymessage(fd, "4060 Rune Knight      4061 Warlock          4062 Ranger           4063 Arch Bishop");
  1122. 			clif_displaymessage(fd, "4064 Mechanic         4065 Guillotine Cross 4073 Royal Guard      4074 Sorcerer");
  1123. 			clif_displaymessage(fd, "4075 Minstrel         4076 Wanderer         4077 Sura             4078 Genetic");
  1124. 			clif_displaymessage(fd, "4079 Shadow Chaser");
  1125. 			clif_displaymessage(fd, "----- Expanded Class -----");
  1126. 			clif_displaymessage(fd, "  23 Super Novice       24 Gunslinger         25 Ninja            4045 Super Baby");
  1127. 			clif_displaymessage(fd, "4046 Taekwon          4047 Star Gladiator   4049 Soul Linker      4050 Gangsi");
  1128. 			clif_displaymessage(fd, "4051 Death Knight     4052 Dark Collector   4190 Ex. Super Novice 4191 Ex. Super Baby");
  1129. 			clif_displaymessage(fd, "4211 Kagerou          4212 Oboro");
  1130. 			clif_displaymessage(fd, "----- Baby Novice And Baby 1st Class -----");
  1131. 			clif_displaymessage(fd, "4023 Baby Novice      4024 Baby Swordman    4025 Baby Magician    4026 Baby Archer");
  1132. 			clif_displaymessage(fd, "4027 Baby Acolyte     4028 Baby Merchant    4029 Baby Thief");
  1133. 			clif_displaymessage(fd, "---- Baby 2nd Class ----");
  1134. 			clif_displaymessage(fd, "4030 Baby Knight      4031 Baby Priest      4032 Baby Wizard      4033 Baby Blacksmith");
  1135. 			clif_displaymessage(fd, "4034 Baby Hunter      4035 Baby Assassin    4037 Baby Crusader    4038 Baby Monk");
  1136. 			clif_displaymessage(fd, "4039 Baby Sage        4040 Baby Rogue       4041 Baby Alchemist   4042 Baby Bard");
  1137. 			clif_displaymessage(fd, "4043 Baby Dancer");
  1138. 			clif_displaymessage(fd, "---- Baby 3rd Class ----");
  1139. 			clif_displaymessage(fd, "4096 Baby Rune Knight 4097 Baby Warlock     4098 Baby Ranger      4099 Baby Arch Bishop");
  1140. 			clif_displaymessage(fd, "4100 Baby Mechanic    4101 Baby Glt. Cross  4102 Baby Royal Guard 4103 Baby Sorcerer");
  1141. 			clif_displaymessage(fd, "4104 Baby Minstrel    4105 Baby Wanderer    4106 Baby Sura        4107 Baby Genetic");
  1142. 			clif_displaymessage(fd, "4108 Baby Shadow Chaser");
  1143. 			//clif_displaymessage(fd, "---- Modes And Others ----");
  1144. 			//clif_displaymessage(fd, "  22 Wedding            26 Christmas          27 Summer           4048 Star Gladiator (Union)");
  1145. 			return -1;
  1146. 		}
  1147. 	}
  1148.  
  1149. 	if (job == 13 || job == 21 || job == 22 || job == 26 || job == 27 || job == 4014 || job == 4022 || job == 4036 || job == 4044 || job == 4048
  1150. 		 || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2)
  1151. 	) // Deny direct transformation into dummy jobs
  1152. 		{clif_displaymessage(fd, "You can not change to this job by command.");
  1153. 		return 0;}
  1154.  
  1155. 	if (pcdb_checkid(job))
  1156. 	{
  1157. 		if (pc_jobchange(sd, job, upper) == 0)
  1158. 			clif_displaymessage(fd, msg_txt(12)); // Your job has been changed.
  1159. 		else {
  1160. 			clif_displaymessage(fd, msg_txt(155)); // You are unable to change your job.
  1161. 			return -1;
  1162. 		}
  1163. 	} else {
  1164. 			// TODO: convert this to use atcommand_help_string()
  1165. 			clif_displaymessage(fd, "Please enter a valid job ID (usage: @job/@jobchange <job name/ID>).");
  1166. 			clif_displaymessage(fd, "----- Novice / 1st Class -----");
  1167. 			clif_displaymessage(fd, "   0 Novice              1 Swordman            2 Magician            3 Archer");
  1168. 			clif_displaymessage(fd, "   4 Acolyte             5 Merchant            6 Thief");
  1169. 			clif_displaymessage(fd, "----- 2nd Class -----");
  1170. 			clif_displaymessage(fd, "   7 Knight              8 Priest              9 Wizard             10 Blacksmith");
  1171. 			clif_displaymessage(fd, "  11 Hunter             12 Assassin           14 Crusader           15 Monk");
  1172. 			clif_displaymessage(fd, "  16 Sage               17 Rogue              18 Alchemist          19 Bard");
  1173. 			clif_displaymessage(fd, "  20 Dancer");
  1174. 			clif_displaymessage(fd, "----- High Novice / High 1st Class -----");
  1175. 			clif_displaymessage(fd, "4001 Novice High      4002 Swordman High    4003 Magician High    4004 Archer High");
  1176. 			clif_displaymessage(fd, "4005 Acolyte High     4006 Merchant High    4007 Thief High");
  1177. 			clif_displaymessage(fd, "----- Transcendent 2nd Class -----");
  1178. 			clif_displaymessage(fd, "4008 Lord Knight      4009 High Priest      4010 High Wizard      4011 Whitesmith");
  1179. 			clif_displaymessage(fd, "4012 Sniper           4013 Assassin Cross   4015 Paladin          4016 Champion");
  1180. 			clif_displaymessage(fd, "4017 Professor        4018 Stalker          4019 Creator          4020 Clown");
  1181. 			clif_displaymessage(fd, "4021 Gypsy");
  1182. 			clif_displaymessage(fd, "----- 3rd Class (Regular) -----");
  1183. 			clif_displaymessage(fd, "4054 Rune Knight      4055 Warlock          4056 Ranger           4057 Arch Bishop");
  1184. 			clif_displaymessage(fd, "4058 Mechanic         4059 Guillotine Cross 4066 Royal Guard      4067 Sorcerer");
  1185. 			clif_displaymessage(fd, "4068 Minstrel         4069 Wanderer         4070 Sura             4071 Genetic");
  1186. 			clif_displaymessage(fd, "4072 Shadow Chaser");
  1187. 			clif_displaymessage(fd, "----- 3rd Class (Transcendent) -----");
  1188. 			clif_displaymessage(fd, "4060 Rune Knight      4061 Warlock          4062 Ranger           4063 Arch Bishop");
  1189. 			clif_displaymessage(fd, "4064 Mechanic         4065 Guillotine Cross 4073 Royal Guard      4074 Sorcerer");
  1190. 			clif_displaymessage(fd, "4075 Minstrel         4076 Wanderer         4077 Sura             4078 Genetic");
  1191. 			clif_displaymessage(fd, "4079 Shadow Chaser");
  1192. 			clif_displaymessage(fd, "----- Expanded Class -----");
  1193. 			clif_displaymessage(fd, "  23 Super Novice       24 Gunslinger         25 Ninja            4045 Super Baby");
  1194. 			clif_displaymessage(fd, "4046 Taekwon          4047 Star Gladiator   4049 Soul Linker      4050 Gangsi");
  1195. 			clif_displaymessage(fd, "4051 Death Knight     4052 Dark Collector   4190 Ex. Super Novice 4191 Ex. Super Baby");
  1196. 			clif_displaymessage(fd, "4211 Kagerou          4212 Oboro");
  1197. 			clif_displaymessage(fd, "----- Baby Novice And Baby 1st Class -----");
  1198. 			clif_displaymessage(fd, "4023 Baby Novice      4024 Baby Swordman    4025 Baby Magician    4026 Baby Archer");
  1199. 			clif_displaymessage(fd, "4027 Baby Acolyte     4028 Baby Merchant    4029 Baby Thief");
  1200. 			clif_displaymessage(fd, "---- Baby 2nd Class ----");
  1201. 			clif_displaymessage(fd, "4030 Baby Knight      4031 Baby Priest      4032 Baby Wizard      4033 Baby Blacksmith");
  1202. 			clif_displaymessage(fd, "4034 Baby Hunter      4035 Baby Assassin    4037 Baby Crusader    4038 Baby Monk");
  1203. 			clif_displaymessage(fd, "4039 Baby Sage        4040 Baby Rogue       4041 Baby Alchemist   4042 Baby Bard");
  1204. 			clif_displaymessage(fd, "4043 Baby Dancer");
  1205. 			clif_displaymessage(fd, "---- Baby 3rd Class ----");
  1206. 			clif_displaymessage(fd, "4096 Baby Rune Knight 4097 Baby Warlock     4098 Baby Ranger      4099 Baby Arch Bishop");
  1207. 			clif_displaymessage(fd, "4100 Baby Mechanic    4101 Baby Glt. Cross  4102 Baby Royal Guard 4103 Baby Sorcerer");
  1208. 			clif_displaymessage(fd, "4104 Baby Minstrel    4105 Baby Wanderer    4106 Baby Sura        4107 Baby Genetic");
  1209. 			clif_displaymessage(fd, "4108 Baby Shadow Chaser");
  1210. 			//clif_displaymessage(fd, "---- Modes And Others ----");
  1211. 			//clif_displaymessage(fd, "  22 Wedding            26 Christmas          27 Summer           4048 Star Gladiator (Union)");
  1212. 		return -1;
  1213. 	}
  1214.  
  1215. 	return 0;
  1216. }
  1217.  
  1218. /*==========================================
  1219.  *
  1220.  *------------------------------------------*/
  1221. ACMD_FUNC(kill)
  1222. {
  1223. 	nullpo_retr(-1, sd);
  1224. 	status_kill(&sd->bl);
  1225. 	clif_displaymessage(sd->fd, msg_txt(13)); // A pity! You've died.
  1226. 	if (fd != sd->fd)
  1227. 		clif_displaymessage(fd, msg_txt(14)); // Character killed.
  1228. 	return 0;
  1229. }
  1230.  
  1231. /*==========================================
  1232.  *
  1233.  *------------------------------------------*/
  1234. ACMD_FUNC(alive)
  1235. {
  1236. 	nullpo_retr(-1, sd);
  1237. 	if (!status_revive(&sd->bl, 100, 100))
  1238. 	{
  1239. 		clif_displaymessage(fd, "You're not dead.");
  1240. 		return -1;
  1241. 	}
  1242. 	clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  1243. 	clif_displaymessage(fd, msg_txt(16)); // You've been revived! It's a miracle!
  1244. 	return 0;
  1245. }
  1246.  
  1247. /*==========================================
  1248.  * +kamic [LuzZza]
  1249.  *------------------------------------------*/
  1250. ACMD_FUNC(kami)
  1251. {
  1252. 	unsigned long color=0;
  1253. 	nullpo_retr(-1, sd);
  1254.  
  1255. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1256.  
  1257. 	if(*(command + 5) != 'c' && *(command + 5) != 'C') {
  1258. 		if (!message || !*message) {
  1259. 			clif_displaymessage(fd, "Please, enter a message (usage: @kami <message>).");
  1260. 			return -1;
  1261. 		}
  1262.  
  1263. 		sscanf(message, "%199[^\n]", atcmd_output);
  1264. 		if (strstr(command, "l") != NULL)
  1265. 			clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  1266. 		else
  1267. 			intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(command + 5) == 'b' || *(command + 5) == 'B') ? 0x10 : 0);
  1268. 	} else {
  1269. 		if(!message || !*message || (sscanf(message, "%lx %199[^\n]", &color, atcmd_output) < 2)) {
  1270. 			clif_displaymessage(fd, "Please, enter color and message (usage: @kamic <color> <message>).");
  1271. 			return -1;
  1272. 		}
  1273.  
  1274. 		if(color > 0xFFFFFF) {
  1275. 			clif_displaymessage(fd, "Invalid color.");
  1276. 			return -1;
  1277. 		}
  1278. 		intif_broadcast2(atcmd_output, strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0);
  1279. 	}
  1280. 	return 0;
  1281. }
  1282.  
  1283. /*==========================================
  1284.  *
  1285.  *------------------------------------------*/
  1286. ACMD_FUNC(heal)
  1287. {
  1288. 	int hp = 0, sp = 0; // [Valaris] thanks to fov
  1289. 	nullpo_retr(-1, sd);
  1290.  
  1291. 	sscanf(message, "%d %d", &hp, &sp);
  1292.  
  1293. 	// some overflow checks
  1294. 	if( hp == INT_MIN ) hp++;
  1295. 	if( sp == INT_MIN ) sp++;
  1296.  
  1297. 	if ( hp == 0 && sp == 0 ) {
  1298. 		if (!status_percent_heal(&sd->bl, 100, 100))
  1299. 			clif_displaymessage(fd, msg_txt(157)); // HP and SP have already been recovered.
  1300. 		else
  1301. 			clif_displaymessage(fd, msg_txt(17)); // HP, SP recovered.
  1302. 		return 0;
  1303. 	}
  1304.  
  1305. 	if ( hp > 0 && sp >= 0 ) {
  1306. 		if(!status_heal(&sd->bl, hp, sp, 0))
  1307. 			clif_displaymessage(fd, msg_txt(157)); // HP and SP are already with the good value.
  1308. 		else
  1309. 			clif_displaymessage(fd, msg_txt(17)); // HP, SP recovered.
  1310. 		return 0;
  1311. 	}
  1312.  
  1313. 	if ( hp < 0 && sp <= 0 ) {
  1314. 		status_damage(NULL, &sd->bl, -hp, -sp, 0, 0);
  1315. 		clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  1316. 		clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified.
  1317. 		return 0;
  1318. 	}
  1319.  
  1320. 	//Opposing signs.
  1321. 	if ( hp ) {
  1322. 		if (hp > 0)
  1323. 			status_heal(&sd->bl, hp, 0, 0);
  1324. 		else {
  1325. 			status_damage(NULL, &sd->bl, -hp, 0, 0, 0);
  1326. 			clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  1327. 		}
  1328. 	}
  1329.  
  1330. 	if ( sp ) {
  1331. 		if (sp > 0)
  1332. 			status_heal(&sd->bl, 0, sp, 0);
  1333. 		else
  1334. 			status_damage(NULL, &sd->bl, 0, -sp, 0, 0);
  1335. 	}
  1336.  
  1337. 	clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified.
  1338. 	return 0;
  1339. }
  1340.  
  1341. /*==========================================
  1342.  * @item command (usage: @item <name/id_of_item> <quantity>) (modified by [Yor] for pet_egg)
  1343.  *------------------------------------------*/
  1344. ACMD_FUNC(item)
  1345. {
  1346. 	char item_name[100];
  1347. 	int number = 0, item_id, flag;
  1348. 	struct item item_tmp;
  1349. 	struct item_data *item_data;
  1350. 	int get_count, i;
  1351. 	nullpo_retr(-1, sd);
  1352.  
  1353. 	memset(item_name, '\0', sizeof(item_name));
  1354.  
  1355. 	if (!message || !*message || (
  1356. 		sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 &&
  1357. 		sscanf(message, "%99s %d", item_name, &number) < 1
  1358. 	)) {
  1359. 		clif_displaymessage(fd, "Please, enter an item name/id (usage: @item <item name or ID> [quantity]).");
  1360. 		return -1;
  1361. 	}
  1362.  
  1363. 	if (number <= 0)
  1364. 		number = 1;
  1365.  
  1366. 	if ((item_data = itemdb_searchname(item_name)) == NULL &&
  1367. 	    (item_data = itemdb_exists(atoi(item_name))) == NULL)
  1368. 	{
  1369. 		clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  1370. 		return -1;
  1371. 	}
  1372.  
  1373. 	item_id = item_data->nameid;
  1374. 	get_count = number;
  1375. 	//Check if it's stackable.
  1376. 	if (!itemdb_isstackable2(item_data))
  1377. 		get_count = 1;
  1378.  
  1379. 	for (i = 0; i < number; i += get_count) {
  1380. 		// if not pet egg
  1381. 		if (!pet_create_egg(sd, item_id)) {
  1382. 			memset(&item_tmp, 0, sizeof(item_tmp));
  1383. 			item_tmp.nameid = item_id;
  1384. 			item_tmp.identify = 1;
  1385.  
  1386. 			if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1387. 				clif_additem(sd, 0, 0, flag);
  1388. 		}
  1389. 	}
  1390.  
  1391. 	clif_displaymessage(fd, msg_txt(18)); // Item created.
  1392. 	return 0;
  1393. }
  1394.  
  1395. /*==========================================
  1396.  *
  1397.  *------------------------------------------*/
  1398. ACMD_FUNC(item2)
  1399. {
  1400. 	struct item item_tmp;
  1401. 	struct item_data *item_data;
  1402. 	char item_name[100];
  1403. 	int item_id, number = 0;
  1404. 	int identify = 0, refine = 0, attr = 0;
  1405. 	int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  1406. 	int flag;
  1407. 	int loop, get_count, i;
  1408. 	nullpo_retr(-1, sd);
  1409.  
  1410. 	memset(item_name, '\0', sizeof(item_name));
  1411.  
  1412. 	if (!message || !*message || (
  1413. 		sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 &&
  1414. 		sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9
  1415. 	)) {
  1416. 		clif_displaymessage(fd, "Please, enter all informations (usage: @item2 <item name or ID> <quantity>");
  1417. 		clif_displaymessage(fd, "  <Identify_flag> <refine> <attribut> <Card1> <Card2> <Card3> <Card4>).");
  1418. 		return -1;
  1419. 	}
  1420.  
  1421. 	if (number <= 0)
  1422. 		number = 1;
  1423.  
  1424. 	item_id = 0;
  1425. 	if ((item_data = itemdb_searchname(item_name)) != NULL ||
  1426. 	    (item_data = itemdb_exists(atoi(item_name))) != NULL)
  1427. 		item_id = item_data->nameid;
  1428.  
  1429. 	if (item_id > 500) {
  1430. 		loop = 1;
  1431. 		get_count = number;
  1432. 		if (item_data->type == IT_WEAPON || item_data->type == IT_ARMOR ||
  1433. 			item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) {
  1434. 			loop = number;
  1435. 			get_count = 1;
  1436. 			if (item_data->type == IT_PETEGG) {
  1437. 				identify = 1;
  1438. 				refine = 0;
  1439. 			}
  1440. 			if (item_data->type == IT_PETARMOR)
  1441. 				refine = 0;
  1442. 			if (refine > MAX_REFINE)
  1443. 				refine = MAX_REFINE;
  1444. 		} else {
  1445. 			identify = 1;
  1446. 			refine = attr = 0;
  1447. 		}
  1448. 		for (i = 0; i < loop; i++) {
  1449. 			memset(&item_tmp, 0, sizeof(item_tmp));
  1450. 			item_tmp.nameid = item_id;
  1451. 			item_tmp.identify = identify;
  1452. 			item_tmp.refine = refine;
  1453. 			item_tmp.attribute = attr;
  1454. 			item_tmp.card[0] = c1;
  1455. 			item_tmp.card[1] = c2;
  1456. 			item_tmp.card[2] = c3;
  1457. 			item_tmp.card[3] = c4;
  1458. 			if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1459. 				clif_additem(sd, 0, 0, flag);
  1460. 		}
  1461.  
  1462. 		clif_displaymessage(fd, msg_txt(18)); // Item created.
  1463. 	} else {
  1464. 		clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  1465. 		return -1;
  1466. 	}
  1467.  
  1468. 	return 0;
  1469. }
  1470.  
  1471. /*==========================================
  1472.  *
  1473.  *------------------------------------------*/
  1474. ACMD_FUNC(itemreset)
  1475. {
  1476. 	int i;
  1477. 	nullpo_retr(-1, sd);
  1478.  
  1479. 	for (i = 0; i < MAX_INVENTORY; i++) {
  1480. 		if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) {
  1481. 			pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_COMMAND);
  1482. 		}
  1483. 	}
  1484. 	clif_displaymessage(fd, msg_txt(20)); // All of your items have been removed.
  1485.  
  1486. 	return 0;
  1487. }
  1488.  
  1489. /*==========================================
  1490.  * Atcommand @lvlup
  1491.  *------------------------------------------*/
  1492. ACMD_FUNC(baselevelup)
  1493. {
  1494. 	int level=0, i=0, status_point=0;
  1495. 	nullpo_retr(-1, sd);
  1496. 	level = atoi(message);
  1497.  
  1498. 	if (!message || !*message || !level) {
  1499. 		clif_displaymessage(fd, "Please, enter a level adjustment (usage: @lvup/@blevel/@baselvlup <number of levels>).");
  1500. 		return -1;
  1501. 	}
  1502.  
  1503. 	if (level > 0) {
  1504. 		if (sd->status.base_level >= pc_maxbaselv(sd)) { // check for max level by Valaris
  1505. 			clif_displaymessage(fd, msg_txt(47)); // Base level can't go any higher.
  1506. 			return -1;
  1507. 		} // End Addition
  1508. 		if ((unsigned int)level > pc_maxbaselv(sd) || (unsigned int)level > pc_maxbaselv(sd) - sd->status.base_level) // fix positiv overflow
  1509. 			level = pc_maxbaselv(sd) - sd->status.base_level;
  1510. 		for (i = 0; i < level; i++)
  1511. 			status_point += pc_gets_status_point(sd->status.base_level + i);
  1512.  
  1513. 		sd->status.status_point += status_point;
  1514. 		sd->status.base_level += (unsigned int)level;
  1515. 		status_percent_heal(&sd->bl, 100, 100);
  1516. 		clif_misceffect(&sd->bl, 0);
  1517. 		clif_displaymessage(fd, msg_txt(21)); // Base level raised.
  1518. 	} else {
  1519. 		if (sd->status.base_level == 1) {
  1520. 			clif_displaymessage(fd, msg_txt(158)); // Base level can't go any lower.
  1521. 			return -1;
  1522. 		}
  1523. 		level*=-1;
  1524. 		if ((unsigned int)level >= sd->status.base_level)
  1525. 			level = sd->status.base_level-1;
  1526. 		for (i = 0; i > -level; i--)
  1527. 			status_point += pc_gets_status_point(sd->status.base_level + i - 1);
  1528. 		if (sd->status.status_point < status_point)
  1529. 			pc_resetstate(sd);
  1530. 		if (sd->status.status_point < status_point)
  1531. 			sd->status.status_point = 0;
  1532. 		else
  1533. 			sd->status.status_point -= status_point;
  1534. 		sd->status.base_level -= (unsigned int)level;
  1535. 		clif_displaymessage(fd, msg_txt(22)); // Base level lowered.
  1536. 	}
  1537. 	sd->status.base_exp = 0;
  1538. 	clif_updatestatus(sd, SP_STATUSPOINT);
  1539. 	clif_updatestatus(sd, SP_BASELEVEL);
  1540. 	clif_updatestatus(sd, SP_BASEEXP);
  1541. 	clif_updatestatus(sd, SP_NEXTBASEEXP);
  1542. 	status_calc_pc(sd, 0);
  1543. 	if(sd->status.party_id)
  1544. 		party_send_levelup(sd);
  1545. 	return 0;
  1546. }
  1547.  
  1548. /*==========================================
  1549.  *
  1550.  *------------------------------------------*/
  1551. ACMD_FUNC(joblevelup)
  1552. {
  1553. 	int level=0;
  1554. 	nullpo_retr(-1, sd);
  1555.  
  1556. 	level = atoi(message);
  1557.  
  1558. 	if (!message || !*message || !level) {
  1559. 		clif_displaymessage(fd, "Please, enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup <number of levels>).");
  1560. 		return -1;
  1561. 	}
  1562. 	if (level > 0) {
  1563. 		if (sd->status.job_level >= pc_maxjoblv(sd)) {
  1564. 			clif_displaymessage(fd, msg_txt(23)); // Job level can't go any higher.
  1565. 			return -1;
  1566. 		}
  1567. 		if ((unsigned int)level > pc_maxjoblv(sd) || (unsigned int)level > pc_maxjoblv(sd) - sd->status.job_level) // fix positiv overflow
  1568. 			level = pc_maxjoblv(sd) - sd->status.job_level;
  1569. 		sd->status.job_level += (unsigned int)level;
  1570. 		sd->status.skill_point += level;
  1571. 		clif_misceffect(&sd->bl, 1);
  1572. 		clif_displaymessage(fd, msg_txt(24)); // Job level raised.
  1573. 	} else {
  1574. 		if (sd->status.job_level == 1) {
  1575. 			clif_displaymessage(fd, msg_txt(159)); // Job level can't go any lower.
  1576. 			return -1;
  1577. 		}
  1578. 		level *=-1;
  1579. 		if ((unsigned int)level >= sd->status.job_level) // fix negativ overflow
  1580. 			level = sd->status.job_level-1;
  1581. 		sd->status.job_level -= (unsigned int)level;
  1582. 		if (sd->status.skill_point < level)
  1583. 			pc_resetskill(sd,0);	//Reset skills since we need to substract more points.
  1584. 		if (sd->status.skill_point < level)
  1585. 			sd->status.skill_point = 0;
  1586. 		else
  1587. 			sd->status.skill_point -= level;
  1588. 		clif_displaymessage(fd, msg_txt(25)); // Job level lowered.
  1589. 	}
  1590. 	sd->status.job_exp = 0;
  1591. 	clif_updatestatus(sd, SP_JOBLEVEL);
  1592. 	clif_updatestatus(sd, SP_JOBEXP);
  1593. 	clif_updatestatus(sd, SP_NEXTJOBEXP);
  1594. 	clif_updatestatus(sd, SP_SKILLPOINT);
  1595. 	status_calc_pc(sd, 0);
  1596.  
  1597. 	return 0;
  1598. }
  1599.  
  1600. /*==========================================
  1601.  * @help
  1602.  *------------------------------------------*/
  1603. ACMD_FUNC(help)
  1604. {
  1605. 	config_setting_t *help;
  1606. 	const char *text = NULL;
  1607. 	const char *command_name = NULL;
  1608. 	char *default_command = "help";
  1609.  
  1610. 	nullpo_retr(-1, sd);
  1611.  
  1612. 	help = config_lookup(&atcommand_config, "help");
  1613. 	if (help == NULL) {
  1614. 		clif_displaymessage(fd, msg_txt(27)); // "Commands help is not available."
  1615. 		return -1;
  1616. 	}
  1617.  
  1618. 	if (!message || !*message) {
  1619. 		command_name = default_command; // If no command_name specified, display help for @help.
  1620. 	} else {
  1621. 		if (*message == atcommand_symbol || *message == charcommand_symbol)
  1622. 			++message;
  1623. 		command_name = atcommand_checkalias(message);
  1624. 	}
  1625.  
  1626. 	if (!pc_can_use_command(sd, command_name, COMMAND_ATCOMMAND)) {
  1627. 		sprintf(atcmd_output, msg_txt(153), message); // "%s is Unknown Command"
  1628. 		clif_displaymessage(fd, atcmd_output);
  1629. 		atcommand_get_suggestions(sd, command_name, true);
  1630. 		return -1;
  1631. 	}
  1632.  
  1633. 	if (!config_setting_lookup_string(help, command_name, &text)) {
  1634. 		clif_displaymessage(fd, "There is no help for this command_name.");
  1635. 		atcommand_get_suggestions(sd, command_name, true);
  1636. 		return -1;
  1637. 	}
  1638.  
  1639. 	sprintf(atcmd_output, "Help for command %c%s:", atcommand_symbol, command_name);
  1640. 	clif_displaymessage(fd, atcmd_output);
  1641.  
  1642. 	{   // Display aliases
  1643. 		DBIterator* iter;
  1644. 		AtCommandInfo *command_info;
  1645. 		AliasInfo *alias_info = NULL;
  1646. 		StringBuf buf;
  1647. 		bool has_aliases = false;
  1648.  
  1649. 		StringBuf_Init(&buf);
  1650. 		StringBuf_AppendStr(&buf, "Available aliases:");
  1651. 		command_info = get_atcommandinfo_byname(command_name);
  1652. 		iter = db_iterator(atcommand_alias_db);
  1653. 		for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) {
  1654. 			if (alias_info->command == command_info) {
  1655. 				StringBuf_Printf(&buf, " %s", alias_info->alias);
  1656. 				has_aliases = true;
  1657. 			}
  1658. 		}
  1659. 		dbi_destroy(iter);
  1660. 		if (has_aliases)
  1661. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  1662. 		StringBuf_Destroy(&buf);
  1663. 	}
  1664.  
  1665. 	// Display help contents
  1666. 	clif_displaymessage(fd, text);
  1667. 	return 0;
  1668. }
  1669.  
  1670. // helper function, used in foreach calls to stop auto-attack timers
  1671. // parameter: '0' - everyone, 'id' - only those attacking someone with that id
  1672. static int atcommand_stopattack(struct block_list *bl,va_list ap)
  1673. {
  1674. 	struct unit_data *ud = unit_bl2ud(bl);
  1675. 	int id = va_arg(ap, int);
  1676. 	if (ud && ud->attacktimer != INVALID_TIMER && (!id || id == ud->target))
  1677. 	{
  1678. 		unit_stop_attack(bl);
  1679. 		return 1;
  1680. 	}
  1681. 	return 0;
  1682. }
  1683. /*==========================================
  1684.  *
  1685.  *------------------------------------------*/
  1686. static int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
  1687. {
  1688. 	TBL_PC* sd = (TBL_PC*)bl;
  1689. 	clif_pvpset(sd, 0, 0, 2);
  1690. 	if (sd->pvp_timer != INVALID_TIMER) {
  1691. 		delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
  1692. 		sd->pvp_timer = INVALID_TIMER;
  1693. 	}
  1694. 	return 0;
  1695. }
  1696.  
  1697. ACMD_FUNC(pvpoff)
  1698. {
  1699. 	nullpo_retr(-1, sd);
  1700.  
  1701. 	if (!map[sd->bl.m].flag.pvp) {
  1702. 		clif_displaymessage(fd, msg_txt(160)); // PvP is already Off.
  1703. 		return -1;
  1704. 	}
  1705.  
  1706. 	map[sd->bl.m].flag.pvp = 0;
  1707.  
  1708. 	if (!battle_config.pk_mode)
  1709. 		clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1710. 	map_foreachinmap(atcommand_pvpoff_sub,sd->bl.m, BL_PC);
  1711. 	map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1712. 	clif_displaymessage(fd, msg_txt(31)); // PvP: Off.
  1713. 	return 0;
  1714. }
  1715.  
  1716. /*==========================================
  1717.  *
  1718.  *------------------------------------------*/
  1719. static int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
  1720. {
  1721. 	TBL_PC* sd = (TBL_PC*)bl;
  1722. 	if (sd->pvp_timer == INVALID_TIMER) {
  1723. 		sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0);
  1724. 		sd->pvp_rank = 0;
  1725. 		sd->pvp_lastusers = 0;
  1726. 		sd->pvp_point = 5;
  1727. 		sd->pvp_won = 0;
  1728. 		sd->pvp_lost = 0;
  1729. 	}
  1730. 	return 0;
  1731. }
  1732.  
  1733. ACMD_FUNC(pvpon)
  1734. {
  1735. 	nullpo_retr(-1, sd);
  1736.  
  1737. 	if (map[sd->bl.m].flag.pvp) {
  1738. 		clif_displaymessage(fd, msg_txt(161)); // PvP is already On.
  1739. 		return -1;
  1740. 	}
  1741.  
  1742. 	map[sd->bl.m].flag.pvp = 1;
  1743.  
  1744. 	if (!battle_config.pk_mode)
  1745. 	{// display pvp circle and rank
  1746. 		clif_map_property_mapall(sd->bl.m, MAPPROPERTY_FREEPVPZONE);
  1747. 		map_foreachinmap(atcommand_pvpon_sub,sd->bl.m, BL_PC);
  1748. 	}
  1749.  
  1750. 	clif_displaymessage(fd, msg_txt(32)); // PvP: On.
  1751.  
  1752. 	return 0;
  1753. }
  1754.  
  1755. /*==========================================
  1756.  *
  1757.  *------------------------------------------*/
  1758. ACMD_FUNC(gvgoff)
  1759. {
  1760. 	nullpo_retr(-1, sd);
  1761.  
  1762. 	if (!map[sd->bl.m].flag.gvg) {
  1763. 		clif_displaymessage(fd, msg_txt(162)); // GvG is already Off.
  1764. 		return -1;
  1765. 	}
  1766.  
  1767. 	map[sd->bl.m].flag.gvg = 0;
  1768. 	clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1769. 	map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1770. 	clif_displaymessage(fd, msg_txt(33)); // GvG: Off.
  1771.  
  1772. 	return 0;
  1773. }
  1774.  
  1775. /*==========================================
  1776.  *
  1777.  *------------------------------------------*/
  1778. ACMD_FUNC(gvgon)
  1779. {
  1780. 	nullpo_retr(-1, sd);
  1781.  
  1782. 	if (map[sd->bl.m].flag.gvg) {
  1783. 		clif_displaymessage(fd, msg_txt(163)); // GvG is already On.
  1784. 		return -1;
  1785. 	}
  1786.  
  1787. 	map[sd->bl.m].flag.gvg = 1;
  1788. 	clif_map_property_mapall(sd->bl.m, MAPPROPERTY_AGITZONE);
  1789. 	clif_displaymessage(fd, msg_txt(34)); // GvG: On.
  1790.  
  1791. 	return 0;
  1792. }
  1793.  
  1794. /*==========================================
  1795.  *
  1796.  *------------------------------------------*/
  1797. ACMD_FUNC(model)
  1798. {
  1799. 	int hair_style = 0, hair_color = 0, cloth_color = 0;
  1800. 	nullpo_retr(-1, sd);
  1801.  
  1802. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1803.  
  1804. 	if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) {
  1805. 		sprintf(atcmd_output, "Please, enter at least a value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).",
  1806. 		        MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1807. 		clif_displaymessage(fd, atcmd_output);
  1808. 		return -1;
  1809. 	}
  1810.  
  1811. 	if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE &&
  1812. 		hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
  1813. 		cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1814. 			pc_changelook(sd, LOOK_HAIR, hair_style);
  1815. 			pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1816. 			pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1817. 			clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1818. 	} else {
  1819. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1820. 		return -1;
  1821. 	}
  1822.  
  1823. 	return 0;
  1824. }
  1825.  
  1826. /*==========================================
  1827.  * @dye && @ccolor
  1828.  *------------------------------------------*/
  1829. ACMD_FUNC(dye)
  1830. {
  1831. 	int cloth_color = 0;
  1832. 	nullpo_retr(-1, sd);
  1833.  
  1834. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1835.  
  1836. 	if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) {
  1837. 		sprintf(atcmd_output, "Please, enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).", MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1838. 		clif_displaymessage(fd, atcmd_output);
  1839. 		return -1;
  1840. 	}
  1841.  
  1842. 	if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1843. 		pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1844. 		clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1845. 	} else {
  1846. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1847. 		return -1;
  1848. 	}
  1849.  
  1850. 	return 0;
  1851. }
  1852.  
  1853. /*==========================================
  1854.  * @hairstyle && @hstyle
  1855.  *------------------------------------------*/
  1856. ACMD_FUNC(hair_style)
  1857. {
  1858. 	int hair_style = 0;
  1859. 	nullpo_retr(-1, sd);
  1860.  
  1861. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1862.  
  1863. 	if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) {
  1864. 		sprintf(atcmd_output, "Please, enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).", MIN_HAIR_STYLE, MAX_HAIR_STYLE);
  1865. 		clif_displaymessage(fd, atcmd_output);
  1866. 		return -1;
  1867. 	}
  1868.  
  1869. 	if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) {
  1870. 			pc_changelook(sd, LOOK_HAIR, hair_style);
  1871. 			clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1872. 	} else {
  1873. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1874. 		return -1;
  1875. 	}
  1876.  
  1877. 	return 0;
  1878. }
  1879.  
  1880. /*==========================================
  1881.  * @haircolor && @hcolor
  1882.  *------------------------------------------*/
  1883. ACMD_FUNC(hair_color)
  1884. {
  1885. 	int hair_color = 0;
  1886. 	nullpo_retr(-1, sd);
  1887.  
  1888. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1889.  
  1890. 	if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) {
  1891. 		sprintf(atcmd_output, "Please, enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).", MIN_HAIR_COLOR, MAX_HAIR_COLOR);
  1892. 		clif_displaymessage(fd, atcmd_output);
  1893. 		return -1;
  1894. 	}
  1895.  
  1896. 	if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) {
  1897. 			pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1898. 			clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1899. 	} else {
  1900. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1901. 		return -1;
  1902. 	}
  1903.  
  1904. 	return 0;
  1905. }
  1906.  
  1907. /*==========================================
  1908.  * @go [city_number or city_name] - Updated by Harbin
  1909.  *------------------------------------------*/
  1910. ACMD_FUNC(go)
  1911. {
  1912. 	int i;
  1913. 	int town;
  1914. 	char map_name[MAP_NAME_LENGTH];
  1915. 	int m;
  1916.  
  1917. 	const struct {
  1918. 		char map[MAP_NAME_LENGTH];
  1919. 		int x, y;
  1920. 	} data[] = {
  1921. 		{ MAP_PRONTERA,      156, 191 }, //  0=Prontera
  1922. 		{ MAP_MORROC,      156,  93 }, //  1=Morroc
  1923. 		{ MAP_GEFFEN,      119,  59 }, //  2=Geffen
  1924. 		{ MAP_PAYON,       162, 233 }, //  3=Payon
  1925. 		{ MAP_ALBERTA,     192, 147 }, //  4=Alberta
  1926. 		{ MAP_IZLUDE,      128, 114 }, //  5=Izlude
  1927. 		{ MAP_ALDEBARAN,   140, 131 }, //  6=Al de Baran
  1928. 		{ MAP_LUTIE,       147, 134 }, //  7=Lutie
  1929. 		{ MAP_COMODO,      209, 143 }, //  8=Comodo
  1930. 		{ MAP_YUNO,        157,  51 }, //  9=Yuno
  1931. 		{ MAP_AMATSU,      198,  84 }, // 10=Amatsu
  1932. 		{ MAP_GONRYUN,     160, 120 }, // 11=Gonryun
  1933. 		{ MAP_UMBALA,       89, 157 }, // 12=Umbala
  1934. 		{ MAP_NIFLHEIM,     21, 153 }, // 13=Niflheim
  1935. 		{ MAP_LOUYANG,     217,  40 }, // 14=Louyang
  1936. 		{ MAP_NOVICE,       53, 111 }, // 15=Training Grounds
  1937. 		{ MAP_JAIL,         23,  61 }, // 16=Prison
  1938. 		{ MAP_JAWAII,      249, 127 }, // 17=Jawaii
  1939. 		{ MAP_AYOTHAYA,    151, 117 }, // 18=Ayothaya
  1940. 		{ MAP_EINBROCH,     64, 200 }, // 19=Einbroch
  1941. 		{ MAP_LIGHTHALZEN, 158,  92 }, // 20=Lighthalzen
  1942. 		{ MAP_EINBECH,      70,  95 }, // 21=Einbech
  1943. 		{ MAP_HUGEL,        96, 145 }, // 22=Hugel
  1944. 		{ MAP_RACHEL,      130, 110 }, // 23=Rachel
  1945. 		{ MAP_VEINS,       216, 123 }, // 24=Veins
  1946. 		{ MAP_MOSCOVIA,    223, 184 }, // 25=Moscovia
  1947. 		{ MAP_MIDCAMP,    180, 240 }, // 26=Midgard Camp
  1948. 		{ MAP_MANUK,       282, 138 }, // 27=Manuk
  1949. 		{ MAP_SPLENDIDE,   197, 176 }, // 28=Splendide
  1950. 		{ MAP_BRASILIS,    182, 239 }, // 29=Brasilis
  1951. 		{ MAP_DICASTES,   198, 187 }, // 30=El Dicastes
  1952. 		{ MAP_MORA,   44, 151 }, // 31=Mora
  1953. 		{ MAP_DEWATA,   200, 180 }, // 32=Dewata
  1954. 		{ MAP_MALANGDO,   140, 114 }, // 33=Malangdo Island
  1955. 		{ MAP_MALAYA,   242, 211 }, // 34=Malaya Port
  1956. 		{ MAP_ECLAGE,   110, 39 }, // 35=Eclage
  1957. 		{ MAP_CASPEN,   110, 39 }, // 35=Caspen
  1958. 	};
  1959.  
  1960. 	nullpo_retr(-1, sd);
  1961.  
  1962. 	if( map[sd->bl.m].flag.nogo && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  1963. 		clif_displaymessage(sd->fd,"You can not use @go on this map.");
  1964. 		return 0;
  1965. 	}
  1966.  
  1967. 	memset(map_name, '\0', sizeof(map_name));
  1968. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1969.  
  1970. 	// get the number
  1971. 	town = atoi(message);
  1972.  
  1973. 	if (!message || !*message || sscanf(message, "%11s", map_name) < 1 || town < 0 || town >= ARRAYLENGTH(data))
  1974. 	{// no value matched so send the list of locations
  1975. 		const char* text;
  1976.  
  1977. 		// attempt to find the text help string
  1978. 		text = atcommand_help_string( command );
  1979.  
  1980. 		// Invalid location number, or name.
  1981. 		clif_displaymessage(fd, msg_txt(38));
  1982.  
  1983. 		if( text )
  1984. 		{// send the text to the client
  1985. 			clif_displaymessage( fd, text );
  1986. 		}
  1987.  
  1988. 		return -1;
  1989. 	}
  1990.  
  1991. 	// get possible name of the city
  1992. 	map_name[MAP_NAME_LENGTH-1] = '\0';
  1993. 	for (i = 0; map_name[i]; i++)
  1994. 		map_name[i] = TOLOWER(map_name[i]);
  1995. 	// try to identify the map name
  1996. 	if (strncmp(map_name, "prontera", 3) == 0) {
  1997. 	    strncmp(map_name, "islude", 3) == 0) {
  1998. 		town = 36;
  1999. 	} else if (strncmp(map_name, "morocc", 3) == 0) {
  2000. 		town = 1;
  2001. 	} else if (strncmp(map_name, "geffen", 3) == 0) {
  2002. 		town = 2;
  2003. 	} else if (strncmp(map_name, "payon", 3) == 0 ||
  2004. 	           strncmp(map_name, "paion", 3) == 0) {
  2005. 		town = 3;
  2006. 	} else if (strncmp(map_name, "alberta", 3) == 0) {
  2007. 		town = 4;
  2008. 	} else if (strncmp(map_name, "izlude", 3) == 0 ||
  2009. 	           strncmp(map_name, "islude", 3) == 0) {
  2010. 		town = 5;
  2011. 	} else if (strncmp(map_name, "aldebaran", 3) == 0 ||
  2012. 	           strcmp(map_name,  "al") == 0) {
  2013. 		town = 6;
  2014. 	} else if (strncmp(map_name, "lutie", 3) == 0 ||
  2015. 	           strcmp(map_name,  "christmas") == 0 ||
  2016. 	           strncmp(map_name, "xmas", 3) == 0 ||
  2017. 	           strncmp(map_name, "x-mas", 3) == 0) {
  2018. 		town = 7;
  2019. 	} else if (strncmp(map_name, "comodo", 3) == 0) {
  2020. 		town = 8;
  2021. 	} else if (strncmp(map_name, "yuno", 3) == 0) {
  2022. 		town = 9;
  2023. 	} else if (strncmp(map_name, "amatsu", 3) == 0) {
  2024. 		town = 10;
  2025. 	} else if (strncmp(map_name, "gonryun", 3) == 0) {
  2026. 		town = 11;
  2027. 	} else if (strncmp(map_name, "umbala", 3) == 0) {
  2028. 		town = 12;
  2029. 	} else if (strncmp(map_name, "niflheim", 3) == 0) {
  2030. 		town = 13;
  2031. 	} else if (strncmp(map_name, "louyang", 3) == 0) {
  2032. 		town = 14;
  2033. 	} else if (strncmp(map_name, "new_1-1", 3) == 0 ||
  2034. 	           strncmp(map_name, "startpoint", 3) == 0 ||
  2035. 	           strncmp(map_name, "begining", 3) == 0) {
  2036. 		town = 15;
  2037. 	} else if (strncmp(map_name, "sec_pri", 3) == 0 ||
  2038. 	           strncmp(map_name, "prison", 3) == 0 ||
  2039. 	           strncmp(map_name, "jails", 3) == 0) {
  2040. 		town = 16;
  2041. 	} else if (strncmp(map_name, "jawaii", 3) == 0 ||
  2042. 	           strncmp(map_name, "jawai", 3) == 0) {
  2043. 		town = 17;
  2044. 	} else if (strncmp(map_name, "ayothaya", 3) == 0 ||
  2045. 	           strncmp(map_name, "ayotaya", 3) == 0) {
  2046. 		town = 18;
  2047. 	} else if (strncmp(map_name, "einbroch", 5) == 0 ||
  2048. 	           strncmp(map_name, "ainbroch", 5) == 0) {
  2049. 		town = 19;
  2050. 	} else if (strncmp(map_name, "lighthalzen", 3) == 0) {
  2051. 		town = 20;
  2052. 	} else if (strncmp(map_name, "einbech", 3) == 0) {
  2053. 		town = 21;
  2054. 	} else if (strncmp(map_name, "hugel", 3) == 0) {
  2055. 		town = 22;
  2056. 	} else if (strncmp(map_name, "rachel", 3) == 0) {
  2057. 		town = 23;
  2058. 	} else if (strncmp(map_name, "veins", 3) == 0) {
  2059. 		town = 24;
  2060. 	} else if (strncmp(map_name, "moscovia", 3) == 0) {
  2061. 		town = 25;
  2062. 	} else if (strncmp(map_name, "mid_camp", 3) == 0) {
  2063. 		town = 26;
  2064. 	} else if (strncmp(map_name, "manuk", 3) == 0) {
  2065. 		town = 27;
  2066. 	} else if (strncmp(map_name, "splendide", 3) == 0) {
  2067. 		town = 28;
  2068. 	} else if (strncmp(map_name, "brasilis", 3) == 0) {
  2069. 		town = 29;
  2070. 	} else if (strncmp(map_name, "dicastes01", 3) == 0) {
  2071. 		town = 30;
  2072. 	} else if (strncmp(map_name, "mora", 3) == 0) {
  2073. 		town = 31;
  2074. 	} else if (strncmp(map_name, "dewata", 3) == 0) {
  2075. 		town = 32;
  2076. 	} else if (strncmp(map_name, "malangdo", 3) == 0) {
  2077. 		town = 33;
  2078. 	} else if (strncmp(map_name, "malaya", 3) == 0) {
  2079. 		town = 34;
  2080. 	} else if (strncmp(map_name, "eclage", 3) == 0) {
  2081. 		town = 35;
  2082. 	} else if (strncmp(map_name, "caspen", 3) == 0) {
  2083. 		town = 0;
  2084. 	}
  2085.  
  2086. 	if (town >= 0 && town < ARRAYLENGTH(data))
  2087. 	{
  2088. 		m = map_mapname2mapid(data[town].map);
  2089. 		if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2090. 			clif_displaymessage(fd, msg_txt(247));
  2091. 			return -1;
  2092. 		}
  2093. 		if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2094. 			clif_displaymessage(fd, msg_txt(248));
  2095. 			return -1;
  2096. 		}
  2097. 		if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == 0) {
  2098. 			clif_displaymessage(fd, msg_txt(0)); // Warped.
  2099. 		} else {
  2100. 			clif_displaymessage(fd, msg_txt(1)); // Map not found.
  2101. 			return -1;
  2102. 		}
  2103. 	} else { // if you arrive here, you have an error in town variable when reading of names
  2104. 		clif_displaymessage(fd, msg_txt(38)); // Invalid location number or name.
  2105. 		return -1;
  2106. 	}
  2107.  
  2108. 	return 0;
  2109. }
  2110.  
  2111. /*==========================================
  2112.  *
  2113.  *------------------------------------------*/
  2114. ACMD_FUNC(monster)
  2115. {
  2116. 	char name[NAME_LENGTH];
  2117. 	char monster[NAME_LENGTH];
  2118. 	char eventname[EVENT_NAME_LENGTH] = "";
  2119. 	int mob_id;
  2120. 	int number = 0;
  2121. 	int count;
  2122. 	int i, k, range;
  2123. 	short mx, my;
  2124. 	nullpo_retr(-1, sd);
  2125.  
  2126. 	memset(name, '\0', sizeof(name));
  2127. 	memset(monster, '\0', sizeof(monster));
  2128. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2129.  
  2130. 	if (!message || !*message) {
  2131. 			clif_displaymessage(fd, msg_txt(80)); // Give the display name or monster name/id please.
  2132. 			return -1;
  2133. 	}
  2134. 	if (sscanf(message, "\"%23[^\"]\" %23s %d", name, monster, &number) > 1 ||
  2135. 		sscanf(message, "%23s \"%23[^\"]\" %d", monster, name, &number) > 1) {
  2136. 		//All data can be left as it is.
  2137. 	} else if ((count=sscanf(message, "%23s %d %23s", monster, &number, name)) > 1) {
  2138. 		//Here, it is possible name was not given and we are using monster for it.
  2139. 		if (count < 3) //Blank mob's name.
  2140. 			name[0] = '\0';
  2141. 	} else if (sscanf(message, "%23s %23s %d", name, monster, &number) > 1) {
  2142. 		//All data can be left as it is.
  2143. 	} else if (sscanf(message, "%23s", monster) > 0) {
  2144. 		//As before, name may be already filled.
  2145. 		name[0] = '\0';
  2146. 	} else {
  2147. 		clif_displaymessage(fd, msg_txt(80)); // Give a display name and monster name/id please.
  2148. 		return -1;
  2149. 	}
  2150.  
  2151. 	if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
  2152. 		mob_id = mobdb_checkid(atoi(monster));
  2153.  
  2154. 	if (mob_id == 0) {
  2155. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  2156. 		return -1;
  2157. 	}
  2158.  
  2159. 	if (mob_id == MOBID_EMPERIUM) {
  2160. 		clif_displaymessage(fd, msg_txt(83)); // Monster 'Emperium' cannot be spawned.
  2161. 		return -1;
  2162. 	}
  2163.  
  2164. 	if (number <= 0)
  2165. 		number = 1;
  2166.  
  2167. 	if( !name[0] )
  2168. 		strcpy(name, "--ja--");
  2169.  
  2170. 	// If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive
  2171. 	if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit)
  2172. 		number = battle_config.atc_spawn_quantity_limit;
  2173.  
  2174. 	if (strcmp(command+1, "monstersmall") == 0)
  2175. 		strcpy(eventname, "2");
  2176. 	else if (strcmp(command+1, "monsterbig") == 0)
  2177. 		strcpy(eventname, "4");
  2178.  
  2179. 	if (battle_config.etc_log)
  2180. 		ShowInfo("%s monster='%s' name='%s' id=%d count=%d (%d,%d)\n", command, monster, name, mob_id, number, sd->bl.x, sd->bl.y);
  2181.  
  2182. 	count = 0;
  2183. 	range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
  2184. 	for (i = 0; i < number; i++) {
  2185. 		map_search_freecell(&sd->bl, 0, &mx,  &my, range, range, 0);
  2186. 		k = mob_once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname);
  2187. 		count += (k != 0) ? 1 : 0;
  2188. 	}
  2189.  
  2190. 	if (count != 0)
  2191. 		if (number == count)
  2192. 			clif_displaymessage(fd, msg_txt(39)); // All monster summoned!
  2193. 		else {
  2194. 			sprintf(atcmd_output, msg_txt(240), count); // %d monster(s) summoned!
  2195. 			clif_displaymessage(fd, atcmd_output);
  2196. 		}
  2197. 	else {
  2198. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  2199. 		return -1;
  2200. 	}
  2201.  
  2202. 	return 0;
  2203. }
  2204.  
  2205. /*==========================================
  2206.  *
  2207.  *------------------------------------------*/
  2208. static int atkillmonster_sub(struct block_list *bl, va_list ap)
  2209. {
  2210. 	struct mob_data *md;
  2211. 	int flag;
  2212.  
  2213. 	nullpo_ret(md=(struct mob_data *)bl);
  2214. 	flag = va_arg(ap, int);
  2215.  
  2216. 	if (md->guardian_data)
  2217. 		return 0; //Do not touch WoE mobs!
  2218.  
  2219. 	if (flag)
  2220. 		status_zap(bl,md->status.hp, 0);
  2221. 	else
  2222. 		status_kill(bl);
  2223. 	return 1;
  2224. }
  2225.  
  2226. void atcommand_killmonster_sub(const int fd, struct map_session_data* sd, const char* message, const int drop)
  2227. {
  2228. 	int map_id;
  2229. 	char map_name[MAP_NAME_LENGTH_EXT];
  2230.  
  2231. 	if (!sd) return;
  2232.  
  2233. 	memset(map_name, '\0', sizeof(map_name));
  2234.  
  2235. 	if (!message || !*message || sscanf(message, "%15s", map_name) < 1)
  2236. 		map_id = sd->bl.m;
  2237. 	else {
  2238. 		if ((map_id = map_mapname2mapid(map_name)) < 0)
  2239. 			map_id = sd->bl.m;
  2240. 	}
  2241.  
  2242. 	map_foreachinmap(atkillmonster_sub, map_id, BL_MOB, drop);
  2243.  
  2244. 	clif_displaymessage(fd, msg_txt(165)); // All monsters killed!
  2245.  
  2246. 	return;
  2247. }
  2248.  
  2249. ACMD_FUNC(killmonster)
  2250. {
  2251. 	atcommand_killmonster_sub(fd, sd, message, 1);
  2252. 	return 0;
  2253. }
  2254.  
  2255. /*==========================================
  2256.  *
  2257.  *------------------------------------------*/
  2258. ACMD_FUNC(killmonster2)
  2259. {
  2260. 	atcommand_killmonster_sub(fd, sd, message, 0);
  2261. 	return 0;
  2262. }
  2263.  
  2264. /*==========================================
  2265.  *
  2266.  *------------------------------------------*/
  2267. ACMD_FUNC(refine)
  2268. {
  2269. 	int i,j, position = 0, refine = 0, current_position, final_refine;
  2270. 	int count;
  2271. 	nullpo_retr(-1, sd);
  2272.  
  2273. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2274.  
  2275. 	if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) {
  2276. 		clif_displaymessage(fd, "Please, enter a position and an amount (usage: @refine <equip position> <+/- amount>).");
  2277. 		sprintf(atcmd_output, "%d: Lower Headgear", EQP_HEAD_LOW);
  2278. 		clif_displaymessage(fd, atcmd_output);
  2279. 		sprintf(atcmd_output, "%d: Right Hand", EQP_HAND_R);
  2280. 		clif_displaymessage(fd, atcmd_output);
  2281. 		sprintf(atcmd_output, "%d: Garment", EQP_GARMENT);
  2282. 		clif_displaymessage(fd, atcmd_output);
  2283. 		sprintf(atcmd_output, "%d: Left Accessory", EQP_ACC_L);
  2284. 		clif_displaymessage(fd, atcmd_output);
  2285. 		sprintf(atcmd_output, "%d: Body Armor", EQP_ARMOR);
  2286. 		clif_displaymessage(fd, atcmd_output);
  2287. 		sprintf(atcmd_output, "%d: Left Hand", EQP_HAND_L);
  2288. 		clif_displaymessage(fd, atcmd_output);
  2289. 		sprintf(atcmd_output, "%d: Shoes", EQP_SHOES);
  2290. 		clif_displaymessage(fd, atcmd_output);
  2291. 		sprintf(atcmd_output, "%d: Right Accessory", EQP_ACC_R);
  2292. 		clif_displaymessage(fd, atcmd_output);
  2293. 		sprintf(atcmd_output, "%d: Top Headgear", EQP_HEAD_TOP);
  2294. 		clif_displaymessage(fd, atcmd_output);
  2295. 		sprintf(atcmd_output, "%d: Mid Headgear", EQP_HEAD_MID);
  2296. 		clif_displaymessage(fd, atcmd_output);
  2297. 		return -1;
  2298. 	}
  2299.  
  2300. 	refine = cap_value(refine, -MAX_REFINE, MAX_REFINE);
  2301.  
  2302. 	count = 0;
  2303. 	for (j = 0; j < EQI_MAX-1; j++) {
  2304. 		if ((i = sd->equip_index[j]) < 0)
  2305. 			continue;
  2306. 		if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == i)
  2307. 			continue;
  2308. 		if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == i)
  2309. 			continue;
  2310. 		if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == i || sd->equip_index[EQI_HEAD_LOW] == i))
  2311. 			continue;
  2312.  
  2313. 		if(position && !(sd->status.inventory[i].equip & position))
  2314. 			continue;
  2315.  
  2316. 		final_refine = cap_value(sd->status.inventory[i].refine + refine, 0, MAX_REFINE);
  2317. 		if (sd->status.inventory[i].refine != final_refine) {
  2318. 			sd->status.inventory[i].refine = final_refine;
  2319. 			current_position = sd->status.inventory[i].equip;
  2320. 			pc_unequipitem(sd, i, 3);
  2321. 			clif_refine(fd, 0, i, sd->status.inventory[i].refine);
  2322. 			clif_delitem(sd, i, 1, 3);
  2323. 			clif_additem(sd, i, 1, 0);
  2324. 			pc_equipitem(sd, i, current_position);
  2325. 			clif_misceffect(&sd->bl, 3);
  2326. 			count++;
  2327. 		}
  2328. 	}
  2329.  
  2330. 	if (count == 0)
  2331. 		clif_displaymessage(fd, msg_txt(166)); // No item has been refined.
  2332. 	else if (count == 1)
  2333. 		clif_displaymessage(fd, msg_txt(167)); // 1 item has been refined.
  2334. 	else {
  2335. 		sprintf(atcmd_output, msg_txt(168), count); // %d items have been refined.
  2336. 		clif_displaymessage(fd, atcmd_output);
  2337. 	}
  2338.  
  2339. 	return 0;
  2340. }
  2341.  
  2342. /*==========================================
  2343.  *
  2344.  *------------------------------------------*/
  2345. ACMD_FUNC(produce)
  2346. {
  2347. 	char item_name[100];
  2348. 	int item_id, attribute = 0, star = 0;
  2349. 	int flag = 0;
  2350. 	struct item_data *item_data;
  2351. 	struct item tmp_item;
  2352. 	nullpo_retr(-1, sd);
  2353.  
  2354. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2355. 	memset(item_name, '\0', sizeof(item_name));
  2356.  
  2357. 	if (!message || !*message || (
  2358. 		sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 &&
  2359. 		sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1
  2360. 	)) {
  2361. 		clif_displaymessage(fd, "Please, enter at least an item name/id (usage: @produce <equip name or equip ID> <element> <# of very's>).");
  2362. 		return -1;
  2363. 	}
  2364.  
  2365. 	item_id = 0;
  2366. 	if ((item_data = itemdb_searchname(item_name)) == NULL &&
  2367. 	    (item_data = itemdb_exists(atoi(item_name))) == NULL)
  2368. 	{
  2369. 		clif_displaymessage(fd, msg_txt(170)); //This item is not an equipment.
  2370. 		return -1;
  2371. 	}
  2372. 	item_id = item_data->nameid;
  2373. 	if (itemdb_isequip2(item_data)) {
  2374. 		if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
  2375. 			attribute = ATTRIBUTE_NORMAL;
  2376. 		if (star < MIN_STAR || star > MAX_STAR)
  2377. 			star = 0;
  2378. 		memset(&tmp_item, 0, sizeof tmp_item);
  2379. 		tmp_item.nameid = item_id;
  2380. 		tmp_item.amount = 1;
  2381. 		tmp_item.identify = 1;
  2382. 		tmp_item.card[0] = CARD0_FORGE;
  2383. 		tmp_item.card[1] = item_data->type==IT_WEAPON?
  2384. 			((star*5) << 8) + attribute:0;
  2385. 		tmp_item.card[2] = GetWord(sd->status.char_id, 0);
  2386. 		tmp_item.card[3] = GetWord(sd->status.char_id, 1);
  2387. 		clif_produceeffect(sd, 0, item_id);
  2388. 		clif_misceffect(&sd->bl, 3);
  2389.  
  2390. 		if ((flag = pc_additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
  2391. 			clif_additem(sd, 0, 0, flag);
  2392. 	} else {
  2393. 		sprintf(atcmd_output, msg_txt(169), item_id, item_data->name); // The item (%d: '%s') is not equipable.
  2394. 		clif_displaymessage(fd, atcmd_output);
  2395. 		return -1;
  2396. 	}
  2397.  
  2398. 	return 0;
  2399. }
  2400.  
  2401. /*==========================================
  2402.  *
  2403.  *------------------------------------------*/
  2404. ACMD_FUNC(memo)
  2405. {
  2406. 	int position = 0;
  2407. 	nullpo_retr(-1, sd);
  2408.  
  2409. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2410.  
  2411. 	if( !message || !*message || sscanf(message, "%d", &position) < 1 )
  2412. 	{
  2413. 		int i;
  2414. 		clif_displaymessage(sd->fd,  "Your actual memo positions are:");
  2415. 		for( i = 0; i < MAX_MEMOPOINTS; i++ )
  2416. 		{
  2417. 			if( sd->status.memo_point[i].map )
  2418. 				sprintf(atcmd_output, "%d - %s (%d,%d)", i, mapindex_id2name(sd->status.memo_point[i].map), sd->status.memo_point[i].x, sd->status.memo_point[i].y);
  2419. 			else
  2420. 				sprintf(atcmd_output, msg_txt(171), i); // %d - void
  2421. 			clif_displaymessage(sd->fd, atcmd_output);
  2422.  		}
  2423. 		return 0;
  2424.  	}
  2425.  
  2426. 	if( position < 0 || position >= MAX_MEMOPOINTS )
  2427. 	{
  2428. 		sprintf(atcmd_output, "Please, enter a valid position (usage: @memo <memo_position:%d-%d>).", 0, MAX_MEMOPOINTS-1);
  2429. 		clif_displaymessage(fd, atcmd_output);
  2430. 		return -1;
  2431. 	}
  2432.  
  2433. 	pc_memo(sd, position);
  2434. 	return 0;
  2435. }
  2436.  
  2437. /*==========================================
  2438.  *
  2439.  *------------------------------------------*/
  2440. ACMD_FUNC(gat)
  2441. {
  2442. 	int y;
  2443. 	nullpo_retr(-1, sd);
  2444.  
  2445. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2446.  
  2447. 	for (y = 2; y >= -2; y--) {
  2448. 		sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
  2449. 			map[sd->bl.m].name,   sd->bl.x - 2, sd->bl.y + y,
  2450.  			map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE),
  2451.  			map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE),
  2452.  			map_getcell(sd->bl.m, sd->bl.x,     sd->bl.y + y, CELL_GETTYPE),
  2453.  			map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE),
  2454.  			map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE));
  2455.  
  2456. 		clif_displaymessage(fd, atcmd_output);
  2457. 	}
  2458.  
  2459. 	return 0;
  2460. }
  2461.  
  2462. /*==========================================
  2463.  *
  2464.  *------------------------------------------*/
  2465. ACMD_FUNC(displaystatus)
  2466. {
  2467. 	int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0;
  2468. 	nullpo_retr(-1, sd);
  2469.  
  2470. 	if (!message || !*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) {
  2471. 		clif_displaymessage(fd, "Please, enter a status type/flag (usage: @displaystatus <status type> <flag> <tick> {<val1> {<val2> {<val3>}}}).");
  2472. 		return -1;
  2473. 	}
  2474. 	if (i < 2) flag = 1;
  2475. 	if (i < 3) tick = 0;
  2476.  
  2477. 	clif_status_change(&sd->bl, type, flag, tick, val1, val2, val3);
  2478.  
  2479. 	return 0;
  2480. }
  2481.  
  2482. /*==========================================
  2483.  * @stpoint (Rewritten by [Yor])
  2484.  *------------------------------------------*/
  2485. ACMD_FUNC(statuspoint)
  2486. {
  2487. 	int point;
  2488. 	unsigned int new_status_point;
  2489.  
  2490. 	if (!message || !*message || (point = atoi(message)) == 0) {
  2491. 		clif_displaymessage(fd, "Please, enter a number (usage: @stpoint <number of points>).");
  2492. 		return -1;
  2493. 	}
  2494.  
  2495. 	if(point < 0)
  2496. 	{
  2497. 		if(sd->status.status_point < (unsigned int)(-point))
  2498. 		{
  2499. 			new_status_point = 0;
  2500. 		}
  2501. 		else
  2502. 		{
  2503. 			new_status_point = sd->status.status_point + point;
  2504. 		}
  2505. 	}
  2506. 	else if(UINT_MAX - sd->status.status_point < (unsigned int)point)
  2507. 	{
  2508. 		new_status_point = UINT_MAX;
  2509. 	}
  2510. 	else
  2511. 	{
  2512. 		new_status_point = sd->status.status_point + point;
  2513. 	}
  2514.  
  2515. 	if (new_status_point != sd->status.status_point) {
  2516. 		sd->status.status_point = new_status_point;
  2517. 		clif_updatestatus(sd, SP_STATUSPOINT);
  2518. 		clif_displaymessage(fd, msg_txt(174)); // Number of status points changed.
  2519. 	} else {
  2520. 		if (point < 0)
  2521. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2522. 		else
  2523. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2524. 		return -1;
  2525. 	}
  2526.  
  2527. 	return 0;
  2528. }
  2529.  
  2530. /*==========================================
  2531.  * @skpoint (Rewritten by [Yor])
  2532.  *------------------------------------------*/
  2533. ACMD_FUNC(skillpoint)
  2534. {
  2535. 	int point;
  2536. 	unsigned int new_skill_point;
  2537. 	nullpo_retr(-1, sd);
  2538.  
  2539. 	if (!message || !*message || (point = atoi(message)) == 0) {
  2540. 		clif_displaymessage(fd, "Please, enter a number (usage: @skpoint <number of points>).");
  2541. 		return -1;
  2542. 	}
  2543.  
  2544. 	if(point < 0)
  2545. 	{
  2546. 		if(sd->status.skill_point < (unsigned int)(-point))
  2547. 		{
  2548. 			new_skill_point = 0;
  2549. 		}
  2550. 		else
  2551. 		{
  2552. 			new_skill_point = sd->status.skill_point + point;
  2553. 		}
  2554. 	}
  2555. 	else if(UINT_MAX - sd->status.skill_point < (unsigned int)point)
  2556. 	{
  2557. 		new_skill_point = UINT_MAX;
  2558. 	}
  2559. 	else
  2560. 	{
  2561. 		new_skill_point = sd->status.skill_point + point;
  2562. 	}
  2563.  
  2564. 	if (new_skill_point != sd->status.skill_point) {
  2565. 		sd->status.skill_point = new_skill_point;
  2566. 		clif_updatestatus(sd, SP_SKILLPOINT);
  2567. 		clif_displaymessage(fd, msg_txt(175)); // Number of skill points changed.
  2568. 	} else {
  2569. 		if (point < 0)
  2570. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2571. 		else
  2572. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2573. 		return -1;
  2574. 	}
  2575.  
  2576. 	return 0;
  2577. }
  2578.  
  2579. /*==========================================
  2580.  * @zeny (Rewritten by [Yor])
  2581.  *------------------------------------------*/
  2582. ACMD_FUNC(zeny)
  2583. {
  2584. 	int zeny, new_zeny;
  2585. 	nullpo_retr(-1, sd);
  2586.  
  2587. 	if (!message || !*message || (zeny = atoi(message)) == 0) {
  2588. 		clif_displaymessage(fd, "Please, enter an amount (usage: @zeny <amount>).");
  2589. 		return -1;
  2590. 	}
  2591.  
  2592. 	new_zeny = sd->status.zeny + zeny;
  2593. 	if (zeny > 0 && (zeny > MAX_ZENY || new_zeny > MAX_ZENY)) // fix positiv overflow
  2594. 		new_zeny = MAX_ZENY;
  2595. 	else if (zeny < 0 && (zeny < -MAX_ZENY || new_zeny < 0)) // fix negativ overflow
  2596. 		new_zeny = 0;
  2597.  
  2598. 	if (new_zeny != sd->status.zeny) {
  2599. 		sd->status.zeny = new_zeny;
  2600. 		clif_updatestatus(sd, SP_ZENY);
  2601. 		clif_displaymessage(fd, msg_txt(176)); // Current amount of zeny changed.
  2602. 	} else {
  2603. 		if (zeny < 0)
  2604. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2605. 		else
  2606. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2607. 		return -1;
  2608. 	}
  2609.  
  2610. 	return 0;
  2611. }
  2612.  
  2613. /*==========================================
  2614.  *
  2615.  *------------------------------------------*/
  2616. ACMD_FUNC(param)
  2617. {
  2618. 	int i, value = 0, new_value, max;
  2619. 	const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" };
  2620. 	short* status[6];
  2621.  	//we don't use direct initialization because it isn't part of the c standard.
  2622. 	nullpo_retr(-1, sd);
  2623.  
  2624. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2625.  
  2626. 	if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2627. 		sprintf(atcmd_output, "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustment>).");
  2628. 		clif_displaymessage(fd, atcmd_output);
  2629. 		return -1;
  2630. 	}
  2631.  
  2632. 	ARR_FIND( 0, ARRAYLENGTH(param), i, strcmpi(command+1, param[i]) == 0 );
  2633.  
  2634. 	if( i == ARRAYLENGTH(param) || i > MAX_STATUS_TYPE) { // normally impossible...
  2635. 		sprintf(atcmd_output, "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustment>).");
  2636. 		clif_displaymessage(fd, atcmd_output);
  2637. 		return -1;
  2638. 	}
  2639.  
  2640. 	status[0] = &sd->status.str;
  2641. 	status[1] = &sd->status.agi;
  2642. 	status[2] = &sd->status.vit;
  2643. 	status[3] = &sd->status.int_;
  2644. 	status[4] = &sd->status.dex;
  2645. 	status[5] = &sd->status.luk;
  2646.  
  2647. 	if( battle_config.atcommand_max_stat_bypass )
  2648. 		max = SHRT_MAX;
  2649. 	else
  2650. 		max = pc_maxparameter(sd);
  2651.  
  2652. 	if(value < 0 && *status[i] <= -value) {
  2653. 		new_value = 1;
  2654. 	} else if(max - *status[i] < value) {
  2655. 		new_value = max;
  2656. 	} else {
  2657. 		new_value = *status[i] + value;
  2658. 	}
  2659.  
  2660. 	if (new_value != *status[i]) {
  2661. 		*status[i] = new_value;
  2662. 		clif_updatestatus(sd, SP_STR + i);
  2663. 		clif_updatestatus(sd, SP_USTR + i);
  2664. 		status_calc_pc(sd, 0);
  2665. 		clif_displaymessage(fd, msg_txt(42)); // Stat changed.
  2666. 	} else {
  2667. 		if (value < 0)
  2668. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2669. 		else
  2670. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2671. 		return -1;
  2672. 	}
  2673.  
  2674. 	return 0;
  2675. }
  2676.  
  2677. /*==========================================
  2678.  * Stat all by fritz (rewritten by [Yor])
  2679.  *------------------------------------------*/
  2680. ACMD_FUNC(stat_all)
  2681. {
  2682. 	int index, count, value, max, new_value;
  2683. 	short* status[6];
  2684.  	//we don't use direct initialization because it isn't part of the c standard.
  2685. 	nullpo_retr(-1, sd);
  2686.  
  2687. 	status[0] = &sd->status.str;
  2688. 	status[1] = &sd->status.agi;
  2689. 	status[2] = &sd->status.vit;
  2690. 	status[3] = &sd->status.int_;
  2691. 	status[4] = &sd->status.dex;
  2692. 	status[5] = &sd->status.luk;
  2693.  
  2694. 	if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2695. 		value = pc_maxparameter(sd);
  2696. 		max = pc_maxparameter(sd);
  2697. 	} else {
  2698. 		if( battle_config.atcommand_max_stat_bypass )
  2699. 			max = SHRT_MAX;
  2700. 		else
  2701. 			max = pc_maxparameter(sd);
  2702. 	}
  2703.  
  2704. 	count = 0;
  2705. 	for (index = 0; index < ARRAYLENGTH(status); index++) {
  2706.  
  2707. 		if (value > 0 && *status[index] > max - value)
  2708. 			new_value = max;
  2709. 		else if (value < 0 && *status[index] <= -value)
  2710. 			new_value = 1;
  2711. 		else
  2712. 			new_value = *status[index] +value;
  2713.  
  2714. 		if (new_value != (int)*status[index]) {
  2715. 			*status[index] = new_value;
  2716. 			clif_updatestatus(sd, SP_STR + index);
  2717. 			clif_updatestatus(sd, SP_USTR + index);
  2718. 			count++;
  2719. 		}
  2720. 	}
  2721.  
  2722. 	if (count > 0) { // if at least 1 stat modified
  2723. 		status_calc_pc(sd, 0);
  2724. 		clif_displaymessage(fd, msg_txt(84)); // All stats changed!
  2725. 	} else {
  2726. 		if (value < 0)
  2727. 			clif_displaymessage(fd, msg_txt(177)); // You cannot decrease that stat anymore.
  2728. 		else
  2729. 			clif_displaymessage(fd, msg_txt(178)); // You cannot increase that stat anymore.
  2730. 		return -1;
  2731. 	}
  2732.  
  2733. 	return 0;
  2734. }
  2735.  
  2736. /*==========================================
  2737.  *
  2738.  *------------------------------------------*/
  2739. ACMD_FUNC(guildlevelup)
  2740. {
  2741. 	int level = 0;
  2742. 	short added_level;
  2743. 	struct guild *guild_info;
  2744. 	nullpo_retr(-1, sd);
  2745.  
  2746. 	if (!message || !*message || sscanf(message, "%d", &level) < 1 || level == 0) {
  2747. 		clif_displaymessage(fd, "Please, enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>).");
  2748. 		return -1;
  2749. 	}
  2750.  
  2751. 	if (sd->status.guild_id <= 0 || (guild_info = guild_search(sd->status.guild_id)) == NULL) {
  2752. 		clif_displaymessage(fd, msg_txt(43)); // You're not in a guild.
  2753. 		return -1;
  2754. 	}
  2755. 	//if (strcmp(sd->status.name, guild_info->master) != 0) {
  2756. 	//	clif_displaymessage(fd, msg_txt(44)); // You're not the master of your guild.
  2757. 	//	return -1;
  2758. 	//}
  2759.  
  2760. 	added_level = (short)level;
  2761. 	if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild_lv))) // fix positiv overflow
  2762. 		added_level = (short)MAX_GUILDLEVEL - guild_info->guild_lv;
  2763. 	else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild_lv))) // fix negativ overflow
  2764. 		added_level = 1 - guild_info->guild_lv;
  2765.  
  2766. 	if (added_level != 0) {
  2767. 		intif_guild_change_basicinfo(guild_info->guild_id, GBI_GUILDLV, &added_level, sizeof(added_level));
  2768. 		clif_displaymessage(fd, msg_txt(179)); // Guild level changed.
  2769. 	} else {
  2770. 		clif_displaymessage(fd, msg_txt(45)); // Guild level change failed.
  2771. 		return -1;
  2772. 	}
  2773.  
  2774. 	return 0;
  2775. }
  2776.  
  2777. /*==========================================
  2778.  *
  2779.  *------------------------------------------*/
  2780. ACMD_FUNC(makeegg)
  2781. {
  2782. 	struct item_data *item_data;
  2783. 	int id, pet_id;
  2784. 	nullpo_retr(-1, sd);
  2785.  
  2786. 	if (!message || !*message) {
  2787. 		clif_displaymessage(fd, "Please, enter a monster/egg name/id (usage: @makeegg <pet>).");
  2788. 		return -1;
  2789. 	}
  2790.  
  2791. 	if ((item_data = itemdb_searchname(message)) != NULL) // for egg name
  2792. 		id = item_data->nameid;
  2793. 	else
  2794. 	if ((id = mobdb_searchname(message)) != 0) // for monster name
  2795. 		;
  2796. 	else
  2797. 		id = atoi(message);
  2798.  
  2799. 	pet_id = search_petDB_index(id, PET_CLASS);
  2800. 	if (pet_id < 0)
  2801. 		pet_id = search_petDB_index(id, PET_EGG);
  2802. 	if (pet_id >= 0) {
  2803. 		sd->catch_target_class = pet_db[pet_id].class_;
  2804. 		intif_create_pet(
  2805. 			sd->status.account_id, sd->status.char_id,
  2806. 			(short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  2807. 			(short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  2808. 			100, 0, 1, pet_db[pet_id].jname);
  2809. 	} else {
  2810. 		clif_displaymessage(fd, msg_txt(180)); // The monster/egg name/id doesn't exist.
  2811. 		return -1;
  2812. 	}
  2813.  
  2814. 	return 0;
  2815. }
  2816.  
  2817. /*==========================================
  2818.  *
  2819.  *------------------------------------------*/
  2820. ACMD_FUNC(hatch)
  2821. {
  2822. 	nullpo_retr(-1, sd);
  2823. 	if (sd->status.pet_id <= 0)
  2824. 		clif_sendegg(sd);
  2825. 	else {
  2826. 		clif_displaymessage(fd, msg_txt(181)); // You already have a pet.
  2827. 		return -1;
  2828. 	}
  2829.  
  2830. 	return 0;
  2831. }
  2832.  
  2833. /*==========================================
  2834.  *
  2835.  *------------------------------------------*/
  2836. ACMD_FUNC(petfriendly)
  2837. {
  2838. 	int friendly;
  2839. 	struct pet_data *pd;
  2840. 	nullpo_retr(-1, sd);
  2841.  
  2842. 	if (!message || !*message || (friendly = atoi(message)) < 0) {
  2843. 		clif_displaymessage(fd, "Please, enter a valid value (usage: @petfriendly <0-1000>).");
  2844. 		return -1;
  2845. 	}
  2846.  
  2847. 	pd = sd->pd;
  2848. 	if (!pd) {
  2849. 		clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2850. 		return -1;
  2851. 	}
  2852.  
  2853. 	if (friendly < 0 || friendly > 1000)
  2854. 	{
  2855. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  2856. 		return -1;
  2857. 	}
  2858.  
  2859. 	if (friendly == pd->pet.intimate) {
  2860. 		clif_displaymessage(fd, msg_txt(183)); // Pet intimacy is already at maximum.
  2861. 		return -1;
  2862. 	}
  2863.  
  2864. 	pet_set_intimate(pd, friendly);
  2865. 	clif_send_petstatus(sd);
  2866. 	clif_displaymessage(fd, msg_txt(182)); // Pet intimacy changed.
  2867. 	return 0;
  2868. }
  2869.  
  2870. /*==========================================
  2871.  *
  2872.  *------------------------------------------*/
  2873. ACMD_FUNC(pethungry)
  2874. {
  2875. 	int hungry;
  2876. 	struct pet_data *pd;
  2877. 	nullpo_retr(-1, sd);
  2878.  
  2879. 	if (!message || !*message || (hungry = atoi(message)) < 0) {
  2880. 		clif_displaymessage(fd, "Please, enter a valid number (usage: @pethungry <0-100>).");
  2881. 		return -1;
  2882. 	}
  2883.  
  2884. 	pd = sd->pd;
  2885. 	if (!sd->status.pet_id || !pd) {
  2886. 		clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2887. 		return -1;
  2888. 	}
  2889. 	if (hungry < 0 || hungry > 100) {
  2890. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  2891. 		return -1;
  2892. 	}
  2893. 	if (hungry == pd->pet.hungry) {
  2894. 		clif_displaymessage(fd, msg_txt(186)); // Pet hunger is already at maximum.
  2895. 		return -1;
  2896. 	}
  2897.  
  2898. 	pd->pet.hungry = hungry;
  2899. 	clif_send_petstatus(sd);
  2900. 	clif_displaymessage(fd, msg_txt(185)); // Pet hunger changed.
  2901.  
  2902. 	return 0;
  2903. }
  2904.  
  2905. /*==========================================
  2906.  *
  2907.  *------------------------------------------*/
  2908. ACMD_FUNC(petrename)
  2909. {
  2910. 	struct pet_data *pd;
  2911. 	nullpo_retr(-1, sd);
  2912. 	if (!sd->status.pet_id || !sd->pd) {
  2913. 		clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2914. 		return -1;
  2915. 	}
  2916. 	pd = sd->pd;
  2917. 	if (!pd->pet.rename_flag) {
  2918. 		clif_displaymessage(fd, msg_txt(188)); // You can already rename your pet.
  2919. 		return -1;
  2920. 	}
  2921.  
  2922. 	pd->pet.rename_flag = 0;
  2923. 	intif_save_petdata(sd->status.account_id, &pd->pet);
  2924. 	clif_send_petstatus(sd);
  2925. 	clif_displaymessage(fd, msg_txt(187)); // You can now rename your pet.
  2926.  
  2927. 	return 0;
  2928. }
  2929.  
  2930. /*==========================================
  2931.  *
  2932.  *------------------------------------------*/
  2933. ACMD_FUNC(recall) {
  2934. 	struct map_session_data *pl_sd = NULL;
  2935.  
  2936. 	nullpo_retr(-1, sd);
  2937.  
  2938. 	if (!message || !*message) {
  2939. 		clif_displaymessage(fd, "Please, enter a player name (usage: @recall <player name/id>).");
  2940. 		return -1;
  2941. 	}
  2942.  
  2943. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  2944. 	{
  2945. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  2946. 		return -1;
  2947. 	}
  2948.  
  2949. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  2950. 	{
  2951. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level doesn't authorize you to preform this action on the specified player.
  2952. 		return -1;
  2953. 	}
  2954.  
  2955. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2956. 		clif_displaymessage(fd, "You are not authorised to warp someone to your actual map.");
  2957. 		return -1;
  2958. 	}
  2959. 	if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2960. 		clif_displaymessage(fd, "You are not authorized to warp this player from its actual map.");
  2961. 		return -1;
  2962. 	}
  2963. 	pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  2964. 	sprintf(atcmd_output, msg_txt(46), pl_sd->status.name); // %s recalled!
  2965. 	clif_displaymessage(fd, atcmd_output);
  2966.  
  2967. 	return 0;
  2968. }
  2969.  
  2970. /*==========================================
  2971.  * charblock command (usage: charblock <player_name>)
  2972.  * This command do a definitiv ban on a player
  2973.  *------------------------------------------*/
  2974. ACMD_FUNC(char_block)
  2975. {
  2976. 	nullpo_retr(-1, sd);
  2977.  
  2978. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2979.  
  2980. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2981. 		clif_displaymessage(fd, "Please, enter a player name (usage: @charblock/@block <name>).");
  2982. 		return -1;
  2983. 	}
  2984.  
  2985. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  2986. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  2987.  
  2988. 	return 0;
  2989. }
  2990.  
  2991. /*==========================================
  2992.  * charban command (usage: charban <time> <player_name>)
  2993.  * This command do a limited ban on a player
  2994.  * Time is done as follows:
  2995.  *   Adjustment value (-1, 1, +1, etc...)
  2996.  *   Modified element:
  2997.  *     a or y: year
  2998.  *     m:  month
  2999.  *     j or d: day
  3000.  *     h:  hour
  3001.  *     mn: minute
  3002.  *     s:  second
  3003.  * <example> @ban +1m-2mn1s-6y test_player
  3004.  *           this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
  3005.  *------------------------------------------*/
  3006. ACMD_FUNC(char_ban)
  3007. {
  3008. 	char * modif_p;
  3009. 	int year, month, day, hour, minute, second, value;
  3010. 	time_t timestamp;
  3011. 	struct tm *tmtime;
  3012. 	nullpo_retr(-1, sd);
  3013.  
  3014. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3015. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3016.  
  3017. 	if (!message || !*message || sscanf(message, "%s %23[^\n]", atcmd_output, atcmd_player_name) < 2) {
  3018. 		clif_displaymessage(fd, "Please, enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish <time> <name>).");
  3019. 		return -1;
  3020. 	}
  3021.  
  3022. 	atcmd_output[sizeof(atcmd_output)-1] = '\0';
  3023.  
  3024. 	modif_p = atcmd_output;
  3025. 	year = month = day = hour = minute = second = 0;
  3026. 	while (modif_p[0] != '\0') {
  3027. 		value = atoi(modif_p);
  3028. 		if (value == 0)
  3029. 			modif_p++;
  3030. 		else {
  3031. 			if (modif_p[0] == '-' || modif_p[0] == '+')
  3032. 				modif_p++;
  3033. 			while (modif_p[0] >= '0' && modif_p[0] <= '9')
  3034. 				modif_p++;
  3035. 			if (modif_p[0] == 's') {
  3036. 				second = value;
  3037. 				modif_p++;
  3038. 			} else if (modif_p[0] == 'n') {
  3039. 				minute = value;
  3040. 				modif_p++;
  3041. 			} else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  3042. 				minute = value;
  3043. 				modif_p = modif_p + 2;
  3044. 			} else if (modif_p[0] == 'h') {
  3045. 				hour = value;
  3046. 				modif_p++;
  3047. 			} else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  3048. 				day = value;
  3049. 				modif_p++;
  3050. 			} else if (modif_p[0] == 'm') {
  3051. 				month = value;
  3052. 				modif_p++;
  3053. 			} else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  3054. 				year = value;
  3055. 				modif_p++;
  3056. 			} else if (modif_p[0] != '\0') {
  3057. 				modif_p++;
  3058. 			}
  3059. 		}
  3060. 	}
  3061. 	if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0) {
  3062. 		clif_displaymessage(fd, msg_txt(85)); // Invalid time for ban command.
  3063. 		return -1;
  3064. 	}
  3065. 	/**
  3066. 	 * We now check if you can adjust the ban to negative (and if this is the case)
  3067. 	 **/
  3068. 	timestamp = time(NULL);
  3069. 	tmtime = localtime(&timestamp);
  3070. 	tmtime->tm_year = tmtime->tm_year + year;
  3071. 	tmtime->tm_mon  = tmtime->tm_mon + month;
  3072. 	tmtime->tm_mday = tmtime->tm_mday + day;
  3073. 	tmtime->tm_hour = tmtime->tm_hour + hour;
  3074. 	tmtime->tm_min  = tmtime->tm_min + minute;
  3075. 	tmtime->tm_sec  = tmtime->tm_sec + second;
  3076. 	timestamp = mktime(tmtime);
  3077. 	if( timestamp <= time(NULL) && !pc_can_use_command(sd, "unban", COMMAND_ATCOMMAND) ) {
  3078. 		clif_displaymessage(fd,"You are not allowed to reduce the length of a ban");
  3079. 		return -1;
  3080. 	}
  3081.  
  3082. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 2, year, month, day, hour, minute, second); // type: 2 - ban
  3083. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3084.  
  3085. 	return 0;
  3086. }
  3087.  
  3088. /*==========================================
  3089.  * charunblock command (usage: charunblock <player_name>)
  3090.  *------------------------------------------*/
  3091. ACMD_FUNC(char_unblock)
  3092. {
  3093. 	nullpo_retr(-1, sd);
  3094.  
  3095. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3096.  
  3097. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3098. 		clif_displaymessage(fd, "Please, enter a player name (usage: @charunblock <player_name>).");
  3099. 		return -1;
  3100. 	}
  3101.  
  3102. 	// send answer to login server via char-server
  3103. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 3, 0, 0, 0, 0, 0, 0); // type: 3 - unblock
  3104. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3105.  
  3106. 	return 0;
  3107. }
  3108.  
  3109. /*==========================================
  3110.  * charunban command (usage: charunban <player_name>)
  3111.  *------------------------------------------*/
  3112. ACMD_FUNC(char_unban)
  3113. {
  3114. 	nullpo_retr(-1, sd);
  3115.  
  3116. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3117.  
  3118. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3119. 		clif_displaymessage(fd, "Please, enter a player name (usage: @charunban <player_name>).");
  3120. 		return -1;
  3121. 	}
  3122.  
  3123. 	// send answer to login server via char-server
  3124. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 4, 0, 0, 0, 0, 0, 0); // type: 4 - unban
  3125. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3126.  
  3127. 	return 0;
  3128. }
  3129.  
  3130. /*==========================================
  3131.  *
  3132.  *------------------------------------------*/
  3133. ACMD_FUNC(night)
  3134. {
  3135. 	nullpo_retr(-1, sd);
  3136.  
  3137. 	if (night_flag != 1) {
  3138. 		map_night_timer(night_timer_tid, 0, 0, 1);
  3139. 	} else {
  3140. 		clif_displaymessage(fd, msg_txt(89)); // Night mode is already enabled.
  3141. 		return -1;
  3142. 	}
  3143.  
  3144. 	return 0;
  3145. }
  3146.  
  3147. /*==========================================
  3148.  *
  3149.  *------------------------------------------*/
  3150. ACMD_FUNC(day)
  3151. {
  3152. 	nullpo_retr(-1, sd);
  3153.  
  3154. 	if (night_flag != 0) {
  3155. 		map_day_timer(day_timer_tid, 0, 0, 1);
  3156. 	} else {
  3157. 		clif_displaymessage(fd, msg_txt(90)); // Day mode is already enabled.
  3158. 		return -1;
  3159. 	}
  3160.  
  3161. 	return 0;
  3162. }
  3163.  
  3164. /*==========================================
  3165.  *
  3166.  *------------------------------------------*/
  3167. ACMD_FUNC(doom)
  3168. {
  3169. 	struct map_session_data* pl_sd;
  3170. 	struct s_mapiterator* iter;
  3171.  
  3172. 	nullpo_retr(-1, sd);
  3173.  
  3174. 	iter = mapit_getallusers();
  3175. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3176. 	{
  3177. 		if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3178. 		{
  3179. 			status_kill(&pl_sd->bl);
  3180. 			clif_specialeffect(&pl_sd->bl,450,AREA);
  3181. 			clif_displaymessage(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement.
  3182. 		}
  3183. 	}
  3184. 	mapit_free(iter);
  3185.  
  3186. 	clif_displaymessage(fd, msg_txt(62)); // Judgement was made.
  3187.  
  3188. 	return 0;
  3189. }
  3190.  
  3191. /*==========================================
  3192.  *
  3193.  *------------------------------------------*/
  3194. ACMD_FUNC(doommap)
  3195. {
  3196. 	struct map_session_data* pl_sd;
  3197. 	struct s_mapiterator* iter;
  3198.  
  3199. 	nullpo_retr(-1, sd);
  3200.  
  3201. 	iter = mapit_getallusers();
  3202. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3203. 	{
  3204. 		if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3205. 		{
  3206. 			status_kill(&pl_sd->bl);
  3207. 			clif_specialeffect(&pl_sd->bl,450,AREA);
  3208. 			clif_displaymessage(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement.
  3209. 		}
  3210. 	}
  3211. 	mapit_free(iter);
  3212.  
  3213. 	clif_displaymessage(fd, msg_txt(62)); // Judgement was made.
  3214.  
  3215. 	return 0;
  3216. }
  3217.  
  3218. /*==========================================
  3219.  *
  3220.  *------------------------------------------*/
  3221. static void atcommand_raise_sub(struct map_session_data* sd)
  3222. {
  3223. 	if (!status_isdead(&sd->bl))
  3224. 		return;
  3225.  
  3226. 	if(!status_revive(&sd->bl, 100, 100))
  3227. 		return;
  3228. 	clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  3229. 	clif_displaymessage(sd->fd, msg_txt(63)); // Mercy has been shown.
  3230. }
  3231.  
  3232. /*==========================================
  3233.  *
  3234.  *------------------------------------------*/
  3235. ACMD_FUNC(raise)
  3236. {
  3237. 	struct map_session_data* pl_sd;
  3238. 	struct s_mapiterator* iter;
  3239.  
  3240. 	nullpo_retr(-1, sd);
  3241.  
  3242. 	iter = mapit_getallusers();
  3243. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3244. 		atcommand_raise_sub(pl_sd);
  3245. 	mapit_free(iter);
  3246.  
  3247. 	clif_displaymessage(fd, msg_txt(64)); // Mercy has been granted.
  3248.  
  3249. 	return 0;
  3250. }
  3251.  
  3252. /*==========================================
  3253.  *
  3254.  *------------------------------------------*/
  3255. ACMD_FUNC(raisemap)
  3256. {
  3257. 	struct map_session_data* pl_sd;
  3258. 	struct s_mapiterator* iter;
  3259.  
  3260. 	nullpo_retr(-1, sd);
  3261.  
  3262. 	iter = mapit_getallusers();
  3263. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3264. 		if (sd->bl.m == pl_sd->bl.m)
  3265. 			atcommand_raise_sub(pl_sd);
  3266. 	mapit_free(iter);
  3267.  
  3268. 	clif_displaymessage(fd, msg_txt(64)); // Mercy has been granted.
  3269.  
  3270. 	return 0;
  3271. }
  3272.  
  3273. /*==========================================
  3274.  *
  3275.  *------------------------------------------*/
  3276. ACMD_FUNC(kick)
  3277. {
  3278. 	struct map_session_data *pl_sd;
  3279. 	nullpo_retr(-1, sd);
  3280.  
  3281. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3282.  
  3283. 	if (!message || !*message) {
  3284. 		clif_displaymessage(fd, "Please, enter a player name (usage: @kick <player name/id>).");
  3285. 		return -1;
  3286. 	}
  3287.  
  3288. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  3289. 	{
  3290. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  3291. 		return -1;
  3292. 	}
  3293.  
  3294. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  3295. 	{
  3296. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  3297. 		return -1;
  3298. 	}
  3299.  
  3300. 	clif_GM_kick(sd, pl_sd);
  3301.  
  3302. 	return 0;
  3303. }
  3304.  
  3305. /*==========================================
  3306.  *
  3307.  *------------------------------------------*/
  3308. ACMD_FUNC(kickall)
  3309. {
  3310. 	struct map_session_data* pl_sd;
  3311. 	struct s_mapiterator* iter;
  3312. 	nullpo_retr(-1, sd);
  3313.  
  3314. 	iter = mapit_getallusers();
  3315. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3316. 	{
  3317. 		if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level
  3318. 			if (sd->status.account_id != pl_sd->status.account_id)
  3319. 				clif_GM_kick(NULL, pl_sd);
  3320. 		}
  3321. 	}
  3322. 	mapit_free(iter);
  3323.  
  3324. 	clif_displaymessage(fd, msg_txt(195)); // All players have been kicked!
  3325.  
  3326. 	return 0;
  3327. }
  3328.  
  3329. /*==========================================
  3330.  *
  3331.  *------------------------------------------*/
  3332. ACMD_FUNC(allskill)
  3333. {
  3334. 	nullpo_retr(-1, sd);
  3335. 	pc_allskillup(sd); // all skills
  3336. 	sd->status.skill_point = 0; // 0 skill points
  3337. 	clif_updatestatus(sd, SP_SKILLPOINT); // update
  3338. 	clif_displaymessage(fd, msg_txt(76)); // All skills have been added to your skill tree.
  3339.  
  3340. 	return 0;
  3341. }
  3342.  
  3343. /*==========================================
  3344.  *
  3345.  *------------------------------------------*/
  3346. ACMD_FUNC(questskill)
  3347. {
  3348. 	int skill_id;
  3349. 	nullpo_retr(-1, sd);
  3350.  
  3351. 	if (!message || !*message || (skill_id = atoi(message)) < 0)
  3352. 	{// also send a list of skills applicable to this command
  3353. 		const char* text;
  3354.  
  3355. 		// attempt to find the text corresponding to this command
  3356. 		text = atcommand_help_string( command );
  3357.  
  3358. 		// send the error message as always
  3359. 		clif_displaymessage(fd, "Please enter a quest skill number.");
  3360.  
  3361. 		if( text )
  3362. 		{// send the skill ID list associated with this command
  3363. 			clif_displaymessage( fd, text );
  3364. 		}
  3365.  
  3366. 		return -1;
  3367. 	}
  3368. 	if (skill_id < 0 && skill_id >= MAX_SKILL_DB) {
  3369. 		clif_displaymessage(fd, msg_txt(198)); // This skill number doesn't exist.
  3370. 		return -1;
  3371. 	}
  3372. 	if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  3373. 		clif_displaymessage(fd, msg_txt(197)); // This skill number doesn't exist or isn't a quest skill.
  3374. 		return -1;
  3375. 	}
  3376. 	if (pc_checkskill(sd, skill_id) > 0) {
  3377. 		clif_displaymessage(fd, msg_txt(196)); // You already have this quest skill.
  3378. 		return -1;
  3379. 	}
  3380.  
  3381. 	pc_skill(sd, skill_id, 1, 0);
  3382. 	clif_displaymessage(fd, msg_txt(70)); // You have learned the skill.
  3383.  
  3384. 	return 0;
  3385. }
  3386.  
  3387. /*==========================================
  3388.  *
  3389.  *------------------------------------------*/
  3390. ACMD_FUNC(lostskill)
  3391. {
  3392. 	int skill_id;
  3393. 	nullpo_retr(-1, sd);
  3394.  
  3395. 	if (!message || !*message || (skill_id = atoi(message)) < 0)
  3396. 	{// also send a list of skills applicable to this command
  3397. 		const char* text;
  3398.  
  3399. 		// attempt to find the text corresponding to this command
  3400. 		text = atcommand_help_string( command );
  3401.  
  3402. 		// send the error message as always
  3403. 		clif_displaymessage(fd, "Please enter a quest skill number.");
  3404.  
  3405. 		if( text )
  3406. 		{// send the skill ID list associated with this command
  3407. 			clif_displaymessage( fd, text );
  3408. 		}
  3409.  
  3410. 		return -1;
  3411. 	}
  3412. 	if (skill_id < 0 && skill_id >= MAX_SKILL) {
  3413. 		clif_displaymessage(fd, msg_txt(198)); // This skill number doesn't exist.
  3414. 		return -1;
  3415. 	}
  3416. 	if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  3417. 		clif_displaymessage(fd, msg_txt(197)); // This skill number doesn't exist or isn't a quest skill.
  3418. 		return -1;
  3419. 	}
  3420. 	if (pc_checkskill(sd, skill_id) == 0) {
  3421. 		clif_displaymessage(fd, msg_txt(201)); // You don't have this quest skill.
  3422. 		return -1;
  3423. 	}
  3424.  
  3425. 	sd->status.skill[skill_id].lv = 0;
  3426. 	sd->status.skill[skill_id].flag = 0;
  3427. 	clif_deleteskill(sd,skill_id);
  3428. 	clif_displaymessage(fd, msg_txt(71)); // You have forgotten the skill.
  3429.  
  3430. 	return 0;
  3431. }
  3432.  
  3433. /*==========================================
  3434.  *
  3435.  *------------------------------------------*/
  3436. ACMD_FUNC(spiritball)
  3437. {
  3438. 	int max_spiritballs;
  3439. 	int number;
  3440. 	nullpo_retr(-1, sd);
  3441.  
  3442. 	max_spiritballs = min(ARRAYLENGTH(sd->spirit_timer), 0x7FFF);
  3443.  
  3444. 	if( !message || !*message || (number = atoi(message)) < 0 || number > max_spiritballs )
  3445. 	{
  3446. 		char msg[CHAT_SIZE_MAX];
  3447. 		safesnprintf(msg, sizeof(msg), "Usage: @spiritball <number: 0-%d>", max_spiritballs);
  3448. 		clif_displaymessage(fd, msg);
  3449. 		return -1;
  3450. 	}
  3451.  
  3452. 	if( sd->spiritball > 0 )
  3453. 		pc_delspiritball(sd, sd->spiritball, 1);
  3454. 	sd->spiritball = number;
  3455. 	clif_spiritball(sd);
  3456. 	// no message, player can look the difference
  3457.  
  3458. 	return 0;
  3459. }
  3460.  
  3461. /*==========================================
  3462.  *
  3463.  *------------------------------------------*/
  3464. ACMD_FUNC(party)
  3465. {
  3466. 	char party[NAME_LENGTH];
  3467. 	nullpo_retr(-1, sd);
  3468.  
  3469. 	memset(party, '\0', sizeof(party));
  3470.  
  3471. 	if (!message || !*message || sscanf(message, "%23[^\n]", party) < 1) {
  3472. 		clif_displaymessage(fd, "Please, enter a party name (usage: @party <party_name>).");
  3473. 		return -1;
  3474. 	}
  3475.  
  3476. 	party_create(sd, party, 0, 0);
  3477.  
  3478. 	return 0;
  3479. }
  3480.  
  3481. /*==========================================
  3482.  *
  3483.  *------------------------------------------*/
  3484. ACMD_FUNC(guild)
  3485. {
  3486. 	char guild[NAME_LENGTH];
  3487. 	int prev;
  3488. 	nullpo_retr(-1, sd);
  3489.  
  3490. 	memset(guild, '\0', sizeof(guild));
  3491.  
  3492. 	if (!message || !*message || sscanf(message, "%23[^\n]", guild) < 1) {
  3493. 		clif_displaymessage(fd, "Please, enter a guild name (usage: @guild <guild_name>).");
  3494. 		return -1;
  3495. 	}
  3496.  
  3497. 	prev = battle_config.guild_emperium_check;
  3498. 	battle_config.guild_emperium_check = 0;
  3499. 	guild_create(sd, guild);
  3500. 	battle_config.guild_emperium_check = prev;
  3501.  
  3502. 	return 0;
  3503. }
  3504.  
  3505. /*==========================================
  3506.  *
  3507.  *------------------------------------------*/
  3508. ACMD_FUNC(agitstart)
  3509. {
  3510. 	nullpo_retr(-1, sd);
  3511. 	if (agit_flag == 1) {
  3512. 		clif_displaymessage(fd, msg_txt(73)); // War of Emperium is currently in progress.
  3513. 		return -1;
  3514. 	}
  3515.  
  3516. 	agit_flag = 1;
  3517. 	guild_agit_start();
  3518. 	clif_displaymessage(fd, msg_txt(72)); // War of Emperium has been initiated.
  3519.  
  3520. 	return 0;
  3521. }
  3522.  
  3523. /*==========================================
  3524.  *
  3525.  *------------------------------------------*/
  3526. ACMD_FUNC(agitstart2)
  3527. {
  3528. 	nullpo_retr(-1, sd);
  3529. 	if (agit2_flag == 1) {
  3530. 		clif_displaymessage(fd, msg_txt(404)); // "War of Emperium SE is currently in progress."
  3531. 		return -1;
  3532. 	}
  3533.  
  3534. 	agit2_flag = 1;
  3535. 	guild_agit2_start();
  3536. 	clif_displaymessage(fd, msg_txt(403)); // "War of Emperium SE has been initiated."
  3537.  
  3538. 	return 0;
  3539. }
  3540.  
  3541. /*==========================================
  3542.  *
  3543.  *------------------------------------------*/
  3544. ACMD_FUNC(agitend)
  3545. {
  3546. 	nullpo_retr(-1, sd);
  3547. 	if (agit_flag == 0) {
  3548. 		clif_displaymessage(fd, msg_txt(75)); // War of Emperium is currently not in progress.
  3549. 		return -1;
  3550. 	}
  3551.  
  3552. 	agit_flag = 0;
  3553. 	guild_agit_end();
  3554. 	clif_displaymessage(fd, msg_txt(74)); // War of Emperium has been ended.
  3555.  
  3556. 	return 0;
  3557. }
  3558.  
  3559. /*==========================================
  3560.  *
  3561.  *------------------------------------------*/
  3562. ACMD_FUNC(agitend2)
  3563. {
  3564. 	nullpo_retr(-1, sd);
  3565. 	if (agit2_flag == 0) {
  3566. 		clif_displaymessage(fd, msg_txt(406)); // "War of Emperium SE is currently not in progress."
  3567. 		return -1;
  3568. 	}
  3569.  
  3570. 	agit2_flag = 0;
  3571. 	guild_agit2_end();
  3572. 	clif_displaymessage(fd, msg_txt(405)); // "War of Emperium SE has been ended."
  3573.  
  3574. 	return 0;
  3575. }
  3576.  
  3577. /*==========================================
  3578.  * @mapexit - shuts down the map server
  3579.  *------------------------------------------*/
  3580. ACMD_FUNC(mapexit)
  3581. {
  3582. 	nullpo_retr(-1, sd);
  3583.  
  3584. 	do_shutdown();
  3585. 	return 0;
  3586. }
  3587.  
  3588. /*==========================================
  3589.  * idsearch <part_of_name>: revrited by [Yor]
  3590.  *------------------------------------------*/
  3591. ACMD_FUNC(idsearch)
  3592. {
  3593. 	char item_name[100];
  3594. 	unsigned int i, match;
  3595. 	struct item_data *item_array[MAX_SEARCH];
  3596. 	nullpo_retr(-1, sd);
  3597.  
  3598. 	memset(item_name, '\0', sizeof(item_name));
  3599. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3600.  
  3601. 	if (!message || !*message || sscanf(message, "%99s", item_name) < 0) {
  3602. 		clif_displaymessage(fd, "Please, enter a part of item name (usage: @idsearch <part_of_item_name>).");
  3603. 		return -1;
  3604. 	}
  3605.  
  3606. 	sprintf(atcmd_output, msg_txt(77), item_name); // The reference result of '%s' (name: id):
  3607. 	clif_displaymessage(fd, atcmd_output);
  3608. 	match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name);
  3609. 	if (match > MAX_SEARCH) {
  3610. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, match);
  3611. 		clif_displaymessage(fd, atcmd_output);
  3612. 		match = MAX_SEARCH;
  3613. 	}
  3614. 	for(i = 0; i < match; i++) {
  3615. 		sprintf(atcmd_output, msg_txt(78), item_array[i]->jname, item_array[i]->nameid); // %s: %d
  3616. 		clif_displaymessage(fd, atcmd_output);
  3617. 	}
  3618. 	sprintf(atcmd_output, msg_txt(79), match); // It is %d affair above.
  3619. 	clif_displaymessage(fd, atcmd_output);
  3620.  
  3621. 	return 0;
  3622. }
  3623.  
  3624. /*==========================================
  3625.  * Recall All Characters Online To Your Location
  3626.  *------------------------------------------*/
  3627. ACMD_FUNC(recallall)
  3628. {
  3629. 	struct map_session_data* pl_sd;
  3630. 	struct s_mapiterator* iter;
  3631. 	int count;
  3632. 	nullpo_retr(-1, sd);
  3633.  
  3634. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3635.  
  3636. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3637. 		clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map.");
  3638. 		return -1;
  3639. 	}
  3640.  
  3641. 	count = 0;
  3642. 	iter = mapit_getallusers();
  3643. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3644. 	{
  3645. 		if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3646. 		{
  3647. 			if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3648. 				count++;
  3649. 			else {
  3650. 				if (pc_isdead(pl_sd)) { //Wake them up
  3651. 					pc_setstand(pl_sd);
  3652. 					pc_setrestartvalue(pl_sd,1);
  3653. 				}
  3654. 				pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3655. 			}
  3656. 		}
  3657. 	}
  3658. 	mapit_free(iter);
  3659.  
  3660. 	clif_displaymessage(fd, msg_txt(92)); // All characters recalled!
  3661. 	if (count) {
  3662. 		sprintf(atcmd_output, "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count);
  3663. 		clif_displaymessage(fd, atcmd_output);
  3664. 	}
  3665.  
  3666. 	return 0;
  3667. }
  3668.  
  3669. /*==========================================
  3670.  * Recall online characters of a guild to your location
  3671.  *------------------------------------------*/
  3672. ACMD_FUNC(guildrecall)
  3673. {
  3674. 	struct map_session_data* pl_sd;
  3675. 	struct s_mapiterator* iter;
  3676. 	int count;
  3677. 	char guild_name[NAME_LENGTH];
  3678. 	struct guild *g;
  3679. 	nullpo_retr(-1, sd);
  3680.  
  3681. 	memset(guild_name, '\0', sizeof(guild_name));
  3682. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3683.  
  3684. 	if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  3685. 		clif_displaymessage(fd, "Please, enter a guild name/id (usage: @guildrecall <guild_name/id>).");
  3686. 		return -1;
  3687. 	}
  3688.  
  3689. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3690. 		clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map.");
  3691. 		return -1;
  3692. 	}
  3693.  
  3694. 	if ((g = guild_searchname(guild_name)) == NULL && // name first to avoid error when name begin with a number
  3695. 	    (g = guild_search(atoi(message))) == NULL)
  3696. 	{
  3697. 		clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the guild is online.
  3698. 		return -1;
  3699. 	}
  3700.  
  3701. 	count = 0;
  3702.  
  3703. 	iter = mapit_getallusers();
  3704. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3705. 	{
  3706. 		if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id)
  3707. 		{
  3708. 			if (pc_get_group_level(pl_sd) > pc_get_group_level(sd))
  3709. 				continue; //Skip GMs greater than you.
  3710. 			if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3711. 				count++;
  3712. 			else
  3713. 				pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3714. 		}
  3715. 	}
  3716. 	mapit_free(iter);
  3717.  
  3718. 	sprintf(atcmd_output, msg_txt(93), g->name); // All online characters of the %s guild have been recalled to your position.
  3719. 	clif_displaymessage(fd, atcmd_output);
  3720. 	if (count) {
  3721. 		sprintf(atcmd_output, "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count);
  3722. 		clif_displaymessage(fd, atcmd_output);
  3723. 	}
  3724.  
  3725. 	return 0;
  3726. }
  3727.  
  3728. /*==========================================
  3729.  * Recall online characters of a party to your location
  3730.  *------------------------------------------*/
  3731. ACMD_FUNC(partyrecall)
  3732. {
  3733. 	struct map_session_data* pl_sd;
  3734. 	struct s_mapiterator* iter;
  3735. 	char party_name[NAME_LENGTH];
  3736. 	struct party_data *p;
  3737. 	int count;
  3738. 	nullpo_retr(-1, sd);
  3739.  
  3740. 	memset(party_name, '\0', sizeof(party_name));
  3741. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3742.  
  3743. 	if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3744. 		clif_displaymessage(fd, "Please, enter a party name/id (usage: @partyrecall <party_name/id>).");
  3745. 		return -1;
  3746. 	}
  3747.  
  3748. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3749. 		clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map.");
  3750. 		return -1;
  3751. 	}
  3752.  
  3753. 	if ((p = party_searchname(party_name)) == NULL && // name first to avoid error when name begin with a number
  3754. 	    (p = party_search(atoi(message))) == NULL)
  3755. 	{
  3756. 		clif_displaymessage(fd, msg_txt(96)); // Incorrect name or ID, or no one from the party is online.
  3757. 		return -1;
  3758. 	}
  3759.  
  3760. 	count = 0;
  3761.  
  3762. 	iter = mapit_getallusers();
  3763. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3764. 	{
  3765. 		if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id)
  3766. 		{
  3767. 			if (pc_get_group_level(pl_sd) > pc_get_group_level(sd))
  3768. 				continue; //Skip GMs greater than you.
  3769. 			if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3770. 				count++;
  3771. 			else
  3772. 				pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3773. 		}
  3774. 	}
  3775. 	mapit_free(iter);
  3776.  
  3777. 	sprintf(atcmd_output, msg_txt(95), p->party.name); // All online characters of the %s party have been recalled to your position.
  3778. 	clif_displaymessage(fd, atcmd_output);
  3779. 	if (count) {
  3780. 		sprintf(atcmd_output, "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count);
  3781. 		clif_displaymessage(fd, atcmd_output);
  3782. 	}
  3783.  
  3784. 	return 0;
  3785. }
  3786.  
  3787. /*==========================================
  3788.  *
  3789.  *------------------------------------------*/
  3790. ACMD_FUNC(reloaditemdb)
  3791. {
  3792. 	nullpo_retr(-1, sd);
  3793. 	itemdb_reload();
  3794. 	clif_displaymessage(fd, msg_txt(97)); // Item database has been reloaded.
  3795.  
  3796. 	return 0;
  3797. }
  3798.  
  3799. /*==========================================
  3800.  *
  3801.  *------------------------------------------*/
  3802. ACMD_FUNC(reloadmobdb)
  3803. {
  3804. 	nullpo_retr(-1, sd);
  3805. 	mob_reload();
  3806. 	read_petdb();
  3807. 	merc_reload();
  3808. 	read_mercenarydb();
  3809. 	read_mercenary_skilldb();
  3810. 	reload_elementaldb();
  3811. 	clif_displaymessage(fd, msg_txt(98)); // Monster database has been reloaded.
  3812.  
  3813. 	return 0;
  3814. }
  3815.  
  3816. /*==========================================
  3817.  *
  3818.  *------------------------------------------*/
  3819. ACMD_FUNC(reloadskilldb)
  3820. {
  3821. 	nullpo_retr(-1, sd);
  3822. 	skill_reload();
  3823. 	merc_skill_reload();
  3824. 	reload_elemental_skilldb();
  3825. 	read_mercenary_skilldb();
  3826. 	clif_displaymessage(fd, msg_txt(99)); // Skill database has been reloaded.
  3827.  
  3828. 	return 0;
  3829. }
  3830.  
  3831. /*==========================================
  3832.  * @reloadatcommand - reloads atcommand_athena.conf groups.conf
  3833.  *------------------------------------------*/
  3834. void atcommand_doload();
  3835. ACMD_FUNC(reloadatcommand) {
  3836. 	atcommand_doload();
  3837. 	pc_groups_reload();
  3838. 	clif_displaymessage(fd, msg_txt(254));
  3839. 	return 0;
  3840. }
  3841. /*==========================================
  3842.  * @reloadbattleconf - reloads battle_athena.conf
  3843.  *------------------------------------------*/
  3844. ACMD_FUNC(reloadbattleconf)
  3845. {
  3846. 	struct Battle_Config prev_config;
  3847. 	memcpy(&prev_config, &battle_config, sizeof(prev_config));
  3848.  
  3849. 	battle_config_read(BATTLE_CONF_FILENAME);
  3850.  
  3851. 	if( prev_config.item_rate_mvp          != battle_config.item_rate_mvp
  3852. 	||  prev_config.item_rate_common       != battle_config.item_rate_common
  3853. 	||  prev_config.item_rate_common_boss  != battle_config.item_rate_common_boss
  3854. 	||  prev_config.item_rate_card         != battle_config.item_rate_card
  3855. 	||  prev_config.item_rate_card_boss    != battle_config.item_rate_card_boss
  3856. 	||  prev_config.item_rate_equip        != battle_config.item_rate_equip
  3857. 	||  prev_config.item_rate_equip_boss   != battle_config.item_rate_equip_boss
  3858. 	||  prev_config.item_rate_heal         != battle_config.item_rate_heal
  3859. 	||  prev_config.item_rate_heal_boss    != battle_config.item_rate_heal_boss
  3860. 	||  prev_config.item_rate_use          != battle_config.item_rate_use
  3861. 	||  prev_config.item_rate_use_boss     != battle_config.item_rate_use_boss
  3862. 	||  prev_config.item_rate_treasure     != battle_config.item_rate_treasure
  3863. 	||  prev_config.item_rate_adddrop      != battle_config.item_rate_adddrop
  3864. 	||  prev_config.logarithmic_drops      != battle_config.logarithmic_drops
  3865. 	||  prev_config.item_drop_common_min   != battle_config.item_drop_common_min
  3866. 	||  prev_config.item_drop_common_max   != battle_config.item_drop_common_max
  3867. 	||  prev_config.item_drop_card_min     != battle_config.item_drop_card_min
  3868. 	||  prev_config.item_drop_card_max     != battle_config.item_drop_card_max
  3869. 	||  prev_config.item_drop_equip_min    != battle_config.item_drop_equip_min
  3870. 	||  prev_config.item_drop_equip_max    != battle_config.item_drop_equip_max
  3871. 	||  prev_config.item_drop_mvp_min      != battle_config.item_drop_mvp_min
  3872. 	||  prev_config.item_drop_mvp_max      != battle_config.item_drop_mvp_max
  3873. 	||  prev_config.item_drop_heal_min     != battle_config.item_drop_heal_min
  3874. 	||  prev_config.item_drop_heal_max     != battle_config.item_drop_heal_max
  3875. 	||  prev_config.item_drop_use_min      != battle_config.item_drop_use_min
  3876. 	||  prev_config.item_drop_use_max      != battle_config.item_drop_use_max
  3877. 	||  prev_config.item_drop_treasure_min != battle_config.item_drop_treasure_min
  3878. 	||  prev_config.item_drop_treasure_max != battle_config.item_drop_treasure_max
  3879. 	||  prev_config.base_exp_rate          != battle_config.base_exp_rate
  3880. 	||  prev_config.job_exp_rate           != battle_config.job_exp_rate
  3881. 	)
  3882.   	{	// Exp or Drop rates changed.
  3883. 		mob_reload(); //Needed as well so rate changes take effect.
  3884. 		chrif_ragsrvinfo(battle_config.base_exp_rate, battle_config.job_exp_rate, battle_config.item_rate_common);
  3885. 	}
  3886. 	clif_displaymessage(fd, msg_txt(255));
  3887. 	return 0;
  3888. }
  3889. /*==========================================
  3890.  * @reloadstatusdb - reloads job_db1.txt job_db2.txt job_db2-2.txt refine_db.txt size_fix.txt
  3891.  *------------------------------------------*/
  3892. ACMD_FUNC(reloadstatusdb)
  3893. {
  3894. 	status_readdb();
  3895. 	clif_displaymessage(fd, msg_txt(256));
  3896. 	return 0;
  3897. }
  3898. /*==========================================
  3899.  * @reloadpcdb - reloads exp.txt skill_tree.txt attr_fix.txt statpoint.txt
  3900.  *------------------------------------------*/
  3901. ACMD_FUNC(reloadpcdb)
  3902. {
  3903. 	pc_readdb();
  3904. 	clif_displaymessage(fd, msg_txt(257));
  3905. 	return 0;
  3906. }
  3907.  
  3908. /*==========================================
  3909.  * @reloadmotd - reloads motd.txt
  3910.  *------------------------------------------*/
  3911. ACMD_FUNC(reloadmotd)
  3912. {
  3913. 	pc_read_motd();
  3914. 	clif_displaymessage(fd, msg_txt(268));
  3915. 	return 0;
  3916. }
  3917.  
  3918. /*==========================================
  3919.  * @reloadscript - reloads all scripts (npcs, warps, mob spawns, ...)
  3920.  *------------------------------------------*/
  3921. ACMD_FUNC(reloadscript)
  3922. {
  3923. 	nullpo_retr(-1, sd);
  3924. 	//atcommand_broadcast( fd, sd, "@broadcast", "Server is reloading scripts..." );
  3925. 	//atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
  3926.  
  3927. 	flush_fifos();
  3928. 	script_reload();
  3929. 	npc_reload();
  3930.  
  3931. 	clif_displaymessage(fd, msg_txt(100)); // Scripts have been reloaded.
  3932.  
  3933. 	return 0;
  3934. }
  3935.  
  3936. /*==========================================
  3937.  * @mapinfo [0-3] <map name> by MC_Cameri
  3938.  * => Shows information about the map [map name]
  3939.  * 0 = no additional information
  3940.  * 1 = Show users in that map and their location
  3941.  * 2 = Shows NPCs in that map
  3942.  * 3 = Shows the shops/chats in that map (not implemented)
  3943.  *------------------------------------------*/
  3944. ACMD_FUNC(mapinfo)
  3945. {
  3946. 	struct map_session_data* pl_sd;
  3947. 	struct s_mapiterator* iter;
  3948. 	struct npc_data *nd = NULL;
  3949. 	struct chat_data *cd = NULL;
  3950. 	char direction[12];
  3951. 	int i, m_id, chat_num, list = 0;
  3952. 	unsigned short m_index;
  3953. 	char mapname[24];
  3954.  
  3955. 	nullpo_retr(-1, sd);
  3956.  
  3957. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3958. 	memset(mapname, '\0', sizeof(mapname));
  3959. 	memset(direction, '\0', sizeof(direction));
  3960.  
  3961. 	sscanf(message, "%d %23[^\n]", &list, mapname);
  3962.  
  3963. 	if (list < 0 || list > 3) {
  3964. 		clif_displaymessage(fd, "Please, enter at least a valid list number (usage: @mapinfo <0-3> [map]).");
  3965. 		return -1;
  3966. 	}
  3967.  
  3968. 	if (mapname[0] == '\0') {
  3969. 		safestrncpy(mapname, mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  3970. 		m_id =  map_mapindex2mapid(sd->mapindex);
  3971. 	} else {
  3972. 		m_id = map_mapname2mapid(mapname);
  3973. 	}
  3974.  
  3975. 	if (m_id < 0) {
  3976. 		clif_displaymessage(fd, msg_txt(1)); // Map not found.
  3977. 		return -1;
  3978. 	}
  3979. 	m_index = mapindex_name2id(mapname); //This one shouldn't fail since the previous seek did not.
  3980.  
  3981. 	clif_displaymessage(fd, "------ Map Info ------");
  3982.  
  3983. 	// count chats (for initial message)
  3984. 	chat_num = 0;
  3985. 	iter = mapit_getallusers();
  3986. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3987. 		if( (cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && cd->usersd[0] == pl_sd )
  3988. 			chat_num++;
  3989. 	mapit_free(iter);
  3990.  
  3991. 	sprintf(atcmd_output, "Map Name: %s | Players In Map: %d | NPCs In Map: %d | Chats In Map: %d", mapname, map[m_id].users, map[m_id].npc_num, chat_num);
  3992. 	clif_displaymessage(fd, atcmd_output);
  3993. 	clif_displaymessage(fd, "------ Map Flags ------");
  3994. 	if (map[m_id].flag.town)
  3995. 		clif_displaymessage(fd, "Town Map");
  3996.  
  3997. 	if (battle_config.autotrade_mapflag == map[m_id].flag.autotrade)
  3998. 		clif_displaymessage(fd, "Autotrade Enabled");
  3999. 	else
  4000. 		clif_displaymessage(fd, "Autotrade Disabled");
  4001.  
  4002. 	if (map[m_id].flag.battleground)
  4003. 		clif_displaymessage(fd, "Battlegrounds ON");
  4004.  
  4005. 	strcpy(atcmd_output,"PvP Flags: ");
  4006. 	if (map[m_id].flag.pvp)
  4007. 		strcat(atcmd_output, "Pvp ON | ");
  4008. 	if (map[m_id].flag.pvp_noguild)
  4009. 		strcat(atcmd_output, "NoGuild | ");
  4010. 	if (map[m_id].flag.pvp_noparty)
  4011. 		strcat(atcmd_output, "NoParty | ");
  4012. 	if (map[m_id].flag.pvp_nightmaredrop)
  4013. 		strcat(atcmd_output, "NightmareDrop | ");
  4014. 	if (map[m_id].flag.pvp_nocalcrank)
  4015. 		strcat(atcmd_output, "NoCalcRank | ");
  4016. 	clif_displaymessage(fd, atcmd_output);
  4017.  
  4018. 	strcpy(atcmd_output,"GvG Flags: ");
  4019. 	if (map[m_id].flag.gvg)
  4020. 		strcat(atcmd_output, "GvG ON | ");
  4021. 	if (map[m_id].flag.gvg_dungeon)
  4022. 		strcat(atcmd_output, "GvG Dungeon | ");
  4023. 	if (map[m_id].flag.gvg_castle)
  4024. 		strcat(atcmd_output, "GvG Castle | ");
  4025. 	if (map[m_id].flag.gvg_noparty)
  4026. 		strcat(atcmd_output, "NoParty | ");
  4027. 	clif_displaymessage(fd, atcmd_output);
  4028.  
  4029. 	strcpy(atcmd_output,"Teleport Flags: ");
  4030. 	if (map[m_id].flag.noteleport)
  4031. 		strcat(atcmd_output, "NoTeleport | ");
  4032. 	if (map[m_id].flag.monster_noteleport)
  4033. 		strcat(atcmd_output, "Monster NoTeleport | ");
  4034. 	if (map[m_id].flag.nowarp)
  4035. 		strcat(atcmd_output, "NoWarp | ");
  4036. 	if (map[m_id].flag.nowarpto)
  4037. 		strcat(atcmd_output, "NoWarpTo | ");
  4038. 	if (map[m_id].flag.noreturn)
  4039. 		strcat(atcmd_output, "NoReturn | ");
  4040. 	if (map[m_id].flag.nogo)
  4041. 		strcat(atcmd_output, "NoGo | ");
  4042. 	if (map[m_id].flag.nomemo)
  4043. 		strcat(atcmd_output, "NoMemo | ");
  4044. 	clif_displaymessage(fd, atcmd_output);
  4045.  
  4046. 	sprintf(atcmd_output, "No Exp Penalty: %s | No Zeny Penalty: %s", (map[m_id].flag.noexppenalty) ? "On" : "Off", (map[m_id].flag.nozenypenalty) ? "On" : "Off");
  4047. 	clif_displaymessage(fd, atcmd_output);
  4048.  
  4049. 	if (map[m_id].flag.nosave) {
  4050. 		if (!map[m_id].save.map)
  4051. 			sprintf(atcmd_output, "No Save (Return to last Save Point)");
  4052. 		else if (map[m_id].save.x == -1 || map[m_id].save.y == -1 )
  4053. 			sprintf(atcmd_output, "No Save, Save Point: %s,Random",mapindex_id2name(map[m_id].save.map));
  4054. 		else
  4055. 			sprintf(atcmd_output, "No Save, Save Point: %s,%d,%d",
  4056. 				mapindex_id2name(map[m_id].save.map),map[m_id].save.x,map[m_id].save.y);
  4057. 		clif_displaymessage(fd, atcmd_output);
  4058. 	}
  4059.  
  4060. 	strcpy(atcmd_output,"Weather Flags: ");
  4061. 	if (map[m_id].flag.snow)
  4062. 		strcat(atcmd_output, "Snow | ");
  4063. 	if (map[m_id].flag.fog)
  4064. 		strcat(atcmd_output, "Fog | ");
  4065. 	if (map[m_id].flag.sakura)
  4066. 		strcat(atcmd_output, "Sakura | ");
  4067. 	if (map[m_id].flag.clouds)
  4068. 		strcat(atcmd_output, "Clouds | ");
  4069. 	if (map[m_id].flag.clouds2)
  4070. 		strcat(atcmd_output, "Clouds2 | ");
  4071. 	if (map[m_id].flag.fireworks)
  4072. 		strcat(atcmd_output, "Fireworks | ");
  4073. 	if (map[m_id].flag.leaves)
  4074. 		strcat(atcmd_output, "Leaves | ");
  4075. 	/**
  4076. 	 * No longer available, keeping here just in case it's back someday. [Ind]
  4077. 	 **/
  4078. 	//if (map[m_id].flag.rain)
  4079. 	//	strcat(atcmd_output, "Rain | ");
  4080. 	if (map[m_id].flag.nightenabled)
  4081. 		strcat(atcmd_output, "Displays Night | ");
  4082. 	clif_displaymessage(fd, atcmd_output);
  4083.  
  4084. 	strcpy(atcmd_output,"Other Flags: ");
  4085. 	if (map[m_id].flag.nobranch)
  4086. 		strcat(atcmd_output, "NoBranch | ");
  4087. 	if (map[m_id].flag.notrade)
  4088. 		strcat(atcmd_output, "NoTrade | ");
  4089. 	if (map[m_id].flag.novending)
  4090. 		strcat(atcmd_output, "NoVending | ");
  4091. 	if (map[m_id].flag.nodrop)
  4092. 		strcat(atcmd_output, "NoDrop | ");
  4093. 	if (map[m_id].flag.noskill)
  4094. 		strcat(atcmd_output, "NoSkill | ");
  4095. 	if (map[m_id].flag.noicewall)
  4096. 		strcat(atcmd_output, "NoIcewall | ");
  4097. 	if (map[m_id].flag.allowks)
  4098. 		strcat(atcmd_output, "AllowKS | ");
  4099. 	if (map[m_id].flag.reset)
  4100. 		strcat(atcmd_output, "Reset | ");
  4101. 	clif_displaymessage(fd, atcmd_output);
  4102.  
  4103. 	strcpy(atcmd_output,"Other Flags: ");
  4104. 	if (map[m_id].nocommand)
  4105. 		strcat(atcmd_output, "NoCommand | ");
  4106. 	if (map[m_id].flag.nobaseexp)
  4107. 		strcat(atcmd_output, "NoBaseEXP | ");
  4108. 	if (map[m_id].flag.nojobexp)
  4109. 		strcat(atcmd_output, "NoJobEXP | ");
  4110. 	if (map[m_id].flag.nomobloot)
  4111. 		strcat(atcmd_output, "NoMobLoot | ");
  4112. 	if (map[m_id].flag.nomvploot)
  4113. 		strcat(atcmd_output, "NoMVPLoot | ");
  4114. 	if (map[m_id].flag.partylock)
  4115. 		strcat(atcmd_output, "PartyLock | ");
  4116. 	if (map[m_id].flag.guildlock)
  4117. 		strcat(atcmd_output, "GuildLock | ");
  4118. 	clif_displaymessage(fd, atcmd_output);
  4119.  
  4120. 	switch (list) {
  4121. 	case 0:
  4122. 		// Do nothing. It's list 0, no additional display.
  4123. 		break;
  4124. 	case 1:
  4125. 		clif_displaymessage(fd, "----- Players in Map -----");
  4126. 		iter = mapit_getallusers();
  4127. 		for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4128. 		{
  4129. 			if (pl_sd->mapindex == m_index) {
  4130. 				sprintf(atcmd_output, "Player '%s' (session #%d) | Location: %d,%d",
  4131. 				        pl_sd->status.name, pl_sd->fd, pl_sd->bl.x, pl_sd->bl.y);
  4132. 				clif_displaymessage(fd, atcmd_output);
  4133. 			}
  4134. 		}
  4135. 		mapit_free(iter);
  4136. 		break;
  4137. 	case 2:
  4138. 		clif_displaymessage(fd, "----- NPCs in Map -----");
  4139. 		for (i = 0; i < map[m_id].npc_num;)
  4140. 		{
  4141. 			nd = map[m_id].npc[i];
  4142. 			switch(nd->ud.dir) {
  4143. 			case 0:  strcpy(direction, "North"); break;
  4144. 			case 1:  strcpy(direction, "North West"); break;
  4145. 			case 2:  strcpy(direction, "West"); break;
  4146. 			case 3:  strcpy(direction, "South West"); break;
  4147. 			case 4:  strcpy(direction, "South"); break;
  4148. 			case 5:  strcpy(direction, "South East"); break;
  4149. 			case 6:  strcpy(direction, "East"); break;
  4150. 			case 7:  strcpy(direction, "North East"); break;
  4151. 			case 9:  strcpy(direction, "North"); break;
  4152. 			default: strcpy(direction, "Unknown"); break;
  4153. 			}
  4154. 			if(strcmp(nd->name,nd->exname) == 0)
  4155. 				sprintf(atcmd_output, "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d",
  4156. 				    ++i, nd->name, direction, nd->class_, nd->bl.x, nd->bl.y);
  4157. 			else
  4158. 				sprintf(atcmd_output, "NPC %d: %s::%s | Direction: %s | Sprite: %d | Location: %d %d",
  4159. 			        ++i, nd->name, nd->exname, direction, nd->class_, nd->bl.x, nd->bl.y);
  4160. 			clif_displaymessage(fd, atcmd_output);
  4161. 		}
  4162. 		break;
  4163. 	case 3:
  4164. 		clif_displaymessage(fd, "----- Chats in Map -----");
  4165. 		iter = mapit_getallusers();
  4166. 		for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4167. 		{
  4168. 			if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL &&
  4169. 			    pl_sd->mapindex == m_index &&
  4170. 			    cd->usersd[0] == pl_sd)
  4171. 			{
  4172. 				sprintf(atcmd_output, "Chat: %s | Player: %s | Location: %d %d",
  4173. 				        cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y);
  4174. 				clif_displaymessage(fd, atcmd_output);
  4175. 				sprintf(atcmd_output, "   Users: %d/%d | Password: %s | Public: %s",
  4176. 				        cd->users, cd->limit, cd->pass, (cd->pub) ? "Yes" : "No");
  4177. 				clif_displaymessage(fd, atcmd_output);
  4178. 			}
  4179. 		}
  4180. 		mapit_free(iter);
  4181. 		break;
  4182. 	default: // normally impossible to arrive here
  4183. 		clif_displaymessage(fd, "Please, enter at least a valid list number (usage: @mapinfo <0-3> [map]).");
  4184. 		return -1;
  4185. 		break;
  4186. 	}
  4187.  
  4188. 	return 0;
  4189. }
  4190.  
  4191. /*==========================================
  4192.  *
  4193.  *------------------------------------------*/
  4194. ACMD_FUNC(mount_peco)
  4195. {
  4196. 	nullpo_retr(-1, sd);
  4197.  
  4198. 	if (sd->disguise) {
  4199. 		clif_displaymessage(fd, msg_txt(212)); // Cannot mount while in disguise.
  4200. 		return -1;
  4201. 	}
  4202.  
  4203. 	if( (sd->class_&MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT && pc_checkskill(sd,RK_DRAGONTRAINING) > 0 ) {
  4204. 		if( !(sd->sc.option&OPTION_DRAGON1) ) {
  4205. 			clif_displaymessage(sd->fd,"You have mounted your Dragon");
  4206. 			pc_setoption(sd, sd->sc.option|OPTION_DRAGON1);
  4207. 		} else {
  4208. 			clif_displaymessage(sd->fd,"You have released your Dragon");
  4209. 			pc_setoption(sd, sd->sc.option&~OPTION_DRAGON1);
  4210. 		}
  4211. 		return 0;
  4212. 	}
  4213. 	if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER && pc_checkskill(sd,RA_WUGRIDER) > 0 ) {
  4214. 		if( !pc_isridingwug(sd) ) {
  4215. 			clif_displaymessage(sd->fd,"You have mounted your Wug");
  4216. 			pc_setoption(sd, sd->sc.option|OPTION_WUGRIDER);
  4217. 		} else {
  4218. 			clif_displaymessage(sd->fd,"You have released your Wug");
  4219. 			pc_setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
  4220. 		}
  4221. 		return 0;
  4222. 	}
  4223. 	if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  4224. 		if( !pc_ismadogear(sd) ) {
  4225. 			clif_displaymessage(sd->fd,"You have mounted your Mado Gear");
  4226. 			pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  4227. 		} else {
  4228. 			clif_displaymessage(sd->fd,"You have released your Mado Gear");
  4229. 			pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  4230. 		}
  4231. 		return 0;
  4232. 	}
  4233. 	if (!pc_isriding(sd)) { // if actually no peco
  4234.  
  4235. 		if (!pc_checkskill(sd, KN_RIDING)) {
  4236. 			clif_displaymessage(fd, msg_txt(213)); // You can not mount a Peco Peco with your current job.
  4237. 			return -1;
  4238. 		}
  4239.  
  4240. 		pc_setoption(sd, sd->sc.option | OPTION_RIDING);
  4241. 		clif_displaymessage(fd, msg_txt(102)); // You have mounted a Peco Peco.
  4242. 	} else {//Dismount
  4243. 		pc_setoption(sd, sd->sc.option & ~OPTION_RIDING);
  4244. 		clif_displaymessage(fd, msg_txt(214)); // You have released your Peco Peco.
  4245. 	}
  4246.  
  4247. 	return 0;
  4248. }
  4249.  
  4250. /*==========================================
  4251.  *Spy Commands by Syrus22
  4252.  *------------------------------------------*/
  4253. ACMD_FUNC(guildspy)
  4254. {
  4255. 	char guild_name[NAME_LENGTH];
  4256. 	struct guild *g;
  4257. 	nullpo_retr(-1, sd);
  4258.  
  4259. 	memset(guild_name, '\0', sizeof(guild_name));
  4260. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  4261.  
  4262. 	if (!enable_spy)
  4263. 	{
  4264. 		clif_displaymessage(fd, "The mapserver has spy command support disabled.");
  4265. 		return -1;
  4266. 	}
  4267. 	if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  4268. 		clif_displaymessage(fd, "Please, enter a guild name/id (usage: @guildspy <guild_name/id>).");
  4269. 		return -1;
  4270. 	}
  4271.  
  4272. 	if ((g = guild_searchname(guild_name)) != NULL || // name first to avoid error when name begin with a number
  4273. 	    (g = guild_search(atoi(message))) != NULL) {
  4274. 		if (sd->guildspy == g->guild_id) {
  4275. 			sd->guildspy = 0;
  4276. 			sprintf(atcmd_output, msg_txt(103), g->name); // No longer spying on the %s guild.
  4277. 			clif_displaymessage(fd, atcmd_output);
  4278. 		} else {
  4279. 			sd->guildspy = g->guild_id;
  4280. 			sprintf(atcmd_output, msg_txt(104), g->name); // Spying on the %s guild.
  4281. 			clif_displaymessage(fd, atcmd_output);
  4282. 		}
  4283. 	} else {
  4284. 		clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the specified guild is online.
  4285. 		return -1;
  4286. 	}
  4287.  
  4288. 	return 0;
  4289. }
  4290.  
  4291. /*==========================================
  4292.  *
  4293.  *------------------------------------------*/
  4294. ACMD_FUNC(partyspy)
  4295. {
  4296. 	char party_name[NAME_LENGTH];
  4297. 	struct party_data *p;
  4298. 	nullpo_retr(-1, sd);
  4299.  
  4300. 	memset(party_name, '\0', sizeof(party_name));
  4301. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  4302.  
  4303. 	if (!enable_spy)
  4304. 	{
  4305. 		clif_displaymessage(fd, "The mapserver has spy command support disabled.");
  4306. 		return -1;
  4307. 	}
  4308.  
  4309. 	if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  4310. 		clif_displaymessage(fd, "Please, enter a party name/id (usage: @partyspy <party_name/id>).");
  4311. 		return -1;
  4312. 	}
  4313.  
  4314. 	if ((p = party_searchname(party_name)) != NULL || // name first to avoid error when name begin with a number
  4315. 	    (p = party_search(atoi(message))) != NULL) {
  4316. 		if (sd->partyspy == p->party.party_id) {
  4317. 			sd->partyspy = 0;
  4318. 			sprintf(atcmd_output, msg_txt(105), p->party.name); // No longer spying on the %s party.
  4319. 			clif_displaymessage(fd, atcmd_output);
  4320. 		} else {
  4321. 			sd->partyspy = p->party.party_id;
  4322. 			sprintf(atcmd_output, msg_txt(106), p->party.name); // Spying on the %s party.
  4323. 			clif_displaymessage(fd, atcmd_output);
  4324. 		}
  4325. 	} else {
  4326. 		clif_displaymessage(fd, msg_txt(96)); // Incorrect name/ID, or no one from the specified party is online.
  4327. 		return -1;
  4328. 	}
  4329.  
  4330. 	return 0;
  4331. }
  4332.  
  4333. /*==========================================
  4334.  * @repairall [Valaris]
  4335.  *------------------------------------------*/
  4336. ACMD_FUNC(repairall)
  4337. {
  4338. 	int count, i;
  4339. 	nullpo_retr(-1, sd);
  4340.  
  4341. 	count = 0;
  4342. 	for (i = 0; i < MAX_INVENTORY; i++) {
  4343. 		if (sd->status.inventory[i].nameid && sd->status.inventory[i].attribute == 1) {
  4344. 			sd->status.inventory[i].attribute = 0;
  4345. 			clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  4346. 			count++;
  4347. 		}
  4348. 	}
  4349.  
  4350. 	if (count > 0) {
  4351. 		clif_misceffect(&sd->bl, 3);
  4352. 		clif_equiplist(sd);
  4353. 		clif_displaymessage(fd, msg_txt(107)); // All items have been repaired.
  4354. 	} else {
  4355. 		clif_displaymessage(fd, msg_txt(108)); // No item need to be repaired.
  4356. 		return -1;
  4357. 	}
  4358.  
  4359. 	return 0;
  4360. }
  4361.  
  4362. /*==========================================
  4363.  * @nuke [Valaris]
  4364.  *------------------------------------------*/
  4365. ACMD_FUNC(nuke)
  4366. {
  4367. 	struct map_session_data *pl_sd;
  4368. 	nullpo_retr(-1, sd);
  4369.  
  4370. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4371.  
  4372. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4373. 		clif_displaymessage(fd, "Please, enter a player name (usage: @nuke <char name>).");
  4374. 		return -1;
  4375. 	}
  4376.  
  4377. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) != NULL) {
  4378. 		if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level
  4379. 			skill_castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, gettick(), 0);
  4380. 			clif_displaymessage(fd, msg_txt(109)); // Player has been nuked!
  4381. 		} else {
  4382. 			clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4383. 			return -1;
  4384. 		}
  4385. 	} else {
  4386. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4387. 		return -1;
  4388. 	}
  4389.  
  4390. 	return 0;
  4391. }
  4392.  
  4393. /*==========================================
  4394.  * @tonpc
  4395.  *------------------------------------------*/
  4396. ACMD_FUNC(tonpc)
  4397. {
  4398. 	char npcname[NAME_LENGTH+1];
  4399. 	struct npc_data *nd;
  4400.  
  4401. 	nullpo_retr(-1, sd);
  4402.  
  4403. 	memset(npcname, 0, sizeof(npcname));
  4404.  
  4405. 	if (!message || !*message || sscanf(message, "%23[^\n]", npcname) < 1) {
  4406. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @tonpc <NPC_name>).");
  4407. 		return -1;
  4408. 	}
  4409.  
  4410. 	if ((nd = npc_name2id(npcname)) != NULL) {
  4411. 		if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
  4412. 			clif_displaymessage(fd, msg_txt(0)); // Warped.
  4413. 		else
  4414. 			return -1;
  4415. 	} else {
  4416. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4417. 		return -1;
  4418. 	}
  4419.  
  4420. 	return 0;
  4421. }
  4422.  
  4423. /*==========================================
  4424.  *
  4425.  *------------------------------------------*/
  4426. ACMD_FUNC(shownpc)
  4427. {
  4428. 	char NPCname[NAME_LENGTH+1];
  4429. 	nullpo_retr(-1, sd);
  4430.  
  4431. 	memset(NPCname, '\0', sizeof(NPCname));
  4432.  
  4433. 	if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  4434. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @enablenpc <NPC_name>).");
  4435. 		return -1;
  4436. 	}
  4437.  
  4438. 	if (npc_name2id(NPCname) != NULL) {
  4439. 		npc_enable(NPCname, 1);
  4440. 		clif_displaymessage(fd, msg_txt(110)); // Npc Enabled.
  4441. 	} else {
  4442. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4443. 		return -1;
  4444. 	}
  4445.  
  4446. 	return 0;
  4447. }
  4448.  
  4449. /*==========================================
  4450.  *
  4451.  *------------------------------------------*/
  4452. ACMD_FUNC(hidenpc)
  4453. {
  4454. 	char NPCname[NAME_LENGTH+1];
  4455. 	nullpo_retr(-1, sd);
  4456.  
  4457. 	memset(NPCname, '\0', sizeof(NPCname));
  4458.  
  4459. 	if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  4460. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @hidenpc <NPC_name>).");
  4461. 		return -1;
  4462. 	}
  4463.  
  4464. 	if (npc_name2id(NPCname) == NULL) {
  4465. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4466. 		return -1;
  4467. 	}
  4468.  
  4469. 	npc_enable(NPCname, 0);
  4470. 	clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
  4471. 	return 0;
  4472. }
  4473.  
  4474. ACMD_FUNC(loadnpc)
  4475. {
  4476. 	FILE *fp;
  4477.  
  4478. 	if (!message || !*message) {
  4479. 		clif_displaymessage(fd, "Please, enter a script file name (usage: @loadnpc <file name>).");
  4480. 		return -1;
  4481. 	}
  4482.  
  4483. 	// check if script file exists
  4484. 	if ((fp = fopen(message, "r")) == NULL) {
  4485. 		clif_displaymessage(fd, msg_txt(261));
  4486. 		return -1;
  4487. 	}
  4488. 	fclose(fp);
  4489.  
  4490. 	// add to list of script sources and run it
  4491. 	npc_addsrcfile(message);
  4492. 	npc_parsesrcfile(message,true);
  4493. 	npc_read_event_script();
  4494.  
  4495. 	clif_displaymessage(fd, msg_txt(262));
  4496.  
  4497. 	return 0;
  4498. }
  4499.  
  4500. ACMD_FUNC(unloadnpc)
  4501. {
  4502. 	struct npc_data *nd;
  4503. 	char NPCname[NAME_LENGTH+1];
  4504. 	nullpo_retr(-1, sd);
  4505.  
  4506. 	memset(NPCname, '\0', sizeof(NPCname));
  4507.  
  4508. 	if (!message || !*message || sscanf(message, "%24[^\n]", NPCname) < 1) {
  4509. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @npcoff <NPC_name>).");
  4510. 		return -1;
  4511. 	}
  4512.  
  4513. 	if ((nd = npc_name2id(NPCname)) == NULL) {
  4514. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4515. 		return -1;
  4516. 	}
  4517.  
  4518. 	npc_unload_duplicates(nd);
  4519. 	npc_unload(nd,true);
  4520. 	npc_read_event_script();
  4521. 	clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
  4522. 	return 0;
  4523. }
  4524.  
  4525. /*==========================================
  4526.  * time in txt for time command (by [Yor])
  4527.  *------------------------------------------*/
  4528. char* txt_time(unsigned int duration)
  4529. {
  4530. 	int days, hours, minutes, seconds;
  4531. 	char temp[CHAT_SIZE_MAX];
  4532. 	static char temp1[CHAT_SIZE_MAX];
  4533.  
  4534. 	memset(temp, '\0', sizeof(temp));
  4535. 	memset(temp1, '\0', sizeof(temp1));
  4536.  
  4537. 	days = duration / (60 * 60 * 24);
  4538. 	duration = duration - (60 * 60 * 24 * days);
  4539. 	hours = duration / (60 * 60);
  4540. 	duration = duration - (60 * 60 * hours);
  4541. 	minutes = duration / 60;
  4542. 	seconds = duration - (60 * minutes);
  4543.  
  4544. 	if (days < 2)
  4545. 		sprintf(temp, msg_txt(219), days); // %d day
  4546. 	else
  4547. 		sprintf(temp, msg_txt(220), days); // %d days
  4548. 	if (hours < 2)
  4549. 		sprintf(temp1, msg_txt(221), temp, hours); // %s %d hour
  4550. 	else
  4551. 		sprintf(temp1, msg_txt(222), temp, hours); // %s %d hours
  4552. 	if (minutes < 2)
  4553. 		sprintf(temp, msg_txt(223), temp1, minutes); // %s %d minute
  4554. 	else
  4555. 		sprintf(temp, msg_txt(224), temp1, minutes); // %s %d minutes
  4556. 	if (seconds < 2)
  4557. 		sprintf(temp1, msg_txt(225), temp, seconds); // %s and %d second
  4558. 	else
  4559. 		sprintf(temp1, msg_txt(226), temp, seconds); // %s and %d seconds
  4560.  
  4561. 	return temp1;
  4562. }
  4563.  
  4564. /*==========================================
  4565.  * @time/@date/@serverdate/@servertime: Display the date/time of the server (by [Yor]
  4566.  * Calculation management of GM modification (@day/@night GM commands) is done
  4567.  *------------------------------------------*/
  4568. ACMD_FUNC(servertime)
  4569. {
  4570. 	const struct TimerData * timer_data;
  4571. 	const struct TimerData * timer_data2;
  4572. 	time_t time_server;  // variable for number of seconds (used with time() function)
  4573. 	struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
  4574. 	char temp[CHAT_SIZE_MAX];
  4575. 	nullpo_retr(-1, sd);
  4576.  
  4577. 	memset(temp, '\0', sizeof(temp));
  4578.  
  4579. 	time(&time_server);  // get time in seconds since 1/1/1970
  4580. 	datetime = localtime(&time_server); // convert seconds in structure
  4581. 	// like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  4582. 	strftime(temp, sizeof(temp)-1, msg_txt(230), datetime); // Server time (normal time): %A, %B %d %Y %X.
  4583. 	clif_displaymessage(fd, temp);
  4584.  
  4585. 	if (battle_config.night_duration == 0 && battle_config.day_duration == 0) {
  4586. 		if (night_flag == 0)
  4587. 			clif_displaymessage(fd, msg_txt(231)); // Game time: The game is in permanent daylight.
  4588. 		else
  4589. 			clif_displaymessage(fd, msg_txt(232)); // Game time: The game is in permanent night.
  4590. 	} else if (battle_config.night_duration == 0)
  4591. 		if (night_flag == 1) { // we start with night
  4592. 			timer_data = get_timer(day_timer_tid);
  4593. 			sprintf(temp, msg_txt(233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in night for %s.
  4594. 			clif_displaymessage(fd, temp);
  4595. 			clif_displaymessage(fd, msg_txt(234)); // Game time: After, the game will be in permanent daylight.
  4596. 		} else
  4597. 			clif_displaymessage(fd, msg_txt(231)); // Game time: The game is in permanent daylight.
  4598. 	else if (battle_config.day_duration == 0)
  4599. 		if (night_flag == 0) { // we start with day
  4600. 			timer_data = get_timer(night_timer_tid);
  4601. 			sprintf(temp, msg_txt(235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  4602. 			clif_displaymessage(fd, temp);
  4603. 			clif_displaymessage(fd, msg_txt(236)); // Game time: After, the game will be in permanent night.
  4604. 		} else
  4605. 			clif_displaymessage(fd, msg_txt(232)); // Game time: The game is in permanent night.
  4606. 	else {
  4607. 		if (night_flag == 0) {
  4608. 			timer_data = get_timer(night_timer_tid);
  4609. 			timer_data2 = get_timer(day_timer_tid);
  4610. 			sprintf(temp, msg_txt(235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  4611. 			clif_displaymessage(fd, temp);
  4612. 			if (DIFF_TICK(timer_data->tick, timer_data2->tick) > 0)
  4613. 				sprintf(temp, msg_txt(237), txt_time(DIFF_TICK(timer_data->interval,DIFF_TICK(timer_data->tick,timer_data2->tick)) / 1000)); // Game time: After, the game will be in night for %s.
  4614. 			else
  4615. 				sprintf(temp, msg_txt(237), txt_time(DIFF_TICK(timer_data2->tick,timer_data->tick)/1000)); // Game time: After, the game will be in night for %s.
  4616. 			clif_displaymessage(fd, temp);
  4617. 			sprintf(temp, msg_txt(238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  4618. 			clif_displaymessage(fd, temp);
  4619. 		} else {
  4620. 			timer_data = get_timer(day_timer_tid);
  4621. 			timer_data2 = get_timer(night_timer_tid);
  4622. 			sprintf(temp, msg_txt(233), txt_time(DIFF_TICK(timer_data->tick,gettick()) / 1000)); // Game time: The game is actualy in night for %s.
  4623. 			clif_displaymessage(fd, temp);
  4624. 			if (DIFF_TICK(timer_data->tick,timer_data2->tick) > 0)
  4625. 				sprintf(temp, msg_txt(239), txt_time((timer_data->interval - DIFF_TICK(timer_data->tick, timer_data2->tick)) / 1000)); // Game time: After, the game will be in daylight for %s.
  4626. 			else
  4627. 				sprintf(temp, msg_txt(239), txt_time(DIFF_TICK(timer_data2->tick, timer_data->tick) / 1000)); // Game time: After, the game will be in daylight for %s.
  4628. 			clif_displaymessage(fd, temp);
  4629. 			sprintf(temp, msg_txt(238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  4630. 			clif_displaymessage(fd, temp);
  4631. 		}
  4632. 	}
  4633.  
  4634. 	return 0;
  4635. }
  4636.  
  4637. //Added by Coltaro
  4638. //We're using this function here instead of using time_t so that it only counts player's jail time when he/she's online (and since the idea is to reduce the amount of minutes one by one in status_change_timer...).
  4639. //Well, using time_t could still work but for some reason that looks like more coding x_x
  4640. static void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute)
  4641. {
  4642. 	const int factor_year = 518400; //12*30*24*60 = 518400
  4643. 	const int factor_month = 43200; //30*24*60 = 43200
  4644. 	const int factor_day = 1440; //24*60 = 1440
  4645. 	const int factor_hour = 60;
  4646.  
  4647. 	*year = jailtime/factor_year;
  4648. 	jailtime -= *year*factor_year;
  4649. 	*month = jailtime/factor_month;
  4650. 	jailtime -= *month*factor_month;
  4651. 	*day = jailtime/factor_day;
  4652. 	jailtime -= *day*factor_day;
  4653. 	*hour = jailtime/factor_hour;
  4654. 	jailtime -= *hour*factor_hour;
  4655. 	*minute = jailtime;
  4656.  
  4657. 	*year = *year > 0? *year : 0;
  4658. 	*month = *month > 0? *month : 0;
  4659. 	*day = *day > 0? *day : 0;
  4660. 	*hour = *hour > 0? *hour : 0;
  4661. 	*minute = *minute > 0? *minute : 0;
  4662. 	return;
  4663. }
  4664.  
  4665. /*==========================================
  4666.  * @jail <char_name> by [Yor]
  4667.  * Special warp! No check with nowarp and nowarpto flag
  4668.  *------------------------------------------*/
  4669. ACMD_FUNC(jail)
  4670. {
  4671. 	struct map_session_data *pl_sd;
  4672. 	int x, y;
  4673. 	unsigned short m_index;
  4674. 	nullpo_retr(-1, sd);
  4675.  
  4676. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4677.  
  4678. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4679. 		clif_displaymessage(fd, "Please, enter a player name (usage: @jail <char_name>).");
  4680. 		return -1;
  4681. 	}
  4682.  
  4683. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4684. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4685. 		return -1;
  4686. 	}
  4687.  
  4688. 	if (pc_get_group_level(sd) < pc_get_group_level(pl_sd))
  4689.   	{ // you can jail only lower or same GM
  4690. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4691. 		return -1;
  4692. 	}
  4693.  
  4694. 	if (pl_sd->sc.data[SC_JAILED])
  4695. 	{
  4696. 		clif_displaymessage(fd, msg_txt(118)); // Player warped in jails.
  4697. 		return -1;
  4698. 	}
  4699.  
  4700. 	switch(rnd() % 2) { //Jail Locations
  4701. 	case 0:
  4702. 		m_index = mapindex_name2id(MAP_JAIL);
  4703. 		x = 24;
  4704. 		y = 75;
  4705. 		break;
  4706. 	default:
  4707. 		m_index = mapindex_name2id(MAP_JAIL);
  4708. 		x = 49;
  4709. 		y = 75;
  4710. 		break;
  4711. 	}
  4712.  
  4713. 	//Duration of INT_MAX to specify infinity.
  4714. 	sc_start4(&pl_sd->bl,SC_JAILED,100,INT_MAX,m_index,x,y,1000);
  4715. 	clif_displaymessage(pl_sd->fd, msg_txt(117)); // GM has send you in jails.
  4716. 	clif_displaymessage(fd, msg_txt(118)); // Player warped in jails.
  4717. 	return 0;
  4718. }
  4719.  
  4720. /*==========================================
  4721.  * @unjail/@discharge <char_name> by [Yor]
  4722.  * Special warp! No check with nowarp and nowarpto flag
  4723.  *------------------------------------------*/
  4724. ACMD_FUNC(unjail)
  4725. {
  4726. 	struct map_session_data *pl_sd;
  4727.  
  4728. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4729.  
  4730. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4731. 		clif_displaymessage(fd, "Please, enter a player name (usage: @unjail/@discharge <char_name>).");
  4732. 		return -1;
  4733. 	}
  4734.  
  4735. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4736. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4737. 		return -1;
  4738. 	}
  4739.  
  4740. 	if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { // you can jail only lower or same GM
  4741.  
  4742. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4743. 		return -1;
  4744. 	}
  4745.  
  4746. 	if (!pl_sd->sc.data[SC_JAILED])
  4747. 	{
  4748. 		clif_displaymessage(fd, msg_txt(119)); // This player is not in jails.
  4749. 		return -1;
  4750. 	}
  4751.  
  4752. 	//Reset jail time to 1 sec.
  4753. 	sc_start(&pl_sd->bl,SC_JAILED,100,1,1000);
  4754. 	clif_displaymessage(pl_sd->fd, msg_txt(120)); // A GM has discharged you from jail.
  4755. 	clif_displaymessage(fd, msg_txt(121)); // Player unjailed.
  4756. 	return 0;
  4757. }
  4758.  
  4759. ACMD_FUNC(jailfor)
  4760. {
  4761. 	struct map_session_data *pl_sd = NULL;
  4762. 	int year, month, day, hour, minute, value;
  4763. 	char * modif_p;
  4764. 	int jailtime = 0,x,y;
  4765. 	short m_index = 0;
  4766. 	nullpo_retr(-1, sd);
  4767.  
  4768. 	if (!message || !*message || sscanf(message, "%s %23[^\n]",atcmd_output,atcmd_player_name) < 2) {
  4769. 		clif_displaymessage(fd, msg_txt(400));	//Usage: @jailfor <time> <character name>
  4770. 		return -1;
  4771. 	}
  4772.  
  4773. 	atcmd_output[sizeof(atcmd_output)-1] = '\0';
  4774.  
  4775. 	modif_p = atcmd_output;
  4776. 	year = month = day = hour = minute = 0;
  4777. 	while (modif_p[0] != '\0') {
  4778. 		value = atoi(modif_p);
  4779. 		if (value == 0)
  4780. 			modif_p++;
  4781. 		else {
  4782. 			if (modif_p[0] == '-' || modif_p[0] == '+')
  4783. 				modif_p++;
  4784. 			while (modif_p[0] >= '0' && modif_p[0] <= '9')
  4785. 				modif_p++;
  4786. 			if (modif_p[0] == 'n') {
  4787. 				minute = value;
  4788. 				modif_p++;
  4789. 			} else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  4790. 				minute = value;
  4791. 				modif_p = modif_p + 2;
  4792. 			} else if (modif_p[0] == 'h') {
  4793. 				hour = value;
  4794. 				modif_p++;
  4795. 			} else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  4796. 				day = value;
  4797. 				modif_p++;
  4798. 			} else if (modif_p[0] == 'm') {
  4799. 				month = value;
  4800. 				modif_p++;
  4801. 			} else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  4802. 				year = value;
  4803. 				modif_p++;
  4804. 			} else if (modif_p[0] != '\0') {
  4805. 				modif_p++;
  4806. 			}
  4807. 		}
  4808. 	}
  4809.  
  4810. 	if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0) {
  4811. 		clif_displaymessage(fd, "Invalid time for jail command.");
  4812. 		return -1;
  4813. 	}
  4814.  
  4815. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4816. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4817. 		return -1;
  4818. 	}
  4819.  
  4820. 	if (pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  4821. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4822. 		return -1;
  4823. 	}
  4824.  
  4825. 	jailtime = year*12*30*24*60 + month*30*24*60 + day*24*60 + hour*60 + minute;	//In minutes
  4826.  
  4827. 	if(jailtime==0) {
  4828. 		clif_displaymessage(fd, "Invalid time for jail command.");
  4829. 		return -1;
  4830. 	}
  4831.  
  4832. 	//Added by Coltaro
  4833. 	if(pl_sd->sc.data[SC_JAILED] && 
  4834. 		pl_sd->sc.data[SC_JAILED]->val1 != INT_MAX)
  4835.   	{	//Update the player's jail time
  4836. 		jailtime += pl_sd->sc.data[SC_JAILED]->val1;
  4837. 		if (jailtime <= 0) {
  4838. 			jailtime = 0;
  4839. 			clif_displaymessage(pl_sd->fd, msg_txt(120)); // GM has discharge you.
  4840. 			clif_displaymessage(fd, msg_txt(121)); // Player unjailed
  4841. 		} else {
  4842. 			get_jail_time(jailtime,&year,&month,&day,&hour,&minute);
  4843. 			sprintf(atcmd_output,msg_txt(402),"You are now",year,month,day,hour,minute); //%s in jail for %d years, %d months, %d days, %d hours and %d minutes
  4844. 	 		clif_displaymessage(pl_sd->fd, atcmd_output);
  4845. 			sprintf(atcmd_output,msg_txt(402),"This player is now",year,month,day,hour,minute); //This player is now in jail for %d years, %d months, %d days, %d hours and %d minutes
  4846. 	 		clif_displaymessage(fd, atcmd_output);
  4847. 		}
  4848. 	} else if (jailtime < 0) {
  4849. 		clif_displaymessage(fd, "Invalid time for jail command.");
  4850. 		return -1;
  4851. 	}
  4852.  
  4853. 	//Jail locations, add more as you wish.
  4854. 	switch(rnd()%2)
  4855. 	{
  4856. 		case 1: //Jail #1
  4857. 			m_index = mapindex_name2id(MAP_JAIL);
  4858. 			x = 49; y = 75;
  4859. 			break;
  4860. 		default: //Default Jail
  4861. 			m_index = mapindex_name2id(MAP_JAIL);
  4862. 			x = 24; y = 75;
  4863. 			break;
  4864. 	}
  4865.  
  4866. 	sc_start4(&pl_sd->bl,SC_JAILED,100,jailtime,m_index,x,y,jailtime?60000:1000); //jailtime = 0: Time was reset to 0. Wait 1 second to warp player out (since it's done in status_change_timer).
  4867. 	return 0;
  4868. }
  4869.  
  4870.  
  4871. //By Coltaro
  4872. ACMD_FUNC(jailtime)
  4873. {
  4874. 	int year, month, day, hour, minute;
  4875.  
  4876. 	nullpo_retr(-1, sd);
  4877.  
  4878. 	if (!sd->sc.data[SC_JAILED]) {
  4879. 		clif_displaymessage(fd, "You are not in jail."); // You are not in jail.
  4880. 		return -1;
  4881. 	}
  4882.  
  4883. 	if (sd->sc.data[SC_JAILED]->val1 == INT_MAX) {
  4884. 		clif_displaymessage(fd, "You have been jailed indefinitely.");
  4885. 		return 0;
  4886. 	}
  4887.  
  4888. 	if (sd->sc.data[SC_JAILED]->val1 <= 0) { // Was not jailed with @jailfor (maybe @jail? or warped there? or got recalled?)
  4889. 		clif_displaymessage(fd, "You have been jailed for an unknown amount of time.");
  4890. 		return -1;
  4891. 	}
  4892.  
  4893. 	//Get remaining jail time
  4894. 	get_jail_time(sd->sc.data[SC_JAILED]->val1,&year,&month,&day,&hour,&minute);
  4895. 	sprintf(atcmd_output,msg_txt(402),"You will remain",year,month,day,hour,minute); // You will remain in jail for %d years, %d months, %d days, %d hours and %d minutes
  4896.  
  4897. 	clif_displaymessage(fd, atcmd_output);
  4898.  
  4899. 	return 0;
  4900. }
  4901.  
  4902. /*==========================================
  4903.  * @disguise <mob_id> by [Valaris] (simplified by [Yor])
  4904.  *------------------------------------------*/
  4905. ACMD_FUNC(disguise)
  4906. {
  4907. 	int id = 0;
  4908. 	nullpo_retr(-1, sd);
  4909.  
  4910. 	if (!message || !*message) {
  4911. 		clif_displaymessage(fd, "Please, enter a Monster/NPC name/id (usage: @disguise <monster_name_or_monster_ID>).");
  4912. 		return -1;
  4913. 	}
  4914.  
  4915. 	if ((id = atoi(message)) > 0)
  4916. 	{	//Acquired an ID
  4917. 		if (!mobdb_checkid(id) && !npcdb_checkid(id))
  4918. 			id = 0; //Invalid id for either mobs or npcs.
  4919. 	}	else	{ //Acquired a Name
  4920. 		if ((id = mobdb_searchname(message)) == 0)
  4921. 		{
  4922. 			struct npc_data* nd = npc_name2id(message);
  4923. 			if (nd != NULL)
  4924. 				id = nd->class_;
  4925. 		}
  4926. 	}
  4927.  
  4928. 	if (id == 0)
  4929. 	{
  4930. 		clif_displaymessage(fd, msg_txt(123));	// Invalid Monster/NPC name/ID specified.
  4931. 		return -1;
  4932. 	}
  4933.  
  4934. 	if(pc_isriding(sd))
  4935. 	{
  4936. 		//FIXME: wrong message [ultramage]
  4937. 		//clif_displaymessage(fd, msg_txt(227)); // Character cannot wear disguise while riding a PecoPeco.
  4938. 		return -1;
  4939. 	}
  4940.  
  4941. 	pc_disguise(sd, id);
  4942. 	clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  4943.  
  4944. 	return 0;
  4945. }
  4946.  
  4947. /*==========================================
  4948.  * DisguiseAll
  4949.  *------------------------------------------*/
  4950. ACMD_FUNC(disguiseall)
  4951. {
  4952. 	int mob_id=0;
  4953. 	struct map_session_data *pl_sd;
  4954. 	struct s_mapiterator* iter;
  4955. 	nullpo_retr(-1, sd);
  4956.  
  4957. 	if (!message || !*message) {
  4958. 		clif_displaymessage(fd, "Please, enter a Monster/NPC name/id (usage: @disguiseall <monster name or monster ID>).");
  4959. 		return -1;
  4960. 	}
  4961.  
  4962. 	if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
  4963. 		mob_id = atoi(message);
  4964.  
  4965. 	if (!mobdb_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
  4966. 		clif_displaymessage(fd, msg_txt(123)); // Monster/NPC name/id not found.
  4967. 		return -1;
  4968. 	}
  4969.  
  4970. 	iter = mapit_getallusers();
  4971. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4972. 		pc_disguise(pl_sd, mob_id);
  4973. 	mapit_free(iter);
  4974.  
  4975. 	clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  4976. 	return 0;
  4977. }
  4978.  
  4979. /*==========================================
  4980.  * @undisguise by [Yor]
  4981.  *------------------------------------------*/
  4982. ACMD_FUNC(undisguise)
  4983. {
  4984. 	nullpo_retr(-1, sd);
  4985. 	if (sd->disguise) {
  4986. 		pc_disguise(sd, 0);
  4987. 		clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  4988. 	} else {
  4989. 		clif_displaymessage(fd, msg_txt(125)); // You're not disguised.
  4990. 		return -1;
  4991. 	}
  4992.  
  4993. 	return 0;
  4994. }
  4995.  
  4996. /*==========================================
  4997.  * UndisguiseAll
  4998.  *------------------------------------------*/
  4999. ACMD_FUNC(undisguiseall)
  5000. {
  5001. 	struct map_session_data *pl_sd;
  5002. 	struct s_mapiterator* iter;
  5003. 	nullpo_retr(-1, sd);
  5004.  
  5005. 	iter = mapit_getallusers();
  5006. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  5007. 		if( pl_sd->disguise )
  5008. 			pc_disguise(pl_sd, 0);
  5009. 	mapit_free(iter);
  5010.  
  5011. 	clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  5012.  
  5013. 	return 0;
  5014. }
  5015.  
  5016. /*==========================================
  5017.  * @exp by [Skotlex]
  5018.  *------------------------------------------*/
  5019. ACMD_FUNC(exp)
  5020. {
  5021. 	char output[CHAT_SIZE_MAX];
  5022. 	double nextb, nextj;
  5023. 	nullpo_retr(-1, sd);
  5024. 	memset(output, '\0', sizeof(output));
  5025.  
  5026. 	nextb = pc_nextbaseexp(sd);
  5027. 	if (nextb)
  5028. 		nextb = sd->status.base_exp*100.0/nextb;
  5029.  
  5030. 	nextj = pc_nextjobexp(sd);
  5031. 	if (nextj)
  5032. 		nextj = sd->status.job_exp*100.0/nextj;
  5033.  
  5034. 	sprintf(output, "Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%)", sd->status.base_level, nextb, sd->status.job_level, nextj);
  5035. 	clif_displaymessage(fd, output);
  5036. 	return 0;
  5037. }
  5038.  
  5039.  
  5040. /*==========================================
  5041.  * @broadcast by [Valaris]
  5042.  *------------------------------------------*/
  5043. ACMD_FUNC(broadcast)
  5044. {
  5045. 	nullpo_retr(-1, sd);
  5046.  
  5047. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  5048.  
  5049. 	if (!message || !*message) {
  5050. 		clif_displaymessage(fd, "Please, enter a message (usage: @broadcast <message>).");
  5051. 		return -1;
  5052. 	}
  5053.  
  5054. 	sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  5055. 	intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, 0);
  5056.  
  5057. 	return 0;
  5058. }
  5059.  
  5060. /*==========================================
  5061.  * @localbroadcast by [Valaris]
  5062.  *------------------------------------------*/
  5063. ACMD_FUNC(localbroadcast)
  5064. {
  5065. 	nullpo_retr(-1, sd);
  5066.  
  5067. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  5068.  
  5069. 	if (!message || !*message) {
  5070. 		clif_displaymessage(fd, "Please, enter a message (usage: @localbroadcast <message>).");
  5071. 		return -1;
  5072. 	}
  5073.  
  5074. 	sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  5075.  
  5076. 	clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  5077.  
  5078. 	return 0;
  5079. }
  5080.  
  5081. /*==========================================
  5082.  * @email <actual@email> <new@email> by [Yor]
  5083.  *------------------------------------------*/
  5084. ACMD_FUNC(email)
  5085. {
  5086. 	char actual_email[100];
  5087. 	char new_email[100];
  5088. 	nullpo_retr(-1, sd);
  5089.  
  5090. 	memset(actual_email, '\0', sizeof(actual_email));
  5091. 	memset(new_email, '\0', sizeof(new_email));
  5092.  
  5093. 	if (!message || !*message || sscanf(message, "%99s %99s", actual_email, new_email) < 2) {
  5094. 		clif_displaymessage(fd, "Please enter 2 emails (usage: @email <actual@email> <new@email>).");
  5095. 		return -1;
  5096. 	}
  5097.  
  5098. 	if (e_mail_check(actual_email) == 0) {
  5099. 		clif_displaymessage(fd, msg_txt(144)); // Invalid actual email. If you have default e-mail, give [email protected].
  5100. 		return -1;
  5101. 	} else if (e_mail_check(new_email) == 0) {
  5102. 		clif_displaymessage(fd, msg_txt(145)); // Invalid new email. Please enter a real e-mail.
  5103. 		return -1;
  5104. 	} else if (strcmpi(new_email, "[email protected]") == 0) {
  5105. 		clif_displaymessage(fd, msg_txt(146)); // New email must be a real e-mail.
  5106. 		return -1;
  5107. 	} else if (strcmpi(actual_email, new_email) == 0) {
  5108. 		clif_displaymessage(fd, msg_txt(147)); // New email must be different of the actual e-mail.
  5109. 		return -1;
  5110. 	}
  5111.  
  5112. 	chrif_changeemail(sd->status.account_id, actual_email, new_email);
  5113. 	clif_displaymessage(fd, msg_txt(148)); // Information sended to login-server via char-server.
  5114. 	return 0;
  5115. }
  5116.  
  5117. /*==========================================
  5118.  *@effect
  5119.  *------------------------------------------*/
  5120. ACMD_FUNC(effect)
  5121. {
  5122. 	int type = 0, flag = 0;
  5123. 	nullpo_retr(-1, sd);
  5124.  
  5125. 	if (!message || !*message || sscanf(message, "%d", &type) < 1) {
  5126. 		clif_displaymessage(fd, "Please, enter an effect number (usage: @effect <effect number>).");
  5127. 		return -1;
  5128. 	}
  5129.  
  5130. 	clif_specialeffect(&sd->bl, type, (send_target)flag);
  5131. 	clif_displaymessage(fd, msg_txt(229)); // Your effect has changed.
  5132. 	return 0;
  5133. }
  5134.  
  5135. /*==========================================
  5136.  * @killer by MouseJstr
  5137.  * enable killing players even when not in pvp
  5138.  *------------------------------------------*/
  5139. ACMD_FUNC(killer)
  5140. {
  5141. 	nullpo_retr(-1, sd);
  5142. 	sd->state.killer = !sd->state.killer;
  5143.  
  5144. 	if(sd->state.killer)
  5145. 		clif_displaymessage(fd, msg_txt(241));
  5146. 	else {
  5147. 		clif_displaymessage(fd, msg_txt(287));
  5148. 		pc_stop_attack(sd);
  5149. 	}
  5150. 	return 0;
  5151. }
  5152.  
  5153. /*==========================================
  5154.  * @killable by MouseJstr
  5155.  * enable other people killing you
  5156.  *------------------------------------------*/
  5157. ACMD_FUNC(killable)
  5158. {
  5159. 	nullpo_retr(-1, sd);
  5160. 	sd->state.killable = !sd->state.killable;
  5161.  
  5162. 	if(sd->state.killable)
  5163. 		clif_displaymessage(fd, msg_txt(242));
  5164. 	else {
  5165. 		clif_displaymessage(fd, msg_txt(288));
  5166. 		map_foreachinrange(atcommand_stopattack,&sd->bl, AREA_SIZE, BL_CHAR, sd->bl.id);
  5167. 	}
  5168. 	return 0;
  5169. }
  5170.  
  5171. /*==========================================
  5172.  * @skillon by MouseJstr
  5173.  * turn skills on for the map
  5174.  *------------------------------------------*/
  5175. ACMD_FUNC(skillon)
  5176. {
  5177. 	nullpo_retr(-1, sd);
  5178. 	map[sd->bl.m].flag.noskill = 0;
  5179. 	clif_displaymessage(fd, msg_txt(244));
  5180. 	return 0;
  5181. }
  5182.  
  5183. /*==========================================
  5184.  * @skilloff by MouseJstr
  5185.  * Turn skills off on the map
  5186.  *------------------------------------------*/
  5187. ACMD_FUNC(skilloff)
  5188. {
  5189. 	nullpo_retr(-1, sd);
  5190. 	map[sd->bl.m].flag.noskill = 1;
  5191. 	clif_displaymessage(fd, msg_txt(243));
  5192. 	return 0;
  5193. }
  5194.  
  5195. /*==========================================
  5196.  * @npcmove by MouseJstr
  5197.  * move a npc
  5198.  *------------------------------------------*/
  5199. ACMD_FUNC(npcmove)
  5200. {
  5201. 	int x = 0, y = 0, m;
  5202. 	struct npc_data *nd = 0;
  5203. 	nullpo_retr(-1, sd);
  5204. 	memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  5205.  
  5206. 	if (!message || !*message || sscanf(message, "%d %d %23[^\n]", &x, &y, atcmd_player_name) < 3) {
  5207. 		clif_displaymessage(fd, "Usage: @npcmove <X> <Y> <npc_name>");
  5208. 		return -1;
  5209. 	}
  5210.  
  5211. 	if ((nd = npc_name2id(atcmd_player_name)) == NULL)
  5212. 	{
  5213. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  5214. 		return -1;
  5215. 	}
  5216.  
  5217. 	if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  5218. 	{
  5219. 		clif_displaymessage(fd, "NPC is not on this map.");
  5220. 		return -1;	//Not on a map.
  5221. 	}
  5222.  
  5223. 	x = cap_value(x, 0, map[m].xs-1);
  5224. 	y = cap_value(y, 0, map[m].ys-1);
  5225. 	map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  5226. 	map_moveblock(&nd->bl, x, y, gettick());
  5227. 	map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  5228. 	clif_displaymessage(fd, "NPC moved.");
  5229.  
  5230. 	return 0;
  5231. }
  5232.  
  5233. /*==========================================
  5234.  * @addwarp by MouseJstr
  5235.  * Create a new static warp point.
  5236.  *------------------------------------------*/
  5237. ACMD_FUNC(addwarp)
  5238. {
  5239. 	char mapname[32];
  5240. 	int x,y;
  5241. 	unsigned short m;
  5242. 	struct npc_data* nd;
  5243.  
  5244. 	nullpo_retr(-1, sd);
  5245.  
  5246. 	if (!message || !*message || sscanf(message, "%31s %d %d", mapname, &x, &y) < 3) {
  5247. 		clif_displaymessage(fd, "usage: @addwarp <mapname> <X> <Y>.");
  5248. 		return -1;
  5249. 	}
  5250.  
  5251. 	m = mapindex_name2id(mapname);
  5252. 	if( m == 0 )
  5253. 	{
  5254. 		sprintf(atcmd_output, "Unknown map '%s'.", mapname);
  5255. 		clif_displaymessage(fd, atcmd_output);
  5256. 		return -1;
  5257. 	}
  5258.  
  5259. 	nd = npc_add_warp(sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
  5260. 	if( nd == NULL )
  5261. 		return -1;
  5262.  
  5263. 	sprintf(atcmd_output, "New warp NPC '%s' created.", nd->exname);
  5264. 	clif_displaymessage(fd, atcmd_output);
  5265. 	return 0;
  5266. }
  5267.  
  5268. /*==========================================
  5269.  * @follow by [MouseJstr]
  5270.  * Follow a player .. staying no more then 5 spaces away
  5271.  *------------------------------------------*/
  5272. ACMD_FUNC(follow)
  5273. {
  5274. 	struct map_session_data *pl_sd = NULL;
  5275. 	nullpo_retr(-1, sd);
  5276.  
  5277. 	if (!message || !*message) {
  5278. 		if (sd->followtarget == -1)
  5279. 			return -1;
  5280.  
  5281. 		pc_stop_following (sd);
  5282. 		clif_displaymessage(fd, "Follow mode OFF.");
  5283. 		return 0;
  5284. 	}
  5285.  
  5286. 	if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  5287. 	{
  5288. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5289. 		return -1;
  5290. 	}
  5291.  
  5292. 	if (sd->followtarget == pl_sd->bl.id) {
  5293. 		pc_stop_following (sd);
  5294. 		clif_displaymessage(fd, "Follow mode OFF.");
  5295. 	} else {
  5296. 		pc_follow(sd, pl_sd->bl.id);
  5297. 		clif_displaymessage(fd, "Follow mode ON.");
  5298. 	}
  5299.  
  5300. 	return 0;
  5301. }
  5302.  
  5303.  
  5304. /*==========================================
  5305.  * @dropall by [MouseJstr]
  5306.  * Drop all your possession on the ground
  5307.  *------------------------------------------*/
  5308. ACMD_FUNC(dropall)
  5309. {
  5310. 	int i;
  5311. 	nullpo_retr(-1, sd);
  5312. 	for (i = 0; i < MAX_INVENTORY; i++) {
  5313. 	if (sd->status.inventory[i].amount) {
  5314. 		if(sd->status.inventory[i].equip != 0)
  5315. 			pc_unequipitem(sd, i, 3);
  5316. 			pc_dropitem(sd,  i, sd->status.inventory[i].amount);
  5317. 		}
  5318. 	}
  5319. 	return 0;
  5320. }
  5321.  
  5322. /*==========================================
  5323.  * @storeall by [MouseJstr]
  5324.  * Put everything into storage
  5325.  *------------------------------------------*/
  5326. ACMD_FUNC(storeall)
  5327. {
  5328. 	int i;
  5329. 	nullpo_retr(-1, sd);
  5330.  
  5331. 	if (sd->state.storage_flag != 1)
  5332.   	{	//Open storage.
  5333. 		if( storage_storageopen(sd) == 1 ) {
  5334. 			clif_displaymessage(fd, "You can't open the storage currently.");
  5335. 			return -1;
  5336. 		}
  5337. 	}
  5338.  
  5339. 	for (i = 0; i < MAX_INVENTORY; i++) {
  5340. 		if (sd->status.inventory[i].amount) {
  5341. 			if(sd->status.inventory[i].equip != 0)
  5342. 				pc_unequipitem(sd, i, 3);
  5343. 			storage_storageadd(sd,  i, sd->status.inventory[i].amount);
  5344. 		}
  5345. 	}
  5346. 	storage_storageclose(sd);
  5347.  
  5348. 	clif_displaymessage(fd, "It is done");
  5349. 	return 0;
  5350. }
  5351.  
  5352. /*==========================================
  5353.  * @skillid by [MouseJstr]
  5354.  * lookup a skill by name
  5355.  *------------------------------------------*/
  5356. ACMD_FUNC(skillid)
  5357. {
  5358. 	int skillen, idx;
  5359. 	nullpo_retr(-1, sd);
  5360.  
  5361. 	if (!message || !*message)
  5362. 	{
  5363. 		clif_displaymessage(fd, "Please enter a skill name to look up (usage: @skillid <skill name>).");
  5364. 		return -1;
  5365. 	}
  5366.  
  5367. 	skillen = strlen(message);
  5368.  
  5369. 	for (idx = 0; idx < MAX_SKILL_DB; idx++) {
  5370. 		if (strnicmp(skill_db[idx].name, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0)
  5371. 		{
  5372. 			sprintf(atcmd_output, "skill %d: %s", idx, skill_db[idx].desc);
  5373. 			clif_displaymessage(fd, atcmd_output);
  5374. 		}
  5375. 	}
  5376.  
  5377. 	return 0;
  5378. }
  5379.  
  5380. /*==========================================
  5381.  * @useskill by [MouseJstr]
  5382.  * A way of using skills without having to find them in the skills menu
  5383.  *------------------------------------------*/
  5384. ACMD_FUNC(useskill)
  5385. {
  5386. 	struct map_session_data *pl_sd = NULL;
  5387. 	struct block_list *bl;
  5388. 	int skillnum;
  5389. 	int skilllv;
  5390. 	char target[100];
  5391. 	nullpo_retr(-1, sd);
  5392.  
  5393. 	if(!message || !*message || sscanf(message, "%d %d %23[^\n]", &skillnum, &skilllv, target) != 3) {
  5394. 		clif_displaymessage(fd, "Usage: @useskill <skillnum> <skillv> <target>");
  5395. 		return -1;
  5396. 	}
  5397.  
  5398. 	if ( (pl_sd = map_nick2sd(target)) == NULL )
  5399. 	{
  5400. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5401. 		return -1;
  5402. 	}
  5403.  
  5404. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  5405. 	{
  5406. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  5407. 		return -1;
  5408. 	}
  5409.  
  5410. 	if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL
  5411. 		&& sd->hd && merc_is_hom_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
  5412. 		bl = &sd->hd->bl;
  5413. 	else
  5414. 		bl = &sd->bl;
  5415.  
  5416. 	if (skill_get_inf(skillnum)&INF_GROUND_SKILL)
  5417. 		unit_skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skillnum, skilllv);
  5418. 	else
  5419. 		unit_skilluse_id(bl, pl_sd->bl.id, skillnum, skilllv);
  5420.  
  5421. 	return 0;
  5422. }
  5423.  
  5424. /*==========================================
  5425.  * @displayskill by [Skotlex]
  5426.  *  Debug command to locate new skill IDs. It sends the
  5427.  *  three possible skill-effect packets to the area.
  5428.  *------------------------------------------*/
  5429. ACMD_FUNC(displayskill)
  5430. {
  5431. 	struct status_data * status;
  5432. 	unsigned int tick;
  5433. 	int skillnum;
  5434. 	int skilllv = 1;
  5435. 	nullpo_retr(-1, sd);
  5436.  
  5437. 	if (!message || !*message || sscanf(message, "%d %d", &skillnum, &skilllv) < 1)
  5438. 	{
  5439. 		clif_displaymessage(fd, "Usage: @displayskill <skillnum> {<skillv>}>");
  5440. 		return -1;
  5441. 	}
  5442. 	status = status_get_status_data(&sd->bl);
  5443. 	tick = gettick();
  5444. 	clif_skill_damage(&sd->bl,&sd->bl, tick, status->amotion, status->dmotion, 1, 1, skillnum, skilllv, 5);
  5445. 	clif_skill_nodamage(&sd->bl, &sd->bl, skillnum, skilllv, 1);
  5446. 	clif_skill_poseffect(&sd->bl, skillnum, skilllv, sd->bl.x, sd->bl.y, tick);
  5447. 	return 0;
  5448. }
  5449.  
  5450. /*==========================================
  5451.  * @skilltree by [MouseJstr]
  5452.  * prints the skill tree for a player required to get to a skill
  5453.  *------------------------------------------*/
  5454. ACMD_FUNC(skilltree)
  5455. {
  5456. 	struct map_session_data *pl_sd = NULL;
  5457. 	int skillnum;
  5458. 	int meets, j, c=0;
  5459. 	char target[NAME_LENGTH];
  5460. 	struct skill_tree_entry *ent;
  5461. 	nullpo_retr(-1, sd);
  5462.  
  5463. 	if(!message || !*message || sscanf(message, "%d %23[^\r\n]", &skillnum, target) != 2) {
  5464. 		clif_displaymessage(fd, "Usage: @skilltree <skillnum> <target>");
  5465. 		return -1;
  5466. 	}
  5467.  
  5468. 	if ( (pl_sd = map_nick2sd(target)) == NULL )
  5469. 	{
  5470. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5471. 		return -1;
  5472. 	}
  5473.  
  5474. 	c = pc_calc_skilltree_normalize_job(pl_sd);
  5475. 	c = pc_mapid2jobid(c, pl_sd->status.sex);
  5476.  
  5477. 	sprintf(atcmd_output, "Player is using %s skill tree (%d basic points)", job_name(c), pc_checkskill(pl_sd, NV_BASIC));
  5478. 	clif_displaymessage(fd, atcmd_output);
  5479.  
  5480. 	ARR_FIND( 0, MAX_SKILL_TREE, j, skill_tree[c][j].id == 0 || skill_tree[c][j].id == skillnum );
  5481. 	if( j == MAX_SKILL_TREE || skill_tree[c][j].id == 0 )
  5482. 	{
  5483. 		sprintf(atcmd_output, "I do not believe the player can use that skill");
  5484. 		clif_displaymessage(fd, atcmd_output);
  5485. 		return 0;
  5486. 	}
  5487.  
  5488. 	ent = &skill_tree[c][j];
  5489.  
  5490. 	meets = 1;
  5491. 	for(j=0;j<MAX_PC_SKILL_REQUIRE;j++)
  5492. 	{
  5493. 		if( ent->need[j].id && pc_checkskill(sd,ent->need[j].id) < ent->need[j].lv)
  5494. 		{
  5495. 			sprintf(atcmd_output, "player requires level %d of skill %s", ent->need[j].lv, skill_db[ent->need[j].id].desc);
  5496. 			clif_displaymessage(fd, atcmd_output);
  5497. 			meets = 0;
  5498. 		}
  5499. 	}
  5500. 	if (meets == 1) {
  5501. 		sprintf(atcmd_output, "I believe the player meets all the requirements for that skill");
  5502. 		clif_displaymessage(fd, atcmd_output);
  5503. 	}
  5504.  
  5505. 	return 0;
  5506. }
  5507.  
  5508. // Hand a ring with partners name on it to this char
  5509. void getring (struct map_session_data* sd)
  5510. {
  5511. 	int flag, item_id;
  5512. 	struct item item_tmp;
  5513. 	item_id = (sd->status.sex) ? WEDDING_RING_M : WEDDING_RING_F;
  5514.  
  5515. 	memset(&item_tmp, 0, sizeof(item_tmp));
  5516. 	item_tmp.nameid = item_id;
  5517. 	item_tmp.identify = 1;
  5518. 	item_tmp.card[0] = 255;
  5519. 	item_tmp.card[2] = sd->status.partner_id;
  5520. 	item_tmp.card[3] = sd->status.partner_id >> 16;
  5521.  
  5522. 	if((flag = pc_additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) {
  5523. 		clif_additem(sd,0,0,flag);
  5524. 		map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  5525. 	}
  5526. }
  5527.  
  5528. /*==========================================
  5529.  * @marry by [MouseJstr], fixed by Lupus
  5530.  * Marry two players
  5531.  *------------------------------------------*/
  5532. ACMD_FUNC(marry)
  5533. {
  5534. 	struct map_session_data *pl_sd = NULL;
  5535. 	char player_name[NAME_LENGTH] = "";
  5536.  
  5537. 	nullpo_retr(-1, sd);
  5538.  
  5539. 	if (!message || !*message || sscanf(message, "%23s", player_name) != 1) {
  5540. 		clif_displaymessage(fd, "Usage: @marry <player name>");
  5541. 		return -1;
  5542. 	}
  5543.  
  5544. 	if ((pl_sd = map_nick2sd(player_name)) == NULL) {
  5545. 		clif_displaymessage(fd, msg_txt(3));
  5546. 		return -1;
  5547. 	}
  5548.  
  5549. 	if (pc_marriage(sd, pl_sd) == 0) {
  5550. 		clif_displaymessage(fd, "They are married.. wish them well.");
  5551. 		clif_wedding_effect(&pl_sd->bl); //wedding effect and music [Lupus]
  5552. 		getring(sd); // Auto-give named rings (Aru)
  5553. 		getring(pl_sd);
  5554. 		return 0;
  5555. 	}
  5556.  
  5557. 	clif_displaymessage(fd, "The two cannot wed because one of them is either a baby or is already married.");
  5558. 	return -1;
  5559. }
  5560.  
  5561. /*==========================================
  5562.  * @divorce by [MouseJstr], fixed by [Lupus]
  5563.  * divorce two players
  5564.  *------------------------------------------*/
  5565. ACMD_FUNC(divorce)
  5566. {
  5567. 	nullpo_retr(-1, sd);
  5568.  
  5569. 	if (pc_divorce(sd) != 0) {
  5570. 		sprintf(atcmd_output, "'%s' is not married.", sd->status.name);
  5571. 		clif_displaymessage(fd, atcmd_output);
  5572. 		return -1;
  5573. 	}
  5574.  
  5575. 	sprintf(atcmd_output, "'%s' and his(her) partner are now divorced.", sd->status.name);
  5576. 	clif_displaymessage(fd, atcmd_output);
  5577. 	return 0;
  5578. }
  5579.  
  5580. /*==========================================
  5581.  * @changelook by [Celest]
  5582.  *------------------------------------------*/
  5583. ACMD_FUNC(changelook)
  5584. {
  5585. 	int i, j = 0, k = 0;
  5586. 	int pos[7] = { LOOK_HEAD_TOP,LOOK_HEAD_MID,LOOK_HEAD_BOTTOM,LOOK_WEAPON,LOOK_SHIELD,LOOK_SHOES,LOOK_ROBE };
  5587.  
  5588. 	if((i = sscanf(message, "%d %d", &j, &k)) < 1) {
  5589. 		clif_displaymessage(fd, "Usage: @changelook [<position>] <view id> -- [] = optional");
  5590. 		clif_displaymessage(fd, "Position: 1-Top 2-Middle 3-Bottom 4-Weapon 5-Shield 6-Shoes 7-Robe");
  5591. 		return -1;
  5592. 	} else if ( i == 2 ) {
  5593. 		if (j < 1 || j > 7)
  5594. 			j = 1;
  5595. 		j = pos[j - 1];
  5596. 	} else if( i == 1 ) {	// position not defined, use HEAD_TOP as default
  5597. 		k = j;	// swap
  5598. 		j = LOOK_HEAD_TOP;
  5599. 	}
  5600.  
  5601. 	clif_changelook(&sd->bl,j,k);
  5602.  
  5603. 	return 0;
  5604. }
  5605.  
  5606. /*==========================================
  5607.  * @autotrade by durf [Lupus] [Paradox924X]
  5608.  * Turns on/off Autotrade for a specific player
  5609.  *------------------------------------------*/
  5610. ACMD_FUNC(autotrade)
  5611. {
  5612. 	nullpo_retr(-1, sd);
  5613.  
  5614. 	if( map[sd->bl.m].flag.autotrade != battle_config.autotrade_mapflag ) {
  5615. 		clif_displaymessage(fd, "Autotrade is not allowed on this map.");
  5616. 		return -1;
  5617. 	}
  5618.  
  5619. 	if( pc_isdead(sd) ) {
  5620. 		clif_displaymessage(fd, "Cannot Autotrade if you are dead.");
  5621. 		return -1;
  5622. 	}
  5623.  
  5624. 	if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying
  5625. 		clif_displaymessage(fd, msg_txt(549)); // "You should have a shop open to use @autotrade."
  5626. 		return -1;
  5627. 	}
  5628.  
  5629. 	sd->state.autotrade = 1;
  5630. 	if( battle_config.at_timeout )
  5631. 	{
  5632. 		int timeout = atoi(message);
  5633. 		status_change_start(&sd->bl, SC_AUTOTRADE, 10000, 0, 0, 0, 0, ((timeout > 0) ? min(timeout,battle_config.at_timeout) : battle_config.at_timeout) * 60000, 0);
  5634. 	}
  5635. 	clif_authfail_fd(fd, 15);
  5636.  
  5637. 	return 0;
  5638. }
  5639.  
  5640. /*==========================================
  5641.  * @changegm by durf (changed by Lupus)
  5642.  * Changes Master of your Guild to a specified guild member
  5643.  *------------------------------------------*/
  5644. ACMD_FUNC(changegm)
  5645. {
  5646. 	struct guild *g;
  5647. 	struct map_session_data *pl_sd;
  5648. 	nullpo_retr(-1, sd);
  5649.  
  5650. 	if (sd->status.guild_id == 0 || (g = guild_search(sd->status.guild_id)) == NULL || strcmp(g->master,sd->status.name)) {
  5651. 		clif_displaymessage(fd, "You need to be a Guild Master to use this command.");
  5652. 		return -1;
  5653. 	}
  5654.  
  5655. 	if( map[sd->bl.m].flag.guildlock || map[sd->bl.m].flag.gvg_castle ) {
  5656. 		clif_displaymessage(fd, "You cannot change guild leaders on this map.");
  5657. 		return -1;
  5658. 	}
  5659.  
  5660. 	if( !message[0] ) {
  5661. 		clif_displaymessage(fd, "Command usage: @changegm <guildmember name>");
  5662. 		return -1;
  5663. 	}
  5664.  
  5665. 	if((pl_sd=map_nick2sd((char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
  5666. 		clif_displaymessage(fd, "Target character must be online and be a guildmate.");
  5667. 		return -1;
  5668. 	}
  5669.  
  5670. 	guild_gm_change(sd->status.guild_id, pl_sd);
  5671. 	return 0;
  5672. }
  5673.  
  5674. /*==========================================
  5675.  * @changeleader by Skotlex
  5676.  * Changes the leader of a party.
  5677.  *------------------------------------------*/
  5678. ACMD_FUNC(changeleader)
  5679. {
  5680. 	nullpo_retr(-1, sd);
  5681.  
  5682. 	if( !message[0] )
  5683. 	{
  5684. 		clif_displaymessage(fd, "Command usage: @changeleader <party member name>");
  5685. 		return -1;
  5686. 	}
  5687.  
  5688. 	if (party_changeleader(sd, map_nick2sd((char *) message)))
  5689. 		return 0;
  5690. 	return -1;
  5691. }
  5692.  
  5693. /*==========================================
  5694.  * @partyoption by Skotlex
  5695.  * Used to change the item share setting of a party.
  5696.  *------------------------------------------*/
  5697. ACMD_FUNC(partyoption)
  5698. {
  5699. 	struct party_data *p;
  5700. 	int mi, option;
  5701. 	char w1[16], w2[16];
  5702. 	nullpo_retr(-1, sd);
  5703.  
  5704. 	if (sd->status.party_id == 0 || (p = party_search(sd->status.party_id)) == NULL)
  5705. 	{
  5706. 		clif_displaymessage(fd, msg_txt(282));
  5707. 		return -1;
  5708. 	}
  5709.  
  5710. 	ARR_FIND( 0, MAX_PARTY, mi, p->data[mi].sd == sd );
  5711. 	if (mi == MAX_PARTY)
  5712. 		return -1; //Shouldn't happen
  5713.  
  5714. 	if (!p->party.member[mi].leader)
  5715. 	{
  5716. 		clif_displaymessage(fd, msg_txt(282));
  5717. 		return -1;
  5718. 	}
  5719.  
  5720. 	if(!message || !*message || sscanf(message, "%15s %15s", w1, w2) < 2)
  5721. 	{
  5722. 		clif_displaymessage(fd, "Command usage: @partyoption <pickup share: yes/no> <item distribution: yes/no>");
  5723. 		return -1;
  5724. 	}
  5725.  
  5726. 	option = (config_switch(w1)?1:0)|(config_switch(w2)?2:0);
  5727.  
  5728. 	//Change item share type.
  5729. 	if (option != p->party.item)
  5730. 		party_changeoption(sd, p->party.exp, option);
  5731. 	else
  5732. 		clif_displaymessage(fd, msg_txt(286));
  5733.  
  5734. 	return 0;
  5735. }
  5736.  
  5737. /*==========================================
  5738.  * @autoloot by Upa-Kun
  5739.  * Turns on/off AutoLoot for a specific player
  5740.  *------------------------------------------*/
  5741. ACMD_FUNC(autoloot)
  5742. {
  5743. 	int rate;
  5744. 	double drate;
  5745. 	nullpo_retr(-1, sd);
  5746. 	// autoloot command without value
  5747. 	if(!message || !*message)
  5748. 	{
  5749. 		if (sd->state.autoloot)
  5750. 			rate = 0;
  5751. 		else
  5752. 			rate = 10000;
  5753. 	} else {
  5754. 		drate = atof(message);
  5755. 		rate = (int)(drate*100);
  5756. 	}
  5757. 	if (rate < 0) rate = 0;
  5758. 	if (rate > 10000) rate = 10000;
  5759.  
  5760. 	sd->state.autoloot = rate;
  5761. 	if (sd->state.autoloot) {
  5762. 		snprintf(atcmd_output, sizeof atcmd_output, "Autolooting items with drop rates of %0.02f%% and below.",((double)sd->state.autoloot)/100.);
  5763. 		clif_displaymessage(fd, atcmd_output);
  5764. 	}else
  5765. 		clif_displaymessage(fd, "Autoloot is now off.");
  5766.  
  5767. 	return 0;
  5768. }
  5769.  
  5770. /*==========================================
  5771.  * @alootid
  5772.  *------------------------------------------*/
  5773. ACMD_FUNC(autolootitem)
  5774. {
  5775. 	struct item_data *item_data = NULL;
  5776. 	int i;
  5777. 	int action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
  5778.  
  5779. 	if (message && *message) {
  5780. 		if (message[0] == '+') {
  5781. 			message++;
  5782. 			action = 1;
  5783. 		}
  5784. 		else if (message[0] == '-') {
  5785. 			message++;
  5786. 			action = 2;
  5787. 		}
  5788. 		else if (!strcmp(message,"reset"))
  5789. 			action = 4;
  5790. 	}
  5791.  
  5792. 	if (action < 3) // add or remove
  5793. 	{
  5794. 		if ((item_data = itemdb_exists(atoi(message))) == NULL)
  5795. 			item_data = itemdb_searchname(message);
  5796. 		if (!item_data) {
  5797. 			// No items founds in the DB with Id or Name
  5798. 			clif_displaymessage(fd, "Item not found.");
  5799. 			return -1;
  5800. 		}
  5801. 	}
  5802.  
  5803. 	switch(action) {
  5804. 	case 1:
  5805. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5806. 		if (i != AUTOLOOTITEM_SIZE) {
  5807. 			clif_displaymessage(fd, "You're already autolooting this item.");
  5808. 			return -1;
  5809. 		}
  5810. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == 0);
  5811. 		if (i == AUTOLOOTITEM_SIZE) {
  5812. 			clif_displaymessage(fd, "Your autolootitem list is full. Remove some items first with @autolootid -<item name or ID>.");
  5813. 			return -1;
  5814. 		}
  5815. 		sd->state.autolootid[i] = item_data->nameid; // Autoloot Activated
  5816. 		sprintf(atcmd_output, "Autolooting item: '%s'/'%s' {%d}", item_data->name, item_data->jname, item_data->nameid);
  5817. 		clif_displaymessage(fd, atcmd_output);
  5818. 		sd->state.autolooting = 1;
  5819. 		break;
  5820. 	case 2:
  5821. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5822. 		if (i == AUTOLOOTITEM_SIZE) {
  5823. 			clif_displaymessage(fd, "You're currently not autolooting this item.");
  5824. 			return -1;
  5825. 		}
  5826. 		sd->state.autolootid[i] = 0;
  5827. 		sprintf(atcmd_output, "Removed item: '%s'/'%s' {%d} from your autolootitem list.", item_data->name, item_data->jname, item_data->nameid);
  5828. 		clif_displaymessage(fd, atcmd_output);
  5829. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5830. 		if (i == AUTOLOOTITEM_SIZE) {
  5831. 			sd->state.autolooting = 0;
  5832. 		}
  5833. 		break;
  5834. 	case 3:
  5835. 		sprintf(atcmd_output, "You can have %d items on your autolootitem list.", AUTOLOOTITEM_SIZE);
  5836. 		clif_displaymessage(fd, atcmd_output);
  5837. 		clif_displaymessage(fd, "To add item to the list, use \"@alootid +<item name or ID>\". To remove item use \"@alootid -<item name or ID>\".");
  5838. 		clif_displaymessage(fd, "\"@alootid reset\" will clear your autolootitem list.");
  5839. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5840. 		if (i == AUTOLOOTITEM_SIZE) {
  5841. 			clif_displaymessage(fd, "Your autolootitem list is empty.");
  5842. 		} else {
  5843. 			clif_displaymessage(fd, "Items on your autolootitem list:");
  5844. 			for(i = 0; i < AUTOLOOTITEM_SIZE; i++)
  5845. 			{
  5846. 				if (sd->state.autolootid[i] == 0)
  5847. 					continue;
  5848. 				if (!(item_data = itemdb_exists(sd->state.autolootid[i]))) {
  5849. 					ShowDebug("Non-existant item %d on autolootitem list (account_id: %d, char_id: %d)", sd->state.autolootid[i], sd->status.account_id, sd->status.char_id);
  5850. 					continue;
  5851. 				}
  5852. 				sprintf(atcmd_output, "'%s'/'%s' {%d}", item_data->name, item_data->jname, item_data->nameid);
  5853. 				clif_displaymessage(fd, atcmd_output);
  5854. 			}
  5855. 		}
  5856. 		break;
  5857. 	case 4:
  5858. 		memset(sd->state.autolootid, 0, sizeof(sd->state.autolootid));
  5859. 		clif_displaymessage(fd, "Your autolootitem list has been reset.");
  5860. 		sd->state.autolooting = 0;
  5861. 		break;
  5862. 	}
  5863. 	return 0;
  5864. }
  5865. /**
  5866.  * No longer available, keeping here just in case it's back someday. [Ind]
  5867.  **/
  5868. /*==========================================
  5869.  * It is made to rain.
  5870.  *------------------------------------------*/
  5871. //ACMD_FUNC(rain)
  5872. //{
  5873. //	nullpo_retr(-1, sd);
  5874. //	if (map[sd->bl.m].flag.rain) {
  5875. //		map[sd->bl.m].flag.rain=0;
  5876. //		clif_weather(sd->bl.m);
  5877. //		clif_displaymessage(fd, "The rain has stopped.");
  5878. //	} else {
  5879. //		map[sd->bl.m].flag.rain=1;
  5880. //		clif_weather(sd->bl.m);
  5881. //		clif_displaymessage(fd, "It is made to rain.");
  5882. //	}
  5883. //	return 0;
  5884. //}
  5885.  
  5886. /*==========================================
  5887.  * It is made to snow.
  5888.  *------------------------------------------*/
  5889. ACMD_FUNC(snow)
  5890. {
  5891. 	nullpo_retr(-1, sd);
  5892. 	if (map[sd->bl.m].flag.snow) {
  5893. 		map[sd->bl.m].flag.snow=0;
  5894. 		clif_weather(sd->bl.m);
  5895. 		clif_displaymessage(fd, "Snow has stopped falling.");
  5896. 	} else {
  5897. 		map[sd->bl.m].flag.snow=1;
  5898. 		clif_weather(sd->bl.m);
  5899. 		clif_displaymessage(fd, "It is made to snow.");
  5900. 	}
  5901.  
  5902. 	return 0;
  5903. }
  5904.  
  5905. /*==========================================
  5906.  * Cherry tree snowstorm is made to fall. (Sakura)
  5907.  *------------------------------------------*/
  5908. ACMD_FUNC(sakura)
  5909. {
  5910. 	nullpo_retr(-1, sd);
  5911. 	if (map[sd->bl.m].flag.sakura) {
  5912. 		map[sd->bl.m].flag.sakura=0;
  5913. 		clif_weather(sd->bl.m);
  5914. 		clif_displaymessage(fd, "Cherry tree leaves no longer fall.");
  5915. 	} else {
  5916. 		map[sd->bl.m].flag.sakura=1;
  5917. 		clif_weather(sd->bl.m);
  5918. 		clif_displaymessage(fd, "Cherry tree leaves is made to fall.");
  5919. 	}
  5920. 	return 0;
  5921. }
  5922.  
  5923. /*==========================================
  5924.  * Clouds appear.
  5925.  *------------------------------------------*/
  5926. ACMD_FUNC(clouds)
  5927. {
  5928. 	nullpo_retr(-1, sd);
  5929. 	if (map[sd->bl.m].flag.clouds) {
  5930. 		map[sd->bl.m].flag.clouds=0;
  5931. 		clif_weather(sd->bl.m);
  5932. 		clif_displaymessage(fd, "The clouds has disappear.");
  5933. 	} else {
  5934. 		map[sd->bl.m].flag.clouds=1;
  5935. 		clif_weather(sd->bl.m);
  5936. 		clif_displaymessage(fd, "Clouds appear.");
  5937. 	}
  5938.  
  5939. 	return 0;
  5940. }
  5941.  
  5942. /*==========================================
  5943.  * Different type of clouds using effect 516
  5944.  *------------------------------------------*/
  5945. ACMD_FUNC(clouds2)
  5946. {
  5947. 	nullpo_retr(-1, sd);
  5948. 	if (map[sd->bl.m].flag.clouds2) {
  5949. 		map[sd->bl.m].flag.clouds2=0;
  5950. 		clif_weather(sd->bl.m);
  5951. 		clif_displaymessage(fd, "The alternative clouds disappear.");
  5952. 	} else {
  5953. 		map[sd->bl.m].flag.clouds2=1;
  5954. 		clif_weather(sd->bl.m);
  5955. 		clif_displaymessage(fd, "Alternative clouds appear.");
  5956. 	}
  5957.  
  5958. 	return 0;
  5959. }
  5960.  
  5961. /*==========================================
  5962.  * Fog hangs over.
  5963.  *------------------------------------------*/
  5964. ACMD_FUNC(fog)
  5965. {
  5966. 	nullpo_retr(-1, sd);
  5967. 	if (map[sd->bl.m].flag.fog) {
  5968. 		map[sd->bl.m].flag.fog=0;
  5969. 		clif_weather(sd->bl.m);
  5970. 		clif_displaymessage(fd, "The fog has gone.");
  5971. 	} else {
  5972. 		map[sd->bl.m].flag.fog=1;
  5973. 		clif_weather(sd->bl.m);
  5974. 		clif_displaymessage(fd, "Fog hangs over.");
  5975. 	}
  5976. 		return 0;
  5977. }
  5978.  
  5979. /*==========================================
  5980.  * Fallen leaves fall.
  5981.  *------------------------------------------*/
  5982. ACMD_FUNC(leaves)
  5983. {
  5984. 	nullpo_retr(-1, sd);
  5985. 	if (map[sd->bl.m].flag.leaves) {
  5986. 		map[sd->bl.m].flag.leaves=0;
  5987. 		clif_weather(sd->bl.m);
  5988. 		clif_displaymessage(fd, "Leaves no longer fall.");
  5989. 	} else {
  5990. 		map[sd->bl.m].flag.leaves=1;
  5991. 		clif_weather(sd->bl.m);
  5992. 		clif_displaymessage(fd, "Fallen leaves fall.");
  5993. 	}
  5994.  
  5995. 	return 0;
  5996. }
  5997.  
  5998. /*==========================================
  5999.  * Fireworks appear.
  6000.  *------------------------------------------*/
  6001. ACMD_FUNC(fireworks)
  6002. {
  6003. 	nullpo_retr(-1, sd);
  6004. 	if (map[sd->bl.m].flag.fireworks) {
  6005. 		map[sd->bl.m].flag.fireworks=0;
  6006. 		clif_weather(sd->bl.m);
  6007. 		clif_displaymessage(fd, "Fireworks are ended.");
  6008. 	} else {
  6009. 		map[sd->bl.m].flag.fireworks=1;
  6010. 		clif_weather(sd->bl.m);
  6011. 		clif_displaymessage(fd, "Fireworks are launched.");
  6012. 	}
  6013.  
  6014. 	return 0;
  6015. }
  6016.  
  6017. /*==========================================
  6018.  * Clearing Weather Effects by Dexity
  6019.  *------------------------------------------*/
  6020. ACMD_FUNC(clearweather)
  6021. {
  6022. 	nullpo_retr(-1, sd);
  6023. 	/**
  6024. 	 * No longer available, keeping here just in case it's back someday. [Ind]
  6025. 	 **/
  6026. 	//map[sd->bl.m].flag.rain=0;
  6027. 	map[sd->bl.m].flag.snow=0;
  6028. 	map[sd->bl.m].flag.sakura=0;
  6029. 	map[sd->bl.m].flag.clouds=0;
  6030. 	map[sd->bl.m].flag.clouds2=0;
  6031. 	map[sd->bl.m].flag.fog=0;
  6032. 	map[sd->bl.m].flag.fireworks=0;
  6033. 	map[sd->bl.m].flag.leaves=0;
  6034. 	clif_weather(sd->bl.m);
  6035. 	clif_displaymessage(fd, msg_txt(291));
  6036.  
  6037. 	return 0;
  6038. }
  6039.  
  6040. /*===============================================================
  6041.  * Sound Command - plays a sound for everyone around! [Codemaster]
  6042.  *---------------------------------------------------------------*/
  6043. ACMD_FUNC(sound)
  6044. {
  6045. 	char sound_file[100];
  6046.  
  6047. 	memset(sound_file, '\0', sizeof(sound_file));
  6048.  
  6049. 		if(!message || !*message || sscanf(message, "%99[^\n]", sound_file) < 1) {
  6050. 		clif_displaymessage(fd, "Please, enter a sound filename. (usage: @sound <filename>)");
  6051. 		return -1;
  6052. 	}
  6053.  
  6054. 	if(strstr(sound_file, ".wav") == NULL)
  6055. 		strcat(sound_file, ".wav");
  6056.  
  6057. 	clif_soundeffectall(&sd->bl, sound_file, 0, AREA);
  6058.  
  6059. 	return 0;
  6060. }
  6061.  
  6062. /*==========================================
  6063.  * 	MOB Search
  6064.  *------------------------------------------*/
  6065. ACMD_FUNC(mobsearch)
  6066. {
  6067. 	char mob_name[100];
  6068. 	int mob_id;
  6069. 	int number = 0;
  6070. 	struct s_mapiterator* it;
  6071.  
  6072. 	nullpo_retr(-1, sd);
  6073.  
  6074. 	if (!message || !*message || sscanf(message, "%99[^\n]", mob_name) < 1) {
  6075. 		clif_displaymessage(fd, "Please, enter a monster name (usage: @mobsearch <monster name>).");
  6076. 		return -1;
  6077. 	}
  6078.  
  6079. 	if ((mob_id = atoi(mob_name)) == 0)
  6080. 		 mob_id = mobdb_searchname(mob_name);
  6081. 	if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  6082. 		snprintf(atcmd_output, sizeof atcmd_output, "Invalid mob id %s!",mob_name);
  6083. 		clif_displaymessage(fd, atcmd_output);
  6084. 		return -1;
  6085. 	}
  6086. 	if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  6087. 				strcpy(mob_name,mob_db(mob_id)->jname);	// --ja--
  6088. //				strcpy(mob_name,mob_db(mob_id)->name);	// --en--
  6089.  
  6090. 	snprintf(atcmd_output, sizeof atcmd_output, "Mob Search... %s %s", mob_name, mapindex_id2name(sd->mapindex));
  6091. 	clif_displaymessage(fd, atcmd_output);
  6092.  
  6093. 	it = mapit_geteachmob();
  6094. 	for(;;)
  6095. 	{
  6096. 		TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  6097. 		if( md == NULL )
  6098. 			break;// no more mobs
  6099.  
  6100. 		if( md->bl.m != sd->bl.m )
  6101. 			continue;
  6102. 		if( mob_id != -1 && md->class_ != mob_id )
  6103. 			continue;
  6104.  
  6105. 		++number;
  6106. 		if( md->spawn_timer == INVALID_TIMER )
  6107. 			snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%3d:%3d] %s", number, md->bl.x, md->bl.y, md->name);
  6108. 		else
  6109. 			snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name);
  6110. 		clif_displaymessage(fd, atcmd_output);
  6111. 	}
  6112. 	mapit_free(it);
  6113.  
  6114. 	return 0;
  6115. }
  6116.  
  6117. /*==========================================
  6118.  * @cleanmap - cleans items on the ground
  6119.  *------------------------------------------*/
  6120. static int atcommand_cleanmap_sub(struct block_list *bl, va_list ap)
  6121. {
  6122. 	nullpo_ret(bl);
  6123. 	map_clearflooritem(bl->id);
  6124.  
  6125. 	return 0;
  6126. }
  6127.  
  6128. ACMD_FUNC(cleanmap)
  6129. {
  6130. 	map_foreachinarea(atcommand_cleanmap_sub, sd->bl.m,
  6131. 		sd->bl.x-AREA_SIZE*2, sd->bl.y-AREA_SIZE*2,
  6132. 		sd->bl.x+AREA_SIZE*2, sd->bl.y+AREA_SIZE*2,
  6133. 		BL_ITEM);
  6134. 	clif_displaymessage(fd, "All dropped items have been cleaned up.");
  6135. 	return 0;
  6136. }
  6137.  
  6138. /*==========================================
  6139.  * make a NPC/PET talk
  6140.  * @npctalkc [SnakeDrak]
  6141.  *------------------------------------------*/
  6142. ACMD_FUNC(npctalk)
  6143. {
  6144. 	char name[NAME_LENGTH],mes[100],temp[100];
  6145. 	struct npc_data *nd;
  6146. 	bool ifcolor=(*(command + 8) != 'c' && *(command + 8) != 'C')?0:1;
  6147. 	unsigned long color=0;
  6148.  
  6149. 	if (sd->sc.count && //no "chatting" while muted.
  6150. 		(sd->sc.data[SC_BERSERK] ||
  6151. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6152. 		return -1;
  6153.  
  6154. 	if(!ifcolor) {
  6155. 		if (!message || !*message || sscanf(message, "%23[^,], %99[^\n]", name, mes) < 2) {
  6156. 			clif_displaymessage(fd, "Please, enter the correct info (usage: @npctalk <npc name>, <message>).");
  6157. 			return -1;
  6158. 		}
  6159. 	}
  6160. 	else {
  6161. 		if (!message || !*message || sscanf(message, "%lx %23[^,], %99[^\n]", &color, name, mes) < 3) {
  6162. 			clif_displaymessage(fd, "Please, enter the correct info (usage: @npctalkc <color> <npc name>, <message>).");
  6163. 			return -1;
  6164. 		}
  6165. 	}
  6166.  
  6167. 	if (!(nd = npc_name2id(name))) {
  6168. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist
  6169. 		return -1;
  6170. 	}
  6171.  
  6172. 	strtok(name, "#"); // discard extra name identifier if present
  6173. 	snprintf(temp, sizeof(temp), "%s : %s", name, mes);
  6174.  
  6175. 	if(ifcolor) clif_messagecolor(&nd->bl,color,temp);
  6176. 	else clif_message(&nd->bl, temp);
  6177.  
  6178. 	return 0;
  6179. }
  6180.  
  6181. ACMD_FUNC(pettalk)
  6182. {
  6183. 	char mes[100],temp[100];
  6184. 	struct pet_data *pd;
  6185.  
  6186. 	nullpo_retr(-1, sd);
  6187.  
  6188. 	if(!sd->status.pet_id || !(pd=sd->pd))
  6189. 	{
  6190. 		clif_displaymessage(fd, msg_txt(184));
  6191. 		return -1;
  6192. 	}
  6193.  
  6194. 	if (sd->sc.count && //no "chatting" while muted.
  6195. 		(sd->sc.data[SC_BERSERK] ||
  6196. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6197. 		return -1;
  6198.  
  6199. 	if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6200. 		clif_displaymessage(fd, "Please, enter a message (usage: @pettalk <message>");
  6201. 		return -1;
  6202. 	}
  6203.  
  6204. 	if (message[0] == '/')
  6205. 	{// pet emotion processing
  6206. 		const char* emo[] = {
  6207. 			"/!", "/?", "/ho", "/lv", "/swt", "/ic", "/an", "/ag", "/$", "/...",
  6208. 			"/scissors", "/rock", "/paper", "/korea", "/lv2", "/thx", "/wah", "/sry", "/heh", "/swt2",
  6209. 			"/hmm", "/no1", "/??", "/omg", "/O", "/X", "/hlp", "/go", "/sob", "/gg",
  6210. 			"/kis", "/kis2", "/pif", "/ok", "-?-", "/indonesia", "/bzz", "/rice", "/awsm", "/meh",
  6211. 			"/shy", "/pat", "/mp", "/slur", "/com", "/yawn", "/grat", "/hp", "/philippines", "/malaysia",
  6212. 			"/singapore", "/brazil", "/fsh", "/spin", "/sigh", "/dum", "/crwd", "/desp", "/dice", "-dice2",
  6213. 			"-dice3", "-dice4", "-dice5", "-dice6", "/india", "/love", "/russia", "-?-", "/mobile", "/mail",
  6214. 			"/chinese", "/antenna1", "/antenna2", "/antenna3", "/hum", "/abs", "/oops", "/spit", "/ene", "/panic",
  6215. 			"/whisp"
  6216. 		};
  6217. 		int i;
  6218. 		ARR_FIND( 0, ARRAYLENGTH(emo), i, stricmp(message, emo[i]) == 0 );
  6219. 		if( i == E_DICE1 ) i = rnd()%6 + E_DICE1; // randomize /dice
  6220. 		if( i < ARRAYLENGTH(emo) )
  6221. 		{
  6222. 			if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  6223. 					sd->emotionlasttime = time(NULL);
  6224. 					return 0;
  6225. 			}
  6226. 			sd->emotionlasttime = time(NULL);
  6227.  
  6228. 			clif_emotion(&pd->bl, i);
  6229. 			return 0;
  6230. 		}
  6231. 	}
  6232.  
  6233. 	snprintf(temp, sizeof temp ,"%s : %s", pd->pet.name, mes);
  6234. 	clif_message(&pd->bl, temp);
  6235.  
  6236. 	return 0;
  6237. }
  6238.  
  6239. /// @users - displays the number of players present on each map (and percentage)
  6240. /// #users displays on the target user instead of self
  6241. ACMD_FUNC(users)
  6242. {
  6243. 	char buf[CHAT_SIZE_MAX];
  6244. 	int i;
  6245. 	int users[MAX_MAPINDEX];
  6246. 	int users_all;
  6247. 	struct s_mapiterator* iter;
  6248.  
  6249. 	memset(users, 0, sizeof(users));
  6250. 	users_all = 0;
  6251.  
  6252. 	// count users on each map
  6253. 	iter = mapit_getallusers();
  6254. 	for(;;)
  6255. 	{
  6256. 		struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter);
  6257. 		if( sd2 == NULL )
  6258. 			break;// no more users
  6259.  
  6260. 		if( sd2->mapindex >= MAX_MAPINDEX )
  6261. 			continue;// invalid mapindex
  6262.  
  6263. 		if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex];
  6264. 		if( users_all < INT_MAX ) ++users_all;
  6265. 	}
  6266. 	mapit_free(iter);
  6267.  
  6268. 	// display results for each map
  6269. 	for( i = 0; i < MAX_MAPINDEX; ++i )
  6270. 	{
  6271. 		if( users[i] == 0 )
  6272. 			continue;// empty
  6273.  
  6274. 		safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
  6275. 		clif_displaymessage(sd->fd, buf);
  6276. 	}
  6277.  
  6278. 	// display overall count
  6279. 	safesnprintf(buf, sizeof(buf), "all: %d", users_all);
  6280. 	clif_displaymessage(sd->fd, buf);
  6281.  
  6282. 	return 0;
  6283. }
  6284.  
  6285. /*==========================================
  6286.  *
  6287.  *------------------------------------------*/
  6288. ACMD_FUNC(reset)
  6289. {
  6290. 	pc_resetstate(sd);
  6291. 	pc_resetskill(sd,1);
  6292. 	sprintf(atcmd_output, msg_txt(208), sd->status.name); // '%s' skill and stats points reseted!
  6293. 	clif_displaymessage(fd, atcmd_output);
  6294. 	return 0;
  6295. }
  6296.  
  6297. /*==========================================
  6298.  *
  6299.  *------------------------------------------*/
  6300. ACMD_FUNC(summon)
  6301. {
  6302. 	char name[NAME_LENGTH];
  6303. 	int mob_id = 0;
  6304. 	int duration = 0;
  6305. 	struct mob_data *md;
  6306. 	unsigned int tick=gettick();
  6307.  
  6308. 	nullpo_retr(-1, sd);
  6309.  
  6310. 	if (!message || !*message || sscanf(message, "%23s %d", name, &duration) < 1)
  6311. 	{
  6312. 		clif_displaymessage(fd, "Please, enter a monster name (usage: @summon <monster name> [duration]");
  6313. 		return -1;
  6314. 	}
  6315.  
  6316. 	if (duration < 1)
  6317. 		duration =1;
  6318. 	else if (duration > 60)
  6319. 		duration =60;
  6320.  
  6321. 	if ((mob_id = atoi(name)) == 0)
  6322. 		mob_id = mobdb_searchname(name);
  6323. 	if(mob_id == 0 || mobdb_checkid(mob_id) == 0)
  6324. 	{
  6325. 		clif_displaymessage(fd, msg_txt(40));	// Invalid monster ID or name.
  6326. 		return -1;
  6327. 	}
  6328.  
  6329. 	md = mob_once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "");
  6330.  
  6331. 	if(!md)
  6332. 		return -1;
  6333.  
  6334. 	md->master_id=sd->bl.id;
  6335. 	md->special_state.ai=1;
  6336. 	md->deletetimer=add_timer(tick+(duration*60000),mob_timer_delete,md->bl.id,0);
  6337. 	clif_specialeffect(&md->bl,344,AREA);
  6338. 	mob_spawn(md);
  6339. 	sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  6340. 	clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick);
  6341. 	clif_displaymessage(fd, msg_txt(39));	// All monster summoned!
  6342.  
  6343. 	return 0;
  6344. }
  6345.  
  6346. /*==========================================
  6347.  * @adjgroup
  6348.  * Temporarily move player to another group
  6349.  * Useful during beta testing to allow players to use GM commands for short periods of time
  6350.  *------------------------------------------*/
  6351. ACMD_FUNC(adjgroup)
  6352. {
  6353. 	int new_group = 0;
  6354. 	nullpo_retr(-1, sd);
  6355.  
  6356. 	if (!message || !*message || sscanf(message, "%d", &new_group) != 1) {
  6357. 		clif_displaymessage(fd, "Usage: @adjgroup <group_id>");
  6358. 		return -1;
  6359. 	}
  6360.  
  6361. 	if (!pc_group_exists(new_group)) {
  6362. 		clif_displaymessage(fd, "Specified group does not exists.");
  6363. 		return -1;
  6364. 	}
  6365.  
  6366. 	sd->group_id = new_group;
  6367. 	clif_displaymessage(fd, "Group changed successfully.");
  6368. 	clif_displaymessage(sd->fd, "Your group has changed.");
  6369. 	return 0;
  6370. }
  6371.  
  6372. /*==========================================
  6373.  * @trade by [MouseJstr]
  6374.  * Open a trade window with a remote player
  6375.  *------------------------------------------*/
  6376. ACMD_FUNC(trade)
  6377. {
  6378.     struct map_session_data *pl_sd = NULL;
  6379. 	nullpo_retr(-1, sd);
  6380.  
  6381. 	if (!message || !*message) {
  6382. 		clif_displaymessage(fd, "Please, enter a player name (usage: @trade <player>).");
  6383. 		return -1;
  6384. 	}
  6385.  
  6386. 	if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  6387. 	{
  6388. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6389. 		return -1;
  6390. 	}
  6391.  
  6392. 	trade_traderequest(sd, pl_sd);
  6393. 	return 0;
  6394. }
  6395.  
  6396. /*==========================================
  6397.  * @setbattleflag by [MouseJstr]
  6398.  * set a battle_config flag without having to reboot
  6399.  *------------------------------------------*/
  6400. ACMD_FUNC(setbattleflag)
  6401. {
  6402. 	char flag[128], value[128];
  6403. 	nullpo_retr(-1, sd);
  6404.  
  6405. 	if (!message || !*message || sscanf(message, "%127s %127s", flag, value) != 2) {
  6406.         	clif_displaymessage(fd, "Usage: @setbattleflag <flag> <value>.");
  6407.         	return -1;
  6408.     	}
  6409.  
  6410. 	if (battle_set_value(flag, value) == 0)
  6411. 	{
  6412. 		clif_displaymessage(fd, "unknown battle_config flag");
  6413. 		return -1;
  6414. 	}
  6415.  
  6416. 	clif_displaymessage(fd, "battle_config set as requested");
  6417.  
  6418. 	return 0;
  6419. }
  6420.  
  6421. /*==========================================
  6422.  * @unmute [Valaris]
  6423.  *------------------------------------------*/
  6424. ACMD_FUNC(unmute)
  6425. {
  6426. 	struct map_session_data *pl_sd = NULL;
  6427. 	nullpo_retr(-1, sd);
  6428.  
  6429. 	if (!message || !*message) {
  6430. 		clif_displaymessage(fd, "Please, enter a player name (usage: @unmute <player>).");
  6431. 		return -1;
  6432. 	}
  6433.  
  6434. 	if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  6435. 	{
  6436. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6437. 		return -1;
  6438. 	}
  6439.  
  6440. 	if(!pl_sd->sc.data[SC_NOCHAT]) {
  6441. 		clif_displaymessage(sd->fd,"Player is not muted");
  6442. 		return -1;
  6443. 	}
  6444.  
  6445. 	pl_sd->status.manner = 0;
  6446. 	status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  6447. 	clif_displaymessage(sd->fd,"Player unmuted");
  6448.  
  6449. 	return 0;
  6450. }
  6451.  
  6452. /*==========================================
  6453.  * @uptime by MC Cameri
  6454.  *------------------------------------------*/
  6455. ACMD_FUNC(uptime)
  6456. {
  6457. 	unsigned long seconds = 0, day = 24*60*60, hour = 60*60,
  6458. 		minute = 60, days = 0, hours = 0, minutes = 0;
  6459. 	nullpo_retr(-1, sd);
  6460.  
  6461. 	seconds = get_uptime();
  6462. 	days = seconds/day;
  6463. 	seconds -= (seconds/day>0)?(seconds/day)*day:0;
  6464. 	hours = seconds/hour;
  6465. 	seconds -= (seconds/hour>0)?(seconds/hour)*hour:0;
  6466. 	minutes = seconds/minute;
  6467. 	seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
  6468.  
  6469. 	snprintf(atcmd_output, sizeof(atcmd_output), msg_txt(245), days, hours, minutes, seconds);
  6470. 	clif_displaymessage(fd, atcmd_output);
  6471.  
  6472. 	return 0;
  6473. }
  6474.  
  6475. /*==========================================
  6476.  * @changesex <sex>
  6477.  * => Changes one's sex. Argument sex can be 0 or 1, m or f, male or female.
  6478.  *------------------------------------------*/
  6479. ACMD_FUNC(changesex)
  6480. {
  6481. 	int i;
  6482. 	nullpo_retr(-1, sd);
  6483. 	pc_resetskill(sd,4);
  6484. 	// to avoid any problem with equipment and invalid sex, equipment is unequiped.
  6485. 	for( i=0; i<EQI_MAX; i++ )
  6486. 		if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3);
  6487. 	chrif_changesex(sd);
  6488. 	return 0;
  6489. }
  6490.  
  6491. /*================================================
  6492.  * @mute - Mutes a player for a set amount of time
  6493.  *------------------------------------------------*/
  6494. ACMD_FUNC(mute)
  6495. {
  6496. 	struct map_session_data *pl_sd = NULL;
  6497. 	int manner;
  6498. 	nullpo_retr(-1, sd);
  6499.  
  6500. 	if (!message || !*message || sscanf(message, "%d %23[^\n]", &manner, atcmd_player_name) < 1) {
  6501. 		clif_displaymessage(fd, "Usage: @mute <time> <character name>.");
  6502. 		return -1;
  6503. 	}
  6504.  
  6505. 	if ( (pl_sd = map_nick2sd(atcmd_player_name)) == NULL )
  6506. 	{
  6507. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6508. 		return -1;
  6509. 	}
  6510.  
  6511. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  6512. 	{
  6513. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  6514. 		return -1;
  6515. 	}
  6516.  
  6517. 	clif_manner_message(sd, 0);
  6518. 	clif_manner_message(pl_sd, 5);
  6519.  
  6520. 	if( pl_sd->status.manner < manner ) {
  6521. 		pl_sd->status.manner -= manner;
  6522. 		sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
  6523. 	} else {
  6524. 		pl_sd->status.manner = 0;
  6525. 		status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  6526. 	}
  6527.  
  6528. 	clif_GM_silence(sd, pl_sd, (manner > 0 ? 1 : 0));
  6529.  
  6530. 	return 0;
  6531. }
  6532.  
  6533. /*==========================================
  6534.  * @refresh (like @jumpto <<yourself>>)
  6535.  *------------------------------------------*/
  6536. ACMD_FUNC(refresh)
  6537. {
  6538. 	nullpo_retr(-1, sd);
  6539. 	clif_refresh(sd);
  6540. 	return 0;
  6541. }
  6542.  
  6543. /*==========================================
  6544.  * @identify
  6545.  * => GM's magnifier.
  6546.  *------------------------------------------*/
  6547. ACMD_FUNC(identify)
  6548. {
  6549. 	int i,num;
  6550.  
  6551. 	nullpo_retr(-1, sd);
  6552.  
  6553. 	for(i=num=0;i<MAX_INVENTORY;i++){
  6554. 		if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  6555. 			num++;
  6556. 		}
  6557. 	}
  6558. 	if (num > 0) {
  6559. 		clif_item_identify_list(sd);
  6560. 	} else {
  6561. 		clif_displaymessage(fd,"There are no items to appraise.");
  6562. 	}
  6563. 	return 0;
  6564. }
  6565.  
  6566. /*==========================================
  6567.  * @gmotd (Global MOTD)
  6568.  * by davidsiaw :P
  6569.  *------------------------------------------*/
  6570. ACMD_FUNC(gmotd)
  6571. {
  6572. 	char buf[CHAT_SIZE_MAX];
  6573. 	size_t len;
  6574. 	FILE* fp;
  6575.  
  6576. 	if( ( fp = fopen(motd_txt, "r") ) != NULL )
  6577. 	{
  6578. 		while( fgets(buf, sizeof(buf), fp) )
  6579. 		{
  6580. 			if( buf[0] == '/' && buf[1] == '/' )
  6581. 			{
  6582. 				continue;
  6583. 			}
  6584.  
  6585. 			len = strlen(buf);
  6586.  
  6587. 			while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) )
  6588. 			{// strip trailing EOL characters
  6589. 				len--;
  6590. 			}
  6591.  
  6592. 			if( len )
  6593. 			{
  6594. 				buf[len] = 0;
  6595.  
  6596. 				intif_broadcast(buf, len+1, 0);
  6597. 			}
  6598. 		}
  6599. 		fclose(fp);
  6600. 	}
  6601. 	return 0;
  6602. }
  6603.  
  6604. ACMD_FUNC(misceffect)
  6605. {
  6606. 	int effect = 0;
  6607. 	nullpo_retr(-1, sd);
  6608. 	if (!message || !*message)
  6609. 		return -1;
  6610. 	if (sscanf(message, "%d", &effect) < 1)
  6611. 		return -1;
  6612. 	clif_misceffect(&sd->bl,effect);
  6613.  
  6614. 	return 0;
  6615. }
  6616.  
  6617. /*==========================================
  6618.  * MAIL SYSTEM
  6619.  *------------------------------------------*/
  6620. ACMD_FUNC(mail)
  6621. {
  6622. 	nullpo_ret(sd);
  6623. 	mail_openmail(sd);
  6624. 	return 0;
  6625. }
  6626.  
  6627. /*==========================================
  6628.  * Show Monster DB Info   v 1.0
  6629.  * originally by [Lupus]
  6630.  *------------------------------------------*/
  6631. ACMD_FUNC(mobinfo)
  6632. {
  6633. 	unsigned char msize[3][7] = {"Small", "Medium", "Large"};
  6634. 	unsigned char mrace[12][11] = {"Formless", "Undead", "Beast", "Plant", "Insect", "Fish", "Demon", "Demi-Human", "Angel", "Dragon", "Boss", "Non-Boss"};
  6635. 	unsigned char melement[10][8] = {"Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
  6636. 	char atcmd_output2[CHAT_SIZE_MAX];
  6637. 	struct item_data *item_data;
  6638. 	struct mob_db *mob, *mob_array[MAX_SEARCH];
  6639. 	int count;
  6640. 	int i, j, k;
  6641.  
  6642. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  6643. 	memset(atcmd_output2, '\0', sizeof(atcmd_output2));
  6644.  
  6645. 	if (!message || !*message) {
  6646. 		clif_displaymessage(fd, "Please, enter a Monster/ID (usage: @mobinfo <monster_name_or_monster_ID>).");
  6647. 		return -1;
  6648. 	}
  6649.  
  6650. 	// If monster identifier/name argument is a name
  6651. 	if ((i = mobdb_checkid(atoi(message))))
  6652. 	{
  6653. 		mob_array[0] = mob_db(i);
  6654. 		count = 1;
  6655. 	} else
  6656. 		count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  6657.  
  6658. 	if (!count) {
  6659. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  6660. 		return -1;
  6661. 	}
  6662.  
  6663. 	if (count > MAX_SEARCH) {
  6664. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count);
  6665. 		clif_displaymessage(fd, atcmd_output);
  6666. 		count = MAX_SEARCH;
  6667. 	}
  6668. 	for (k = 0; k < count; k++) {
  6669. 		mob = mob_array[k];
  6670.  
  6671. 		// stats
  6672. 		if (mob->mexp)
  6673. 			sprintf(atcmd_output, "MVP Monster: '%s'/'%s'/'%s' (%d)", mob->name, mob->jname, mob->sprite, mob->vd.class_);
  6674. 		else
  6675. 			sprintf(atcmd_output, "Monster: '%s'/'%s'/'%s' (%d)", mob->name, mob->jname, mob->sprite, mob->vd.class_);
  6676. 		clif_displaymessage(fd, atcmd_output);
  6677. 		sprintf(atcmd_output, " Lv:%d  HP:%d  Base EXP:%u  Job EXP:%u  HIT:%d  FLEE:%d", mob->lv, mob->status.max_hp, mob->base_exp, mob->job_exp,MOB_HIT(mob), MOB_FLEE(mob));
  6678. 		clif_displaymessage(fd, atcmd_output);
  6679. 		sprintf(atcmd_output, " DEF:%d  MDEF:%d  STR:%d  AGI:%d  VIT:%d  INT:%d  DEX:%d  LUK:%d",
  6680. 			mob->status.def, mob->status.mdef,mob->status.str, mob->status.agi,
  6681. 			mob->status.vit, mob->status.int_, mob->status.dex, mob->status.luk);
  6682. 		clif_displaymessage(fd, atcmd_output);
  6683.  
  6684. 		sprintf(atcmd_output, " ATK:%d~%d  Range:%d~%d~%d  Size:%s  Race: %s  Element: %s (Lv:%d)",
  6685. 			mob->status.rhw.atk, mob->status.rhw.atk2, mob->status.rhw.range,
  6686. 			mob->range2 , mob->range3, msize[mob->status.size],
  6687. 			mrace[mob->status.race], melement[mob->status.def_ele], mob->status.ele_lv);
  6688. 		clif_displaymessage(fd, atcmd_output);
  6689. 		// drops
  6690. 		clif_displaymessage(fd, " Drops:");
  6691. 		strcpy(atcmd_output, " ");
  6692. 		j = 0;
  6693. 		for (i = 0; i < MAX_MOB_DROP; i++) {
  6694. 			int droprate;
  6695. 			if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_exists(mob->dropitem[i].nameid)) == NULL)
  6696. 				continue;
  6697. 			droprate = mob->dropitem[i].p;
  6698. #ifdef RENEWAL_DROP
  6699. 			if( battle_config.atcommand_mobinfo_type )
  6700. 				droprate = droprate * party_renewal_drop_mod(sd->status.base_level - mob->lv) / 100;
  6701. #endif
  6702. 			if (item_data->slot)
  6703. 				sprintf(atcmd_output2, " - %s[%d]  %02.02f%%", item_data->jname, item_data->slot, (float)droprate / 100);
  6704. 			else
  6705. 				sprintf(atcmd_output2, " - %s  %02.02f%%", item_data->jname, (float)droprate / 100);
  6706. 			strcat(atcmd_output, atcmd_output2);
  6707. 			if (++j % 3 == 0) {
  6708. 				clif_displaymessage(fd, atcmd_output);
  6709. 				strcpy(atcmd_output, " ");
  6710. 			}
  6711. 		}
  6712. 		if (j == 0)
  6713. 			clif_displaymessage(fd, "This monster has no drops.");
  6714. 		else if (j % 3 != 0)
  6715. 			clif_displaymessage(fd, atcmd_output);
  6716. 		// mvp
  6717. 		if (mob->mexp) {
  6718. 			sprintf(atcmd_output, " MVP Bonus EXP:%u", mob->mexp);
  6719. 			clif_displaymessage(fd, atcmd_output);
  6720. 			strcpy(atcmd_output, " MVP Items:");
  6721. 			j = 0;
  6722. 			for (i = 0; i < MAX_MVP_DROP; i++) {
  6723. 				if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_exists(mob->mvpitem[i].nameid)) == NULL)
  6724. 					continue;
  6725. 				if (mob->mvpitem[i].p > 0) {
  6726. 					j++;
  6727. 					if (j == 1)
  6728. 						sprintf(atcmd_output2, " %s  %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  6729. 					else
  6730. 						sprintf(atcmd_output2, " - %s  %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  6731. 					strcat(atcmd_output, atcmd_output2);
  6732. 				}
  6733. 			}
  6734. 			if (j == 0)
  6735. 				clif_displaymessage(fd, "This monster has no MVP prizes.");
  6736. 			else
  6737. 				clif_displaymessage(fd, atcmd_output);
  6738. 		}
  6739. 	}
  6740. 	return 0;
  6741. }
  6742.  
  6743. /*=========================================
  6744. * @showmobs by KarLaeda
  6745. * => For 15 sec displays the mobs on minimap
  6746. *------------------------------------------*/
  6747. ACMD_FUNC(showmobs)
  6748. {
  6749. 	char mob_name[100];
  6750. 	int mob_id;
  6751. 	int number = 0;
  6752. 	struct s_mapiterator* it;
  6753.  
  6754. 	nullpo_retr(-1, sd);
  6755.  
  6756. 	if(sscanf(message, "%99[^\n]", mob_name) < 0)
  6757. 		return -1;
  6758.  
  6759. 	if((mob_id = atoi(mob_name)) == 0)
  6760. 		mob_id = mobdb_searchname(mob_name);
  6761. 	if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  6762. 		snprintf(atcmd_output, sizeof atcmd_output, "Invalid mob id %s!",mob_name);
  6763. 		clif_displaymessage(fd, atcmd_output);
  6764. 		return 0;
  6765. 	}
  6766. // Uncomment the following line to show mini-bosses & MVP.
  6767. //#define SHOW_MVP
  6768. #ifndef SHOW_MVP
  6769. 	if(mob_db(mob_id)->status.mode&MD_BOSS){
  6770. 		snprintf(atcmd_output, sizeof atcmd_output, "Can't show Boss mobs!");
  6771. 		clif_displaymessage(fd, atcmd_output);
  6772. 		return 0;
  6773. 	}
  6774. #endif
  6775. 	if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  6776. 		strcpy(mob_name,mob_db(mob_id)->jname);    // --ja--
  6777. 		//strcpy(mob_name,mob_db(mob_id)->name);    // --en--
  6778.  
  6779. 	snprintf(atcmd_output, sizeof atcmd_output, "Mob Search... %s %s",
  6780. 		mob_name, mapindex_id2name(sd->mapindex));
  6781. 	clif_displaymessage(fd, atcmd_output);
  6782.  
  6783. 	it = mapit_geteachmob();
  6784. 	for(;;)
  6785. 	{
  6786. 		TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  6787. 		if( md == NULL )
  6788. 			break;// no more mobs
  6789.  
  6790. 		if( md->bl.m != sd->bl.m )
  6791. 			continue;
  6792. 		if( mob_id != -1 && md->class_ != mob_id )
  6793. 			continue;
  6794. 		if( md->special_state.ai || md->master_id )
  6795. 			continue; // hide slaves and player summoned mobs
  6796. 		if( md->spawn_timer != INVALID_TIMER )
  6797. 			continue; // hide mobs waiting for respawn
  6798.  
  6799. 		++number;
  6800. 		clif_viewpoint(sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF);
  6801. 	}
  6802. 	mapit_free(it);
  6803.  
  6804. 	return 0;
  6805. }
  6806.  
  6807. /*==========================================
  6808.  * homunculus level up [orn]
  6809.  *------------------------------------------*/
  6810. ACMD_FUNC(homlevel)
  6811. {
  6812. 	TBL_HOM * hd;
  6813. 	int level = 0, i = 0;
  6814.  
  6815. 	nullpo_retr(-1, sd);
  6816.  
  6817. 	if ( !message || !*message || ( level = atoi(message) ) < 1 ) {
  6818. 		clif_displaymessage(fd, "Please, enter a level adjustment: (usage: @homlevel <# of levels to level up>.");
  6819. 		return -1;
  6820. 	}
  6821.  
  6822. 	if ( !merc_is_hom_active(sd->hd) ) {
  6823. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6824. 		return -1;
  6825. 	}
  6826.  
  6827. 	hd = sd->hd;
  6828.  
  6829. 	for (i = 1; i <= level && hd->exp_next; i++){
  6830. 		hd->homunculus.exp += hd->exp_next;
  6831. 		merc_hom_levelup(hd);
  6832. 	}
  6833. 	status_calc_homunculus(hd,0);
  6834. 	status_percent_heal(&hd->bl, 100, 100);
  6835. 	clif_specialeffect(&hd->bl,568,AREA);
  6836. 	return 0;
  6837. }
  6838.  
  6839. /*==========================================
  6840.  * homunculus evolution H [orn]
  6841.  *------------------------------------------*/
  6842. ACMD_FUNC(homevolution)
  6843. {
  6844. 	nullpo_retr(-1, sd);
  6845.  
  6846. 	if ( !merc_is_hom_active(sd->hd) ) {
  6847. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6848. 		return -1;
  6849. 	}
  6850.  
  6851. 	if ( !merc_hom_evolution(sd->hd) ) {
  6852. 		clif_displaymessage(fd, "Your homunculus doesn't evolve.");
  6853. 		return -1;
  6854. 	}
  6855. 	clif_homskillinfoblock(sd);
  6856. 	return 0;
  6857. }
  6858.  
  6859. /*==========================================
  6860.  * call choosen homunculus [orn]
  6861.  *------------------------------------------*/
  6862. ACMD_FUNC(makehomun)
  6863. {
  6864. 	int homunid;
  6865. 	nullpo_retr(-1, sd);
  6866.  
  6867. 	if ( sd->status.hom_id ) {
  6868. 		clif_displaymessage(fd, msg_txt(450));
  6869. 		return -1;
  6870. 	}
  6871.  
  6872. 	if (!message || !*message) {
  6873. 		clif_displaymessage(fd, "Please, enter a homunculus id: (usage: @makehomun <homunculus id>.");
  6874. 		return -1;
  6875. 	}
  6876.  
  6877. 	homunid = atoi(message);
  6878. 	if( homunid < HM_CLASS_BASE || homunid > HM_CLASS_BASE + MAX_HOMUNCULUS_CLASS - 1 )
  6879. 	{
  6880. 		clif_displaymessage(fd, "Invalid Homunculus id.");
  6881. 		return -1;
  6882. 	}
  6883.  
  6884. 	merc_create_homunculus_request(sd,homunid);
  6885. 	return 0;
  6886. }
  6887.  
  6888. /*==========================================
  6889.  * modify homunculus intimacy [orn]
  6890.  *------------------------------------------*/
  6891. ACMD_FUNC(homfriendly)
  6892. {
  6893. 	int friendly = 0;
  6894.  
  6895. 	nullpo_retr(-1, sd);
  6896.  
  6897. 	if ( !merc_is_hom_active(sd->hd) ) {
  6898. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6899. 		return -1;
  6900. 	}
  6901.  
  6902. 	if (!message || !*message) {
  6903. 		clif_displaymessage(fd, "Please, enter a friendly value: (usage: @homfriendly <friendly value[0-1000]>.");
  6904. 		return -1;
  6905. 	}
  6906.  
  6907. 	friendly = atoi(message);
  6908. 	friendly = cap_value(friendly, 0, 1000);
  6909.  
  6910. 	sd->hd->homunculus.intimacy = friendly * 100 ;
  6911. 	clif_send_homdata(sd,SP_INTIMATE,friendly);
  6912. 	return 0;
  6913. }
  6914.  
  6915. /*==========================================
  6916.  * modify homunculus hunger [orn]
  6917.  *------------------------------------------*/
  6918. ACMD_FUNC(homhungry)
  6919. {
  6920. 	int hungry = 0;
  6921.  
  6922. 	nullpo_retr(-1, sd);
  6923.  
  6924. 	if ( !merc_is_hom_active(sd->hd) ) {
  6925. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6926. 		return -1;
  6927. 	}
  6928.  
  6929. 	if (!message || !*message) {
  6930. 		clif_displaymessage(fd, "Please, enter a hunger value: (usage: @homhungry <hunger value[0-100]>.");
  6931. 		return -1;
  6932. 	}
  6933.  
  6934. 	hungry = atoi(message);
  6935. 	hungry = cap_value(hungry, 0, 100);
  6936.  
  6937. 	sd->hd->homunculus.hunger = hungry;
  6938. 	clif_send_homdata(sd,SP_HUNGRY,hungry);
  6939. 	return 0;
  6940. }
  6941.  
  6942. /*==========================================
  6943.  * make the homunculus speak [orn]
  6944.  *------------------------------------------*/
  6945. ACMD_FUNC(homtalk)
  6946. {
  6947. 	char mes[100],temp[100];
  6948.  
  6949. 	nullpo_retr(-1, sd);
  6950.  
  6951. 	if (sd->sc.count && //no "chatting" while muted.
  6952. 		(sd->sc.data[SC_BERSERK] ||
  6953. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6954. 		return -1;
  6955.  
  6956. 	if ( !merc_is_hom_active(sd->hd) ) {
  6957. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6958. 		return -1;
  6959. 	}
  6960.  
  6961. 	if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6962. 		clif_displaymessage(fd, "Please, enter a message (usage: @homtalk <message>");
  6963. 		return -1;
  6964. 	}
  6965.  
  6966. 	snprintf(temp, sizeof temp ,"%s : %s", sd->hd->homunculus.name, mes);
  6967. 	clif_message(&sd->hd->bl, temp);
  6968.  
  6969. 	return 0;
  6970. }
  6971.  
  6972. /*==========================================
  6973.  * Show homunculus stats
  6974.  *------------------------------------------*/
  6975. ACMD_FUNC(hominfo)
  6976. {
  6977. 	struct homun_data *hd;
  6978. 	struct status_data *status;
  6979. 	nullpo_retr(-1, sd);
  6980.  
  6981. 	if ( !merc_is_hom_active(sd->hd) ) {
  6982. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6983. 		return -1;
  6984. 	}
  6985.  
  6986. 	hd = sd->hd;
  6987. 	status = status_get_status_data(&hd->bl);
  6988. 	clif_displaymessage(fd, "Homunculus stats :");
  6989.  
  6990. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"HP : %d/%d - SP : %d/%d",
  6991. 		status->hp, status->max_hp, status->sp, status->max_sp);
  6992. 	clif_displaymessage(fd, atcmd_output);
  6993.  
  6994. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"ATK : %d - MATK : %d~%d",
  6995. 		status->rhw.atk2 +status->batk, status->matk_min, status->matk_max);
  6996. 	clif_displaymessage(fd, atcmd_output);
  6997.  
  6998. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Hungry : %d - Intimacy : %u",
  6999. 		hd->homunculus.hunger, hd->homunculus.intimacy/100);
  7000. 	clif_displaymessage(fd, atcmd_output);
  7001.  
  7002. 	snprintf(atcmd_output, sizeof(atcmd_output) ,
  7003. 		"Stats: Str %d / Agi %d / Vit %d / Int %d / Dex %d / Luk %d",
  7004. 		status->str, status->agi, status->vit,
  7005. 		status->int_, status->dex, status->luk);
  7006. 	clif_displaymessage(fd, atcmd_output);
  7007.  
  7008. 	return 0;
  7009. }
  7010.  
  7011. ACMD_FUNC(homstats)
  7012. {
  7013. 	struct homun_data *hd;
  7014. 	struct s_homunculus_db *db;
  7015. 	struct s_homunculus *hom;
  7016. 	int lv, min, max, evo;
  7017.  
  7018. 	nullpo_retr(-1, sd);
  7019.  
  7020. 	if ( !merc_is_hom_active(sd->hd) ) {
  7021. 		clif_displaymessage(fd, "You do not have a homunculus.");
  7022. 		return -1;
  7023. 	}
  7024.  
  7025. 	hd = sd->hd;
  7026.  
  7027. 	hom = &hd->homunculus;
  7028. 	db = hd->homunculusDB;
  7029. 	lv = hom->level;
  7030.  
  7031. 	snprintf(atcmd_output, sizeof(atcmd_output) ,
  7032. 		"Homunculus growth stats (Lv %d %s):", lv, db->name);
  7033. 	clif_displaymessage(fd, atcmd_output);
  7034. 	lv--; //Since the first increase is at level 2.
  7035.  
  7036. 	evo = (hom->class_ == db->evo_class);
  7037. 	min = db->base.HP +lv*db->gmin.HP +(evo?db->emin.HP:0);
  7038. 	max = db->base.HP +lv*db->gmax.HP +(evo?db->emax.HP:0);;
  7039. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Max HP: %d (%d~%d)", hom->max_hp, min, max);
  7040. 	clif_displaymessage(fd, atcmd_output);
  7041.  
  7042. 	min = db->base.SP +lv*db->gmin.SP +(evo?db->emin.SP:0);
  7043. 	max = db->base.SP +lv*db->gmax.SP +(evo?db->emax.SP:0);;
  7044. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Max SP: %d (%d~%d)", hom->max_sp, min, max);
  7045. 	clif_displaymessage(fd, atcmd_output);
  7046.  
  7047. 	min = db->base.str +lv*(db->gmin.str/10) +(evo?db->emin.str:0);
  7048. 	max = db->base.str +lv*(db->gmax.str/10) +(evo?db->emax.str:0);;
  7049. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Str: %d (%d~%d)", hom->str/10, min, max);
  7050. 	clif_displaymessage(fd, atcmd_output);
  7051.  
  7052. 	min = db->base.agi +lv*(db->gmin.agi/10) +(evo?db->emin.agi:0);
  7053. 	max = db->base.agi +lv*(db->gmax.agi/10) +(evo?db->emax.agi:0);;
  7054. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Agi: %d (%d~%d)", hom->agi/10, min, max);
  7055. 	clif_displaymessage(fd, atcmd_output);
  7056.  
  7057. 	min = db->base.vit +lv*(db->gmin.vit/10) +(evo?db->emin.vit:0);
  7058. 	max = db->base.vit +lv*(db->gmax.vit/10) +(evo?db->emax.vit:0);;
  7059. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Vit: %d (%d~%d)", hom->vit/10, min, max);
  7060. 	clif_displaymessage(fd, atcmd_output);
  7061.  
  7062. 	min = db->base.int_ +lv*(db->gmin.int_/10) +(evo?db->emin.int_:0);
  7063. 	max = db->base.int_ +lv*(db->gmax.int_/10) +(evo?db->emax.int_:0);;
  7064. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Int: %d (%d~%d)", hom->int_/10, min, max);
  7065. 	clif_displaymessage(fd, atcmd_output);
  7066.  
  7067. 	min = db->base.dex +lv*(db->gmin.dex/10) +(evo?db->emin.dex:0);
  7068. 	max = db->base.dex +lv*(db->gmax.dex/10) +(evo?db->emax.dex:0);;
  7069. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Dex: %d (%d~%d)", hom->dex/10, min, max);
  7070. 	clif_displaymessage(fd, atcmd_output);
  7071.  
  7072. 	min = db->base.luk +lv*(db->gmin.luk/10) +(evo?db->emin.luk:0);
  7073. 	max = db->base.luk +lv*(db->gmax.luk/10) +(evo?db->emax.luk:0);;
  7074. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Luk: %d (%d~%d)", hom->luk/10, min, max);
  7075. 	clif_displaymessage(fd, atcmd_output);
  7076.  
  7077. 	return 0;
  7078. }
  7079.  
  7080. ACMD_FUNC(homshuffle)
  7081. {
  7082. 	nullpo_retr(-1, sd);
  7083.  
  7084. 	if(!sd->hd)
  7085. 		return -1; // nothing to do
  7086.  
  7087. 	if(!merc_hom_shuffle(sd->hd))
  7088. 		return -1;
  7089.  
  7090. 	clif_displaymessage(sd->fd, "[Homunculus Stats Altered]");
  7091. 	atcommand_homstats(fd, sd, command, message); //Print out the new stats
  7092. 	return 0;
  7093. }
  7094.  
  7095. /*==========================================
  7096.  * Show Items DB Info   v 1.0
  7097.  * originally by [Lupus]
  7098.  *------------------------------------------*/
  7099. ACMD_FUNC(iteminfo)
  7100. {
  7101. 	struct item_data *item_data, *item_array[MAX_SEARCH];
  7102. 	int i, count = 1;
  7103.  
  7104. 	if (!message || !*message) {
  7105. 		clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @ii/@iteminfo <item name or ID>).");
  7106. 		return -1;
  7107. 	}
  7108. 	if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  7109. 		count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  7110.  
  7111. 	if (!count) {
  7112. 		clif_displaymessage(fd, msg_txt(19));	// Invalid item ID or name.
  7113. 		return -1;
  7114. 	}
  7115.  
  7116. 	if (count > MAX_SEARCH) {
  7117. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  7118. 		clif_displaymessage(fd, atcmd_output);
  7119. 		count = MAX_SEARCH;
  7120. 	}
  7121. 	for (i = 0; i < count; i++) {
  7122. 		item_data = item_array[i];
  7123. 		sprintf(atcmd_output, "Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s",
  7124. 			item_data->name,item_data->jname,item_data->slot,item_data->nameid,
  7125. 			itemdb_typename(item_data->type), 
  7126. 			(item_data->script==NULL)? "None" : "With script"
  7127. 		);
  7128. 		clif_displaymessage(fd, atcmd_output);
  7129.  
  7130. 		sprintf(atcmd_output, "NPC Buy:%dz, Sell:%dz | Weight: %.1f ", item_data->value_buy, item_data->value_sell, item_data->weight/10. );
  7131. 		clif_displaymessage(fd, atcmd_output);
  7132.  
  7133. 		if (item_data->maxchance == -1)
  7134. 			strcpy(atcmd_output, " - Available in the shops only.");
  7135. 		else if (!battle_config.atcommand_mobinfo_type && item_data->maxchance)
  7136. 			sprintf(atcmd_output, " - Maximal monsters drop chance: %02.02f%%", (float)item_data->maxchance / 100 );
  7137. 		else
  7138. 			strcpy(atcmd_output, " - Monsters don't drop this item.");
  7139. 		clif_displaymessage(fd, atcmd_output);
  7140.  
  7141. 	}
  7142. 	return 0;
  7143. }
  7144.  
  7145. /*==========================================
  7146.  * Show who drops the item.
  7147.  *------------------------------------------*/
  7148. ACMD_FUNC(whodrops)
  7149. {
  7150. 	struct item_data *item_data, *item_array[MAX_SEARCH];
  7151. 	int i,j, count = 1;
  7152.  
  7153. 	if (!message || !*message) {
  7154. 		clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @whodrops <item name or ID>).");
  7155. 		return -1;
  7156. 	}
  7157. 	if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  7158. 		count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  7159.  
  7160. 	if (!count) {
  7161. 		clif_displaymessage(fd, msg_txt(19));	// Invalid item ID or name.
  7162. 		return -1;
  7163. 	}
  7164.  
  7165. 	if (count > MAX_SEARCH) {
  7166. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  7167. 		clif_displaymessage(fd, atcmd_output);
  7168. 		count = MAX_SEARCH;
  7169. 	}
  7170. 	for (i = 0; i < count; i++) {
  7171. 		item_data = item_array[i];
  7172. 		sprintf(atcmd_output, "Item: '%s'[%d]", item_data->jname,item_data->slot);
  7173. 		clif_displaymessage(fd, atcmd_output);
  7174.  
  7175. 		if (item_data->mob[0].chance == 0) {
  7176. 			strcpy(atcmd_output, " - Item is not dropped by mobs.");
  7177. 			clif_displaymessage(fd, atcmd_output);
  7178. 		} else {
  7179. 			sprintf(atcmd_output, "- Common mobs with highest drop chance (only max %d are listed):", MAX_SEARCH);
  7180. 			clif_displaymessage(fd, atcmd_output);
  7181.  
  7182. 			for (j=0; j < MAX_SEARCH && item_data->mob[j].chance > 0; j++)
  7183. 			{
  7184. 				sprintf(atcmd_output, "- %s (%02.02f%%)", mob_db(item_data->mob[j].id)->jname, item_data->mob[j].chance/100.);
  7185. 				clif_displaymessage(fd, atcmd_output);
  7186. 			}
  7187. 		}
  7188. 	}
  7189. 	return 0;
  7190. }
  7191.  
  7192. ACMD_FUNC(whereis)
  7193. {
  7194. 	struct mob_db *mob, *mob_array[MAX_SEARCH];
  7195. 	int count;
  7196. 	int i, j, k;
  7197.  
  7198. 	if (!message || !*message) {
  7199. 		clif_displaymessage(fd, "Please, enter a Monster/ID (usage: @whereis<monster_name_or_monster_ID>).");
  7200. 		return -1;
  7201. 	}
  7202.  
  7203. 	// If monster identifier/name argument is a name
  7204. 	if ((i = mobdb_checkid(atoi(message))))
  7205. 	{
  7206. 		mob_array[0] = mob_db(i);
  7207. 		count = 1;
  7208. 	} else
  7209. 		count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  7210.  
  7211. 	if (!count) {
  7212. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  7213. 		return -1;
  7214. 	}
  7215.  
  7216. 	if (count > MAX_SEARCH) {
  7217. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count);
  7218. 		clif_displaymessage(fd, atcmd_output);
  7219. 		count = MAX_SEARCH;
  7220. 	}
  7221. 	for (k = 0; k < count; k++) {
  7222. 		mob = mob_array[k];
  7223. 		snprintf(atcmd_output, sizeof atcmd_output, "%s spawns in:", mob->jname);
  7224. 		clif_displaymessage(fd, atcmd_output);
  7225.  
  7226. 		for (i = 0; i < ARRAYLENGTH(mob->spawn) && mob->spawn[i].qty; i++)
  7227. 		{
  7228. 			j = map_mapindex2mapid(mob->spawn[i].mapindex);
  7229. 			if (j < 0) continue;
  7230. 			snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map[j].name, mob->spawn[i].qty);
  7231. 			clif_displaymessage(fd, atcmd_output);
  7232. 		}
  7233. 		if (i == 0)
  7234. 			clif_displaymessage(fd, "This monster does not spawn normally.");
  7235. 	}
  7236.  
  7237. 	return 0;
  7238. }
  7239.  
  7240. /*==========================================
  7241.  * @adopt by [Veider]
  7242.  * adopt a novice
  7243.  *------------------------------------------*/
  7244. ACMD_FUNC(adopt)
  7245. {
  7246. 	struct map_session_data *pl_sd1, *pl_sd2, *pl_sd3;
  7247. 	char player1[NAME_LENGTH], player2[NAME_LENGTH], player3[NAME_LENGTH];
  7248. 	char output[CHAT_SIZE_MAX];
  7249.  
  7250. 	nullpo_retr(-1, sd);
  7251.  
  7252. 	if (!message || !*message || sscanf(message, "%23[^,],%23[^,],%23[^\r\n]", player1, player2, player3) < 3) {
  7253. 		clif_displaymessage(fd, "usage: @adopt <father>,<mother>,<child>.");
  7254. 		return -1;
  7255. 	}
  7256.  
  7257. 	if (battle_config.etc_log)
  7258. 		ShowInfo("Adopting: --%s--%s--%s--\n",player1,player2,player3);
  7259.  
  7260. 	if((pl_sd1=map_nick2sd((char *) player1)) == NULL) {
  7261. 		sprintf(output, "Cannot find player %s online", player1);
  7262. 		clif_displaymessage(fd, output);
  7263. 		return -1;
  7264. 	}
  7265.  
  7266. 	if((pl_sd2=map_nick2sd((char *) player2)) == NULL) {
  7267. 		sprintf(output, "Cannot find player %s online", player2);
  7268. 		clif_displaymessage(fd, output);
  7269. 		return -1;
  7270. 	}
  7271.  
  7272. 	if((pl_sd3=map_nick2sd((char *) player3)) == NULL) {
  7273. 		sprintf(output, "Cannot find player %s online", player3);
  7274. 		clif_displaymessage(fd, output);
  7275. 		return -1;
  7276. 	}
  7277.  
  7278. 	if( !pc_adoption(pl_sd1, pl_sd2, pl_sd3) ) {
  7279. 		return -1;
  7280. 	}
  7281.  
  7282. 	clif_displaymessage(fd, "They are family... wish them luck");
  7283. 	return 0;
  7284. }
  7285.  
  7286. ACMD_FUNC(version)
  7287. {
  7288. 	const char * revision;
  7289.  
  7290. 	if ((revision = get_svn_revision()) != 0) {
  7291. 		sprintf(atcmd_output,"rAthena Version SVN r%s",revision);
  7292. 		clif_displaymessage(fd,atcmd_output);
  7293. 	} else 
  7294. 		clif_displaymessage(fd,"Cannot determine SVN revision");
  7295.  
  7296. 	return 0;
  7297. }
  7298.  
  7299. /*==========================================
  7300.  * @mutearea by MouseJstr
  7301.  *------------------------------------------*/
  7302. static int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
  7303. {
  7304.  
  7305. 	int time, id;
  7306. 	struct map_session_data *pl_sd = (struct map_session_data *)bl;
  7307. 	if (pl_sd == NULL)
  7308. 		return 0;
  7309.  
  7310. 	id = va_arg(ap, int);
  7311. 	time = va_arg(ap, int);
  7312.  
  7313. 	if (id != bl->id && !pc_get_group_level(pl_sd)) {
  7314. 		pl_sd->status.manner -= time;
  7315. 		if (pl_sd->status.manner < 0)
  7316. 			sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
  7317. 		else
  7318. 			status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  7319. 	}
  7320. 	return 0;
  7321. }
  7322.  
  7323. ACMD_FUNC(mutearea)
  7324. {
  7325. 	int time;
  7326. 	nullpo_ret(sd);
  7327.  
  7328. 	if (!message || !*message) {
  7329. 		clif_displaymessage(fd, "Please, enter a time in minutes (usage: @mutearea/@stfu <time in minutes>.");
  7330. 		return -1;
  7331. 	}
  7332.  
  7333. 	time = atoi(message);
  7334.  
  7335. 	map_foreachinarea(atcommand_mutearea_sub,sd->bl.m, 
  7336. 		sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, 
  7337. 		sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd->bl.id, time);
  7338.  
  7339. 	return 0;
  7340. }
  7341.  
  7342.  
  7343. ACMD_FUNC(rates)
  7344. {
  7345. 	char buf[CHAT_SIZE_MAX];
  7346.  
  7347. 	nullpo_ret(sd);
  7348. 	memset(buf, '\0', sizeof(buf));
  7349.  
  7350. 	snprintf(buf, CHAT_SIZE_MAX, "Experience rates: Base %.2fx / Job %.2fx",
  7351. 		battle_config.base_exp_rate/100., battle_config.job_exp_rate/100.);
  7352. 	clif_displaymessage(fd, buf);
  7353. 	snprintf(buf, CHAT_SIZE_MAX, "Normal Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx",
  7354. 		battle_config.item_rate_common/100., battle_config.item_rate_heal/100., battle_config.item_rate_use/100., battle_config.item_rate_equip/100., battle_config.item_rate_card/100.);
  7355. 	clif_displaymessage(fd, buf);
  7356. 	snprintf(buf, CHAT_SIZE_MAX, "Boss Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx",
  7357. 		battle_config.item_rate_common_boss/100., battle_config.item_rate_heal_boss/100., battle_config.item_rate_use_boss/100., battle_config.item_rate_equip_boss/100., battle_config.item_rate_card_boss/100.);
  7358. 	clif_displaymessage(fd, buf);
  7359. 	snprintf(buf, CHAT_SIZE_MAX, "Other Drop Rates: MvP %.2fx / Card-Based %.2fx / Treasure %.2fx",
  7360. 		battle_config.item_rate_mvp/100., battle_config.item_rate_adddrop/100., battle_config.item_rate_treasure/100.);
  7361. 	clif_displaymessage(fd, buf);
  7362.  
  7363. 	return 0;
  7364. }
  7365.  
  7366. /*==========================================
  7367.  * @me by lordalfa
  7368.  * => Displays the OUTPUT string on top of the Visible players Heads.
  7369.  *------------------------------------------*/
  7370. ACMD_FUNC(me)
  7371. {
  7372. 	char tempmes[CHAT_SIZE_MAX];
  7373. 	nullpo_retr(-1, sd);
  7374.  
  7375. 	memset(tempmes, '\0', sizeof(tempmes));
  7376. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  7377.  
  7378. 	if (sd->sc.count && //no "chatting" while muted.
  7379. 		(sd->sc.data[SC_BERSERK] ||
  7380. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  7381. 		return -1;
  7382.  
  7383. 	if (!message || !*message || sscanf(message, "%199[^\n]", tempmes) < 0) {
  7384. 		clif_displaymessage(fd, "Please, enter a message (usage: @me <message>).");
  7385. 		return -1;
  7386. 	}
  7387.  
  7388. 	sprintf(atcmd_output, msg_txt(270), sd->status.name, tempmes);	// *%s %s*
  7389. 	clif_disp_overhead(sd, atcmd_output);
  7390.  
  7391. 	return 0;
  7392.  
  7393. }
  7394.  
  7395. /*==========================================
  7396.  * @size
  7397.  * => Resize your character sprite. [Valaris]
  7398.  *------------------------------------------*/
  7399. ACMD_FUNC(size)
  7400. {
  7401. 	int size=0;
  7402.  
  7403. 	nullpo_retr(-1, sd);
  7404.  
  7405. 	size = atoi(message);
  7406. 	if(sd->state.size) {
  7407. 		sd->state.size=0;
  7408. 		pc_setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_TELEPORT);
  7409. 	}
  7410.  
  7411. 	if(size==1) {
  7412. 		sd->state.size=1;
  7413. 		clif_specialeffect(&sd->bl,420,AREA);
  7414. 	} else if(size==2) {
  7415. 		sd->state.size=2;
  7416. 		clif_specialeffect(&sd->bl,422,AREA);
  7417. 	}
  7418.  
  7419. 	return 0;
  7420. }
  7421.  
  7422. /*==========================================
  7423.  * @monsterignore
  7424.  * => Makes monsters ignore you. [Valaris]
  7425.  *------------------------------------------*/
  7426. ACMD_FUNC(monsterignore)
  7427. {
  7428. 	nullpo_retr(-1, sd);
  7429.  
  7430. 	if (!sd->state.monster_ignore) {
  7431. 		sd->state.monster_ignore = 1;
  7432. 		clif_displaymessage(sd->fd, "You are now immune to attacks.");
  7433. 	} else {
  7434. 		sd->state.monster_ignore = 0;
  7435. 		clif_displaymessage(sd->fd, "Returned to normal state.");
  7436. 	}
  7437.  
  7438. 	return 0;
  7439. }
  7440. /*==========================================
  7441.  * @fakename
  7442.  * => Gives your character a fake name. [Valaris]
  7443.  *------------------------------------------*/
  7444. ACMD_FUNC(fakename)
  7445. {
  7446. 	nullpo_retr(-1, sd);
  7447.  
  7448. 	if( !message || !*message )
  7449. 	{
  7450. 		if( sd->fakename[0] )
  7451. 		{
  7452. 			sd->fakename[0] = '\0';
  7453. 			clif_charnameack(0, &sd->bl);
  7454. 			clif_displaymessage(sd->fd, "Returned to real name.");
  7455. 			return 0;
  7456. 		}
  7457.  
  7458. 		clif_displaymessage(sd->fd, "You must enter a name.");
  7459. 		return -1;
  7460. 	}
  7461.  
  7462. 	if( strlen(message) < 2 )
  7463. 	{
  7464. 		clif_displaymessage(sd->fd, "Fake name must be at least two characters.");
  7465. 		return -1;
  7466. 	}
  7467.  
  7468. 	safestrncpy(sd->fakename, message, sizeof(sd->fakename));
  7469. 	clif_charnameack(0, &sd->bl);
  7470. 	clif_displaymessage(sd->fd, "Fake name enabled.");
  7471.  
  7472. 	return 0;
  7473. }
  7474.  
  7475. /*==========================================
  7476.  * Ragnarok Resources
  7477.  *------------------------------------------*/
  7478. ACMD_FUNC(mapflag) {
  7479. #define checkflag( cmd ) if ( map[ sd->bl.m ].flag.cmd ) clif_displaymessage(sd->fd,#cmd)
  7480. #define setflag( cmd ) \
  7481. 	if ( strcmp( flag_name , #cmd ) == 0 && ( flag == 0 || flag == 1 ) ){\
  7482. 		map[ sd->bl.m ].flag.cmd = flag;\
  7483. 		sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s",#cmd,flag?"On":"Off");\
  7484. 		clif_displaymessage(sd->fd,atcmd_output);\
  7485. 		return 0;\
  7486. 	}
  7487. 	unsigned char flag_name[100];
  7488. 	int flag=9,i;
  7489. 	nullpo_retr(-1, sd);
  7490. 	memset(flag_name, '\0', sizeof(flag_name));
  7491.  
  7492. 	if (!message || !*message || (sscanf(message, "%99s %d", flag_name, &flag) < 1)) {
  7493. 		clif_displaymessage(sd->fd,"Enabled Mapflags in this map:");
  7494. 		clif_displaymessage(sd->fd,"----------------------------------");
  7495. 		checkflag(autotrade);			checkflag(allowks);				checkflag(nomemo);		checkflag(noteleport);
  7496. 		checkflag(noreturn);			checkflag(monster_noteleport);	checkflag(nosave);		checkflag(nobranch);
  7497. 		checkflag(noexppenalty);		checkflag(pvp);					checkflag(pvp_noparty);	checkflag(pvp_noguild);
  7498. 		checkflag(pvp_nightmaredrop);	checkflag(pvp_nocalcrank);		checkflag(gvg_castle);	checkflag(gvg);
  7499. 		checkflag(gvg_dungeon);			checkflag(gvg_noparty);			checkflag(battleground);checkflag(nozenypenalty);
  7500. 		checkflag(notrade);				checkflag(noskill);				checkflag(nowarp);		checkflag(nowarpto);
  7501. 		checkflag(noicewall);			checkflag(snow);				checkflag(clouds);		checkflag(clouds2);
  7502. 		checkflag(fog);					checkflag(fireworks);			checkflag(sakura);		checkflag(leaves);
  7503. 		checkflag(nogo);				checkflag(nobaseexp);
  7504. 		checkflag(nojobexp);			checkflag(nomobloot);			checkflag(nomvploot);	checkflag(nightenabled);
  7505. 		checkflag(restricted);			checkflag(nodrop);				checkflag(novending);	checkflag(loadevent);
  7506. 		checkflag(nochat);				checkflag(partylock);			checkflag(guildlock);	checkflag(src4instance);
  7507. 		clif_displaymessage(sd->fd," ");
  7508. 		clif_displaymessage(sd->fd,"Usage: \"@mapflag monster_teleport 1\" (0=Off 1=On)");
  7509. 		clif_displaymessage(sd->fd,"Use: \"@mapflag available\" to list the available mapflags");
  7510. 		return 1;
  7511. 	}
  7512. 	for (i = 0; flag_name[i]; i++) flag_name[i] = tolower(flag_name[i]); //lowercase
  7513.  
  7514. 	setflag(autotrade);			setflag(allowks);			setflag(nomemo);			setflag(noteleport);
  7515. 	setflag(noreturn);			setflag(monster_noteleport);setflag(nosave);			setflag(nobranch);
  7516. 	setflag(noexppenalty);		setflag(pvp);				setflag(pvp_noparty);		setflag(pvp_noguild);
  7517. 	setflag(pvp_nightmaredrop);	setflag(pvp_nocalcrank);	setflag(gvg_castle);		setflag(gvg);
  7518. 	setflag(gvg_dungeon);		setflag(gvg_noparty);		setflag(battleground);		setflag(nozenypenalty);
  7519. 	setflag(notrade);			setflag(noskill);			setflag(nowarp);			setflag(nowarpto);
  7520. 	setflag(noicewall);			setflag(snow);				setflag(clouds);			setflag(clouds2);
  7521. 	setflag(fog);				setflag(fireworks);			setflag(sakura);			setflag(leaves);
  7522. 	setflag(nogo);				setflag(nobaseexp);
  7523. 	setflag(nojobexp);			setflag(nomobloot);			setflag(nomvploot);			setflag(nightenabled);
  7524. 	setflag(restricted);		setflag(nodrop);			setflag(novending);			setflag(loadevent);
  7525. 	setflag(nochat);			setflag(partylock);			setflag(guildlock);			setflag(src4instance);
  7526.  
  7527. 	clif_displaymessage(sd->fd,"Invalid flag name or flag");
  7528. 	clif_displaymessage(sd->fd,"Usage: \"@mapflag monster_teleport 1\" (0=Off | 1=On)");
  7529. 	clif_displaymessage(sd->fd,"Available Flags:");
  7530. 	clif_displaymessage(sd->fd,"----------------------------------");
  7531. 	clif_displaymessage(sd->fd,"town, autotrade, allowks, nomemo, noteleport, noreturn, monster_noteleport, nosave,");
  7532. 	clif_displaymessage(sd->fd,"nobranch, noexppenalty, pvp, pvp_noparty, pvp_noguild, pvp_nightmaredrop,");
  7533. 	clif_displaymessage(sd->fd,"pvp_nocalcrank, gvg_castle, gvg, gvg_dungeon, gvg_noparty, battleground,");
  7534. 	clif_displaymessage(sd->fd,"nozenypenalty, notrade, noskill, nowarp, nowarpto, noicewall, snow, clouds, clouds2,");
  7535. 	clif_displaymessage(sd->fd,"fog, fireworks, sakura, leaves, nogo, nobaseexp, nojobexp, nomobloot,");
  7536. 	clif_displaymessage(sd->fd,"nomvploot, nightenabled, restricted, nodrop, novending, loadevent, nochat, partylock,");
  7537. 	clif_displaymessage(sd->fd,"guildlock, src4instance");
  7538.  
  7539. #undef checkflag
  7540. #undef setflag
  7541.  
  7542. 	return 0;
  7543. }
  7544.  
  7545. /*===================================
  7546.  * Remove some messages
  7547.  *-----------------------------------*/
  7548. ACMD_FUNC(showexp)
  7549. {
  7550. 	if (sd->state.showexp) {
  7551. 		sd->state.showexp = 0;
  7552. 		clif_displaymessage(fd, "Gained exp will not be shown.");
  7553. 		return 0;
  7554. 	}
  7555.  
  7556. 	sd->state.showexp = 1;
  7557. 	clif_displaymessage(fd, "Gained exp is now shown");
  7558. 	return 0;
  7559. }
  7560.  
  7561. ACMD_FUNC(showzeny)
  7562. {
  7563. 	if (sd->state.showzeny) {
  7564. 		sd->state.showzeny = 0;
  7565. 		clif_displaymessage(fd, "Gained zeny will not be shown.");
  7566. 		return 0;
  7567. 	}
  7568.  
  7569. 	sd->state.showzeny = 1;
  7570. 	clif_displaymessage(fd, "Gained zeny is now shown");
  7571. 	return 0;
  7572. }
  7573.  
  7574. ACMD_FUNC(showdelay)
  7575. {
  7576. 	if (sd->state.showdelay) {
  7577. 		sd->state.showdelay = 0;
  7578. 		clif_displaymessage(fd, "Skill delay failures won't be shown.");
  7579. 		return 0;
  7580. 	}
  7581.  
  7582. 	sd->state.showdelay = 1;
  7583. 	clif_displaymessage(fd, "Skill delay failures are shown now.");
  7584. 	return 0;
  7585. }
  7586.  
  7587. /*==========================================
  7588.  * Duel organizing functions [LuzZza]
  7589.  *
  7590.  * @duel [limit|nick] - create a duel
  7591.  * @invite <nick> - invite player
  7592.  * @accept - accept invitation
  7593.  * @reject - reject invitation
  7594.  * @leave - leave duel
  7595.  *------------------------------------------*/
  7596. ACMD_FUNC(invite)
  7597. {
  7598. 	unsigned int did = sd->duel_group;
  7599. 	struct map_session_data *target_sd = map_nick2sd((char *)message);
  7600.  
  7601. 	if(did <= 0)	{
  7602. 		// "Duel: @invite without @duel."
  7603. 		clif_displaymessage(fd, msg_txt(350));
  7604. 		return 0;
  7605. 	}
  7606.  
  7607. 	if(duel_list[did].max_players_limit > 0 &&
  7608. 		duel_list[did].members_count >= duel_list[did].max_players_limit) {
  7609.  
  7610. 		// "Duel: Limit of players is reached."
  7611. 		clif_displaymessage(fd, msg_txt(351));
  7612. 		return 0;
  7613. 	}
  7614.  
  7615. 	if(target_sd == NULL) {
  7616. 		// "Duel: Player not found."
  7617. 		clif_displaymessage(fd, msg_txt(352));
  7618. 		return 0;
  7619. 	}
  7620.  
  7621. 	if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  7622. 		// "Duel: Player already in duel."
  7623. 		clif_displaymessage(fd, msg_txt(353));
  7624. 		return 0;
  7625. 	}
  7626.  
  7627. 	if(battle_config.duel_only_on_same_map && target_sd->bl.m != sd->bl.m)
  7628. 	{
  7629. 		sprintf(atcmd_output, msg_txt(364), message);
  7630. 		clif_displaymessage(fd, atcmd_output);
  7631. 		return 0;
  7632. 	}
  7633.  
  7634. 	duel_invite(did, sd, target_sd);
  7635. 	// "Duel: Invitation has been sent."
  7636. 	clif_displaymessage(fd, msg_txt(354));
  7637. 	return 0;
  7638. }
  7639.  
  7640. ACMD_FUNC(duel)
  7641. {
  7642. 	char output[CHAT_SIZE_MAX];
  7643. 	unsigned int maxpl=0, newduel;
  7644. 	struct map_session_data *target_sd;
  7645.  
  7646. 	if(sd->duel_group > 0) {
  7647. 		duel_showinfo(sd->duel_group, sd);
  7648. 		return 0;
  7649. 	}
  7650.  
  7651. 	if(sd->duel_invite > 0) {
  7652. 		// "Duel: @duel without @reject."
  7653. 		clif_displaymessage(fd, msg_txt(355));
  7654. 		return 0;
  7655. 	}
  7656.  
  7657. 	if(!duel_checktime(sd)) {
  7658. 		// "Duel: You can take part in duel only one time per %d minutes."
  7659. 		sprintf(output, msg_txt(356), battle_config.duel_time_interval);
  7660. 		clif_displaymessage(fd, output);
  7661. 		return 0;
  7662. 	}
  7663.  
  7664. 	if( message[0] ) {
  7665. 		if(sscanf(message, "%d", &maxpl) >= 1) {
  7666. 			if(maxpl < 2 || maxpl > 65535) {
  7667. 				clif_displaymessage(fd, msg_txt(357)); // "Duel: Invalid value."
  7668. 				return 0;
  7669. 			}
  7670. 			duel_create(sd, maxpl);
  7671. 		} else {
  7672. 			target_sd = map_nick2sd((char *)message);
  7673. 			if(target_sd != NULL) {
  7674. 				if((newduel = duel_create(sd, 2)) != -1) {
  7675. 					if(target_sd->duel_group > 0 ||	target_sd->duel_invite > 0) {
  7676. 						clif_displaymessage(fd, msg_txt(353)); // "Duel: Player already in duel."
  7677. 						return 0;
  7678. 					}
  7679. 					duel_invite(newduel, sd, target_sd);
  7680. 					clif_displaymessage(fd, msg_txt(354)); // "Duel: Invitation has been sent."
  7681. 				}
  7682. 			} else {
  7683. 				// "Duel: Player not found."
  7684. 				clif_displaymessage(fd, msg_txt(352));
  7685. 				return 0;
  7686. 			}
  7687. 		}
  7688. 	} else
  7689. 		duel_create(sd, 0);
  7690.  
  7691. 	return 0;
  7692. }
  7693.  
  7694.  
  7695. ACMD_FUNC(leave)
  7696. {
  7697. 	if(sd->duel_group <= 0) {
  7698. 		// "Duel: @leave without @duel."
  7699. 		clif_displaymessage(fd, msg_txt(358));
  7700. 		return 0;
  7701. 	}
  7702.  
  7703. 	duel_leave(sd->duel_group, sd);
  7704. 	clif_displaymessage(fd, msg_txt(359)); // "Duel: You left the duel."
  7705. 	return 0;
  7706. }
  7707.  
  7708. ACMD_FUNC(accept)
  7709. {
  7710. 	char output[CHAT_SIZE_MAX];
  7711.  
  7712. 	if(!duel_checktime(sd)) {
  7713. 		// "Duel: You can take part in duel only one time per %d minutes."
  7714. 		sprintf(output, msg_txt(356), battle_config.duel_time_interval);
  7715. 		clif_displaymessage(fd, output);
  7716. 		return 0;
  7717. 	}
  7718.  
  7719. 	if(sd->duel_invite <= 0) {
  7720. 		// "Duel: @accept without invititation."
  7721. 		clif_displaymessage(fd, msg_txt(360));
  7722. 		return 0;
  7723. 	}
  7724.  
  7725. 	if( duel_list[sd->duel_invite].max_players_limit > 0 && duel_list[sd->duel_invite].members_count >= duel_list[sd->duel_invite].max_players_limit )
  7726. 	{
  7727. 		// "Duel: Limit of players is reached."
  7728. 		clif_displaymessage(fd, msg_txt(351));
  7729. 		return 0;
  7730. 	}
  7731.  
  7732. 	duel_accept(sd->duel_invite, sd);
  7733. 	// "Duel: Invitation has been accepted."
  7734. 	clif_displaymessage(fd, msg_txt(361));
  7735. 	return 0;
  7736. }
  7737.  
  7738. ACMD_FUNC(reject)
  7739. {
  7740. 	if(sd->duel_invite <= 0) {
  7741. 		// "Duel: @reject without invititation."
  7742. 		clif_displaymessage(fd, msg_txt(362));
  7743. 		return 0;
  7744. 	}
  7745.  
  7746. 	duel_reject(sd->duel_invite, sd);
  7747. 	// "Duel: Invitation has been rejected."
  7748. 	clif_displaymessage(fd, msg_txt(363));
  7749. 	return 0;
  7750. }
  7751.  
  7752. /*===================================
  7753.  * Cash Points
  7754.  *-----------------------------------*/
  7755. ACMD_FUNC(cash)
  7756. {
  7757. 	char output[128];
  7758. 	int value;
  7759. 	nullpo_retr(-1, sd);
  7760.  
  7761. 	if( !message || !*message || (value = atoi(message)) == 0 ) {
  7762. 		clif_displaymessage(fd, "Please, enter an amount.");
  7763. 		return -1;
  7764. 	}
  7765.  
  7766. 	if( !strcmpi(command+1,"cash") )
  7767. 	{
  7768. 		if( value > 0 ) {
  7769. 			pc_getcash(sd, value, 0);
  7770. 			sprintf(output, msg_txt(505), value, sd->cashPoints);
  7771. 			clif_disp_onlyself(sd, output, strlen(output));
  7772. 		} else {
  7773. 			pc_paycash(sd, -value, 0);
  7774. 			sprintf(output, msg_txt(410), value, sd->cashPoints);
  7775. 			clif_disp_onlyself(sd, output, strlen(output));
  7776. 		}
  7777. 	}
  7778. 	else
  7779. 	{ // @points
  7780. 		if( value > 0 ) {
  7781. 			pc_getcash(sd, 0, value);
  7782. 			sprintf(output, msg_txt(506), value, sd->kafraPoints);
  7783. 			clif_disp_onlyself(sd, output, strlen(output));
  7784. 		} else {
  7785. 			pc_paycash(sd, -value, -value);
  7786. 			sprintf(output, msg_txt(411), -value, sd->kafraPoints);
  7787. 			clif_disp_onlyself(sd, output, strlen(output));
  7788. 		}
  7789. 	}
  7790.  
  7791. 	return 0;
  7792. }
  7793.  
  7794. // @clone/@slaveclone/@evilclone <playername> [Valaris]
  7795. ACMD_FUNC(clone)
  7796. {
  7797. 	int x=0,y=0,flag=0,master=0,i=0;
  7798. 	struct map_session_data *pl_sd=NULL;
  7799.  
  7800. 	if (!message || !*message) {
  7801. 		clif_displaymessage(sd->fd,"You must enter a name or character ID.");
  7802. 		return 0;
  7803. 	}
  7804.  
  7805. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL) {
  7806. 		clif_displaymessage(fd, msg_txt(3));	// Character not found.
  7807. 		return 0;
  7808. 	}
  7809.  
  7810. 	if(pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  7811. 		clif_displaymessage(fd, msg_txt(126));	// Cannot clone a player of higher GM level than yourself.
  7812. 		return 0;
  7813. 	}
  7814.  
  7815. 	if (strcmpi(command+1, "clone") == 0) 
  7816. 		flag = 1;
  7817. 	else if (strcmpi(command+1, "slaveclone") == 0) {
  7818. 	  	flag = 2;
  7819. 		master = sd->bl.id;
  7820. 		if (battle_config.atc_slave_clone_limit
  7821. 			&& mob_countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
  7822. 			clif_displaymessage(fd, msg_txt(127));	// You've reached your slave clones limit.
  7823. 			return 0;
  7824. 		}
  7825. 	}
  7826.  
  7827. 	do {
  7828. 		x = sd->bl.x + (rnd() % 10 - 5);
  7829. 		y = sd->bl.y + (rnd() % 10 - 5);
  7830. 	} while (map_getcell(sd->bl.m,x,y,CELL_CHKNOPASS) && i++ < 10);
  7831.  
  7832. 	if (i >= 10) {
  7833. 		x = sd->bl.x;
  7834. 		y = sd->bl.y;
  7835. 	}
  7836.  
  7837. 	if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
  7838. 		clif_displaymessage(fd, msg_txt(128+flag*2));	// Evil Clone spawned. Clone spawned. Slave clone spawned.
  7839. 		return 0;
  7840. 	}
  7841. 	clif_displaymessage(fd, msg_txt(129+flag*2));	// Unable to spawn evil clone. Unable to spawn clone. Unable to spawn slave clone.
  7842. 	return 0;
  7843. }
  7844.  
  7845. /*===================================
  7846.  * Main chat [LuzZza]
  7847.  * Usage: @main <on|off|message>
  7848.  *-----------------------------------*/
  7849. ACMD_FUNC(main)
  7850. {
  7851. 	if( message[0] ) {
  7852.  
  7853. 		if(strcmpi(message, "on") == 0) {
  7854. 			if(!sd->state.mainchat) {
  7855. 				sd->state.mainchat = 1;
  7856. 				clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  7857. 			} else {
  7858. 				clif_displaymessage(fd, msg_txt(381)); // Main chat already activated.
  7859. 			}
  7860. 		} else if(strcmpi(message, "off") == 0) {
  7861. 			if(sd->state.mainchat) {
  7862. 				sd->state.mainchat = 0;
  7863. 				clif_displaymessage(fd, msg_txt(382)); // Main chat has been disabled.
  7864. 			} else {
  7865. 				clif_displaymessage(fd, msg_txt(383)); // Main chat already disabled.
  7866. 			}
  7867. 		} else {
  7868. 			if(!sd->state.mainchat) {
  7869. 				sd->state.mainchat = 1;
  7870. 				clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  7871. 			}
  7872. 			if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) {
  7873. 				clif_displaymessage(fd, msg_txt(387));
  7874. 				return -1;
  7875. 			}
  7876.  
  7877. 			// send the message using inter-server system
  7878. 			intif_main_message( sd, message );
  7879. 		}
  7880.  
  7881. 	} else {
  7882.  
  7883. 		if(sd->state.mainchat) 
  7884. 			clif_displaymessage(fd, msg_txt(384)); // Main chat currently enabled. Usage: @main <on|off>, @main <message>.
  7885. 		else
  7886. 			clif_displaymessage(fd, msg_txt(385)); // Main chat currently disabled. Usage: @main <on|off>, @main <message>.
  7887. 	}
  7888. 	return 0;
  7889. }
  7890.  
  7891. /*=====================================
  7892.  * Autorejecting Invites/Deals [LuzZza]
  7893.  * Usage: @noask
  7894.  *-------------------------------------*/
  7895. ACMD_FUNC(noask)
  7896. {
  7897. 	if(sd->state.noask) {
  7898. 		clif_displaymessage(fd, msg_txt(391)); // Autorejecting is deactivated.
  7899. 		sd->state.noask = 0;
  7900. 	} else {
  7901. 		clif_displaymessage(fd, msg_txt(390)); // Autorejecting is activated.
  7902. 		sd->state.noask = 1;
  7903. 	}
  7904.  
  7905. 	return 0;
  7906. }
  7907.  
  7908. /*=====================================
  7909.  * Send a @request message to all GMs of lowest_gm_level.
  7910.  * Usage: @request <petition>
  7911.  *-------------------------------------*/
  7912. ACMD_FUNC(request)
  7913. {
  7914. 	if (!message || !*message) {
  7915. 		clif_displaymessage(sd->fd,msg_txt(277));	// Usage: @request <petition/message to online GMs>.
  7916. 		return -1;
  7917. 	}
  7918.  
  7919. 	sprintf(atcmd_output, msg_txt(278), message);	// (@request): %s
  7920. 	intif_wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output);
  7921. 	clif_disp_onlyself(sd, atcmd_output, strlen(atcmd_output));
  7922. 	clif_displaymessage(sd->fd,msg_txt(279));	// @request sent.
  7923. 	return 0;
  7924. }
  7925.  
  7926. /*==========================================
  7927.  * Feel (SG save map) Reset [HiddenDragon]
  7928.  *------------------------------------------*/
  7929. ACMD_FUNC(feelreset)
  7930. {
  7931. 	pc_resetfeel(sd);
  7932. 	clif_displaymessage(fd, "Reset 'Feeling' maps.");
  7933.  
  7934. 	return 0;
  7935. }
  7936.  
  7937. /*==========================================
  7938.  * AUCTION SYSTEM
  7939.  *------------------------------------------*/
  7940. ACMD_FUNC(auction)
  7941. {
  7942. 	nullpo_ret(sd);
  7943.  
  7944. 	clif_Auction_openwindow(sd);
  7945.  
  7946. 	return 0;
  7947. }
  7948.  
  7949. /*==========================================
  7950.  * Kill Steal Protection
  7951.  *------------------------------------------*/
  7952. ACMD_FUNC(ksprotection)
  7953. {
  7954. 	nullpo_retr(-1,sd);
  7955.  
  7956. 	if( sd->state.noks ) {
  7957. 		sd->state.noks = 0;
  7958. 		sprintf(atcmd_output, "[ K.S Protection Inactive ]");
  7959. 	}
  7960. 	else
  7961. 	{
  7962. 		if( !message || !*message || !strcmpi(message, "party") )
  7963. 		{ // Default is Party
  7964. 			sd->state.noks = 2;
  7965. 			sprintf(atcmd_output, "[ K.S Protection Active - Option: Party ]");
  7966. 		}
  7967. 		else if( !strcmpi(message, "self") )
  7968. 		{
  7969. 			sd->state.noks = 1;
  7970. 			sprintf(atcmd_output, "[ K.S Protection Active - Option: Self ]");
  7971. 		}
  7972. 		else if( !strcmpi(message, "guild") )
  7973. 		{
  7974. 			sd->state.noks = 3;
  7975. 			sprintf(atcmd_output, "[ K.S Protection Active - Option: Guild ]");
  7976. 		}
  7977. 		else
  7978. 			sprintf(atcmd_output, "Usage: @noks <self|party|guild>");
  7979. 	}
  7980.  
  7981. 	clif_displaymessage(fd, atcmd_output);
  7982. 	return 0;
  7983. }
  7984. /*==========================================
  7985.  * Map Kill Steal Protection Setting
  7986.  *------------------------------------------*/
  7987. ACMD_FUNC(allowks)
  7988. {
  7989. 	nullpo_retr(-1,sd);
  7990.  
  7991. 	if( map[sd->bl.m].flag.allowks ) {
  7992. 		map[sd->bl.m].flag.allowks = 0;
  7993. 		sprintf(atcmd_output, "[ Map K.S Protection Active ]");
  7994. 	} else {
  7995. 		map[sd->bl.m].flag.allowks = 1;
  7996. 		sprintf(atcmd_output, "[ Map K.S Protection Inactive ]");
  7997. 	}
  7998.  
  7999. 	clif_displaymessage(fd, atcmd_output);
  8000. 	return 0;
  8001. }
  8002.  
  8003. ACMD_FUNC(resetstat)
  8004. {
  8005. 	nullpo_retr(-1, sd);
  8006.  
  8007. 	pc_resetstate(sd);
  8008. 	sprintf(atcmd_output, msg_txt(207), sd->status.name);
  8009. 	clif_displaymessage(fd, atcmd_output);
  8010. 	return 0;
  8011. }
  8012.  
  8013. ACMD_FUNC(resetskill)
  8014. {
  8015. 	nullpo_retr(-1,sd);
  8016.  
  8017. 	pc_resetskill(sd,1);
  8018. 	sprintf(atcmd_output, msg_txt(206), sd->status.name);
  8019. 	clif_displaymessage(fd, atcmd_output);
  8020. 	return 0;
  8021. }
  8022.  
  8023. /*==========================================
  8024.  * #storagelist: Displays the items list of a player's storage.
  8025.  * #cartlist: Displays contents of target's cart.
  8026.  * #itemlist: Displays contents of target's inventory.
  8027.  *------------------------------------------*/
  8028. ACMD_FUNC(itemlist)
  8029. {
  8030. 	int i, j, count, counter;
  8031. 	const char* location;
  8032. 	const struct item* items;
  8033. 	int size;
  8034. 	StringBuf buf;
  8035.  
  8036. 	nullpo_retr(-1, sd);
  8037.  
  8038. 	if( strcmp(command+1, "storagelist") == 0 )
  8039. 	{
  8040. 		location = "storage";
  8041. 		items = sd->status.storage.items;
  8042. 		size = MAX_STORAGE;
  8043. 	}
  8044. 	else
  8045. 	if( strcmp(command+1, "cartlist") == 0 )
  8046. 	{
  8047. 		location = "cart";
  8048. 		items = sd->status.cart;
  8049. 		size = MAX_CART;
  8050. 	}
  8051. 	else
  8052. 	if( strcmp(command+1, "itemlist") == 0 )
  8053. 	{
  8054. 		location = "inventory";
  8055. 		items = sd->status.inventory;
  8056. 		size = MAX_INVENTORY;
  8057. 	}
  8058. 	else
  8059. 		return 1;
  8060.  
  8061. 	StringBuf_Init(&buf);
  8062.  
  8063. 	count = 0; // total slots occupied
  8064. 	counter = 0; // total items found
  8065. 	for( i = 0; i < size; ++i )
  8066. 	{
  8067. 		const struct item* it = &items[i];
  8068. 		struct item_data* itd;
  8069.  
  8070. 		if( it->nameid == 0 || (itd = itemdb_exists(it->nameid)) == NULL )
  8071. 			continue;
  8072.  
  8073. 		counter += it->amount;
  8074. 		count++;
  8075.  
  8076. 		if( count == 1 )
  8077. 		{
  8078. 			StringBuf_Printf(&buf, "------ %s items list of '%s' ------", location, sd->status.name);
  8079. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  8080. 			StringBuf_Clear(&buf);
  8081. 		}
  8082.  
  8083. 		if( it->refine )
  8084. 			StringBuf_Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid);
  8085. 		else
  8086. 			StringBuf_Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid);
  8087.  
  8088. 		if( it->equip )
  8089. 		{
  8090. 			char equipstr[CHAT_SIZE_MAX];
  8091. 			strcpy(equipstr, " | equipped: ");
  8092. 			if( it->equip & EQP_GARMENT )
  8093. 				strcat(equipstr, "garment, ");
  8094. 			if( it->equip & EQP_ACC_L )
  8095. 				strcat(equipstr, "left accessory, ");
  8096. 			if( it->equip & EQP_ARMOR )
  8097. 				strcat(equipstr, "body/armor, ");
  8098. 			if( (it->equip & EQP_ARMS) == EQP_HAND_R )
  8099. 				strcat(equipstr, "right hand, ");
  8100. 			if( (it->equip & EQP_ARMS) == EQP_HAND_L )
  8101. 				strcat(equipstr, "left hand, ");
  8102. 			if( (it->equip & EQP_ARMS) == EQP_ARMS )
  8103. 				strcat(equipstr, "both hands, ");
  8104. 			if( it->equip & EQP_SHOES )
  8105. 				strcat(equipstr, "feet, ");
  8106. 			if( it->equip & EQP_ACC_R )
  8107. 				strcat(equipstr, "right accessory, ");
  8108. 			if( (it->equip & EQP_HELM) == EQP_HEAD_LOW )
  8109. 				strcat(equipstr, "lower head, ");
  8110. 			if( (it->equip & EQP_HELM) == EQP_HEAD_TOP )
  8111. 				strcat(equipstr, "top head, ");
  8112. 			if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_TOP) )
  8113. 				strcat(equipstr, "lower/top head, ");
  8114. 			if( (it->equip & EQP_HELM) == EQP_HEAD_MID )
  8115. 				strcat(equipstr, "mid head, ");
  8116. 			if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_MID) )
  8117. 				strcat(equipstr, "lower/mid head, ");
  8118. 			if( (it->equip & EQP_HELM) == EQP_HELM )
  8119. 				strcat(equipstr, "lower/mid/top head, ");
  8120. 			// remove final ', '
  8121. 			equipstr[strlen(equipstr) - 2] = '\0';
  8122. 			StringBuf_AppendStr(&buf, equipstr);
  8123. 		}
  8124.  
  8125. 		clif_displaymessage(fd, StringBuf_Value(&buf));
  8126. 		StringBuf_Clear(&buf);
  8127.  
  8128. 		if( it->card[0] == CARD0_PET )
  8129. 		{// pet egg
  8130. 			if (it->card[3])
  8131. 				StringBuf_Printf(&buf, " -> (pet egg, pet id: %u, named)", (unsigned int)MakeDWord(it->card[1], it->card[2]));
  8132. 			else
  8133. 				StringBuf_Printf(&buf, " -> (pet egg, pet id: %u, unnamed)", (unsigned int)MakeDWord(it->card[1], it->card[2]));
  8134. 		}
  8135. 		else
  8136. 		if(it->card[0] == CARD0_FORGE)
  8137. 		{// forged item
  8138. 			StringBuf_Printf(&buf, " -> (crafted item, creator id: %u, star crumbs %d, element %d)", (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f);
  8139. 		}
  8140. 		else
  8141. 		if(it->card[0] == CARD0_CREATE)
  8142. 		{// created item
  8143. 			StringBuf_Printf(&buf, " -> (produced item, creator id: %u)", (unsigned int)MakeDWord(it->card[2], it->card[3]));
  8144. 		}
  8145. 		else
  8146. 		{// normal item
  8147. 			int counter2 = 0;
  8148.  
  8149. 			for( j = 0; j < itd->slot; ++j )
  8150. 			{
  8151. 				struct item_data* card;
  8152.  
  8153. 				if( it->card[j] == 0 || (card = itemdb_exists(it->card[j])) == NULL )
  8154. 					continue;
  8155.  
  8156. 				counter2++;
  8157.  
  8158. 				if( counter2 == 1 )
  8159. 					StringBuf_AppendStr(&buf, " -> (card(s): ");
  8160.  
  8161. 				if( counter2 != 1 )
  8162. 					StringBuf_AppendStr(&buf, ", ");
  8163.  
  8164. 				StringBuf_Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid);
  8165. 			}
  8166.  
  8167. 			if( counter2 > 0 )
  8168. 				StringBuf_AppendStr(&buf, ")");
  8169. 		}
  8170.  
  8171. 		if( StringBuf_Length(&buf) > 0 )
  8172. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  8173.  
  8174. 		StringBuf_Clear(&buf);
  8175. 	}
  8176.  
  8177. 	if( count == 0 )
  8178. 		StringBuf_Printf(&buf, "No item found in this player's %s.", location);
  8179. 	else
  8180. 		StringBuf_Printf(&buf, "%d item(s) found in %d %s slots.", counter, count, location);
  8181.  
  8182. 	clif_displaymessage(fd, StringBuf_Value(&buf));
  8183.  
  8184. 	StringBuf_Destroy(&buf);
  8185.  
  8186. 	return 0;
  8187. }
  8188.  
  8189. ACMD_FUNC(stats)
  8190. {
  8191. 	char job_jobname[100];
  8192. 	char output[CHAT_SIZE_MAX];
  8193. 	int i;
  8194. 	struct {
  8195. 		const char* format;
  8196. 		int value;
  8197. 	} output_table[] = {
  8198. 		{ "Base Level - %d", 0 },
  8199. 		{ NULL, 0 },
  8200. 		{ "Hp - %d", 0 },
  8201. 		{ "MaxHp - %d", 0 },
  8202. 		{ "Sp - %d", 0 },
  8203. 		{ "MaxSp - %d", 0 },
  8204. 		{ "Str - %3d", 0 },
  8205. 		{ "Agi - %3d", 0 },
  8206. 		{ "Vit - %3d", 0 },
  8207. 		{ "Int - %3d", 0 },
  8208. 		{ "Dex - %3d", 0 },
  8209. 		{ "Luk - %3d", 0 },
  8210. 		{ "Zeny - %d", 0 },
  8211. 		{ "Free SK Points - %d", 0 },
  8212. 		{ "JobChangeLvl (2nd) - %d", 0 },
  8213. 		{ "JobChangeLvl (3rd) - %d", 0 },
  8214. 		{ NULL, 0 }
  8215. 	};
  8216.  
  8217. 	memset(job_jobname, '\0', sizeof(job_jobname));
  8218. 	memset(output, '\0', sizeof(output));
  8219.  
  8220. 	//direct array initialization with variables is not standard C compliant.
  8221. 	output_table[0].value = sd->status.base_level;
  8222. 	output_table[1].format = job_jobname;
  8223. 	output_table[1].value = sd->status.job_level;
  8224. 	output_table[2].value = sd->status.hp;
  8225. 	output_table[3].value = sd->status.max_hp;
  8226. 	output_table[4].value = sd->status.sp;
  8227. 	output_table[5].value = sd->status.max_sp;
  8228. 	output_table[6].value = sd->status.str;
  8229. 	output_table[7].value = sd->status.agi;
  8230. 	output_table[8].value = sd->status.vit;
  8231. 	output_table[9].value = sd->status.int_;
  8232. 	output_table[10].value = sd->status.dex;
  8233. 	output_table[11].value = sd->status.luk;
  8234. 	output_table[12].value = sd->status.zeny;
  8235. 	output_table[13].value = sd->status.skill_point;
  8236. 	output_table[14].value = sd->change_level_2nd;
  8237. 	output_table[15].value = sd->change_level_3rd;
  8238.  
  8239. 	sprintf(job_jobname, "Job - %s %s", job_name(sd->status.class_), "(level %d)");
  8240. 	sprintf(output, msg_txt(53), sd->status.name); // '%s' stats:
  8241.  
  8242. 	clif_displaymessage(fd, output);
  8243.  
  8244. 	for (i = 0; output_table[i].format != NULL; i++) {
  8245. 		sprintf(output, output_table[i].format, output_table[i].value);
  8246. 		clif_displaymessage(fd, output);
  8247. 	}
  8248.  
  8249. 	return 0;
  8250. }
  8251.  
  8252. ACMD_FUNC(delitem)
  8253. {
  8254. 	char item_name[100];
  8255. 	int nameid, amount = 0, total, idx;
  8256. 	struct item_data* id;
  8257.  
  8258. 	nullpo_retr(-1, sd);
  8259.  
  8260. 	if( !message || !*message || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &amount) < 2 && sscanf(message, "%99s %d", item_name, &amount) < 2 ) || amount < 1 )
  8261. 	{
  8262. 		clif_displaymessage(fd, "Please, enter an item name/id, a quantity and a player name (usage: #delitem <player> <item_name_or_ID> <quantity>).");
  8263. 		return -1;
  8264. 	}
  8265.  
  8266. 	if( ( id = itemdb_searchname(item_name) ) != NULL || ( id = itemdb_exists(atoi(item_name)) ) != NULL )
  8267. 	{
  8268. 		nameid = id->nameid;
  8269. 	}
  8270. 	else
  8271. 	{
  8272. 		clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  8273. 		return -1;
  8274. 	}
  8275.  
  8276. 	total = amount;
  8277.  
  8278. 	// delete items
  8279. 	while( amount && ( idx = pc_search_inventory(sd, nameid) ) != -1 )
  8280. 	{
  8281. 		int delamount = ( amount < sd->status.inventory[idx].amount ) ? amount : sd->status.inventory[idx].amount;
  8282.  
  8283. 		if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET )
  8284. 		{// delete pet
  8285. 			intif_delete_petdata(MakeDWord(sd->status.inventory[idx].card[1], sd->status.inventory[idx].card[2]));
  8286. 		}
  8287. 		pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_COMMAND);
  8288.  
  8289. 		amount-= delamount;
  8290. 	}
  8291.  
  8292. 	// notify target
  8293. 	sprintf(atcmd_output, msg_txt(113), total-amount); // %d item(s) removed by a GM.
  8294. 	clif_displaymessage(sd->fd, atcmd_output);
  8295.  
  8296. 	// notify source
  8297. 	if( amount == total )
  8298. 	{
  8299. 		clif_displaymessage(fd, msg_txt(116)); // Character does not have the item.
  8300. 	}
  8301. 	else if( amount )
  8302. 	{
  8303. 		sprintf(atcmd_output, msg_txt(115), total-amount, total-amount, total); // %d item(s) removed. Player had only %d on %d items.
  8304. 		clif_displaymessage(fd, atcmd_output);
  8305. 	}
  8306. 	else
  8307. 	{
  8308. 		sprintf(atcmd_output, msg_txt(114), total); // %d item(s) removed from the player.
  8309. 		clif_displaymessage(fd, atcmd_output);
  8310. 	}
  8311.  
  8312. 	return 0;
  8313. }
  8314.  
  8315. /*==========================================
  8316.  * Custom Fonts
  8317.  *------------------------------------------*/
  8318. ACMD_FUNC(font)
  8319. {
  8320. 	int font_id;
  8321. 	nullpo_retr(-1,sd);
  8322.  
  8323. 	font_id = atoi(message);
  8324. 	if( font_id == 0 )
  8325. 	{
  8326. 		if( sd->user_font )
  8327. 		{
  8328. 			sd->user_font = 0;
  8329. 			clif_displaymessage(fd, "Returning to normal font.");
  8330. 			clif_font(sd);
  8331. 		}
  8332. 		else
  8333. 		{
  8334. 			clif_displaymessage(fd, "Use @font <1..9> to change your messages font.");
  8335. 			clif_displaymessage(fd, "Use 0 or no parameter to back to normal font.");
  8336. 		}
  8337. 	}
  8338. 	else if( font_id < 0 || font_id > 9 )
  8339. 		clif_displaymessage(fd, "Invalid font. Use a Value from 0 to 9.");
  8340. 	else if( font_id != sd->user_font )
  8341. 	{
  8342. 		sd->user_font = font_id;
  8343. 		clif_font(sd);
  8344. 		clif_displaymessage(fd, "Font changed.");
  8345. 	}
  8346. 	else
  8347. 		clif_displaymessage(fd, "Already using this font.");
  8348.  
  8349. 	return 0;
  8350. }
  8351.  
  8352. /*==========================================
  8353.  * type: 1 = commands (@), 2 = charcommands (#)
  8354.  *------------------------------------------*/
  8355. static void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommandType type)
  8356. {
  8357. 	char line_buff[CHATBOX_SIZE];
  8358. 	char* cur = line_buff;
  8359. 	AtCommandInfo* cmd;
  8360. 	DBIterator *iter = db_iterator(atcommand_db);
  8361. 	int count = 0;
  8362.  
  8363. 	memset(line_buff,' ',CHATBOX_SIZE);
  8364. 	line_buff[CHATBOX_SIZE-1] = 0;
  8365.  
  8366. 	clif_displaymessage(fd, msg_txt(273)); // "Commands available:"
  8367.  
  8368. 	for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  8369. 		unsigned int slen = 0;
  8370.  
  8371. 		if (!pc_can_use_command(sd, cmd->command, type))
  8372. 			continue;
  8373.  
  8374. 		slen = strlen(cmd->command);
  8375.  
  8376. 		// flush the text buffer if this command won't fit into it
  8377. 		if ( slen + cur - line_buff >= CHATBOX_SIZE )
  8378. 		{
  8379. 			clif_displaymessage(fd,line_buff);
  8380. 			cur = line_buff;
  8381. 			memset(line_buff,' ',CHATBOX_SIZE);
  8382. 			line_buff[CHATBOX_SIZE-1] = 0;
  8383. 		}
  8384.  
  8385. 		memcpy(cur,cmd->command,slen);
  8386. 		cur += slen+(10-slen%10);
  8387.  
  8388. 		count++;
  8389. 	}
  8390. 	dbi_destroy(iter);
  8391. 	clif_displaymessage(fd,line_buff);
  8392.  
  8393. 	sprintf(atcmd_output, msg_txt(274), count); // "%d commands found."
  8394. 	clif_displaymessage(fd, atcmd_output);
  8395.  
  8396. 	return;
  8397. }
  8398.  
  8399. /*==========================================
  8400.  * @commands Lists available @ commands to you
  8401.  *------------------------------------------*/
  8402. ACMD_FUNC(commands)
  8403. {
  8404. 	atcommand_commands_sub(sd, fd, COMMAND_ATCOMMAND);
  8405. 	return 0;
  8406. }
  8407.  
  8408. /*==========================================
  8409.  * @charcommands Lists available # commands to you
  8410.  *------------------------------------------*/
  8411. ACMD_FUNC(charcommands)
  8412. {
  8413. 	atcommand_commands_sub(sd, fd, COMMAND_CHARCOMMAND);
  8414. 	return 0;
  8415. }
  8416.  
  8417. ACMD_FUNC(new_mount) {
  8418.  
  8419. 	clif_displaymessage(sd->fd,"NOTICE: If you crash with mount your LUA is outdated");
  8420. 	if( !(sd->sc.option&OPTION_MOUNTING) ) {
  8421. 		clif_displaymessage(sd->fd,"You have mounted.");
  8422. 		pc_setoption(sd, sd->sc.option|OPTION_MOUNTING);
  8423. 	} else {
  8424. 		clif_displaymessage(sd->fd,"You have released your mount");
  8425. 		pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);
  8426. 	}
  8427. 	return 0;
  8428. }
  8429.  
  8430. ACMD_FUNC(accinfo) {
  8431. 	char query[NAME_LENGTH];
  8432.  
  8433. 	if (!message || !*message || strlen(message) > NAME_LENGTH ) {
  8434. 		clif_displaymessage(fd, "(usage: @accinfo/@accountinfo <account_id/char name>).");
  8435. 		clif_displaymessage(fd, "You may search partial name by making use of '%' in the search, \"@accinfo %Mario%\" lists all characters whose name contain \"Mario\"");
  8436. 		return -1;
  8437. 	}
  8438.  
  8439. 	//remove const type
  8440. 	safestrncpy(query, message, NAME_LENGTH);
  8441.  
  8442. 	intif_request_accinfo( sd->fd, sd->bl.id, sd->group_id, query );
  8443.  
  8444. 	return 0;
  8445. }
  8446.  
  8447. /* [Ind] */
  8448. ACMD_FUNC(set) {
  8449. 	char reg[32], val[128];
  8450. 	struct script_data* data;
  8451. 	int toset = 0;
  8452. 	bool is_str = false;
  8453.  
  8454. 	if( !message || !*message || (toset = sscanf(message, "%32s %128[^\n]s", reg, val)) < 1  ) {
  8455. 		clif_displaymessage(fd, "Usage: @set <variable name> <value>");
  8456. 		clif_displaymessage(fd, "Usage: e.g. @set PoringCharVar 50");
  8457. 		clif_displaymessage(fd, "Usage: e.g. @set PoringCharVarSTR$ Super Duper String");
  8458. 		clif_displaymessage(fd, "Usage: e.g. \"@set PoringCharVarSTR$\" outputs it's value, Super Duper String");
  8459. 		return -1;
  8460. 	}
  8461.  
  8462. 	/* disabled variable types (they require a proper script state to function, so allowing them would crash the server) */
  8463. 	if( reg[0] == '.' ) {
  8464. 		clif_displaymessage(fd, "NPC Variables may not be used with @set");
  8465. 		return -1;
  8466. 	} else if( reg[0] == '\'' ) {
  8467. 		clif_displaymessage(fd, "Instance variables may not be used with @set");
  8468. 		return -1;
  8469. 	}
  8470.  
  8471. 	is_str = ( reg[strlen(reg) - 1] == '$' ) ? true : false;
  8472.  
  8473. 	if( toset >= 2 ) {/* we only set the var if there is an val, otherwise we only output the value */
  8474. 		if( is_str )
  8475. 			set_var(sd, reg, (void*) val);
  8476. 		else
  8477. 			set_var(sd, reg, (void*)__64BPRTSIZE((int)(atoi(val))));
  8478.  
  8479. 	}
  8480.  
  8481. 	CREATE(data, struct script_data,1);
  8482.  
  8483.  
  8484. 	if( is_str ) {// string variable
  8485.  
  8486. 		switch( reg[0] ) {
  8487. 			case '@':
  8488. 				data->u.str = pc_readregstr(sd, add_str(reg));
  8489. 				break;
  8490. 			case '$':
  8491. 				data->u.str = mapreg_readregstr(add_str(reg));
  8492. 				break;
  8493. 			case '#':
  8494. 				if( reg[1] == '#' )
  8495. 					data->u.str = pc_readaccountreg2str(sd, reg);// global
  8496. 				else
  8497. 					data->u.str = pc_readaccountregstr(sd, reg);// local
  8498. 				break;
  8499. 			default:
  8500. 				data->u.str = pc_readglobalreg_str(sd, reg);
  8501. 				break;
  8502. 		}
  8503.  
  8504. 		if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string
  8505. 			data->type = C_CONSTSTR;
  8506. 			data->u.str = "";
  8507. 		} else {// duplicate string
  8508. 			data->type = C_STR;
  8509. 			data->u.str = aStrdup(data->u.str);
  8510. 		}
  8511.  
  8512. 	} else {// integer variable
  8513.  
  8514. 		data->type = C_INT;
  8515. 		switch( reg[0] ) {
  8516. 			case '@':
  8517. 				data->u.num = pc_readreg(sd, add_str(reg));
  8518. 				break;
  8519. 			case '$':
  8520. 				data->u.num = mapreg_readreg(add_str(reg));
  8521. 				break;
  8522. 			case '#':
  8523. 				if( reg[1] == '#' )
  8524. 					data->u.num = pc_readaccountreg2(sd, reg);// global
  8525. 				else
  8526. 					data->u.num = pc_readaccountreg(sd, reg);// local
  8527. 				break;
  8528. 			default:
  8529. 				data->u.num = pc_readglobalreg(sd, reg);
  8530. 				break;
  8531. 		}
  8532.  
  8533. 	}
  8534.  
  8535.  
  8536. 	switch( data->type ) {
  8537. 		case C_INT:
  8538. 			sprintf(atcmd_output,"%s value is now :%d",reg,data->u.num);
  8539. 			break;
  8540. 		case C_STR:
  8541. 			sprintf(atcmd_output,"%s value is now :%s",reg,data->u.str);
  8542. 			break;
  8543. 		case C_CONSTSTR:
  8544. 			sprintf(atcmd_output,"%s is empty",reg);
  8545. 			break;
  8546. 		default:
  8547. 			sprintf(atcmd_output,"%s data type is not supported :%u",reg,data->type);
  8548. 			break;
  8549. 	}
  8550.  
  8551. 	clif_displaymessage(fd, atcmd_output);
  8552.  
  8553. 	aFree(data);
  8554.  
  8555. 	return 0;
  8556. }
  8557.  
  8558. /**
  8559.  * Fills the reference of available commands in atcommand DBMap
  8560.  **/
  8561. #define ACMD_DEF(x) { #x, atcommand_ ## x }
  8562. #define ACMD_DEF2(x2, x) { x2, atcommand_ ## x }
  8563. void atcommand_basecommands(void) {
  8564. 	/**
  8565. 	 * Command reference list, place the base of your commands here
  8566. 	 **/
  8567. 	AtCommandInfo atcommand_base[] = {
  8568. 		ACMD_DEF2("warp", mapmove),
  8569. 		ACMD_DEF(jumpto),
  8570. 		ACMD_DEF(jump),
  8571. 		ACMD_DEF(who),
  8572. 		ACMD_DEF2("who2", who),
  8573. 		ACMD_DEF2("who3", who),
  8574. 		ACMD_DEF2("whomap", who),
  8575. 		ACMD_DEF2("whomap2", who),
  8576. 		ACMD_DEF2("whomap3", who),
  8577. 		ACMD_DEF(whogm),
  8578. 		ACMD_DEF(save),
  8579. 		ACMD_DEF(load),
  8580. 		ACMD_DEF(speed),
  8581. 		ACMD_DEF(storage),
  8582. 		ACMD_DEF(guildstorage),
  8583. 		ACMD_DEF(option),
  8584. 		ACMD_DEF(hide), // + /hide
  8585. 		ACMD_DEF(jobchange),
  8586. 		ACMD_DEF(kill),
  8587. 		ACMD_DEF(alive),
  8588. 		ACMD_DEF(kami),
  8589. 		ACMD_DEF2("kamib", kami),
  8590. 		ACMD_DEF2("kamic", kami),
  8591. 		ACMD_DEF2("lkami", kami),
  8592. 		ACMD_DEF(heal),
  8593. 		ACMD_DEF(item),
  8594. 		ACMD_DEF(item2),
  8595. 		ACMD_DEF(itemreset),
  8596. 		ACMD_DEF2("blvl", baselevelup),
  8597. 		ACMD_DEF2("jlvl", joblevelup),
  8598. 		ACMD_DEF(help),
  8599. 		ACMD_DEF(pvpoff),
  8600. 		ACMD_DEF(pvpon),
  8601. 		ACMD_DEF(gvgoff),
  8602. 		ACMD_DEF(gvgon),
  8603. 		ACMD_DEF(model),
  8604. 		ACMD_DEF(go),
  8605. 		ACMD_DEF(monster),
  8606. 		ACMD_DEF2("monstersmall", monster),
  8607. 		ACMD_DEF2("monsterbig", monster),
  8608. 		ACMD_DEF(killmonster),
  8609. 		ACMD_DEF(killmonster2),
  8610. 		ACMD_DEF(refine),
  8611. 		ACMD_DEF(produce),
  8612. 		ACMD_DEF(memo),
  8613. 		ACMD_DEF(gat),
  8614. 		ACMD_DEF(displaystatus),
  8615. 		ACMD_DEF2("stpoint", statuspoint),
  8616. 		ACMD_DEF2("skpoint", skillpoint),
  8617. 		ACMD_DEF(zeny),
  8618. 		ACMD_DEF2("str", param),
  8619. 		ACMD_DEF2("agi", param),
  8620. 		ACMD_DEF2("vit", param),
  8621. 		ACMD_DEF2("int", param),
  8622. 		ACMD_DEF2("dex", param),
  8623. 		ACMD_DEF2("luk", param),
  8624. 		ACMD_DEF2("glvl", guildlevelup),
  8625. 		ACMD_DEF(makeegg),
  8626. 		ACMD_DEF(hatch),
  8627. 		ACMD_DEF(petfriendly),
  8628. 		ACMD_DEF(pethungry),
  8629. 		ACMD_DEF(petrename),
  8630. 		ACMD_DEF(recall), // + /recall
  8631. 		ACMD_DEF(night),
  8632. 		ACMD_DEF(day),
  8633. 		ACMD_DEF(doom),
  8634. 		ACMD_DEF(doommap),
  8635. 		ACMD_DEF(raise),
  8636. 		ACMD_DEF(raisemap),
  8637. 		ACMD_DEF(kick), // + right click menu for GM "(name) force to quit"
  8638. 		ACMD_DEF(kickall),
  8639. 		ACMD_DEF(allskill),
  8640. 		ACMD_DEF(questskill),
  8641. 		ACMD_DEF(lostskill),
  8642. 		ACMD_DEF(spiritball),
  8643. 		ACMD_DEF(party),
  8644. 		ACMD_DEF(guild),
  8645. 		ACMD_DEF(agitstart),
  8646. 		ACMD_DEF(agitend),
  8647. 		ACMD_DEF(mapexit),
  8648. 		ACMD_DEF(idsearch),
  8649. 		ACMD_DEF(broadcast), // + /b and /nb
  8650. 		ACMD_DEF(localbroadcast), // + /lb and /nlb
  8651. 		ACMD_DEF(recallall),
  8652. 		ACMD_DEF(reloaditemdb),
  8653. 		ACMD_DEF(reloadmobdb),
  8654. 		ACMD_DEF(reloadskilldb),
  8655. 		ACMD_DEF(reloadscript),
  8656. 		ACMD_DEF(reloadatcommand),
  8657. 		ACMD_DEF(reloadbattleconf),
  8658. 		ACMD_DEF(reloadstatusdb),
  8659. 		ACMD_DEF(reloadpcdb),
  8660. 		ACMD_DEF(reloadmotd),
  8661. 		ACMD_DEF(mapinfo),
  8662. 		ACMD_DEF(dye),
  8663. 		ACMD_DEF2("hairstyle", hair_style),
  8664. 		ACMD_DEF2("haircolor", hair_color),
  8665. 		ACMD_DEF2("allstats", stat_all),
  8666. 		ACMD_DEF2("block", char_block),
  8667. 		ACMD_DEF2("ban", char_ban),
  8668. 		ACMD_DEF2("unblock", char_unblock),
  8669. 		ACMD_DEF2("unban", char_unban),
  8670. 		ACMD_DEF2("mount", mount_peco),
  8671. 		ACMD_DEF(guildspy),
  8672. 		ACMD_DEF(partyspy),
  8673. 		ACMD_DEF(repairall),
  8674. 		ACMD_DEF(guildrecall),
  8675. 		ACMD_DEF(partyrecall),
  8676. 		ACMD_DEF(nuke),
  8677. 		ACMD_DEF(shownpc),
  8678. 		ACMD_DEF(hidenpc),
  8679. 		ACMD_DEF(loadnpc),
  8680. 		ACMD_DEF(unloadnpc),
  8681. 		ACMD_DEF2("time", servertime),
  8682. 		ACMD_DEF(jail),
  8683. 		ACMD_DEF(unjail),
  8684. 		ACMD_DEF(jailfor),
  8685. 		ACMD_DEF(jailtime),
  8686. 		ACMD_DEF(disguise),
  8687. 		ACMD_DEF(undisguise),
  8688. 		ACMD_DEF(email),
  8689. 		ACMD_DEF(effect),
  8690. 		ACMD_DEF(follow),
  8691. 		ACMD_DEF(addwarp),
  8692. 		ACMD_DEF(skillon),
  8693. 		ACMD_DEF(skilloff),
  8694. 		ACMD_DEF(killer),
  8695. 		ACMD_DEF(npcmove),
  8696. 		ACMD_DEF(killable),
  8697. 		ACMD_DEF(dropall),
  8698. 		ACMD_DEF(storeall),
  8699. 		ACMD_DEF(skillid),
  8700. 		ACMD_DEF(useskill),
  8701. 		ACMD_DEF(displayskill),
  8702. 		ACMD_DEF(snow),
  8703. 		ACMD_DEF(sakura),
  8704. 		ACMD_DEF(clouds),
  8705. 		ACMD_DEF(clouds2),
  8706. 		ACMD_DEF(fog),
  8707. 		ACMD_DEF(fireworks),
  8708. 		ACMD_DEF(leaves),
  8709. 		ACMD_DEF(summon),
  8710. 		ACMD_DEF(adjgroup),
  8711. 		ACMD_DEF(trade),
  8712. 		ACMD_DEF(send),
  8713. 		ACMD_DEF(setbattleflag),
  8714. 		ACMD_DEF(unmute),
  8715. 		ACMD_DEF(clearweather),
  8716. 		ACMD_DEF(uptime),
  8717. 		ACMD_DEF(changesex),
  8718. 		ACMD_DEF(mute),
  8719. 		ACMD_DEF(refresh),
  8720. 		ACMD_DEF(identify),
  8721. 		ACMD_DEF(gmotd),
  8722. 		ACMD_DEF(misceffect),
  8723. 		ACMD_DEF(mobsearch),
  8724. 		ACMD_DEF(cleanmap),
  8725. 		ACMD_DEF(npctalk),
  8726. 		ACMD_DEF(pettalk),
  8727. 		ACMD_DEF(users),
  8728. 		ACMD_DEF(reset),
  8729. 		ACMD_DEF(skilltree),
  8730. 		ACMD_DEF(marry),
  8731. 		ACMD_DEF(divorce),
  8732. 		ACMD_DEF(sound),
  8733. 		ACMD_DEF(undisguiseall),
  8734. 		ACMD_DEF(disguiseall),
  8735. 		ACMD_DEF(changelook),
  8736. 		ACMD_DEF(autoloot),
  8737. 		ACMD_DEF2("alootid", autolootitem),
  8738. 		ACMD_DEF(mobinfo),
  8739. 		ACMD_DEF(exp),
  8740. 		ACMD_DEF(adopt),
  8741. 		ACMD_DEF(version),
  8742. 		ACMD_DEF(mutearea),
  8743. 		ACMD_DEF(rates),
  8744. 		ACMD_DEF(iteminfo),
  8745. 		ACMD_DEF(whodrops),
  8746. 		ACMD_DEF(whereis),
  8747. 		ACMD_DEF(mapflag),
  8748. 		ACMD_DEF(me),
  8749. 		ACMD_DEF(monsterignore),
  8750. 		ACMD_DEF(fakename),
  8751. 		ACMD_DEF(size),
  8752. 		ACMD_DEF(showexp),
  8753. 		ACMD_DEF(showzeny),
  8754. 		ACMD_DEF(showdelay),
  8755. 		ACMD_DEF(autotrade),
  8756. 		ACMD_DEF(changegm),
  8757. 		ACMD_DEF(changeleader),
  8758. 		ACMD_DEF(partyoption),
  8759. 		ACMD_DEF(invite),
  8760. 		ACMD_DEF(duel),
  8761. 		ACMD_DEF(leave),
  8762. 		ACMD_DEF(accept),
  8763. 		ACMD_DEF(reject),
  8764. 		ACMD_DEF(main),
  8765. 		ACMD_DEF(clone),
  8766. 		ACMD_DEF2("slaveclone", clone),
  8767. 		ACMD_DEF2("evilclone", clone),
  8768. 		ACMD_DEF(tonpc),
  8769. 		ACMD_DEF(commands),
  8770. 		ACMD_DEF(noask),
  8771. 		ACMD_DEF(request),
  8772. 		ACMD_DEF(homlevel),
  8773. 		ACMD_DEF(homevolution),
  8774. 		ACMD_DEF(makehomun),
  8775. 		ACMD_DEF(homfriendly),
  8776. 		ACMD_DEF(homhungry),
  8777. 		ACMD_DEF(homtalk),
  8778. 		ACMD_DEF(hominfo),
  8779. 		ACMD_DEF(homstats),
  8780. 		ACMD_DEF(homshuffle),
  8781. 		ACMD_DEF(showmobs),
  8782. 		ACMD_DEF(feelreset),
  8783. 		ACMD_DEF(auction),
  8784. 		ACMD_DEF(mail),
  8785. 		ACMD_DEF2("noks", ksprotection),
  8786. 		ACMD_DEF(allowks),
  8787. 		ACMD_DEF(cash),
  8788. 		ACMD_DEF2("points", cash),
  8789. 		ACMD_DEF(agitstart2),
  8790. 		ACMD_DEF(agitend2),
  8791. 		ACMD_DEF2("skreset", resetskill),
  8792. 		ACMD_DEF2("streset", resetstat),
  8793. 		ACMD_DEF2("storagelist", itemlist),
  8794. 		ACMD_DEF2("cartlist", itemlist),
  8795. 		ACMD_DEF2("itemlist", itemlist),
  8796. 		ACMD_DEF(stats),
  8797. 		ACMD_DEF(delitem),
  8798. 		ACMD_DEF(charcommands),
  8799. 		ACMD_DEF(font),
  8800. 		ACMD_DEF(accinfo),
  8801. 		ACMD_DEF(set),
  8802. 		/**
  8803. 		 * For Testing Purposes, not going to be here after we're done.
  8804. 		 **/
  8805. 		ACMD_DEF2("newmount", new_mount),
  8806. 	};
  8807. 	AtCommandInfo* atcommand;
  8808. 	int i;
  8809.  
  8810. 	for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) {
  8811. 		if(atcommand_exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK
  8812. 			ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command);
  8813. 			continue;
  8814. 		}
  8815. 		CREATE(atcommand, AtCommandInfo, 1);
  8816. 		safestrncpy(atcommand->command, atcommand_base[i].command, sizeof(atcommand->command));
  8817. 		atcommand->func = atcommand_base[i].func;
  8818. 		strdb_put(atcommand_db, atcommand->command, atcommand);
  8819. 	}
  8820. 	return;
  8821. }
  8822.  
  8823. /*==========================================
  8824.  * Command lookup functions
  8825.  *------------------------------------------*/
  8826. bool atcommand_exists(const char* name)
  8827. {
  8828. 	return strdb_exists(atcommand_db, name);
  8829. }
  8830.  
  8831. static AtCommandInfo* get_atcommandinfo_byname(const char *name)
  8832. {
  8833. 	if (strdb_exists(atcommand_db, name))
  8834. 		return (AtCommandInfo*)strdb_get(atcommand_db, name);
  8835. 	return NULL;
  8836. }
  8837.  
  8838. static const char* atcommand_checkalias(const char *aliasname)
  8839. {
  8840. 	AliasInfo *alias_info = NULL;
  8841. 	if ((alias_info = (AliasInfo*)strdb_get(atcommand_alias_db, aliasname)) != NULL)
  8842. 		return alias_info->command->command;
  8843. 	return aliasname;
  8844. }
  8845.  
  8846. /// AtCommand suggestion
  8847. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand) {
  8848. 	DBIterator* atcommand_iter;
  8849. 	DBIterator* alias_iter;
  8850. 	AtCommandInfo* command_info = NULL;
  8851. 	AliasInfo* alias_info = NULL;
  8852. 	AtCommandType type;
  8853. 	char* suggestions[MAX_SUGGESTIONS];
  8854. 	int count = 0;
  8855.  
  8856. 	if (!battle_config.atcommand_suggestions_enabled)
  8857. 		return;
  8858.  
  8859. 	atcommand_iter = db_iterator(atcommand_db);
  8860. 	alias_iter = db_iterator(atcommand_alias_db);	
  8861.  
  8862. 	if (atcommand)
  8863. 		type = COMMAND_ATCOMMAND;
  8864. 	else
  8865. 		type = COMMAND_CHARCOMMAND;
  8866.  
  8867.  
  8868. 	// First match the beginnings of the commands
  8869. 	for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter) && count < MAX_SUGGESTIONS; command_info = dbi_next(atcommand_iter)) {
  8870. 		if ( strstr(command_info->command, name) == command_info->command && pc_can_use_command(sd, command_info->command, type) )
  8871. 		{
  8872. 			suggestions[count] = command_info->command;
  8873. 			++count;
  8874. 		}
  8875. 	}
  8876.  
  8877. 	for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter) && count < MAX_SUGGESTIONS; alias_info = dbi_next(alias_iter)) {
  8878. 		if ( strstr(alias_info->alias, name) == alias_info->alias && pc_can_use_command(sd, alias_info->command->command, type) )
  8879. 		{
  8880. 			suggestions[count] = alias_info->alias;
  8881. 			++count;
  8882. 		}
  8883. 	}
  8884.  
  8885. 	// Fill up the space left, with full matches
  8886. 	for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter) && count < MAX_SUGGESTIONS; command_info = dbi_next(atcommand_iter)) {
  8887. 		if ( strstr(command_info->command, name) != NULL && pc_can_use_command(sd, command_info->command, type) )
  8888. 		{
  8889. 			suggestions[count] = command_info->command;
  8890. 			++count;
  8891. 		}
  8892. 	}
  8893.  
  8894. 	for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter) && count < MAX_SUGGESTIONS; alias_info = dbi_next(alias_iter)) {
  8895. 		if ( strstr(alias_info->alias, name) != NULL && pc_can_use_command(sd, alias_info->command->command, type) )
  8896. 		{
  8897. 			suggestions[count] = alias_info->alias;
  8898. 			++count;
  8899. 		}
  8900. 	}
  8901.  
  8902. 	if (count > 0)
  8903. 	{
  8904. 		char buffer[512];
  8905. 		int i;
  8906.  
  8907. 		strcpy(buffer, msg_txt(205));
  8908. 		strcat(buffer,"\n");
  8909.  
  8910. 		for(i=0; i < count; ++i)
  8911. 		{
  8912. 			strcat(buffer,suggestions[i]);
  8913. 			strcat(buffer," ");
  8914. 		}
  8915.  
  8916. 		clif_displaymessage(sd->fd, buffer);
  8917. 	}
  8918.  
  8919. 	dbi_destroy(atcommand_iter);
  8920. 	dbi_destroy(alias_iter);
  8921. }
  8922.  
  8923. /// Executes an at-command.
  8924. bool is_atcommand(const int fd, struct map_session_data* sd, const char* message, int type)
  8925. {
  8926. 	char charname[NAME_LENGTH], params[100];
  8927. 	char charname2[NAME_LENGTH], params2[100];
  8928. 	char command[100];
  8929. 	char output[CHAT_SIZE_MAX];
  8930.  
  8931. 	//Reconstructed message
  8932. 	char atcmd_msg[CHAT_SIZE_MAX];
  8933.  
  8934. 	TBL_PC * ssd = NULL; //sd for target
  8935. 	AtCommandInfo * info;
  8936.  
  8937. 	nullpo_retr(false, sd);
  8938.  
  8939. 	//Shouldn't happen
  8940. 	if ( !message || !*message )
  8941. 		return false;
  8942.  
  8943. 	//Block NOCHAT but do not display it as a normal message
  8944. 	if ( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCOMMAND )
  8945. 		return true;
  8946.  
  8947. 	// skip 10/11-langtype's codepage indicator, if detected
  8948. 	if ( message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand_symbol || message[3] == charcommand_symbol) )
  8949. 		message += 3;
  8950.  
  8951. 	//Should display as a normal message
  8952. 	if ( *message != atcommand_symbol && *message != charcommand_symbol )
  8953. 		return false;
  8954.  
  8955. 	// type value 0 = server invoked: bypass restrictions
  8956. 	// 1 = player invoked
  8957. 	if ( type == 1) {
  8958. 		//Commands are disabled on maps flagged as 'nocommand'
  8959. 		if ( map[sd->bl.m].nocommand && pc_get_group_level(sd) < map[sd->bl.m].nocommand ) {
  8960. 			clif_displaymessage(fd, msg_txt(143));
  8961. 			return false;
  8962. 		}
  8963. 	}
  8964.  
  8965. 	if (*message == charcommand_symbol) {
  8966. 		do {
  8967. 			int x, y, z;
  8968.  
  8969. 			//Checks to see if #command has a name or a name + parameters.
  8970. 			x = sscanf(message, "%99s \"%23[^\"]\" %99[^\n]", command, charname, params);
  8971. 			y = sscanf(message, "%99s %23s %99[^\n]", command, charname2, params2);
  8972.  
  8973. 			//z always has the value of the scan that was successful
  8974. 			z = ( x > 1 ) ? x : y;
  8975.  
  8976. 			//#command + name means the sufficient target was used and anything else after
  8977. 			//can be looked at by the actual command function since most scan to see if the
  8978. 			//right parameters are used.
  8979. 			if ( x > 2 ) {
  8980. 				sprintf(atcmd_msg, "%s %s", command, params);
  8981. 				break;
  8982. 			}
  8983. 			else if ( y > 2 ) {
  8984. 				sprintf(atcmd_msg, "%s %s", command, params2);
  8985. 				break;
  8986. 			}
  8987. 			//Regardless of what style the #command is used, if it's correct, it will always have
  8988. 			//this value if there is no parameter. Send it as just the #command
  8989. 			else if ( z == 2 ) {
  8990. 				sprintf(atcmd_msg, "%s", command);
  8991. 				break;
  8992. 			}
  8993.  
  8994. 			sprintf(output, "Charcommand failed. Usage: %c<command> <char name> <params>.", charcommand_symbol);
  8995. 			clif_displaymessage(fd, output);
  8996. 			return true;
  8997. 		} while(0);
  8998. 	}
  8999. 	else if (*message == atcommand_symbol) {
  9000. 		//atcmd_msg is constructed above differently for charcommands
  9001. 		//it's copied from message if not a charcommand so it can 
  9002. 		//pass through the rest of the code compatible with both symbols
  9003. 		sprintf(atcmd_msg, "%s", message);
  9004. 	}
  9005.  
  9006. 	//Clearing these to be used once more. 
  9007. 	memset(command, '\0', sizeof(command));
  9008. 	memset(params, '\0', sizeof(params));
  9009.  
  9010. 	//check to see if any params exist within this command
  9011. 	if( sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2 )
  9012. 		params[0] = '\0';
  9013.  
  9014. 	//Grab the command information and check for the proper GM level required to use it or if the command exists
  9015. 	info = get_atcommandinfo_byname(atcommand_checkalias(command + 1));
  9016. 	if (info == NULL)
  9017. 	{
  9018. 		if( pc_get_group_level(sd) ) { // TODO: remove or replace with proper permission
  9019. 			sprintf(output, msg_txt(153), command); // "%s is Unknown Command."
  9020. 			clif_displaymessage(fd, output);
  9021. 			atcommand_get_suggestions(sd, command + 1, *message == atcommand_symbol);
  9022. 			return true;
  9023. 		} else
  9024. 			return false;
  9025. 	}
  9026.  
  9027. 	// type == 1 : player invoked
  9028. 	if (type == 1) {
  9029. 		if ((*command == atcommand_symbol && !pc_can_use_command(sd, atcommand_checkalias(command + 1), COMMAND_ATCOMMAND)) ||
  9030. 		    (*command == charcommand_symbol && !pc_can_use_command(sd, atcommand_checkalias(command + 1), COMMAND_CHARCOMMAND))) {
  9031. 			return false;
  9032. 		}
  9033. 	}
  9034.  
  9035. 	// Check if target is valid only if confirmed that player can use command.
  9036. 	if (*message == charcommand_symbol &&
  9037. 	    (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  9038. 		sprintf(output, "%s failed. Player not found.", command);
  9039. 		clif_displaymessage(fd, output);
  9040. 		return true;
  9041. 	}
  9042.  
  9043. 	//Attempt to use the command
  9044. 	if ( (info->func(fd, (*atcmd_msg == atcommand_symbol) ? sd : ssd, command, params) != 0) )
  9045. 	{
  9046. 		sprintf(output,msg_txt(154), command); // %s failed.
  9047. 		clif_displaymessage(fd, output);
  9048. 		return true;
  9049. 	}
  9050.  
  9051. 	//Log only if successful.
  9052. 	if ( *atcmd_msg == atcommand_symbol )
  9053. 		log_atcommand(sd, atcmd_msg);
  9054. 	else if ( *atcmd_msg == charcommand_symbol )
  9055. 		log_atcommand(sd, message);
  9056.  
  9057. 	return true;
  9058. }
  9059.  
  9060. /*==========================================
  9061.  *
  9062.  *------------------------------------------*/
  9063. static void atcommand_config_read(const char* config_filename)
  9064. {
  9065. 	config_setting_t *aliases = NULL, *help = NULL;
  9066. 	const char *symbol = NULL;
  9067. 	int num_aliases = 0;
  9068.  
  9069. 	if (conf_read_file(&atcommand_config, config_filename))
  9070. 		return;
  9071.  
  9072. 	// Command symbols
  9073. 	if (config_lookup_string(&atcommand_config, "atcommand_symbol", &symbol)) {
  9074. 		if (ISPRINT(*symbol) && // no control characters
  9075. 			*symbol != '/' && // symbol of client commands
  9076. 			*symbol != '%' && // symbol of party chat
  9077. 			*symbol != '$' && // symbol of guild chat
  9078. 			*symbol != charcommand_symbol) 
  9079. 			atcommand_symbol = *symbol;
  9080. 	}
  9081.  
  9082. 	if (config_lookup_string(&atcommand_config, "charcommand_symbol", &symbol)) {
  9083. 		if (ISPRINT(*symbol) && // no control characters
  9084. 			*symbol != '/' && // symbol of client commands
  9085. 			*symbol != '%' && // symbol of party chat
  9086. 			*symbol != '$' && // symbol of guild chat
  9087. 			*symbol != atcommand_symbol)
  9088. 			charcommand_symbol = *symbol;
  9089. 	}
  9090.  
  9091. 	// Command aliases
  9092. 	aliases = config_lookup(&atcommand_config, "aliases");
  9093. 	if (aliases != NULL) {
  9094. 		int i = 0;
  9095. 		int count = config_setting_length(aliases);
  9096.  
  9097. 		for (i = 0; i < count; ++i) {
  9098. 			config_setting_t *command = NULL;
  9099. 			const char *commandname = NULL;
  9100. 			int j = 0, alias_count = 0;
  9101. 			AtCommandInfo *commandinfo = NULL;
  9102.  
  9103. 			command = config_setting_get_elem(aliases, i);
  9104. 			if (config_setting_type(command) != CONFIG_TYPE_ARRAY)
  9105. 				continue;
  9106. 			commandname = config_setting_name(command);
  9107. 			if (!atcommand_exists(commandname)) {
  9108. 				ShowConfigWarning(command, "atcommand_config_read: can not set alias for non-existent command %s", commandname);
  9109. 				continue;
  9110. 			}
  9111. 			commandinfo = get_atcommandinfo_byname(commandname);
  9112. 			alias_count = config_setting_length(command);
  9113. 			for (j = 0; j < alias_count; ++j) {
  9114. 				const char *alias = config_setting_get_string_elem(command, j);
  9115. 				if (alias != NULL) {
  9116. 					AliasInfo *alias_info;
  9117. 					if (strdb_exists(atcommand_alias_db, alias)) {
  9118. 						ShowConfigWarning(command, "atcommand_config_read: alias %s already exists", alias);
  9119. 						continue;
  9120. 					}
  9121. 					CREATE(alias_info, AliasInfo, 1);
  9122. 					alias_info->command = commandinfo;
  9123. 					safestrncpy(alias_info->alias, alias, sizeof(alias_info->alias));
  9124. 					strdb_put(atcommand_alias_db, alias, alias_info);
  9125. 					++num_aliases;
  9126. 				}
  9127. 			}
  9128. 		}
  9129. 	}
  9130.  
  9131. 	// Commands help
  9132. 	// We only check if all commands exist
  9133. 	help = config_lookup(&atcommand_config, "help");
  9134. 	if (help != NULL) {
  9135. 		int count = config_setting_length(help);
  9136. 		int i;
  9137.  
  9138. 		for (i = 0; i < count; ++i) {
  9139. 			config_setting_t *command = NULL;
  9140. 			const char *commandname = NULL;
  9141.  
  9142. 			command = config_setting_get_elem(help, i);
  9143. 			commandname = config_setting_name(command);
  9144. 			if (!atcommand_exists(commandname))
  9145. 				ShowConfigWarning(command, "atcommand_config_read: command %s does not exist", commandname);
  9146. 		}
  9147. 	}
  9148.  
  9149. 	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' command aliases in '"CL_WHITE"%s"CL_RESET"'.\n", num_aliases, config_filename);
  9150. 	return;
  9151. }
  9152.  
  9153. void atcommand_db_clear(void)
  9154. {
  9155. 	if (atcommand_db != NULL)
  9156. 		db_destroy(atcommand_db);
  9157. 	if (atcommand_alias_db != NULL)
  9158. 		db_destroy(atcommand_alias_db);
  9159. }
  9160.  
  9161. void atcommand_doload(void)
  9162. {
  9163. 	atcommand_db_clear();
  9164. 	atcommand_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  9165. 	atcommand_alias_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  9166. 	atcommand_basecommands(); //fills initial atcommand_db with known commands
  9167. 	atcommand_config_read(ATCOMMAND_CONF_FILENAME);
  9168. }
  9169.  
  9170. void do_init_atcommand(void)
  9171. {
  9172. 	atcommand_doload();
  9173. }
  9174.  
  9175. void do_final_atcommand(void)
  9176. {
  9177. 	atcommand_db_clear();
  9178. }
Viewed 1256 times, submitted by Guest.