summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c4
-rw-r--r--src/map/intif.c64
-rw-r--r--src/map/mail.c45
-rw-r--r--src/map/mail.h4
4 files changed, 62 insertions, 55 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index c5cab5987..0c5ff0362 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -11650,8 +11650,8 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd)
if (body_len > MAIL_BODY_LENGTH)
body_len = MAIL_BODY_LENGTH;
- if( !mail_getattach(sd, &msg) )
- {
+ if( !mail_setattachment(sd, &msg) )
+ { // Invalid Append condition
clif_Mail_send(sd->fd, 1); // fail
mail_removeitem(sd,0);
mail_removezeny(sd,0);
diff --git a/src/map/intif.c b/src/map/intif.c
index 089d776f6..3cced222f 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -34,7 +34,7 @@ static const int packet_len_table[]={
-1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
- 9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,10, 0, 0, //0x3840
+ 9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1560,19 +1560,9 @@ int intif_parse_Mail_getattach(int fd)
return 1;
}
- if (zeny > 0)
- {
- sd->status.zeny += zeny;
- clif_updatestatus(sd, SP_ZENY);
- }
-
memcpy(&item, RFIFOP(fd,12), sizeof(struct item));
- if (item.nameid > 0 && item.amount > 0)
- {
- pc_additem(sd, &item, item.amount);
- clif_Mail_getattachment(sd->fd, 0);
- }
+ mail_getattachment(sd, zeny, &item);
return 0;
}
/*------------------------------------------
@@ -1695,33 +1685,43 @@ int intif_Mail_send(int account_id, struct mail_message *msg)
static void intif_parse_Mail_send(int fd)
{
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- int mail_id = RFIFOL(fd,6);
- bool fail = false;
+ struct mail_message msg;
+ struct map_session_data *sd;
+ bool fail;
- if( mail_id == 0 )
- fail = true;
- else
+ if( RFIFOW(fd,2) - 4 != sizeof(struct mail_message) )
{
- fail = !mail_checkattach(sd);
-
- // Confirmation to CharServer
- WFIFOHEAD(inter_fd,7);
- WFIFOW(inter_fd,0) = 0x304e;
- WFIFOL(inter_fd,2) = mail_id;
- WFIFOB(inter_fd,6) = fail;
- WFIFOSET(inter_fd,7);
+ if (battle_config.error_log)
+ ShowError("intif_parse_Mail_send: data size error %d %d\n", RFIFOW(fd,2) - 4, sizeof(struct mail_message));
+ return;
}
- nullpo_retv(sd);
+ memcpy(&msg, RFIFOP(fd,4), sizeof(struct mail_message));
+ fail = (msg.id == 0);
- if( fail )
- { // Return items and zeny to owner
- mail_removeitem(sd, 0);
- mail_removezeny(sd, 0);
+ if( (sd = map_charid2sd(msg.send_id)) )
+ {
+ if( fail )
+ {
+ pc_additem(sd, &msg.item, msg.item.amount);
+ if( msg.zeny > 0 )
+ {
+ sd->status.zeny += msg.zeny;
+ clif_updatestatus(sd, SP_ZENY);
+ }
+ }
+
+ clif_Mail_send(sd->fd, fail);
}
- clif_Mail_send(sd->fd, fail);
+ if( fail )
+ return;
+
+ if( (sd = map_charid2sd(msg.dest_id)) )
+ {
+ sd->mail.inbox.changed = true;
+ clif_Mail_new(sd->fd, msg.id, msg.send_name, msg.title);
+ }
}
static void intif_parse_Mail_new(int fd)
diff --git a/src/map/mail.c b/src/map/mail.c
index e7cd6b2d6..9d2f4375e 100644
--- a/src/map/mail.c
+++ b/src/map/mail.c
@@ -9,6 +9,7 @@
#include "itemdb.h"
#include "clif.h"
#include "pc.h"
+#include "log.h"
#include <time.h>
#include <string.h>
@@ -26,7 +27,12 @@ int mail_removeitem(struct map_session_data *sd, short flag)
if( sd->mail.amount )
{
if (flag)
+ { // Item send
+ if(log_config.enable_logs&0x2000)
+ log_pick_pc(sd, "E", sd->mail.nameid, -sd->mail.amount, &sd->status.inventory[sd->mail.index]);
+
pc_delitem(sd, sd->mail.index, sd->mail.amount, 1);
+ }
else
clif_additem(sd, sd->mail.index, sd->mail.amount, 0);
}
@@ -72,7 +78,7 @@ unsigned char mail_setitem(struct map_session_data *sd, int idx, int amount)
return 1;
if( amount < 0 || amount > sd->status.inventory[idx].amount )
return 1;
- if( !itemdb_isdropable(&sd->status.inventory[idx], pc_isGM(sd)) )
+ if( !pc_candrop(sd, &sd->status.inventory[idx]) )
return 1;
sd->mail.index = idx;
@@ -83,12 +89,12 @@ unsigned char mail_setitem(struct map_session_data *sd, int idx, int amount)
}
}
-bool mail_getattach(struct map_session_data *sd, struct mail_message *msg)
+bool mail_setattachment(struct map_session_data *sd, struct mail_message *msg)
{
int n;
- nullpo_retr(0,sd);
- nullpo_retr(0,msg);
+ nullpo_retr(false,sd);
+ nullpo_retr(false,msg);
if( sd->mail.zeny < 0 || sd->mail.zeny > sd->status.zeny )
return false;
@@ -110,29 +116,30 @@ bool mail_getattach(struct map_session_data *sd, struct mail_message *msg)
msg->zeny = sd->mail.zeny;
+ // Removes the attachment from sender
+ mail_removeitem(sd,1);
+ mail_removezeny(sd,1);
+
return true;
}
-bool mail_checkattach(struct map_session_data *sd)
+void mail_getattachment(struct map_session_data* sd, int zeny, struct item* item)
{
- nullpo_retr(false,sd);
-
- if( sd->mail.zeny > 0 && sd->status.zeny < sd->status.zeny )
- return false;
-
- if( sd->mail.amount > 0 )
+ if( zeny > 0 )
{
- if( sd->status.inventory[sd->mail.index].nameid != sd->mail.nameid )
- return false;
-
- if( sd->status.inventory[sd->mail.index].amount < sd->mail.amount )
- return false;
+ sd->status.zeny += zeny;
+ clif_updatestatus(sd, SP_ZENY);
}
- mail_removeitem(sd,1);
- mail_removezeny(sd,1);
+ if( item->nameid > 0 && item->amount > 0 )
+ {
+ pc_additem(sd, item, item->amount);
- return true;
+ if(log_config.enable_logs&0x2000)
+ log_pick_pc(sd, "E", item->nameid, item->amount, item);
+
+ clif_Mail_getattachment(sd->fd, 0);
+ }
}
int mail_openmail(struct map_session_data *sd)
diff --git a/src/map/mail.h b/src/map/mail.h
index 1228f5772..1079fc560 100644
--- a/src/map/mail.h
+++ b/src/map/mail.h
@@ -11,8 +11,8 @@ time_t mail_calctimes(void);
int mail_removeitem(struct map_session_data *sd, short flag);
int mail_removezeny(struct map_session_data *sd, short flag);
unsigned char mail_setitem(struct map_session_data *sd, int idx, int amount);
-bool mail_getattach(struct map_session_data *sd, struct mail_message *msg);
-bool mail_checkattach(struct map_session_data *sd);
+bool mail_setattachment(struct map_session_data *sd, struct mail_message *msg);
+void mail_getattachment(struct map_session_data* sd, int zeny, struct item* item);
int mail_openmail(struct map_session_data *sd);
#endif /* _MAIL_H_ */