@@ -346,11 +346,128 @@ static int64 inter_rodex_savemessage(struct rodex_message *msg)
346346 return msg -> id ;
347347}
348348
349+ static int64 inter_rodex_getzeny (int64 mail_id )
350+ {
351+ Assert_retr (-1 , mail_id > 0 );
352+
353+ if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "SELECT `zeny`, `type` FROM `%s` WHERE `mail_id` = '%" PRId64 "'" , rodex_db , mail_id )) {
354+ Sql_ShowDebug (inter -> sql_handle );
355+ } else {
356+ if (SQL_SUCCESS == SQL -> NextRow (inter -> sql_handle )) {
357+ char * data ;
358+ SQL -> GetData (inter -> sql_handle , 0 , & data , NULL );
359+ int64 zeny = atoi (data );
360+ SQL -> GetData (inter -> sql_handle , 1 , & data , NULL );
361+ uint8 type = atoi (data );
362+ SQL -> FreeResult (inter -> sql_handle );
363+ if ((type & MAIL_TYPE_ZENY ) == 0 )
364+ return -1 ;
365+ return zeny ;
366+ }
367+ }
368+ SQL -> FreeResult (inter -> sql_handle );
369+
370+ return -1 ;
371+ }
372+
373+ static int inter_rodex_getitems (int64 mail_id , struct rodex_item * items )
374+ {
375+ Assert_retr (-1 , mail_id > 0 );
376+ nullpo_retr (-1 , items );
377+
378+ if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "SELECT `type` FROM `%s` WHERE `mail_id` = '%" PRId64 "'" , rodex_db , mail_id )) {
379+ Sql_ShowDebug (inter -> sql_handle );
380+ return -1 ;
381+ } else {
382+ if (SQL_SUCCESS == SQL -> NextRow (inter -> sql_handle )) {
383+ char * data ;
384+ SQL -> GetData (inter -> sql_handle , 0 , & data , NULL );
385+ uint8 type = atoi (data );
386+ SQL -> FreeResult (inter -> sql_handle );
387+ if ((type & MAIL_TYPE_ITEM ) == 0 )
388+ return -1 ;
389+ } else {
390+ SQL -> FreeResult (inter -> sql_handle );
391+ return -1 ;
392+ }
393+ }
394+
395+
396+ int itemsCount = 0 ;
397+
398+ struct SqlStmt * stmt_items = SQL -> StmtMalloc (inter -> sql_handle );
399+
400+ if (stmt_items == NULL ) {
401+ return -1 ;
402+ }
403+
404+ StringBuf buf ;
405+ StrBuf -> Init (& buf );
406+
407+ StrBuf -> AppendStr (& buf , "SELECT `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`" );
408+ for (int i = 0 ; i < MAX_SLOTS ; i ++ ) {
409+ StrBuf -> Printf (& buf , ", `card%d`" , i );
410+ }
411+ for (int i = 0 ; i < MAX_ITEM_OPTIONS ; i ++ ) {
412+ StrBuf -> Printf (& buf , ", `opt_idx%d`, `opt_val%d`" , i , i );
413+ }
414+ StrBuf -> Printf (& buf , "FROM `%s` WHERE mail_id = ? ORDER BY `mail_id` ASC" , rodex_item_db );
415+
416+ struct item it = { 0 };
417+
418+ if (SQL_ERROR == SQL -> StmtPrepareStr (stmt_items , StrBuf -> Value (& buf ))
419+ || SQL_ERROR == SQL -> StmtBindParam (stmt_items , 0 , SQLDT_INT64 , & mail_id , sizeof mail_id )
420+ ) {
421+ SqlStmt_ShowDebug (stmt_items );
422+ }
423+
424+ if (SQL_ERROR == SQL -> StmtExecute (stmt_items )
425+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 0 , SQLDT_INT , & it .nameid , sizeof it .nameid , NULL , NULL )
426+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 1 , SQLDT_SHORT , & it .amount , sizeof it .amount , NULL , NULL )
427+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 2 , SQLDT_UINT , & it .equip , sizeof it .equip , NULL , NULL )
428+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 3 , SQLDT_CHAR , & it .identify , sizeof it .identify , NULL , NULL )
429+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 4 , SQLDT_CHAR , & it .refine , sizeof it .refine , NULL , NULL )
430+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 5 , SQLDT_CHAR , & it .attribute , sizeof it .attribute , NULL , NULL )
431+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 6 , SQLDT_UINT , & it .expire_time , sizeof it .expire_time , NULL , NULL )
432+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 7 , SQLDT_UCHAR , & it .bound , sizeof it .bound , NULL , NULL )
433+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 8 , SQLDT_UINT64 , & it .unique_id , sizeof it .unique_id , NULL , NULL )
434+ ) {
435+ SqlStmt_ShowDebug (stmt_items );
436+ }
437+ for (int i = 0 ; i < MAX_SLOTS ; i ++ ) {
438+ if (SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 9 + i , SQLDT_INT , & it .card [i ], sizeof it .card [i ], NULL , NULL ))
439+ SqlStmt_ShowDebug (stmt_items );
440+ }
441+ for (int i = 0 ; i < MAX_ITEM_OPTIONS ; i ++ ) {
442+ if (SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 9 + MAX_SLOTS + i * 2 , SQLDT_INT16 , & it .option [i ].index , sizeof it .option [i ].index , NULL , NULL )
443+ || SQL_ERROR == SQL -> StmtBindColumn (stmt_items , 10 + MAX_SLOTS + i * 2 , SQLDT_INT16 , & it .option [i ].value , sizeof it .option [i ].value , NULL , NULL )
444+ ) {
445+ SqlStmt_ShowDebug (stmt_items );
446+ }
447+ }
448+
449+ for (int i = 0 ; i < RODEX_MAX_ITEM && SQL_SUCCESS == SQL -> StmtNextRow (stmt_items ); ++ i ) {
450+ items [i ].item = it ;
451+ items [i ].idx = itemsCount ;
452+ itemsCount ++ ;
453+ }
454+
455+ SQL -> StmtFreeResult (stmt_items );
456+
457+ StrBuf -> Destroy (& buf );
458+ SQL -> StmtFree (stmt_items );
459+
460+ return itemsCount ;
461+ }
462+
349463/*==========================================
350464 * Update/Delete mail
351465 *------------------------------------------*/
352- static bool inter_rodex_updatemail (int64 mail_id , int8 flag )
466+ static bool inter_rodex_updatemail (int fd , int account_id , int char_id , int64 mail_id , uint8 opentype , int8 flag )
353467{
468+ Assert_retr (false, fd >= 0 );
469+ Assert_retr (false, account_id > 0 );
470+ Assert_retr (false, char_id > 0 );
354471 Assert_retr (false, mail_id > 0 );
355472 Assert_retr (false, flag >= 0 && flag <= 4 );
356473
@@ -361,17 +478,26 @@ static bool inter_rodex_updatemail(int64 mail_id, int8 flag)
361478 break ;
362479
363480 case 1 : // Get Zeny
364- if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "UPDATE `%s` SET `zeny` = 0, `type` = `type` & (~2) WHERE `mail_id` = '%" PRId64 "'" , rodex_db , mail_id ))
481+ {
482+ const int64 zeny = inter_rodex -> getzeny (mail_id );
483+ if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "UPDATE `%s` SET `zeny` = 0, `type` = `type` & (~2) WHERE `mail_id` = '%" PRId64 "'" , rodex_db , mail_id )) {
365484 Sql_ShowDebug (inter -> sql_handle );
485+ break ;
486+ }
487+ mapif -> rodex_getzenyack (fd , char_id , mail_id , opentype , zeny );
366488 break ;
367-
489+ }
368490 case 2 : // Get Items
491+ {
492+ struct rodex_item items [RODEX_MAX_ITEM ];
493+ const int count = inter_rodex -> getitems (mail_id , & items [0 ]);
369494 if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "DELETE FROM `%s` WHERE `mail_id` = '%" PRId64 "'" , rodex_item_db , mail_id ))
370495 Sql_ShowDebug (inter -> sql_handle );
371496 if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "UPDATE `%s` SET `zeny` = 0, `type` = `type` & (~4) WHERE `mail_id` = '%" PRId64 "'" , rodex_db , mail_id ))
372497 Sql_ShowDebug (inter -> sql_handle );
498+ mapif -> rodex_getitemsack (fd , char_id , mail_id , opentype , count , & items [0 ]);
373499 break ;
374-
500+ }
375501 case 3 : // Delete Mail
376502 if (SQL_ERROR == SQL -> Query (inter -> sql_handle , "DELETE FROM `%s` WHERE `mail_id` = '%" PRId64 "'" , rodex_db , mail_id ))
377503 Sql_ShowDebug (inter -> sql_handle );
@@ -429,4 +555,6 @@ void inter_rodex_defaults(void)
429555 inter_rodex -> hasnew = inter_rodex_hasnew ;
430556 inter_rodex -> checkname = inter_rodex_checkname ;
431557 inter_rodex -> updatemail = inter_rodex_updatemail ;
558+ inter_rodex -> getzeny = inter_rodex_getzeny ;
559+ inter_rodex -> getitems = inter_rodex_getitems ;
432560}
0 commit comments