#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../map/atcommand.h"
#include "../map/pc.h"
#include "../map/script.h"
#include "../common/socket.h"
#include "../common/strlib.h"
#include "../common/malloc.h"
#include "../common/HPMi.h"
#include "../common/HPMDataCheck.h" // should always be the last file included! (if you don't make it last, it'll intentionally break compile time)
HPExport struct hplugin_info pinfo = {
"market", // Plugin name
SERVER_TYPE_MAP,// Which server types this plugin works with?
"0.1", // Plugin version
HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
};
ACMD(bst) {
int announcement_delay = 5;
if ( !message || !*message ) {
clif->message(fd, "Please, enter a message (usage: @bst <message>).");
return false;
}
else if ( pc->readreg( sd, script->add_str("@bst_delay") ) + announcement_delay > (int)time(NULL) ) {
char atcmd_output[CHAT_SIZE_MAX];
safesnprintf( atcmd_output, CHAT_SIZE_MAX, "There is a %d seconds delay of using this command again.", announcement_delay );
clif->message( fd, atcmd_output );
return false;
}
else if ( ( message[0] == 'B' || message[0] == 'S' || message[0] == 'T' ) && message[1] == '>' ) {
struct s_mapiterator* iter = mapit->alloc( MAPIT_NORMAL, BL_PC );
char atcmd_output[CHAT_SIZE_MAX];
short msg_len = 0;
int announcement_color = 0xFFC0CB;
int colorcode = (announcement_color & 0x0000FF) << 16 | (announcement_color & 0x00FF00) | (announcement_color & 0xFF0000) >> 16;
TBL_PC *psd;
safesnprintf( atcmd_output, CHAT_SIZE_MAX, "[Market] %s : %s", sd->status.name, message );
msg_len = strlen(atcmd_output) +1;
for ( psd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); psd = (TBL_PC*)mapit->next(iter) ) {
WFIFOHEAD( psd->fd, msg_len + 12 );
WFIFOW( psd->fd, 0 ) = 0x2C1;
WFIFOW( psd->fd, 2 ) = msg_len + 12;
WFIFOL( psd->fd, 4 ) = 0;
WFIFOL( psd->fd, 8 ) = colorcode;
safestrncpy( (char*)WFIFOP( psd->fd,12 ), atcmd_output, msg_len );
WFIFOSET( psd->fd, msg_len + 12 );
}
mapit->free(iter);
pc->setreg( sd, script->add_str("@bst_delay"), (int)time(NULL) );
return true;
}
else {
clif->message( fd, "Market Symbol is Needed when using this command ( B> S> T> )." );
return false;
}
}
HPExport void plugin_init (void) {
clif = GET_SYMBOL("clif");
session = GET_SYMBOL("session");
strlib = GET_SYMBOL("strlib");
sockt = GET_SYMBOL("sockt");
iMalloc = GET_SYMBOL("iMalloc");
mapit = GET_SYMBOL("mapit");
script = GET_SYMBOL("script");
pc = GET_SYMBOL("pc");
addAtcommand("bst",bst);
}