static void mapif_parse_Mail_send(int fd) { struct mail_message msg; char esc_name[NAME_LENGTH*2+1]; int account_id = 0; if(RFIFOW(fd,2) != 8 + sizeof(struct mail_message)) return; account_id = RFIFOL(fd,4); memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message)); // Try to find the Dest Char by Name Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); else if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { char *data; Sql_GetData(sql_handle, 0, &data, NULL); if (atoi(data) != account_id) { // Cannot send mail to char in the same account Sql_GetData(sql_handle, 1, &data, NULL); msg.dest_id = atoi(data); } } Sql_FreeResult(sql_handle); msg.status = MAIL_NEW; if( msg.dest_id > 0 ) msg.id = mail_savemessage(&msg); mapif_Mail_send(fd, &msg); }
bool mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item, int amount) { struct mail_message msg; memset(&msg, 0, sizeof(struct mail_message)); msg.send_id = send_id; safestrncpy(msg.send_name, send_name, NAME_LENGTH); msg.dest_id = dest_id; safestrncpy(msg.dest_name, dest_name, NAME_LENGTH); safestrncpy(msg.title, title, MAIL_TITLE_LENGTH); safestrncpy(msg.body, body, MAIL_BODY_LENGTH); msg.zeny = zeny; if( item != NULL ){ int i; for( i = 0; i < amount && i < MAIL_MAX_ITEM; i++ ){ memcpy(&msg.item[i], &item[i], sizeof(struct item)); } } msg.timestamp = time(NULL); msg.type = MAIL_INBOX_NORMAL; if( !mail_savemessage(&msg) ){ return false; } mapif_Mail_new(&msg); return true; }
void mapif_parse_Mail_send(int fd) { struct mail_message msg; char esc_name[NAME_LENGTH*2+1]; char *data; size_t len; if(RFIFOW(fd,2) != 8 + sizeof(struct mail_message)) return; memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message)); if( msg.dest_id != 0 ){ if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name` FROM `%s` WHERE `char_id` = '%u'", schema_config.char_db, msg.dest_id) ){ Sql_ShowDebug(sql_handle); return; } msg.dest_id = 0; msg.dest_name[0] = '\0'; if( SQL_SUCCESS == Sql_NextRow(sql_handle) ){ Sql_GetData(sql_handle, 0, &data, NULL); msg.dest_id = atoi(data); Sql_GetData(sql_handle, 1, &data, &len); safestrncpy(msg.dest_name, data, NAME_LENGTH); } Sql_FreeResult(sql_handle); } // Try to find the Dest Char by Name Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) ){ Sql_ShowDebug(sql_handle); }else if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ){ #if PACKETVER < 20150513 uint32 account_id = RFIFOL(fd,4); Sql_GetData(sql_handle, 0, &data, NULL); if (atoi(data) != account_id) { // Cannot send mail to char in the same account Sql_GetData(sql_handle, 1, &data, NULL); msg.dest_id = atoi(data); } #else // In RODEX you can even send mails to yourself Sql_GetData(sql_handle, 1, &data, NULL); msg.dest_id = atoi(data); #endif } Sql_FreeResult(sql_handle); msg.status = MAIL_NEW; if( msg.dest_id > 0 ) msg.id = mail_savemessage(&msg); mapif_Mail_send(fd, &msg); // notify sender mapif_Mail_new(&msg); // notify recipient }
/*========================================== * Return Mail *------------------------------------------*/ void mapif_Mail_return(int fd, uint32 char_id, int mail_id) { struct mail_message msg; int new_mail = 0; if( mail_loadmessage(mail_id, &msg) ) { if( msg.dest_id != char_id) return; else if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_db, mail_id) || SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_attachment_db, mail_id) ) Sql_ShowDebug(sql_handle); // If it was not sent by the server, since we do not want to return mails to the server else if( msg.send_id != 0 ) { char temp_[MAIL_TITLE_LENGTH + 3]; // swap sender and receiver SWAP(msg.send_id, msg.dest_id); safestrncpy(temp_, msg.send_name, NAME_LENGTH); safestrncpy(msg.send_name, msg.dest_name, NAME_LENGTH); safestrncpy(msg.dest_name, temp_, NAME_LENGTH); // set reply message title snprintf(temp_, sizeof(temp_), "RE:%s", msg.title); safestrncpy(msg.title, temp_, sizeof(temp_)); msg.status = MAIL_NEW; msg.type = MAIL_INBOX_RETURNED; msg.timestamp = time(NULL); new_mail = mail_savemessage(&msg); mapif_Mail_new(&msg); } } // Only if the request came from a map-server and was not timer triggered for an offline character if( fd <= 0 ){ return; } WFIFOHEAD(fd,11); WFIFOW(fd,0) = 0x384c; WFIFOL(fd,2) = char_id; WFIFOL(fd,6) = mail_id; WFIFOB(fd,10) = (new_mail == 0); WFIFOSET(fd,11); }
void mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item) { struct mail_message msg; memset(&msg, 0, sizeof(struct mail_message)); msg.send_id = send_id; safestrncpy(msg.send_name, send_name, NAME_LENGTH); msg.dest_id = dest_id; safestrncpy(msg.dest_name, dest_name, NAME_LENGTH); safestrncpy(msg.title, title, MAIL_TITLE_LENGTH); safestrncpy(msg.body, body, MAIL_BODY_LENGTH); msg.zeny = zeny; if( item != NULL ) memcpy(&msg.item, item, sizeof(struct item)); msg.timestamp = time(NULL); mail_savemessage(&msg); mapif_Mail_new(&msg); }
/*========================================== * Return Mail *------------------------------------------*/ static void mapif_Mail_return(int fd, int char_id, int mail_id) { struct mail_message msg; int new_mail = 0; if( mail_loadmessage(mail_id, &msg) ) { if( msg.dest_id != char_id) return; else if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) Sql_ShowDebug(sql_handle); else { char temp_[MAIL_TITLE_LENGTH]; // swap sender and receiver swap(msg.send_id, msg.dest_id); safestrncpy(temp_, msg.send_name, NAME_LENGTH); safestrncpy(msg.send_name, msg.dest_name, NAME_LENGTH); safestrncpy(msg.dest_name, temp_, NAME_LENGTH); // set reply message title snprintf(temp_, MAIL_TITLE_LENGTH, "RE:%s", msg.title); safestrncpy(msg.title, temp_, MAIL_TITLE_LENGTH); msg.status = MAIL_NEW; msg.timestamp = time(NULL); new_mail = mail_savemessage(&msg); mapif_Mail_new(&msg); } } WFIFOHEAD(fd,11); WFIFOW(fd,0) = 0x384c; WFIFOL(fd,2) = char_id; WFIFOL(fd,6) = mail_id; WFIFOB(fd,10) = (new_mail == 0); WFIFOSET(fd,11); }