viewing paste topic/7157 - bst.c | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#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)
};
 
struct player_data {
    int bst_delay;
};
 
ACMD(bst) {
    struct player_data *ssd;
    int announcement_delay = 5;
    if ( !( ssd = getFromMSD(sd,0) ) ) {
        CREATE( ssd, struct player_data, 1 );
        ssd->bst_delay = 0;
        addToMSD( sd, ssd, 0, true );
    }
    if ( !message || !*message ) {
        clif->message(fd, "Please, enter a message (usage: @bst <message>).");
        return false;
    }
    else if ( ssd->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);
        ssd->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");
 
    addAtcommand("bst",bst);
}
Viewed 1269 times, submitted by AnnieRuru.