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?"),