viewing paste Unknown #1651 | 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
BUILDIN_FUNC(sendmail)
{
    struct mail_message msg;
    const char* body; 
    const char* title; 
    int zeny, nameid, amount;
    struct script_data *data;
 
 
    memset(&msg, '\0', sizeof (msg));
 
    amount = script_getnum(st, 4);
    zeny = script_getnum(st, 5);
    title = script_getstr(st, 6);
    body = script_getstr(st, 7);
 
    if (script_hasdata(st, 8))
    {
        const char* sender_name = script_getstr(st, 8);
 
        if (strlen(sender_name) < 4)
            safestrncpy(msg.send_name, "Server", NAME_LENGTH);
        else
            safestrncpy(msg.send_name, sender_name, NAME_LENGTH);
    }
    else
    {
        TBL_PC *sender_sd = script_rid2sd(st);
        
        if (sender_sd == NULL)
            safestrncpy(msg.send_name, "Server", strlen("Server")+1);
        else
        {
            msg.send_id = sender_sd->status.char_id;
            safestrncpy(msg.send_name, sender_sd->status.name, NAME_LENGTH);
        }
    }
    
    data = script_getdata(st, 2);
    get_val(st, data);
    
    if ( data_isint(data) )
    {
        int char_id = conv_num(st, data);
        const char *name;
        
        msg.dest_id = char_id;
        
        if ( (name = map_charid2nick(char_id)) != NULL )
            safestrncpy(msg.dest_name, name, NAME_LENGTH);
        else
        {
            ShowError("buildin_sendmail: Nonexistant destination char_id %d requested.\n", char_id);
            return 1; 
        }
    }
    else if ( data_isstring(data) )
    {
        const char* destination_name = conv_str(st, data);
        
        if (strlen(destination_name) < 4 ) // bad dest? then it fails!
        {
            ShowError("buildin_sendmail: Bad destination player %s requested.\n", destination_name);
            script_pushint(st, -1);
            return 1;
        }
        else
            safestrncpy(msg.dest_name, destination_name, NAME_LENGTH);
    }
    
    
    data = script_getdata(st, 3);
    get_val(st, data);
    
    if ( data_isstring(data) )
    {
        const char *name=conv_str(st,data);
        struct item_data *item_data = itemdb_searchname(name);
        
        if( item_data == NULL )
        {
            ShowError("buildin_sendmail: Nonexistant item %s requested.\n", name);
            return 1; //No item created.
        }
        
        nameid = item_data->nameid;
    }   
 
    if ( strlen(title) < 1 )
        safestrncpy(msg.title, "Mail Scripting System", MAIL_TITLE_LENGTH);
    else
        safestrncpy(msg.title, title, MAIL_TITLE_LENGTH );
    
    if ( strlen(body) < 1 || strlen(body) > MAIL_BODY_LENGTH)
        memset(msg.body, 0, MAIL_BODY_LENGTH);
    else
        safestrncpy(msg.body, body, strlen(body)+1);
        
    msg.status = MAIL_NEW;
    msg.timestamp = time(NULL);
    msg.zeny = zeny;
 
    if (amount)
    {
        msg.item.nameid = nameid;
        msg.item.amount = amount;
        msg.item.identify = 1;
    }
 
 
    script_pushint(st, intif_Mail_send(0, &msg));
 
    return 0;
}
 
 
 
    BUILDIN_DEF(sendmail, "vviiss?"),
Viewed 782 times, submitted by Guest.