viewing paste Unknown #15568 | 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
// @commands (script based)
int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const char* message, const char* eventname)
{
    struct event_data* ev = (struct event_data*)strdb_get(ev_db, eventname);
    struct npc_data *nd;
    struct script_state *st;
    int i = 0, j = 0, k = 0, a = 0;
    char *temp;
 
    nullpo_ret(sd);
 
    if( ev == NULL || (nd = ev->nd) == NULL ) {
        ShowError("npc_event: event not found [%s]\n", eventname);
        return 0;
    }
 
    if( sd->npc_id != 0 ) { // Enqueue the event trigger.
        int i;
        ARR_FIND( 0, MAX_EVENTQUEUE, i, sd->eventqueue[i][0] == '\0' );
        if( i < MAX_EVENTQUEUE ) {
            safestrncpy(sd->eventqueue[i],eventname,50); //Event enqueued.
            return 0;
        }
 
        ShowWarning("npc_event: player's event queue is full, can't add event '%s' !\n", eventname);
        return 1;
    }
 
    if( ev->nd->sc.option&OPTION_INVISIBLE ) { // Disabled npc, shouldn't trigger event.
        npc_event_dequeue(sd);
        return 2;
    }
 
    st = script_alloc_state(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id);
    setd_sub(st, NULL, ".@atcmd_command$", 0, (void *)command, NULL);
        temp = (char*)aMalloc(strlen(message) + 1);
        for( i = 0; i < ( strlen( message ) + 1 ) && k < 127; i ++ ) {
            if( message[i] == ' ' || message[i] == '\0' || message[i] == '"') {
                if( message[ ( i - 1 ) ] == ' ' ) {
                    continue; // To prevent "@atcmd [space][space][space]..."
                }
                if(message[i] == '"'){
                    i++;
                    while(message[i] != '"' && k < 127) {
                        temp[k] = message[i];
                        k++;    
                        i++;
                    }
                }else{
                    temp[k] = '\0';
                    k = 0;
                    setd_sub( st, NULL, ".@atcmd_parameters$", j++, (void *)temp, NULL );
                }
            } else {
                if(message[i - 1] == '"'){
                    clif->message(sd->fd, "Wrong input.");
                    clif->message(sd->fd, "@jail <value1> <value2> ...");
                    return -1;
                }
                temp[k] = message[i];
                k++;
            }
        }
        //}
        setd_sub(st, NULL, ".@atcmd_numparameters", 0, (void *)__64BPRTSIZE(j), NULL);
        aFree(temp);
 
        run_script_main(st);   return 0;
}
Viewed 552 times, submitted by Guest.