+int atcommand_broadcastchat(const int fd, struct map_session_data* sd, const char* command, const char* message) +{ + char msg[CHAT_SIZE_MAX]; + short type; + nullpo_retr(-1, sd); + + if(strcmp(command+1,"market") == 0) + type = 1; + else if(strcmp(command+1,"recruit") == 0) + type = 2; + else if(strcmp(command+1,"reloadchannelcolor") == 0) + type = 3; + else + return -1; + + if(!message || !*message || sscanf(message, "%255s",msg) < 1) + { + sprintf(atcmd_output,"To enable/disable, use: @%s ",command+1); + clif_displaymessage(sd->fd,atcmd_output); + sprintf(atcmd_output,"To send the message, use: @%s ",command+1); + clif_displaymessage(sd->fd,atcmd_output); + return -1; + } + + if(type == 3) + { + clif_load_marketrecruit_color(); + clif_displaymessage(fd, "Database color of Market and Recruit channel had been reloaded"); + return 0; + } + + if(strcmp(msg,"on") == 0) + { + switch(type) + { + case 1: + sd->state.market_chnl = 1; + break; + case 2: + sd->state.recruit_chnl = 1; + break; + } + sprintf(atcmd_output,"%s is %s now.",command+1,"ON"); + clif_displaymessage(sd->fd,atcmd_output); + return 0; + } + else if(strcmp(msg,"off") == 0) + { + switch(type) + { + case 1: + sd->state.market_chnl = 0; + break; + case 2: + sd->state.recruit_chnl = 0; + break; + } + sprintf(atcmd_output,"%s is %s now.",command+1,"OFF"); + clif_displaymessage(sd->fd,atcmd_output); + return 0; + } + else + { + double diff_tick = DIFF_TICK(sd->broadcastchat_tick,gettick()); + if( (type == 1 && !sd->state.market_chnl) || (type == 2 && !sd->state.recruit_chnl) ) + { + sprintf(atcmd_output,"You must enable '%s' first by using, @%s ",command+1,command+1); + clif_displaymessage(sd->fd,atcmd_output); + return -1; + } + if(diff_tick > 0) + { + sprintf(atcmd_output,"You must wait %0.1f second(s) to use this command.",diff_tick/1000.); + clif_displaymessage(sd->fd,atcmd_output); + return -1; + } + snprintf(atcmd_output, CHAT_SIZE_MAX - 5, "[ %s ] %s : %s",(type == 1)?"Market":"Recruit",sd->status.name, msg); + clif_marketrecruit_msg(sd,atcmd_output,type); + sd->broadcastchat_tick = gettick()+battle_config.broadcastchat_interval; + } + + return 0; +}