viewing paste atcommand.c | C++

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. int atcmd_binding_count = 0;
  61.  
  62. struct AtCommandInfo {
  63. 	char command[ATCOMMAND_LENGTH]; 
  64. 	AtCommandFunc func;
  65. 	char* at_groups;/* quick @commands "can-use" lookup */
  66. 	char* char_groups;/* quick @charcommands "can-use" lookup */
  67. };
  68.  
  69. struct AliasInfo {
  70. 	AtCommandInfo *command;
  71. 	char alias[ATCOMMAND_LENGTH];
  72. };
  73.  
  74.  
  75. char atcommand_symbol = '@'; // first char of the commands
  76. char charcommand_symbol = '#';
  77.  
  78. static char* msg_table[MAX_MSG]; // Server messages (0-499 reserved for GM commands, 500-999 reserved for others)
  79. static DBMap* atcommand_db = NULL; //name -> AtCommandInfo
  80. static DBMap* atcommand_alias_db = NULL; //alias -> AtCommandInfo
  81. static config_t atcommand_config;
  82.  
  83. static char atcmd_output[CHAT_SIZE_MAX];
  84. static char atcmd_player_name[NAME_LENGTH];
  85.  
  86. static AtCommandInfo* get_atcommandinfo_byname(const char *name); // @help
  87. static const char* atcommand_checkalias(const char *aliasname); // @help
  88. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand); // @help
  89.  
  90. // @commands (script-based)
  91. struct atcmd_binding_data* get_atcommandbind_byname(const char* name) {
  92. 	int i = 0;
  93.  
  94. 	if( *name == atcommand_symbol || *name == charcommand_symbol )
  95. 		name++; // for backwards compatibility
  96.  
  97. 	ARR_FIND( 0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command, name) == 0 );
  98.  
  99. 	return ( i < atcmd_binding_count ) ? atcmd_binding[i] : NULL;
  100. }
  101.  
  102. //-----------------------------------------------------------
  103. // Return the message string of the specified number by [Yor]
  104. //-----------------------------------------------------------
  105. const char* msg_txt(int msg_number)
  106. {
  107. 	if (msg_number >= 0 && msg_number < MAX_MSG &&
  108. 	    msg_table[msg_number] != NULL && msg_table[msg_number][0] != '\0')
  109. 		return msg_table[msg_number];
  110.  
  111. 	return "??";
  112. }
  113.  
  114. /*==========================================
  115.  * Read Message Data
  116.  *------------------------------------------*/
  117. int msg_config_read(const char* cfgName)
  118. {
  119. 	int msg_number;
  120. 	char line[1024], w1[1024], w2[1024];
  121. 	FILE *fp;
  122. 	static int called = 1;
  123.  
  124. 	if ((fp = fopen(cfgName, "r")) == NULL) {
  125. 		ShowError("Messages file not found: %s\n", cfgName);
  126. 		return 1;
  127. 	}
  128.  
  129. 	if ((--called) == 0)
  130. 		memset(msg_table, 0, sizeof(msg_table[0]) * MAX_MSG);
  131.  
  132. 	while(fgets(line, sizeof(line), fp))
  133. 	{
  134. 		if (line[0] == '/' && line[1] == '/')
  135. 			continue;
  136. 		if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
  137. 			continue;
  138.  
  139. 		if (strcmpi(w1, "import") == 0)
  140. 			msg_config_read(w2);
  141. 		else
  142. 		{
  143. 			msg_number = atoi(w1);
  144. 			if (msg_number >= 0 && msg_number < MAX_MSG)
  145. 			{
  146. 				if (msg_table[msg_number] != NULL)
  147. 					aFree(msg_table[msg_number]);
  148. 				msg_table[msg_number] = (char *)aMalloc((strlen(w2) + 1)*sizeof (char));
  149. 				strcpy(msg_table[msg_number],w2);
  150. 			}
  151. 		}
  152. 	}
  153.  
  154. 	fclose(fp);
  155.  
  156. 	return 0;
  157. }
  158.  
  159. /*==========================================
  160.  * Cleanup Message Data
  161.  *------------------------------------------*/
  162. void do_final_msg(void)
  163. {
  164. 	int i;
  165. 	for (i = 0; i < MAX_MSG; i++)
  166. 		aFree(msg_table[i]);
  167. }
  168.  
  169. /**
  170.  * retrieves the help string associated with a given command.
  171.  *
  172.  * @param name the name of the command to retrieve help information for
  173.  * @return the string associated with the command, or NULL
  174.  */
  175. static const char* atcommand_help_string(const char* name)
  176. {
  177. 	const char* str = NULL;
  178. 	config_setting_t* info;
  179.  
  180. 	if( *name == atcommand_symbol || *name == charcommand_symbol )
  181. 	{// remove the prefix symbol for the raw name of the command
  182. 		name ++;
  183. 	}
  184.  
  185. 	// attept to find the first default help command
  186. 	info = config_lookup(&atcommand_config, "help");
  187.  
  188. 	if( info == NULL )
  189. 	{// failed to find the help property in the configuration file
  190. 		return NULL;
  191. 	}
  192.  
  193. 	if( !config_setting_lookup_string( info, name, &str ) )
  194. 	{// failed to find the matching help string
  195. 		return NULL;
  196. 	}
  197.  
  198. 	// push the result from the method
  199. 	return str;
  200. }
  201.  
  202.  
  203. /*==========================================
  204.  * @send (used for testing packet sends from the client)
  205.  *------------------------------------------*/
  206. ACMD_FUNC(send)
  207. {
  208. 	int len=0,off,end,type;
  209. 	long num;
  210.  
  211. 	// read message type as hex number (without the 0x)
  212. 	if(!message || !*message ||
  213. 			!((sscanf(message, "len %x", &type)==1 && (len=1))
  214. 			|| sscanf(message, "%x", &type)==1) )
  215. 	{
  216. 		clif_displaymessage(fd, "Usage:");
  217. 		clif_displaymessage(fd, "	@send len <packet hex number>");
  218. 		clif_displaymessage(fd, "	@send <packet hex number> {<value>}*");
  219. 		clif_displaymessage(fd, "	Value: <type=B(default),W,L><number> or S<length>\"<string>\"");
  220. 		return -1;
  221. 	}
  222.  
  223. #define PARSE_ERROR(error,p) \
  224. 	{\
  225. 		clif_displaymessage(fd, (error));\
  226. 		sprintf(atcmd_output, ">%s", (p));\
  227. 		clif_displaymessage(fd, atcmd_output);\
  228. 	}
  229. //define PARSE_ERROR
  230.  
  231. #define CHECK_EOS(p) \
  232. 	if(*(p) == 0){\
  233. 		clif_displaymessage(fd, "Unexpected end of string");\
  234. 		return -1;\
  235. 	}
  236. //define CHECK_EOS
  237.  
  238. #define SKIP_VALUE(p) \
  239. 	{\
  240. 		while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
  241. 		while(*(p) && ISSPACE(*(p)))  ++(p); /* space */\
  242. 	}
  243. //define SKIP_VALUE
  244.  
  245. #define GET_VALUE(p,num) \
  246. 	{\
  247. 		if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
  248. 			PARSE_ERROR("Invalid number in:",(p));\
  249. 			return -1;\
  250. 		}\
  251. 	}
  252. //define GET_VALUE
  253.  
  254. 	if (type > 0 && type < MAX_PACKET_DB) {
  255.  
  256. 		if(len)
  257. 		{// show packet length
  258. 			sprintf(atcmd_output, "Packet 0x%x length: %d", type, packet_db[sd->packet_ver][type].len);
  259. 			clif_displaymessage(fd, atcmd_output);
  260. 			return 0;
  261. 		}
  262.  
  263. 		len=packet_db[sd->packet_ver][type].len;
  264. 		off=2;
  265. 		if(len == 0)
  266. 		{// unknown packet - ERROR
  267. 			sprintf(atcmd_output, "Unknown packet: 0x%x", type);
  268. 			clif_displaymessage(fd, atcmd_output);
  269. 			return -1;
  270. 		} else if(len == -1)
  271. 		{// dynamic packet
  272. 			len=SHRT_MAX-4; // maximum length
  273. 			off=4;
  274. 		}
  275. 		WFIFOHEAD(fd, len);
  276. 		WFIFOW(fd,0)=TOW(type);
  277.  
  278. 		// parse packet contents
  279. 		SKIP_VALUE(message);
  280. 		while(*message != 0 && off < len){
  281. 			if(ISDIGIT(*message) || *message == '-' || *message == '+')
  282. 			{// default (byte)
  283. 				GET_VALUE(message,num);
  284. 				WFIFOB(fd,off)=TOB(num);
  285. 				++off;
  286. 			} else if(TOUPPER(*message) == 'B')
  287. 			{// byte
  288. 				++message;
  289. 				GET_VALUE(message,num);
  290. 				WFIFOB(fd,off)=TOB(num);
  291. 				++off;
  292. 			} else if(TOUPPER(*message) == 'W')
  293. 			{// word (2 bytes)
  294. 				++message;
  295. 				GET_VALUE(message,num);
  296. 				WFIFOW(fd,off)=TOW(num);
  297. 				off+=2;
  298. 			} else if(TOUPPER(*message) == 'L')
  299. 			{// long word (4 bytes)
  300. 				++message;
  301. 				GET_VALUE(message,num);
  302. 				WFIFOL(fd,off)=TOL(num);
  303. 				off+=4;
  304. 			} else if(TOUPPER(*message) == 'S')
  305. 			{// string - escapes are valid
  306. 				// get string length - num <= 0 means not fixed length (default)
  307. 				++message;
  308. 				if(*message == '"'){
  309. 					num=0;
  310. 				} else {
  311. 					GET_VALUE(message,num);
  312. 					while(*message != '"')
  313. 					{// find start of string
  314. 						if(*message == 0 || ISSPACE(*message)){
  315. 							PARSE_ERROR("Not a string:",message);
  316. 							return -1;
  317. 						}
  318. 						++message;
  319. 					}
  320. 				}
  321.  
  322. 				// parse string
  323. 				++message;
  324. 				CHECK_EOS(message);
  325. 				end=(num<=0? 0: min(off+((int)num),len));
  326. 				for(; *message != '"' && (off < end || end == 0); ++off){
  327. 					if(*message == '\\'){
  328. 						++message;
  329. 						CHECK_EOS(message);
  330. 						switch(*message){
  331. 							case 'a': num=0x07; break; // Bell
  332. 							case 'b': num=0x08; break; // Backspace
  333. 							case 't': num=0x09; break; // Horizontal tab
  334. 							case 'n': num=0x0A; break; // Line feed
  335. 							case 'v': num=0x0B; break; // Vertical tab
  336. 							case 'f': num=0x0C; break; // Form feed
  337. 							case 'r': num=0x0D; break; // Carriage return
  338. 							case 'e': num=0x1B; break; // Escape
  339. 							default:  num=*message; break;
  340. 							case 'x': // Hexadecimal
  341. 							{
  342. 								++message;
  343. 								CHECK_EOS(message);
  344. 								if(!ISXDIGIT(*message)){
  345. 									PARSE_ERROR("Not a hexadecimal digit:",message);
  346. 									return -1;
  347. 								}
  348. 								num=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  349. 								if(ISXDIGIT(*message)){
  350. 									++message;
  351. 									CHECK_EOS(message);
  352. 									num<<=8;
  353. 									num+=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  354. 								}
  355. 								WFIFOB(fd,off)=TOB(num);
  356. 								++message;
  357. 								CHECK_EOS(message);
  358. 								continue;
  359. 							}
  360. 							case '0':
  361. 							case '1':
  362. 							case '2':
  363. 							case '3':
  364. 							case '4':
  365. 							case '5':
  366. 							case '6':
  367. 							case '7': // Octal
  368. 							{
  369. 								num=*message-'0'; // 1st octal digit
  370. 								++message;
  371. 								CHECK_EOS(message);
  372. 								if(ISDIGIT(*message) && *message < '8'){
  373. 									num<<=3;
  374. 									num+=*message-'0'; // 2nd octal digit
  375. 									++message;
  376. 									CHECK_EOS(message);
  377. 									if(ISDIGIT(*message) && *message < '8'){
  378. 										num<<=3;
  379. 										num+=*message-'0'; // 3rd octal digit
  380. 										++message;
  381. 										CHECK_EOS(message);
  382. 									}
  383. 								}
  384. 								WFIFOB(fd,off)=TOB(num);
  385. 								continue;
  386. 							}
  387. 						}
  388. 					} else
  389. 						num=*message;
  390. 					WFIFOB(fd,off)=TOB(num);
  391. 					++message;
  392. 					CHECK_EOS(message);
  393. 				}//for
  394. 				while(*message != '"')
  395. 				{// ignore extra characters
  396. 					++message;
  397. 					CHECK_EOS(message);
  398. 				}
  399.  
  400. 				// terminate the string
  401. 				if(off < end)
  402. 				{// fill the rest with 0's
  403. 					memset(WFIFOP(fd,off),0,end-off);
  404. 					off=end;
  405. 				}
  406. 			} else
  407. 			{// unknown
  408. 				PARSE_ERROR("Unknown type of value in:",message);
  409. 				return -1;
  410. 			}
  411. 			SKIP_VALUE(message);
  412. 		}
  413.  
  414. 		if(packet_db[sd->packet_ver][type].len == -1)
  415. 		{// send dynamic packet
  416. 			WFIFOW(fd,2)=TOW(off);
  417. 			WFIFOSET(fd,off);
  418. 		} else
  419. 		{// send static packet
  420. 			if(off < len)
  421. 				memset(WFIFOP(fd,off),0,len-off);
  422. 			WFIFOSET(fd,len);
  423. 		}
  424. 	} else {
  425. 		clif_displaymessage(fd, msg_txt(259)); // Invalid packet
  426. 		return -1;
  427. 	}
  428. 	sprintf (atcmd_output, msg_txt(258), type, type); // Sent packet 0x%x (%d)
  429. 	clif_displaymessage(fd, atcmd_output);
  430. 	return 0;
  431. #undef PARSE_ERROR
  432. #undef CHECK_EOS
  433. #undef SKIP_VALUE
  434. #undef GET_VALUE
  435. }
  436.  
  437. /*==========================================
  438.  * @rura, @warp, @mapmove
  439.  *------------------------------------------*/
  440. ACMD_FUNC(mapmove)
  441. {
  442. 	char map_name[MAP_NAME_LENGTH_EXT];
  443. 	unsigned short mapindex;
  444. 	short x = 0, y = 0;
  445. 	int m = -1;
  446.  
  447. 	nullpo_retr(-1, sd);
  448.  
  449. 	memset(map_name, '\0', sizeof(map_name));
  450.  
  451. 	if (!message || !*message ||
  452. 		(sscanf(message, "%15s %hd %hd", map_name, &x, &y) < 3 &&
  453. 		 sscanf(message, "%15[^,],%hd,%hd", map_name, &x, &y) < 1)) {
  454.  
  455. 			clif_displaymessage(fd, "Please, enter a map (usage: @warp/@rura/@mapmove <mapname> <x> <y>).");
  456. 			return -1;
  457. 	}
  458.  
  459. 	mapindex = mapindex_name2id(map_name);
  460. 	if (mapindex)
  461. 		m = map_mapindex2mapid(mapindex);
  462.  
  463. 	if (!mapindex) { // m < 0 means on different server! [Kevin]
  464. 		clif_displaymessage(fd, msg_txt(1)); // Map not found.
  465. 		return -1;
  466. 	}
  467.  
  468. 	if ((x || y) && map_getcell(m, x, y, CELL_CHKNOPASS))
  469.   	{	//This is to prevent the pc_setpos call from printing an error.
  470. 		clif_displaymessage(fd, msg_txt(2));
  471. 		if (!map_search_freecell(NULL, m, &x, &y, 10, 10, 1))
  472. 			x = y = 0; //Invalid cell, use random spot.
  473. 	}
  474. 	if (map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  475. 		clif_displaymessage(fd, msg_txt(247));
  476. 		return -1;
  477. 	}
  478. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  479. 		clif_displaymessage(fd, msg_txt(248));
  480. 		return -1;
  481. 	}
  482. 	if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != 0) {
  483. 		clif_displaymessage(fd, msg_txt(1)); // Map not found.
  484. 		return -1;
  485. 	}
  486.  
  487. 	clif_displaymessage(fd, msg_txt(0)); // Warped.
  488. 	return 0;
  489. }
  490.  
  491. /*==========================================
  492.  * Displays where a character is. Corrected version by Silent. [Skotlex]
  493.  *------------------------------------------*/
  494. ACMD_FUNC(where)
  495. {
  496. 	struct map_session_data* pl_sd;
  497.  
  498. 	nullpo_retr(-1, sd);
  499. 	memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  500.  
  501. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  502. 		clif_displaymessage(fd, "Please, enter a player name (usage: @where <char name>).");
  503. 		return -1;
  504. 	}
  505.  
  506. 	pl_sd = map_nick2sd(atcmd_player_name);
  507. 	if (pl_sd == NULL ||
  508. 	    strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 ||
  509. 	    (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > pc_get_group_level(sd) && !pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  510. 	) {
  511. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  512. 		return -1;
  513. 	}
  514.  
  515. 	snprintf(atcmd_output, sizeof atcmd_output, "%s %s %d %d", pl_sd->status.name, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  516. 	clif_displaymessage(fd, atcmd_output);
  517.  
  518. 	return 0;
  519. }
  520.  
  521. /*==========================================
  522.  *
  523.  *------------------------------------------*/
  524. ACMD_FUNC(jumpto)
  525. {
  526. 	struct map_session_data *pl_sd = NULL;
  527.  
  528. 	nullpo_retr(-1, sd);
  529.  
  530. 	if (!message || !*message) {
  531. 		clif_displaymessage(fd, "Please, enter a player name (usage: @jumpto/@warpto/@goto <player name/id>).");
  532. 		return -1;
  533. 	}
  534.  
  535. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  536. 	{
  537. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  538. 		return -1;
  539. 	}
  540.  
  541. 	if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  542. 	{
  543. 		clif_displaymessage(fd, msg_txt(247));	// You are not authorized to warp to this map.
  544. 		return -1;
  545. 	}
  546.  
  547. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  548. 	{
  549. 		clif_displaymessage(fd, msg_txt(248));	// You are not authorized to warp from your current map.
  550. 		return -1;
  551. 	}
  552.  
  553. 	if( pc_isdead(sd) )
  554. 	{
  555. 		clif_displaymessage(fd, msg_txt(664));
  556. 		return -1;
  557. 	}
  558.  
  559. 	pc_setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  560. 	sprintf(atcmd_output, msg_txt(4), pl_sd->status.name); // Jumped to %s
  561.  	clif_displaymessage(fd, atcmd_output);
  562.  
  563. 	return 0;
  564. }
  565.  
  566. /*==========================================
  567.  *
  568.  *------------------------------------------*/
  569. ACMD_FUNC(jump)
  570. {
  571. 	short x = 0, y = 0;
  572.  
  573. 	nullpo_retr(-1, sd);
  574.  
  575. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  576.  
  577. 	sscanf(message, "%hd %hd", &x, &y);
  578.  
  579. 	if (map[sd->bl.m].flag.noteleport && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  580. 		clif_displaymessage(fd, msg_txt(248));	// You are not authorized to warp from your current map.
  581. 		return -1;
  582. 	}
  583.  
  584. 	if( pc_isdead(sd) )
  585. 	{
  586. 		clif_displaymessage(fd, msg_txt(664));
  587. 		return -1;
  588. 	}
  589.  
  590. 	if ((x || y) && map_getcell(sd->bl.m, x, y, CELL_CHKNOPASS))
  591.   	{	//This is to prevent the pc_setpos call from printing an error.
  592. 		clif_displaymessage(fd, msg_txt(2));
  593. 		if (!map_search_freecell(NULL, sd->bl.m, &x, &y, 10, 10, 1))
  594. 			x = y = 0; //Invalid cell, use random spot.
  595. 	}
  596.  
  597. 	pc_setpos(sd, sd->mapindex, x, y, CLR_TELEPORT);
  598. 	sprintf(atcmd_output, msg_txt(5), sd->bl.x, sd->bl.y); // Jumped to %d %d
  599. 	clif_displaymessage(fd, atcmd_output);
  600. 	return 0;
  601. }
  602.  
  603. /*==========================================
  604.  * Display list of online characters with
  605.  * various info.
  606.  *------------------------------------------*/
  607. ACMD_FUNC(who)
  608. {
  609. 	struct map_session_data *pl_sd = NULL;
  610. 	struct s_mapiterator *iter = NULL;
  611. 	char map_name[MAP_NAME_LENGTH_EXT] = "";
  612. 	char player_name[NAME_LENGTH] = "";
  613. 	int count = 0;
  614. 	int level = 0;
  615. 	StringBuf buf;
  616. 	/**
  617. 	 * 1 = @who  : Player name, [Title], [Party name], [Guild name]
  618. 	 * 2 = @who2 : Player name, [Title], BLvl, JLvl, Job
  619. 	 * 3 = @who3 : [CID/AID] Player name [Title], Map, X, Y
  620. 	 */
  621. 	int display_type = 1;
  622. 	int map_id = -1;
  623.  
  624. 	nullpo_retr(-1, sd);
  625.  
  626. 	if (strstr(command, "map") != NULL) {
  627. 		if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map_mapname2mapid(map_name)) < 0)
  628. 			map_id = sd->bl.m;
  629. 	} else {
  630. 		sscanf(message, "%23s", player_name);
  631. 	}
  632.  
  633. 	if (strstr(command, "2") != NULL)
  634. 		display_type = 2;
  635. 	else if (strstr(command, "3") != NULL)
  636. 		display_type = 3;
  637.  
  638. 	level = pc_get_group_level(sd);
  639. 	StringBuf_Init(&buf);
  640.  
  641. 	iter = mapit_getallusers();
  642. 	for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter))	{
  643. 		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
  644. 			if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive
  645. 				|| (map_id >= 0 && pl_sd->bl.m != map_id))
  646. 				continue;
  647. 			switch (display_type) {
  648. 				case 2: {
  649. 					StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  650. 					if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  651. 						StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  652. 					StringBuf_Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level,
  653. 						job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s"
  654. 					break;
  655. 				}
  656. 				case 3: {
  657. 					if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  658. 						StringBuf_Printf(&buf, "(CID:%d/AID:%d) ", pl_sd->status.char_id, pl_sd->status.account_id);
  659. 					StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  660. 					if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  661. 						StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  662. 					StringBuf_Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d"
  663. 					break;
  664. 				}
  665. 				default: {
  666. 					struct party_data *p = party_search(pl_sd->status.party_id);
  667. 					struct guild *g = guild_search(pl_sd->status.guild_id);
  668.  
  669. 					StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  670. 					if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  671. 						StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  672. 					if (p != NULL)
  673. 						StringBuf_Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'"
  674. 					if (g != NULL)
  675. 						StringBuf_Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'"
  676. 					break;
  677. 				}
  678. 			}
  679. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  680. 			StringBuf_Clear(&buf);
  681. 			count++;
  682. 		}
  683. 	}
  684. 	mapit_free(iter);
  685.  
  686. 	if (map_id < 0) {
  687. 		if (count == 0)
  688. 			StringBuf_Printf(&buf, msg_txt(28)); // No player found.
  689. 		else if (count == 1)
  690. 			StringBuf_Printf(&buf, msg_txt(29)); // 1 player found.
  691. 		else
  692. 			StringBuf_Printf(&buf, msg_txt(30), count); // %d players found.
  693. 	} else {
  694. 		if (count == 0)
  695. 			StringBuf_Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'.
  696. 		else if (count == 1)
  697. 			StringBuf_Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'.
  698. 		else
  699. 			StringBuf_Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'.
  700. 	}
  701. 	clif_displaymessage(fd, StringBuf_Value(&buf));
  702. 	StringBuf_Destroy(&buf);
  703. 	return 0;
  704. }
  705.  
  706. /*==========================================
  707.  *
  708.  *------------------------------------------*/
  709. ACMD_FUNC(whogm)
  710. {
  711. 	struct map_session_data* pl_sd;
  712. 	struct s_mapiterator* iter;
  713. 	int j, count;
  714. 	int pl_level, level;
  715. 	char match_text[CHAT_SIZE_MAX];
  716. 	char player_name[NAME_LENGTH];
  717. 	struct guild *g;
  718. 	struct party_data *p;
  719.  
  720. 	nullpo_retr(-1, sd);
  721.  
  722. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  723. 	memset(match_text, '\0', sizeof(match_text));
  724. 	memset(player_name, '\0', sizeof(player_name));
  725.  
  726. 	if (sscanf(message, "%199[^\n]", match_text) < 1)
  727. 		strcpy(match_text, "");
  728. 	for (j = 0; match_text[j]; j++)
  729. 		match_text[j] = TOLOWER(match_text[j]);
  730.  
  731. 	count = 0;
  732. 	level = pc_get_group_level(sd);
  733.  
  734. 	iter = mapit_getallusers();
  735. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  736. 	{
  737. 		pl_level = pc_get_group_level(pl_sd);
  738. 		if (!pl_level)
  739. 			continue;
  740.  
  741. 		if (match_text[0])
  742. 		{
  743. 			memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
  744. 			for (j = 0; player_name[j]; j++)
  745. 				player_name[j] = TOLOWER(player_name[j]);
  746. 		  	// search with no case sensitive
  747. 			if (strstr(player_name, match_text) == NULL)
  748. 				continue;
  749. 		}
  750. 		if (pl_level > level) {
  751. 			if (pl_sd->sc.option & OPTION_INVISIBLE)
  752. 				continue;
  753. 			sprintf(atcmd_output, "Name: %s (GM)", pl_sd->status.name);
  754. 			clif_displaymessage(fd, atcmd_output);
  755. 			count++;
  756. 			continue;
  757. 		}
  758.  
  759. 		sprintf(atcmd_output, "Name: %s (GM:%d) | Location: %s %d %d",
  760. 			pl_sd->status.name, pl_level,
  761. 			mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  762. 		clif_displaymessage(fd, atcmd_output);
  763.  
  764. 		sprintf(atcmd_output, "       BLvl: %d | Job: %s (Lvl: %d)",
  765. 			pl_sd->status.base_level,
  766. 			job_name(pl_sd->status.class_), pl_sd->status.job_level);
  767. 		clif_displaymessage(fd, atcmd_output);
  768.  
  769. 		p = party_search(pl_sd->status.party_id);
  770. 		g = guild_search(pl_sd->status.guild_id);
  771.  
  772. 		sprintf(atcmd_output,"       Party: '%s' | Guild: '%s'",
  773. 			p?p->party.name:"None", g?g->name:"None");
  774.  
  775. 		clif_displaymessage(fd, atcmd_output);
  776. 		count++;
  777. 	}
  778. 	mapit_free(iter);
  779.  
  780. 	if (count == 0)
  781. 		clif_displaymessage(fd, msg_txt(150)); // No GM found.
  782. 	else if (count == 1)
  783. 		clif_displaymessage(fd, msg_txt(151)); // 1 GM found.
  784. 	else {
  785. 		sprintf(atcmd_output, msg_txt(152), count); // %d GMs found.
  786. 		clif_displaymessage(fd, atcmd_output);
  787. 	}
  788.  
  789. 	return 0;
  790. }
  791.  
  792. /*==========================================
  793.  *
  794.  *------------------------------------------*/
  795. ACMD_FUNC(save)
  796. {
  797. 	nullpo_retr(-1, sd);
  798.  
  799. 	pc_setsavepoint(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  800. 	if (sd->status.pet_id > 0 && sd->pd)
  801. 		intif_save_petdata(sd->status.account_id, &sd->pd->pet);
  802.  
  803. 	chrif_save(sd,0);
  804.  
  805. 	clif_displaymessage(fd, msg_txt(6)); // Your save point has been changed.
  806.  
  807. 	return 0;
  808. }
  809.  
  810. /*==========================================
  811.  *
  812.  *------------------------------------------*/
  813. ACMD_FUNC(load)
  814. {
  815. 	int m;
  816.  
  817. 	nullpo_retr(-1, sd);
  818.  
  819. 	m = map_mapindex2mapid(sd->status.save_point.map);
  820. 	if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  821. 		clif_displaymessage(fd, msg_txt(249));	// You are not authorized to warp to your save map.
  822. 		return -1;
  823. 	}
  824. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  825. 		clif_displaymessage(fd, msg_txt(248));	// You are not authorized to warp from your current map.
  826. 		return -1;
  827. 	}
  828.  
  829. 	pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_OUTSIGHT);
  830. 	clif_displaymessage(fd, msg_txt(7)); // Warping to save point..
  831.  
  832. 	return 0;
  833. }
  834.  
  835. /*==========================================
  836.  *
  837.  *------------------------------------------*/
  838. ACMD_FUNC(speed)
  839. {
  840. 	int speed;
  841.  
  842. 	nullpo_retr(-1, sd);
  843.  
  844. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  845.  
  846. 	if (!message || !*message || sscanf(message, "%d", &speed) < 1) {
  847. 		sprintf(atcmd_output, "Please, enter a speed value (usage: @speed <%d-%d>).", MIN_WALK_SPEED, MAX_WALK_SPEED);
  848. 		clif_displaymessage(fd, atcmd_output);
  849. 		return -1;
  850. 	}
  851.  
  852. 	sd->base_status.speed = cap_value(speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
  853. 	status_calc_bl(&sd->bl, SCB_SPEED);
  854. 	clif_displaymessage(fd, msg_txt(8)); // Speed changed.
  855. 	return 0;
  856. }
  857.  
  858. /*==========================================
  859.  *
  860.  *------------------------------------------*/
  861. ACMD_FUNC(storage)
  862. {
  863. 	nullpo_retr(-1, sd);
  864.  
  865. 	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
  866. 		return -1;
  867.  
  868. 	if (storage_storageopen(sd) == 1)
  869. 	{	//Already open.
  870. 		clif_displaymessage(fd, msg_txt(250));
  871. 		return -1;
  872. 	}
  873.  
  874. 	clif_displaymessage(fd, "Storage opened.");
  875.  
  876. 	return 0;
  877. }
  878.  
  879.  
  880. /*==========================================
  881.  *
  882.  *------------------------------------------*/
  883. ACMD_FUNC(guildstorage)
  884. {
  885. 	nullpo_retr(-1, sd);
  886.  
  887. 	if (!sd->status.guild_id) {
  888. 		clif_displaymessage(fd, msg_txt(252));
  889. 		return -1;
  890. 	}
  891.  
  892. 	if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading)
  893. 		return -1;
  894.  
  895. 	if (sd->state.storage_flag == 1) {
  896. 		clif_displaymessage(fd, msg_txt(250));
  897. 		return -1;
  898. 	}
  899.  
  900. 	if (sd->state.storage_flag == 2) {
  901. 		clif_displaymessage(fd, msg_txt(251));
  902. 		return -1;
  903. 	}
  904.  
  905. 	storage_guild_storageopen(sd);
  906. 	clif_displaymessage(fd, "Guild storage opened.");
  907. 	return 0;
  908. }
  909.  
  910. /*==========================================
  911.  *
  912.  *------------------------------------------*/
  913. ACMD_FUNC(option)
  914. {
  915. 	int param1 = 0, param2 = 0, param3 = 0;
  916. 	nullpo_retr(-1, sd);
  917.  
  918. 	if (!message || !*message || sscanf(message, "%d %d %d", &param1, &param2, &param3) < 1 || param1 < 0 || param2 < 0 || param3 < 0)
  919. 	{// failed to match the parameters so inform the user of the options
  920. 		const char* text = NULL;
  921.  
  922. 		// attempt to find the setting information for this command
  923. 		text = atcommand_help_string( command );
  924.  
  925. 		// notify the user of the requirement to enter an option
  926. 		clif_displaymessage(fd, "Please, enter at least one option..");
  927.  
  928. 		if( text )
  929. 		{// send the help text associated with this command
  930. 			clif_displaymessage( fd, text );
  931. 		}
  932.  
  933. 		return -1;
  934. 	}
  935.  
  936. 	sd->sc.opt1 = param1;
  937. 	sd->sc.opt2 = param2;
  938. 	pc_setoption(sd, param3);
  939.  
  940. 	clif_displaymessage(fd, msg_txt(9)); // Options changed.
  941.  
  942. 	return 0;
  943. }
  944.  
  945. /*==========================================
  946.  *
  947.  *------------------------------------------*/
  948. ACMD_FUNC(hide)
  949. {
  950. 	nullpo_retr(-1, sd);
  951. 	if (sd->sc.option & OPTION_INVISIBLE) {
  952. 		sd->sc.option &= ~OPTION_INVISIBLE;
  953. 		if (sd->disguise)
  954. 			status_set_viewdata(&sd->bl, sd->disguise);
  955. 		else
  956. 			status_set_viewdata(&sd->bl, sd->status.class_);
  957. 		clif_displaymessage(fd, msg_txt(10)); // Invisible: Off
  958.  
  959. 		// increment the number of pvp players on the map
  960. 		map[sd->bl.m].users_pvp++;
  961.  
  962. 		if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank )
  963. 		{// register the player for ranking calculations
  964. 			sd->pvp_timer = add_timer( gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0 );
  965. 		}
  966. 		//bugreport:2266
  967. 		map_foreachinmovearea(clif_insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl);
  968. 	} else {
  969. 		sd->sc.option |= OPTION_INVISIBLE;
  970. 		sd->vd.class_ = INVISIBLE_CLASS;
  971. 		clif_displaymessage(fd, msg_txt(11)); // Invisible: On
  972.  
  973. 		// decrement the number of pvp players on the map
  974. 		map[sd->bl.m].users_pvp--;
  975.  
  976. 		if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER )
  977. 		{// unregister the player for ranking
  978. 			delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  979. 			sd->pvp_timer = INVALID_TIMER;
  980. 		}
  981. 	}
  982. 	clif_changeoption(&sd->bl);
  983.  
  984. 	return 0;
  985. }
  986.  
  987. /*==========================================
  988.  * Changes a character's class
  989.  *------------------------------------------*/
  990. ACMD_FUNC(jobchange)
  991. {
  992. 	//FIXME: redundancy, potentially wrong code, should use job_name() or similar instead of hardcoding the table [ultramage]
  993. 	int job = 0, upper = 0;
  994. 	nullpo_retr(-1, sd);
  995.  
  996. 	if (!message || !*message || sscanf(message, "%d %d", &job, &upper) < 1)
  997. 	{
  998. 		int i, found = 0;
  999. 		const struct { char name[24]; int id; } jobs[] = {
  1000. 			{ "novice",		0 },
  1001. 			{ "swordman",	1 },
  1002. 			{ "swordsman",	1 },
  1003. 			{ "magician",	2 },
  1004. 			{ "mage",		2 },
  1005. 			{ "archer",		3 },
  1006. 			{ "acolyte",	4 },
  1007. 			{ "merchant",	5 },
  1008. 			{ "thief",		6 },
  1009. 			{ "knight",		7 },
  1010. 			{ "priest",		8 },
  1011. 			{ "priestess",	8 },
  1012. 			{ "wizard",		9 },
  1013. 			{ "blacksmith",	10 },
  1014. 			{ "hunter",		11 },
  1015. 			{ "assassin",	12 },
  1016. 			{ "crusader",	14 },
  1017. 			{ "monk",		15 },
  1018. 			{ "sage",		16 },
  1019. 			{ "rogue",		17 },
  1020. 			{ "alchemist",	18 },
  1021. 			{ "bard",		19 },
  1022. 			{ "dancer",		20 },
  1023. 			{ "super novice",	23 },
  1024. 			{ "supernovice",	23 },
  1025. 			{ "gunslinger",	24 },
  1026. 			{ "gunner",	24 },
  1027. 			{ "ninja",	25 },
  1028. 			{ "novice high",	4001 },
  1029. 			{ "high novice",	4001 },
  1030. 			{ "swordman high",	4002 },
  1031. 			{ "swordsman high",	4002 },
  1032. 			{ "magician high",	4003 },
  1033. 			{ "mage high",		4003 },
  1034. 			{ "archer high",	4004 },
  1035. 			{ "acolyte high",	4005 },
  1036. 			{ "merchant high",	4006 },
  1037. 			{ "thief high",		4007 },
  1038. 			{ "lord knight",	4008 },
  1039. 			{ "high priest",	4009 },
  1040. 			{ "high priestess",	4009 },
  1041. 			{ "high wizard",	4010 },
  1042. 			{ "whitesmith",		4011 },
  1043. 			{ "sniper",		4012 },
  1044. 			{ "assassin cross",	4013 },
  1045. 			{ "paladin",	4015 },
  1046. 			{ "champion",	4016 },
  1047. 			{ "professor",	4017 },
  1048. 			{ "stalker",	4018 },
  1049. 			{ "creator",	4019 },
  1050. 			{ "clown",		4020 },
  1051. 			{ "gypsy",		4021 },
  1052. 			{ "baby novice",	4023 },
  1053. 			{ "baby swordman",	4024 },
  1054. 			{ "baby swordsman",	4024 },
  1055. 			{ "baby magician",	4025 },
  1056. 			{ "baby mage",		4025 },
  1057. 			{ "baby archer",	4026 },
  1058. 			{ "baby acolyte",	4027 },
  1059. 			{ "baby merchant",	4028 },
  1060. 			{ "baby thief",		4029 },
  1061. 			{ "baby knight",	4030 },
  1062. 			{ "baby priest",	4031 },
  1063. 			{ "baby priestess",	4031 },
  1064. 			{ "baby wizard",	4032 },
  1065. 			{ "baby blacksmith",4033 },
  1066. 			{ "baby hunter",	4034 },
  1067. 			{ "baby assassin",	4035 },
  1068. 			{ "baby crusader",	4037 },
  1069. 			{ "baby monk",		4038 },
  1070. 			{ "baby sage",		4039 },
  1071. 			{ "baby rogue",		4040 },
  1072. 			{ "baby alchemist",	4041 },
  1073. 			{ "baby bard",		4042 },
  1074. 			{ "baby dancer",	4043 },
  1075. 			{ "super baby",		4045 },
  1076. 			{ "taekwon",		4046 },
  1077. 			{ "taekwon boy",	4046 },
  1078. 			{ "taekwon girl",	4046 },
  1079. 			{ "star gladiator",	4047 },
  1080. 			{ "soul linker",	4049 },
  1081. 			{ "gangsi",		4050 },
  1082. 			{ "bongun",		4050 },
  1083. 			{ "munak",		4050 },
  1084. 			{ "death knight",	4051 },
  1085. 			{ "dark collector",	4052 },
  1086. 			{ "rune knight",	4054 },
  1087. 			{ "warlock",		4055 },
  1088. 			{ "ranger",		4056 },
  1089. 			{ "arch bishop",	4057 },
  1090. 			{ "mechanic",		4058 },
  1091. 			{ "guillotine",		4059 },
  1092. 			{ "rune knight2",	4060 },
  1093. 			{ "warlock2",		4061 },
  1094. 			{ "ranger2",		4062 },
  1095. 			{ "arch bishop2",	4063 },
  1096. 			{ "mechanic2",		4064 },
  1097. 			{ "guillotine2",	4065 },
  1098. 			{ "royal guard",	4066 },
  1099. 			{ "sorcerer",		4067 },
  1100. 			{ "minstrel",		4068 },
  1101. 			{ "wanderer",		4069 },
  1102. 			{ "sura",		4070 },
  1103. 			{ "genetic",		4071 },
  1104. 			{ "shadow chaser",	4072 },
  1105. 			{ "royal guard2",	4073 },
  1106. 			{ "sorcerer2",		4074 },
  1107. 			{ "minstrel2",		4075 },
  1108. 			{ "wanderer2",		4076 },
  1109. 			{ "sura2",		4077 },
  1110. 			{ "genetic2",		4078 },
  1111. 			{ "shadow chaser2",	4079 },
  1112. 			{ "baby rune",		4096 },
  1113. 			{ "baby warlock",	4097 },
  1114. 			{ "baby ranger",	4098 },
  1115. 			{ "baby bishop",	4099 },
  1116. 			{ "baby mechanic",	4100 },
  1117. 			{ "baby cross",		4101 },
  1118. 			{ "baby guard",		4102 },
  1119. 			{ "baby sorcerer",	4103 },
  1120. 			{ "baby minstrel",	4104 },
  1121. 			{ "baby wanderer",	4105 },
  1122. 			{ "baby sura",		4106 },
  1123. 			{ "baby genetic",	4107 },
  1124. 			{ "baby chaser",	4108 },
  1125. 			{ "super novice e",	4190 },
  1126. 			{ "super baby e",	4191 },
  1127. 			{ "kagerou",		4211 },
  1128. 			{ "oboro",		4212 },
  1129. 		};
  1130.  
  1131. 		for (i=0; i < ARRAYLENGTH(jobs); i++) {
  1132. 			if (strncmpi(message, jobs[i].name, 16) == 0) {
  1133. 				job = jobs[i].id;
  1134. 				upper = 0;
  1135. 				found = 1;
  1136. 				break;
  1137. 			}
  1138. 		}
  1139.  
  1140. 		// TODO: convert this to use atcommand_help_string()
  1141. 		if (!found) {
  1142. 			clif_displaymessage(fd, "Please, enter a job ID (usage: @job/@jobchange <job name/ID>).");
  1143. 			clif_displaymessage(fd, "----- Novice / 1st Class -----");
  1144. 			clif_displaymessage(fd, "   0 Novice              1 Swordman            2 Magician            3 Archer");
  1145. 			clif_displaymessage(fd, "   4 Acolyte             5 Merchant            6 Thief");
  1146. 			clif_displaymessage(fd, "----- 2nd Class -----");
  1147. 			clif_displaymessage(fd, "   7 Knight              8 Priest              9 Wizard             10 Blacksmith");
  1148. 			clif_displaymessage(fd, "  11 Hunter             12 Assassin           14 Crusader           15 Monk");
  1149. 			clif_displaymessage(fd, "  16 Sage               17 Rogue              18 Alchemist          19 Bard");
  1150. 			clif_displaymessage(fd, "  20 Dancer");
  1151. 			clif_displaymessage(fd, "----- High Novice / High 1st Class -----");
  1152. 			clif_displaymessage(fd, "4001 Novice High      4002 Swordman High    4003 Magician High    4004 Archer High");
  1153. 			clif_displaymessage(fd, "4005 Acolyte High     4006 Merchant High    4007 Thief High");
  1154. 			clif_displaymessage(fd, "----- Transcendent 2nd Class -----");
  1155. 			clif_displaymessage(fd, "4008 Lord Knight      4009 High Priest      4010 High Wizard      4011 Whitesmith");
  1156. 			clif_displaymessage(fd, "4012 Sniper           4013 Assassin Cross   4015 Paladin          4016 Champion");
  1157. 			clif_displaymessage(fd, "4017 Professor        4018 Stalker          4019 Creator          4020 Clown");
  1158. 			clif_displaymessage(fd, "4021 Gypsy");
  1159. 			clif_displaymessage(fd, "----- 3rd Class (Regular) -----");
  1160. 			clif_displaymessage(fd, "4054 Rune Knight      4055 Warlock          4056 Ranger           4057 Arch Bishop");
  1161. 			clif_displaymessage(fd, "4058 Mechanic         4059 Guillotine Cross 4066 Royal Guard      4067 Sorcerer");
  1162. 			clif_displaymessage(fd, "4068 Minstrel         4069 Wanderer         4070 Sura             4071 Genetic");
  1163. 			clif_displaymessage(fd, "4072 Shadow Chaser");
  1164. 			clif_displaymessage(fd, "----- 3rd Class (Transcendent) -----");
  1165. 			clif_displaymessage(fd, "4060 Rune Knight      4061 Warlock          4062 Ranger           4063 Arch Bishop");
  1166. 			clif_displaymessage(fd, "4064 Mechanic         4065 Guillotine Cross 4073 Royal Guard      4074 Sorcerer");
  1167. 			clif_displaymessage(fd, "4075 Minstrel         4076 Wanderer         4077 Sura             4078 Genetic");
  1168. 			clif_displaymessage(fd, "4079 Shadow Chaser");
  1169. 			clif_displaymessage(fd, "----- Expanded Class -----");
  1170. 			clif_displaymessage(fd, "  23 Super Novice       24 Gunslinger         25 Ninja            4045 Super Baby");
  1171. 			clif_displaymessage(fd, "4046 Taekwon          4047 Star Gladiator   4049 Soul Linker      4050 Gangsi");
  1172. 			clif_displaymessage(fd, "4051 Death Knight     4052 Dark Collector   4190 Ex. Super Novice 4191 Ex. Super Baby");
  1173. 			clif_displaymessage(fd, "4211 Kagerou          4212 Oboro");
  1174. 			clif_displaymessage(fd, "----- Baby Novice And Baby 1st Class -----");
  1175. 			clif_displaymessage(fd, "4023 Baby Novice      4024 Baby Swordman    4025 Baby Magician    4026 Baby Archer");
  1176. 			clif_displaymessage(fd, "4027 Baby Acolyte     4028 Baby Merchant    4029 Baby Thief");
  1177. 			clif_displaymessage(fd, "---- Baby 2nd Class ----");
  1178. 			clif_displaymessage(fd, "4030 Baby Knight      4031 Baby Priest      4032 Baby Wizard      4033 Baby Blacksmith");
  1179. 			clif_displaymessage(fd, "4034 Baby Hunter      4035 Baby Assassin    4037 Baby Crusader    4038 Baby Monk");
  1180. 			clif_displaymessage(fd, "4039 Baby Sage        4040 Baby Rogue       4041 Baby Alchemist   4042 Baby Bard");
  1181. 			clif_displaymessage(fd, "4043 Baby Dancer");
  1182. 			clif_displaymessage(fd, "---- Baby 3rd Class ----");
  1183. 			clif_displaymessage(fd, "4096 Baby Rune Knight 4097 Baby Warlock     4098 Baby Ranger      4099 Baby Arch Bishop");
  1184. 			clif_displaymessage(fd, "4100 Baby Mechanic    4101 Baby Glt. Cross  4102 Baby Royal Guard 4103 Baby Sorcerer");
  1185. 			clif_displaymessage(fd, "4104 Baby Minstrel    4105 Baby Wanderer    4106 Baby Sura        4107 Baby Genetic");
  1186. 			clif_displaymessage(fd, "4108 Baby Shadow Chaser");
  1187. 			//clif_displaymessage(fd, "---- Modes And Others ----");
  1188. 			//clif_displaymessage(fd, "  22 Wedding            26 Christmas          27 Summer           4048 Star Gladiator (Union)");
  1189. 			return -1;
  1190. 		}
  1191. 	}
  1192.  
  1193. 	if (job == 13 || job == 21 || job == 22 || job == 26 || job == 27 || job == 4014 || job == 4022 || job == 4036 || job == 4044 || job == 4048
  1194. 		 || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2)
  1195. 	) // Deny direct transformation into dummy jobs
  1196. 		{clif_displaymessage(fd, "You can not change to this job by command.");
  1197. 		return 0;}
  1198.  
  1199. 	if (pcdb_checkid(job))
  1200. 	{
  1201. 		if (pc_jobchange(sd, job, upper) == 0)
  1202. 			clif_displaymessage(fd, msg_txt(12)); // Your job has been changed.
  1203. 		else {
  1204. 			clif_displaymessage(fd, msg_txt(155)); // You are unable to change your job.
  1205. 			return -1;
  1206. 		}
  1207. 	} else {
  1208. 			// TODO: convert this to use atcommand_help_string()
  1209. 			clif_displaymessage(fd, "Please enter a valid job ID (usage: @job/@jobchange <job name/ID>).");
  1210. 			clif_displaymessage(fd, "----- Novice / 1st Class -----");
  1211. 			clif_displaymessage(fd, "   0 Novice              1 Swordman            2 Magician            3 Archer");
  1212. 			clif_displaymessage(fd, "   4 Acolyte             5 Merchant            6 Thief");
  1213. 			clif_displaymessage(fd, "----- 2nd Class -----");
  1214. 			clif_displaymessage(fd, "   7 Knight              8 Priest              9 Wizard             10 Blacksmith");
  1215. 			clif_displaymessage(fd, "  11 Hunter             12 Assassin           14 Crusader           15 Monk");
  1216. 			clif_displaymessage(fd, "  16 Sage               17 Rogue              18 Alchemist          19 Bard");
  1217. 			clif_displaymessage(fd, "  20 Dancer");
  1218. 			clif_displaymessage(fd, "----- High Novice / High 1st Class -----");
  1219. 			clif_displaymessage(fd, "4001 Novice High      4002 Swordman High    4003 Magician High    4004 Archer High");
  1220. 			clif_displaymessage(fd, "4005 Acolyte High     4006 Merchant High    4007 Thief High");
  1221. 			clif_displaymessage(fd, "----- Transcendent 2nd Class -----");
  1222. 			clif_displaymessage(fd, "4008 Lord Knight      4009 High Priest      4010 High Wizard      4011 Whitesmith");
  1223. 			clif_displaymessage(fd, "4012 Sniper           4013 Assassin Cross   4015 Paladin          4016 Champion");
  1224. 			clif_displaymessage(fd, "4017 Professor        4018 Stalker          4019 Creator          4020 Clown");
  1225. 			clif_displaymessage(fd, "4021 Gypsy");
  1226. 			clif_displaymessage(fd, "----- 3rd Class (Regular) -----");
  1227. 			clif_displaymessage(fd, "4054 Rune Knight      4055 Warlock          4056 Ranger           4057 Arch Bishop");
  1228. 			clif_displaymessage(fd, "4058 Mechanic         4059 Guillotine Cross 4066 Royal Guard      4067 Sorcerer");
  1229. 			clif_displaymessage(fd, "4068 Minstrel         4069 Wanderer         4070 Sura             4071 Genetic");
  1230. 			clif_displaymessage(fd, "4072 Shadow Chaser");
  1231. 			clif_displaymessage(fd, "----- 3rd Class (Transcendent) -----");
  1232. 			clif_displaymessage(fd, "4060 Rune Knight      4061 Warlock          4062 Ranger           4063 Arch Bishop");
  1233. 			clif_displaymessage(fd, "4064 Mechanic         4065 Guillotine Cross 4073 Royal Guard      4074 Sorcerer");
  1234. 			clif_displaymessage(fd, "4075 Minstrel         4076 Wanderer         4077 Sura             4078 Genetic");
  1235. 			clif_displaymessage(fd, "4079 Shadow Chaser");
  1236. 			clif_displaymessage(fd, "----- Expanded Class -----");
  1237. 			clif_displaymessage(fd, "  23 Super Novice       24 Gunslinger         25 Ninja            4045 Super Baby");
  1238. 			clif_displaymessage(fd, "4046 Taekwon          4047 Star Gladiator   4049 Soul Linker      4050 Gangsi");
  1239. 			clif_displaymessage(fd, "4051 Death Knight     4052 Dark Collector   4190 Ex. Super Novice 4191 Ex. Super Baby");
  1240. 			clif_displaymessage(fd, "4211 Kagerou          4212 Oboro");
  1241. 			clif_displaymessage(fd, "----- Baby Novice And Baby 1st Class -----");
  1242. 			clif_displaymessage(fd, "4023 Baby Novice      4024 Baby Swordman    4025 Baby Magician    4026 Baby Archer");
  1243. 			clif_displaymessage(fd, "4027 Baby Acolyte     4028 Baby Merchant    4029 Baby Thief");
  1244. 			clif_displaymessage(fd, "---- Baby 2nd Class ----");
  1245. 			clif_displaymessage(fd, "4030 Baby Knight      4031 Baby Priest      4032 Baby Wizard      4033 Baby Blacksmith");
  1246. 			clif_displaymessage(fd, "4034 Baby Hunter      4035 Baby Assassin    4037 Baby Crusader    4038 Baby Monk");
  1247. 			clif_displaymessage(fd, "4039 Baby Sage        4040 Baby Rogue       4041 Baby Alchemist   4042 Baby Bard");
  1248. 			clif_displaymessage(fd, "4043 Baby Dancer");
  1249. 			clif_displaymessage(fd, "---- Baby 3rd Class ----");
  1250. 			clif_displaymessage(fd, "4096 Baby Rune Knight 4097 Baby Warlock     4098 Baby Ranger      4099 Baby Arch Bishop");
  1251. 			clif_displaymessage(fd, "4100 Baby Mechanic    4101 Baby Glt. Cross  4102 Baby Royal Guard 4103 Baby Sorcerer");
  1252. 			clif_displaymessage(fd, "4104 Baby Minstrel    4105 Baby Wanderer    4106 Baby Sura        4107 Baby Genetic");
  1253. 			clif_displaymessage(fd, "4108 Baby Shadow Chaser");
  1254. 			//clif_displaymessage(fd, "---- Modes And Others ----");
  1255. 			//clif_displaymessage(fd, "  22 Wedding            26 Christmas          27 Summer           4048 Star Gladiator (Union)");
  1256. 		return -1;
  1257. 	}
  1258.  
  1259. 	return 0;
  1260. }
  1261.  
  1262. /*==========================================
  1263.  *
  1264.  *------------------------------------------*/
  1265. ACMD_FUNC(kill)
  1266. {
  1267. 	nullpo_retr(-1, sd);
  1268. 	status_kill(&sd->bl);
  1269. 	clif_displaymessage(sd->fd, msg_txt(13)); // A pity! You've died.
  1270. 	if (fd != sd->fd)
  1271. 		clif_displaymessage(fd, msg_txt(14)); // Character killed.
  1272. 	return 0;
  1273. }
  1274.  
  1275. /*==========================================
  1276.  *
  1277.  *------------------------------------------*/
  1278. ACMD_FUNC(alive)
  1279. {
  1280. 	nullpo_retr(-1, sd);
  1281. 	if (!status_revive(&sd->bl, 100, 100))
  1282. 	{
  1283. 		clif_displaymessage(fd, msg_txt(667));
  1284. 		return -1;
  1285. 	}
  1286. 	clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  1287. 	clif_displaymessage(fd, msg_txt(16)); // You've been revived! It's a miracle!
  1288. 	return 0;
  1289. }
  1290.  
  1291. /*==========================================
  1292.  * +kamic [LuzZza]
  1293.  *------------------------------------------*/
  1294. ACMD_FUNC(kami)
  1295. {
  1296. 	unsigned long color=0;
  1297. 	nullpo_retr(-1, sd);
  1298.  
  1299. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1300.  
  1301. 	if(*(command + 5) != 'c' && *(command + 5) != 'C') {
  1302. 		if (!message || !*message) {
  1303. 			clif_displaymessage(fd, "Please, enter a message (usage: @kami <message>).");
  1304. 			return -1;
  1305. 		}
  1306.  
  1307. 		sscanf(message, "%199[^\n]", atcmd_output);
  1308. 		if (strstr(command, "l") != NULL)
  1309. 			clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  1310. 		else
  1311. 			intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(command + 5) == 'b' || *(command + 5) == 'B') ? 0x10 : 0);
  1312. 	} else {
  1313. 		if(!message || !*message || (sscanf(message, "%lx %199[^\n]", &color, atcmd_output) < 2)) {
  1314. 			clif_displaymessage(fd, "Please, enter color and message (usage: @kamic <color> <message>).");
  1315. 			return -1;
  1316. 		}
  1317.  
  1318. 		if(color > 0xFFFFFF) {
  1319. 			clif_displaymessage(fd, "Invalid color.");
  1320. 			return -1;
  1321. 		}
  1322. 		intif_broadcast2(atcmd_output, strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0);
  1323. 	}
  1324. 	return 0;
  1325. }
  1326.  
  1327. /*==========================================
  1328.  *
  1329.  *------------------------------------------*/
  1330. ACMD_FUNC(heal)
  1331. {
  1332. 	int hp = 0, sp = 0; // [Valaris] thanks to fov
  1333. 	nullpo_retr(-1, sd);
  1334.  
  1335. 	sscanf(message, "%d %d", &hp, &sp);
  1336.  
  1337. 	// some overflow checks
  1338. 	if( hp == INT_MIN ) hp++;
  1339. 	if( sp == INT_MIN ) sp++;
  1340.  
  1341. 	if ( hp == 0 && sp == 0 ) {
  1342. 		if (!status_percent_heal(&sd->bl, 100, 100))
  1343. 			clif_displaymessage(fd, msg_txt(157)); // HP and SP have already been recovered.
  1344. 		else
  1345. 			clif_displaymessage(fd, msg_txt(17)); // HP, SP recovered.
  1346. 		return 0;
  1347. 	}
  1348.  
  1349. 	if ( hp > 0 && sp >= 0 ) {
  1350. 		if(!status_heal(&sd->bl, hp, sp, 0))
  1351. 			clif_displaymessage(fd, msg_txt(157)); // HP and SP are already with the good value.
  1352. 		else
  1353. 			clif_displaymessage(fd, msg_txt(17)); // HP, SP recovered.
  1354. 		return 0;
  1355. 	}
  1356.  
  1357. 	if ( hp < 0 && sp <= 0 ) {
  1358. 		status_damage(NULL, &sd->bl, -hp, -sp, 0, 0);
  1359. 		clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  1360. 		clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified.
  1361. 		return 0;
  1362. 	}
  1363.  
  1364. 	//Opposing signs.
  1365. 	if ( hp ) {
  1366. 		if (hp > 0)
  1367. 			status_heal(&sd->bl, hp, 0, 0);
  1368. 		else {
  1369. 			status_damage(NULL, &sd->bl, -hp, 0, 0, 0);
  1370. 			clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  1371. 		}
  1372. 	}
  1373.  
  1374. 	if ( sp ) {
  1375. 		if (sp > 0)
  1376. 			status_heal(&sd->bl, 0, sp, 0);
  1377. 		else
  1378. 			status_damage(NULL, &sd->bl, 0, -sp, 0, 0);
  1379. 	}
  1380.  
  1381. 	clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified.
  1382. 	return 0;
  1383. }
  1384.  
  1385. /*==========================================
  1386.  * @item command (usage: @item <name/id_of_item> <quantity>) (modified by [Yor] for pet_egg)
  1387.  *------------------------------------------*/
  1388. ACMD_FUNC(item)
  1389. {
  1390. 	char item_name[100];
  1391. 	int number = 0, item_id, flag;
  1392. 	struct item item_tmp;
  1393. 	struct item_data *item_data;
  1394. 	int get_count, i;
  1395. 	nullpo_retr(-1, sd);
  1396.  
  1397. 	memset(item_name, '\0', sizeof(item_name));
  1398.  
  1399. 	if (!message || !*message || (
  1400. 		sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 &&
  1401. 		sscanf(message, "%99s %d", item_name, &number) < 1
  1402. 	)) {
  1403. 		clif_displaymessage(fd, "Please, enter an item name/id (usage: @item <item name or ID> [quantity]).");
  1404. 		return -1;
  1405. 	}
  1406.  
  1407. 	if (number <= 0)
  1408. 		number = 1;
  1409.  
  1410. 	if ((item_data = itemdb_searchname(item_name)) == NULL &&
  1411. 	    (item_data = itemdb_exists(atoi(item_name))) == NULL)
  1412. 	{
  1413. 		clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  1414. 		return -1;
  1415. 	}
  1416.  
  1417. 	item_id = item_data->nameid;
  1418. 	get_count = number;
  1419. 	//Check if it's stackable.
  1420. 	if (!itemdb_isstackable2(item_data))
  1421. 		get_count = 1;
  1422.  
  1423. 	for (i = 0; i < number; i += get_count) {
  1424. 		// if not pet egg
  1425. 		if (!pet_create_egg(sd, item_id)) {
  1426. 			memset(&item_tmp, 0, sizeof(item_tmp));
  1427. 			item_tmp.nameid = item_id;
  1428. 			item_tmp.identify = 1;
  1429.  
  1430. 			if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1431. 				clif_additem(sd, 0, 0, flag);
  1432. 		}
  1433. 	}
  1434.  
  1435. 	clif_displaymessage(fd, msg_txt(18)); // Item created.
  1436. 	return 0;
  1437. }
  1438.  
  1439. /*==========================================
  1440.  *
  1441.  *------------------------------------------*/
  1442. ACMD_FUNC(item2)
  1443. {
  1444. 	struct item item_tmp;
  1445. 	struct item_data *item_data;
  1446. 	char item_name[100];
  1447. 	int item_id, number = 0;
  1448. 	int identify = 0, refine = 0, attr = 0;
  1449. 	int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  1450. 	int flag;
  1451. 	int loop, get_count, i;
  1452. 	nullpo_retr(-1, sd);
  1453.  
  1454. 	memset(item_name, '\0', sizeof(item_name));
  1455.  
  1456. 	if (!message || !*message || (
  1457. 		sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 &&
  1458. 		sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9
  1459. 	)) {
  1460. 		clif_displaymessage(fd, "Please, enter all informations (usage: @item2 <item name or ID> <quantity>");
  1461. 		clif_displaymessage(fd, "  <Identify_flag> <refine> <attribut> <Card1> <Card2> <Card3> <Card4>).");
  1462. 		return -1;
  1463. 	}
  1464.  
  1465. 	if (number <= 0)
  1466. 		number = 1;
  1467.  
  1468. 	item_id = 0;
  1469. 	if ((item_data = itemdb_searchname(item_name)) != NULL ||
  1470. 	    (item_data = itemdb_exists(atoi(item_name))) != NULL)
  1471. 		item_id = item_data->nameid;
  1472.  
  1473. 	if (item_id > 500) {
  1474. 		loop = 1;
  1475. 		get_count = number;
  1476. 		if (item_data->type == IT_WEAPON || item_data->type == IT_ARMOR ||
  1477. 			item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) {
  1478. 			loop = number;
  1479. 			get_count = 1;
  1480. 			if (item_data->type == IT_PETEGG) {
  1481. 				identify = 1;
  1482. 				refine = 0;
  1483. 			}
  1484. 			if (item_data->type == IT_PETARMOR)
  1485. 				refine = 0;
  1486. 			if (refine > MAX_REFINE)
  1487. 				refine = MAX_REFINE;
  1488. 		} else {
  1489. 			identify = 1;
  1490. 			refine = attr = 0;
  1491. 		}
  1492. 		for (i = 0; i < loop; i++) {
  1493. 			memset(&item_tmp, 0, sizeof(item_tmp));
  1494. 			item_tmp.nameid = item_id;
  1495. 			item_tmp.identify = identify;
  1496. 			item_tmp.refine = refine;
  1497. 			item_tmp.attribute = attr;
  1498. 			item_tmp.card[0] = c1;
  1499. 			item_tmp.card[1] = c2;
  1500. 			item_tmp.card[2] = c3;
  1501. 			item_tmp.card[3] = c4;
  1502. 			if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1503. 				clif_additem(sd, 0, 0, flag);
  1504. 		}
  1505.  
  1506. 		clif_displaymessage(fd, msg_txt(18)); // Item created.
  1507. 	} else {
  1508. 		clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  1509. 		return -1;
  1510. 	}
  1511.  
  1512. 	return 0;
  1513. }
  1514.  
  1515. /*==========================================
  1516.  *
  1517.  *------------------------------------------*/
  1518. ACMD_FUNC(itemreset)
  1519. {
  1520. 	int i;
  1521. 	nullpo_retr(-1, sd);
  1522.  
  1523. 	for (i = 0; i < MAX_INVENTORY; i++) {
  1524. 		if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) {
  1525. 			pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_COMMAND);
  1526. 		}
  1527. 	}
  1528. 	clif_displaymessage(fd, msg_txt(20)); // All of your items have been removed.
  1529.  
  1530. 	return 0;
  1531. }
  1532.  
  1533. /*==========================================
  1534.  * Atcommand @lvlup
  1535.  *------------------------------------------*/
  1536. ACMD_FUNC(baselevelup)
  1537. {
  1538. 	int level=0, i=0, status_point=0;
  1539. 	nullpo_retr(-1, sd);
  1540. 	level = atoi(message);
  1541.  
  1542. 	if (!message || !*message || !level) {
  1543. 		clif_displaymessage(fd, "Please, enter a level adjustment (usage: @lvup/@blevel/@baselvlup <number of levels>).");
  1544. 		return -1;
  1545. 	}
  1546.  
  1547. 	if (level > 0) {
  1548. 		if (sd->status.base_level >= pc_maxbaselv(sd)) { // check for max level by Valaris
  1549. 			clif_displaymessage(fd, msg_txt(47)); // Base level can't go any higher.
  1550. 			return -1;
  1551. 		} // End Addition
  1552. 		if ((unsigned int)level > pc_maxbaselv(sd) || (unsigned int)level > pc_maxbaselv(sd) - sd->status.base_level) // fix positiv overflow
  1553. 			level = pc_maxbaselv(sd) - sd->status.base_level;
  1554. 		for (i = 0; i < level; i++)
  1555. 			status_point += pc_gets_status_point(sd->status.base_level + i);
  1556.  
  1557. 		sd->status.status_point += status_point;
  1558. 		sd->status.base_level += (unsigned int)level;
  1559. 		status_percent_heal(&sd->bl, 100, 100);
  1560. 		clif_misceffect(&sd->bl, 0);
  1561. 		clif_displaymessage(fd, msg_txt(21)); // Base level raised.
  1562. 	} else {
  1563. 		if (sd->status.base_level == 1) {
  1564. 			clif_displaymessage(fd, msg_txt(158)); // Base level can't go any lower.
  1565. 			return -1;
  1566. 		}
  1567. 		level*=-1;
  1568. 		if ((unsigned int)level >= sd->status.base_level)
  1569. 			level = sd->status.base_level-1;
  1570. 		for (i = 0; i > -level; i--)
  1571. 			status_point += pc_gets_status_point(sd->status.base_level + i - 1);
  1572. 		if (sd->status.status_point < status_point)
  1573. 			pc_resetstate(sd);
  1574. 		if (sd->status.status_point < status_point)
  1575. 			sd->status.status_point = 0;
  1576. 		else
  1577. 			sd->status.status_point -= status_point;
  1578. 		sd->status.base_level -= (unsigned int)level;
  1579. 		clif_displaymessage(fd, msg_txt(22)); // Base level lowered.
  1580. 	}
  1581. 	sd->status.base_exp = 0;
  1582. 	clif_updatestatus(sd, SP_STATUSPOINT);
  1583. 	clif_updatestatus(sd, SP_BASELEVEL);
  1584. 	clif_updatestatus(sd, SP_BASEEXP);
  1585. 	clif_updatestatus(sd, SP_NEXTBASEEXP);
  1586. 	status_calc_pc(sd, 0);
  1587. 	if(sd->status.party_id)
  1588. 		party_send_levelup(sd);
  1589. 	return 0;
  1590. }
  1591.  
  1592. /*==========================================
  1593.  *
  1594.  *------------------------------------------*/
  1595. ACMD_FUNC(joblevelup)
  1596. {
  1597. 	int level=0;
  1598. 	nullpo_retr(-1, sd);
  1599.  
  1600. 	level = atoi(message);
  1601.  
  1602. 	if (!message || !*message || !level) {
  1603. 		clif_displaymessage(fd, "Please, enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup <number of levels>).");
  1604. 		return -1;
  1605. 	}
  1606. 	if (level > 0) {
  1607. 		if (sd->status.job_level >= pc_maxjoblv(sd)) {
  1608. 			clif_displaymessage(fd, msg_txt(23)); // Job level can't go any higher.
  1609. 			return -1;
  1610. 		}
  1611. 		if ((unsigned int)level > pc_maxjoblv(sd) || (unsigned int)level > pc_maxjoblv(sd) - sd->status.job_level) // fix positiv overflow
  1612. 			level = pc_maxjoblv(sd) - sd->status.job_level;
  1613. 		sd->status.job_level += (unsigned int)level;
  1614. 		sd->status.skill_point += level;
  1615. 		clif_misceffect(&sd->bl, 1);
  1616. 		clif_displaymessage(fd, msg_txt(24)); // Job level raised.
  1617. 	} else {
  1618. 		if (sd->status.job_level == 1) {
  1619. 			clif_displaymessage(fd, msg_txt(159)); // Job level can't go any lower.
  1620. 			return -1;
  1621. 		}
  1622. 		level *=-1;
  1623. 		if ((unsigned int)level >= sd->status.job_level) // fix negativ overflow
  1624. 			level = sd->status.job_level-1;
  1625. 		sd->status.job_level -= (unsigned int)level;
  1626. 		if (sd->status.skill_point < level)
  1627. 			pc_resetskill(sd,0);	//Reset skills since we need to substract more points.
  1628. 		if (sd->status.skill_point < level)
  1629. 			sd->status.skill_point = 0;
  1630. 		else
  1631. 			sd->status.skill_point -= level;
  1632. 		clif_displaymessage(fd, msg_txt(25)); // Job level lowered.
  1633. 	}
  1634. 	sd->status.job_exp = 0;
  1635. 	clif_updatestatus(sd, SP_JOBLEVEL);
  1636. 	clif_updatestatus(sd, SP_JOBEXP);
  1637. 	clif_updatestatus(sd, SP_NEXTJOBEXP);
  1638. 	clif_updatestatus(sd, SP_SKILLPOINT);
  1639. 	status_calc_pc(sd, 0);
  1640.  
  1641. 	return 0;
  1642. }
  1643.  
  1644. /*==========================================
  1645.  * @help
  1646.  *------------------------------------------*/
  1647. ACMD_FUNC(help)
  1648. {
  1649. 	config_setting_t *help;
  1650. 	const char *text = NULL;
  1651. 	const char *command_name = NULL;
  1652. 	char *default_command = "help";
  1653.  
  1654. 	nullpo_retr(-1, sd);
  1655.  
  1656. 	help = config_lookup(&atcommand_config, "help");
  1657. 	if (help == NULL) {
  1658. 		clif_displaymessage(fd, msg_txt(27)); // "Commands help is not available."
  1659. 		return -1;
  1660. 	}
  1661.  
  1662. 	if (!message || !*message) {
  1663. 		command_name = default_command; // If no command_name specified, display help for @help.
  1664. 	} else {
  1665. 		if (*message == atcommand_symbol || *message == charcommand_symbol)
  1666. 			++message;
  1667. 		command_name = atcommand_checkalias(message);
  1668. 	}
  1669.  
  1670. 	if (!pc_can_use_command(sd, command_name, COMMAND_ATCOMMAND)) {
  1671. 		sprintf(atcmd_output, msg_txt(153), message); // "%s is Unknown Command"
  1672. 		clif_displaymessage(fd, atcmd_output);
  1673. 		atcommand_get_suggestions(sd, command_name, true);
  1674. 		return -1;
  1675. 	}
  1676.  
  1677. 	if (!config_setting_lookup_string(help, command_name, &text)) {
  1678. 		clif_displaymessage(fd, "There is no help for this command_name.");
  1679. 		atcommand_get_suggestions(sd, command_name, true);
  1680. 		return -1;
  1681. 	}
  1682.  
  1683. 	sprintf(atcmd_output, "Help for command %c%s:", atcommand_symbol, command_name);
  1684. 	clif_displaymessage(fd, atcmd_output);
  1685.  
  1686. 	{   // Display aliases
  1687. 		DBIterator* iter;
  1688. 		AtCommandInfo *command_info;
  1689. 		AliasInfo *alias_info = NULL;
  1690. 		StringBuf buf;
  1691. 		bool has_aliases = false;
  1692.  
  1693. 		StringBuf_Init(&buf);
  1694. 		StringBuf_AppendStr(&buf, "Available aliases:");
  1695. 		command_info = get_atcommandinfo_byname(command_name);
  1696. 		iter = db_iterator(atcommand_alias_db);
  1697. 		for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) {
  1698. 			if (alias_info->command == command_info) {
  1699. 				StringBuf_Printf(&buf, " %s", alias_info->alias);
  1700. 				has_aliases = true;
  1701. 			}
  1702. 		}
  1703. 		dbi_destroy(iter);
  1704. 		if (has_aliases)
  1705. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  1706. 		StringBuf_Destroy(&buf);
  1707. 	}
  1708.  
  1709. 	// Display help contents
  1710. 	clif_displaymessage(fd, text);
  1711. 	return 0;
  1712. }
  1713.  
  1714. // helper function, used in foreach calls to stop auto-attack timers
  1715. // parameter: '0' - everyone, 'id' - only those attacking someone with that id
  1716. static int atcommand_stopattack(struct block_list *bl,va_list ap)
  1717. {
  1718. 	struct unit_data *ud = unit_bl2ud(bl);
  1719. 	int id = va_arg(ap, int);
  1720. 	if (ud && ud->attacktimer != INVALID_TIMER && (!id || id == ud->target))
  1721. 	{
  1722. 		unit_stop_attack(bl);
  1723. 		return 1;
  1724. 	}
  1725. 	return 0;
  1726. }
  1727. /*==========================================
  1728.  *
  1729.  *------------------------------------------*/
  1730. static int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
  1731. {
  1732. 	TBL_PC* sd = (TBL_PC*)bl;
  1733. 	clif_pvpset(sd, 0, 0, 2);
  1734. 	if (sd->pvp_timer != INVALID_TIMER) {
  1735. 		delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
  1736. 		sd->pvp_timer = INVALID_TIMER;
  1737. 	}
  1738. 	return 0;
  1739. }
  1740.  
  1741. ACMD_FUNC(pvpoff)
  1742. {
  1743. 	nullpo_retr(-1, sd);
  1744.  
  1745. 	if (!map[sd->bl.m].flag.pvp) {
  1746. 		clif_displaymessage(fd, msg_txt(160)); // PvP is already Off.
  1747. 		return -1;
  1748. 	}
  1749.  
  1750. 	map[sd->bl.m].flag.pvp = 0;
  1751.  
  1752. 	if (!battle_config.pk_mode)
  1753. 		clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1754. 	map_foreachinmap(atcommand_pvpoff_sub,sd->bl.m, BL_PC);
  1755. 	map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1756. 	clif_displaymessage(fd, msg_txt(31)); // PvP: Off.
  1757. 	return 0;
  1758. }
  1759.  
  1760. /*==========================================
  1761.  *
  1762.  *------------------------------------------*/
  1763. static int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
  1764. {
  1765. 	TBL_PC* sd = (TBL_PC*)bl;
  1766. 	if (sd->pvp_timer == INVALID_TIMER) {
  1767. 		sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0);
  1768. 		sd->pvp_rank = 0;
  1769. 		sd->pvp_lastusers = 0;
  1770. 		sd->pvp_point = 5;
  1771. 		sd->pvp_won = 0;
  1772. 		sd->pvp_lost = 0;
  1773. 	}
  1774. 	return 0;
  1775. }
  1776.  
  1777. ACMD_FUNC(pvpon)
  1778. {
  1779. 	nullpo_retr(-1, sd);
  1780.  
  1781. 	if (map[sd->bl.m].flag.pvp) {
  1782. 		clif_displaymessage(fd, msg_txt(161)); // PvP is already On.
  1783. 		return -1;
  1784. 	}
  1785.  
  1786. 	map[sd->bl.m].flag.pvp = 1;
  1787.  
  1788. 	if (!battle_config.pk_mode)
  1789. 	{// display pvp circle and rank
  1790. 		clif_map_property_mapall(sd->bl.m, MAPPROPERTY_FREEPVPZONE);
  1791. 		map_foreachinmap(atcommand_pvpon_sub,sd->bl.m, BL_PC);
  1792. 	}
  1793.  
  1794. 	clif_displaymessage(fd, msg_txt(32)); // PvP: On.
  1795.  
  1796. 	return 0;
  1797. }
  1798.  
  1799. /*==========================================
  1800.  *
  1801.  *------------------------------------------*/
  1802. ACMD_FUNC(gvgoff)
  1803. {
  1804. 	nullpo_retr(-1, sd);
  1805.  
  1806. 	if (!map[sd->bl.m].flag.gvg) {
  1807. 		clif_displaymessage(fd, msg_txt(162)); // GvG is already Off.
  1808. 		return -1;
  1809. 	}
  1810.  
  1811. 	map[sd->bl.m].flag.gvg = 0;
  1812. 	clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1813. 	map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1814. 	clif_displaymessage(fd, msg_txt(33)); // GvG: Off.
  1815.  
  1816. 	return 0;
  1817. }
  1818.  
  1819. /*==========================================
  1820.  *
  1821.  *------------------------------------------*/
  1822. ACMD_FUNC(gvgon)
  1823. {
  1824. 	nullpo_retr(-1, sd);
  1825.  
  1826. 	if (map[sd->bl.m].flag.gvg) {
  1827. 		clif_displaymessage(fd, msg_txt(163)); // GvG is already On.
  1828. 		return -1;
  1829. 	}
  1830.  
  1831. 	map[sd->bl.m].flag.gvg = 1;
  1832. 	clif_map_property_mapall(sd->bl.m, MAPPROPERTY_AGITZONE);
  1833. 	clif_displaymessage(fd, msg_txt(34)); // GvG: On.
  1834.  
  1835. 	return 0;
  1836. }
  1837.  
  1838. /*==========================================
  1839.  *
  1840.  *------------------------------------------*/
  1841. ACMD_FUNC(model)
  1842. {
  1843. 	int hair_style = 0, hair_color = 0, cloth_color = 0;
  1844. 	nullpo_retr(-1, sd);
  1845.  
  1846. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1847.  
  1848. 	if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) {
  1849. 		sprintf(atcmd_output, "Please, enter at least a value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).",
  1850. 		        MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1851. 		clif_displaymessage(fd, atcmd_output);
  1852. 		return -1;
  1853. 	}
  1854.  
  1855. 	if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE &&
  1856. 		hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
  1857. 		cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1858. 			pc_changelook(sd, LOOK_HAIR, hair_style);
  1859. 			pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1860. 			pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1861. 			clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1862. 	} else {
  1863. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1864. 		return -1;
  1865. 	}
  1866.  
  1867. 	return 0;
  1868. }
  1869.  
  1870. /*==========================================
  1871.  * @dye && @ccolor
  1872.  *------------------------------------------*/
  1873. ACMD_FUNC(dye)
  1874. {
  1875. 	int cloth_color = 0;
  1876. 	nullpo_retr(-1, sd);
  1877.  
  1878. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1879.  
  1880. 	if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) {
  1881. 		sprintf(atcmd_output, "Please, enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).", MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1882. 		clif_displaymessage(fd, atcmd_output);
  1883. 		return -1;
  1884. 	}
  1885.  
  1886. 	if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1887. 		pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1888. 		clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1889. 	} else {
  1890. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1891. 		return -1;
  1892. 	}
  1893.  
  1894. 	return 0;
  1895. }
  1896.  
  1897. /*==========================================
  1898.  * @hairstyle && @hstyle
  1899.  *------------------------------------------*/
  1900. ACMD_FUNC(hair_style)
  1901. {
  1902. 	int hair_style = 0;
  1903. 	nullpo_retr(-1, sd);
  1904.  
  1905. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1906.  
  1907. 	if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) {
  1908. 		sprintf(atcmd_output, "Please, enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).", MIN_HAIR_STYLE, MAX_HAIR_STYLE);
  1909. 		clif_displaymessage(fd, atcmd_output);
  1910. 		return -1;
  1911. 	}
  1912.  
  1913. 	if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) {
  1914. 			pc_changelook(sd, LOOK_HAIR, hair_style);
  1915. 			clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1916. 	} else {
  1917. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1918. 		return -1;
  1919. 	}
  1920.  
  1921. 	return 0;
  1922. }
  1923.  
  1924. /*==========================================
  1925.  * @haircolor && @hcolor
  1926.  *------------------------------------------*/
  1927. ACMD_FUNC(hair_color)
  1928. {
  1929. 	int hair_color = 0;
  1930. 	nullpo_retr(-1, sd);
  1931.  
  1932. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  1933.  
  1934. 	if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) {
  1935. 		sprintf(atcmd_output, "Please, enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).", MIN_HAIR_COLOR, MAX_HAIR_COLOR);
  1936. 		clif_displaymessage(fd, atcmd_output);
  1937. 		return -1;
  1938. 	}
  1939.  
  1940. 	if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) {
  1941. 			pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1942. 			clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1943. 	} else {
  1944. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1945. 		return -1;
  1946. 	}
  1947.  
  1948. 	return 0;
  1949. }
  1950.  
  1951. /*==========================================
  1952.  * @go [city_number or city_name] - Updated by Harbin
  1953.  *------------------------------------------*/
  1954. ACMD_FUNC(go)
  1955. {
  1956. 	int i;
  1957. 	int town;
  1958. 	char map_name[MAP_NAME_LENGTH];
  1959. 	int m;
  1960.  
  1961. 	const struct {
  1962. 		char map[MAP_NAME_LENGTH];
  1963. 		int x, y;
  1964. 	} data[] = {
  1965. 		{ MAP_PRONTERA,    156, 191 }, //  0=Prontera
  1966. 		{ MAP_MORROC,      156,  93 }, //  1=Morroc
  1967. 		{ MAP_GEFFEN,      119,  59 }, //  2=Geffen
  1968. 		{ MAP_PAYON,       162, 233 }, //  3=Payon
  1969. 		{ MAP_ALBERTA,     192, 147 }, //  4=Alberta
  1970. #ifdef RENEWAL
  1971. 		{ MAP_IZLUDE,      128, 146 }, //  5=Izlude (Renewal)
  1972. #else
  1973. 		{ MAP_IZLUDE,      128, 114 }, //  5=Izlude
  1974. #endif
  1975. 		{ MAP_ALDEBARAN,   140, 131 }, //  6=Al de Baran
  1976. 		{ MAP_LUTIE,       147, 134 }, //  7=Lutie
  1977. 		{ MAP_COMODO,      209, 143 }, //  8=Comodo
  1978. 		{ MAP_YUNO,        157,  51 }, //  9=Yuno
  1979. 		{ MAP_AMATSU,      198,  84 }, // 10=Amatsu
  1980. 		{ MAP_GONRYUN,     160, 120 }, // 11=Gonryun
  1981. 		{ MAP_UMBALA,       89, 157 }, // 12=Umbala
  1982. 		{ MAP_NIFLHEIM,     21, 153 }, // 13=Niflheim
  1983. 		{ MAP_LOUYANG,     217,  40 }, // 14=Louyang
  1984. 		{ MAP_NOVICE,       53, 111 }, // 15=Training Grounds
  1985. 		{ MAP_JAIL,         23,  61 }, // 16=Prison
  1986. 		{ MAP_JAWAII,      249, 127 }, // 17=Jawaii
  1987. 		{ MAP_AYOTHAYA,    151, 117 }, // 18=Ayothaya
  1988. 		{ MAP_EINBROCH,     64, 200 }, // 19=Einbroch
  1989. 		{ MAP_LIGHTHALZEN, 158,  92 }, // 20=Lighthalzen
  1990. 		{ MAP_EINBECH,      70,  95 }, // 21=Einbech
  1991. 		{ MAP_HUGEL,        96, 145 }, // 22=Hugel
  1992. 		{ MAP_RACHEL,      130, 110 }, // 23=Rachel
  1993. 		{ MAP_VEINS,       216, 123 }, // 24=Veins
  1994. 		{ MAP_MOSCOVIA,    223, 184 }, // 25=Moscovia
  1995. 		{ MAP_MIDCAMP,     180, 240 }, // 26=Midgard Camp
  1996. 		{ MAP_MANUK,       282, 138 }, // 27=Manuk
  1997. 		{ MAP_SPLENDIDE,   197, 176 }, // 28=Splendide
  1998. 		{ MAP_BRASILIS,    182, 239 }, // 29=Brasilis
  1999. <<<<<<< .mine
  2000. 		{ MAP_DICASTES,   198, 187 }, // 30=El Dicastes
  2001. 		{ MAP_MORA,   44, 151 }, // 31=Mora
  2002. 		{ MAP_DEWATA,   200, 180 }, // 32=Dewata
  2003. 		{ MAP_MALANGDO,   140, 114 }, // 33=Malangdo Island
  2004. 		{ MAP_MALAYA,   232, 222 }, // 34=Malaya Port
  2005. 		{ MAP_ECLAGE,   110, 39 }, // 35=Eclage
  2006. =======
  2007. 		{ MAP_DICASTES,    198, 187 }, // 30=El Dicastes
  2008. 		{ MAP_MORA,         44, 151 }, // 31=Mora
  2009. 		{ MAP_DEWATA,      200, 180 }, // 32=Dewata
  2010. 		{ MAP_MALANGDO,    140, 114 }, // 33=Malangdo Island
  2011. 		{ MAP_MALAYA,      242, 211 }, // 34=Malaya Port
  2012. 		{ MAP_ECLAGE,      110,  39 }, // 35=Eclage
  2013. >>>>>>> .r16590
  2014. 	};
  2015.  
  2016. 	nullpo_retr(-1, sd);
  2017.  
  2018. 	if( map[sd->bl.m].flag.nogo && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  2019. 		clif_displaymessage(sd->fd,"You can not use @go on this map.");
  2020. 		return 0;
  2021. 	}
  2022.  
  2023. 	memset(map_name, '\0', sizeof(map_name));
  2024. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2025.  
  2026. 	// get the number
  2027. 	town = atoi(message);
  2028.  
  2029. 	if (!message || !*message || sscanf(message, "%11s", map_name) < 1 || town < 0 || town >= ARRAYLENGTH(data))
  2030. 	{// no value matched so send the list of locations
  2031. 		const char* text;
  2032.  
  2033. 		// attempt to find the text help string
  2034. 		text = atcommand_help_string( command );
  2035.  
  2036. 		// Invalid location number, or name.
  2037. 		clif_displaymessage(fd, msg_txt(38));
  2038.  
  2039. 		if( text )
  2040. 		{// send the text to the client
  2041. 			clif_displaymessage( fd, text );
  2042. 		}
  2043.  
  2044. 		return -1;
  2045. 	}
  2046.  
  2047. 	// get possible name of the city
  2048. 	map_name[MAP_NAME_LENGTH-1] = '\0';
  2049. 	for (i = 0; map_name[i]; i++)
  2050. 		map_name[i] = TOLOWER(map_name[i]);
  2051. 	// try to identify the map name
  2052. 	if (strncmp(map_name, "prontera", 3) == 0) {
  2053. 		town = 0;
  2054. 	} else if (strncmp(map_name, "morocc", 3) == 0) {
  2055. 		town = 1;
  2056. 	} else if (strncmp(map_name, "geffen", 3) == 0) {
  2057. 		town = 2;
  2058. 	} else if (strncmp(map_name, "payon", 3) == 0 ||
  2059. 	           strncmp(map_name, "paion", 3) == 0) {
  2060. 		town = 3;
  2061. 	} else if (strncmp(map_name, "alberta", 3) == 0) {
  2062. 		town = 4;
  2063. 	} else if (strncmp(map_name, "izlude", 3) == 0 ||
  2064. 	           strncmp(map_name, "islude", 3) == 0) {
  2065. 		town = 5;
  2066. 	} else if (strncmp(map_name, "aldebaran", 3) == 0 ||
  2067. 	           strcmp(map_name,  "al") == 0) {
  2068. 		town = 6;
  2069. 	} else if (strncmp(map_name, "lutie", 3) == 0 ||
  2070. 	           strcmp(map_name,  "christmas") == 0 ||
  2071. 	           strncmp(map_name, "xmas", 3) == 0 ||
  2072. 	           strncmp(map_name, "x-mas", 3) == 0) {
  2073. 		town = 7;
  2074. 	} else if (strncmp(map_name, "comodo", 3) == 0) {
  2075. 		town = 8;
  2076. 	} else if (strncmp(map_name, "yuno", 3) == 0) {
  2077. 		town = 9;
  2078. 	} else if (strncmp(map_name, "amatsu", 3) == 0) {
  2079. 		town = 10;
  2080. 	} else if (strncmp(map_name, "gonryun", 3) == 0) {
  2081. 		town = 11;
  2082. 	} else if (strncmp(map_name, "umbala", 3) == 0) {
  2083. 		town = 12;
  2084. 	} else if (strncmp(map_name, "niflheim", 3) == 0) {
  2085. 		town = 13;
  2086. 	} else if (strncmp(map_name, "louyang", 3) == 0) {
  2087. 		town = 14;
  2088. 	} else if (strncmp(map_name, "new_1-1", 3) == 0 ||
  2089. 	           strncmp(map_name, "startpoint", 3) == 0 ||
  2090. 	           strncmp(map_name, "begining", 3) == 0) {
  2091. 		town = 15;
  2092. 	} else if (strncmp(map_name, "sec_pri", 3) == 0 ||
  2093. 	           strncmp(map_name, "prison", 3) == 0 ||
  2094. 	           strncmp(map_name, "jails", 3) == 0) {
  2095. 		town = 16;
  2096. 	} else if (strncmp(map_name, "jawaii", 3) == 0 ||
  2097. 	           strncmp(map_name, "jawai", 3) == 0) {
  2098. 		town = 17;
  2099. 	} else if (strncmp(map_name, "ayothaya", 3) == 0 ||
  2100. 	           strncmp(map_name, "ayotaya", 3) == 0) {
  2101. 		town = 18;
  2102. 	} else if (strncmp(map_name, "einbroch", 5) == 0 ||
  2103. 	           strncmp(map_name, "ainbroch", 5) == 0) {
  2104. 		town = 19;
  2105. 	} else if (strncmp(map_name, "lighthalzen", 3) == 0) {
  2106. 		town = 20;
  2107. 	} else if (strncmp(map_name, "einbech", 3) == 0) {
  2108. 		town = 21;
  2109. 	} else if (strncmp(map_name, "hugel", 3) == 0) {
  2110. 		town = 22;
  2111. 	} else if (strncmp(map_name, "rachel", 3) == 0) {
  2112. 		town = 23;
  2113. 	} else if (strncmp(map_name, "veins", 3) == 0) {
  2114. 		town = 24;
  2115. 	} else if (strncmp(map_name, "moscovia", 3) == 0) {
  2116. 		town = 25;
  2117. 	} else if (strncmp(map_name, "mid_camp", 3) == 0) {
  2118. 		town = 26;
  2119. 	} else if (strncmp(map_name, "manuk", 3) == 0) {
  2120. 		town = 27;
  2121. 	} else if (strncmp(map_name, "splendide", 3) == 0) {
  2122. 		town = 28;
  2123. 	} else if (strncmp(map_name, "brasilis", 3) == 0) {
  2124. 		town = 29;
  2125. 	} else if (strncmp(map_name, "dicastes01", 3) == 0) {
  2126. 		town = 30;
  2127. 	} else if (strncmp(map_name, "mora", 3) == 0) {
  2128. 		town = 31;
  2129. 	} else if (strncmp(map_name, "dewata", 3) == 0) {
  2130. 		town = 32;
  2131. 	} else if (strncmp(map_name, "malangdo", 3) == 0) {
  2132. 		town = 33;
  2133. 	} else if (strncmp(map_name, "malaya", 3) == 0) {
  2134. 		town = 34;
  2135. 	} else if (strncmp(map_name, "eclage", 3) == 0) {
  2136. 		town = 35;
  2137. 	}
  2138.  
  2139. 	if (town >= 0 && town < ARRAYLENGTH(data))
  2140. 	{
  2141. 		m = map_mapname2mapid(data[town].map);
  2142. 		if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2143. 			clif_displaymessage(fd, msg_txt(247));
  2144. 			return -1;
  2145. 		}
  2146. 		if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2147. 			clif_displaymessage(fd, msg_txt(248));
  2148. 			return -1;
  2149. 		}
  2150. 		if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == 0) {
  2151. 			clif_displaymessage(fd, msg_txt(0)); // Warped.
  2152. 		} else {
  2153. 			clif_displaymessage(fd, msg_txt(1)); // Map not found.
  2154. 			return -1;
  2155. 		}
  2156. 	} else { // if you arrive here, you have an error in town variable when reading of names
  2157. 		clif_displaymessage(fd, msg_txt(38)); // Invalid location number or name.
  2158. 		return -1;
  2159. 	}
  2160.  
  2161. 	return 0;
  2162. }
  2163.  
  2164. /*==========================================
  2165.  *
  2166.  *------------------------------------------*/
  2167. ACMD_FUNC(monster)
  2168. {
  2169. 	char name[NAME_LENGTH];
  2170. 	char monster[NAME_LENGTH];
  2171. 	char eventname[EVENT_NAME_LENGTH] = "";
  2172. 	int mob_id;
  2173. 	int number = 0;
  2174. 	int count;
  2175. 	int i, k, range;
  2176. 	short mx, my;
  2177. 	nullpo_retr(-1, sd);
  2178.  
  2179. 	memset(name, '\0', sizeof(name));
  2180. 	memset(monster, '\0', sizeof(monster));
  2181. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2182.  
  2183. 	if (!message || !*message) {
  2184. 			clif_displaymessage(fd, msg_txt(80)); // Give the display name or monster name/id please.
  2185. 			return -1;
  2186. 	}
  2187. 	if (sscanf(message, "\"%23[^\"]\" %23s %d", name, monster, &number) > 1 ||
  2188. 		sscanf(message, "%23s \"%23[^\"]\" %d", monster, name, &number) > 1) {
  2189. 		//All data can be left as it is.
  2190. 	} else if ((count=sscanf(message, "%23s %d %23s", monster, &number, name)) > 1) {
  2191. 		//Here, it is possible name was not given and we are using monster for it.
  2192. 		if (count < 3) //Blank mob's name.
  2193. 			name[0] = '\0';
  2194. 	} else if (sscanf(message, "%23s %23s %d", name, monster, &number) > 1) {
  2195. 		//All data can be left as it is.
  2196. 	} else if (sscanf(message, "%23s", monster) > 0) {
  2197. 		//As before, name may be already filled.
  2198. 		name[0] = '\0';
  2199. 	} else {
  2200. 		clif_displaymessage(fd, msg_txt(80)); // Give a display name and monster name/id please.
  2201. 		return -1;
  2202. 	}
  2203.  
  2204. 	if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
  2205. 		mob_id = mobdb_checkid(atoi(monster));
  2206.  
  2207. 	if (mob_id == 0) {
  2208. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  2209. 		return -1;
  2210. 	}
  2211.  
  2212. 	if (mob_id == MOBID_EMPERIUM) {
  2213. 		clif_displaymessage(fd, msg_txt(83)); // Monster 'Emperium' cannot be spawned.
  2214. 		return -1;
  2215. 	}
  2216.  
  2217. 	if (number <= 0)
  2218. 		number = 1;
  2219.  
  2220. 	if( !name[0] )
  2221. 		strcpy(name, "--ja--");
  2222.  
  2223. 	// 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
  2224. 	if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit)
  2225. 		number = battle_config.atc_spawn_quantity_limit;
  2226.  
  2227. 	if (strcmp(command+1, "monstersmall") == 0)
  2228. 		strcpy(eventname, "2");
  2229. 	else if (strcmp(command+1, "monsterbig") == 0)
  2230. 		strcpy(eventname, "4");
  2231.  
  2232. 	if (battle_config.etc_log)
  2233. 		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);
  2234.  
  2235. 	count = 0;
  2236. 	range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
  2237. 	for (i = 0; i < number; i++) {
  2238. 		map_search_freecell(&sd->bl, 0, &mx,  &my, range, range, 0);
  2239. 		k = mob_once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname);
  2240. 		count += (k != 0) ? 1 : 0;
  2241. 	}
  2242.  
  2243. 	if (count != 0)
  2244. 		if (number == count)
  2245. 			clif_displaymessage(fd, msg_txt(39)); // All monster summoned!
  2246. 		else {
  2247. 			sprintf(atcmd_output, msg_txt(240), count); // %d monster(s) summoned!
  2248. 			clif_displaymessage(fd, atcmd_output);
  2249. 		}
  2250. 	else {
  2251. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  2252. 		return -1;
  2253. 	}
  2254.  
  2255. 	return 0;
  2256. }
  2257.  
  2258. /*==========================================
  2259.  *
  2260.  *------------------------------------------*/
  2261. static int atkillmonster_sub(struct block_list *bl, va_list ap)
  2262. {
  2263. 	struct mob_data *md;
  2264. 	int flag;
  2265.  
  2266. 	nullpo_ret(md=(struct mob_data *)bl);
  2267. 	flag = va_arg(ap, int);
  2268.  
  2269. 	if (md->guardian_data)
  2270. 		return 0; //Do not touch WoE mobs!
  2271.  
  2272. 	if (flag)
  2273. 		status_zap(bl,md->status.hp, 0);
  2274. 	else
  2275. 		status_kill(bl);
  2276. 	return 1;
  2277. }
  2278.  
  2279. void atcommand_killmonster_sub(const int fd, struct map_session_data* sd, const char* message, const int drop)
  2280. {
  2281. 	int map_id;
  2282. 	char map_name[MAP_NAME_LENGTH_EXT];
  2283.  
  2284. 	if (!sd) return;
  2285.  
  2286. 	memset(map_name, '\0', sizeof(map_name));
  2287.  
  2288. 	if (!message || !*message || sscanf(message, "%15s", map_name) < 1)
  2289. 		map_id = sd->bl.m;
  2290. 	else {
  2291. 		if ((map_id = map_mapname2mapid(map_name)) < 0)
  2292. 			map_id = sd->bl.m;
  2293. 	}
  2294.  
  2295. 	map_foreachinmap(atkillmonster_sub, map_id, BL_MOB, drop);
  2296.  
  2297. 	clif_displaymessage(fd, msg_txt(165)); // All monsters killed!
  2298.  
  2299. 	return;
  2300. }
  2301.  
  2302. ACMD_FUNC(killmonster)
  2303. {
  2304. 	atcommand_killmonster_sub(fd, sd, message, 1);
  2305. 	return 0;
  2306. }
  2307.  
  2308. /*==========================================
  2309.  *
  2310.  *------------------------------------------*/
  2311. ACMD_FUNC(killmonster2)
  2312. {
  2313. 	atcommand_killmonster_sub(fd, sd, message, 0);
  2314. 	return 0;
  2315. }
  2316.  
  2317. /*==========================================
  2318.  *
  2319.  *------------------------------------------*/
  2320. ACMD_FUNC(refine)
  2321. {
  2322. 	int i,j, position = 0, refine = 0, current_position, final_refine;
  2323. 	int count;
  2324. 	nullpo_retr(-1, sd);
  2325.  
  2326. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2327.  
  2328. 	if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) {
  2329. 		clif_displaymessage(fd, "Please, enter a position and an amount (usage: @refine <equip position> <+/- amount>).");
  2330. 		sprintf(atcmd_output, "%d: Lower Headgear", EQP_HEAD_LOW);
  2331. 		clif_displaymessage(fd, atcmd_output);
  2332. 		sprintf(atcmd_output, "%d: Right Hand", EQP_HAND_R);
  2333. 		clif_displaymessage(fd, atcmd_output);
  2334. 		sprintf(atcmd_output, "%d: Garment", EQP_GARMENT);
  2335. 		clif_displaymessage(fd, atcmd_output);
  2336. 		sprintf(atcmd_output, "%d: Left Accessory", EQP_ACC_L);
  2337. 		clif_displaymessage(fd, atcmd_output);
  2338. 		sprintf(atcmd_output, "%d: Body Armor", EQP_ARMOR);
  2339. 		clif_displaymessage(fd, atcmd_output);
  2340. 		sprintf(atcmd_output, "%d: Left Hand", EQP_HAND_L);
  2341. 		clif_displaymessage(fd, atcmd_output);
  2342. 		sprintf(atcmd_output, "%d: Shoes", EQP_SHOES);
  2343. 		clif_displaymessage(fd, atcmd_output);
  2344. 		sprintf(atcmd_output, "%d: Right Accessory", EQP_ACC_R);
  2345. 		clif_displaymessage(fd, atcmd_output);
  2346. 		sprintf(atcmd_output, "%d: Top Headgear", EQP_HEAD_TOP);
  2347. 		clif_displaymessage(fd, atcmd_output);
  2348. 		sprintf(atcmd_output, "%d: Mid Headgear", EQP_HEAD_MID);
  2349. 		clif_displaymessage(fd, atcmd_output);
  2350. 		return -1;
  2351. 	}
  2352.  
  2353. 	refine = cap_value(refine, -MAX_REFINE, MAX_REFINE);
  2354.  
  2355. 	count = 0;
  2356. 	for (j = 0; j < EQI_MAX-1; j++) {
  2357. 		if ((i = sd->equip_index[j]) < 0)
  2358. 			continue;
  2359. 		if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == i)
  2360. 			continue;
  2361. 		if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == i)
  2362. 			continue;
  2363. 		if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == i || sd->equip_index[EQI_HEAD_LOW] == i))
  2364. 			continue;
  2365.  
  2366. 		if(position && !(sd->status.inventory[i].equip & position))
  2367. 			continue;
  2368.  
  2369. 		final_refine = cap_value(sd->status.inventory[i].refine + refine, 0, MAX_REFINE);
  2370. 		if (sd->status.inventory[i].refine != final_refine) {
  2371. 			sd->status.inventory[i].refine = final_refine;
  2372. 			current_position = sd->status.inventory[i].equip;
  2373. 			pc_unequipitem(sd, i, 3);
  2374. 			clif_refine(fd, 0, i, sd->status.inventory[i].refine);
  2375. 			clif_delitem(sd, i, 1, 3);
  2376. 			clif_additem(sd, i, 1, 0);
  2377. 			pc_equipitem(sd, i, current_position);
  2378. 			clif_misceffect(&sd->bl, 3);
  2379. 			count++;
  2380. 		}
  2381. 	}
  2382.  
  2383. 	if (count == 0)
  2384. 		clif_displaymessage(fd, msg_txt(166)); // No item has been refined.
  2385. 	else if (count == 1)
  2386. 		clif_displaymessage(fd, msg_txt(167)); // 1 item has been refined.
  2387. 	else {
  2388. 		sprintf(atcmd_output, msg_txt(168), count); // %d items have been refined.
  2389. 		clif_displaymessage(fd, atcmd_output);
  2390. 	}
  2391.  
  2392. 	return 0;
  2393. }
  2394.  
  2395. /*==========================================
  2396.  *
  2397.  *------------------------------------------*/
  2398. ACMD_FUNC(produce)
  2399. {
  2400. 	char item_name[100];
  2401. 	int item_id, attribute = 0, star = 0;
  2402. 	int flag = 0;
  2403. 	struct item_data *item_data;
  2404. 	struct item tmp_item;
  2405. 	nullpo_retr(-1, sd);
  2406.  
  2407. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2408. 	memset(item_name, '\0', sizeof(item_name));
  2409.  
  2410. 	if (!message || !*message || (
  2411. 		sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 &&
  2412. 		sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1
  2413. 	)) {
  2414. 		clif_displaymessage(fd, "Please, enter at least an item name/id (usage: @produce <equip name or equip ID> <element> <# of very's>).");
  2415. 		return -1;
  2416. 	}
  2417.  
  2418. 	item_id = 0;
  2419. 	if ((item_data = itemdb_searchname(item_name)) == NULL &&
  2420. 	    (item_data = itemdb_exists(atoi(item_name))) == NULL)
  2421. 	{
  2422. 		clif_displaymessage(fd, msg_txt(170)); //This item is not an equipment.
  2423. 		return -1;
  2424. 	}
  2425. 	item_id = item_data->nameid;
  2426. 	if (itemdb_isequip2(item_data)) {
  2427. 		if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
  2428. 			attribute = ATTRIBUTE_NORMAL;
  2429. 		if (star < MIN_STAR || star > MAX_STAR)
  2430. 			star = 0;
  2431. 		memset(&tmp_item, 0, sizeof tmp_item);
  2432. 		tmp_item.nameid = item_id;
  2433. 		tmp_item.amount = 1;
  2434. 		tmp_item.identify = 1;
  2435. 		tmp_item.card[0] = CARD0_FORGE;
  2436. 		tmp_item.card[1] = item_data->type==IT_WEAPON?
  2437. 			((star*5) << 8) + attribute:0;
  2438. 		tmp_item.card[2] = GetWord(sd->status.char_id, 0);
  2439. 		tmp_item.card[3] = GetWord(sd->status.char_id, 1);
  2440. 		clif_produceeffect(sd, 0, item_id);
  2441. 		clif_misceffect(&sd->bl, 3);
  2442.  
  2443. 		if ((flag = pc_additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
  2444. 			clif_additem(sd, 0, 0, flag);
  2445. 	} else {
  2446. 		sprintf(atcmd_output, msg_txt(169), item_id, item_data->name); // The item (%d: '%s') is not equipable.
  2447. 		clif_displaymessage(fd, atcmd_output);
  2448. 		return -1;
  2449. 	}
  2450.  
  2451. 	return 0;
  2452. }
  2453.  
  2454. /*==========================================
  2455.  *
  2456.  *------------------------------------------*/
  2457. ACMD_FUNC(memo)
  2458. {
  2459. 	int position = 0;
  2460. 	nullpo_retr(-1, sd);
  2461.  
  2462. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2463.  
  2464. 	if( !message || !*message || sscanf(message, "%d", &position) < 1 )
  2465. 	{
  2466. 		int i;
  2467. 		clif_displaymessage(sd->fd,  msg_txt(668));
  2468. 		for( i = 0; i < MAX_MEMOPOINTS; i++ )
  2469. 		{
  2470. 			if( sd->status.memo_point[i].map )
  2471. 				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);
  2472. 			else
  2473. 				sprintf(atcmd_output, msg_txt(171), i); // %d - void
  2474. 			clif_displaymessage(sd->fd, atcmd_output);
  2475.  		}
  2476. 		return 0;
  2477.  	}
  2478.  
  2479. 	if( position < 0 || position >= MAX_MEMOPOINTS )
  2480. 	{
  2481. 		sprintf(atcmd_output, "Please, enter a valid position (usage: @memo <memo_position:%d-%d>).", 0, MAX_MEMOPOINTS-1);
  2482. 		clif_displaymessage(fd, atcmd_output);
  2483. 		return -1;
  2484. 	}
  2485.  
  2486. 	pc_memo(sd, position);
  2487. 	return 0;
  2488. }
  2489.  
  2490. /*==========================================
  2491.  *
  2492.  *------------------------------------------*/
  2493. ACMD_FUNC(gat)
  2494. {
  2495. 	int y;
  2496. 	nullpo_retr(-1, sd);
  2497.  
  2498. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2499.  
  2500. 	for (y = 2; y >= -2; y--) {
  2501. 		sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
  2502. 			map[sd->bl.m].name,   sd->bl.x - 2, sd->bl.y + y,
  2503.  			map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE),
  2504.  			map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE),
  2505.  			map_getcell(sd->bl.m, sd->bl.x,     sd->bl.y + y, CELL_GETTYPE),
  2506.  			map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE),
  2507.  			map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE));
  2508.  
  2509. 		clif_displaymessage(fd, atcmd_output);
  2510. 	}
  2511.  
  2512. 	return 0;
  2513. }
  2514.  
  2515. /*==========================================
  2516.  *
  2517.  *------------------------------------------*/
  2518. ACMD_FUNC(displaystatus)
  2519. {
  2520. 	int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0;
  2521. 	nullpo_retr(-1, sd);
  2522.  
  2523. 	if (!message || !*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) {
  2524. 		clif_displaymessage(fd, "Please, enter a status type/flag (usage: @displaystatus <status type> <flag> <tick> {<val1> {<val2> {<val3>}}}).");
  2525. 		return -1;
  2526. 	}
  2527. 	if (i < 2) flag = 1;
  2528. 	if (i < 3) tick = 0;
  2529.  
  2530. 	clif_status_change(&sd->bl, type, flag, tick, val1, val2, val3);
  2531.  
  2532. 	return 0;
  2533. }
  2534.  
  2535. /*==========================================
  2536.  * @stpoint (Rewritten by [Yor])
  2537.  *------------------------------------------*/
  2538. ACMD_FUNC(statuspoint)
  2539. {
  2540. 	int point;
  2541. 	unsigned int new_status_point;
  2542.  
  2543. 	if (!message || !*message || (point = atoi(message)) == 0) {
  2544. 		clif_displaymessage(fd, "Please, enter a number (usage: @stpoint <number of points>).");
  2545. 		return -1;
  2546. 	}
  2547.  
  2548. 	if(point < 0)
  2549. 	{
  2550. 		if(sd->status.status_point < (unsigned int)(-point))
  2551. 		{
  2552. 			new_status_point = 0;
  2553. 		}
  2554. 		else
  2555. 		{
  2556. 			new_status_point = sd->status.status_point + point;
  2557. 		}
  2558. 	}
  2559. 	else if(UINT_MAX - sd->status.status_point < (unsigned int)point)
  2560. 	{
  2561. 		new_status_point = UINT_MAX;
  2562. 	}
  2563. 	else
  2564. 	{
  2565. 		new_status_point = sd->status.status_point + point;
  2566. 	}
  2567.  
  2568. 	if (new_status_point != sd->status.status_point) {
  2569. 		sd->status.status_point = new_status_point;
  2570. 		clif_updatestatus(sd, SP_STATUSPOINT);
  2571. 		clif_displaymessage(fd, msg_txt(174)); // Number of status points changed.
  2572. 	} else {
  2573. 		if (point < 0)
  2574. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2575. 		else
  2576. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2577. 		return -1;
  2578. 	}
  2579.  
  2580. 	return 0;
  2581. }
  2582.  
  2583. /*==========================================
  2584.  * @skpoint (Rewritten by [Yor])
  2585.  *------------------------------------------*/
  2586. ACMD_FUNC(skillpoint)
  2587. {
  2588. 	int point;
  2589. 	unsigned int new_skill_point;
  2590. 	nullpo_retr(-1, sd);
  2591.  
  2592. 	if (!message || !*message || (point = atoi(message)) == 0) {
  2593. 		clif_displaymessage(fd, "Please, enter a number (usage: @skpoint <number of points>).");
  2594. 		return -1;
  2595. 	}
  2596.  
  2597. 	if(point < 0)
  2598. 	{
  2599. 		if(sd->status.skill_point < (unsigned int)(-point))
  2600. 		{
  2601. 			new_skill_point = 0;
  2602. 		}
  2603. 		else
  2604. 		{
  2605. 			new_skill_point = sd->status.skill_point + point;
  2606. 		}
  2607. 	}
  2608. 	else if(UINT_MAX - sd->status.skill_point < (unsigned int)point)
  2609. 	{
  2610. 		new_skill_point = UINT_MAX;
  2611. 	}
  2612. 	else
  2613. 	{
  2614. 		new_skill_point = sd->status.skill_point + point;
  2615. 	}
  2616.  
  2617. 	if (new_skill_point != sd->status.skill_point) {
  2618. 		sd->status.skill_point = new_skill_point;
  2619. 		clif_updatestatus(sd, SP_SKILLPOINT);
  2620. 		clif_displaymessage(fd, msg_txt(175)); // Number of skill points changed.
  2621. 	} else {
  2622. 		if (point < 0)
  2623. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2624. 		else
  2625. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2626. 		return -1;
  2627. 	}
  2628.  
  2629. 	return 0;
  2630. }
  2631.  
  2632. /*==========================================
  2633.  * @zeny (Rewritten by [Yor])
  2634.  *------------------------------------------*/
  2635. ACMD_FUNC(zeny)
  2636. {
  2637. 	int zeny, new_zeny;
  2638. 	nullpo_retr(-1, sd);
  2639.  
  2640. 	if (!message || !*message || (zeny = atoi(message)) == 0) {
  2641. 		clif_displaymessage(fd, "Please, enter an amount (usage: @zeny <amount>).");
  2642. 		return -1;
  2643. 	}
  2644.  
  2645. 	new_zeny = sd->status.zeny + zeny;
  2646. 	if (zeny > 0 && (zeny > MAX_ZENY || new_zeny > MAX_ZENY)) // fix positiv overflow
  2647. 		new_zeny = MAX_ZENY;
  2648. 	else if (zeny < 0 && (zeny < -MAX_ZENY || new_zeny < 0)) // fix negativ overflow
  2649. 		new_zeny = 0;
  2650.  
  2651. 	if (new_zeny != sd->status.zeny) {
  2652. 		sd->status.zeny = new_zeny;
  2653. 		clif_updatestatus(sd, SP_ZENY);
  2654. 		clif_displaymessage(fd, msg_txt(176)); // Current amount of zeny changed.
  2655. 	} else {
  2656. 		if (zeny < 0)
  2657. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2658. 		else
  2659. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2660. 		return -1;
  2661. 	}
  2662.  
  2663. 	return 0;
  2664. }
  2665.  
  2666. /*==========================================
  2667.  *
  2668.  *------------------------------------------*/
  2669. ACMD_FUNC(param)
  2670. {
  2671. 	int i, value = 0, new_value, max;
  2672. 	const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" };
  2673. 	short* status[6];
  2674.  	//we don't use direct initialization because it isn't part of the c standard.
  2675. 	nullpo_retr(-1, sd);
  2676.  
  2677. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  2678.  
  2679. 	if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2680. 		sprintf(atcmd_output, "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustment>).");
  2681. 		clif_displaymessage(fd, atcmd_output);
  2682. 		return -1;
  2683. 	}
  2684.  
  2685. 	ARR_FIND( 0, ARRAYLENGTH(param), i, strcmpi(command+1, param[i]) == 0 );
  2686.  
  2687. 	if( i == ARRAYLENGTH(param) || i > MAX_STATUS_TYPE) { // normally impossible...
  2688. 		sprintf(atcmd_output, "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustment>).");
  2689. 		clif_displaymessage(fd, atcmd_output);
  2690. 		return -1;
  2691. 	}
  2692.  
  2693. 	status[0] = &sd->status.str;
  2694. 	status[1] = &sd->status.agi;
  2695. 	status[2] = &sd->status.vit;
  2696. 	status[3] = &sd->status.int_;
  2697. 	status[4] = &sd->status.dex;
  2698. 	status[5] = &sd->status.luk;
  2699.  
  2700. 	if( battle_config.atcommand_max_stat_bypass )
  2701. 		max = SHRT_MAX;
  2702. 	else
  2703. 		max = pc_maxparameter(sd);
  2704.  
  2705. 	if(value < 0 && *status[i] <= -value) {
  2706. 		new_value = 1;
  2707. 	} else if(max - *status[i] < value) {
  2708. 		new_value = max;
  2709. 	} else {
  2710. 		new_value = *status[i] + value;
  2711. 	}
  2712.  
  2713. 	if (new_value != *status[i]) {
  2714. 		*status[i] = new_value;
  2715. 		clif_updatestatus(sd, SP_STR + i);
  2716. 		clif_updatestatus(sd, SP_USTR + i);
  2717. 		status_calc_pc(sd, 0);
  2718. 		clif_displaymessage(fd, msg_txt(42)); // Stat changed.
  2719. 	} else {
  2720. 		if (value < 0)
  2721. 			clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2722. 		else
  2723. 			clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2724. 		return -1;
  2725. 	}
  2726.  
  2727. 	return 0;
  2728. }
  2729.  
  2730. /*==========================================
  2731.  * Stat all by fritz (rewritten by [Yor])
  2732.  *------------------------------------------*/
  2733. ACMD_FUNC(stat_all)
  2734. {
  2735. 	int index, count, value, max, new_value;
  2736. 	short* status[6];
  2737.  	//we don't use direct initialization because it isn't part of the c standard.
  2738. 	nullpo_retr(-1, sd);
  2739.  
  2740. 	status[0] = &sd->status.str;
  2741. 	status[1] = &sd->status.agi;
  2742. 	status[2] = &sd->status.vit;
  2743. 	status[3] = &sd->status.int_;
  2744. 	status[4] = &sd->status.dex;
  2745. 	status[5] = &sd->status.luk;
  2746.  
  2747. 	if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2748. 		value = pc_maxparameter(sd);
  2749. 		max = pc_maxparameter(sd);
  2750. 	} else {
  2751. 		if( battle_config.atcommand_max_stat_bypass )
  2752. 			max = SHRT_MAX;
  2753. 		else
  2754. 			max = pc_maxparameter(sd);
  2755. 	}
  2756.  
  2757. 	count = 0;
  2758. 	for (index = 0; index < ARRAYLENGTH(status); index++) {
  2759.  
  2760. 		if (value > 0 && *status[index] > max - value)
  2761. 			new_value = max;
  2762. 		else if (value < 0 && *status[index] <= -value)
  2763. 			new_value = 1;
  2764. 		else
  2765. 			new_value = *status[index] +value;
  2766.  
  2767. 		if (new_value != (int)*status[index]) {
  2768. 			*status[index] = new_value;
  2769. 			clif_updatestatus(sd, SP_STR + index);
  2770. 			clif_updatestatus(sd, SP_USTR + index);
  2771. 			count++;
  2772. 		}
  2773. 	}
  2774.  
  2775. 	if (count > 0) { // if at least 1 stat modified
  2776. 		status_calc_pc(sd, 0);
  2777. 		clif_displaymessage(fd, msg_txt(84)); // All stats changed!
  2778. 	} else {
  2779. 		if (value < 0)
  2780. 			clif_displaymessage(fd, msg_txt(177)); // You cannot decrease that stat anymore.
  2781. 		else
  2782. 			clif_displaymessage(fd, msg_txt(178)); // You cannot increase that stat anymore.
  2783. 		return -1;
  2784. 	}
  2785.  
  2786. 	return 0;
  2787. }
  2788.  
  2789. /*==========================================
  2790.  *
  2791.  *------------------------------------------*/
  2792. ACMD_FUNC(guildlevelup)
  2793. {
  2794. 	int level = 0;
  2795. 	short added_level;
  2796. 	struct guild *guild_info;
  2797. 	nullpo_retr(-1, sd);
  2798.  
  2799. 	if (!message || !*message || sscanf(message, "%d", &level) < 1 || level == 0) {
  2800. 		clif_displaymessage(fd, "Please, enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>).");
  2801. 		return -1;
  2802. 	}
  2803.  
  2804. 	if (sd->status.guild_id <= 0 || (guild_info = guild_search(sd->status.guild_id)) == NULL) {
  2805. 		clif_displaymessage(fd, msg_txt(43)); // You're not in a guild.
  2806. 		return -1;
  2807. 	}
  2808. 	//if (strcmp(sd->status.name, guild_info->master) != 0) {
  2809. 	//	clif_displaymessage(fd, msg_txt(44)); // You're not the master of your guild.
  2810. 	//	return -1;
  2811. 	//}
  2812.  
  2813. 	added_level = (short)level;
  2814. 	if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild_lv))) // fix positiv overflow
  2815. 		added_level = (short)MAX_GUILDLEVEL - guild_info->guild_lv;
  2816. 	else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild_lv))) // fix negativ overflow
  2817. 		added_level = 1 - guild_info->guild_lv;
  2818.  
  2819. 	if (added_level != 0) {
  2820. 		intif_guild_change_basicinfo(guild_info->guild_id, GBI_GUILDLV, &added_level, sizeof(added_level));
  2821. 		clif_displaymessage(fd, msg_txt(179)); // Guild level changed.
  2822. 	} else {
  2823. 		clif_displaymessage(fd, msg_txt(45)); // Guild level change failed.
  2824. 		return -1;
  2825. 	}
  2826.  
  2827. 	return 0;
  2828. }
  2829.  
  2830. /*==========================================
  2831.  *
  2832.  *------------------------------------------*/
  2833. ACMD_FUNC(makeegg)
  2834. {
  2835. 	struct item_data *item_data;
  2836. 	int id, pet_id;
  2837. 	nullpo_retr(-1, sd);
  2838.  
  2839. 	if (!message || !*message) {
  2840. 		clif_displaymessage(fd, "Please, enter a monster/egg name/id (usage: @makeegg <pet>).");
  2841. 		return -1;
  2842. 	}
  2843.  
  2844. 	if ((item_data = itemdb_searchname(message)) != NULL) // for egg name
  2845. 		id = item_data->nameid;
  2846. 	else
  2847. 	if ((id = mobdb_searchname(message)) != 0) // for monster name
  2848. 		;
  2849. 	else
  2850. 		id = atoi(message);
  2851.  
  2852. 	pet_id = search_petDB_index(id, PET_CLASS);
  2853. 	if (pet_id < 0)
  2854. 		pet_id = search_petDB_index(id, PET_EGG);
  2855. 	if (pet_id >= 0) {
  2856. 		sd->catch_target_class = pet_db[pet_id].class_;
  2857. 		intif_create_pet(
  2858. 			sd->status.account_id, sd->status.char_id,
  2859. 			(short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  2860. 			(short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  2861. 			100, 0, 1, pet_db[pet_id].jname);
  2862. 	} else {
  2863. 		clif_displaymessage(fd, msg_txt(180)); // The monster/egg name/id doesn't exist.
  2864. 		return -1;
  2865. 	}
  2866.  
  2867. 	return 0;
  2868. }
  2869.  
  2870. /*==========================================
  2871.  *
  2872.  *------------------------------------------*/
  2873. ACMD_FUNC(hatch)
  2874. {
  2875. 	nullpo_retr(-1, sd);
  2876. 	if (sd->status.pet_id <= 0)
  2877. 		clif_sendegg(sd);
  2878. 	else {
  2879. 		clif_displaymessage(fd, msg_txt(181)); // You already have a pet.
  2880. 		return -1;
  2881. 	}
  2882.  
  2883. 	return 0;
  2884. }
  2885.  
  2886. /*==========================================
  2887.  *
  2888.  *------------------------------------------*/
  2889. ACMD_FUNC(petfriendly)
  2890. {
  2891. 	int friendly;
  2892. 	struct pet_data *pd;
  2893. 	nullpo_retr(-1, sd);
  2894.  
  2895. 	if (!message || !*message || (friendly = atoi(message)) < 0) {
  2896. 		clif_displaymessage(fd, "Please, enter a valid value (usage: @petfriendly <0-1000>).");
  2897. 		return -1;
  2898. 	}
  2899.  
  2900. 	pd = sd->pd;
  2901. 	if (!pd) {
  2902. 		clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2903. 		return -1;
  2904. 	}
  2905.  
  2906. 	if (friendly < 0 || friendly > 1000)
  2907. 	{
  2908. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  2909. 		return -1;
  2910. 	}
  2911.  
  2912. 	if (friendly == pd->pet.intimate) {
  2913. 		clif_displaymessage(fd, msg_txt(183)); // Pet intimacy is already at maximum.
  2914. 		return -1;
  2915. 	}
  2916.  
  2917. 	pet_set_intimate(pd, friendly);
  2918. 	clif_send_petstatus(sd);
  2919. 	clif_displaymessage(fd, msg_txt(182)); // Pet intimacy changed.
  2920. 	return 0;
  2921. }
  2922.  
  2923. /*==========================================
  2924.  *
  2925.  *------------------------------------------*/
  2926. ACMD_FUNC(pethungry)
  2927. {
  2928. 	int hungry;
  2929. 	struct pet_data *pd;
  2930. 	nullpo_retr(-1, sd);
  2931.  
  2932. 	if (!message || !*message || (hungry = atoi(message)) < 0) {
  2933. 		clif_displaymessage(fd, "Please, enter a valid number (usage: @pethungry <0-100>).");
  2934. 		return -1;
  2935. 	}
  2936.  
  2937. 	pd = sd->pd;
  2938. 	if (!sd->status.pet_id || !pd) {
  2939. 		clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2940. 		return -1;
  2941. 	}
  2942. 	if (hungry < 0 || hungry > 100) {
  2943. 		clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  2944. 		return -1;
  2945. 	}
  2946. 	if (hungry == pd->pet.hungry) {
  2947. 		clif_displaymessage(fd, msg_txt(186)); // Pet hunger is already at maximum.
  2948. 		return -1;
  2949. 	}
  2950.  
  2951. 	pd->pet.hungry = hungry;
  2952. 	clif_send_petstatus(sd);
  2953. 	clif_displaymessage(fd, msg_txt(185)); // Pet hunger changed.
  2954.  
  2955. 	return 0;
  2956. }
  2957.  
  2958. /*==========================================
  2959.  *
  2960.  *------------------------------------------*/
  2961. ACMD_FUNC(petrename)
  2962. {
  2963. 	struct pet_data *pd;
  2964. 	nullpo_retr(-1, sd);
  2965. 	if (!sd->status.pet_id || !sd->pd) {
  2966. 		clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2967. 		return -1;
  2968. 	}
  2969. 	pd = sd->pd;
  2970. 	if (!pd->pet.rename_flag) {
  2971. 		clif_displaymessage(fd, msg_txt(188)); // You can already rename your pet.
  2972. 		return -1;
  2973. 	}
  2974.  
  2975. 	pd->pet.rename_flag = 0;
  2976. 	intif_save_petdata(sd->status.account_id, &pd->pet);
  2977. 	clif_send_petstatus(sd);
  2978. 	clif_displaymessage(fd, msg_txt(187)); // You can now rename your pet.
  2979.  
  2980. 	return 0;
  2981. }
  2982.  
  2983. /*==========================================
  2984.  *
  2985.  *------------------------------------------*/
  2986. ACMD_FUNC(recall) {
  2987. 	struct map_session_data *pl_sd = NULL;
  2988.  
  2989. 	nullpo_retr(-1, sd);
  2990.  
  2991. 	if (!message || !*message) {
  2992. 		clif_displaymessage(fd, "Please, enter a player name (usage: @recall <player name/id>).");
  2993. 		return -1;
  2994. 	}
  2995.  
  2996. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  2997. 	{
  2998. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  2999. 		return -1;
  3000. 	}
  3001.  
  3002. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  3003. 	{
  3004. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level doesn't authorize you to preform this action on the specified player.
  3005. 		return -1;
  3006. 	}
  3007.  
  3008. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3009. 		clif_displaymessage(fd, "You are not authorised to warp someone to your actual map.");
  3010. 		return -1;
  3011. 	}
  3012. 	if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3013. 		clif_displaymessage(fd, "You are not authorized to warp this player from its actual map.");
  3014. 		return -1;
  3015. 	}
  3016. 	pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3017. 	sprintf(atcmd_output, msg_txt(46), pl_sd->status.name); // %s recalled!
  3018. 	clif_displaymessage(fd, atcmd_output);
  3019.  
  3020. 	return 0;
  3021. }
  3022.  
  3023. /*==========================================
  3024.  * charblock command (usage: charblock <player_name>)
  3025.  * This command do a definitiv ban on a player
  3026.  *------------------------------------------*/
  3027. ACMD_FUNC(char_block)
  3028. {
  3029. 	nullpo_retr(-1, sd);
  3030.  
  3031. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3032.  
  3033. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3034. 		clif_displaymessage(fd, "Please, enter a player name (usage: @charblock/@block <name>).");
  3035. 		return -1;
  3036. 	}
  3037.  
  3038. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  3039. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3040.  
  3041. 	return 0;
  3042. }
  3043.  
  3044. /*==========================================
  3045.  * charban command (usage: charban <time> <player_name>)
  3046.  * This command do a limited ban on a player
  3047.  * Time is done as follows:
  3048.  *   Adjustment value (-1, 1, +1, etc...)
  3049.  *   Modified element:
  3050.  *     a or y: year
  3051.  *     m:  month
  3052.  *     j or d: day
  3053.  *     h:  hour
  3054.  *     mn: minute
  3055.  *     s:  second
  3056.  * <example> @ban +1m-2mn1s-6y test_player
  3057.  *           this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
  3058.  *------------------------------------------*/
  3059. ACMD_FUNC(char_ban)
  3060. {
  3061. 	char * modif_p;
  3062. 	int year, month, day, hour, minute, second, value;
  3063. 	time_t timestamp;
  3064. 	struct tm *tmtime;
  3065. 	nullpo_retr(-1, sd);
  3066.  
  3067. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3068. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3069.  
  3070. 	if (!message || !*message || sscanf(message, "%s %23[^\n]", atcmd_output, atcmd_player_name) < 2) {
  3071. 		clif_displaymessage(fd, "Please, enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish <time> <name>).");
  3072. 		return -1;
  3073. 	}
  3074.  
  3075. 	atcmd_output[sizeof(atcmd_output)-1] = '\0';
  3076.  
  3077. 	modif_p = atcmd_output;
  3078. 	year = month = day = hour = minute = second = 0;
  3079. 	while (modif_p[0] != '\0') {
  3080. 		value = atoi(modif_p);
  3081. 		if (value == 0)
  3082. 			modif_p++;
  3083. 		else {
  3084. 			if (modif_p[0] == '-' || modif_p[0] == '+')
  3085. 				modif_p++;
  3086. 			while (modif_p[0] >= '0' && modif_p[0] <= '9')
  3087. 				modif_p++;
  3088. 			if (modif_p[0] == 's') {
  3089. 				second = value;
  3090. 				modif_p++;
  3091. 			} else if (modif_p[0] == 'n') {
  3092. 				minute = value;
  3093. 				modif_p++;
  3094. 			} else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  3095. 				minute = value;
  3096. 				modif_p = modif_p + 2;
  3097. 			} else if (modif_p[0] == 'h') {
  3098. 				hour = value;
  3099. 				modif_p++;
  3100. 			} else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  3101. 				day = value;
  3102. 				modif_p++;
  3103. 			} else if (modif_p[0] == 'm') {
  3104. 				month = value;
  3105. 				modif_p++;
  3106. 			} else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  3107. 				year = value;
  3108. 				modif_p++;
  3109. 			} else if (modif_p[0] != '\0') {
  3110. 				modif_p++;
  3111. 			}
  3112. 		}
  3113. 	}
  3114. 	if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0) {
  3115. 		clif_displaymessage(fd, msg_txt(85)); // Invalid time for ban command.
  3116. 		return -1;
  3117. 	}
  3118. 	/**
  3119. 	 * We now check if you can adjust the ban to negative (and if this is the case)
  3120. 	 **/
  3121. 	timestamp = time(NULL);
  3122. 	tmtime = localtime(&timestamp);
  3123. 	tmtime->tm_year = tmtime->tm_year + year;
  3124. 	tmtime->tm_mon  = tmtime->tm_mon + month;
  3125. 	tmtime->tm_mday = tmtime->tm_mday + day;
  3126. 	tmtime->tm_hour = tmtime->tm_hour + hour;
  3127. 	tmtime->tm_min  = tmtime->tm_min + minute;
  3128. 	tmtime->tm_sec  = tmtime->tm_sec + second;
  3129. 	timestamp = mktime(tmtime);
  3130. 	if( timestamp <= time(NULL) && !pc_can_use_command(sd, "unban", COMMAND_ATCOMMAND) ) {
  3131. 		clif_displaymessage(fd,"You are not allowed to reduce the length of a ban");
  3132. 		return -1;
  3133. 	}
  3134.  
  3135. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 2, year, month, day, hour, minute, second); // type: 2 - ban
  3136. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3137.  
  3138. 	return 0;
  3139. }
  3140.  
  3141. /*==========================================
  3142.  * charunblock command (usage: charunblock <player_name>)
  3143.  *------------------------------------------*/
  3144. ACMD_FUNC(char_unblock)
  3145. {
  3146. 	nullpo_retr(-1, sd);
  3147.  
  3148. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3149.  
  3150. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3151. 		clif_displaymessage(fd, "Please, enter a player name (usage: @charunblock <player_name>).");
  3152. 		return -1;
  3153. 	}
  3154.  
  3155. 	// send answer to login server via char-server
  3156. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 3, 0, 0, 0, 0, 0, 0); // type: 3 - unblock
  3157. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3158.  
  3159. 	return 0;
  3160. }
  3161.  
  3162. /*==========================================
  3163.  * charunban command (usage: charunban <player_name>)
  3164.  *------------------------------------------*/
  3165. ACMD_FUNC(char_unban)
  3166. {
  3167. 	nullpo_retr(-1, sd);
  3168.  
  3169. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3170.  
  3171. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3172. 		clif_displaymessage(fd, "Please, enter a player name (usage: @charunban <player_name>).");
  3173. 		return -1;
  3174. 	}
  3175.  
  3176. 	// send answer to login server via char-server
  3177. 	chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 4, 0, 0, 0, 0, 0, 0); // type: 4 - unban
  3178. 	clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  3179.  
  3180. 	return 0;
  3181. }
  3182.  
  3183. /*==========================================
  3184.  *
  3185.  *------------------------------------------*/
  3186. ACMD_FUNC(night)
  3187. {
  3188. 	nullpo_retr(-1, sd);
  3189.  
  3190. 	if (night_flag != 1) {
  3191. 		map_night_timer(night_timer_tid, 0, 0, 1);
  3192. 	} else {
  3193. 		clif_displaymessage(fd, msg_txt(89)); // Night mode is already enabled.
  3194. 		return -1;
  3195. 	}
  3196.  
  3197. 	return 0;
  3198. }
  3199.  
  3200. /*==========================================
  3201.  *
  3202.  *------------------------------------------*/
  3203. ACMD_FUNC(day)
  3204. {
  3205. 	nullpo_retr(-1, sd);
  3206.  
  3207. 	if (night_flag != 0) {
  3208. 		map_day_timer(day_timer_tid, 0, 0, 1);
  3209. 	} else {
  3210. 		clif_displaymessage(fd, msg_txt(90)); // Day mode is already enabled.
  3211. 		return -1;
  3212. 	}
  3213.  
  3214. 	return 0;
  3215. }
  3216.  
  3217. /*==========================================
  3218.  *
  3219.  *------------------------------------------*/
  3220. ACMD_FUNC(doom)
  3221. {
  3222. 	struct map_session_data* pl_sd;
  3223. 	struct s_mapiterator* iter;
  3224.  
  3225. 	nullpo_retr(-1, sd);
  3226.  
  3227. 	iter = mapit_getallusers();
  3228. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3229. 	{
  3230. 		if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3231. 		{
  3232. 			status_kill(&pl_sd->bl);
  3233. 			clif_specialeffect(&pl_sd->bl,450,AREA);
  3234. 			clif_displaymessage(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement.
  3235. 		}
  3236. 	}
  3237. 	mapit_free(iter);
  3238.  
  3239. 	clif_displaymessage(fd, msg_txt(62)); // Judgement was made.
  3240.  
  3241. 	return 0;
  3242. }
  3243.  
  3244. /*==========================================
  3245.  *
  3246.  *------------------------------------------*/
  3247. ACMD_FUNC(doommap)
  3248. {
  3249. 	struct map_session_data* pl_sd;
  3250. 	struct s_mapiterator* iter;
  3251.  
  3252. 	nullpo_retr(-1, sd);
  3253.  
  3254. 	iter = mapit_getallusers();
  3255. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3256. 	{
  3257. 		if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3258. 		{
  3259. 			status_kill(&pl_sd->bl);
  3260. 			clif_specialeffect(&pl_sd->bl,450,AREA);
  3261. 			clif_displaymessage(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement.
  3262. 		}
  3263. 	}
  3264. 	mapit_free(iter);
  3265.  
  3266. 	clif_displaymessage(fd, msg_txt(62)); // Judgement was made.
  3267.  
  3268. 	return 0;
  3269. }
  3270.  
  3271. /*==========================================
  3272.  *
  3273.  *------------------------------------------*/
  3274. static void atcommand_raise_sub(struct map_session_data* sd)
  3275. {
  3276. 	if (!status_isdead(&sd->bl))
  3277. 		return;
  3278.  
  3279. 	if(!status_revive(&sd->bl, 100, 100))
  3280. 		return;
  3281. 	clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  3282. 	clif_displaymessage(sd->fd, msg_txt(63)); // Mercy has been shown.
  3283. }
  3284.  
  3285. /*==========================================
  3286.  *
  3287.  *------------------------------------------*/
  3288. ACMD_FUNC(raise)
  3289. {
  3290. 	struct map_session_data* pl_sd;
  3291. 	struct s_mapiterator* iter;
  3292.  
  3293. 	nullpo_retr(-1, sd);
  3294.  
  3295. 	iter = mapit_getallusers();
  3296. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3297. 		atcommand_raise_sub(pl_sd);
  3298. 	mapit_free(iter);
  3299.  
  3300. 	clif_displaymessage(fd, msg_txt(64)); // Mercy has been granted.
  3301.  
  3302. 	return 0;
  3303. }
  3304.  
  3305. /*==========================================
  3306.  *
  3307.  *------------------------------------------*/
  3308. ACMD_FUNC(raisemap)
  3309. {
  3310. 	struct map_session_data* pl_sd;
  3311. 	struct s_mapiterator* iter;
  3312.  
  3313. 	nullpo_retr(-1, sd);
  3314.  
  3315. 	iter = mapit_getallusers();
  3316. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3317. 		if (sd->bl.m == pl_sd->bl.m)
  3318. 			atcommand_raise_sub(pl_sd);
  3319. 	mapit_free(iter);
  3320.  
  3321. 	clif_displaymessage(fd, msg_txt(64)); // Mercy has been granted.
  3322.  
  3323. 	return 0;
  3324. }
  3325.  
  3326. /*==========================================
  3327.  *
  3328.  *------------------------------------------*/
  3329. ACMD_FUNC(kick)
  3330. {
  3331. 	struct map_session_data *pl_sd;
  3332. 	nullpo_retr(-1, sd);
  3333.  
  3334. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3335.  
  3336. 	if (!message || !*message) {
  3337. 		clif_displaymessage(fd, "Please, enter a player name (usage: @kick <player name/id>).");
  3338. 		return -1;
  3339. 	}
  3340.  
  3341. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  3342. 	{
  3343. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  3344. 		return -1;
  3345. 	}
  3346.  
  3347. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  3348. 	{
  3349. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  3350. 		return -1;
  3351. 	}
  3352.  
  3353. 	clif_GM_kick(sd, pl_sd);
  3354.  
  3355. 	return 0;
  3356. }
  3357.  
  3358. /*==========================================
  3359.  *
  3360.  *------------------------------------------*/
  3361. ACMD_FUNC(kickall)
  3362. {
  3363. 	struct map_session_data* pl_sd;
  3364. 	struct s_mapiterator* iter;
  3365. 	nullpo_retr(-1, sd);
  3366.  
  3367. 	iter = mapit_getallusers();
  3368. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3369. 	{
  3370. 		if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level
  3371. 			if (sd->status.account_id != pl_sd->status.account_id)
  3372. 				clif_GM_kick(NULL, pl_sd);
  3373. 		}
  3374. 	}
  3375. 	mapit_free(iter);
  3376.  
  3377. 	clif_displaymessage(fd, msg_txt(195)); // All players have been kicked!
  3378.  
  3379. 	return 0;
  3380. }
  3381.  
  3382. /*==========================================
  3383.  *
  3384.  *------------------------------------------*/
  3385. ACMD_FUNC(allskill)
  3386. {
  3387. 	nullpo_retr(-1, sd);
  3388. 	pc_allskillup(sd); // all skills
  3389. 	sd->status.skill_point = 0; // 0 skill points
  3390. 	clif_updatestatus(sd, SP_SKILLPOINT); // update
  3391. 	clif_displaymessage(fd, msg_txt(76)); // All skills have been added to your skill tree.
  3392.  
  3393. 	return 0;
  3394. }
  3395.  
  3396. /*==========================================
  3397.  *
  3398.  *------------------------------------------*/
  3399. ACMD_FUNC(questskill)
  3400. {
  3401. 	int skill_id;
  3402. 	nullpo_retr(-1, sd);
  3403.  
  3404. 	if (!message || !*message || (skill_id = atoi(message)) < 0)
  3405. 	{// also send a list of skills applicable to this command
  3406. 		const char* text;
  3407.  
  3408. 		// attempt to find the text corresponding to this command
  3409. 		text = atcommand_help_string( command );
  3410.  
  3411. 		// send the error message as always
  3412. 		clif_displaymessage(fd, "Please enter a quest skill number.");
  3413.  
  3414. 		if( text )
  3415. 		{// send the skill ID list associated with this command
  3416. 			clif_displaymessage( fd, text );
  3417. 		}
  3418.  
  3419. 		return -1;
  3420. 	}
  3421. 	if (skill_id < 0 && skill_id >= MAX_SKILL_DB) {
  3422. 		clif_displaymessage(fd, msg_txt(198)); // This skill number doesn't exist.
  3423. 		return -1;
  3424. 	}
  3425. 	if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  3426. 		clif_displaymessage(fd, msg_txt(197)); // This skill number doesn't exist or isn't a quest skill.
  3427. 		return -1;
  3428. 	}
  3429. 	if (pc_checkskill(sd, skill_id) > 0) {
  3430. 		clif_displaymessage(fd, msg_txt(196)); // You already have this quest skill.
  3431. 		return -1;
  3432. 	}
  3433.  
  3434. 	pc_skill(sd, skill_id, 1, 0);
  3435. 	clif_displaymessage(fd, msg_txt(70)); // You have learned the skill.
  3436.  
  3437. 	return 0;
  3438. }
  3439.  
  3440. /*==========================================
  3441.  *
  3442.  *------------------------------------------*/
  3443. ACMD_FUNC(lostskill)
  3444. {
  3445. 	int skill_id;
  3446. 	nullpo_retr(-1, sd);
  3447.  
  3448. 	if (!message || !*message || (skill_id = atoi(message)) < 0)
  3449. 	{// also send a list of skills applicable to this command
  3450. 		const char* text;
  3451.  
  3452. 		// attempt to find the text corresponding to this command
  3453. 		text = atcommand_help_string( command );
  3454.  
  3455. 		// send the error message as always
  3456. 		clif_displaymessage(fd, "Please enter a quest skill number.");
  3457.  
  3458. 		if( text )
  3459. 		{// send the skill ID list associated with this command
  3460. 			clif_displaymessage( fd, text );
  3461. 		}
  3462.  
  3463. 		return -1;
  3464. 	}
  3465. 	if (skill_id < 0 && skill_id >= MAX_SKILL) {
  3466. 		clif_displaymessage(fd, msg_txt(198)); // This skill number doesn't exist.
  3467. 		return -1;
  3468. 	}
  3469. 	if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  3470. 		clif_displaymessage(fd, msg_txt(197)); // This skill number doesn't exist or isn't a quest skill.
  3471. 		return -1;
  3472. 	}
  3473. 	if (pc_checkskill(sd, skill_id) == 0) {
  3474. 		clif_displaymessage(fd, msg_txt(201)); // You don't have this quest skill.
  3475. 		return -1;
  3476. 	}
  3477.  
  3478. 	sd->status.skill[skill_id].lv = 0;
  3479. 	sd->status.skill[skill_id].flag = 0;
  3480. 	clif_deleteskill(sd,skill_id);
  3481. 	clif_displaymessage(fd, msg_txt(71)); // You have forgotten the skill.
  3482.  
  3483. 	return 0;
  3484. }
  3485.  
  3486. /*==========================================
  3487.  *
  3488.  *------------------------------------------*/
  3489. ACMD_FUNC(spiritball)
  3490. {
  3491. 	int max_spiritballs;
  3492. 	int number;
  3493. 	nullpo_retr(-1, sd);
  3494.  
  3495. 	max_spiritballs = min(ARRAYLENGTH(sd->spirit_timer), 0x7FFF);
  3496.  
  3497. 	if( !message || !*message || (number = atoi(message)) < 0 || number > max_spiritballs )
  3498. 	{
  3499. 		char msg[CHAT_SIZE_MAX];
  3500. 		safesnprintf(msg, sizeof(msg), "Usage: @spiritball <number: 0-%d>", max_spiritballs);
  3501. 		clif_displaymessage(fd, msg);
  3502. 		return -1;
  3503. 	}
  3504.  
  3505. 	if( sd->spiritball > 0 )
  3506. 		pc_delspiritball(sd, sd->spiritball, 1);
  3507. 	sd->spiritball = number;
  3508. 	clif_spiritball(sd);
  3509. 	// no message, player can look the difference
  3510.  
  3511. 	return 0;
  3512. }
  3513.  
  3514. /*==========================================
  3515.  *
  3516.  *------------------------------------------*/
  3517. ACMD_FUNC(party)
  3518. {
  3519. 	char party[NAME_LENGTH];
  3520. 	nullpo_retr(-1, sd);
  3521.  
  3522. 	memset(party, '\0', sizeof(party));
  3523.  
  3524. 	if (!message || !*message || sscanf(message, "%23[^\n]", party) < 1) {
  3525. 		clif_displaymessage(fd, "Please, enter a party name (usage: @party <party_name>).");
  3526. 		return -1;
  3527. 	}
  3528.  
  3529. 	party_create(sd, party, 0, 0);
  3530.  
  3531. 	return 0;
  3532. }
  3533.  
  3534. /*==========================================
  3535.  *
  3536.  *------------------------------------------*/
  3537. ACMD_FUNC(guild)
  3538. {
  3539. 	char guild[NAME_LENGTH];
  3540. 	int prev;
  3541. 	nullpo_retr(-1, sd);
  3542.  
  3543. 	memset(guild, '\0', sizeof(guild));
  3544.  
  3545. 	if (!message || !*message || sscanf(message, "%23[^\n]", guild) < 1) {
  3546. 		clif_displaymessage(fd, "Please, enter a guild name (usage: @guild <guild_name>).");
  3547. 		return -1;
  3548. 	}
  3549.  
  3550. 	prev = battle_config.guild_emperium_check;
  3551. 	battle_config.guild_emperium_check = 0;
  3552. 	guild_create(sd, guild);
  3553. 	battle_config.guild_emperium_check = prev;
  3554.  
  3555. 	return 0;
  3556. }
  3557.  
  3558. /*==========================================
  3559.  *
  3560.  *------------------------------------------*/
  3561. ACMD_FUNC(agitstart)
  3562. {
  3563. 	nullpo_retr(-1, sd);
  3564. 	if (agit_flag == 1) {
  3565. 		clif_displaymessage(fd, msg_txt(73)); // War of Emperium is currently in progress.
  3566. 		return -1;
  3567. 	}
  3568.  
  3569. 	agit_flag = 1;
  3570. 	guild_agit_start();
  3571. 	clif_displaymessage(fd, msg_txt(72)); // War of Emperium has been initiated.
  3572.  
  3573. 	return 0;
  3574. }
  3575.  
  3576. /*==========================================
  3577.  *
  3578.  *------------------------------------------*/
  3579. ACMD_FUNC(agitstart2)
  3580. {
  3581. 	nullpo_retr(-1, sd);
  3582. 	if (agit2_flag == 1) {
  3583. 		clif_displaymessage(fd, msg_txt(404)); // "War of Emperium SE is currently in progress."
  3584. 		return -1;
  3585. 	}
  3586.  
  3587. 	agit2_flag = 1;
  3588. 	guild_agit2_start();
  3589. 	clif_displaymessage(fd, msg_txt(403)); // "War of Emperium SE has been initiated."
  3590.  
  3591. 	return 0;
  3592. }
  3593.  
  3594. /*==========================================
  3595.  *
  3596.  *------------------------------------------*/
  3597. ACMD_FUNC(agitend)
  3598. {
  3599. 	nullpo_retr(-1, sd);
  3600. 	if (agit_flag == 0) {
  3601. 		clif_displaymessage(fd, msg_txt(75)); // War of Emperium is currently not in progress.
  3602. 		return -1;
  3603. 	}
  3604.  
  3605. 	agit_flag = 0;
  3606. 	guild_agit_end();
  3607. 	clif_displaymessage(fd, msg_txt(74)); // War of Emperium has been ended.
  3608.  
  3609. 	return 0;
  3610. }
  3611.  
  3612. /*==========================================
  3613.  *
  3614.  *------------------------------------------*/
  3615. ACMD_FUNC(agitend2)
  3616. {
  3617. 	nullpo_retr(-1, sd);
  3618. 	if (agit2_flag == 0) {
  3619. 		clif_displaymessage(fd, msg_txt(406)); // "War of Emperium SE is currently not in progress."
  3620. 		return -1;
  3621. 	}
  3622.  
  3623. 	agit2_flag = 0;
  3624. 	guild_agit2_end();
  3625. 	clif_displaymessage(fd, msg_txt(405)); // "War of Emperium SE has been ended."
  3626.  
  3627. 	return 0;
  3628. }
  3629.  
  3630. /*==========================================
  3631.  * @mapexit - shuts down the map server
  3632.  *------------------------------------------*/
  3633. ACMD_FUNC(mapexit)
  3634. {
  3635. 	nullpo_retr(-1, sd);
  3636.  
  3637. 	do_shutdown();
  3638. 	return 0;
  3639. }
  3640.  
  3641. /*==========================================
  3642.  * idsearch <part_of_name>: revrited by [Yor]
  3643.  *------------------------------------------*/
  3644. ACMD_FUNC(idsearch)
  3645. {
  3646. 	char item_name[100];
  3647. 	unsigned int i, match;
  3648. 	struct item_data *item_array[MAX_SEARCH];
  3649. 	nullpo_retr(-1, sd);
  3650.  
  3651. 	memset(item_name, '\0', sizeof(item_name));
  3652. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3653.  
  3654. 	if (!message || !*message || sscanf(message, "%99s", item_name) < 0) {
  3655. 		clif_displaymessage(fd, "Please, enter a part of item name (usage: @idsearch <part_of_item_name>).");
  3656. 		return -1;
  3657. 	}
  3658.  
  3659. 	sprintf(atcmd_output, msg_txt(77), item_name); // The reference result of '%s' (name: id):
  3660. 	clif_displaymessage(fd, atcmd_output);
  3661. 	match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name);
  3662. 	if (match > MAX_SEARCH) {
  3663. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, match);
  3664. 		clif_displaymessage(fd, atcmd_output);
  3665. 		match = MAX_SEARCH;
  3666. 	}
  3667. 	for(i = 0; i < match; i++) {
  3668. 		sprintf(atcmd_output, msg_txt(78), item_array[i]->jname, item_array[i]->nameid); // %s: %d
  3669. 		clif_displaymessage(fd, atcmd_output);
  3670. 	}
  3671. 	sprintf(atcmd_output, msg_txt(79), match); // It is %d affair above.
  3672. 	clif_displaymessage(fd, atcmd_output);
  3673.  
  3674. 	return 0;
  3675. }
  3676.  
  3677. /*==========================================
  3678.  * Recall All Characters Online To Your Location
  3679.  *------------------------------------------*/
  3680. ACMD_FUNC(recallall)
  3681. {
  3682. 	struct map_session_data* pl_sd;
  3683. 	struct s_mapiterator* iter;
  3684. 	int count;
  3685. 	nullpo_retr(-1, sd);
  3686.  
  3687. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  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. 	count = 0;
  3695. 	iter = mapit_getallusers();
  3696. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3697. 	{
  3698. 		if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3699. 		{
  3700. 			if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3701. 				count++;
  3702. 			else {
  3703. 				if (pc_isdead(pl_sd)) { //Wake them up
  3704. 					pc_setstand(pl_sd);
  3705. 					pc_setrestartvalue(pl_sd,1);
  3706. 				}
  3707. 				pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3708. 			}
  3709. 		}
  3710. 	}
  3711. 	mapit_free(iter);
  3712.  
  3713. 	clif_displaymessage(fd, msg_txt(92)); // All characters recalled!
  3714. 	if (count) {
  3715. 		sprintf(atcmd_output, "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count);
  3716. 		clif_displaymessage(fd, atcmd_output);
  3717. 	}
  3718.  
  3719. 	return 0;
  3720. }
  3721.  
  3722. /*==========================================
  3723.  * Recall online characters of a guild to your location
  3724.  *------------------------------------------*/
  3725. ACMD_FUNC(guildrecall)
  3726. {
  3727. 	struct map_session_data* pl_sd;
  3728. 	struct s_mapiterator* iter;
  3729. 	int count;
  3730. 	char guild_name[NAME_LENGTH];
  3731. 	struct guild *g;
  3732. 	nullpo_retr(-1, sd);
  3733.  
  3734. 	memset(guild_name, '\0', sizeof(guild_name));
  3735. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3736.  
  3737. 	if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  3738. 		clif_displaymessage(fd, "Please, enter a guild name/id (usage: @guildrecall <guild_name/id>).");
  3739. 		return -1;
  3740. 	}
  3741.  
  3742. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3743. 		clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map.");
  3744. 		return -1;
  3745. 	}
  3746.  
  3747. 	if ((g = guild_searchname(guild_name)) == NULL && // name first to avoid error when name begin with a number
  3748. 	    (g = guild_search(atoi(message))) == NULL)
  3749. 	{
  3750. 		clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the guild is online.
  3751. 		return -1;
  3752. 	}
  3753.  
  3754. 	count = 0;
  3755.  
  3756. 	iter = mapit_getallusers();
  3757. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3758. 	{
  3759. 		if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id)
  3760. 		{
  3761. 			if (pc_get_group_level(pl_sd) > pc_get_group_level(sd))
  3762. 				continue; //Skip GMs greater than you.
  3763. 			if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3764. 				count++;
  3765. 			else
  3766. 				pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3767. 		}
  3768. 	}
  3769. 	mapit_free(iter);
  3770.  
  3771. 	sprintf(atcmd_output, msg_txt(93), g->name); // All online characters of the %s guild have been recalled to your position.
  3772. 	clif_displaymessage(fd, atcmd_output);
  3773. 	if (count) {
  3774. 		sprintf(atcmd_output, "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count);
  3775. 		clif_displaymessage(fd, atcmd_output);
  3776. 	}
  3777.  
  3778. 	return 0;
  3779. }
  3780.  
  3781. /*==========================================
  3782.  * Recall online characters of a party to your location
  3783.  *------------------------------------------*/
  3784. ACMD_FUNC(partyrecall)
  3785. {
  3786. 	struct map_session_data* pl_sd;
  3787. 	struct s_mapiterator* iter;
  3788. 	char party_name[NAME_LENGTH];
  3789. 	struct party_data *p;
  3790. 	int count;
  3791. 	nullpo_retr(-1, sd);
  3792.  
  3793. 	memset(party_name, '\0', sizeof(party_name));
  3794. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  3795.  
  3796. 	if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3797. 		clif_displaymessage(fd, "Please, enter a party name/id (usage: @partyrecall <party_name/id>).");
  3798. 		return -1;
  3799. 	}
  3800.  
  3801. 	if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3802. 		clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map.");
  3803. 		return -1;
  3804. 	}
  3805.  
  3806. 	if ((p = party_searchname(party_name)) == NULL && // name first to avoid error when name begin with a number
  3807. 	    (p = party_search(atoi(message))) == NULL)
  3808. 	{
  3809. 		clif_displaymessage(fd, msg_txt(96)); // Incorrect name or ID, or no one from the party is online.
  3810. 		return -1;
  3811. 	}
  3812.  
  3813. 	count = 0;
  3814.  
  3815. 	iter = mapit_getallusers();
  3816. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3817. 	{
  3818. 		if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id)
  3819. 		{
  3820. 			if (pc_get_group_level(pl_sd) > pc_get_group_level(sd))
  3821. 				continue; //Skip GMs greater than you.
  3822. 			if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3823. 				count++;
  3824. 			else
  3825. 				pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3826. 		}
  3827. 	}
  3828. 	mapit_free(iter);
  3829.  
  3830. 	sprintf(atcmd_output, msg_txt(95), p->party.name); // All online characters of the %s party have been recalled to your position.
  3831. 	clif_displaymessage(fd, atcmd_output);
  3832. 	if (count) {
  3833. 		sprintf(atcmd_output, "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count);
  3834. 		clif_displaymessage(fd, atcmd_output);
  3835. 	}
  3836.  
  3837. 	return 0;
  3838. }
  3839.  
  3840. /*==========================================
  3841.  *
  3842.  *------------------------------------------*/
  3843. ACMD_FUNC(reloaditemdb)
  3844. {
  3845. 	nullpo_retr(-1, sd);
  3846. 	itemdb_reload();
  3847. 	clif_displaymessage(fd, msg_txt(97)); // Item database has been reloaded.
  3848.  
  3849. 	return 0;
  3850. }
  3851.  
  3852. /*==========================================
  3853.  *
  3854.  *------------------------------------------*/
  3855. ACMD_FUNC(reloadmobdb)
  3856. {
  3857. 	nullpo_retr(-1, sd);
  3858. 	mob_reload();
  3859. 	read_petdb();
  3860. 	merc_reload();
  3861. 	read_mercenarydb();
  3862. 	read_mercenary_skilldb();
  3863. 	reload_elementaldb();
  3864. 	clif_displaymessage(fd, msg_txt(98)); // Monster database has been reloaded.
  3865.  
  3866. 	return 0;
  3867. }
  3868.  
  3869. /*==========================================
  3870.  *
  3871.  *------------------------------------------*/
  3872. ACMD_FUNC(reloadskilldb)
  3873. {
  3874. 	nullpo_retr(-1, sd);
  3875. 	skill_reload();
  3876. 	merc_skill_reload();
  3877. 	reload_elemental_skilldb();
  3878. 	read_mercenary_skilldb();
  3879. 	clif_displaymessage(fd, msg_txt(99)); // Skill database has been reloaded.
  3880.  
  3881. 	return 0;
  3882. }
  3883.  
  3884. /*==========================================
  3885.  * @reloadatcommand - reloads atcommand_athena.conf groups.conf
  3886.  *------------------------------------------*/
  3887. void atcommand_doload();
  3888. ACMD_FUNC(reloadatcommand) {
  3889. 	config_t run_test;
  3890.  
  3891. 	if (conf_read_file(&run_test, "conf/groups.conf")) {
  3892. 		clif_displaymessage(fd, "Error reading groups.conf, can't reload");
  3893. 		return -1;
  3894. 	}
  3895.  
  3896. 	config_destroy(&run_test);
  3897.  
  3898. 	if (conf_read_file(&run_test, ATCOMMAND_CONF_FILENAME)) {
  3899. 		clif_displaymessage(fd, "Error reading atcommand.conf, can't reload");
  3900. 		return -1;
  3901. 	}
  3902.  
  3903. 	config_destroy(&run_test);
  3904.  
  3905. 	atcommand_doload();
  3906. 	pc_groups_reload();
  3907. 	clif_displaymessage(fd, msg_txt(254));
  3908. 	return 0;
  3909. }
  3910. /*==========================================
  3911.  * @reloadbattleconf - reloads battle_athena.conf
  3912.  *------------------------------------------*/
  3913. ACMD_FUNC(reloadbattleconf)
  3914. {
  3915. 	struct Battle_Config prev_config;
  3916. 	memcpy(&prev_config, &battle_config, sizeof(prev_config));
  3917.  
  3918. 	battle_config_read(BATTLE_CONF_FILENAME);
  3919.  
  3920. 	if( prev_config.item_rate_mvp          != battle_config.item_rate_mvp
  3921. 	||  prev_config.item_rate_common       != battle_config.item_rate_common
  3922. 	||  prev_config.item_rate_common_boss  != battle_config.item_rate_common_boss
  3923. 	||  prev_config.item_rate_card         != battle_config.item_rate_card
  3924. 	||  prev_config.item_rate_card_boss    != battle_config.item_rate_card_boss
  3925. 	||  prev_config.item_rate_equip        != battle_config.item_rate_equip
  3926. 	||  prev_config.item_rate_equip_boss   != battle_config.item_rate_equip_boss
  3927. 	||  prev_config.item_rate_heal         != battle_config.item_rate_heal
  3928. 	||  prev_config.item_rate_heal_boss    != battle_config.item_rate_heal_boss
  3929. 	||  prev_config.item_rate_use          != battle_config.item_rate_use
  3930. 	||  prev_config.item_rate_use_boss     != battle_config.item_rate_use_boss
  3931. 	||  prev_config.item_rate_treasure     != battle_config.item_rate_treasure
  3932. 	||  prev_config.item_rate_adddrop      != battle_config.item_rate_adddrop
  3933. 	||  prev_config.logarithmic_drops      != battle_config.logarithmic_drops
  3934. 	||  prev_config.item_drop_common_min   != battle_config.item_drop_common_min
  3935. 	||  prev_config.item_drop_common_max   != battle_config.item_drop_common_max
  3936. 	||  prev_config.item_drop_card_min     != battle_config.item_drop_card_min
  3937. 	||  prev_config.item_drop_card_max     != battle_config.item_drop_card_max
  3938. 	||  prev_config.item_drop_equip_min    != battle_config.item_drop_equip_min
  3939. 	||  prev_config.item_drop_equip_max    != battle_config.item_drop_equip_max
  3940. 	||  prev_config.item_drop_mvp_min      != battle_config.item_drop_mvp_min
  3941. 	||  prev_config.item_drop_mvp_max      != battle_config.item_drop_mvp_max
  3942. 	||  prev_config.item_drop_heal_min     != battle_config.item_drop_heal_min
  3943. 	||  prev_config.item_drop_heal_max     != battle_config.item_drop_heal_max
  3944. 	||  prev_config.item_drop_use_min      != battle_config.item_drop_use_min
  3945. 	||  prev_config.item_drop_use_max      != battle_config.item_drop_use_max
  3946. 	||  prev_config.item_drop_treasure_min != battle_config.item_drop_treasure_min
  3947. 	||  prev_config.item_drop_treasure_max != battle_config.item_drop_treasure_max
  3948. 	||  prev_config.base_exp_rate          != battle_config.base_exp_rate
  3949. 	||  prev_config.job_exp_rate           != battle_config.job_exp_rate
  3950. 	)
  3951.   	{	// Exp or Drop rates changed.
  3952. 		mob_reload(); //Needed as well so rate changes take effect.
  3953. 		chrif_ragsrvinfo(battle_config.base_exp_rate, battle_config.job_exp_rate, battle_config.item_rate_common);
  3954. 	}
  3955. 	clif_displaymessage(fd, msg_txt(255));
  3956. 	return 0;
  3957. }
  3958. /*==========================================
  3959.  * @reloadstatusdb - reloads job_db1.txt job_db2.txt job_db2-2.txt refine_db.txt size_fix.txt
  3960.  *------------------------------------------*/
  3961. ACMD_FUNC(reloadstatusdb)
  3962. {
  3963. 	status_readdb();
  3964. 	clif_displaymessage(fd, msg_txt(256));
  3965. 	return 0;
  3966. }
  3967. /*==========================================
  3968.  * @reloadpcdb - reloads exp.txt skill_tree.txt attr_fix.txt statpoint.txt
  3969.  *------------------------------------------*/
  3970. ACMD_FUNC(reloadpcdb)
  3971. {
  3972. 	pc_readdb();
  3973. 	clif_displaymessage(fd, msg_txt(257));
  3974. 	return 0;
  3975. }
  3976.  
  3977. /*==========================================
  3978.  * @reloadmotd - reloads motd.txt
  3979.  *------------------------------------------*/
  3980. ACMD_FUNC(reloadmotd)
  3981. {
  3982. 	pc_read_motd();
  3983. 	clif_displaymessage(fd, msg_txt(268));
  3984. 	return 0;
  3985. }
  3986.  
  3987. /*==========================================
  3988.  * @reloadscript - reloads all scripts (npcs, warps, mob spawns, ...)
  3989.  *------------------------------------------*/
  3990. ACMD_FUNC(reloadscript)
  3991. {
  3992. 	nullpo_retr(-1, sd);
  3993. 	//atcommand_broadcast( fd, sd, "@broadcast", "Server is reloading scripts..." );
  3994. 	//atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
  3995.  
  3996. 	flush_fifos();
  3997. 	map_reloadnpc(true); // reload config files seeking for npcs
  3998. 	script_reload();
  3999. 	npc_reload();
  4000.  
  4001. 	clif_displaymessage(fd, msg_txt(100)); // Scripts have been reloaded.
  4002.  
  4003. 	return 0;
  4004. }
  4005.  
  4006. /*==========================================
  4007.  * @mapinfo [0-3] <map name> by MC_Cameri
  4008.  * => Shows information about the map [map name]
  4009.  * 0 = no additional information
  4010.  * 1 = Show users in that map and their location
  4011.  * 2 = Shows NPCs in that map
  4012.  * 3 = Shows the shops/chats in that map (not implemented)
  4013.  *------------------------------------------*/
  4014. ACMD_FUNC(mapinfo)
  4015. {
  4016. 	struct map_session_data* pl_sd;
  4017. 	struct s_mapiterator* iter;
  4018. 	struct npc_data *nd = NULL;
  4019. 	struct chat_data *cd = NULL;
  4020. 	char direction[12];
  4021. 	int i, m_id, chat_num, list = 0;
  4022. 	unsigned short m_index;
  4023. 	char mapname[24];
  4024.  
  4025. 	nullpo_retr(-1, sd);
  4026.  
  4027. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  4028. 	memset(mapname, '\0', sizeof(mapname));
  4029. 	memset(direction, '\0', sizeof(direction));
  4030.  
  4031. 	sscanf(message, "%d %23[^\n]", &list, mapname);
  4032.  
  4033. 	if (list < 0 || list > 3) {
  4034. 		clif_displaymessage(fd, "Please, enter at least a valid list number (usage: @mapinfo <0-3> [map]).");
  4035. 		return -1;
  4036. 	}
  4037.  
  4038. 	if (mapname[0] == '\0') {
  4039. 		safestrncpy(mapname, mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  4040. 		m_id =  map_mapindex2mapid(sd->mapindex);
  4041. 	} else {
  4042. 		m_id = map_mapname2mapid(mapname);
  4043. 	}
  4044.  
  4045. 	if (m_id < 0) {
  4046. 		clif_displaymessage(fd, msg_txt(1)); // Map not found.
  4047. 		return -1;
  4048. 	}
  4049. 	m_index = mapindex_name2id(mapname); //This one shouldn't fail since the previous seek did not.
  4050.  
  4051. 	clif_displaymessage(fd, "------ Map Info ------");
  4052.  
  4053. 	// count chats (for initial message)
  4054. 	chat_num = 0;
  4055. 	iter = mapit_getallusers();
  4056. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4057. 		if( (cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && cd->usersd[0] == pl_sd )
  4058. 			chat_num++;
  4059. 	mapit_free(iter);
  4060.  
  4061. 	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);
  4062. 	clif_displaymessage(fd, atcmd_output);
  4063. 	clif_displaymessage(fd, "------ Map Flags ------");
  4064. 	if (map[m_id].flag.town)
  4065. 		clif_displaymessage(fd, "Town Map");
  4066.  
  4067. 	if (battle_config.autotrade_mapflag == map[m_id].flag.autotrade)
  4068. 		clif_displaymessage(fd, "Autotrade Enabled");
  4069. 	else
  4070. 		clif_displaymessage(fd, "Autotrade Disabled");
  4071.  
  4072. 	if (map[m_id].flag.battleground)
  4073. 		clif_displaymessage(fd, "Battlegrounds ON");
  4074.  
  4075. 	strcpy(atcmd_output,"PvP Flags: ");
  4076. 	if (map[m_id].flag.pvp)
  4077. 		strcat(atcmd_output, "Pvp ON | ");
  4078. 	if (map[m_id].flag.pvp_noguild)
  4079. 		strcat(atcmd_output, "NoGuild | ");
  4080. 	if (map[m_id].flag.pvp_noparty)
  4081. 		strcat(atcmd_output, "NoParty | ");
  4082. 	if (map[m_id].flag.pvp_nightmaredrop)
  4083. 		strcat(atcmd_output, "NightmareDrop | ");
  4084. 	if (map[m_id].flag.pvp_nocalcrank)
  4085. 		strcat(atcmd_output, "NoCalcRank | ");
  4086. 	clif_displaymessage(fd, atcmd_output);
  4087.  
  4088. 	strcpy(atcmd_output,"GvG Flags: ");
  4089. 	if (map[m_id].flag.gvg)
  4090. 		strcat(atcmd_output, "GvG ON | ");
  4091. 	if (map[m_id].flag.gvg_dungeon)
  4092. 		strcat(atcmd_output, "GvG Dungeon | ");
  4093. 	if (map[m_id].flag.gvg_castle)
  4094. 		strcat(atcmd_output, "GvG Castle | ");
  4095. 	if (map[m_id].flag.gvg_noparty)
  4096. 		strcat(atcmd_output, "NoParty | ");
  4097. 	clif_displaymessage(fd, atcmd_output);
  4098.  
  4099. 	strcpy(atcmd_output,"Teleport Flags: ");
  4100. 	if (map[m_id].flag.noteleport)
  4101. 		strcat(atcmd_output, "NoTeleport | ");
  4102. 	if (map[m_id].flag.monster_noteleport)
  4103. 		strcat(atcmd_output, "Monster NoTeleport | ");
  4104. 	if (map[m_id].flag.nowarp)
  4105. 		strcat(atcmd_output, "NoWarp | ");
  4106. 	if (map[m_id].flag.nowarpto)
  4107. 		strcat(atcmd_output, "NoWarpTo | ");
  4108. 	if (map[m_id].flag.noreturn)
  4109. 		strcat(atcmd_output, "NoReturn | ");
  4110. 	if (map[m_id].flag.nogo)
  4111. 		strcat(atcmd_output, "NoGo | ");
  4112. 	if (map[m_id].flag.nomemo)
  4113. 		strcat(atcmd_output, "NoMemo | ");
  4114. 	clif_displaymessage(fd, atcmd_output);
  4115.  
  4116. 	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");
  4117. 	clif_displaymessage(fd, atcmd_output);
  4118.  
  4119. 	if (map[m_id].flag.nosave) {
  4120. 		if (!map[m_id].save.map)
  4121. 			sprintf(atcmd_output, "No Save (Return to last Save Point)");
  4122. 		else if (map[m_id].save.x == -1 || map[m_id].save.y == -1 )
  4123. 			sprintf(atcmd_output, "No Save, Save Point: %s,Random",mapindex_id2name(map[m_id].save.map));
  4124. 		else
  4125. 			sprintf(atcmd_output, "No Save, Save Point: %s,%d,%d",
  4126. 				mapindex_id2name(map[m_id].save.map),map[m_id].save.x,map[m_id].save.y);
  4127. 		clif_displaymessage(fd, atcmd_output);
  4128. 	}
  4129.  
  4130. 	strcpy(atcmd_output,"Weather Flags: ");
  4131. 	if (map[m_id].flag.snow)
  4132. 		strcat(atcmd_output, "Snow | ");
  4133. 	if (map[m_id].flag.fog)
  4134. 		strcat(atcmd_output, "Fog | ");
  4135. 	if (map[m_id].flag.sakura)
  4136. 		strcat(atcmd_output, "Sakura | ");
  4137. 	if (map[m_id].flag.clouds)
  4138. 		strcat(atcmd_output, "Clouds | ");
  4139. 	if (map[m_id].flag.clouds2)
  4140. 		strcat(atcmd_output, "Clouds2 | ");
  4141. 	if (map[m_id].flag.fireworks)
  4142. 		strcat(atcmd_output, "Fireworks | ");
  4143. 	if (map[m_id].flag.leaves)
  4144. 		strcat(atcmd_output, "Leaves | ");
  4145. 	/**
  4146. 	 * No longer available, keeping here just in case it's back someday. [Ind]
  4147. 	 **/
  4148. 	//if (map[m_id].flag.rain)
  4149. 	//	strcat(atcmd_output, "Rain | ");
  4150. 	if (map[m_id].flag.nightenabled)
  4151. 		strcat(atcmd_output, "Displays Night | ");
  4152. 	clif_displaymessage(fd, atcmd_output);
  4153.  
  4154. 	strcpy(atcmd_output,"Other Flags: ");
  4155. 	if (map[m_id].flag.nobranch)
  4156. 		strcat(atcmd_output, "NoBranch | ");
  4157. 	if (map[m_id].flag.notrade)
  4158. 		strcat(atcmd_output, "NoTrade | ");
  4159. 	if (map[m_id].flag.novending)
  4160. 		strcat(atcmd_output, "NoVending | ");
  4161. 	if (map[m_id].flag.nodrop)
  4162. 		strcat(atcmd_output, "NoDrop | ");
  4163. 	if (map[m_id].flag.noskill)
  4164. 		strcat(atcmd_output, "NoSkill | ");
  4165. 	if (map[m_id].flag.noicewall)
  4166. 		strcat(atcmd_output, "NoIcewall | ");
  4167. 	if (map[m_id].flag.allowks)
  4168. 		strcat(atcmd_output, "AllowKS | ");
  4169. 	if (map[m_id].flag.reset)
  4170. 		strcat(atcmd_output, "Reset | ");
  4171. 	clif_displaymessage(fd, atcmd_output);
  4172.  
  4173. 	strcpy(atcmd_output,"Other Flags: ");
  4174. 	if (map[m_id].nocommand)
  4175. 		strcat(atcmd_output, "NoCommand | ");
  4176. 	if (map[m_id].flag.nobaseexp)
  4177. 		strcat(atcmd_output, "NoBaseEXP | ");
  4178. 	if (map[m_id].flag.nojobexp)
  4179. 		strcat(atcmd_output, "NoJobEXP | ");
  4180. 	if (map[m_id].flag.nomobloot)
  4181. 		strcat(atcmd_output, "NoMobLoot | ");
  4182. 	if (map[m_id].flag.nomvploot)
  4183. 		strcat(atcmd_output, "NoMVPLoot | ");
  4184. 	if (map[m_id].flag.partylock)
  4185. 		strcat(atcmd_output, "PartyLock | ");
  4186. 	if (map[m_id].flag.guildlock)
  4187. 		strcat(atcmd_output, "GuildLock | ");
  4188. 	clif_displaymessage(fd, atcmd_output);
  4189.  
  4190. 	switch (list) {
  4191. 	case 0:
  4192. 		// Do nothing. It's list 0, no additional display.
  4193. 		break;
  4194. 	case 1:
  4195. 		clif_displaymessage(fd, "----- Players in Map -----");
  4196. 		iter = mapit_getallusers();
  4197. 		for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4198. 		{
  4199. 			if (pl_sd->mapindex == m_index) {
  4200. 				sprintf(atcmd_output, "Player '%s' (session #%d) | Location: %d,%d",
  4201. 				        pl_sd->status.name, pl_sd->fd, pl_sd->bl.x, pl_sd->bl.y);
  4202. 				clif_displaymessage(fd, atcmd_output);
  4203. 			}
  4204. 		}
  4205. 		mapit_free(iter);
  4206. 		break;
  4207. 	case 2:
  4208. 		clif_displaymessage(fd, "----- NPCs in Map -----");
  4209. 		for (i = 0; i < map[m_id].npc_num;)
  4210. 		{
  4211. 			nd = map[m_id].npc[i];
  4212. 			switch(nd->ud.dir) {
  4213. 			case 0:  strcpy(direction, "North"); break;
  4214. 			case 1:  strcpy(direction, "North West"); break;
  4215. 			case 2:  strcpy(direction, "West"); break;
  4216. 			case 3:  strcpy(direction, "South West"); break;
  4217. 			case 4:  strcpy(direction, "South"); break;
  4218. 			case 5:  strcpy(direction, "South East"); break;
  4219. 			case 6:  strcpy(direction, "East"); break;
  4220. 			case 7:  strcpy(direction, "North East"); break;
  4221. 			case 9:  strcpy(direction, "North"); break;
  4222. 			default: strcpy(direction, "Unknown"); break;
  4223. 			}
  4224. 			if(strcmp(nd->name,nd->exname) == 0)
  4225. 				sprintf(atcmd_output, "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d",
  4226. 				    ++i, nd->name, direction, nd->class_, nd->bl.x, nd->bl.y);
  4227. 			else
  4228. 				sprintf(atcmd_output, "NPC %d: %s::%s | Direction: %s | Sprite: %d | Location: %d %d",
  4229. 			        ++i, nd->name, nd->exname, direction, nd->class_, nd->bl.x, nd->bl.y);
  4230. 			clif_displaymessage(fd, atcmd_output);
  4231. 		}
  4232. 		break;
  4233. 	case 3:
  4234. 		clif_displaymessage(fd, "----- Chats in Map -----");
  4235. 		iter = mapit_getallusers();
  4236. 		for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4237. 		{
  4238. 			if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL &&
  4239. 			    pl_sd->mapindex == m_index &&
  4240. 			    cd->usersd[0] == pl_sd)
  4241. 			{
  4242. 				sprintf(atcmd_output, "Chat: %s | Player: %s | Location: %d %d",
  4243. 				        cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y);
  4244. 				clif_displaymessage(fd, atcmd_output);
  4245. 				sprintf(atcmd_output, "   Users: %d/%d | Password: %s | Public: %s",
  4246. 				        cd->users, cd->limit, cd->pass, (cd->pub) ? "Yes" : "No");
  4247. 				clif_displaymessage(fd, atcmd_output);
  4248. 			}
  4249. 		}
  4250. 		mapit_free(iter);
  4251. 		break;
  4252. 	default: // normally impossible to arrive here
  4253. 		clif_displaymessage(fd, "Please, enter at least a valid list number (usage: @mapinfo <0-3> [map]).");
  4254. 		return -1;
  4255. 		break;
  4256. 	}
  4257.  
  4258. 	return 0;
  4259. }
  4260.  
  4261. /*==========================================
  4262.  *
  4263.  *------------------------------------------*/
  4264. ACMD_FUNC(mount_peco)
  4265. {
  4266. 	nullpo_retr(-1, sd);
  4267.  
  4268. 	if (sd->disguise) {
  4269. 		clif_displaymessage(fd, msg_txt(212)); // Cannot mount while in disguise.
  4270. 		return -1;
  4271. 	}
  4272.  
  4273. 	if( (sd->class_&MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT && pc_checkskill(sd,RK_DRAGONTRAINING) > 0 ) {
  4274. 		if( !(sd->sc.option&OPTION_DRAGON1) ) {
  4275. 			clif_displaymessage(sd->fd,"You have mounted your Dragon");
  4276. 			pc_setoption(sd, sd->sc.option|OPTION_DRAGON1);
  4277. 		} else {
  4278. 			clif_displaymessage(sd->fd,"You have released your Dragon");
  4279. 			pc_setoption(sd, sd->sc.option&~OPTION_DRAGON1);
  4280. 		}
  4281. 		return 0;
  4282. 	}
  4283. 	if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER && pc_checkskill(sd,RA_WUGRIDER) > 0 ) {
  4284. 		if( !pc_isridingwug(sd) ) {
  4285. 			clif_displaymessage(sd->fd,"You have mounted your Wug");
  4286. 			pc_setoption(sd, sd->sc.option|OPTION_WUGRIDER);
  4287. 		} else {
  4288. 			clif_displaymessage(sd->fd,"You have released your Wug");
  4289. 			pc_setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
  4290. 		}
  4291. 		return 0;
  4292. 	}
  4293. 	if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  4294. 		if( !pc_ismadogear(sd) ) {
  4295. 			clif_displaymessage(sd->fd,"You have mounted your Mado Gear");
  4296. 			pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  4297. 		} else {
  4298. 			clif_displaymessage(sd->fd,"You have released your Mado Gear");
  4299. 			pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  4300. 		}
  4301. 		return 0;
  4302. 	}
  4303. 	if (!pc_isriding(sd)) { // if actually no peco
  4304.  
  4305. 		if (!pc_checkskill(sd, KN_RIDING)) {
  4306. 			clif_displaymessage(fd, msg_txt(213)); // You can not mount a Peco Peco with your current job.
  4307. 			return -1;
  4308. 		}
  4309.  
  4310. 		pc_setoption(sd, sd->sc.option | OPTION_RIDING);
  4311. 		clif_displaymessage(fd, msg_txt(102)); // You have mounted a Peco Peco.
  4312. 	} else {//Dismount
  4313. 		pc_setoption(sd, sd->sc.option & ~OPTION_RIDING);
  4314. 		clif_displaymessage(fd, msg_txt(214)); // You have released your Peco Peco.
  4315. 	}
  4316.  
  4317. 	return 0;
  4318. }
  4319.  
  4320. /*==========================================
  4321.  *Spy Commands by Syrus22
  4322.  *------------------------------------------*/
  4323. ACMD_FUNC(guildspy)
  4324. {
  4325. 	char guild_name[NAME_LENGTH];
  4326. 	struct guild *g;
  4327. 	nullpo_retr(-1, sd);
  4328.  
  4329. 	memset(guild_name, '\0', sizeof(guild_name));
  4330. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  4331.  
  4332. 	if (!enable_spy)
  4333. 	{
  4334. 		clif_displaymessage(fd, "The mapserver has spy command support disabled.");
  4335. 		return -1;
  4336. 	}
  4337. 	if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  4338. 		clif_displaymessage(fd, "Please, enter a guild name/id (usage: @guildspy <guild_name/id>).");
  4339. 		return -1;
  4340. 	}
  4341.  
  4342. 	if ((g = guild_searchname(guild_name)) != NULL || // name first to avoid error when name begin with a number
  4343. 	    (g = guild_search(atoi(message))) != NULL) {
  4344. 		if (sd->guildspy == g->guild_id) {
  4345. 			sd->guildspy = 0;
  4346. 			sprintf(atcmd_output, msg_txt(103), g->name); // No longer spying on the %s guild.
  4347. 			clif_displaymessage(fd, atcmd_output);
  4348. 		} else {
  4349. 			sd->guildspy = g->guild_id;
  4350. 			sprintf(atcmd_output, msg_txt(104), g->name); // Spying on the %s guild.
  4351. 			clif_displaymessage(fd, atcmd_output);
  4352. 		}
  4353. 	} else {
  4354. 		clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the specified guild is online.
  4355. 		return -1;
  4356. 	}
  4357.  
  4358. 	return 0;
  4359. }
  4360.  
  4361. /*==========================================
  4362.  *
  4363.  *------------------------------------------*/
  4364. ACMD_FUNC(partyspy)
  4365. {
  4366. 	char party_name[NAME_LENGTH];
  4367. 	struct party_data *p;
  4368. 	nullpo_retr(-1, sd);
  4369.  
  4370. 	memset(party_name, '\0', sizeof(party_name));
  4371. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  4372.  
  4373. 	if (!enable_spy)
  4374. 	{
  4375. 		clif_displaymessage(fd, "The mapserver has spy command support disabled.");
  4376. 		return -1;
  4377. 	}
  4378.  
  4379. 	if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  4380. 		clif_displaymessage(fd, "Please, enter a party name/id (usage: @partyspy <party_name/id>).");
  4381. 		return -1;
  4382. 	}
  4383.  
  4384. 	if ((p = party_searchname(party_name)) != NULL || // name first to avoid error when name begin with a number
  4385. 	    (p = party_search(atoi(message))) != NULL) {
  4386. 		if (sd->partyspy == p->party.party_id) {
  4387. 			sd->partyspy = 0;
  4388. 			sprintf(atcmd_output, msg_txt(105), p->party.name); // No longer spying on the %s party.
  4389. 			clif_displaymessage(fd, atcmd_output);
  4390. 		} else {
  4391. 			sd->partyspy = p->party.party_id;
  4392. 			sprintf(atcmd_output, msg_txt(106), p->party.name); // Spying on the %s party.
  4393. 			clif_displaymessage(fd, atcmd_output);
  4394. 		}
  4395. 	} else {
  4396. 		clif_displaymessage(fd, msg_txt(96)); // Incorrect name/ID, or no one from the specified party is online.
  4397. 		return -1;
  4398. 	}
  4399.  
  4400. 	return 0;
  4401. }
  4402.  
  4403. /*==========================================
  4404.  * @repairall [Valaris]
  4405.  *------------------------------------------*/
  4406. ACMD_FUNC(repairall)
  4407. {
  4408. 	int count, i;
  4409. 	nullpo_retr(-1, sd);
  4410.  
  4411. 	count = 0;
  4412. 	for (i = 0; i < MAX_INVENTORY; i++) {
  4413. 		if (sd->status.inventory[i].nameid && sd->status.inventory[i].attribute == 1) {
  4414. 			sd->status.inventory[i].attribute = 0;
  4415. 			clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  4416. 			count++;
  4417. 		}
  4418. 	}
  4419.  
  4420. 	if (count > 0) {
  4421. 		clif_misceffect(&sd->bl, 3);
  4422. 		clif_equiplist(sd);
  4423. 		clif_displaymessage(fd, msg_txt(107)); // All items have been repaired.
  4424. 	} else {
  4425. 		clif_displaymessage(fd, msg_txt(108)); // No item need to be repaired.
  4426. 		return -1;
  4427. 	}
  4428.  
  4429. 	return 0;
  4430. }
  4431.  
  4432. /*==========================================
  4433.  * @nuke [Valaris]
  4434.  *------------------------------------------*/
  4435. ACMD_FUNC(nuke)
  4436. {
  4437. 	struct map_session_data *pl_sd;
  4438. 	nullpo_retr(-1, sd);
  4439.  
  4440. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4441.  
  4442. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4443. 		clif_displaymessage(fd, "Please, enter a player name (usage: @nuke <char name>).");
  4444. 		return -1;
  4445. 	}
  4446.  
  4447. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) != NULL) {
  4448. 		if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level
  4449. 			skill_castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, gettick(), 0);
  4450. 			clif_displaymessage(fd, msg_txt(109)); // Player has been nuked!
  4451. 		} else {
  4452. 			clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4453. 			return -1;
  4454. 		}
  4455. 	} else {
  4456. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4457. 		return -1;
  4458. 	}
  4459.  
  4460. 	return 0;
  4461. }
  4462.  
  4463. /*==========================================
  4464.  * @tonpc
  4465.  *------------------------------------------*/
  4466. ACMD_FUNC(tonpc)
  4467. {
  4468. 	char npcname[NAME_LENGTH+1];
  4469. 	struct npc_data *nd;
  4470.  
  4471. 	nullpo_retr(-1, sd);
  4472.  
  4473. 	memset(npcname, 0, sizeof(npcname));
  4474.  
  4475. 	if (!message || !*message || sscanf(message, "%23[^\n]", npcname) < 1) {
  4476. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @tonpc <NPC_name>).");
  4477. 		return -1;
  4478. 	}
  4479.  
  4480. 	if ((nd = npc_name2id(npcname)) != NULL) {
  4481. 		if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
  4482. 			clif_displaymessage(fd, msg_txt(0)); // Warped.
  4483. 		else
  4484. 			return -1;
  4485. 	} else {
  4486. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4487. 		return -1;
  4488. 	}
  4489.  
  4490. 	return 0;
  4491. }
  4492.  
  4493. /*==========================================
  4494.  *
  4495.  *------------------------------------------*/
  4496. ACMD_FUNC(shownpc)
  4497. {
  4498. 	char NPCname[NAME_LENGTH+1];
  4499. 	nullpo_retr(-1, sd);
  4500.  
  4501. 	memset(NPCname, '\0', sizeof(NPCname));
  4502.  
  4503. 	if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  4504. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @enablenpc <NPC_name>).");
  4505. 		return -1;
  4506. 	}
  4507.  
  4508. 	if (npc_name2id(NPCname) != NULL) {
  4509. 		npc_enable(NPCname, 1);
  4510. 		clif_displaymessage(fd, msg_txt(110)); // Npc Enabled.
  4511. 	} else {
  4512. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4513. 		return -1;
  4514. 	}
  4515.  
  4516. 	return 0;
  4517. }
  4518.  
  4519. /*==========================================
  4520.  *
  4521.  *------------------------------------------*/
  4522. ACMD_FUNC(hidenpc)
  4523. {
  4524. 	char NPCname[NAME_LENGTH+1];
  4525. 	nullpo_retr(-1, sd);
  4526.  
  4527. 	memset(NPCname, '\0', sizeof(NPCname));
  4528.  
  4529. 	if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  4530. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @hidenpc <NPC_name>).");
  4531. 		return -1;
  4532. 	}
  4533.  
  4534. 	if (npc_name2id(NPCname) == NULL) {
  4535. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4536. 		return -1;
  4537. 	}
  4538.  
  4539. 	npc_enable(NPCname, 0);
  4540. 	clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
  4541. 	return 0;
  4542. }
  4543.  
  4544. ACMD_FUNC(loadnpc)
  4545. {
  4546. 	FILE *fp;
  4547.  
  4548. 	if (!message || !*message) {
  4549. 		clif_displaymessage(fd, "Please, enter a script file name (usage: @loadnpc <file name>).");
  4550. 		return -1;
  4551. 	}
  4552.  
  4553. 	// check if script file exists
  4554. 	if ((fp = fopen(message, "r")) == NULL) {
  4555. 		clif_displaymessage(fd, msg_txt(261));
  4556. 		return -1;
  4557. 	}
  4558. 	fclose(fp);
  4559.  
  4560. 	// add to list of script sources and run it
  4561. 	npc_addsrcfile(message);
  4562. 	npc_parsesrcfile(message,true);
  4563. 	npc_read_event_script();
  4564.  
  4565. 	clif_displaymessage(fd, msg_txt(262));
  4566.  
  4567. 	return 0;
  4568. }
  4569.  
  4570. ACMD_FUNC(unloadnpc)
  4571. {
  4572. 	struct npc_data *nd;
  4573. 	char NPCname[NAME_LENGTH+1];
  4574. 	nullpo_retr(-1, sd);
  4575.  
  4576. 	memset(NPCname, '\0', sizeof(NPCname));
  4577.  
  4578. 	if (!message || !*message || sscanf(message, "%24[^\n]", NPCname) < 1) {
  4579. 		clif_displaymessage(fd, "Please, enter a NPC name (usage: @npcoff <NPC_name>).");
  4580. 		return -1;
  4581. 	}
  4582.  
  4583. 	if ((nd = npc_name2id(NPCname)) == NULL) {
  4584. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4585. 		return -1;
  4586. 	}
  4587.  
  4588. 	npc_unload_duplicates(nd);
  4589. 	npc_unload(nd,true);
  4590. 	npc_read_event_script();
  4591. 	clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
  4592. 	return 0;
  4593. }
  4594.  
  4595. /*==========================================
  4596.  * time in txt for time command (by [Yor])
  4597.  *------------------------------------------*/
  4598. char* txt_time(unsigned int duration)
  4599. {
  4600. 	int days, hours, minutes, seconds;
  4601. 	char temp[CHAT_SIZE_MAX];
  4602. 	static char temp1[CHAT_SIZE_MAX];
  4603.  
  4604. 	memset(temp, '\0', sizeof(temp));
  4605. 	memset(temp1, '\0', sizeof(temp1));
  4606.  
  4607. 	days = duration / (60 * 60 * 24);
  4608. 	duration = duration - (60 * 60 * 24 * days);
  4609. 	hours = duration / (60 * 60);
  4610. 	duration = duration - (60 * 60 * hours);
  4611. 	minutes = duration / 60;
  4612. 	seconds = duration - (60 * minutes);
  4613.  
  4614. 	if (days < 2)
  4615. 		sprintf(temp, msg_txt(219), days); // %d day
  4616. 	else
  4617. 		sprintf(temp, msg_txt(220), days); // %d days
  4618. 	if (hours < 2)
  4619. 		sprintf(temp1, msg_txt(221), temp, hours); // %s %d hour
  4620. 	else
  4621. 		sprintf(temp1, msg_txt(222), temp, hours); // %s %d hours
  4622. 	if (minutes < 2)
  4623. 		sprintf(temp, msg_txt(223), temp1, minutes); // %s %d minute
  4624. 	else
  4625. 		sprintf(temp, msg_txt(224), temp1, minutes); // %s %d minutes
  4626. 	if (seconds < 2)
  4627. 		sprintf(temp1, msg_txt(225), temp, seconds); // %s and %d second
  4628. 	else
  4629. 		sprintf(temp1, msg_txt(226), temp, seconds); // %s and %d seconds
  4630.  
  4631. 	return temp1;
  4632. }
  4633.  
  4634. /*==========================================
  4635.  * @time/@date/@serverdate/@servertime: Display the date/time of the server (by [Yor]
  4636.  * Calculation management of GM modification (@day/@night GM commands) is done
  4637.  *------------------------------------------*/
  4638. ACMD_FUNC(servertime)
  4639. {
  4640. 	const struct TimerData * timer_data;
  4641. 	const struct TimerData * timer_data2;
  4642. 	time_t time_server;  // variable for number of seconds (used with time() function)
  4643. 	struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
  4644. 	char temp[CHAT_SIZE_MAX];
  4645. 	nullpo_retr(-1, sd);
  4646.  
  4647. 	memset(temp, '\0', sizeof(temp));
  4648.  
  4649. 	time(&time_server);  // get time in seconds since 1/1/1970
  4650. 	datetime = localtime(&time_server); // convert seconds in structure
  4651. 	// like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  4652. 	strftime(temp, sizeof(temp)-1, msg_txt(230), datetime); // Server time (normal time): %A, %B %d %Y %X.
  4653. 	clif_displaymessage(fd, temp);
  4654.  
  4655. 	if (battle_config.night_duration == 0 && battle_config.day_duration == 0) {
  4656. 		if (night_flag == 0)
  4657. 			clif_displaymessage(fd, msg_txt(231)); // Game time: The game is in permanent daylight.
  4658. 		else
  4659. 			clif_displaymessage(fd, msg_txt(232)); // Game time: The game is in permanent night.
  4660. 	} else if (battle_config.night_duration == 0)
  4661. 		if (night_flag == 1) { // we start with night
  4662. 			timer_data = get_timer(day_timer_tid);
  4663. 			sprintf(temp, msg_txt(233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in night for %s.
  4664. 			clif_displaymessage(fd, temp);
  4665. 			clif_displaymessage(fd, msg_txt(234)); // Game time: After, the game will be in permanent daylight.
  4666. 		} else
  4667. 			clif_displaymessage(fd, msg_txt(231)); // Game time: The game is in permanent daylight.
  4668. 	else if (battle_config.day_duration == 0)
  4669. 		if (night_flag == 0) { // we start with day
  4670. 			timer_data = get_timer(night_timer_tid);
  4671. 			sprintf(temp, msg_txt(235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  4672. 			clif_displaymessage(fd, temp);
  4673. 			clif_displaymessage(fd, msg_txt(236)); // Game time: After, the game will be in permanent night.
  4674. 		} else
  4675. 			clif_displaymessage(fd, msg_txt(232)); // Game time: The game is in permanent night.
  4676. 	else {
  4677. 		if (night_flag == 0) {
  4678. 			timer_data = get_timer(night_timer_tid);
  4679. 			timer_data2 = get_timer(day_timer_tid);
  4680. 			sprintf(temp, msg_txt(235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  4681. 			clif_displaymessage(fd, temp);
  4682. 			if (DIFF_TICK(timer_data->tick, timer_data2->tick) > 0)
  4683. 				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.
  4684. 			else
  4685. 				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.
  4686. 			clif_displaymessage(fd, temp);
  4687. 			sprintf(temp, msg_txt(238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  4688. 			clif_displaymessage(fd, temp);
  4689. 		} else {
  4690. 			timer_data = get_timer(day_timer_tid);
  4691. 			timer_data2 = get_timer(night_timer_tid);
  4692. 			sprintf(temp, msg_txt(233), txt_time(DIFF_TICK(timer_data->tick,gettick()) / 1000)); // Game time: The game is actualy in night for %s.
  4693. 			clif_displaymessage(fd, temp);
  4694. 			if (DIFF_TICK(timer_data->tick,timer_data2->tick) > 0)
  4695. 				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.
  4696. 			else
  4697. 				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.
  4698. 			clif_displaymessage(fd, temp);
  4699. 			sprintf(temp, msg_txt(238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  4700. 			clif_displaymessage(fd, temp);
  4701. 		}
  4702. 	}
  4703.  
  4704. 	return 0;
  4705. }
  4706.  
  4707. //Added by Coltaro
  4708. //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...).
  4709. //Well, using time_t could still work but for some reason that looks like more coding x_x
  4710. static void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute)
  4711. {
  4712. 	const int factor_year = 518400; //12*30*24*60 = 518400
  4713. 	const int factor_month = 43200; //30*24*60 = 43200
  4714. 	const int factor_day = 1440; //24*60 = 1440
  4715. 	const int factor_hour = 60;
  4716.  
  4717. 	*year = jailtime/factor_year;
  4718. 	jailtime -= *year*factor_year;
  4719. 	*month = jailtime/factor_month;
  4720. 	jailtime -= *month*factor_month;
  4721. 	*day = jailtime/factor_day;
  4722. 	jailtime -= *day*factor_day;
  4723. 	*hour = jailtime/factor_hour;
  4724. 	jailtime -= *hour*factor_hour;
  4725. 	*minute = jailtime;
  4726.  
  4727. 	*year = *year > 0? *year : 0;
  4728. 	*month = *month > 0? *month : 0;
  4729. 	*day = *day > 0? *day : 0;
  4730. 	*hour = *hour > 0? *hour : 0;
  4731. 	*minute = *minute > 0? *minute : 0;
  4732. 	return;
  4733. }
  4734.  
  4735. /*==========================================
  4736.  * @jail <char_name> by [Yor]
  4737.  * Special warp! No check with nowarp and nowarpto flag
  4738.  *------------------------------------------*/
  4739. ACMD_FUNC(jail)
  4740. {
  4741. 	struct map_session_data *pl_sd;
  4742. 	int x, y;
  4743. 	unsigned short m_index;
  4744. 	nullpo_retr(-1, sd);
  4745.  
  4746. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4747.  
  4748. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4749. 		clif_displaymessage(fd, "Please, enter a player name (usage: @jail <char_name>).");
  4750. 		return -1;
  4751. 	}
  4752.  
  4753. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4754. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4755. 		return -1;
  4756. 	}
  4757.  
  4758. 	if (pc_get_group_level(sd) < pc_get_group_level(pl_sd))
  4759.   	{ // you can jail only lower or same GM
  4760. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4761. 		return -1;
  4762. 	}
  4763.  
  4764. 	if (pl_sd->sc.data[SC_JAILED])
  4765. 	{
  4766. 		clif_displaymessage(fd, msg_txt(118)); // Player warped in jails.
  4767. 		return -1;
  4768. 	}
  4769.  
  4770. 	switch(rnd() % 2) { //Jail Locations
  4771. 	case 0:
  4772. 		m_index = mapindex_name2id(MAP_JAIL);
  4773. 		x = 24;
  4774. 		y = 75;
  4775. 		break;
  4776. 	default:
  4777. 		m_index = mapindex_name2id(MAP_JAIL);
  4778. 		x = 49;
  4779. 		y = 75;
  4780. 		break;
  4781. 	}
  4782.  
  4783. 	//Duration of INT_MAX to specify infinity.
  4784. 	sc_start4(&pl_sd->bl,SC_JAILED,100,INT_MAX,m_index,x,y,1000);
  4785. 	clif_displaymessage(pl_sd->fd, msg_txt(117)); // GM has send you in jails.
  4786. 	clif_displaymessage(fd, msg_txt(118)); // Player warped in jails.
  4787. 	return 0;
  4788. }
  4789.  
  4790. /*==========================================
  4791.  * @unjail/@discharge <char_name> by [Yor]
  4792.  * Special warp! No check with nowarp and nowarpto flag
  4793.  *------------------------------------------*/
  4794. ACMD_FUNC(unjail)
  4795. {
  4796. 	struct map_session_data *pl_sd;
  4797.  
  4798. 	memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4799.  
  4800. 	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4801. 		clif_displaymessage(fd, "Please, enter a player name (usage: @unjail/@discharge <char_name>).");
  4802. 		return -1;
  4803. 	}
  4804.  
  4805. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4806. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4807. 		return -1;
  4808. 	}
  4809.  
  4810. 	if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { // you can jail only lower or same GM
  4811.  
  4812. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4813. 		return -1;
  4814. 	}
  4815.  
  4816. 	if (!pl_sd->sc.data[SC_JAILED])
  4817. 	{
  4818. 		clif_displaymessage(fd, msg_txt(119)); // This player is not in jails.
  4819. 		return -1;
  4820. 	}
  4821.  
  4822. 	//Reset jail time to 1 sec.
  4823. 	sc_start(&pl_sd->bl,SC_JAILED,100,1,1000);
  4824. 	clif_displaymessage(pl_sd->fd, msg_txt(120)); // A GM has discharged you from jail.
  4825. 	clif_displaymessage(fd, msg_txt(121)); // Player unjailed.
  4826. 	return 0;
  4827. }
  4828.  
  4829. ACMD_FUNC(jailfor)
  4830. {
  4831. 	struct map_session_data *pl_sd = NULL;
  4832. 	int year, month, day, hour, minute, value;
  4833. 	char * modif_p;
  4834. 	int jailtime = 0,x,y;
  4835. 	short m_index = 0;
  4836. 	nullpo_retr(-1, sd);
  4837.  
  4838. 	if (!message || !*message || sscanf(message, "%s %23[^\n]",atcmd_output,atcmd_player_name) < 2) {
  4839. 		clif_displaymessage(fd, msg_txt(400));	//Usage: @jailfor <time> <character name>
  4840. 		return -1;
  4841. 	}
  4842.  
  4843. 	atcmd_output[sizeof(atcmd_output)-1] = '\0';
  4844.  
  4845. 	modif_p = atcmd_output;
  4846. 	year = month = day = hour = minute = 0;
  4847. 	while (modif_p[0] != '\0') {
  4848. 		value = atoi(modif_p);
  4849. 		if (value == 0)
  4850. 			modif_p++;
  4851. 		else {
  4852. 			if (modif_p[0] == '-' || modif_p[0] == '+')
  4853. 				modif_p++;
  4854. 			while (modif_p[0] >= '0' && modif_p[0] <= '9')
  4855. 				modif_p++;
  4856. 			if (modif_p[0] == 'n') {
  4857. 				minute = value;
  4858. 				modif_p++;
  4859. 			} else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  4860. 				minute = value;
  4861. 				modif_p = modif_p + 2;
  4862. 			} else if (modif_p[0] == 'h') {
  4863. 				hour = value;
  4864. 				modif_p++;
  4865. 			} else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  4866. 				day = value;
  4867. 				modif_p++;
  4868. 			} else if (modif_p[0] == 'm') {
  4869. 				month = value;
  4870. 				modif_p++;
  4871. 			} else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  4872. 				year = value;
  4873. 				modif_p++;
  4874. 			} else if (modif_p[0] != '\0') {
  4875. 				modif_p++;
  4876. 			}
  4877. 		}
  4878. 	}
  4879.  
  4880. 	if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0) {
  4881. 		clif_displaymessage(fd, "Invalid time for jail command.");
  4882. 		return -1;
  4883. 	}
  4884.  
  4885. 	if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4886. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4887. 		return -1;
  4888. 	}
  4889.  
  4890. 	if (pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  4891. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4892. 		return -1;
  4893. 	}
  4894.  
  4895. 	jailtime = year*12*30*24*60 + month*30*24*60 + day*24*60 + hour*60 + minute;	//In minutes
  4896.  
  4897. 	if(jailtime==0) {
  4898. 		clif_displaymessage(fd, "Invalid time for jail command.");
  4899. 		return -1;
  4900. 	}
  4901.  
  4902. 	//Added by Coltaro
  4903. 	if(pl_sd->sc.data[SC_JAILED] && 
  4904. 		pl_sd->sc.data[SC_JAILED]->val1 != INT_MAX)
  4905.   	{	//Update the player's jail time
  4906. 		jailtime += pl_sd->sc.data[SC_JAILED]->val1;
  4907. 		if (jailtime <= 0) {
  4908. 			jailtime = 0;
  4909. 			clif_displaymessage(pl_sd->fd, msg_txt(120)); // GM has discharge you.
  4910. 			clif_displaymessage(fd, msg_txt(121)); // Player unjailed
  4911. 		} else {
  4912. 			get_jail_time(jailtime,&year,&month,&day,&hour,&minute);
  4913. 			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
  4914. 	 		clif_displaymessage(pl_sd->fd, atcmd_output);
  4915. 			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
  4916. 	 		clif_displaymessage(fd, atcmd_output);
  4917. 		}
  4918. 	} else if (jailtime < 0) {
  4919. 		clif_displaymessage(fd, "Invalid time for jail command.");
  4920. 		return -1;
  4921. 	}
  4922.  
  4923. 	//Jail locations, add more as you wish.
  4924. 	switch(rnd()%2)
  4925. 	{
  4926. 		case 1: //Jail #1
  4927. 			m_index = mapindex_name2id(MAP_JAIL);
  4928. 			x = 49; y = 75;
  4929. 			break;
  4930. 		default: //Default Jail
  4931. 			m_index = mapindex_name2id(MAP_JAIL);
  4932. 			x = 24; y = 75;
  4933. 			break;
  4934. 	}
  4935.  
  4936. 	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).
  4937. 	return 0;
  4938. }
  4939.  
  4940.  
  4941. //By Coltaro
  4942. ACMD_FUNC(jailtime)
  4943. {
  4944. 	int year, month, day, hour, minute;
  4945.  
  4946. 	nullpo_retr(-1, sd);
  4947.  
  4948. 	if (!sd->sc.data[SC_JAILED]) {
  4949. 		clif_displaymessage(fd, "You are not in jail."); // You are not in jail.
  4950. 		return -1;
  4951. 	}
  4952.  
  4953. 	if (sd->sc.data[SC_JAILED]->val1 == INT_MAX) {
  4954. 		clif_displaymessage(fd, "You have been jailed indefinitely.");
  4955. 		return 0;
  4956. 	}
  4957.  
  4958. 	if (sd->sc.data[SC_JAILED]->val1 <= 0) { // Was not jailed with @jailfor (maybe @jail? or warped there? or got recalled?)
  4959. 		clif_displaymessage(fd, "You have been jailed for an unknown amount of time.");
  4960. 		return -1;
  4961. 	}
  4962.  
  4963. 	//Get remaining jail time
  4964. 	get_jail_time(sd->sc.data[SC_JAILED]->val1,&year,&month,&day,&hour,&minute);
  4965. 	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
  4966.  
  4967. 	clif_displaymessage(fd, atcmd_output);
  4968.  
  4969. 	return 0;
  4970. }
  4971.  
  4972. /*==========================================
  4973.  * @disguise <mob_id> by [Valaris] (simplified by [Yor])
  4974.  *------------------------------------------*/
  4975. ACMD_FUNC(disguise)
  4976. {
  4977. 	int id = 0;
  4978. 	nullpo_retr(-1, sd);
  4979.  
  4980. 	if (!message || !*message) {
  4981. 		clif_displaymessage(fd, "Please, enter a Monster/NPC name/id (usage: @disguise <monster_name_or_monster_ID>).");
  4982. 		return -1;
  4983. 	}
  4984.  
  4985. 	if ((id = atoi(message)) > 0)
  4986. 	{	//Acquired an ID
  4987. 		if (!mobdb_checkid(id) && !npcdb_checkid(id))
  4988. 			id = 0; //Invalid id for either mobs or npcs.
  4989. 	}	else	{ //Acquired a Name
  4990. 		if ((id = mobdb_searchname(message)) == 0)
  4991. 		{
  4992. 			struct npc_data* nd = npc_name2id(message);
  4993. 			if (nd != NULL)
  4994. 				id = nd->class_;
  4995. 		}
  4996. 	}
  4997.  
  4998. 	if (id == 0)
  4999. 	{
  5000. 		clif_displaymessage(fd, msg_txt(123));	// Invalid Monster/NPC name/ID specified.
  5001. 		return -1;
  5002. 	}
  5003.  
  5004. 	if(pc_isriding(sd))
  5005. 	{
  5006. 		//FIXME: wrong message [ultramage]
  5007. 		//clif_displaymessage(fd, msg_txt(227)); // Character cannot wear disguise while riding a PecoPeco.
  5008. 		return -1;
  5009. 	}
  5010.  
  5011. 	pc_disguise(sd, id);
  5012. 	clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  5013.  
  5014. 	return 0;
  5015. }
  5016.  
  5017. /*==========================================
  5018.  * DisguiseAll
  5019.  *------------------------------------------*/
  5020. ACMD_FUNC(disguiseall)
  5021. {
  5022. 	int mob_id=0;
  5023. 	struct map_session_data *pl_sd;
  5024. 	struct s_mapiterator* iter;
  5025. 	nullpo_retr(-1, sd);
  5026.  
  5027. 	if (!message || !*message) {
  5028. 		clif_displaymessage(fd, "Please, enter a Monster/NPC name/id (usage: @disguiseall <monster name or monster ID>).");
  5029. 		return -1;
  5030. 	}
  5031.  
  5032. 	if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
  5033. 		mob_id = atoi(message);
  5034.  
  5035. 	if (!mobdb_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
  5036. 		clif_displaymessage(fd, msg_txt(123)); // Monster/NPC name/id not found.
  5037. 		return -1;
  5038. 	}
  5039.  
  5040. 	iter = mapit_getallusers();
  5041. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  5042. 		pc_disguise(pl_sd, mob_id);
  5043. 	mapit_free(iter);
  5044.  
  5045. 	clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  5046. 	return 0;
  5047. }
  5048.  
  5049. /*==========================================
  5050.  * @undisguise by [Yor]
  5051.  *------------------------------------------*/
  5052. ACMD_FUNC(undisguise)
  5053. {
  5054. 	nullpo_retr(-1, sd);
  5055. 	if (sd->disguise) {
  5056. 		pc_disguise(sd, 0);
  5057. 		clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  5058. 	} else {
  5059. 		clif_displaymessage(fd, msg_txt(125)); // You're not disguised.
  5060. 		return -1;
  5061. 	}
  5062.  
  5063. 	return 0;
  5064. }
  5065.  
  5066. /*==========================================
  5067.  * UndisguiseAll
  5068.  *------------------------------------------*/
  5069. ACMD_FUNC(undisguiseall)
  5070. {
  5071. 	struct map_session_data *pl_sd;
  5072. 	struct s_mapiterator* iter;
  5073. 	nullpo_retr(-1, sd);
  5074.  
  5075. 	iter = mapit_getallusers();
  5076. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  5077. 		if( pl_sd->disguise )
  5078. 			pc_disguise(pl_sd, 0);
  5079. 	mapit_free(iter);
  5080.  
  5081. 	clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  5082.  
  5083. 	return 0;
  5084. }
  5085.  
  5086. /*==========================================
  5087.  * @exp by [Skotlex]
  5088.  *------------------------------------------*/
  5089. ACMD_FUNC(exp)
  5090. {
  5091. 	char output[CHAT_SIZE_MAX];
  5092. 	double nextb, nextj;
  5093. 	nullpo_retr(-1, sd);
  5094. 	memset(output, '\0', sizeof(output));
  5095.  
  5096. 	nextb = pc_nextbaseexp(sd);
  5097. 	if (nextb)
  5098. 		nextb = sd->status.base_exp*100.0/nextb;
  5099.  
  5100. 	nextj = pc_nextjobexp(sd);
  5101. 	if (nextj)
  5102. 		nextj = sd->status.job_exp*100.0/nextj;
  5103.  
  5104. 	sprintf(output, "Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%)", sd->status.base_level, nextb, sd->status.job_level, nextj);
  5105. 	clif_displaymessage(fd, output);
  5106. 	return 0;
  5107. }
  5108.  
  5109.  
  5110. /*==========================================
  5111.  * @broadcast by [Valaris]
  5112.  *------------------------------------------*/
  5113. ACMD_FUNC(broadcast)
  5114. {
  5115. 	nullpo_retr(-1, sd);
  5116.  
  5117. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  5118.  
  5119. 	if (!message || !*message) {
  5120. 		clif_displaymessage(fd, "Please, enter a message (usage: @broadcast <message>).");
  5121. 		return -1;
  5122. 	}
  5123.  
  5124. 	sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  5125. 	intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, 0);
  5126.  
  5127. 	return 0;
  5128. }
  5129.  
  5130. /*==========================================
  5131.  * @localbroadcast by [Valaris]
  5132.  *------------------------------------------*/
  5133. ACMD_FUNC(localbroadcast)
  5134. {
  5135. 	nullpo_retr(-1, sd);
  5136.  
  5137. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  5138.  
  5139. 	if (!message || !*message) {
  5140. 		clif_displaymessage(fd, "Please, enter a message (usage: @localbroadcast <message>).");
  5141. 		return -1;
  5142. 	}
  5143.  
  5144. 	sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  5145.  
  5146. 	clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  5147.  
  5148. 	return 0;
  5149. }
  5150.  
  5151. /*==========================================
  5152.  * @email <actual@email> <new@email> by [Yor]
  5153.  *------------------------------------------*/
  5154. ACMD_FUNC(email)
  5155. {
  5156. 	char actual_email[100];
  5157. 	char new_email[100];
  5158. 	nullpo_retr(-1, sd);
  5159.  
  5160. 	memset(actual_email, '\0', sizeof(actual_email));
  5161. 	memset(new_email, '\0', sizeof(new_email));
  5162.  
  5163. 	if (!message || !*message || sscanf(message, "%99s %99s", actual_email, new_email) < 2) {
  5164. 		clif_displaymessage(fd, "Please enter 2 emails (usage: @email <actual@email> <new@email>).");
  5165. 		return -1;
  5166. 	}
  5167.  
  5168. 	if (e_mail_check(actual_email) == 0) {
  5169. 		clif_displaymessage(fd, msg_txt(144)); // Invalid actual email. If you have default e-mail, give [email protected].
  5170. 		return -1;
  5171. 	} else if (e_mail_check(new_email) == 0) {
  5172. 		clif_displaymessage(fd, msg_txt(145)); // Invalid new email. Please enter a real e-mail.
  5173. 		return -1;
  5174. 	} else if (strcmpi(new_email, "[email protected]") == 0) {
  5175. 		clif_displaymessage(fd, msg_txt(146)); // New email must be a real e-mail.
  5176. 		return -1;
  5177. 	} else if (strcmpi(actual_email, new_email) == 0) {
  5178. 		clif_displaymessage(fd, msg_txt(147)); // New email must be different of the actual e-mail.
  5179. 		return -1;
  5180. 	}
  5181.  
  5182. 	chrif_changeemail(sd->status.account_id, actual_email, new_email);
  5183. 	clif_displaymessage(fd, msg_txt(148)); // Information sended to login-server via char-server.
  5184. 	return 0;
  5185. }
  5186.  
  5187. /*==========================================
  5188.  *@effect
  5189.  *------------------------------------------*/
  5190. ACMD_FUNC(effect)
  5191. {
  5192. 	int type = 0, flag = 0;
  5193. 	nullpo_retr(-1, sd);
  5194.  
  5195. 	if (!message || !*message || sscanf(message, "%d", &type) < 1) {
  5196. 		clif_displaymessage(fd, "Please, enter an effect number (usage: @effect <effect number>).");
  5197. 		return -1;
  5198. 	}
  5199.  
  5200. 	clif_specialeffect(&sd->bl, type, (send_target)flag);
  5201. 	clif_displaymessage(fd, msg_txt(229)); // Your effect has changed.
  5202. 	return 0;
  5203. }
  5204.  
  5205. /*==========================================
  5206.  * @killer by MouseJstr
  5207.  * enable killing players even when not in pvp
  5208.  *------------------------------------------*/
  5209. ACMD_FUNC(killer)
  5210. {
  5211. 	nullpo_retr(-1, sd);
  5212. 	sd->state.killer = !sd->state.killer;
  5213.  
  5214. 	if(sd->state.killer)
  5215. 		clif_displaymessage(fd, msg_txt(241));
  5216. 	else {
  5217. 		clif_displaymessage(fd, msg_txt(287));
  5218. 		pc_stop_attack(sd);
  5219. 	}
  5220. 	return 0;
  5221. }
  5222.  
  5223. /*==========================================
  5224.  * @killable by MouseJstr
  5225.  * enable other people killing you
  5226.  *------------------------------------------*/
  5227. ACMD_FUNC(killable)
  5228. {
  5229. 	nullpo_retr(-1, sd);
  5230. 	sd->state.killable = !sd->state.killable;
  5231.  
  5232. 	if(sd->state.killable)
  5233. 		clif_displaymessage(fd, msg_txt(242));
  5234. 	else {
  5235. 		clif_displaymessage(fd, msg_txt(288));
  5236. 		map_foreachinrange(atcommand_stopattack,&sd->bl, AREA_SIZE, BL_CHAR, sd->bl.id);
  5237. 	}
  5238. 	return 0;
  5239. }
  5240.  
  5241. /*==========================================
  5242.  * @skillon by MouseJstr
  5243.  * turn skills on for the map
  5244.  *------------------------------------------*/
  5245. ACMD_FUNC(skillon)
  5246. {
  5247. 	nullpo_retr(-1, sd);
  5248. 	map[sd->bl.m].flag.noskill = 0;
  5249. 	clif_displaymessage(fd, msg_txt(244));
  5250. 	return 0;
  5251. }
  5252.  
  5253. /*==========================================
  5254.  * @skilloff by MouseJstr
  5255.  * Turn skills off on the map
  5256.  *------------------------------------------*/
  5257. ACMD_FUNC(skilloff)
  5258. {
  5259. 	nullpo_retr(-1, sd);
  5260. 	map[sd->bl.m].flag.noskill = 1;
  5261. 	clif_displaymessage(fd, msg_txt(243));
  5262. 	return 0;
  5263. }
  5264.  
  5265. /*==========================================
  5266.  * @npcmove by MouseJstr
  5267.  * move a npc
  5268.  *------------------------------------------*/
  5269. ACMD_FUNC(npcmove)
  5270. {
  5271. 	int x = 0, y = 0, m;
  5272. 	struct npc_data *nd = 0;
  5273. 	nullpo_retr(-1, sd);
  5274. 	memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  5275.  
  5276. 	if (!message || !*message || sscanf(message, "%d %d %23[^\n]", &x, &y, atcmd_player_name) < 3) {
  5277. 		clif_displaymessage(fd, "Usage: @npcmove <X> <Y> <npc_name>");
  5278. 		return -1;
  5279. 	}
  5280.  
  5281. 	if ((nd = npc_name2id(atcmd_player_name)) == NULL)
  5282. 	{
  5283. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  5284. 		return -1;
  5285. 	}
  5286.  
  5287. 	if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  5288. 	{
  5289. 		clif_displaymessage(fd, "NPC is not on this map.");
  5290. 		return -1;	//Not on a map.
  5291. 	}
  5292.  
  5293. 	x = cap_value(x, 0, map[m].xs-1);
  5294. 	y = cap_value(y, 0, map[m].ys-1);
  5295. 	map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  5296. 	map_moveblock(&nd->bl, x, y, gettick());
  5297. 	map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  5298. 	clif_displaymessage(fd, "NPC moved.");
  5299.  
  5300. 	return 0;
  5301. }
  5302.  
  5303. /*==========================================
  5304.  * @addwarp by MouseJstr
  5305.  * Create a new static warp point.
  5306.  *------------------------------------------*/
  5307. ACMD_FUNC(addwarp)
  5308. {
  5309. 	char mapname[32];
  5310. 	int x,y;
  5311. 	unsigned short m;
  5312. 	struct npc_data* nd;
  5313.  
  5314. 	nullpo_retr(-1, sd);
  5315.  
  5316. 	if (!message || !*message || sscanf(message, "%31s %d %d", mapname, &x, &y) < 3) {
  5317. 		clif_displaymessage(fd, "usage: @addwarp <mapname> <X> <Y>.");
  5318. 		return -1;
  5319. 	}
  5320.  
  5321. 	m = mapindex_name2id(mapname);
  5322. 	if( m == 0 )
  5323. 	{
  5324. 		sprintf(atcmd_output, "Unknown map '%s'.", mapname);
  5325. 		clif_displaymessage(fd, atcmd_output);
  5326. 		return -1;
  5327. 	}
  5328.  
  5329. 	nd = npc_add_warp(sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
  5330. 	if( nd == NULL )
  5331. 		return -1;
  5332.  
  5333. 	sprintf(atcmd_output, "New warp NPC '%s' created.", nd->exname);
  5334. 	clif_displaymessage(fd, atcmd_output);
  5335. 	return 0;
  5336. }
  5337.  
  5338. /*==========================================
  5339.  * @follow by [MouseJstr]
  5340.  * Follow a player .. staying no more then 5 spaces away
  5341.  *------------------------------------------*/
  5342. ACMD_FUNC(follow)
  5343. {
  5344. 	struct map_session_data *pl_sd = NULL;
  5345. 	nullpo_retr(-1, sd);
  5346.  
  5347. 	if (!message || !*message) {
  5348. 		if (sd->followtarget == -1)
  5349. 			return -1;
  5350.  
  5351. 		pc_stop_following (sd);
  5352. 		clif_displaymessage(fd, "Follow mode OFF.");
  5353. 		return 0;
  5354. 	}
  5355.  
  5356. 	if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  5357. 	{
  5358. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5359. 		return -1;
  5360. 	}
  5361.  
  5362. 	if (sd->followtarget == pl_sd->bl.id) {
  5363. 		pc_stop_following (sd);
  5364. 		clif_displaymessage(fd, "Follow mode OFF.");
  5365. 	} else {
  5366. 		pc_follow(sd, pl_sd->bl.id);
  5367. 		clif_displaymessage(fd, "Follow mode ON.");
  5368. 	}
  5369.  
  5370. 	return 0;
  5371. }
  5372.  
  5373.  
  5374. /*==========================================
  5375.  * @dropall by [MouseJstr]
  5376.  * Drop all your possession on the ground
  5377.  *------------------------------------------*/
  5378. ACMD_FUNC(dropall)
  5379. {
  5380. 	int i;
  5381. 	nullpo_retr(-1, sd);
  5382. 	for (i = 0; i < MAX_INVENTORY; i++) {
  5383. 	if (sd->status.inventory[i].amount) {
  5384. 		if(sd->status.inventory[i].equip != 0)
  5385. 			pc_unequipitem(sd, i, 3);
  5386. 			pc_dropitem(sd,  i, sd->status.inventory[i].amount);
  5387. 		}
  5388. 	}
  5389. 	return 0;
  5390. }
  5391.  
  5392. /*==========================================
  5393.  * @storeall by [MouseJstr]
  5394.  * Put everything into storage
  5395.  *------------------------------------------*/
  5396. ACMD_FUNC(storeall)
  5397. {
  5398. 	int i;
  5399. 	nullpo_retr(-1, sd);
  5400.  
  5401. 	if (sd->state.storage_flag != 1)
  5402.   	{	//Open storage.
  5403. 		if( storage_storageopen(sd) == 1 ) {
  5404. 			clif_displaymessage(fd, "You can't open the storage currently.");
  5405. 			return -1;
  5406. 		}
  5407. 	}
  5408.  
  5409. 	for (i = 0; i < MAX_INVENTORY; i++) {
  5410. 		if (sd->status.inventory[i].amount) {
  5411. 			if(sd->status.inventory[i].equip != 0)
  5412. 				pc_unequipitem(sd, i, 3);
  5413. 			storage_storageadd(sd,  i, sd->status.inventory[i].amount);
  5414. 		}
  5415. 	}
  5416. 	storage_storageclose(sd);
  5417.  
  5418. 	clif_displaymessage(fd, "It is done");
  5419. 	return 0;
  5420. }
  5421.  
  5422. /*==========================================
  5423.  * @skillid by [MouseJstr]
  5424.  * lookup a skill by name
  5425.  *------------------------------------------*/
  5426. ACMD_FUNC(skillid)
  5427. {
  5428. 	int skillen, idx;
  5429. 	nullpo_retr(-1, sd);
  5430.  
  5431. 	if (!message || !*message)
  5432. 	{
  5433. 		clif_displaymessage(fd, "Please enter a skill name to look up (usage: @skillid <skill name>).");
  5434. 		return -1;
  5435. 	}
  5436.  
  5437. 	skillen = strlen(message);
  5438.  
  5439. 	for (idx = 0; idx < MAX_SKILL_DB; idx++) {
  5440. 		if (strnicmp(skill_db[idx].name, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0)
  5441. 		{
  5442. 			sprintf(atcmd_output, "skill %d: %s", idx, skill_db[idx].desc);
  5443. 			clif_displaymessage(fd, atcmd_output);
  5444. 		}
  5445. 	}
  5446.  
  5447. 	return 0;
  5448. }
  5449.  
  5450. /*==========================================
  5451.  * @useskill by [MouseJstr]
  5452.  * A way of using skills without having to find them in the skills menu
  5453.  *------------------------------------------*/
  5454. ACMD_FUNC(useskill)
  5455. {
  5456. 	struct map_session_data *pl_sd = NULL;
  5457. 	struct block_list *bl;
  5458. 	int skillnum;
  5459. 	int skilllv;
  5460. 	char target[100];
  5461. 	nullpo_retr(-1, sd);
  5462.  
  5463. 	if(!message || !*message || sscanf(message, "%d %d %23[^\n]", &skillnum, &skilllv, target) != 3) {
  5464. 		clif_displaymessage(fd, "Usage: @useskill <skillnum> <skillv> <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. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  5475. 	{
  5476. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  5477. 		return -1;
  5478. 	}
  5479.  
  5480. 	if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL
  5481. 		&& sd->hd && merc_is_hom_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
  5482. 		bl = &sd->hd->bl;
  5483. 	else
  5484. 		bl = &sd->bl;
  5485.  
  5486. 	if (skill_get_inf(skillnum)&INF_GROUND_SKILL)
  5487. 		unit_skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skillnum, skilllv);
  5488. 	else
  5489. 		unit_skilluse_id(bl, pl_sd->bl.id, skillnum, skilllv);
  5490.  
  5491. 	return 0;
  5492. }
  5493.  
  5494. /*==========================================
  5495.  * @displayskill by [Skotlex]
  5496.  *  Debug command to locate new skill IDs. It sends the
  5497.  *  three possible skill-effect packets to the area.
  5498.  *------------------------------------------*/
  5499. ACMD_FUNC(displayskill)
  5500. {
  5501. 	struct status_data * status;
  5502. 	unsigned int tick;
  5503. 	int skillnum;
  5504. 	int skilllv = 1;
  5505. 	nullpo_retr(-1, sd);
  5506.  
  5507. 	if (!message || !*message || sscanf(message, "%d %d", &skillnum, &skilllv) < 1)
  5508. 	{
  5509. 		clif_displaymessage(fd, "Usage: @displayskill <skillnum> {<skillv>}>");
  5510. 		return -1;
  5511. 	}
  5512. 	status = status_get_status_data(&sd->bl);
  5513. 	tick = gettick();
  5514. 	clif_skill_damage(&sd->bl,&sd->bl, tick, status->amotion, status->dmotion, 1, 1, skillnum, skilllv, 5);
  5515. 	clif_skill_nodamage(&sd->bl, &sd->bl, skillnum, skilllv, 1);
  5516. 	clif_skill_poseffect(&sd->bl, skillnum, skilllv, sd->bl.x, sd->bl.y, tick);
  5517. 	return 0;
  5518. }
  5519.  
  5520. /*==========================================
  5521.  * @skilltree by [MouseJstr]
  5522.  * prints the skill tree for a player required to get to a skill
  5523.  *------------------------------------------*/
  5524. ACMD_FUNC(skilltree)
  5525. {
  5526. 	struct map_session_data *pl_sd = NULL;
  5527. 	int skillnum;
  5528. 	int meets, j, c=0;
  5529. 	char target[NAME_LENGTH];
  5530. 	struct skill_tree_entry *ent;
  5531. 	nullpo_retr(-1, sd);
  5532.  
  5533. 	if(!message || !*message || sscanf(message, "%d %23[^\r\n]", &skillnum, target) != 2) {
  5534. 		clif_displaymessage(fd, "Usage: @skilltree <skillnum> <target>");
  5535. 		return -1;
  5536. 	}
  5537.  
  5538. 	if ( (pl_sd = map_nick2sd(target)) == NULL )
  5539. 	{
  5540. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5541. 		return -1;
  5542. 	}
  5543.  
  5544. 	c = pc_calc_skilltree_normalize_job(pl_sd);
  5545. 	c = pc_mapid2jobid(c, pl_sd->status.sex);
  5546.  
  5547. 	sprintf(atcmd_output, "Player is using %s skill tree (%d basic points)", job_name(c), pc_checkskill(pl_sd, NV_BASIC));
  5548. 	clif_displaymessage(fd, atcmd_output);
  5549.  
  5550. 	ARR_FIND( 0, MAX_SKILL_TREE, j, skill_tree[c][j].id == 0 || skill_tree[c][j].id == skillnum );
  5551. 	if( j == MAX_SKILL_TREE || skill_tree[c][j].id == 0 )
  5552. 	{
  5553. 		sprintf(atcmd_output, "I do not believe the player can use that skill");
  5554. 		clif_displaymessage(fd, atcmd_output);
  5555. 		return 0;
  5556. 	}
  5557.  
  5558. 	ent = &skill_tree[c][j];
  5559.  
  5560. 	meets = 1;
  5561. 	for(j=0;j<MAX_PC_SKILL_REQUIRE;j++)
  5562. 	{
  5563. 		if( ent->need[j].id && pc_checkskill(sd,ent->need[j].id) < ent->need[j].lv)
  5564. 		{
  5565. 			sprintf(atcmd_output, "player requires level %d of skill %s", ent->need[j].lv, skill_db[ent->need[j].id].desc);
  5566. 			clif_displaymessage(fd, atcmd_output);
  5567. 			meets = 0;
  5568. 		}
  5569. 	}
  5570. 	if (meets == 1) {
  5571. 		sprintf(atcmd_output, "I believe the player meets all the requirements for that skill");
  5572. 		clif_displaymessage(fd, atcmd_output);
  5573. 	}
  5574.  
  5575. 	return 0;
  5576. }
  5577.  
  5578. // Hand a ring with partners name on it to this char
  5579. void getring (struct map_session_data* sd)
  5580. {
  5581. 	int flag, item_id;
  5582. 	struct item item_tmp;
  5583. 	item_id = (sd->status.sex) ? WEDDING_RING_M : WEDDING_RING_F;
  5584.  
  5585. 	memset(&item_tmp, 0, sizeof(item_tmp));
  5586. 	item_tmp.nameid = item_id;
  5587. 	item_tmp.identify = 1;
  5588. 	item_tmp.card[0] = 255;
  5589. 	item_tmp.card[2] = sd->status.partner_id;
  5590. 	item_tmp.card[3] = sd->status.partner_id >> 16;
  5591.  
  5592. 	if((flag = pc_additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) {
  5593. 		clif_additem(sd,0,0,flag);
  5594. 		map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  5595. 	}
  5596. }
  5597.  
  5598. /*==========================================
  5599.  * @marry by [MouseJstr], fixed by Lupus
  5600.  * Marry two players
  5601.  *------------------------------------------*/
  5602. ACMD_FUNC(marry)
  5603. {
  5604. 	struct map_session_data *pl_sd = NULL;
  5605. 	char player_name[NAME_LENGTH] = "";
  5606.  
  5607. 	nullpo_retr(-1, sd);
  5608.  
  5609. 	if (!message || !*message || sscanf(message, "%23s", player_name) != 1) {
  5610. 		clif_displaymessage(fd, "Usage: @marry <player name>");
  5611. 		return -1;
  5612. 	}
  5613.  
  5614. 	if ((pl_sd = map_nick2sd(player_name)) == NULL) {
  5615. 		clif_displaymessage(fd, msg_txt(3));
  5616. 		return -1;
  5617. 	}
  5618.  
  5619. 	if (pc_marriage(sd, pl_sd) == 0) {
  5620. 		clif_displaymessage(fd, "They are married.. wish them well.");
  5621. 		clif_wedding_effect(&pl_sd->bl); //wedding effect and music [Lupus]
  5622. 		getring(sd); // Auto-give named rings (Aru)
  5623. 		getring(pl_sd);
  5624. 		return 0;
  5625. 	}
  5626.  
  5627. 	clif_displaymessage(fd, "The two cannot wed because one of them is either a baby or is already married.");
  5628. 	return -1;
  5629. }
  5630.  
  5631. /*==========================================
  5632.  * @divorce by [MouseJstr], fixed by [Lupus]
  5633.  * divorce two players
  5634.  *------------------------------------------*/
  5635. ACMD_FUNC(divorce)
  5636. {
  5637. 	nullpo_retr(-1, sd);
  5638.  
  5639. 	if (pc_divorce(sd) != 0) {
  5640. 		sprintf(atcmd_output, "'%s' is not married.", sd->status.name);
  5641. 		clif_displaymessage(fd, atcmd_output);
  5642. 		return -1;
  5643. 	}
  5644.  
  5645. 	sprintf(atcmd_output, "'%s' and his(her) partner are now divorced.", sd->status.name);
  5646. 	clif_displaymessage(fd, atcmd_output);
  5647. 	return 0;
  5648. }
  5649.  
  5650. /*==========================================
  5651.  * @changelook by [Celest]
  5652.  *------------------------------------------*/
  5653. ACMD_FUNC(changelook)
  5654. {
  5655. 	int i, j = 0, k = 0;
  5656. 	int pos[7] = { LOOK_HEAD_TOP,LOOK_HEAD_MID,LOOK_HEAD_BOTTOM,LOOK_WEAPON,LOOK_SHIELD,LOOK_SHOES,LOOK_ROBE };
  5657.  
  5658. 	if((i = sscanf(message, "%d %d", &j, &k)) < 1) {
  5659. 		clif_displaymessage(fd, "Usage: @changelook [<position>] <view id> -- [] = optional");
  5660. 		clif_displaymessage(fd, "Position: 1-Top 2-Middle 3-Bottom 4-Weapon 5-Shield 6-Shoes 7-Robe");
  5661. 		return -1;
  5662. 	} else if ( i == 2 ) {
  5663. 		if (j < 1 || j > 7)
  5664. 			j = 1;
  5665. 		j = pos[j - 1];
  5666. 	} else if( i == 1 ) {	// position not defined, use HEAD_TOP as default
  5667. 		k = j;	// swap
  5668. 		j = LOOK_HEAD_TOP;
  5669. 	}
  5670.  
  5671. 	clif_changelook(&sd->bl,j,k);
  5672.  
  5673. 	return 0;
  5674. }
  5675.  
  5676. /*==========================================
  5677.  * @autotrade by durf [Lupus] [Paradox924X]
  5678.  * Turns on/off Autotrade for a specific player
  5679.  *------------------------------------------*/
  5680. ACMD_FUNC(autotrade)
  5681. {
  5682. 	nullpo_retr(-1, sd);
  5683.  
  5684. 	if( map[sd->bl.m].flag.autotrade != battle_config.autotrade_mapflag ) {
  5685. 		clif_displaymessage(fd, "Autotrade is not allowed on this map.");
  5686. 		return -1;
  5687. 	}
  5688.  
  5689. 	if( pc_isdead(sd) ) {
  5690. 		clif_displaymessage(fd, "Cannot Autotrade if you are dead.");
  5691. 		return -1;
  5692. 	}
  5693.  
  5694. 	if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying
  5695. 		clif_displaymessage(fd, msg_txt(549)); // "You should have a shop open to use @autotrade."
  5696. 		return -1;
  5697. 	}
  5698.  
  5699. 	sd->state.autotrade = 1;
  5700. 	if( battle_config.at_timeout )
  5701. 	{
  5702. 		int timeout = atoi(message);
  5703. 		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);
  5704. 	}
  5705. 	clif_authfail_fd(fd, 15);
  5706.  
  5707. 	return 0;
  5708. }
  5709.  
  5710. /*==========================================
  5711.  * @changegm by durf (changed by Lupus)
  5712.  * Changes Master of your Guild to a specified guild member
  5713.  *------------------------------------------*/
  5714. ACMD_FUNC(changegm)
  5715. {
  5716. 	struct guild *g;
  5717. 	struct map_session_data *pl_sd;
  5718. 	nullpo_retr(-1, sd);
  5719.  
  5720. 	if (sd->status.guild_id == 0 || (g = guild_search(sd->status.guild_id)) == NULL || strcmp(g->master,sd->status.name)) {
  5721. 		clif_displaymessage(fd, "You need to be a Guild Master to use this command.");
  5722. 		return -1;
  5723. 	}
  5724.  
  5725. 	if( map[sd->bl.m].flag.guildlock || map[sd->bl.m].flag.gvg_castle ) {
  5726. 		clif_displaymessage(fd, "You cannot change guild leaders on this map.");
  5727. 		return -1;
  5728. 	}
  5729.  
  5730. 	if( !message[0] ) {
  5731. 		clif_displaymessage(fd, "Command usage: @changegm <guildmember name>");
  5732. 		return -1;
  5733. 	}
  5734.  
  5735. 	if((pl_sd=map_nick2sd((char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
  5736. 		clif_displaymessage(fd, "Target character must be online and be a guildmate.");
  5737. 		return -1;
  5738. 	}
  5739.  
  5740. 	guild_gm_change(sd->status.guild_id, pl_sd);
  5741. 	return 0;
  5742. }
  5743.  
  5744. /*==========================================
  5745.  * @changeleader by Skotlex
  5746.  * Changes the leader of a party.
  5747.  *------------------------------------------*/
  5748. ACMD_FUNC(changeleader)
  5749. {
  5750. 	nullpo_retr(-1, sd);
  5751.  
  5752. 	if( !message[0] )
  5753. 	{
  5754. 		clif_displaymessage(fd, "Command usage: @changeleader <party member name>");
  5755. 		return -1;
  5756. 	}
  5757.  
  5758. 	if (party_changeleader(sd, map_nick2sd((char *) message)))
  5759. 		return 0;
  5760. 	return -1;
  5761. }
  5762.  
  5763. /*==========================================
  5764.  * @partyoption by Skotlex
  5765.  * Used to change the item share setting of a party.
  5766.  *------------------------------------------*/
  5767. ACMD_FUNC(partyoption)
  5768. {
  5769. 	struct party_data *p;
  5770. 	int mi, option;
  5771. 	char w1[16], w2[16];
  5772. 	nullpo_retr(-1, sd);
  5773.  
  5774. 	if (sd->status.party_id == 0 || (p = party_search(sd->status.party_id)) == NULL)
  5775. 	{
  5776. 		clif_displaymessage(fd, msg_txt(282));
  5777. 		return -1;
  5778. 	}
  5779.  
  5780. 	ARR_FIND( 0, MAX_PARTY, mi, p->data[mi].sd == sd );
  5781. 	if (mi == MAX_PARTY)
  5782. 		return -1; //Shouldn't happen
  5783.  
  5784. 	if (!p->party.member[mi].leader)
  5785. 	{
  5786. 		clif_displaymessage(fd, msg_txt(282));
  5787. 		return -1;
  5788. 	}
  5789.  
  5790. 	if(!message || !*message || sscanf(message, "%15s %15s", w1, w2) < 2)
  5791. 	{
  5792. 		clif_displaymessage(fd, "Command usage: @partyoption <pickup share: yes/no> <item distribution: yes/no>");
  5793. 		return -1;
  5794. 	}
  5795.  
  5796. 	option = (config_switch(w1)?1:0)|(config_switch(w2)?2:0);
  5797.  
  5798. 	//Change item share type.
  5799. 	if (option != p->party.item)
  5800. 		party_changeoption(sd, p->party.exp, option);
  5801. 	else
  5802. 		clif_displaymessage(fd, msg_txt(286));
  5803.  
  5804. 	return 0;
  5805. }
  5806.  
  5807. /*==========================================
  5808.  * @autoloot by Upa-Kun
  5809.  * Turns on/off AutoLoot for a specific player
  5810.  *------------------------------------------*/
  5811. ACMD_FUNC(autoloot)
  5812. {
  5813. 	int rate;
  5814. 	double drate;
  5815. 	nullpo_retr(-1, sd);
  5816. 	// autoloot command without value
  5817. 	if(!message || !*message)
  5818. 	{
  5819. 		if (sd->state.autoloot)
  5820. 			rate = 0;
  5821. 		else
  5822. 			rate = 10000;
  5823. 	} else {
  5824. 		drate = atof(message);
  5825. 		rate = (int)(drate*100);
  5826. 	}
  5827. 	if (rate < 0) rate = 0;
  5828. 	if (rate > 10000) rate = 10000;
  5829.  
  5830. 	sd->state.autoloot = rate;
  5831. 	if (sd->state.autoloot) {
  5832. 		snprintf(atcmd_output, sizeof atcmd_output, "Autolooting items with drop rates of %0.02f%% and below.",((double)sd->state.autoloot)/100.);
  5833. 		clif_displaymessage(fd, atcmd_output);
  5834. 	}else
  5835. 		clif_displaymessage(fd, "Autoloot is now off.");
  5836.  
  5837. 	return 0;
  5838. }
  5839.  
  5840. /*==========================================
  5841.  * @alootid
  5842.  *------------------------------------------*/
  5843. ACMD_FUNC(autolootitem)
  5844. {
  5845. 	struct item_data *item_data = NULL;
  5846. 	int i;
  5847. 	int action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
  5848.  
  5849. 	if (message && *message) {
  5850. 		if (message[0] == '+') {
  5851. 			message++;
  5852. 			action = 1;
  5853. 		}
  5854. 		else if (message[0] == '-') {
  5855. 			message++;
  5856. 			action = 2;
  5857. 		}
  5858. 		else if (!strcmp(message,"reset"))
  5859. 			action = 4;
  5860. 	}
  5861.  
  5862. 	if (action < 3) // add or remove
  5863. 	{
  5864. 		if ((item_data = itemdb_exists(atoi(message))) == NULL)
  5865. 			item_data = itemdb_searchname(message);
  5866. 		if (!item_data) {
  5867. 			// No items founds in the DB with Id or Name
  5868. 			clif_displaymessage(fd, "Item not found.");
  5869. 			return -1;
  5870. 		}
  5871. 	}
  5872.  
  5873. 	switch(action) {
  5874. 	case 1:
  5875. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5876. 		if (i != AUTOLOOTITEM_SIZE) {
  5877. 			clif_displaymessage(fd, "You're already autolooting this item.");
  5878. 			return -1;
  5879. 		}
  5880. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == 0);
  5881. 		if (i == AUTOLOOTITEM_SIZE) {
  5882. 			clif_displaymessage(fd, "Your autolootitem list is full. Remove some items first with @autolootid -<item name or ID>.");
  5883. 			return -1;
  5884. 		}
  5885. 		sd->state.autolootid[i] = item_data->nameid; // Autoloot Activated
  5886. 		sprintf(atcmd_output, "Autolooting item: '%s'/'%s' {%d}", item_data->name, item_data->jname, item_data->nameid);
  5887. 		clif_displaymessage(fd, atcmd_output);
  5888. 		sd->state.autolooting = 1;
  5889. 		break;
  5890. 	case 2:
  5891. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5892. 		if (i == AUTOLOOTITEM_SIZE) {
  5893. 			clif_displaymessage(fd, "You're currently not autolooting this item.");
  5894. 			return -1;
  5895. 		}
  5896. 		sd->state.autolootid[i] = 0;
  5897. 		sprintf(atcmd_output, "Removed item: '%s'/'%s' {%d} from your autolootitem list.", item_data->name, item_data->jname, item_data->nameid);
  5898. 		clif_displaymessage(fd, atcmd_output);
  5899. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5900. 		if (i == AUTOLOOTITEM_SIZE) {
  5901. 			sd->state.autolooting = 0;
  5902. 		}
  5903. 		break;
  5904. 	case 3:
  5905. 		sprintf(atcmd_output, "You can have %d items on your autolootitem list.", AUTOLOOTITEM_SIZE);
  5906. 		clif_displaymessage(fd, atcmd_output);
  5907. 		clif_displaymessage(fd, "To add item to the list, use \"@alootid +<item name or ID>\". To remove item use \"@alootid -<item name or ID>\".");
  5908. 		clif_displaymessage(fd, "\"@alootid reset\" will clear your autolootitem list.");
  5909. 		ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5910. 		if (i == AUTOLOOTITEM_SIZE) {
  5911. 			clif_displaymessage(fd, "Your autolootitem list is empty.");
  5912. 		} else {
  5913. 			clif_displaymessage(fd, "Items on your autolootitem list:");
  5914. 			for(i = 0; i < AUTOLOOTITEM_SIZE; i++)
  5915. 			{
  5916. 				if (sd->state.autolootid[i] == 0)
  5917. 					continue;
  5918. 				if (!(item_data = itemdb_exists(sd->state.autolootid[i]))) {
  5919. 					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);
  5920. 					continue;
  5921. 				}
  5922. 				sprintf(atcmd_output, "'%s'/'%s' {%d}", item_data->name, item_data->jname, item_data->nameid);
  5923. 				clif_displaymessage(fd, atcmd_output);
  5924. 			}
  5925. 		}
  5926. 		break;
  5927. 	case 4:
  5928. 		memset(sd->state.autolootid, 0, sizeof(sd->state.autolootid));
  5929. 		clif_displaymessage(fd, "Your autolootitem list has been reset.");
  5930. 		sd->state.autolooting = 0;
  5931. 		break;
  5932. 	}
  5933. 	return 0;
  5934. }
  5935. /**
  5936.  * No longer available, keeping here just in case it's back someday. [Ind]
  5937.  **/
  5938. /*==========================================
  5939.  * It is made to rain.
  5940.  *------------------------------------------*/
  5941. //ACMD_FUNC(rain)
  5942. //{
  5943. //	nullpo_retr(-1, sd);
  5944. //	if (map[sd->bl.m].flag.rain) {
  5945. //		map[sd->bl.m].flag.rain=0;
  5946. //		clif_weather(sd->bl.m);
  5947. //		clif_displaymessage(fd, "The rain has stopped.");
  5948. //	} else {
  5949. //		map[sd->bl.m].flag.rain=1;
  5950. //		clif_weather(sd->bl.m);
  5951. //		clif_displaymessage(fd, "It is made to rain.");
  5952. //	}
  5953. //	return 0;
  5954. //}
  5955.  
  5956. /*==========================================
  5957.  * It is made to snow.
  5958.  *------------------------------------------*/
  5959. ACMD_FUNC(snow)
  5960. {
  5961. 	nullpo_retr(-1, sd);
  5962. 	if (map[sd->bl.m].flag.snow) {
  5963. 		map[sd->bl.m].flag.snow=0;
  5964. 		clif_weather(sd->bl.m);
  5965. 		clif_displaymessage(fd, "Snow has stopped falling.");
  5966. 	} else {
  5967. 		map[sd->bl.m].flag.snow=1;
  5968. 		clif_weather(sd->bl.m);
  5969. 		clif_displaymessage(fd, "It is made to snow.");
  5970. 	}
  5971.  
  5972. 	return 0;
  5973. }
  5974.  
  5975. /*==========================================
  5976.  * Cherry tree snowstorm is made to fall. (Sakura)
  5977.  *------------------------------------------*/
  5978. ACMD_FUNC(sakura)
  5979. {
  5980. 	nullpo_retr(-1, sd);
  5981. 	if (map[sd->bl.m].flag.sakura) {
  5982. 		map[sd->bl.m].flag.sakura=0;
  5983. 		clif_weather(sd->bl.m);
  5984. 		clif_displaymessage(fd, "Cherry tree leaves no longer fall.");
  5985. 	} else {
  5986. 		map[sd->bl.m].flag.sakura=1;
  5987. 		clif_weather(sd->bl.m);
  5988. 		clif_displaymessage(fd, "Cherry tree leaves is made to fall.");
  5989. 	}
  5990. 	return 0;
  5991. }
  5992.  
  5993. /*==========================================
  5994.  * Clouds appear.
  5995.  *------------------------------------------*/
  5996. ACMD_FUNC(clouds)
  5997. {
  5998. 	nullpo_retr(-1, sd);
  5999. 	if (map[sd->bl.m].flag.clouds) {
  6000. 		map[sd->bl.m].flag.clouds=0;
  6001. 		clif_weather(sd->bl.m);
  6002. 		clif_displaymessage(fd, "The clouds has disappear.");
  6003. 	} else {
  6004. 		map[sd->bl.m].flag.clouds=1;
  6005. 		clif_weather(sd->bl.m);
  6006. 		clif_displaymessage(fd, "Clouds appear.");
  6007. 	}
  6008.  
  6009. 	return 0;
  6010. }
  6011.  
  6012. /*==========================================
  6013.  * Different type of clouds using effect 516
  6014.  *------------------------------------------*/
  6015. ACMD_FUNC(clouds2)
  6016. {
  6017. 	nullpo_retr(-1, sd);
  6018. 	if (map[sd->bl.m].flag.clouds2) {
  6019. 		map[sd->bl.m].flag.clouds2=0;
  6020. 		clif_weather(sd->bl.m);
  6021. 		clif_displaymessage(fd, "The alternative clouds disappear.");
  6022. 	} else {
  6023. 		map[sd->bl.m].flag.clouds2=1;
  6024. 		clif_weather(sd->bl.m);
  6025. 		clif_displaymessage(fd, "Alternative clouds appear.");
  6026. 	}
  6027.  
  6028. 	return 0;
  6029. }
  6030.  
  6031. /*==========================================
  6032.  * Fog hangs over.
  6033.  *------------------------------------------*/
  6034. ACMD_FUNC(fog)
  6035. {
  6036. 	nullpo_retr(-1, sd);
  6037. 	if (map[sd->bl.m].flag.fog) {
  6038. 		map[sd->bl.m].flag.fog=0;
  6039. 		clif_weather(sd->bl.m);
  6040. 		clif_displaymessage(fd, "The fog has gone.");
  6041. 	} else {
  6042. 		map[sd->bl.m].flag.fog=1;
  6043. 		clif_weather(sd->bl.m);
  6044. 		clif_displaymessage(fd, "Fog hangs over.");
  6045. 	}
  6046. 		return 0;
  6047. }
  6048.  
  6049. /*==========================================
  6050.  * Fallen leaves fall.
  6051.  *------------------------------------------*/
  6052. ACMD_FUNC(leaves)
  6053. {
  6054. 	nullpo_retr(-1, sd);
  6055. 	if (map[sd->bl.m].flag.leaves) {
  6056. 		map[sd->bl.m].flag.leaves=0;
  6057. 		clif_weather(sd->bl.m);
  6058. 		clif_displaymessage(fd, "Leaves no longer fall.");
  6059. 	} else {
  6060. 		map[sd->bl.m].flag.leaves=1;
  6061. 		clif_weather(sd->bl.m);
  6062. 		clif_displaymessage(fd, "Fallen leaves fall.");
  6063. 	}
  6064.  
  6065. 	return 0;
  6066. }
  6067.  
  6068. /*==========================================
  6069.  * Fireworks appear.
  6070.  *------------------------------------------*/
  6071. ACMD_FUNC(fireworks)
  6072. {
  6073. 	nullpo_retr(-1, sd);
  6074. 	if (map[sd->bl.m].flag.fireworks) {
  6075. 		map[sd->bl.m].flag.fireworks=0;
  6076. 		clif_weather(sd->bl.m);
  6077. 		clif_displaymessage(fd, "Fireworks are ended.");
  6078. 	} else {
  6079. 		map[sd->bl.m].flag.fireworks=1;
  6080. 		clif_weather(sd->bl.m);
  6081. 		clif_displaymessage(fd, "Fireworks are launched.");
  6082. 	}
  6083.  
  6084. 	return 0;
  6085. }
  6086.  
  6087. /*==========================================
  6088.  * Clearing Weather Effects by Dexity
  6089.  *------------------------------------------*/
  6090. ACMD_FUNC(clearweather)
  6091. {
  6092. 	nullpo_retr(-1, sd);
  6093. 	/**
  6094. 	 * No longer available, keeping here just in case it's back someday. [Ind]
  6095. 	 **/
  6096. 	//map[sd->bl.m].flag.rain=0;
  6097. 	map[sd->bl.m].flag.snow=0;
  6098. 	map[sd->bl.m].flag.sakura=0;
  6099. 	map[sd->bl.m].flag.clouds=0;
  6100. 	map[sd->bl.m].flag.clouds2=0;
  6101. 	map[sd->bl.m].flag.fog=0;
  6102. 	map[sd->bl.m].flag.fireworks=0;
  6103. 	map[sd->bl.m].flag.leaves=0;
  6104. 	clif_weather(sd->bl.m);
  6105. 	clif_displaymessage(fd, msg_txt(291));
  6106.  
  6107. 	return 0;
  6108. }
  6109.  
  6110. /*===============================================================
  6111.  * Sound Command - plays a sound for everyone around! [Codemaster]
  6112.  *---------------------------------------------------------------*/
  6113. ACMD_FUNC(sound)
  6114. {
  6115. 	char sound_file[100];
  6116.  
  6117. 	memset(sound_file, '\0', sizeof(sound_file));
  6118.  
  6119. 		if(!message || !*message || sscanf(message, "%99[^\n]", sound_file) < 1) {
  6120. 		clif_displaymessage(fd, "Please, enter a sound filename. (usage: @sound <filename>)");
  6121. 		return -1;
  6122. 	}
  6123.  
  6124. 	if(strstr(sound_file, ".wav") == NULL)
  6125. 		strcat(sound_file, ".wav");
  6126.  
  6127. 	clif_soundeffectall(&sd->bl, sound_file, 0, AREA);
  6128.  
  6129. 	return 0;
  6130. }
  6131.  
  6132. /*==========================================
  6133.  * 	MOB Search
  6134.  *------------------------------------------*/
  6135. ACMD_FUNC(mobsearch)
  6136. {
  6137. 	char mob_name[100];
  6138. 	int mob_id;
  6139. 	int number = 0;
  6140. 	struct s_mapiterator* it;
  6141.  
  6142. 	nullpo_retr(-1, sd);
  6143.  
  6144. 	if (!message || !*message || sscanf(message, "%99[^\n]", mob_name) < 1) {
  6145. 		clif_displaymessage(fd, "Please, enter a monster name (usage: @mobsearch <monster name>).");
  6146. 		return -1;
  6147. 	}
  6148.  
  6149. 	if ((mob_id = atoi(mob_name)) == 0)
  6150. 		 mob_id = mobdb_searchname(mob_name);
  6151. 	if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  6152. 		snprintf(atcmd_output, sizeof atcmd_output, "Invalid mob id %s!",mob_name);
  6153. 		clif_displaymessage(fd, atcmd_output);
  6154. 		return -1;
  6155. 	}
  6156. 	if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  6157. 				strcpy(mob_name,mob_db(mob_id)->jname);	// --ja--
  6158. //				strcpy(mob_name,mob_db(mob_id)->name);	// --en--
  6159.  
  6160. 	snprintf(atcmd_output, sizeof atcmd_output, "Mob Search... %s %s", mob_name, mapindex_id2name(sd->mapindex));
  6161. 	clif_displaymessage(fd, atcmd_output);
  6162.  
  6163. 	it = mapit_geteachmob();
  6164. 	for(;;)
  6165. 	{
  6166. 		TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  6167. 		if( md == NULL )
  6168. 			break;// no more mobs
  6169.  
  6170. 		if( md->bl.m != sd->bl.m )
  6171. 			continue;
  6172. 		if( mob_id != -1 && md->class_ != mob_id )
  6173. 			continue;
  6174.  
  6175. 		++number;
  6176. 		if( md->spawn_timer == INVALID_TIMER )
  6177. 			snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%3d:%3d] %s", number, md->bl.x, md->bl.y, md->name);
  6178. 		else
  6179. 			snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name);
  6180. 		clif_displaymessage(fd, atcmd_output);
  6181. 	}
  6182. 	mapit_free(it);
  6183.  
  6184. 	return 0;
  6185. }
  6186.  
  6187. /*==========================================
  6188.  * @cleanmap - cleans items on the ground
  6189.  *------------------------------------------*/
  6190. static int atcommand_cleanmap_sub(struct block_list *bl, va_list ap)
  6191. {
  6192. 	nullpo_ret(bl);
  6193. 	map_clearflooritem(bl->id);
  6194.  
  6195. 	return 0;
  6196. }
  6197.  
  6198. ACMD_FUNC(cleanmap)
  6199. {
  6200. 	map_foreachinarea(atcommand_cleanmap_sub, sd->bl.m,
  6201. 		sd->bl.x-AREA_SIZE*2, sd->bl.y-AREA_SIZE*2,
  6202. 		sd->bl.x+AREA_SIZE*2, sd->bl.y+AREA_SIZE*2,
  6203. 		BL_ITEM);
  6204. 	clif_displaymessage(fd, "All dropped items have been cleaned up.");
  6205. 	return 0;
  6206. }
  6207.  
  6208. /*==========================================
  6209.  * make a NPC/PET talk
  6210.  * @npctalkc [SnakeDrak]
  6211.  *------------------------------------------*/
  6212. ACMD_FUNC(npctalk)
  6213. {
  6214. 	char name[NAME_LENGTH],mes[100],temp[100];
  6215. 	struct npc_data *nd;
  6216. 	bool ifcolor=(*(command + 8) != 'c' && *(command + 8) != 'C')?0:1;
  6217. 	unsigned long color=0;
  6218.  
  6219. 	if (sd->sc.count && //no "chatting" while muted.
  6220. 		(sd->sc.data[SC_BERSERK] ||
  6221. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6222. 		return -1;
  6223.  
  6224. 	if(!ifcolor) {
  6225. 		if (!message || !*message || sscanf(message, "%23[^,], %99[^\n]", name, mes) < 2) {
  6226. 			clif_displaymessage(fd, "Please, enter the correct info (usage: @npctalk <npc name>, <message>).");
  6227. 			return -1;
  6228. 		}
  6229. 	}
  6230. 	else {
  6231. 		if (!message || !*message || sscanf(message, "%lx %23[^,], %99[^\n]", &color, name, mes) < 3) {
  6232. 			clif_displaymessage(fd, "Please, enter the correct info (usage: @npctalkc <color> <npc name>, <message>).");
  6233. 			return -1;
  6234. 		}
  6235. 	}
  6236.  
  6237. 	if (!(nd = npc_name2id(name))) {
  6238. 		clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist
  6239. 		return -1;
  6240. 	}
  6241.  
  6242. 	strtok(name, "#"); // discard extra name identifier if present
  6243. 	snprintf(temp, sizeof(temp), "%s : %s", name, mes);
  6244.  
  6245. 	if(ifcolor) clif_messagecolor(&nd->bl,color,temp);
  6246. 	else clif_message(&nd->bl, temp);
  6247.  
  6248. 	return 0;
  6249. }
  6250.  
  6251. ACMD_FUNC(pettalk)
  6252. {
  6253. 	char mes[100],temp[100];
  6254. 	struct pet_data *pd;
  6255.  
  6256. 	nullpo_retr(-1, sd);
  6257.  
  6258. 	if(!sd->status.pet_id || !(pd=sd->pd))
  6259. 	{
  6260. 		clif_displaymessage(fd, msg_txt(184));
  6261. 		return -1;
  6262. 	}
  6263.  
  6264. 	if (sd->sc.count && //no "chatting" while muted.
  6265. 		(sd->sc.data[SC_BERSERK] ||
  6266. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6267. 		return -1;
  6268.  
  6269. 	if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6270. 		clif_displaymessage(fd, "Please, enter a message (usage: @pettalk <message>");
  6271. 		return -1;
  6272. 	}
  6273.  
  6274. 	if (message[0] == '/')
  6275. 	{// pet emotion processing
  6276. 		const char* emo[] = {
  6277. 			"/!", "/?", "/ho", "/lv", "/swt", "/ic", "/an", "/ag", "/$", "/...",
  6278. 			"/scissors", "/rock", "/paper", "/korea", "/lv2", "/thx", "/wah", "/sry", "/heh", "/swt2",
  6279. 			"/hmm", "/no1", "/??", "/omg", "/O", "/X", "/hlp", "/go", "/sob", "/gg",
  6280. 			"/kis", "/kis2", "/pif", "/ok", "-?-", "/indonesia", "/bzz", "/rice", "/awsm", "/meh",
  6281. 			"/shy", "/pat", "/mp", "/slur", "/com", "/yawn", "/grat", "/hp", "/philippines", "/malaysia",
  6282. 			"/singapore", "/brazil", "/fsh", "/spin", "/sigh", "/dum", "/crwd", "/desp", "/dice", "-dice2",
  6283. 			"-dice3", "-dice4", "-dice5", "-dice6", "/india", "/love", "/russia", "-?-", "/mobile", "/mail",
  6284. 			"/chinese", "/antenna1", "/antenna2", "/antenna3", "/hum", "/abs", "/oops", "/spit", "/ene", "/panic",
  6285. 			"/whisp"
  6286. 		};
  6287. 		int i;
  6288. 		ARR_FIND( 0, ARRAYLENGTH(emo), i, stricmp(message, emo[i]) == 0 );
  6289. 		if( i == E_DICE1 ) i = rnd()%6 + E_DICE1; // randomize /dice
  6290. 		if( i < ARRAYLENGTH(emo) )
  6291. 		{
  6292. 			if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  6293. 					sd->emotionlasttime = time(NULL);
  6294. 					return 0;
  6295. 			}
  6296. 			sd->emotionlasttime = time(NULL);
  6297.  
  6298. 			clif_emotion(&pd->bl, i);
  6299. 			return 0;
  6300. 		}
  6301. 	}
  6302.  
  6303. 	snprintf(temp, sizeof temp ,"%s : %s", pd->pet.name, mes);
  6304. 	clif_message(&pd->bl, temp);
  6305.  
  6306. 	return 0;
  6307. }
  6308.  
  6309. /// @users - displays the number of players present on each map (and percentage)
  6310. /// #users displays on the target user instead of self
  6311. ACMD_FUNC(users)
  6312. {
  6313. 	char buf[CHAT_SIZE_MAX];
  6314. 	int i;
  6315. 	int users[MAX_MAPINDEX];
  6316. 	int users_all;
  6317. 	struct s_mapiterator* iter;
  6318.  
  6319. 	memset(users, 0, sizeof(users));
  6320. 	users_all = 0;
  6321.  
  6322. 	// count users on each map
  6323. 	iter = mapit_getallusers();
  6324. 	for(;;)
  6325. 	{
  6326. 		struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter);
  6327. 		if( sd2 == NULL )
  6328. 			break;// no more users
  6329.  
  6330. 		if( sd2->mapindex >= MAX_MAPINDEX )
  6331. 			continue;// invalid mapindex
  6332.  
  6333. 		if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex];
  6334. 		if( users_all < INT_MAX ) ++users_all;
  6335. 	}
  6336. 	mapit_free(iter);
  6337.  
  6338. 	// display results for each map
  6339. 	for( i = 0; i < MAX_MAPINDEX; ++i )
  6340. 	{
  6341. 		if( users[i] == 0 )
  6342. 			continue;// empty
  6343.  
  6344. 		safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
  6345. 		clif_displaymessage(sd->fd, buf);
  6346. 	}
  6347.  
  6348. 	// display overall count
  6349. 	safesnprintf(buf, sizeof(buf), "all: %d", users_all);
  6350. 	clif_displaymessage(sd->fd, buf);
  6351.  
  6352. 	return 0;
  6353. }
  6354.  
  6355. /*==========================================
  6356.  *
  6357.  *------------------------------------------*/
  6358. ACMD_FUNC(reset)
  6359. {
  6360. 	pc_resetstate(sd);
  6361. 	pc_resetskill(sd,1);
  6362. 	sprintf(atcmd_output, msg_txt(208), sd->status.name); // '%s' skill and stats points reseted!
  6363. 	clif_displaymessage(fd, atcmd_output);
  6364. 	return 0;
  6365. }
  6366.  
  6367. /*==========================================
  6368.  *
  6369.  *------------------------------------------*/
  6370. ACMD_FUNC(summon)
  6371. {
  6372. 	char name[NAME_LENGTH];
  6373. 	int mob_id = 0;
  6374. 	int duration = 0;
  6375. 	struct mob_data *md;
  6376. 	unsigned int tick=gettick();
  6377.  
  6378. 	nullpo_retr(-1, sd);
  6379.  
  6380. 	if (!message || !*message || sscanf(message, "%23s %d", name, &duration) < 1)
  6381. 	{
  6382. 		clif_displaymessage(fd, "Please, enter a monster name (usage: @summon <monster name> [duration]");
  6383. 		return -1;
  6384. 	}
  6385.  
  6386. 	if (duration < 1)
  6387. 		duration =1;
  6388. 	else if (duration > 60)
  6389. 		duration =60;
  6390.  
  6391. 	if ((mob_id = atoi(name)) == 0)
  6392. 		mob_id = mobdb_searchname(name);
  6393. 	if(mob_id == 0 || mobdb_checkid(mob_id) == 0)
  6394. 	{
  6395. 		clif_displaymessage(fd, msg_txt(40));	// Invalid monster ID or name.
  6396. 		return -1;
  6397. 	}
  6398.  
  6399. 	md = mob_once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "");
  6400.  
  6401. 	if(!md)
  6402. 		return -1;
  6403.  
  6404. 	md->master_id=sd->bl.id;
  6405. 	md->special_state.ai=1;
  6406. 	md->deletetimer=add_timer(tick+(duration*60000),mob_timer_delete,md->bl.id,0);
  6407. 	clif_specialeffect(&md->bl,344,AREA);
  6408. 	mob_spawn(md);
  6409. 	sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  6410. 	clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick);
  6411. 	clif_displaymessage(fd, msg_txt(39));	// All monster summoned!
  6412.  
  6413. 	return 0;
  6414. }
  6415.  
  6416. /*==========================================
  6417.  * @adjgroup
  6418.  * Temporarily move player to another group
  6419.  * Useful during beta testing to allow players to use GM commands for short periods of time
  6420.  *------------------------------------------*/
  6421. ACMD_FUNC(adjgroup)
  6422. {
  6423. 	int new_group = 0;
  6424. 	nullpo_retr(-1, sd);
  6425.  
  6426. 	if (!message || !*message || sscanf(message, "%d", &new_group) != 1) {
  6427. 		clif_displaymessage(fd, "Usage: @adjgroup <group_id>");
  6428. 		return -1;
  6429. 	}
  6430.  
  6431. 	if (!pc_group_exists(new_group)) {
  6432. 		clif_displaymessage(fd, "Specified group does not exists.");
  6433. 		return -1;
  6434. 	}
  6435.  
  6436. 	sd->group_id = new_group;
  6437. 	pc_group_pc_load(sd);/* update cache */
  6438. 	clif_displaymessage(fd, "Group changed successfully.");
  6439. 	clif_displaymessage(sd->fd, "Your group has changed.");
  6440. 	return 0;
  6441. }
  6442.  
  6443. /*==========================================
  6444.  * @trade by [MouseJstr]
  6445.  * Open a trade window with a remote player
  6446.  *------------------------------------------*/
  6447. ACMD_FUNC(trade)
  6448. {
  6449.     struct map_session_data *pl_sd = NULL;
  6450. 	nullpo_retr(-1, sd);
  6451.  
  6452. 	if (!message || !*message) {
  6453. 		clif_displaymessage(fd, "Please, enter a player name (usage: @trade <player>).");
  6454. 		return -1;
  6455. 	}
  6456.  
  6457. 	if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  6458. 	{
  6459. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6460. 		return -1;
  6461. 	}
  6462.  
  6463. 	trade_traderequest(sd, pl_sd);
  6464. 	return 0;
  6465. }
  6466.  
  6467. /*==========================================
  6468.  * @setbattleflag by [MouseJstr]
  6469.  * set a battle_config flag without having to reboot
  6470.  *------------------------------------------*/
  6471. ACMD_FUNC(setbattleflag)
  6472. {
  6473. 	char flag[128], value[128];
  6474. 	nullpo_retr(-1, sd);
  6475.  
  6476. 	if (!message || !*message || sscanf(message, "%127s %127s", flag, value) != 2) {
  6477.         	clif_displaymessage(fd, "Usage: @setbattleflag <flag> <value>.");
  6478.         	return -1;
  6479.     	}
  6480.  
  6481. 	if (battle_set_value(flag, value) == 0)
  6482. 	{
  6483. 		clif_displaymessage(fd, "unknown battle_config flag");
  6484. 		return -1;
  6485. 	}
  6486.  
  6487. 	clif_displaymessage(fd, "battle_config set as requested");
  6488.  
  6489. 	return 0;
  6490. }
  6491.  
  6492. /*==========================================
  6493.  * @unmute [Valaris]
  6494.  *------------------------------------------*/
  6495. ACMD_FUNC(unmute)
  6496. {
  6497. 	struct map_session_data *pl_sd = NULL;
  6498. 	nullpo_retr(-1, sd);
  6499.  
  6500. 	if (!message || !*message) {
  6501. 		clif_displaymessage(fd, "Please, enter a player name (usage: @unmute <player>).");
  6502. 		return -1;
  6503. 	}
  6504.  
  6505. 	if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  6506. 	{
  6507. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6508. 		return -1;
  6509. 	}
  6510.  
  6511. 	if(!pl_sd->sc.data[SC_NOCHAT]) {
  6512. 		clif_displaymessage(sd->fd,"Player is not muted");
  6513. 		return -1;
  6514. 	}
  6515.  
  6516. 	pl_sd->status.manner = 0;
  6517. 	status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  6518. 	clif_displaymessage(sd->fd,"Player unmuted");
  6519.  
  6520. 	return 0;
  6521. }
  6522.  
  6523. /*==========================================
  6524.  * @uptime by MC Cameri
  6525.  *------------------------------------------*/
  6526. ACMD_FUNC(uptime)
  6527. {
  6528. 	unsigned long seconds = 0, day = 24*60*60, hour = 60*60,
  6529. 		minute = 60, days = 0, hours = 0, minutes = 0;
  6530. 	nullpo_retr(-1, sd);
  6531.  
  6532. 	seconds = get_uptime();
  6533. 	days = seconds/day;
  6534. 	seconds -= (seconds/day>0)?(seconds/day)*day:0;
  6535. 	hours = seconds/hour;
  6536. 	seconds -= (seconds/hour>0)?(seconds/hour)*hour:0;
  6537. 	minutes = seconds/minute;
  6538. 	seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
  6539.  
  6540. 	snprintf(atcmd_output, sizeof(atcmd_output), msg_txt(245), days, hours, minutes, seconds);
  6541. 	clif_displaymessage(fd, atcmd_output);
  6542.  
  6543. 	return 0;
  6544. }
  6545.  
  6546. /*==========================================
  6547.  * @changesex <sex>
  6548.  * => Changes one's sex. Argument sex can be 0 or 1, m or f, male or female.
  6549.  *------------------------------------------*/
  6550. ACMD_FUNC(changesex)
  6551. {
  6552. 	int i;
  6553. 	nullpo_retr(-1, sd);
  6554. 	pc_resetskill(sd,4);
  6555. 	// to avoid any problem with equipment and invalid sex, equipment is unequiped.
  6556. 	for( i=0; i<EQI_MAX; i++ )
  6557. 		if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3);
  6558. 	chrif_changesex(sd);
  6559. 	return 0;
  6560. }
  6561.  
  6562. /*================================================
  6563.  * @mute - Mutes a player for a set amount of time
  6564.  *------------------------------------------------*/
  6565. ACMD_FUNC(mute)
  6566. {
  6567. 	struct map_session_data *pl_sd = NULL;
  6568. 	int manner;
  6569. 	nullpo_retr(-1, sd);
  6570.  
  6571. 	if (!message || !*message || sscanf(message, "%d %23[^\n]", &manner, atcmd_player_name) < 1) {
  6572. 		clif_displaymessage(fd, "Usage: @mute <time> <character name>.");
  6573. 		return -1;
  6574. 	}
  6575.  
  6576. 	if ( (pl_sd = map_nick2sd(atcmd_player_name)) == NULL )
  6577. 	{
  6578. 		clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6579. 		return -1;
  6580. 	}
  6581.  
  6582. 	if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  6583. 	{
  6584. 		clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  6585. 		return -1;
  6586. 	}
  6587.  
  6588. 	clif_manner_message(sd, 0);
  6589. 	clif_manner_message(pl_sd, 5);
  6590.  
  6591. 	if( pl_sd->status.manner < manner ) {
  6592. 		pl_sd->status.manner -= manner;
  6593. 		sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
  6594. 	} else {
  6595. 		pl_sd->status.manner = 0;
  6596. 		status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  6597. 	}
  6598.  
  6599. 	clif_GM_silence(sd, pl_sd, (manner > 0 ? 1 : 0));
  6600.  
  6601. 	return 0;
  6602. }
  6603.  
  6604. /*==========================================
  6605.  * @refresh (like @jumpto <<yourself>>)
  6606.  *------------------------------------------*/
  6607. ACMD_FUNC(refresh)
  6608. {
  6609. 	nullpo_retr(-1, sd);
  6610. 	clif_refresh(sd);
  6611. 	return 0;
  6612. }
  6613.  
  6614. /*==========================================
  6615.  * @identify
  6616.  * => GM's magnifier.
  6617.  *------------------------------------------*/
  6618. ACMD_FUNC(identify)
  6619. {
  6620. 	int i,num;
  6621.  
  6622. 	nullpo_retr(-1, sd);
  6623.  
  6624. 	for(i=num=0;i<MAX_INVENTORY;i++){
  6625. 		if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  6626. 			num++;
  6627. 		}
  6628. 	}
  6629. 	if (num > 0) {
  6630. 		clif_item_identify_list(sd);
  6631. 	} else {
  6632. 		clif_displaymessage(fd,"There are no items to appraise.");
  6633. 	}
  6634. 	return 0;
  6635. }
  6636.  
  6637. /*==========================================
  6638.  * @gmotd (Global MOTD)
  6639.  * by davidsiaw :P
  6640.  *------------------------------------------*/
  6641. ACMD_FUNC(gmotd)
  6642. {
  6643. 	char buf[CHAT_SIZE_MAX];
  6644. 	size_t len;
  6645. 	FILE* fp;
  6646.  
  6647. 	if( ( fp = fopen(motd_txt, "r") ) != NULL )
  6648. 	{
  6649. 		while( fgets(buf, sizeof(buf), fp) )
  6650. 		{
  6651. 			if( buf[0] == '/' && buf[1] == '/' )
  6652. 			{
  6653. 				continue;
  6654. 			}
  6655.  
  6656. 			len = strlen(buf);
  6657.  
  6658. 			while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) )
  6659. 			{// strip trailing EOL characters
  6660. 				len--;
  6661. 			}
  6662.  
  6663. 			if( len )
  6664. 			{
  6665. 				buf[len] = 0;
  6666.  
  6667. 				intif_broadcast(buf, len+1, 0);
  6668. 			}
  6669. 		}
  6670. 		fclose(fp);
  6671. 	}
  6672. 	return 0;
  6673. }
  6674.  
  6675. ACMD_FUNC(misceffect)
  6676. {
  6677. 	int effect = 0;
  6678. 	nullpo_retr(-1, sd);
  6679. 	if (!message || !*message)
  6680. 		return -1;
  6681. 	if (sscanf(message, "%d", &effect) < 1)
  6682. 		return -1;
  6683. 	clif_misceffect(&sd->bl,effect);
  6684.  
  6685. 	return 0;
  6686. }
  6687.  
  6688. /*==========================================
  6689.  * MAIL SYSTEM
  6690.  *------------------------------------------*/
  6691. ACMD_FUNC(mail)
  6692. {
  6693. 	nullpo_ret(sd);
  6694. 	mail_openmail(sd);
  6695. 	return 0;
  6696. }
  6697.  
  6698. /*==========================================
  6699.  * Show Monster DB Info   v 1.0
  6700.  * originally by [Lupus]
  6701.  *------------------------------------------*/
  6702. ACMD_FUNC(mobinfo)
  6703. {
  6704. 	unsigned char msize[3][7] = {"Small", "Medium", "Large"};
  6705. 	unsigned char mrace[12][11] = {"Formless", "Undead", "Beast", "Plant", "Insect", "Fish", "Demon", "Demi-Human", "Angel", "Dragon", "Boss", "Non-Boss"};
  6706. 	unsigned char melement[10][8] = {"Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
  6707. 	char atcmd_output2[CHAT_SIZE_MAX];
  6708. 	struct item_data *item_data;
  6709. 	struct mob_db *mob, *mob_array[MAX_SEARCH];
  6710. 	int count;
  6711. 	int i, j, k;
  6712.  
  6713. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  6714. 	memset(atcmd_output2, '\0', sizeof(atcmd_output2));
  6715.  
  6716. 	if (!message || !*message) {
  6717. 		clif_displaymessage(fd, "Please, enter a Monster/ID (usage: @mobinfo <monster_name_or_monster_ID>).");
  6718. 		return -1;
  6719. 	}
  6720.  
  6721. 	// If monster identifier/name argument is a name
  6722. 	if ((i = mobdb_checkid(atoi(message))))
  6723. 	{
  6724. 		mob_array[0] = mob_db(i);
  6725. 		count = 1;
  6726. 	} else
  6727. 		count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  6728.  
  6729. 	if (!count) {
  6730. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  6731. 		return -1;
  6732. 	}
  6733.  
  6734. 	if (count > MAX_SEARCH) {
  6735. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count);
  6736. 		clif_displaymessage(fd, atcmd_output);
  6737. 		count = MAX_SEARCH;
  6738. 	}
  6739. 	for (k = 0; k < count; k++) {
  6740. 		mob = mob_array[k];
  6741.  
  6742. 		// stats
  6743. 		if (mob->mexp)
  6744. 			sprintf(atcmd_output, "MVP Monster: '%s'/'%s'/'%s' (%d)", mob->name, mob->jname, mob->sprite, mob->vd.class_);
  6745. 		else
  6746. 			sprintf(atcmd_output, "Monster: '%s'/'%s'/'%s' (%d)", mob->name, mob->jname, mob->sprite, mob->vd.class_);
  6747. 		clif_displaymessage(fd, atcmd_output);
  6748. 		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));
  6749. 		clif_displaymessage(fd, atcmd_output);
  6750. 		sprintf(atcmd_output, " DEF:%d  MDEF:%d  STR:%d  AGI:%d  VIT:%d  INT:%d  DEX:%d  LUK:%d",
  6751. 			mob->status.def, mob->status.mdef,mob->status.str, mob->status.agi,
  6752. 			mob->status.vit, mob->status.int_, mob->status.dex, mob->status.luk);
  6753. 		clif_displaymessage(fd, atcmd_output);
  6754.  
  6755. 		sprintf(atcmd_output, " ATK:%d~%d  Range:%d~%d~%d  Size:%s  Race: %s  Element: %s (Lv:%d)",
  6756. 			mob->status.rhw.atk, mob->status.rhw.atk2, mob->status.rhw.range,
  6757. 			mob->range2 , mob->range3, msize[mob->status.size],
  6758. 			mrace[mob->status.race], melement[mob->status.def_ele], mob->status.ele_lv);
  6759. 		clif_displaymessage(fd, atcmd_output);
  6760. 		// drops
  6761. 		clif_displaymessage(fd, " Drops:");
  6762. 		strcpy(atcmd_output, " ");
  6763. 		j = 0;
  6764. 		for (i = 0; i < MAX_MOB_DROP; i++) {
  6765. 			int droprate;
  6766. 			if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_exists(mob->dropitem[i].nameid)) == NULL)
  6767. 				continue;
  6768. 			droprate = mob->dropitem[i].p;
  6769. #ifdef RENEWAL_DROP
  6770. 			if( battle_config.atcommand_mobinfo_type )
  6771. 				droprate = droprate * party_renewal_drop_mod(sd->status.base_level - mob->lv) / 100;
  6772. #endif
  6773. 			if (item_data->slot)
  6774. 				sprintf(atcmd_output2, " - %s[%d]  %02.02f%%", item_data->jname, item_data->slot, (float)droprate / 100);
  6775. 			else
  6776. 				sprintf(atcmd_output2, " - %s  %02.02f%%", item_data->jname, (float)droprate / 100);
  6777. 			strcat(atcmd_output, atcmd_output2);
  6778. 			if (++j % 3 == 0) {
  6779. 				clif_displaymessage(fd, atcmd_output);
  6780. 				strcpy(atcmd_output, " ");
  6781. 			}
  6782. 		}
  6783. 		if (j == 0)
  6784. 			clif_displaymessage(fd, "This monster has no drops.");
  6785. 		else if (j % 3 != 0)
  6786. 			clif_displaymessage(fd, atcmd_output);
  6787. 		// mvp
  6788. 		if (mob->mexp) {
  6789. 			sprintf(atcmd_output, " MVP Bonus EXP:%u", mob->mexp);
  6790. 			clif_displaymessage(fd, atcmd_output);
  6791. 			strcpy(atcmd_output, " MVP Items:");
  6792. 			j = 0;
  6793. 			for (i = 0; i < MAX_MVP_DROP; i++) {
  6794. 				if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_exists(mob->mvpitem[i].nameid)) == NULL)
  6795. 					continue;
  6796. 				if (mob->mvpitem[i].p > 0) {
  6797. 					j++;
  6798. 					if (j == 1)
  6799. 						sprintf(atcmd_output2, " %s  %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  6800. 					else
  6801. 						sprintf(atcmd_output2, " - %s  %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  6802. 					strcat(atcmd_output, atcmd_output2);
  6803. 				}
  6804. 			}
  6805. 			if (j == 0)
  6806. 				clif_displaymessage(fd, "This monster has no MVP prizes.");
  6807. 			else
  6808. 				clif_displaymessage(fd, atcmd_output);
  6809. 		}
  6810. 	}
  6811. 	return 0;
  6812. }
  6813.  
  6814. /*=========================================
  6815. * @showmobs by KarLaeda
  6816. * => For 15 sec displays the mobs on minimap
  6817. *------------------------------------------*/
  6818. ACMD_FUNC(showmobs)
  6819. {
  6820. 	char mob_name[100];
  6821. 	int mob_id;
  6822. 	int number = 0;
  6823. 	struct s_mapiterator* it;
  6824.  
  6825. 	nullpo_retr(-1, sd);
  6826.  
  6827. 	if(sscanf(message, "%99[^\n]", mob_name) < 0)
  6828. 		return -1;
  6829.  
  6830. 	if((mob_id = atoi(mob_name)) == 0)
  6831. 		mob_id = mobdb_searchname(mob_name);
  6832. 	if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  6833. 		snprintf(atcmd_output, sizeof atcmd_output, "Invalid mob id %s!",mob_name);
  6834. 		clif_displaymessage(fd, atcmd_output);
  6835. 		return 0;
  6836. 	}
  6837.  
  6838. 	if(mob_db(mob_id)->status.mode&MD_BOSS && !pc_has_permission(sd, PC_PERM_SHOW_BOSS)){	// If player group does not have access to boss mobs.
  6839. 		snprintf(atcmd_output, sizeof atcmd_output, "Can't show Boss mobs!");
  6840. 		clif_displaymessage(fd, atcmd_output);
  6841. 		return 0;
  6842. 	}
  6843.  
  6844. 	if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  6845. 		strcpy(mob_name,mob_db(mob_id)->jname);    // --ja--
  6846. 		//strcpy(mob_name,mob_db(mob_id)->name);    // --en--
  6847.  
  6848. 	snprintf(atcmd_output, sizeof atcmd_output, "Mob Search... %s %s",
  6849. 		mob_name, mapindex_id2name(sd->mapindex));
  6850. 	clif_displaymessage(fd, atcmd_output);
  6851.  
  6852. 	it = mapit_geteachmob();
  6853. 	for(;;)
  6854. 	{
  6855. 		TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  6856. 		if( md == NULL )
  6857. 			break;// no more mobs
  6858.  
  6859. 		if( md->bl.m != sd->bl.m )
  6860. 			continue;
  6861. 		if( mob_id != -1 && md->class_ != mob_id )
  6862. 			continue;
  6863. 		if( md->special_state.ai || md->master_id )
  6864. 			continue; // hide slaves and player summoned mobs
  6865. 		if( md->spawn_timer != INVALID_TIMER )
  6866. 			continue; // hide mobs waiting for respawn
  6867.  
  6868. 		++number;
  6869. 		clif_viewpoint(sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF);
  6870. 	}
  6871. 	mapit_free(it);
  6872.  
  6873. 	return 0;
  6874. }
  6875.  
  6876. /*==========================================
  6877.  * homunculus level up [orn]
  6878.  *------------------------------------------*/
  6879. ACMD_FUNC(homlevel)
  6880. {
  6881. 	TBL_HOM * hd;
  6882. 	int level = 0, i = 0;
  6883.  
  6884. 	nullpo_retr(-1, sd);
  6885.  
  6886. 	if ( !message || !*message || ( level = atoi(message) ) < 1 ) {
  6887. 		clif_displaymessage(fd, "Please, enter a level adjustment: (usage: @homlevel <# of levels to level up>.");
  6888. 		return -1;
  6889. 	}
  6890.  
  6891. 	if ( !merc_is_hom_active(sd->hd) ) {
  6892. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6893. 		return -1;
  6894. 	}
  6895.  
  6896. 	hd = sd->hd;
  6897.  
  6898. 	for (i = 1; i <= level && hd->exp_next; i++){
  6899. 		hd->homunculus.exp += hd->exp_next;
  6900. 		merc_hom_levelup(hd);
  6901. 	}
  6902. 	status_calc_homunculus(hd,0);
  6903. 	status_percent_heal(&hd->bl, 100, 100);
  6904. 	clif_specialeffect(&hd->bl,568,AREA);
  6905. 	return 0;
  6906. }
  6907.  
  6908. /*==========================================
  6909.  * homunculus evolution H [orn]
  6910.  *------------------------------------------*/
  6911. ACMD_FUNC(homevolution)
  6912. {
  6913. 	nullpo_retr(-1, sd);
  6914.  
  6915. 	if ( !merc_is_hom_active(sd->hd) ) {
  6916. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6917. 		return -1;
  6918. 	}
  6919.  
  6920. 	if ( !merc_hom_evolution(sd->hd) ) {
  6921. 		clif_displaymessage(fd, "Your homunculus doesn't evolve.");
  6922. 		return -1;
  6923. 	}
  6924. 	clif_homskillinfoblock(sd);
  6925. 	return 0;
  6926. }
  6927.  
  6928. /*==========================================
  6929.  * call choosen homunculus [orn]
  6930.  *------------------------------------------*/
  6931. ACMD_FUNC(makehomun)
  6932. {
  6933. 	int homunid;
  6934. 	nullpo_retr(-1, sd);
  6935.  
  6936. 	if ( sd->status.hom_id ) {
  6937. 		clif_displaymessage(fd, msg_txt(450));
  6938. 		return -1;
  6939. 	}
  6940.  
  6941. 	if (!message || !*message) {
  6942. 		clif_displaymessage(fd, "Please, enter a homunculus id: (usage: @makehomun <homunculus id>.");
  6943. 		return -1;
  6944. 	}
  6945.  
  6946. 	homunid = atoi(message);
  6947. 	if( homunid < HM_CLASS_BASE || homunid > HM_CLASS_BASE + MAX_HOMUNCULUS_CLASS - 1 )
  6948. 	{
  6949. 		clif_displaymessage(fd, "Invalid Homunculus id.");
  6950. 		return -1;
  6951. 	}
  6952.  
  6953. 	merc_create_homunculus_request(sd,homunid);
  6954. 	return 0;
  6955. }
  6956.  
  6957. /*==========================================
  6958.  * modify homunculus intimacy [orn]
  6959.  *------------------------------------------*/
  6960. ACMD_FUNC(homfriendly)
  6961. {
  6962. 	int friendly = 0;
  6963.  
  6964. 	nullpo_retr(-1, sd);
  6965.  
  6966. 	if ( !merc_is_hom_active(sd->hd) ) {
  6967. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6968. 		return -1;
  6969. 	}
  6970.  
  6971. 	if (!message || !*message) {
  6972. 		clif_displaymessage(fd, "Please, enter a friendly value: (usage: @homfriendly <friendly value[0-1000]>.");
  6973. 		return -1;
  6974. 	}
  6975.  
  6976. 	friendly = atoi(message);
  6977. 	friendly = cap_value(friendly, 0, 1000);
  6978.  
  6979. 	sd->hd->homunculus.intimacy = friendly * 100 ;
  6980. 	clif_send_homdata(sd,SP_INTIMATE,friendly);
  6981. 	return 0;
  6982. }
  6983.  
  6984. /*==========================================
  6985.  * modify homunculus hunger [orn]
  6986.  *------------------------------------------*/
  6987. ACMD_FUNC(homhungry)
  6988. {
  6989. 	int hungry = 0;
  6990.  
  6991. 	nullpo_retr(-1, sd);
  6992.  
  6993. 	if ( !merc_is_hom_active(sd->hd) ) {
  6994. 		clif_displaymessage(fd, "You do not have a homunculus.");
  6995. 		return -1;
  6996. 	}
  6997.  
  6998. 	if (!message || !*message) {
  6999. 		clif_displaymessage(fd, "Please, enter a hunger value: (usage: @homhungry <hunger value[0-100]>.");
  7000. 		return -1;
  7001. 	}
  7002.  
  7003. 	hungry = atoi(message);
  7004. 	hungry = cap_value(hungry, 0, 100);
  7005.  
  7006. 	sd->hd->homunculus.hunger = hungry;
  7007. 	clif_send_homdata(sd,SP_HUNGRY,hungry);
  7008. 	return 0;
  7009. }
  7010.  
  7011. /*==========================================
  7012.  * make the homunculus speak [orn]
  7013.  *------------------------------------------*/
  7014. ACMD_FUNC(homtalk)
  7015. {
  7016. 	char mes[100],temp[100];
  7017.  
  7018. 	nullpo_retr(-1, sd);
  7019.  
  7020. 	if (sd->sc.count && //no "chatting" while muted.
  7021. 		(sd->sc.data[SC_BERSERK] ||
  7022. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  7023. 		return -1;
  7024.  
  7025. 	if ( !merc_is_hom_active(sd->hd) ) {
  7026. 		clif_displaymessage(fd, "You do not have a homunculus.");
  7027. 		return -1;
  7028. 	}
  7029.  
  7030. 	if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  7031. 		clif_displaymessage(fd, "Please, enter a message (usage: @homtalk <message>");
  7032. 		return -1;
  7033. 	}
  7034.  
  7035. 	snprintf(temp, sizeof temp ,"%s : %s", sd->hd->homunculus.name, mes);
  7036. 	clif_message(&sd->hd->bl, temp);
  7037.  
  7038. 	return 0;
  7039. }
  7040.  
  7041. /*==========================================
  7042.  * Show homunculus stats
  7043.  *------------------------------------------*/
  7044. ACMD_FUNC(hominfo)
  7045. {
  7046. 	struct homun_data *hd;
  7047. 	struct status_data *status;
  7048. 	nullpo_retr(-1, sd);
  7049.  
  7050. 	if ( !merc_is_hom_active(sd->hd) ) {
  7051. 		clif_displaymessage(fd, "You do not have a homunculus.");
  7052. 		return -1;
  7053. 	}
  7054.  
  7055. 	hd = sd->hd;
  7056. 	status = status_get_status_data(&hd->bl);
  7057. 	clif_displaymessage(fd, "Homunculus stats :");
  7058.  
  7059. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"HP : %d/%d - SP : %d/%d",
  7060. 		status->hp, status->max_hp, status->sp, status->max_sp);
  7061. 	clif_displaymessage(fd, atcmd_output);
  7062.  
  7063. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"ATK : %d - MATK : %d~%d",
  7064. 		status->rhw.atk2 +status->batk, status->matk_min, status->matk_max);
  7065. 	clif_displaymessage(fd, atcmd_output);
  7066.  
  7067. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Hungry : %d - Intimacy : %u",
  7068. 		hd->homunculus.hunger, hd->homunculus.intimacy/100);
  7069. 	clif_displaymessage(fd, atcmd_output);
  7070.  
  7071. 	snprintf(atcmd_output, sizeof(atcmd_output) ,
  7072. 		"Stats: Str %d / Agi %d / Vit %d / Int %d / Dex %d / Luk %d",
  7073. 		status->str, status->agi, status->vit,
  7074. 		status->int_, status->dex, status->luk);
  7075. 	clif_displaymessage(fd, atcmd_output);
  7076.  
  7077. 	return 0;
  7078. }
  7079.  
  7080. ACMD_FUNC(homstats)
  7081. {
  7082. 	struct homun_data *hd;
  7083. 	struct s_homunculus_db *db;
  7084. 	struct s_homunculus *hom;
  7085. 	int lv, min, max, evo;
  7086.  
  7087. 	nullpo_retr(-1, sd);
  7088.  
  7089. 	if ( !merc_is_hom_active(sd->hd) ) {
  7090. 		clif_displaymessage(fd, "You do not have a homunculus.");
  7091. 		return -1;
  7092. 	}
  7093.  
  7094. 	hd = sd->hd;
  7095.  
  7096. 	hom = &hd->homunculus;
  7097. 	db = hd->homunculusDB;
  7098. 	lv = hom->level;
  7099.  
  7100. 	snprintf(atcmd_output, sizeof(atcmd_output) ,
  7101. 		"Homunculus growth stats (Lv %d %s):", lv, db->name);
  7102. 	clif_displaymessage(fd, atcmd_output);
  7103. 	lv--; //Since the first increase is at level 2.
  7104.  
  7105. 	evo = (hom->class_ == db->evo_class);
  7106. 	min = db->base.HP +lv*db->gmin.HP +(evo?db->emin.HP:0);
  7107. 	max = db->base.HP +lv*db->gmax.HP +(evo?db->emax.HP:0);;
  7108. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Max HP: %d (%d~%d)", hom->max_hp, min, max);
  7109. 	clif_displaymessage(fd, atcmd_output);
  7110.  
  7111. 	min = db->base.SP +lv*db->gmin.SP +(evo?db->emin.SP:0);
  7112. 	max = db->base.SP +lv*db->gmax.SP +(evo?db->emax.SP:0);;
  7113. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Max SP: %d (%d~%d)", hom->max_sp, min, max);
  7114. 	clif_displaymessage(fd, atcmd_output);
  7115.  
  7116. 	min = db->base.str +lv*(db->gmin.str/10) +(evo?db->emin.str:0);
  7117. 	max = db->base.str +lv*(db->gmax.str/10) +(evo?db->emax.str:0);;
  7118. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Str: %d (%d~%d)", hom->str/10, min, max);
  7119. 	clif_displaymessage(fd, atcmd_output);
  7120.  
  7121. 	min = db->base.agi +lv*(db->gmin.agi/10) +(evo?db->emin.agi:0);
  7122. 	max = db->base.agi +lv*(db->gmax.agi/10) +(evo?db->emax.agi:0);;
  7123. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Agi: %d (%d~%d)", hom->agi/10, min, max);
  7124. 	clif_displaymessage(fd, atcmd_output);
  7125.  
  7126. 	min = db->base.vit +lv*(db->gmin.vit/10) +(evo?db->emin.vit:0);
  7127. 	max = db->base.vit +lv*(db->gmax.vit/10) +(evo?db->emax.vit:0);;
  7128. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Vit: %d (%d~%d)", hom->vit/10, min, max);
  7129. 	clif_displaymessage(fd, atcmd_output);
  7130.  
  7131. 	min = db->base.int_ +lv*(db->gmin.int_/10) +(evo?db->emin.int_:0);
  7132. 	max = db->base.int_ +lv*(db->gmax.int_/10) +(evo?db->emax.int_:0);;
  7133. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Int: %d (%d~%d)", hom->int_/10, min, max);
  7134. 	clif_displaymessage(fd, atcmd_output);
  7135.  
  7136. 	min = db->base.dex +lv*(db->gmin.dex/10) +(evo?db->emin.dex:0);
  7137. 	max = db->base.dex +lv*(db->gmax.dex/10) +(evo?db->emax.dex:0);;
  7138. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Dex: %d (%d~%d)", hom->dex/10, min, max);
  7139. 	clif_displaymessage(fd, atcmd_output);
  7140.  
  7141. 	min = db->base.luk +lv*(db->gmin.luk/10) +(evo?db->emin.luk:0);
  7142. 	max = db->base.luk +lv*(db->gmax.luk/10) +(evo?db->emax.luk:0);;
  7143. 	snprintf(atcmd_output, sizeof(atcmd_output) ,"Luk: %d (%d~%d)", hom->luk/10, min, max);
  7144. 	clif_displaymessage(fd, atcmd_output);
  7145.  
  7146. 	return 0;
  7147. }
  7148.  
  7149. ACMD_FUNC(homshuffle)
  7150. {
  7151. 	nullpo_retr(-1, sd);
  7152.  
  7153. 	if(!sd->hd)
  7154. 		return -1; // nothing to do
  7155.  
  7156. 	if(!merc_hom_shuffle(sd->hd))
  7157. 		return -1;
  7158.  
  7159. 	clif_displaymessage(sd->fd, "[Homunculus Stats Altered]");
  7160. 	atcommand_homstats(fd, sd, command, message); //Print out the new stats
  7161. 	return 0;
  7162. }
  7163.  
  7164. /*==========================================
  7165.  * Show Items DB Info   v 1.0
  7166.  * originally by [Lupus]
  7167.  *------------------------------------------*/
  7168. ACMD_FUNC(iteminfo)
  7169. {
  7170. 	struct item_data *item_data, *item_array[MAX_SEARCH];
  7171. 	int i, count = 1;
  7172.  
  7173. 	if (!message || !*message) {
  7174. 		clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @ii/@iteminfo <item name or ID>).");
  7175. 		return -1;
  7176. 	}
  7177. 	if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  7178. 		count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  7179.  
  7180. 	if (!count) {
  7181. 		clif_displaymessage(fd, msg_txt(19));	// Invalid item ID or name.
  7182. 		return -1;
  7183. 	}
  7184.  
  7185. 	if (count > MAX_SEARCH) {
  7186. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  7187. 		clif_displaymessage(fd, atcmd_output);
  7188. 		count = MAX_SEARCH;
  7189. 	}
  7190. 	for (i = 0; i < count; i++) {
  7191. 		item_data = item_array[i];
  7192. 		sprintf(atcmd_output, "Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s",
  7193. 			item_data->name,item_data->jname,item_data->slot,item_data->nameid,
  7194. 			itemdb_typename(item_data->type), 
  7195. 			(item_data->script==NULL)? "None" : "With script"
  7196. 		);
  7197. 		clif_displaymessage(fd, atcmd_output);
  7198.  
  7199. 		sprintf(atcmd_output, "NPC Buy:%dz, Sell:%dz | Weight: %.1f ", item_data->value_buy, item_data->value_sell, item_data->weight/10. );
  7200. 		clif_displaymessage(fd, atcmd_output);
  7201.  
  7202. 		if (item_data->maxchance == -1)
  7203. 			strcpy(atcmd_output, " - Available in the shops only.");
  7204. 		else if (!battle_config.atcommand_mobinfo_type && item_data->maxchance)
  7205. 			sprintf(atcmd_output, " - Maximal monsters drop chance: %02.02f%%", (float)item_data->maxchance / 100 );
  7206. 		else
  7207. 			strcpy(atcmd_output, " - Monsters don't drop this item.");
  7208. 		clif_displaymessage(fd, atcmd_output);
  7209.  
  7210. 	}
  7211. 	return 0;
  7212. }
  7213.  
  7214. /*==========================================
  7215.  * Show who drops the item.
  7216.  *------------------------------------------*/
  7217. ACMD_FUNC(whodrops)
  7218. {
  7219. 	struct item_data *item_data, *item_array[MAX_SEARCH];
  7220. 	int i,j, count = 1;
  7221.  
  7222. 	if (!message || !*message) {
  7223. 		clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @whodrops <item name or ID>).");
  7224. 		return -1;
  7225. 	}
  7226. 	if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  7227. 		count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  7228.  
  7229. 	if (!count) {
  7230. 		clif_displaymessage(fd, msg_txt(19));	// Invalid item ID or name.
  7231. 		return -1;
  7232. 	}
  7233.  
  7234. 	if (count > MAX_SEARCH) {
  7235. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  7236. 		clif_displaymessage(fd, atcmd_output);
  7237. 		count = MAX_SEARCH;
  7238. 	}
  7239. 	for (i = 0; i < count; i++) {
  7240. 		item_data = item_array[i];
  7241. 		sprintf(atcmd_output, "Item: '%s'[%d]", item_data->jname,item_data->slot);
  7242. 		clif_displaymessage(fd, atcmd_output);
  7243.  
  7244. 		if (item_data->mob[0].chance == 0) {
  7245. 			strcpy(atcmd_output, " - Item is not dropped by mobs.");
  7246. 			clif_displaymessage(fd, atcmd_output);
  7247. 		} else {
  7248. 			sprintf(atcmd_output, "- Common mobs with highest drop chance (only max %d are listed):", MAX_SEARCH);
  7249. 			clif_displaymessage(fd, atcmd_output);
  7250.  
  7251. 			for (j=0; j < MAX_SEARCH && item_data->mob[j].chance > 0; j++)
  7252. 			{
  7253. 				sprintf(atcmd_output, "- %s (%02.02f%%)", mob_db(item_data->mob[j].id)->jname, item_data->mob[j].chance/100.);
  7254. 				clif_displaymessage(fd, atcmd_output);
  7255. 			}
  7256. 		}
  7257. 	}
  7258. 	return 0;
  7259. }
  7260.  
  7261. ACMD_FUNC(whereis)
  7262. {
  7263. 	struct mob_db *mob, *mob_array[MAX_SEARCH];
  7264. 	int count;
  7265. 	int i, j, k;
  7266.  
  7267. 	if (!message || !*message) {
  7268. 		clif_displaymessage(fd, "Please, enter a Monster/ID (usage: @whereis<monster_name_or_monster_ID>).");
  7269. 		return -1;
  7270. 	}
  7271.  
  7272. 	// If monster identifier/name argument is a name
  7273. 	if ((i = mobdb_checkid(atoi(message))))
  7274. 	{
  7275. 		mob_array[0] = mob_db(i);
  7276. 		count = 1;
  7277. 	} else
  7278. 		count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  7279.  
  7280. 	if (!count) {
  7281. 		clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  7282. 		return -1;
  7283. 	}
  7284.  
  7285. 	if (count > MAX_SEARCH) {
  7286. 		sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count);
  7287. 		clif_displaymessage(fd, atcmd_output);
  7288. 		count = MAX_SEARCH;
  7289. 	}
  7290. 	for (k = 0; k < count; k++) {
  7291. 		mob = mob_array[k];
  7292. 		snprintf(atcmd_output, sizeof atcmd_output, "%s spawns in:", mob->jname);
  7293. 		clif_displaymessage(fd, atcmd_output);
  7294.  
  7295. 		for (i = 0; i < ARRAYLENGTH(mob->spawn) && mob->spawn[i].qty; i++)
  7296. 		{
  7297. 			j = map_mapindex2mapid(mob->spawn[i].mapindex);
  7298. 			if (j < 0) continue;
  7299. 			snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map[j].name, mob->spawn[i].qty);
  7300. 			clif_displaymessage(fd, atcmd_output);
  7301. 		}
  7302. 		if (i == 0)
  7303. 			clif_displaymessage(fd, "This monster does not spawn normally.");
  7304. 	}
  7305.  
  7306. 	return 0;
  7307. }
  7308.  
  7309. /*==========================================
  7310.  * @adopt by [Veider]
  7311.  * adopt a novice
  7312.  *------------------------------------------*/
  7313. ACMD_FUNC(adopt)
  7314. {
  7315. 	struct map_session_data *pl_sd1, *pl_sd2, *pl_sd3;
  7316. 	char player1[NAME_LENGTH], player2[NAME_LENGTH], player3[NAME_LENGTH];
  7317. 	char output[CHAT_SIZE_MAX];
  7318.  
  7319. 	nullpo_retr(-1, sd);
  7320.  
  7321. 	if (!message || !*message || sscanf(message, "%23[^,],%23[^,],%23[^\r\n]", player1, player2, player3) < 3) {
  7322. 		clif_displaymessage(fd, "usage: @adopt <father>,<mother>,<child>.");
  7323. 		return -1;
  7324. 	}
  7325.  
  7326. 	if (battle_config.etc_log)
  7327. 		ShowInfo("Adopting: --%s--%s--%s--\n",player1,player2,player3);
  7328.  
  7329. 	if((pl_sd1=map_nick2sd((char *) player1)) == NULL) {
  7330. 		sprintf(output, "Cannot find player %s online", player1);
  7331. 		clif_displaymessage(fd, output);
  7332. 		return -1;
  7333. 	}
  7334.  
  7335. 	if((pl_sd2=map_nick2sd((char *) player2)) == NULL) {
  7336. 		sprintf(output, "Cannot find player %s online", player2);
  7337. 		clif_displaymessage(fd, output);
  7338. 		return -1;
  7339. 	}
  7340.  
  7341. 	if((pl_sd3=map_nick2sd((char *) player3)) == NULL) {
  7342. 		sprintf(output, "Cannot find player %s online", player3);
  7343. 		clif_displaymessage(fd, output);
  7344. 		return -1;
  7345. 	}
  7346.  
  7347. 	if( !pc_adoption(pl_sd1, pl_sd2, pl_sd3) ) {
  7348. 		return -1;
  7349. 	}
  7350.  
  7351. 	clif_displaymessage(fd, "They are family... wish them luck");
  7352. 	return 0;
  7353. }
  7354.  
  7355. ACMD_FUNC(version)
  7356. {
  7357. 	const char * revision;
  7358.  
  7359. 	if ((revision = get_svn_revision()) != 0) {
  7360. 		sprintf(atcmd_output,"rAthena Version SVN r%s",revision);
  7361. 		clif_displaymessage(fd,atcmd_output);
  7362. 	} else 
  7363. 		clif_displaymessage(fd,"Cannot determine SVN revision");
  7364.  
  7365. 	return 0;
  7366. }
  7367.  
  7368. /*==========================================
  7369.  * @mutearea by MouseJstr
  7370.  *------------------------------------------*/
  7371. static int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
  7372. {
  7373.  
  7374. 	int time, id;
  7375. 	struct map_session_data *pl_sd = (struct map_session_data *)bl;
  7376. 	if (pl_sd == NULL)
  7377. 		return 0;
  7378.  
  7379. 	id = va_arg(ap, int);
  7380. 	time = va_arg(ap, int);
  7381.  
  7382. 	if (id != bl->id && !pc_get_group_level(pl_sd)) {
  7383. 		pl_sd->status.manner -= time;
  7384. 		if (pl_sd->status.manner < 0)
  7385. 			sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
  7386. 		else
  7387. 			status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  7388. 	}
  7389. 	return 0;
  7390. }
  7391.  
  7392. ACMD_FUNC(mutearea)
  7393. {
  7394. 	int time;
  7395. 	nullpo_ret(sd);
  7396.  
  7397. 	if (!message || !*message) {
  7398. 		clif_displaymessage(fd, "Please, enter a time in minutes (usage: @mutearea/@stfu <time in minutes>.");
  7399. 		return -1;
  7400. 	}
  7401.  
  7402. 	time = atoi(message);
  7403.  
  7404. 	map_foreachinarea(atcommand_mutearea_sub,sd->bl.m, 
  7405. 		sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, 
  7406. 		sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd->bl.id, time);
  7407.  
  7408. 	return 0;
  7409. }
  7410.  
  7411.  
  7412. ACMD_FUNC(rates)
  7413. {
  7414. 	char buf[CHAT_SIZE_MAX];
  7415.  
  7416. 	nullpo_ret(sd);
  7417. 	memset(buf, '\0', sizeof(buf));
  7418.  
  7419. 	snprintf(buf, CHAT_SIZE_MAX, "Experience rates: Base %.2fx / Job %.2fx",
  7420. 		battle_config.base_exp_rate/100., battle_config.job_exp_rate/100.);
  7421. 	clif_displaymessage(fd, buf);
  7422. 	snprintf(buf, CHAT_SIZE_MAX, "Normal Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx",
  7423. 		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.);
  7424. 	clif_displaymessage(fd, buf);
  7425. 	snprintf(buf, CHAT_SIZE_MAX, "Boss Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx",
  7426. 		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.);
  7427. 	clif_displaymessage(fd, buf);
  7428. 	snprintf(buf, CHAT_SIZE_MAX, "Other Drop Rates: MvP %.2fx / Card-Based %.2fx / Treasure %.2fx",
  7429. 		battle_config.item_rate_mvp/100., battle_config.item_rate_adddrop/100., battle_config.item_rate_treasure/100.);
  7430. 	clif_displaymessage(fd, buf);
  7431.  
  7432. 	return 0;
  7433. }
  7434.  
  7435. /*==========================================
  7436.  * @me by lordalfa
  7437.  * => Displays the OUTPUT string on top of the Visible players Heads.
  7438.  *------------------------------------------*/
  7439. ACMD_FUNC(me)
  7440. {
  7441. 	char tempmes[CHAT_SIZE_MAX];
  7442. 	nullpo_retr(-1, sd);
  7443.  
  7444. 	memset(tempmes, '\0', sizeof(tempmes));
  7445. 	memset(atcmd_output, '\0', sizeof(atcmd_output));
  7446.  
  7447. 	if (sd->sc.count && //no "chatting" while muted.
  7448. 		(sd->sc.data[SC_BERSERK] ||
  7449. 		(sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  7450. 		return -1;
  7451.  
  7452. 	if (!message || !*message || sscanf(message, "%199[^\n]", tempmes) < 0) {
  7453. 		clif_displaymessage(fd, "Please, enter a message (usage: @me <message>).");
  7454. 		return -1;
  7455. 	}
  7456.  
  7457. 	sprintf(atcmd_output, msg_txt(270), sd->status.name, tempmes);	// *%s %s*
  7458. 	clif_disp_overhead(sd, atcmd_output);
  7459.  
  7460. 	return 0;
  7461.  
  7462. }
  7463.  
  7464. /*==========================================
  7465.  * @size
  7466.  * => Resize your character sprite. [Valaris]
  7467.  *------------------------------------------*/
  7468. ACMD_FUNC(size)
  7469. {
  7470. 	int size=0;
  7471.  
  7472. 	nullpo_retr(-1, sd);
  7473.  
  7474. 	size = atoi(message);
  7475. 	if(sd->state.size) {
  7476. 		sd->state.size=0;
  7477. 		pc_setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_TELEPORT);
  7478. 	}
  7479.  
  7480. 	if(size==1) {
  7481. 		sd->state.size=1;
  7482. 		clif_specialeffect(&sd->bl,420,AREA);
  7483. 	} else if(size==2) {
  7484. 		sd->state.size=2;
  7485. 		clif_specialeffect(&sd->bl,422,AREA);
  7486. 	}
  7487.  
  7488. 	return 0;
  7489. }
  7490.  
  7491. /*==========================================
  7492.  * @monsterignore
  7493.  * => Makes monsters ignore you. [Valaris]
  7494.  *------------------------------------------*/
  7495. ACMD_FUNC(monsterignore)
  7496. {
  7497. 	nullpo_retr(-1, sd);
  7498.  
  7499. 	if (!sd->state.monster_ignore) {
  7500. 		sd->state.monster_ignore = 1;
  7501. 		clif_displaymessage(sd->fd, "You are now immune to attacks.");
  7502. 	} else {
  7503. 		sd->state.monster_ignore = 0;
  7504. 		clif_displaymessage(sd->fd, "Returned to normal state.");
  7505. 	}
  7506.  
  7507. 	return 0;
  7508. }
  7509. /*==========================================
  7510.  * @fakename
  7511.  * => Gives your character a fake name. [Valaris]
  7512.  *------------------------------------------*/
  7513. ACMD_FUNC(fakename)
  7514. {
  7515. 	nullpo_retr(-1, sd);
  7516.  
  7517. 	if( !message || !*message )
  7518. 	{
  7519. 		if( sd->fakename[0] )
  7520. 		{
  7521. 			sd->fakename[0] = '\0';
  7522. 			clif_charnameack(0, &sd->bl);
  7523. 			clif_displaymessage(sd->fd, "Returned to real name.");
  7524. 			return 0;
  7525. 		}
  7526.  
  7527. 		clif_displaymessage(sd->fd, "You must enter a name.");
  7528. 		return -1;
  7529. 	}
  7530.  
  7531. 	if( strlen(message) < 2 )
  7532. 	{
  7533. 		clif_displaymessage(sd->fd, "Fake name must be at least two characters.");
  7534. 		return -1;
  7535. 	}
  7536.  
  7537. 	safestrncpy(sd->fakename, message, sizeof(sd->fakename));
  7538. 	clif_charnameack(0, &sd->bl);
  7539. 	clif_displaymessage(sd->fd, "Fake name enabled.");
  7540.  
  7541. 	return 0;
  7542. }
  7543.  
  7544. /*==========================================
  7545.  * Ragnarok Resources
  7546.  *------------------------------------------*/
  7547. ACMD_FUNC(mapflag) {
  7548. #define checkflag( cmd ) if ( map[ sd->bl.m ].flag.cmd ) clif_displaymessage(sd->fd,#cmd)
  7549. #define setflag( cmd ) \
  7550. 	if ( strcmp( flag_name , #cmd ) == 0 && ( flag == 0 || flag == 1 ) ){\
  7551. 		map[ sd->bl.m ].flag.cmd = flag;\
  7552. 		sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s",#cmd,flag?"On":"Off");\
  7553. 		clif_displaymessage(sd->fd,atcmd_output);\
  7554. 		return 0;\
  7555. 	}
  7556. 	unsigned char flag_name[100];
  7557. 	int flag=9,i;
  7558. 	nullpo_retr(-1, sd);
  7559. 	memset(flag_name, '\0', sizeof(flag_name));
  7560.  
  7561. 	if (!message || !*message || (sscanf(message, "%99s %d", flag_name, &flag) < 1)) {
  7562. 		clif_displaymessage(sd->fd,"Enabled Mapflags in this map:");
  7563. 		clif_displaymessage(sd->fd,"----------------------------------");
  7564. 		checkflag(autotrade);			checkflag(allowks);				checkflag(nomemo);		checkflag(noteleport);
  7565. 		checkflag(noreturn);			checkflag(monster_noteleport);	checkflag(nosave);		checkflag(nobranch);
  7566. 		checkflag(noexppenalty);		checkflag(pvp);					checkflag(pvp_noparty);	checkflag(pvp_noguild);
  7567. 		checkflag(pvp_nightmaredrop);	checkflag(pvp_nocalcrank);		checkflag(gvg_castle);	checkflag(gvg);
  7568. 		checkflag(gvg_dungeon);			checkflag(gvg_noparty);			checkflag(battleground);checkflag(nozenypenalty);
  7569. 		checkflag(notrade);				checkflag(noskill);				checkflag(nowarp);		checkflag(nowarpto);
  7570. 		checkflag(noicewall);			checkflag(snow);				checkflag(clouds);		checkflag(clouds2);
  7571. 		checkflag(fog);					checkflag(fireworks);			checkflag(sakura);		checkflag(leaves);
  7572. 		checkflag(nogo);				checkflag(nobaseexp);
  7573. 		checkflag(nojobexp);			checkflag(nomobloot);			checkflag(nomvploot);	checkflag(nightenabled);
  7574. 		checkflag(restricted);			checkflag(nodrop);				checkflag(novending);	checkflag(loadevent);
  7575. 		checkflag(nochat);				checkflag(partylock);			checkflag(guildlock);	checkflag(src4instance);
  7576. 		clif_displaymessage(sd->fd," ");
  7577. 		clif_displaymessage(sd->fd,"Usage: \"@mapflag monster_teleport 1\" (0=Off 1=On)");
  7578. 		clif_displaymessage(sd->fd,"Use: \"@mapflag available\" to list the available mapflags");
  7579. 		return 1;
  7580. 	}
  7581. 	for (i = 0; flag_name[i]; i++) flag_name[i] = tolower(flag_name[i]); //lowercase
  7582.  
  7583. 	setflag(autotrade);			setflag(allowks);			setflag(nomemo);			setflag(noteleport);
  7584. 	setflag(noreturn);			setflag(monster_noteleport);setflag(nosave);			setflag(nobranch);
  7585. 	setflag(noexppenalty);		setflag(pvp);				setflag(pvp_noparty);		setflag(pvp_noguild);
  7586. 	setflag(pvp_nightmaredrop);	setflag(pvp_nocalcrank);	setflag(gvg_castle);		setflag(gvg);
  7587. 	setflag(gvg_dungeon);		setflag(gvg_noparty);		setflag(battleground);		setflag(nozenypenalty);
  7588. 	setflag(notrade);			setflag(noskill);			setflag(nowarp);			setflag(nowarpto);
  7589. 	setflag(noicewall);			setflag(snow);				setflag(clouds);			setflag(clouds2);
  7590. 	setflag(fog);				setflag(fireworks);			setflag(sakura);			setflag(leaves);
  7591. 	setflag(nogo);				setflag(nobaseexp);
  7592. 	setflag(nojobexp);			setflag(nomobloot);			setflag(nomvploot);			setflag(nightenabled);
  7593. 	setflag(restricted);		setflag(nodrop);			setflag(novending);			setflag(loadevent);
  7594. 	setflag(nochat);			setflag(partylock);			setflag(guildlock);			setflag(src4instance);
  7595.  
  7596. 	clif_displaymessage(sd->fd,"Invalid flag name or flag");
  7597. 	clif_displaymessage(sd->fd,"Usage: \"@mapflag monster_teleport 1\" (0=Off | 1=On)");
  7598. 	clif_displaymessage(sd->fd,"Available Flags:");
  7599. 	clif_displaymessage(sd->fd,"----------------------------------");
  7600. 	clif_displaymessage(sd->fd,"town, autotrade, allowks, nomemo, noteleport, noreturn, monster_noteleport, nosave,");
  7601. 	clif_displaymessage(sd->fd,"nobranch, noexppenalty, pvp, pvp_noparty, pvp_noguild, pvp_nightmaredrop,");
  7602. 	clif_displaymessage(sd->fd,"pvp_nocalcrank, gvg_castle, gvg, gvg_dungeon, gvg_noparty, battleground,");
  7603. 	clif_displaymessage(sd->fd,"nozenypenalty, notrade, noskill, nowarp, nowarpto, noicewall, snow, clouds, clouds2,");
  7604. 	clif_displaymessage(sd->fd,"fog, fireworks, sakura, leaves, nogo, nobaseexp, nojobexp, nomobloot,");
  7605. 	clif_displaymessage(sd->fd,"nomvploot, nightenabled, restricted, nodrop, novending, loadevent, nochat, partylock,");
  7606. 	clif_displaymessage(sd->fd,"guildlock, src4instance");
  7607.  
  7608. #undef checkflag
  7609. #undef setflag
  7610.  
  7611. 	return 0;
  7612. }
  7613.  
  7614. /*===================================
  7615.  * Remove some messages
  7616.  *-----------------------------------*/
  7617. ACMD_FUNC(showexp)
  7618. {
  7619. 	if (sd->state.showexp) {
  7620. 		sd->state.showexp = 0;
  7621. 		clif_displaymessage(fd, "Gained exp will not be shown.");
  7622. 		return 0;
  7623. 	}
  7624.  
  7625. 	sd->state.showexp = 1;
  7626. 	clif_displaymessage(fd, "Gained exp is now shown");
  7627. 	return 0;
  7628. }
  7629.  
  7630. ACMD_FUNC(showzeny)
  7631. {
  7632. 	if (sd->state.showzeny) {
  7633. 		sd->state.showzeny = 0;
  7634. 		clif_displaymessage(fd, "Gained zeny will not be shown.");
  7635. 		return 0;
  7636. 	}
  7637.  
  7638. 	sd->state.showzeny = 1;
  7639. 	clif_displaymessage(fd, "Gained zeny is now shown");
  7640. 	return 0;
  7641. }
  7642.  
  7643. ACMD_FUNC(showdelay)
  7644. {
  7645. 	if (sd->state.showdelay) {
  7646. 		sd->state.showdelay = 0;
  7647. 		clif_displaymessage(fd, "Skill delay failures won't be shown.");
  7648. 		return 0;
  7649. 	}
  7650.  
  7651. 	sd->state.showdelay = 1;
  7652. 	clif_displaymessage(fd, "Skill delay failures are shown now.");
  7653. 	return 0;
  7654. }
  7655.  
  7656. /*==========================================
  7657.  * Duel organizing functions [LuzZza]
  7658.  *
  7659.  * @duel [limit|nick] - create a duel
  7660.  * @invite <nick> - invite player
  7661.  * @accept - accept invitation
  7662.  * @reject - reject invitation
  7663.  * @leave - leave duel
  7664.  *------------------------------------------*/
  7665. ACMD_FUNC(invite)
  7666. {
  7667. 	unsigned int did = sd->duel_group;
  7668. 	struct map_session_data *target_sd = map_nick2sd((char *)message);
  7669.  
  7670. 	if(did <= 0)	{
  7671. 		// "Duel: @invite without @duel."
  7672. 		clif_displaymessage(fd, msg_txt(350));
  7673. 		return 0;
  7674. 	}
  7675.  
  7676. 	if(duel_list[did].max_players_limit > 0 &&
  7677. 		duel_list[did].members_count >= duel_list[did].max_players_limit) {
  7678.  
  7679. 		// "Duel: Limit of players is reached."
  7680. 		clif_displaymessage(fd, msg_txt(351));
  7681. 		return 0;
  7682. 	}
  7683.  
  7684. 	if(target_sd == NULL) {
  7685. 		// "Duel: Player not found."
  7686. 		clif_displaymessage(fd, msg_txt(352));
  7687. 		return 0;
  7688. 	}
  7689.  
  7690. 	if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  7691. 		// "Duel: Player already in duel."
  7692. 		clif_displaymessage(fd, msg_txt(353));
  7693. 		return 0;
  7694. 	}
  7695.  
  7696. 	if(battle_config.duel_only_on_same_map && target_sd->bl.m != sd->bl.m)
  7697. 	{
  7698. 		sprintf(atcmd_output, msg_txt(364), message);
  7699. 		clif_displaymessage(fd, atcmd_output);
  7700. 		return 0;
  7701. 	}
  7702.  
  7703. 	duel_invite(did, sd, target_sd);
  7704. 	// "Duel: Invitation has been sent."
  7705. 	clif_displaymessage(fd, msg_txt(354));
  7706. 	return 0;
  7707. }
  7708.  
  7709. ACMD_FUNC(duel)
  7710. {
  7711. 	char output[CHAT_SIZE_MAX];
  7712. 	unsigned int maxpl=0, newduel;
  7713. 	struct map_session_data *target_sd;
  7714.  
  7715. 	if(sd->duel_group > 0) {
  7716. 		duel_showinfo(sd->duel_group, sd);
  7717. 		return 0;
  7718. 	}
  7719.  
  7720. 	if(sd->duel_invite > 0) {
  7721. 		// "Duel: @duel without @reject."
  7722. 		clif_displaymessage(fd, msg_txt(355));
  7723. 		return 0;
  7724. 	}
  7725.  
  7726. 	if(!duel_checktime(sd)) {
  7727. 		// "Duel: You can take part in duel only one time per %d minutes."
  7728. 		sprintf(output, msg_txt(356), battle_config.duel_time_interval);
  7729. 		clif_displaymessage(fd, output);
  7730. 		return 0;
  7731. 	}
  7732.  
  7733. 	if( message[0] ) {
  7734. 		if(sscanf(message, "%d", &maxpl) >= 1) {
  7735. 			if(maxpl < 2 || maxpl > 65535) {
  7736. 				clif_displaymessage(fd, msg_txt(357)); // "Duel: Invalid value."
  7737. 				return 0;
  7738. 			}
  7739. 			duel_create(sd, maxpl);
  7740. 		} else {
  7741. 			target_sd = map_nick2sd((char *)message);
  7742. 			if(target_sd != NULL) {
  7743. 				if((newduel = duel_create(sd, 2)) != -1) {
  7744. 					if(target_sd->duel_group > 0 ||	target_sd->duel_invite > 0) {
  7745. 						clif_displaymessage(fd, msg_txt(353)); // "Duel: Player already in duel."
  7746. 						return 0;
  7747. 					}
  7748. 					duel_invite(newduel, sd, target_sd);
  7749. 					clif_displaymessage(fd, msg_txt(354)); // "Duel: Invitation has been sent."
  7750. 				}
  7751. 			} else {
  7752. 				// "Duel: Player not found."
  7753. 				clif_displaymessage(fd, msg_txt(352));
  7754. 				return 0;
  7755. 			}
  7756. 		}
  7757. 	} else
  7758. 		duel_create(sd, 0);
  7759.  
  7760. 	return 0;
  7761. }
  7762.  
  7763.  
  7764. ACMD_FUNC(leave)
  7765. {
  7766. 	if(sd->duel_group <= 0) {
  7767. 		// "Duel: @leave without @duel."
  7768. 		clif_displaymessage(fd, msg_txt(358));
  7769. 		return 0;
  7770. 	}
  7771.  
  7772. 	duel_leave(sd->duel_group, sd);
  7773. 	clif_displaymessage(fd, msg_txt(359)); // "Duel: You left the duel."
  7774. 	return 0;
  7775. }
  7776.  
  7777. ACMD_FUNC(accept)
  7778. {
  7779. 	char output[CHAT_SIZE_MAX];
  7780.  
  7781. 	if(!duel_checktime(sd)) {
  7782. 		// "Duel: You can take part in duel only one time per %d minutes."
  7783. 		sprintf(output, msg_txt(356), battle_config.duel_time_interval);
  7784. 		clif_displaymessage(fd, output);
  7785. 		return 0;
  7786. 	}
  7787.  
  7788. 	if(sd->duel_invite <= 0) {
  7789. 		// "Duel: @accept without invititation."
  7790. 		clif_displaymessage(fd, msg_txt(360));
  7791. 		return 0;
  7792. 	}
  7793.  
  7794. 	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 )
  7795. 	{
  7796. 		// "Duel: Limit of players is reached."
  7797. 		clif_displaymessage(fd, msg_txt(351));
  7798. 		return 0;
  7799. 	}
  7800.  
  7801. 	duel_accept(sd->duel_invite, sd);
  7802. 	// "Duel: Invitation has been accepted."
  7803. 	clif_displaymessage(fd, msg_txt(361));
  7804. 	return 0;
  7805. }
  7806.  
  7807. ACMD_FUNC(reject)
  7808. {
  7809. 	if(sd->duel_invite <= 0) {
  7810. 		// "Duel: @reject without invititation."
  7811. 		clif_displaymessage(fd, msg_txt(362));
  7812. 		return 0;
  7813. 	}
  7814.  
  7815. 	duel_reject(sd->duel_invite, sd);
  7816. 	// "Duel: Invitation has been rejected."
  7817. 	clif_displaymessage(fd, msg_txt(363));
  7818. 	return 0;
  7819. }
  7820.  
  7821. /*===================================
  7822.  * Cash Points
  7823.  *-----------------------------------*/
  7824. ACMD_FUNC(cash)
  7825. {
  7826. 	char output[128];
  7827. 	int value;
  7828. 	nullpo_retr(-1, sd);
  7829.  
  7830. 	if( !message || !*message || (value = atoi(message)) == 0 ) {
  7831. 		clif_displaymessage(fd, "Please, enter an amount.");
  7832. 		return -1;
  7833. 	}
  7834.  
  7835. 	if( !strcmpi(command+1,"cash") )
  7836. 	{
  7837. 		if( value > 0 ) {
  7838. 			pc_getcash(sd, value, 0);
  7839. 			sprintf(output, msg_txt(505), value, sd->cashPoints);
  7840. 			clif_disp_onlyself(sd, output, strlen(output));
  7841. 		} else {
  7842. 			pc_paycash(sd, -value, 0);
  7843. 			sprintf(output, msg_txt(410), value, sd->cashPoints);
  7844. 			clif_disp_onlyself(sd, output, strlen(output));
  7845. 		}
  7846. 	}
  7847. 	else
  7848. 	{ // @points
  7849. 		if( value > 0 ) {
  7850. 			pc_getcash(sd, 0, value);
  7851. 			sprintf(output, msg_txt(506), value, sd->kafraPoints);
  7852. 			clif_disp_onlyself(sd, output, strlen(output));
  7853. 		} else {
  7854. 			pc_paycash(sd, -value, -value);
  7855. 			sprintf(output, msg_txt(411), -value, sd->kafraPoints);
  7856. 			clif_disp_onlyself(sd, output, strlen(output));
  7857. 		}
  7858. 	}
  7859.  
  7860. 	return 0;
  7861. }
  7862.  
  7863. // @clone/@slaveclone/@evilclone <playername> [Valaris]
  7864. ACMD_FUNC(clone)
  7865. {
  7866. 	int x=0,y=0,flag=0,master=0,i=0;
  7867. 	struct map_session_data *pl_sd=NULL;
  7868.  
  7869. 	if (!message || !*message) {
  7870. 		clif_displaymessage(sd->fd,"You must enter a name or character ID.");
  7871. 		return 0;
  7872. 	}
  7873.  
  7874. 	if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL) {
  7875. 		clif_displaymessage(fd, msg_txt(3));	// Character not found.
  7876. 		return 0;
  7877. 	}
  7878.  
  7879. 	if(pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  7880. 		clif_displaymessage(fd, msg_txt(126));	// Cannot clone a player of higher GM level than yourself.
  7881. 		return 0;
  7882. 	}
  7883.  
  7884. 	if (strcmpi(command+1, "clone") == 0) 
  7885. 		flag = 1;
  7886. 	else if (strcmpi(command+1, "slaveclone") == 0) {
  7887. 	  	flag = 2;
  7888. 		master = sd->bl.id;
  7889. 		if (battle_config.atc_slave_clone_limit
  7890. 			&& mob_countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
  7891. 			clif_displaymessage(fd, msg_txt(127));	// You've reached your slave clones limit.
  7892. 			return 0;
  7893. 		}
  7894. 	}
  7895.  
  7896. 	do {
  7897. 		x = sd->bl.x + (rnd() % 10 - 5);
  7898. 		y = sd->bl.y + (rnd() % 10 - 5);
  7899. 	} while (map_getcell(sd->bl.m,x,y,CELL_CHKNOPASS) && i++ < 10);
  7900.  
  7901. 	if (i >= 10) {
  7902. 		x = sd->bl.x;
  7903. 		y = sd->bl.y;
  7904. 	}
  7905.  
  7906. 	if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
  7907. 		clif_displaymessage(fd, msg_txt(128+flag*2));	// Evil Clone spawned. Clone spawned. Slave clone spawned.
  7908. 		return 0;
  7909. 	}
  7910. 	clif_displaymessage(fd, msg_txt(129+flag*2));	// Unable to spawn evil clone. Unable to spawn clone. Unable to spawn slave clone.
  7911. 	return 0;
  7912. }
  7913.  
  7914. /*===================================
  7915.  * Main chat [LuzZza]
  7916.  * Usage: @main <on|off|message>
  7917.  *-----------------------------------*/
  7918. ACMD_FUNC(main)
  7919. {
  7920. 	if( message[0] ) {
  7921.  
  7922. 		if(strcmpi(message, "on") == 0) {
  7923. 			if(!sd->state.mainchat) {
  7924. 				sd->state.mainchat = 1;
  7925. 				clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  7926. 			} else {
  7927. 				clif_displaymessage(fd, msg_txt(381)); // Main chat already activated.
  7928. 			}
  7929. 		} else if(strcmpi(message, "off") == 0) {
  7930. 			if(sd->state.mainchat) {
  7931. 				sd->state.mainchat = 0;
  7932. 				clif_displaymessage(fd, msg_txt(382)); // Main chat has been disabled.
  7933. 			} else {
  7934. 				clif_displaymessage(fd, msg_txt(383)); // Main chat already disabled.
  7935. 			}
  7936. 		} else {
  7937. 			if(!sd->state.mainchat) {
  7938. 				sd->state.mainchat = 1;
  7939. 				clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  7940. 			}
  7941. 			if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) {
  7942. 				clif_displaymessage(fd, msg_txt(387));
  7943. 				return -1;
  7944. 			}
  7945.  
  7946. 			// send the message using inter-server system
  7947. 			intif_main_message( sd, message );
  7948. 		}
  7949.  
  7950. 	} else {
  7951.  
  7952. 		if(sd->state.mainchat) 
  7953. 			clif_displaymessage(fd, msg_txt(384)); // Main chat currently enabled. Usage: @main <on|off>, @main <message>.
  7954. 		else
  7955. 			clif_displaymessage(fd, msg_txt(385)); // Main chat currently disabled. Usage: @main <on|off>, @main <message>.
  7956. 	}
  7957. 	return 0;
  7958. }
  7959.  
  7960. /*=====================================
  7961.  * Autorejecting Invites/Deals [LuzZza]
  7962.  * Usage: @noask
  7963.  *-------------------------------------*/
  7964. ACMD_FUNC(noask)
  7965. {
  7966. 	if(sd->state.noask) {
  7967. 		clif_displaymessage(fd, msg_txt(391)); // Autorejecting is deactivated.
  7968. 		sd->state.noask = 0;
  7969. 	} else {
  7970. 		clif_displaymessage(fd, msg_txt(390)); // Autorejecting is activated.
  7971. 		sd->state.noask = 1;
  7972. 	}
  7973.  
  7974. 	return 0;
  7975. }
  7976.  
  7977. /*=====================================
  7978.  * Send a @request message to all GMs of lowest_gm_level.
  7979.  * Usage: @request <petition>
  7980.  *-------------------------------------*/
  7981. ACMD_FUNC(request)
  7982. {
  7983. 	if (!message || !*message) {
  7984. 		clif_displaymessage(sd->fd,msg_txt(277));	// Usage: @request <petition/message to online GMs>.
  7985. 		return -1;
  7986. 	}
  7987.  
  7988. 	sprintf(atcmd_output, msg_txt(278), message);	// (@request): %s
  7989. 	intif_wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output);
  7990. 	clif_disp_onlyself(sd, atcmd_output, strlen(atcmd_output));
  7991. 	clif_displaymessage(sd->fd,msg_txt(279));	// @request sent.
  7992. 	return 0;
  7993. }
  7994.  
  7995. /*==========================================
  7996.  * Feel (SG save map) Reset [HiddenDragon]
  7997.  *------------------------------------------*/
  7998. ACMD_FUNC(feelreset)
  7999. {
  8000. 	pc_resetfeel(sd);
  8001. 	clif_displaymessage(fd, "Reset 'Feeling' maps.");
  8002.  
  8003. 	return 0;
  8004. }
  8005.  
  8006. /*==========================================
  8007.  * AUCTION SYSTEM
  8008.  *------------------------------------------*/
  8009. ACMD_FUNC(auction)
  8010. {
  8011. 	nullpo_ret(sd);
  8012.  
  8013. 	clif_Auction_openwindow(sd);
  8014.  
  8015. 	return 0;
  8016. }
  8017.  
  8018. /*==========================================
  8019.  * Kill Steal Protection
  8020.  *------------------------------------------*/
  8021. ACMD_FUNC(ksprotection)
  8022. {
  8023. 	nullpo_retr(-1,sd);
  8024.  
  8025. 	if( sd->state.noks ) {
  8026. 		sd->state.noks = 0;
  8027. 		sprintf(atcmd_output, "[ K.S Protection Inactive ]");
  8028. 	}
  8029. 	else
  8030. 	{
  8031. 		if( !message || !*message || !strcmpi(message, "party") )
  8032. 		{ // Default is Party
  8033. 			sd->state.noks = 2;
  8034. 			sprintf(atcmd_output, "[ K.S Protection Active - Option: Party ]");
  8035. 		}
  8036. 		else if( !strcmpi(message, "self") )
  8037. 		{
  8038. 			sd->state.noks = 1;
  8039. 			sprintf(atcmd_output, "[ K.S Protection Active - Option: Self ]");
  8040. 		}
  8041. 		else if( !strcmpi(message, "guild") )
  8042. 		{
  8043. 			sd->state.noks = 3;
  8044. 			sprintf(atcmd_output, "[ K.S Protection Active - Option: Guild ]");
  8045. 		}
  8046. 		else
  8047. 			sprintf(atcmd_output, "Usage: @noks <self|party|guild>");
  8048. 	}
  8049.  
  8050. 	clif_displaymessage(fd, atcmd_output);
  8051. 	return 0;
  8052. }
  8053. /*==========================================
  8054.  * Map Kill Steal Protection Setting
  8055.  *------------------------------------------*/
  8056. ACMD_FUNC(allowks)
  8057. {
  8058. 	nullpo_retr(-1,sd);
  8059.  
  8060. 	if( map[sd->bl.m].flag.allowks ) {
  8061. 		map[sd->bl.m].flag.allowks = 0;
  8062. 		sprintf(atcmd_output, "[ Map K.S Protection Active ]");
  8063. 	} else {
  8064. 		map[sd->bl.m].flag.allowks = 1;
  8065. 		sprintf(atcmd_output, "[ Map K.S Protection Inactive ]");
  8066. 	}
  8067.  
  8068. 	clif_displaymessage(fd, atcmd_output);
  8069. 	return 0;
  8070. }
  8071.  
  8072. ACMD_FUNC(resetstat)
  8073. {
  8074. 	nullpo_retr(-1, sd);
  8075.  
  8076. 	pc_resetstate(sd);
  8077. 	sprintf(atcmd_output, msg_txt(207), sd->status.name);
  8078. 	clif_displaymessage(fd, atcmd_output);
  8079. 	return 0;
  8080. }
  8081.  
  8082. ACMD_FUNC(resetskill)
  8083. {
  8084. 	nullpo_retr(-1,sd);
  8085.  
  8086. 	pc_resetskill(sd,1);
  8087. 	sprintf(atcmd_output, msg_txt(206), sd->status.name);
  8088. 	clif_displaymessage(fd, atcmd_output);
  8089. 	return 0;
  8090. }
  8091.  
  8092. /*==========================================
  8093.  * #storagelist: Displays the items list of a player's storage.
  8094.  * #cartlist: Displays contents of target's cart.
  8095.  * #itemlist: Displays contents of target's inventory.
  8096.  *------------------------------------------*/
  8097. ACMD_FUNC(itemlist)
  8098. {
  8099. 	int i, j, count, counter;
  8100. 	const char* location;
  8101. 	const struct item* items;
  8102. 	int size;
  8103. 	StringBuf buf;
  8104.  
  8105. 	nullpo_retr(-1, sd);
  8106.  
  8107. 	if( strcmp(command+1, "storagelist") == 0 )
  8108. 	{
  8109. 		location = "storage";
  8110. 		items = sd->status.storage.items;
  8111. 		size = MAX_STORAGE;
  8112. 	}
  8113. 	else
  8114. 	if( strcmp(command+1, "cartlist") == 0 )
  8115. 	{
  8116. 		location = "cart";
  8117. 		items = sd->status.cart;
  8118. 		size = MAX_CART;
  8119. 	}
  8120. 	else
  8121. 	if( strcmp(command+1, "itemlist") == 0 )
  8122. 	{
  8123. 		location = "inventory";
  8124. 		items = sd->status.inventory;
  8125. 		size = MAX_INVENTORY;
  8126. 	}
  8127. 	else
  8128. 		return 1;
  8129.  
  8130. 	StringBuf_Init(&buf);
  8131.  
  8132. 	count = 0; // total slots occupied
  8133. 	counter = 0; // total items found
  8134. 	for( i = 0; i < size; ++i )
  8135. 	{
  8136. 		const struct item* it = &items[i];
  8137. 		struct item_data* itd;
  8138.  
  8139. 		if( it->nameid == 0 || (itd = itemdb_exists(it->nameid)) == NULL )
  8140. 			continue;
  8141.  
  8142. 		counter += it->amount;
  8143. 		count++;
  8144.  
  8145. 		if( count == 1 )
  8146. 		{
  8147. 			StringBuf_Printf(&buf, "------ %s items list of '%s' ------", location, sd->status.name);
  8148. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  8149. 			StringBuf_Clear(&buf);
  8150. 		}
  8151.  
  8152. 		if( it->refine )
  8153. 			StringBuf_Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid);
  8154. 		else
  8155. 			StringBuf_Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid);
  8156.  
  8157. 		if( it->equip )
  8158. 		{
  8159. 			char equipstr[CHAT_SIZE_MAX];
  8160. 			strcpy(equipstr, " | equipped: ");
  8161. 			if( it->equip & EQP_GARMENT )
  8162. 				strcat(equipstr, "garment, ");
  8163. 			if( it->equip & EQP_ACC_L )
  8164. 				strcat(equipstr, "left accessory, ");
  8165. 			if( it->equip & EQP_ARMOR )
  8166. 				strcat(equipstr, "body/armor, ");
  8167. 			if( (it->equip & EQP_ARMS) == EQP_HAND_R )
  8168. 				strcat(equipstr, "right hand, ");
  8169. 			if( (it->equip & EQP_ARMS) == EQP_HAND_L )
  8170. 				strcat(equipstr, "left hand, ");
  8171. 			if( (it->equip & EQP_ARMS) == EQP_ARMS )
  8172. 				strcat(equipstr, "both hands, ");
  8173. 			if( it->equip & EQP_SHOES )
  8174. 				strcat(equipstr, "feet, ");
  8175. 			if( it->equip & EQP_ACC_R )
  8176. 				strcat(equipstr, "right accessory, ");
  8177. 			if( (it->equip & EQP_HELM) == EQP_HEAD_LOW )
  8178. 				strcat(equipstr, "lower head, ");
  8179. 			if( (it->equip & EQP_HELM) == EQP_HEAD_TOP )
  8180. 				strcat(equipstr, "top head, ");
  8181. 			if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_TOP) )
  8182. 				strcat(equipstr, "lower/top head, ");
  8183. 			if( (it->equip & EQP_HELM) == EQP_HEAD_MID )
  8184. 				strcat(equipstr, "mid head, ");
  8185. 			if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_MID) )
  8186. 				strcat(equipstr, "lower/mid head, ");
  8187. 			if( (it->equip & EQP_HELM) == EQP_HELM )
  8188. 				strcat(equipstr, "lower/mid/top head, ");
  8189. 			// remove final ', '
  8190. 			equipstr[strlen(equipstr) - 2] = '\0';
  8191. 			StringBuf_AppendStr(&buf, equipstr);
  8192. 		}
  8193.  
  8194. 		clif_displaymessage(fd, StringBuf_Value(&buf));
  8195. 		StringBuf_Clear(&buf);
  8196.  
  8197. 		if( it->card[0] == CARD0_PET )
  8198. 		{// pet egg
  8199. 			if (it->card[3])
  8200. 				StringBuf_Printf(&buf, " -> (pet egg, pet id: %u, named)", (unsigned int)MakeDWord(it->card[1], it->card[2]));
  8201. 			else
  8202. 				StringBuf_Printf(&buf, " -> (pet egg, pet id: %u, unnamed)", (unsigned int)MakeDWord(it->card[1], it->card[2]));
  8203. 		}
  8204. 		else
  8205. 		if(it->card[0] == CARD0_FORGE)
  8206. 		{// forged item
  8207. 			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);
  8208. 		}
  8209. 		else
  8210. 		if(it->card[0] == CARD0_CREATE)
  8211. 		{// created item
  8212. 			StringBuf_Printf(&buf, " -> (produced item, creator id: %u)", (unsigned int)MakeDWord(it->card[2], it->card[3]));
  8213. 		}
  8214. 		else
  8215. 		{// normal item
  8216. 			int counter2 = 0;
  8217.  
  8218. 			for( j = 0; j < itd->slot; ++j )
  8219. 			{
  8220. 				struct item_data* card;
  8221.  
  8222. 				if( it->card[j] == 0 || (card = itemdb_exists(it->card[j])) == NULL )
  8223. 					continue;
  8224.  
  8225. 				counter2++;
  8226.  
  8227. 				if( counter2 == 1 )
  8228. 					StringBuf_AppendStr(&buf, " -> (card(s): ");
  8229.  
  8230. 				if( counter2 != 1 )
  8231. 					StringBuf_AppendStr(&buf, ", ");
  8232.  
  8233. 				StringBuf_Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid);
  8234. 			}
  8235.  
  8236. 			if( counter2 > 0 )
  8237. 				StringBuf_AppendStr(&buf, ")");
  8238. 		}
  8239.  
  8240. 		if( StringBuf_Length(&buf) > 0 )
  8241. 			clif_displaymessage(fd, StringBuf_Value(&buf));
  8242.  
  8243. 		StringBuf_Clear(&buf);
  8244. 	}
  8245.  
  8246. 	if( count == 0 )
  8247. 		StringBuf_Printf(&buf, "No item found in this player's %s.", location);
  8248. 	else
  8249. 		StringBuf_Printf(&buf, "%d item(s) found in %d %s slots.", counter, count, location);
  8250.  
  8251. 	clif_displaymessage(fd, StringBuf_Value(&buf));
  8252.  
  8253. 	StringBuf_Destroy(&buf);
  8254.  
  8255. 	return 0;
  8256. }
  8257.  
  8258. ACMD_FUNC(stats)
  8259. {
  8260. 	char job_jobname[100];
  8261. 	char output[CHAT_SIZE_MAX];
  8262. 	int i;
  8263. 	struct {
  8264. 		const char* format;
  8265. 		int value;
  8266. 	} output_table[] = {
  8267. 		{ "Base Level - %d", 0 },
  8268. 		{ NULL, 0 },
  8269. 		{ "Hp - %d", 0 },
  8270. 		{ "MaxHp - %d", 0 },
  8271. 		{ "Sp - %d", 0 },
  8272. 		{ "MaxSp - %d", 0 },
  8273. 		{ "Str - %3d", 0 },
  8274. 		{ "Agi - %3d", 0 },
  8275. 		{ "Vit - %3d", 0 },
  8276. 		{ "Int - %3d", 0 },
  8277. 		{ "Dex - %3d", 0 },
  8278. 		{ "Luk - %3d", 0 },
  8279. 		{ "Zeny - %d", 0 },
  8280. 		{ "Free SK Points - %d", 0 },
  8281. 		{ "JobChangeLvl (2nd) - %d", 0 },
  8282. 		{ "JobChangeLvl (3rd) - %d", 0 },
  8283. 		{ NULL, 0 }
  8284. 	};
  8285.  
  8286. 	memset(job_jobname, '\0', sizeof(job_jobname));
  8287. 	memset(output, '\0', sizeof(output));
  8288.  
  8289. 	//direct array initialization with variables is not standard C compliant.
  8290. 	output_table[0].value = sd->status.base_level;
  8291. 	output_table[1].format = job_jobname;
  8292. 	output_table[1].value = sd->status.job_level;
  8293. 	output_table[2].value = sd->status.hp;
  8294. 	output_table[3].value = sd->status.max_hp;
  8295. 	output_table[4].value = sd->status.sp;
  8296. 	output_table[5].value = sd->status.max_sp;
  8297. 	output_table[6].value = sd->status.str;
  8298. 	output_table[7].value = sd->status.agi;
  8299. 	output_table[8].value = sd->status.vit;
  8300. 	output_table[9].value = sd->status.int_;
  8301. 	output_table[10].value = sd->status.dex;
  8302. 	output_table[11].value = sd->status.luk;
  8303. 	output_table[12].value = sd->status.zeny;
  8304. 	output_table[13].value = sd->status.skill_point;
  8305. 	output_table[14].value = sd->change_level_2nd;
  8306. 	output_table[15].value = sd->change_level_3rd;
  8307.  
  8308. 	sprintf(job_jobname, "Job - %s %s", job_name(sd->status.class_), "(level %d)");
  8309. 	sprintf(output, msg_txt(53), sd->status.name); // '%s' stats:
  8310.  
  8311. 	clif_displaymessage(fd, output);
  8312.  
  8313. 	for (i = 0; output_table[i].format != NULL; i++) {
  8314. 		sprintf(output, output_table[i].format, output_table[i].value);
  8315. 		clif_displaymessage(fd, output);
  8316. 	}
  8317.  
  8318. 	return 0;
  8319. }
  8320.  
  8321. ACMD_FUNC(delitem)
  8322. {
  8323. 	char item_name[100];
  8324. 	int nameid, amount = 0, total, idx;
  8325. 	struct item_data* id;
  8326.  
  8327. 	nullpo_retr(-1, sd);
  8328.  
  8329. 	if( !message || !*message || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &amount) < 2 && sscanf(message, "%99s %d", item_name, &amount) < 2 ) || amount < 1 )
  8330. 	{
  8331. 		clif_displaymessage(fd, "Please, enter an item name/id, a quantity and a player name (usage: #delitem <player> <item_name_or_ID> <quantity>).");
  8332. 		return -1;
  8333. 	}
  8334.  
  8335. 	if( ( id = itemdb_searchname(item_name) ) != NULL || ( id = itemdb_exists(atoi(item_name)) ) != NULL )
  8336. 	{
  8337. 		nameid = id->nameid;
  8338. 	}
  8339. 	else
  8340. 	{
  8341. 		clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  8342. 		return -1;
  8343. 	}
  8344.  
  8345. 	total = amount;
  8346.  
  8347. 	// delete items
  8348. 	while( amount && ( idx = pc_search_inventory(sd, nameid) ) != -1 )
  8349. 	{
  8350. 		int delamount = ( amount < sd->status.inventory[idx].amount ) ? amount : sd->status.inventory[idx].amount;
  8351.  
  8352. 		if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET )
  8353. 		{// delete pet
  8354. 			intif_delete_petdata(MakeDWord(sd->status.inventory[idx].card[1], sd->status.inventory[idx].card[2]));
  8355. 		}
  8356. 		pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_COMMAND);
  8357.  
  8358. 		amount-= delamount;
  8359. 	}
  8360.  
  8361. 	// notify target
  8362. 	sprintf(atcmd_output, msg_txt(113), total-amount); // %d item(s) removed by a GM.
  8363. 	clif_displaymessage(sd->fd, atcmd_output);
  8364.  
  8365. 	// notify source
  8366. 	if( amount == total )
  8367. 	{
  8368. 		clif_displaymessage(fd, msg_txt(116)); // Character does not have the item.
  8369. 	}
  8370. 	else if( amount )
  8371. 	{
  8372. 		sprintf(atcmd_output, msg_txt(115), total-amount, total-amount, total); // %d item(s) removed. Player had only %d on %d items.
  8373. 		clif_displaymessage(fd, atcmd_output);
  8374. 	}
  8375. 	else
  8376. 	{
  8377. 		sprintf(atcmd_output, msg_txt(114), total); // %d item(s) removed from the player.
  8378. 		clif_displaymessage(fd, atcmd_output);
  8379. 	}
  8380.  
  8381. 	return 0;
  8382. }
  8383.  
  8384. /*==========================================
  8385.  * Custom Fonts
  8386.  *------------------------------------------*/
  8387. ACMD_FUNC(font)
  8388. {
  8389. 	int font_id;
  8390. 	nullpo_retr(-1,sd);
  8391.  
  8392. 	font_id = atoi(message);
  8393. 	if( font_id == 0 )
  8394. 	{
  8395. 		if( sd->user_font )
  8396. 		{
  8397. 			sd->user_font = 0;
  8398. 			clif_displaymessage(fd, "Returning to normal font.");
  8399. 			clif_font(sd);
  8400. 		}
  8401. 		else
  8402. 		{
  8403. 			clif_displaymessage(fd, "Use @font <1..9> to change your messages font.");
  8404. 			clif_displaymessage(fd, "Use 0 or no parameter to back to normal font.");
  8405. 		}
  8406. 	}
  8407. 	else if( font_id < 0 || font_id > 9 )
  8408. 		clif_displaymessage(fd, "Invalid font. Use a Value from 0 to 9.");
  8409. 	else if( font_id != sd->user_font )
  8410. 	{
  8411. 		sd->user_font = font_id;
  8412. 		clif_font(sd);
  8413. 		clif_displaymessage(fd, "Font changed.");
  8414. 	}
  8415. 	else
  8416. 		clif_displaymessage(fd, "Already using this font.");
  8417.  
  8418. 	return 0;
  8419. }
  8420.  
  8421. /*==========================================
  8422. * @whosell - List who is vending the item (amount, price, and location).
  8423. * revamped by VoidLess, original by zephyrus_cr
  8424. *------------------------------------------*/
  8425. ACMD_FUNC(whosell)
  8426. {
  8427. 	char item_name[100];
  8428. 	int item_id = 0, j, count = 0, sat_num = 0;
  8429. 	int s_type = 1; // search bitmask: 0-name,1-id, 2-card, 4-refine
  8430. 	int refine = 0,card_id = 0;
  8431. 	bool flag = 0; // place dot on the minimap?
  8432. 	struct map_session_data* pl_sd;
  8433. 	struct s_mapiterator* iter;
  8434. 	unsigned int MinPrice = battle_config.vending_max_value, MaxPrice = 0;
  8435. 	struct item_data *item_data;
  8436. 	nullpo_retr(-1, sd);
  8437. 	if (!message || !*message) {
  8438. 		clif_displaymessage(fd, "Use: @whosell (<+refine> )(<item_id>)(<[card_id]>) or @whosell <name>");
  8439. 		return -1;
  8440. 	}
  8441. 	if (sscanf(message, "+%d %d[%d]", &refine, &item_id, &card_id) == 3){
  8442. 		s_type = 1+2+4;
  8443. 	}
  8444. 	else if (sscanf(message, "+%d %d", &refine, &item_id) == 2){
  8445. 		s_type = 1+4;
  8446. 	}
  8447. 	else if (sscanf(message, "+%d [%d]", &refine, &card_id) == 2){
  8448. 		s_type = 2+4;
  8449. 	}
  8450. 	else if (sscanf(message, "%d[%d]", &item_id, &card_id) == 2){
  8451. 		s_type = 1+2;
  8452. 	}
  8453. 	else if (sscanf(message, "[%d]", &card_id) == 1){
  8454. 		s_type = 2;
  8455. 	}
  8456. 	else if (sscanf(message, "+%d", &refine) == 1){
  8457. 		s_type = 4;
  8458. 	}
  8459. 	else if (sscanf(message, "%d", &item_id) == 1 && item_id == atoi(message)){
  8460. 	//names, that start on num are not working
  8461. 	//so implemented minumum item_id>500
  8462. 	//or better make item_id == atoi(message) ?
  8463. 		s_type = 1;
  8464. 	}
  8465. 	else if (sscanf(message, "%99[^\n]", item_name) == 1){
  8466. 		s_type = 1;
  8467. 		if ((item_data = itemdb_searchname(item_name)) == NULL){
  8468. 			clif_displaymessage(fd, "Not found item with this name");
  8469. 			return -1;
  8470. 		}
  8471. 		item_id = item_data->nameid;
  8472. 	}
  8473. 	else {
  8474. 		clif_displaymessage(fd, "Use: @whosell (<+refine> )(<item_id>)(<[card_id]>) or @whosell <name>");
  8475. 		return -1;
  8476. 	}
  8477.  
  8478. 	//check card
  8479. 	if(s_type & 2 && ((item_data = itemdb_exists(card_id)) == NULL || item_data->type != IT_CARD)){
  8480. 		clif_displaymessage(fd, "Not found a card with than ID");
  8481. 		return -1;
  8482. 	}
  8483. 	//check item
  8484. 	if(s_type & 1 && (item_data = itemdb_exists(item_id)) == NULL){
  8485. 		clif_displaymessage(fd, "Not found an item with than ID");
  8486. 		return -1;
  8487. 	}
  8488. 	//check refine
  8489. 	if(s_type & 4){
  8490. 		if (refine<0 || refine>10){
  8491. 			clif_displaymessage(fd, "Refine out of bounds: 0 - 10");
  8492. 			return -1;
  8493. 		}
  8494. 		/*if(item_data->type != IT_WEAPON && item_data->type != IT_ARMOR){
  8495. 			clif_displaymessage(fd, "Use refine only with weapon or armor");
  8496. 			return -1;
  8497. 		}*/
  8498. 	}
  8499. 	iter = mapit_getallusers();
  8500. 	for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  8501. 	{
  8502. 		if( pl_sd->vender_id ) //check if player is vending
  8503. 		{
  8504. 			for (j = 0; j < pl_sd->vend_num; j++) {
  8505. 				if((item_data = itemdb_exists(pl_sd->status.cart[pl_sd->vending[j].index].nameid)) == NULL)
  8506. 					continue;
  8507. 				if(s_type & 1 && pl_sd->status.cart[pl_sd->vending[j].index].nameid != item_id)
  8508. 					continue;
  8509. 				if(s_type & 2 && ((item_data->type != IT_ARMOR && item_data->type != IT_WEAPON) ||
  8510. 								(pl_sd->status.cart[pl_sd->vending[j].index].card[0] != card_id &&
  8511. 								pl_sd->status.cart[pl_sd->vending[j].index].card[1] != card_id &&
  8512. 								pl_sd->status.cart[pl_sd->vending[j].index].card[2] != card_id &&
  8513. 								pl_sd->status.cart[pl_sd->vending[j].index].card[3] != card_id)))
  8514. 					continue;
  8515. 				if(s_type & 4 && ((item_data->type != IT_ARMOR && item_data->type != IT_WEAPON) || pl_sd->status.cart[pl_sd->vending[j].index].refine != refine))
  8516. 					continue;
  8517. 				if(item_data->type == IT_ARMOR)
  8518. 					snprintf(atcmd_output, CHAT_SIZE_MAX, "+%d %d[%d] | Price %d | Amount %d | Map %s[%d,%d] | Seller %s",pl_sd->status.cart[pl_sd->vending[j].index].refine
  8519. 							,pl_sd->status.cart[pl_sd->vending[j].index].nameid
  8520. 							,pl_sd->status.cart[pl_sd->vending[j].index].card[0]
  8521. 							,pl_sd->vending[j].value
  8522. 							,pl_sd->vending[j].amount
  8523. 							,mapindex_id2name(pl_sd->mapindex)
  8524. 							,pl_sd->bl.x,pl_sd->bl.y
  8525. 							,pl_sd->status.name);
  8526. 				else if(item_data->type == IT_WEAPON)
  8527. 					snprintf(atcmd_output, CHAT_SIZE_MAX, "+%d %d[%d,%d,%d,%d] | Price %d | Amount %d | Map %s[%d,%d] | Seller %s",pl_sd->status.cart[pl_sd->vending[j].index].refine
  8528. 							,pl_sd->status.cart[pl_sd->vending[j].index].nameid
  8529. 							,pl_sd->status.cart[pl_sd->vending[j].index].card[0]
  8530. 							,pl_sd->status.cart[pl_sd->vending[j].index].card[1]
  8531. 							,pl_sd->status.cart[pl_sd->vending[j].index].card[2]
  8532. 							,pl_sd->status.cart[pl_sd->vending[j].index].card[3]
  8533. 							,pl_sd->vending[j].value
  8534. 							,pl_sd->vending[j].amount
  8535. 							,mapindex_id2name(pl_sd->mapindex)
  8536. 							,pl_sd->bl.x,pl_sd->bl.y
  8537. 							,pl_sd->status.name);
  8538. 				else
  8539. 					snprintf(atcmd_output, CHAT_SIZE_MAX, "ID %d | Price %d | Amount %d | Map %s[%d,%d] | Seller %s",pl_sd->status.cart[pl_sd->vending[j].index].nameid
  8540. 							,pl_sd->vending[j].value
  8541. 							,pl_sd->vending[j].amount
  8542. 							,mapindex_id2name(pl_sd->mapindex)
  8543. 							,pl_sd->bl.x, pl_sd->bl.y
  8544. 							,pl_sd->status.name);
  8545. 				if(pl_sd->vending[j].value < MinPrice) MinPrice = pl_sd->vending[j].value;
  8546. 				if(pl_sd->vending[j].value > MaxPrice) MaxPrice = pl_sd->vending[j].value;
  8547. 				clif_displaymessage(fd, atcmd_output);
  8548. 				count++;
  8549. 				flag = 1;
  8550. 			}
  8551. 			if(flag && pl_sd->mapindex == sd->mapindex){
  8552. 				clif_viewpoint(sd, 1, 1, pl_sd->bl.x, pl_sd->bl.y, ++sat_num, 0xFFFFFF);
  8553. 				flag = 0;
  8554. 			}
  8555. 		}
  8556. 	}
  8557. 	mapit_free(iter);
  8558. 	if(count > 0) {
  8559. 		snprintf(atcmd_output,CHAT_SIZE_MAX, "Found %d ea. Prices from %dz to %dz", count, MinPrice, MaxPrice);
  8560. 		clif_displaymessage(fd, atcmd_output);
  8561. 	} else
  8562. 		clif_displaymessage(fd, "Nobody is selling it now.");
  8563. 	return 0;
  8564. }
  8565.  
  8566. /*==========================================
  8567. * @jumptowhosell - warps to the cheapest shop.
  8568. * Made by Vengence
  8569. *------------------------------------------*/
  8570. ACMD_FUNC(jumptowhosell)
  8571. {
  8572. char item_name[100];
  8573. int item_id = 0, j, count = 0, sat_num = 0;
  8574. int s_type = 1; // search bitmask: 0-name,1-id, 2-card, 4-refine
  8575. int refine = 0,card_id = 0;
  8576. bool flag = 0; // place dot on the minimap?
  8577. struct map_session_data* pl_sd;
  8578. struct s_mapiterator* iter;
  8579. unsigned int MinPrice = battle_config.vending_max_value, MaxPrice = 0;
  8580. struct item_data *item_data;
  8581.  
  8582. nullpo_retr(-1, sd);
  8583.  
  8584. if (!message || !*message) {
  8585. clif_displaymessage(fd, "Use: @jtws (<+refine> )(<item_id>)(<[card_id]>) or @jtws <name>");
  8586. return -1;
  8587. }
  8588.  
  8589. if (sscanf(message, "+%d %d[%d]", &refine, &item_id, &card_id) == 3){
  8590. s_type = 1+2+4;
  8591. }
  8592. else if (sscanf(message, "+%d %d", &refine, &item_id) == 2){
  8593. s_type = 1+4;
  8594. }
  8595. else if (sscanf(message, "+%d [%d]", &refine, &card_id) == 2){
  8596. s_type = 2+4;
  8597. }
  8598. else if (sscanf(message, "%d[%d]", &item_id, &card_id) == 2){
  8599. s_type = 1+2;
  8600. }
  8601. else if (sscanf(message, "[%d]", &card_id) == 1){
  8602. s_type = 2;
  8603. }
  8604. else if (sscanf(message, "+%d", &refine) == 1){
  8605. s_type = 4;
  8606. }
  8607. else if (sscanf(message, "%d", &item_id) == 1 && item_id == atoi(message)){
  8608. //names, that start on num are not working
  8609. //so implemented minumum item_id>500
  8610. //or better make item_id == atoi(message) ?
  8611. s_type = 1;
  8612. }
  8613. else if (sscanf(message, "%99[^\n]", item_name) == 1){
  8614. s_type = 1;
  8615. if ((item_data = itemdb_searchname(item_name)) == NULL){
  8616. clif_displaymessage(fd, "Not found item with this name");
  8617. return -1;
  8618. }
  8619. item_id = item_data->nameid;
  8620. }
  8621. else {
  8622. clif_displaymessage(fd, "Use: @jtws (<+refine> )(<item_id>)(<[card_id]>) or @jtws <name>");
  8623. return -1;
  8624. }
  8625.  
  8626.  
  8627. //check card
  8628. if(s_type & 2 && ((item_data = itemdb_exists(card_id)) == NULL || item_data->type != IT_CARD)){
  8629. clif_displaymessage(fd, "Not found a card with than ID");
  8630. return -1;
  8631. }
  8632. //check item
  8633. if(s_type & 1 && (item_data = itemdb_exists(item_id)) == NULL){
  8634. clif_displaymessage(fd, "Not found an item with than ID");
  8635. return -1;
  8636. }
  8637. //check refine
  8638. if(s_type & 4){
  8639. if (refine<0 || refine>10){
  8640. clif_displaymessage(fd, "Refine out of bounds: 0 - 10");
  8641. return -1;
  8642. }
  8643. /*if(item_data->type != IT_WEAPON && item_data->type != IT_ARMOR){
  8644. clif_displaymessage(fd, "Use refine only with weapon or armor");
  8645. return -1;
  8646. }*/
  8647. }
  8648.  
  8649. iter = mapit_getallusers();
  8650. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  8651. {
  8652. if( pl_sd->vender_id ) //check if player is vending
  8653. {
  8654. for (j = 0; j < pl_sd->vend_num; j++) {
  8655. if(pl_sd->vending[j].value < MinPrice) MinPrice = pl_sd->vending[j].value;
  8656. if(pl_sd->vending[j].value > MaxPrice) MaxPrice = pl_sd->vending[j].value;
  8657. count++;
  8658. flag = 1;
  8659. }
  8660. if(flag && pl_sd->mapindex == sd->mapindex){
  8661. flag = 0;
  8662. }
  8663. }
  8664. }
  8665. mapit_free(iter);
  8666.  
  8667. if(count > 0) {
  8668. iter = mapit_getallusers();
  8669. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  8670. {
  8671. if( pl_sd->vender_id ) //check if player is vending
  8672. {
  8673. for (j = 0; j < pl_sd->vend_num; j++) {
  8674. if(pl_sd->vending[j].value == MinPrice)
  8675. {
  8676. pc_setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, 3);
  8677. snprintf(atcmd_output,CHAT_SIZE_MAX, "Warped to %s", pl_sd->status.name);
  8678. clif_displaymessage(fd, atcmd_output);
  8679. }
  8680. }
  8681. }
  8682. }
  8683. } else
  8684. clif_displaymessage(fd, "Nobody is selling it now.");
  8685.  
  8686. return 0;
  8687. }
  8688.  
  8689. /*==========================================
  8690.  * type: 1 = commands (@), 2 = charcommands (#)
  8691.  *------------------------------------------*/
  8692. static void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommandType type)
  8693. {
  8694. 	char line_buff[CHATBOX_SIZE];
  8695. 	char* cur = line_buff;
  8696. 	AtCommandInfo* cmd;
  8697. 	DBIterator *iter = db_iterator(atcommand_db);
  8698. 	int count = 0;
  8699.  
  8700. 	memset(line_buff,' ',CHATBOX_SIZE);
  8701. 	line_buff[CHATBOX_SIZE-1] = 0;
  8702.  
  8703. 	clif_displaymessage(fd, msg_txt(273)); // "Commands available:"
  8704.  
  8705. 	for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  8706. 		unsigned int slen = 0;
  8707.  
  8708. 		switch( type ) {
  8709. 			case COMMAND_CHARCOMMAND:
  8710. 				if( cmd->char_groups[sd->group_pos] == 0 )
  8711. 					continue;
  8712. 				break;
  8713. 			case COMMAND_ATCOMMAND:
  8714. 				if( cmd->at_groups[sd->group_pos] == 0 )
  8715. 					continue;
  8716. 				break;
  8717. 			default:
  8718. 				continue;
  8719. 		}
  8720.  
  8721.  
  8722. 		slen = strlen(cmd->command);
  8723.  
  8724. 		// flush the text buffer if this command won't fit into it
  8725. 		if ( slen + cur - line_buff >= CHATBOX_SIZE )
  8726. 		{
  8727. 			clif_displaymessage(fd,line_buff);
  8728. 			cur = line_buff;
  8729. 			memset(line_buff,' ',CHATBOX_SIZE);
  8730. 			line_buff[CHATBOX_SIZE-1] = 0;
  8731. 		}
  8732.  
  8733. 		memcpy(cur,cmd->command,slen);
  8734. 		cur += slen+(10-slen%10);
  8735.  
  8736. 		count++;
  8737. 	}
  8738. 	dbi_destroy(iter);
  8739. 	clif_displaymessage(fd,line_buff);
  8740.  
  8741. 	sprintf(atcmd_output, msg_txt(274), count); // "%d commands found."
  8742. 	clif_displaymessage(fd, atcmd_output);
  8743.  
  8744. 	return;
  8745. }
  8746.  
  8747. /*==========================================
  8748.  * @commands Lists available @ commands to you
  8749.  *------------------------------------------*/
  8750. ACMD_FUNC(commands)
  8751. {
  8752. 	atcommand_commands_sub(sd, fd, COMMAND_ATCOMMAND);
  8753. 	return 0;
  8754. }
  8755.  
  8756. /*==========================================
  8757.  * @charcommands Lists available # commands to you
  8758.  *------------------------------------------*/
  8759. ACMD_FUNC(charcommands)
  8760. {
  8761. 	atcommand_commands_sub(sd, fd, COMMAND_CHARCOMMAND);
  8762. 	return 0;
  8763. }
  8764.  
  8765. ACMD_FUNC(new_mount) {
  8766.  
  8767. 	clif_displaymessage(sd->fd,"NOTICE: If you crash with mount your LUA is outdated");
  8768. 	if( !(sd->sc.option&OPTION_MOUNTING) ) {
  8769. 		clif_displaymessage(sd->fd,"You have mounted.");
  8770. 		pc_setoption(sd, sd->sc.option|OPTION_MOUNTING);
  8771. 	} else {
  8772. 		clif_displaymessage(sd->fd,"You have released your mount");
  8773. 		pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);
  8774. 	}
  8775. 	return 0;
  8776. }
  8777.  
  8778. ACMD_FUNC(accinfo) {
  8779. 	char query[NAME_LENGTH];
  8780.  
  8781. 	if (!message || !*message || strlen(message) > NAME_LENGTH ) {
  8782. 		clif_displaymessage(fd, "(usage: @accinfo/@accountinfo <account_id/char name>).");
  8783. 		clif_displaymessage(fd, "You may search partial name by making use of '%' in the search, \"@accinfo %Mario%\" lists all characters whose name contain \"Mario\"");
  8784. 		return -1;
  8785. 	}
  8786.  
  8787. 	//remove const type
  8788. 	safestrncpy(query, message, NAME_LENGTH);
  8789.  
  8790. 	intif_request_accinfo( sd->fd, sd->bl.id, sd->group_id, query );
  8791.  
  8792. 	return 0;
  8793. }
  8794.  
  8795. /* [Ind] */
  8796. ACMD_FUNC(set) {
  8797. 	char reg[32], val[128];
  8798. 	struct script_data* data;
  8799. 	int toset = 0;
  8800. 	bool is_str = false;
  8801.  
  8802. 	if( !message || !*message || (toset = sscanf(message, "%32s %128[^\n]s", reg, val)) < 1  ) {
  8803. 		clif_displaymessage(fd, "Usage: @set <variable name> <value>");
  8804. 		clif_displaymessage(fd, "Usage: e.g. @set PoringCharVar 50");
  8805. 		clif_displaymessage(fd, "Usage: e.g. @set PoringCharVarSTR$ Super Duper String");
  8806. 		clif_displaymessage(fd, "Usage: e.g. \"@set PoringCharVarSTR$\" outputs it's value, Super Duper String");
  8807. 		return -1;
  8808. 	}
  8809.  
  8810. 	/* disabled variable types (they require a proper script state to function, so allowing them would crash the server) */
  8811. 	if( reg[0] == '.' ) {
  8812. 		clif_displaymessage(fd, "NPC Variables may not be used with @set");
  8813. 		return -1;
  8814. 	} else if( reg[0] == '\'' ) {
  8815. 		clif_displaymessage(fd, "Instance variables may not be used with @set");
  8816. 		return -1;
  8817. 	}
  8818.  
  8819. 	is_str = ( reg[strlen(reg) - 1] == '$' ) ? true : false;
  8820.  
  8821. 	if( toset >= 2 ) {/* we only set the var if there is an val, otherwise we only output the value */
  8822. 		if( is_str )
  8823. 			set_var(sd, reg, (void*) val);
  8824. 		else
  8825. 			set_var(sd, reg, (void*)__64BPRTSIZE((int)(atoi(val))));
  8826.  
  8827. 	}
  8828.  
  8829. 	CREATE(data, struct script_data,1);
  8830.  
  8831.  
  8832. 	if( is_str ) {// string variable
  8833.  
  8834. 		switch( reg[0] ) {
  8835. 			case '@':
  8836. 				data->u.str = pc_readregstr(sd, add_str(reg));
  8837. 				break;
  8838. 			case '$':
  8839. 				data->u.str = mapreg_readregstr(add_str(reg));
  8840. 				break;
  8841. 			case '#':
  8842. 				if( reg[1] == '#' )
  8843. 					data->u.str = pc_readaccountreg2str(sd, reg);// global
  8844. 				else
  8845. 					data->u.str = pc_readaccountregstr(sd, reg);// local
  8846. 				break;
  8847. 			default:
  8848. 				data->u.str = pc_readglobalreg_str(sd, reg);
  8849. 				break;
  8850. 		}
  8851.  
  8852. 		if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string
  8853. 			data->type = C_CONSTSTR;
  8854. 			data->u.str = "";
  8855. 		} else {// duplicate string
  8856. 			data->type = C_STR;
  8857. 			data->u.str = aStrdup(data->u.str);
  8858. 		}
  8859.  
  8860. 	} else {// integer variable
  8861.  
  8862. 		data->type = C_INT;
  8863. 		switch( reg[0] ) {
  8864. 			case '@':
  8865. 				data->u.num = pc_readreg(sd, add_str(reg));
  8866. 				break;
  8867. 			case '$':
  8868. 				data->u.num = mapreg_readreg(add_str(reg));
  8869. 				break;
  8870. 			case '#':
  8871. 				if( reg[1] == '#' )
  8872. 					data->u.num = pc_readaccountreg2(sd, reg);// global
  8873. 				else
  8874. 					data->u.num = pc_readaccountreg(sd, reg);// local
  8875. 				break;
  8876. 			default:
  8877. 				data->u.num = pc_readglobalreg(sd, reg);
  8878. 				break;
  8879. 		}
  8880.  
  8881. 	}
  8882.  
  8883.  
  8884. 	switch( data->type ) {
  8885. 		case C_INT:
  8886. 			sprintf(atcmd_output,"%s value is now :%d",reg,data->u.num);
  8887. 			break;
  8888. 		case C_STR:
  8889. 			sprintf(atcmd_output,"%s value is now :%s",reg,data->u.str);
  8890. 			break;
  8891. 		case C_CONSTSTR:
  8892. 			sprintf(atcmd_output,"%s is empty",reg);
  8893. 			break;
  8894. 		default:
  8895. 			sprintf(atcmd_output,"%s data type is not supported :%u",reg,data->type);
  8896. 			break;
  8897. 	}
  8898.  
  8899. 	clif_displaymessage(fd, atcmd_output);
  8900.  
  8901. 	aFree(data);
  8902.  
  8903. 	return 0;
  8904. }
  8905.  
  8906. /**
  8907.  * Fills the reference of available commands in atcommand DBMap
  8908.  **/
  8909. #define ACMD_DEF(x) { #x, atcommand_ ## x, NULL, NULL }
  8910. #define ACMD_DEF2(x2, x) { x2, atcommand_ ## x, NULL, NULL }
  8911. void atcommand_basecommands(void) {
  8912. 	/**
  8913. 	 * Command reference list, place the base of your commands here
  8914. 	 **/
  8915. 	AtCommandInfo atcommand_base[] = {
  8916. 		ACMD_DEF2("warp", mapmove),
  8917. 		ACMD_DEF(where),
  8918. 		ACMD_DEF(jumpto),
  8919. 		ACMD_DEF(jump),
  8920. 		ACMD_DEF(who),
  8921. 		ACMD_DEF2("who2", who),
  8922. 		ACMD_DEF2("who3", who),
  8923. 		ACMD_DEF2("whomap", who),
  8924. 		ACMD_DEF2("whomap2", who),
  8925. 		ACMD_DEF2("whomap3", who),
  8926. 		ACMD_DEF(whogm),
  8927. 		ACMD_DEF(save),
  8928. 		ACMD_DEF(load),
  8929. 		ACMD_DEF(speed),
  8930. 		ACMD_DEF(storage),
  8931. 		ACMD_DEF(guildstorage),
  8932. 		ACMD_DEF(option),
  8933. 		ACMD_DEF(hide), // + /hide
  8934. 		ACMD_DEF(jobchange),
  8935. 		ACMD_DEF(kill),
  8936. 		ACMD_DEF(alive),
  8937. 		ACMD_DEF(kami),
  8938. 		ACMD_DEF2("kamib", kami),
  8939. 		ACMD_DEF2("kamic", kami),
  8940. 		ACMD_DEF2("lkami", kami),
  8941. 		ACMD_DEF(heal),
  8942. 		ACMD_DEF(item),
  8943. 		ACMD_DEF(item2),
  8944. 		ACMD_DEF(itemreset),
  8945. 		ACMD_DEF2("blvl", baselevelup),
  8946. 		ACMD_DEF2("jlvl", joblevelup),
  8947. 		ACMD_DEF(help),
  8948. 		ACMD_DEF(pvpoff),
  8949. 		ACMD_DEF(pvpon),
  8950. 		ACMD_DEF(gvgoff),
  8951. 		ACMD_DEF(gvgon),
  8952. 		ACMD_DEF(model),
  8953. 		ACMD_DEF(go),
  8954. 		ACMD_DEF(monster),
  8955. 		ACMD_DEF2("monstersmall", monster),
  8956. 		ACMD_DEF2("monsterbig", monster),
  8957. 		ACMD_DEF(killmonster),
  8958. 		ACMD_DEF(killmonster2),
  8959. 		ACMD_DEF(refine),
  8960. 		ACMD_DEF(produce),
  8961. 		ACMD_DEF(memo),
  8962. 		ACMD_DEF(gat),
  8963. 		ACMD_DEF(displaystatus),
  8964. 		ACMD_DEF2("stpoint", statuspoint),
  8965. 		ACMD_DEF2("skpoint", skillpoint),
  8966. 		ACMD_DEF(zeny),
  8967. 		ACMD_DEF2("str", param),
  8968. 		ACMD_DEF2("agi", param),
  8969. 		ACMD_DEF2("vit", param),
  8970. 		ACMD_DEF2("int", param),
  8971. 		ACMD_DEF2("dex", param),
  8972. 		ACMD_DEF2("luk", param),
  8973. 		ACMD_DEF2("glvl", guildlevelup),
  8974. 		ACMD_DEF(makeegg),
  8975. 		ACMD_DEF(hatch),
  8976. 		ACMD_DEF(petfriendly),
  8977. 		ACMD_DEF(pethungry),
  8978. 		ACMD_DEF(petrename),
  8979. 		ACMD_DEF(recall), // + /recall
  8980. 		ACMD_DEF(night),
  8981. 		ACMD_DEF(day),
  8982. 		ACMD_DEF(doom),
  8983. 		ACMD_DEF(doommap),
  8984. 		ACMD_DEF(raise),
  8985. 		ACMD_DEF(raisemap),
  8986. 		ACMD_DEF(kick), // + right click menu for GM "(name) force to quit"
  8987. 		ACMD_DEF(kickall),
  8988. 		ACMD_DEF(allskill),
  8989. 		ACMD_DEF(questskill),
  8990. 		ACMD_DEF(lostskill),
  8991. 		ACMD_DEF(spiritball),
  8992. 		ACMD_DEF(party),
  8993. 		ACMD_DEF(guild),
  8994. 		ACMD_DEF(agitstart),
  8995. 		ACMD_DEF(agitend),
  8996. 		ACMD_DEF(mapexit),
  8997. 		ACMD_DEF(idsearch),
  8998. 		ACMD_DEF(broadcast), // + /b and /nb
  8999. 		ACMD_DEF(localbroadcast), // + /lb and /nlb
  9000. 		ACMD_DEF(recallall),
  9001. 		ACMD_DEF(reloaditemdb),
  9002. 		ACMD_DEF(reloadmobdb),
  9003. 		ACMD_DEF(reloadskilldb),
  9004. 		ACMD_DEF(reloadscript),
  9005. 		ACMD_DEF(reloadatcommand),
  9006. 		ACMD_DEF(reloadbattleconf),
  9007. 		ACMD_DEF(reloadstatusdb),
  9008. 		ACMD_DEF(reloadpcdb),
  9009. 		ACMD_DEF(reloadmotd),
  9010. 		ACMD_DEF(mapinfo),
  9011. 		ACMD_DEF(dye),
  9012. 		ACMD_DEF2("hairstyle", hair_style),
  9013. 		ACMD_DEF2("haircolor", hair_color),
  9014. 		ACMD_DEF2("allstats", stat_all),
  9015. 		ACMD_DEF2("block", char_block),
  9016. 		ACMD_DEF2("ban", char_ban),
  9017. 		ACMD_DEF2("unblock", char_unblock),
  9018. 		ACMD_DEF2("unban", char_unban),
  9019. 		ACMD_DEF2("mount", mount_peco),
  9020. 		ACMD_DEF(guildspy),
  9021. 		ACMD_DEF(partyspy),
  9022. 		ACMD_DEF(repairall),
  9023. 		ACMD_DEF(guildrecall),
  9024. 		ACMD_DEF(partyrecall),
  9025. 		ACMD_DEF(nuke),
  9026. 		ACMD_DEF(shownpc),
  9027. 		ACMD_DEF(hidenpc),
  9028. 		ACMD_DEF(loadnpc),
  9029. 		ACMD_DEF(unloadnpc),
  9030. 		ACMD_DEF2("time", servertime),
  9031. 		ACMD_DEF(jail),
  9032. 		ACMD_DEF(unjail),
  9033. 		ACMD_DEF(jailfor),
  9034. 		ACMD_DEF(jailtime),
  9035. 		ACMD_DEF(disguise),
  9036. 		ACMD_DEF(undisguise),
  9037. 		ACMD_DEF(email),
  9038. 		ACMD_DEF(effect),
  9039. 		ACMD_DEF(follow),
  9040. 		ACMD_DEF(addwarp),
  9041. 		ACMD_DEF(skillon),
  9042. 		ACMD_DEF(skilloff),
  9043. 		ACMD_DEF(killer),
  9044. 		ACMD_DEF(npcmove),
  9045. 		ACMD_DEF(killable),
  9046. 		ACMD_DEF(dropall),
  9047. 		ACMD_DEF(storeall),
  9048. 		ACMD_DEF(skillid),
  9049. 		ACMD_DEF(useskill),
  9050. 		ACMD_DEF(displayskill),
  9051. 		ACMD_DEF(snow),
  9052. 		ACMD_DEF(sakura),
  9053. 		ACMD_DEF(clouds),
  9054. 		ACMD_DEF(clouds2),
  9055. 		ACMD_DEF(fog),
  9056. 		ACMD_DEF(fireworks),
  9057. 		ACMD_DEF(leaves),
  9058. 		ACMD_DEF(summon),
  9059. 		ACMD_DEF(adjgroup),
  9060. 		ACMD_DEF(trade),
  9061. 		ACMD_DEF(send),
  9062. 		ACMD_DEF(setbattleflag),
  9063. 		ACMD_DEF(unmute),
  9064. 		ACMD_DEF(clearweather),
  9065. 		ACMD_DEF(uptime),
  9066. 		ACMD_DEF(changesex),
  9067. 		ACMD_DEF(mute),
  9068. 		ACMD_DEF(refresh),
  9069. 		ACMD_DEF(identify),
  9070. 		ACMD_DEF(gmotd),
  9071. 		ACMD_DEF(misceffect),
  9072. 		ACMD_DEF(mobsearch),
  9073. 		ACMD_DEF(cleanmap),
  9074. 		ACMD_DEF(npctalk),
  9075. 		ACMD_DEF(pettalk),
  9076. 		ACMD_DEF(users),
  9077. 		ACMD_DEF(reset),
  9078. 		ACMD_DEF(skilltree),
  9079. 		ACMD_DEF(marry),
  9080. 		ACMD_DEF(divorce),
  9081. 		ACMD_DEF(sound),
  9082. 		ACMD_DEF(undisguiseall),
  9083. 		ACMD_DEF(disguiseall),
  9084. 		ACMD_DEF(changelook),
  9085. 		ACMD_DEF(autoloot),
  9086. 		ACMD_DEF2("alootid", autolootitem),
  9087. 		ACMD_DEF(mobinfo),
  9088. 		ACMD_DEF(exp),
  9089. 		ACMD_DEF(adopt),
  9090. 		ACMD_DEF(version),
  9091. 		ACMD_DEF(mutearea),
  9092. 		ACMD_DEF(rates),
  9093. 		ACMD_DEF(iteminfo),
  9094. 		ACMD_DEF(whodrops),
  9095. 		ACMD_DEF(whereis),
  9096. 		ACMD_DEF(mapflag),
  9097. 		ACMD_DEF(me),
  9098. 		ACMD_DEF(monsterignore),
  9099. 		ACMD_DEF(fakename),
  9100. 		ACMD_DEF(size),
  9101. 		ACMD_DEF(showexp),
  9102. 		ACMD_DEF(showzeny),
  9103. 		ACMD_DEF(showdelay),
  9104. 		ACMD_DEF(autotrade),
  9105. 		ACMD_DEF(changegm),
  9106. 		ACMD_DEF(changeleader),
  9107. 		ACMD_DEF(partyoption),
  9108. 		ACMD_DEF(invite),
  9109. 		ACMD_DEF(duel),
  9110. 		ACMD_DEF(leave),
  9111. 		ACMD_DEF(accept),
  9112. 		ACMD_DEF(reject),
  9113. 		ACMD_DEF(main),
  9114. 		ACMD_DEF(clone),
  9115. 		ACMD_DEF2("slaveclone", clone),
  9116. 		ACMD_DEF2("evilclone", clone),
  9117. 		ACMD_DEF(tonpc),
  9118. 		ACMD_DEF(commands),
  9119. 		ACMD_DEF(noask),
  9120. 		ACMD_DEF(request),
  9121. 		ACMD_DEF(homlevel),
  9122. 		ACMD_DEF(homevolution),
  9123. 		ACMD_DEF(makehomun),
  9124. 		ACMD_DEF(homfriendly),
  9125. 		ACMD_DEF(homhungry),
  9126. 		ACMD_DEF(homtalk),
  9127. 		ACMD_DEF(hominfo),
  9128. 		ACMD_DEF(homstats),
  9129. 		ACMD_DEF(homshuffle),
  9130. 		ACMD_DEF(showmobs),
  9131. 		ACMD_DEF(feelreset),
  9132. 		ACMD_DEF(auction),
  9133. 		ACMD_DEF(mail),
  9134. 		ACMD_DEF2("noks", ksprotection),
  9135. 		ACMD_DEF(allowks),
  9136. 		ACMD_DEF(cash),
  9137. 		ACMD_DEF2("points", cash),
  9138. 		ACMD_DEF(agitstart2),
  9139. 		ACMD_DEF(agitend2),
  9140. 		ACMD_DEF2("skreset", resetskill),
  9141. 		ACMD_DEF2("streset", resetstat),
  9142. 		ACMD_DEF2("storagelist", itemlist),
  9143. 		ACMD_DEF2("cartlist", itemlist),
  9144. 		ACMD_DEF2("itemlist", itemlist),
  9145. 		ACMD_DEF(stats),
  9146. 		ACMD_DEF(delitem),
  9147. 		ACMD_DEF(charcommands),
  9148. 		ACMD_DEF(font),
  9149. 		ACMD_DEF(accinfo),
  9150. 		ACMD_DEF(set),
  9151. 		/**
  9152. 		 * For Testing Purposes, not going to be here after we're done.
  9153. 		 **/
  9154. 		ACMD_DEF2("newmount", new_mount),
  9155. 		ACMD_DEF(whosell),
  9156. 		ACMD_DEF(jumptowhosell),
  9157. 	};
  9158. 	AtCommandInfo* atcommand;
  9159. 	int i;
  9160.  
  9161. 	for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) {
  9162. 		if(atcommand_exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK
  9163. 			ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command);
  9164. 			continue;
  9165. 		}
  9166. 		CREATE(atcommand, AtCommandInfo, 1);
  9167. 		safestrncpy(atcommand->command, atcommand_base[i].command, sizeof(atcommand->command));
  9168. 		atcommand->func = atcommand_base[i].func;
  9169. 		strdb_put(atcommand_db, atcommand->command, atcommand);
  9170. 	}
  9171. 	return;
  9172. }
  9173.  
  9174. /*==========================================
  9175.  * Command lookup functions
  9176.  *------------------------------------------*/
  9177. bool atcommand_exists(const char* name)
  9178. {
  9179. 	return strdb_exists(atcommand_db, name);
  9180. }
  9181.  
  9182. static AtCommandInfo* get_atcommandinfo_byname(const char *name)
  9183. {
  9184. 	if (strdb_exists(atcommand_db, name))
  9185. 		return (AtCommandInfo*)strdb_get(atcommand_db, name);
  9186. 	return NULL;
  9187. }
  9188.  
  9189. static const char* atcommand_checkalias(const char *aliasname)
  9190. {
  9191. 	AliasInfo *alias_info = NULL;
  9192. 	if ((alias_info = (AliasInfo*)strdb_get(atcommand_alias_db, aliasname)) != NULL)
  9193. 		return alias_info->command->command;
  9194. 	return aliasname;
  9195. }
  9196.  
  9197. /// AtCommand suggestion
  9198. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand) {
  9199. 	DBIterator* atcommand_iter;
  9200. 	DBIterator* alias_iter;
  9201. 	AtCommandInfo* command_info = NULL;
  9202. 	AliasInfo* alias_info = NULL;
  9203. 	AtCommandType type = atcommand ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND;
  9204. 	char* full_match[MAX_SUGGESTIONS];
  9205. 	char* suggestions[MAX_SUGGESTIONS];
  9206. 	char* match;
  9207. 	int prefix_count = 0, full_count = 0;
  9208. 	bool can_use;
  9209.  
  9210. 	if (!battle_config.atcommand_suggestions_enabled)
  9211. 		return;
  9212.  
  9213. 	atcommand_iter = db_iterator(atcommand_db);
  9214. 	alias_iter = db_iterator(atcommand_alias_db);
  9215.  
  9216. 	// Build the matches
  9217. 	for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter); command_info = dbi_next(atcommand_iter))     {
  9218. 		match = strstr(command_info->command, name);
  9219. 		can_use = pc_can_use_command(sd, command_info->command, type);
  9220. 		if ( prefix_count < MAX_SUGGESTIONS && match == command_info->command && can_use ) {
  9221. 			suggestions[prefix_count] = command_info->command;
  9222. 			++prefix_count;
  9223. 		}
  9224. 		if ( full_count < MAX_SUGGESTIONS && match != NULL && match != command_info->command && can_use ) {
  9225. 			full_match[full_count] = command_info->command;
  9226. 			++full_count;
  9227. 		}
  9228. 	}
  9229.  
  9230. 	for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter); alias_info = dbi_next(alias_iter)) {
  9231. 		match = strstr(alias_info->alias, name);
  9232. 		can_use = pc_can_use_command(sd, alias_info->command->command, type);
  9233. 		if ( prefix_count < MAX_SUGGESTIONS && match == alias_info->alias && can_use) {
  9234. 			suggestions[prefix_count] = alias_info->alias;
  9235. 			++prefix_count;
  9236. 		}
  9237. 		if ( full_count < MAX_SUGGESTIONS && match != NULL && match != alias_info->alias && can_use ) {
  9238. 			full_match[full_count] = alias_info->alias;
  9239. 			++full_count;
  9240. 		}
  9241. 	}
  9242.  
  9243. 	if ((full_count+prefix_count) > 0) {
  9244. 		char buffer[512];
  9245. 		int i;
  9246.  
  9247. 		// Merge full match and prefix match results
  9248. 		if (prefix_count < MAX_SUGGESTIONS) {
  9249. 			memmove(&suggestions[prefix_count], full_match, sizeof(char*) * (MAX_SUGGESTIONS-prefix_count));
  9250. 			prefix_count = min(prefix_count+full_count, MAX_SUGGESTIONS);
  9251. 		}
  9252.  
  9253. 		// Build the suggestion string
  9254. 		strcpy(buffer, msg_txt(205));
  9255. 		strcat(buffer,"\n");
  9256.  
  9257. 		for(i=0; i < prefix_count; ++i) {
  9258. 			strcat(buffer,suggestions[i]);
  9259. 			strcat(buffer," ");
  9260. 		}
  9261.  
  9262. 		clif_displaymessage(sd->fd, buffer);
  9263. 	}
  9264.  
  9265. 	dbi_destroy(atcommand_iter);
  9266. 	dbi_destroy(alias_iter);
  9267. }
  9268.  
  9269. /// Executes an at-command.
  9270. bool is_atcommand(const int fd, struct map_session_data* sd, const char* message, int type)
  9271. {
  9272. 	char charname[NAME_LENGTH], params[100];
  9273. 	char charname2[NAME_LENGTH], params2[100];
  9274. 	char command[100];
  9275. 	char output[CHAT_SIZE_MAX];
  9276.  
  9277. 	//Reconstructed message
  9278. 	char atcmd_msg[CHAT_SIZE_MAX];
  9279.  
  9280. 	TBL_PC * ssd = NULL; //sd for target
  9281. 	AtCommandInfo * info;
  9282.  
  9283. 	nullpo_retr(false, sd);
  9284.  
  9285. 	//Shouldn't happen
  9286. 	if ( !message || !*message )
  9287. 		return false;
  9288.  
  9289. 	//Block NOCHAT but do not display it as a normal message
  9290. 	if ( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCOMMAND )
  9291. 		return true;
  9292.  
  9293. 	// skip 10/11-langtype's codepage indicator, if detected
  9294. 	if ( message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand_symbol || message[3] == charcommand_symbol) )
  9295. 		message += 3;
  9296.  
  9297. 	//Should display as a normal message
  9298. 	if ( *message != atcommand_symbol && *message != charcommand_symbol )
  9299. 		return false;
  9300.  
  9301. 	// type value 0 = server invoked: bypass restrictions
  9302. 	// 1 = player invoked
  9303. 	if ( type == 1) {
  9304. 		//Commands are disabled on maps flagged as 'nocommand'
  9305. 		if ( map[sd->bl.m].nocommand && pc_get_group_level(sd) < map[sd->bl.m].nocommand ) {
  9306. 			clif_displaymessage(fd, msg_txt(143));
  9307. 			return false;
  9308. 		}
  9309. 	}
  9310.  
  9311. 	if (*message == charcommand_symbol) {
  9312. 		do {
  9313. 			int x, y, z;
  9314.  
  9315. 			//Checks to see if #command has a name or a name + parameters.
  9316. 			x = sscanf(message, "%99s \"%23[^\"]\" %99[^\n]", command, charname, params);
  9317. 			y = sscanf(message, "%99s %23s %99[^\n]", command, charname2, params2);
  9318.  
  9319. 			//z always has the value of the scan that was successful
  9320. 			z = ( x > 1 ) ? x : y;
  9321.  
  9322. 			//#command + name means the sufficient target was used and anything else after
  9323. 			//can be looked at by the actual command function since most scan to see if the
  9324. 			//right parameters are used.
  9325. 			if ( x > 2 ) {
  9326. 				sprintf(atcmd_msg, "%s %s", command, params);
  9327. 				break;
  9328. 			}
  9329. 			else if ( y > 2 ) {
  9330. 				sprintf(atcmd_msg, "%s %s", command, params2);
  9331. 				break;
  9332. 			}
  9333. 			//Regardless of what style the #command is used, if it's correct, it will always have
  9334. 			//this value if there is no parameter. Send it as just the #command
  9335. 			else if ( z == 2 ) {
  9336. 				sprintf(atcmd_msg, "%s", command);
  9337. 				break;
  9338. 			}
  9339.  
  9340. 			sprintf(output, "Charcommand failed. Usage: %c<command> <char name> <params>.", charcommand_symbol);
  9341. 			clif_displaymessage(fd, output);
  9342. 			return true;
  9343. 		} while(0);
  9344. 	}
  9345. 	else if (*message == atcommand_symbol) {
  9346. 		//atcmd_msg is constructed above differently for charcommands
  9347. 		//it's copied from message if not a charcommand so it can 
  9348. 		//pass through the rest of the code compatible with both symbols
  9349. 		sprintf(atcmd_msg, "%s", message);
  9350. 	}
  9351.  
  9352. 	//Clearing these to be used once more. 
  9353. 	memset(command, '\0', sizeof(command));
  9354. 	memset(params, '\0', sizeof(params));
  9355.  
  9356. 	//check to see if any params exist within this command
  9357. 	if( sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2 )
  9358. 		params[0] = '\0';
  9359.  
  9360. 	// @commands (script based)
  9361. 	if(type == 1 && atcmd_binding_count > 0) {
  9362. 		struct atcmd_binding_data * binding;
  9363.  
  9364. 		// Check if the command initiated is a character command
  9365. 		if (*message == charcommand_symbol &&
  9366. 				(ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  9367. 			sprintf(output, "%s failed. Player not found.", command);
  9368. 			clif_displaymessage(fd, output);
  9369. 			return true;
  9370. 		}
  9371.  
  9372. 		// Get atcommand binding
  9373. 		binding = get_atcommandbind_byname(command);
  9374.  
  9375. 		// Check if the binding isn't NULL and there is a NPC event, level of usage met, et cetera
  9376. 		if( binding != NULL && binding->npc_event[0] &&
  9377. 			((*atcmd_msg == atcommand_symbol && pc_get_group_level(sd) >= binding->level) ||
  9378. 			 (*atcmd_msg == charcommand_symbol && pc_get_group_level(sd) >= binding->level2)))
  9379. 		{
  9380. 			// Check if self or character invoking; if self == character invoked, then self invoke.
  9381. 			bool invokeFlag = ((*atcmd_msg == atcommand_symbol) ? 1 : 0);
  9382. 			npc_do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
  9383. 			return true;
  9384. 		}
  9385. 	}
  9386.  
  9387. 	//Grab the command information and check for the proper GM level required to use it or if the command exists
  9388. 	info = get_atcommandinfo_byname(atcommand_checkalias(command + 1));
  9389. 	if (info == NULL) {
  9390. 		if( pc_get_group_level(sd) ) { // TODO: remove or replace with proper permission
  9391. 			sprintf(output, msg_txt(153), command); // "%s is Unknown Command."
  9392. 			clif_displaymessage(fd, output);
  9393. 			atcommand_get_suggestions(sd, command + 1, *message == atcommand_symbol);
  9394. 			return true;
  9395. 		} else
  9396. 			return false;
  9397. 	}
  9398.  
  9399. 	// type == 1 : player invoked
  9400. 	if (type == 1) {
  9401. 		if ((*command == atcommand_symbol && info->at_groups[sd->group_pos] == 0) ||
  9402. 		    (*command == charcommand_symbol && info->char_groups[sd->group_pos] == 0) ) {
  9403. 			return false;
  9404. 		}
  9405. 	}
  9406.  
  9407. 	// Check if target is valid only if confirmed that player can use command.
  9408. 	if (*message == charcommand_symbol &&
  9409. 	    (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  9410. 		sprintf(output, "%s failed. Player not found.", command);
  9411. 		clif_displaymessage(fd, output);
  9412. 		return true;
  9413. 	}
  9414.  
  9415. 	//Attempt to use the command
  9416. 	if ( (info->func(fd, (*atcmd_msg == atcommand_symbol) ? sd : ssd, command, params) != 0) )
  9417. 	{
  9418. 		sprintf(output,msg_txt(154), command); // %s failed.
  9419. 		clif_displaymessage(fd, output);
  9420. 		return true;
  9421. 	}
  9422.  
  9423. 	//Log only if successful.
  9424. 	if ( *atcmd_msg == atcommand_symbol )
  9425. 		log_atcommand(sd, atcmd_msg);
  9426. 	else if ( *atcmd_msg == charcommand_symbol )
  9427. 		log_atcommand(sd, message);
  9428.  
  9429. 	return true;
  9430. }
  9431.  
  9432. /*==========================================
  9433.  *
  9434.  *------------------------------------------*/
  9435. static void atcommand_config_read(const char* config_filename)
  9436. {
  9437. 	config_setting_t *aliases = NULL, *help = NULL;
  9438. 	const char *symbol = NULL;
  9439. 	int num_aliases = 0;
  9440.  
  9441. 	if (conf_read_file(&atcommand_config, config_filename))
  9442. 		return;
  9443.  
  9444. 	// Command symbols
  9445. 	if (config_lookup_string(&atcommand_config, "atcommand_symbol", &symbol)) {
  9446. 		if (ISPRINT(*symbol) && // no control characters
  9447. 			*symbol != '/' && // symbol of client commands
  9448. 			*symbol != '%' && // symbol of party chat
  9449. 			*symbol != '$' && // symbol of guild chat
  9450. 			*symbol != charcommand_symbol) 
  9451. 			atcommand_symbol = *symbol;
  9452. 	}
  9453.  
  9454. 	if (config_lookup_string(&atcommand_config, "charcommand_symbol", &symbol)) {
  9455. 		if (ISPRINT(*symbol) && // no control characters
  9456. 			*symbol != '/' && // symbol of client commands
  9457. 			*symbol != '%' && // symbol of party chat
  9458. 			*symbol != '$' && // symbol of guild chat
  9459. 			*symbol != atcommand_symbol)
  9460. 			charcommand_symbol = *symbol;
  9461. 	}
  9462.  
  9463. 	// Command aliases
  9464. 	aliases = config_lookup(&atcommand_config, "aliases");
  9465. 	if (aliases != NULL) {
  9466. 		int i = 0;
  9467. 		int count = config_setting_length(aliases);
  9468.  
  9469. 		for (i = 0; i < count; ++i) {
  9470. 			config_setting_t *command = NULL;
  9471. 			const char *commandname = NULL;
  9472. 			int j = 0, alias_count = 0;
  9473. 			AtCommandInfo *commandinfo = NULL;
  9474.  
  9475. 			command = config_setting_get_elem(aliases, i);
  9476. 			if (config_setting_type(command) != CONFIG_TYPE_ARRAY)
  9477. 				continue;
  9478. 			commandname = config_setting_name(command);
  9479. 			if (!atcommand_exists(commandname)) {
  9480. 				ShowConfigWarning(command, "atcommand_config_read: can not set alias for non-existent command %s", commandname);
  9481. 				continue;
  9482. 			}
  9483. 			commandinfo = get_atcommandinfo_byname(commandname);
  9484. 			alias_count = config_setting_length(command);
  9485. 			for (j = 0; j < alias_count; ++j) {
  9486. 				const char *alias = config_setting_get_string_elem(command, j);
  9487. 				if (alias != NULL) {
  9488. 					AliasInfo *alias_info;
  9489. 					if (strdb_exists(atcommand_alias_db, alias)) {
  9490. 						ShowConfigWarning(command, "atcommand_config_read: alias %s already exists", alias);
  9491. 						continue;
  9492. 					}
  9493. 					CREATE(alias_info, AliasInfo, 1);
  9494. 					alias_info->command = commandinfo;
  9495. 					safestrncpy(alias_info->alias, alias, sizeof(alias_info->alias));
  9496. 					strdb_put(atcommand_alias_db, alias, alias_info);
  9497. 					++num_aliases;
  9498. 				}
  9499. 			}
  9500. 		}
  9501. 	}
  9502.  
  9503. 	// Commands help
  9504. 	// We only check if all commands exist
  9505. 	help = config_lookup(&atcommand_config, "help");
  9506. 	if (help != NULL) {
  9507. 		int count = config_setting_length(help);
  9508. 		int i;
  9509.  
  9510. 		for (i = 0; i < count; ++i) {
  9511. 			config_setting_t *command = NULL;
  9512. 			const char *commandname = NULL;
  9513.  
  9514. 			command = config_setting_get_elem(help, i);
  9515. 			commandname = config_setting_name(command);
  9516. 			if (!atcommand_exists(commandname))
  9517. 				ShowConfigWarning(command, "atcommand_config_read: command %s does not exist", commandname);
  9518. 		}
  9519. 	}
  9520.  
  9521. 	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' command aliases in '"CL_WHITE"%s"CL_RESET"'.\n", num_aliases, config_filename);
  9522. 	return;
  9523. }
  9524. void atcommand_db_load_groups(int* group_ids) {
  9525. 	DBIterator *iter = db_iterator(atcommand_db);
  9526. 	AtCommandInfo* cmd;
  9527. 	int i;
  9528.  
  9529. 	for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  9530. 		cmd->at_groups = aMalloc( pc_group_max * sizeof(char) );
  9531. 		cmd->char_groups = aMalloc( pc_group_max * sizeof(char) );
  9532. 		for(i = 0; i < pc_group_max; i++) {
  9533. 			if( pc_group_can_use_command(group_ids[i], cmd->command, COMMAND_ATCOMMAND ) )
  9534. 			   cmd->at_groups[i] = 1;
  9535. 			else
  9536. 			   cmd->at_groups[i] = 0;
  9537. 		   if( pc_group_can_use_command(group_ids[i], cmd->command, COMMAND_CHARCOMMAND ) )
  9538. 			  cmd->char_groups[i] = 1;
  9539. 			else
  9540. 			  cmd->char_groups[i] = 0;
  9541. 		}
  9542. 	}
  9543.  
  9544. 	dbi_destroy(iter);
  9545.  
  9546. 	return;
  9547. }
  9548. void atcommand_db_clear(void) {
  9549.  
  9550. 	if (atcommand_db != NULL) {
  9551. 		DBIterator *iter = db_iterator(atcommand_db);
  9552. 		AtCommandInfo* cmd;
  9553.  
  9554. 		for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  9555. 			aFree(cmd->at_groups);
  9556. 			aFree(cmd->char_groups);
  9557. 		}
  9558.  
  9559. 		dbi_destroy(iter);
  9560.  
  9561. 		db_destroy(atcommand_db);
  9562. 	}
  9563. 	if (atcommand_alias_db != NULL)
  9564. 		db_destroy(atcommand_alias_db);
  9565.  
  9566. 	config_destroy(&atcommand_config);
  9567. }
  9568.  
  9569. void atcommand_doload(void) {
  9570. 	atcommand_db_clear();
  9571. 	atcommand_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  9572. 	atcommand_alias_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  9573. 	atcommand_basecommands(); //fills initial atcommand_db with known commands
  9574. 	atcommand_config_read(ATCOMMAND_CONF_FILENAME);
  9575. }
  9576.  
  9577. void do_init_atcommand(void) {
  9578. 	atcommand_doload();
  9579. }
  9580.  
  9581. void do_final_atcommand(void) {
  9582. 	atcommand_db_clear();
  9583. }
Viewed 1388 times, submitted by Guest.