summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/clif.c3
-rw-r--r--src/map/mail.c147
2 files changed, 69 insertions, 81 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 5d34e0f64..03622cfe3 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -4713,6 +4713,9 @@ int clif_status_change(struct block_list *bl,int type,int flag)
*/
int clif_displaymessage(const int fd, char* mes)
{
+ // invalid pointer?
+ nullpo_retr(-1, mes);
+
//Console [Wizputer]
if (fd == 0)
printf("\033[0;36mConsole: \033[0m\033[1m%s\033[0m\n", mes);
diff --git a/src/map/mail.c b/src/map/mail.c
index 74d2bf7c0..204ba9392 100644
--- a/src/map/mail.c
+++ b/src/map/mail.c
@@ -30,13 +30,13 @@ extern char msg_table[1000][256]; // Server messages (0-499 reserved for GM comm
int mail_check(struct map_session_data *sd,int type)
{
- int i=0,new_=0,priority=0;
+ int i = 0, new_ = 0, priority = 0;
char message[50];
- if(sd==NULL)
- return 0;
+ nullpo_retr (0, sd);
- sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`read_flag`,`priority`,`check_flag` FROM `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id`", mail_db, sd->status.account_id);
+ sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`read_flag`,`priority`,`check_flag"
+ "FROM `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id`", mail_db, sd->status.account_id);
if (mysql_query(&mail_handle, tmp_msql)) {
printf("Database server error (executing query for %s): %s\n", mail_db, mysql_error(&mail_handle));
@@ -45,58 +45,51 @@ int mail_check(struct map_session_data *sd,int type)
mail_res = mysql_store_result(&mail_handle);
if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
+ if (mysql_num_rows(mail_res) == 0) {
//clif_displaymessage(sd->fd,"You have no messages.");
clif_displaymessage(sd->fd,msg_table[516]);
- mysql_free_result(mail_res);
- return 0;
- }
-
- while ((mail_row = mysql_fetch_row(mail_res))) {
- i++;
+ mysql_free_result(mail_res);
+ return 0;
+ }
- if(!atoi(mail_row[5])) {
+ while ((mail_row = mysql_fetch_row(mail_res))) {
+ i++;
+ if(!atoi(mail_row[5])) {
sprintf(tmp_msql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_msql) ) {
- printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
- }
+ if(mysql_query(&mail_handle, tmp_msql) ) {
+ printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
}
+ }
- if(!atoi(mail_row[3])) {
- new_++;
- if(atoi(mail_row[4]))
- priority++;
- if(type==2 || type==3) {
- if(atoi(mail_row[4])) {
- //sprintf(message, "%d - From : %s (New - Priority)", i, mail_row[2]);
- sprintf(message, msg_table[511], i, mail_row[2]);
-
- clif_displaymessage(sd->fd, jstrescape(message));
- }
-
- else {
- //sprintf(message, "%d - From : %s (New)", i, mail_row[2]);
- sprintf(message, msg_table[512], i, mail_row[2]);
- clif_displaymessage(sd->fd, jstrescape(message));
- }
- }
- }
+ if(!atoi(mail_row[3])) {
+ new_++;
+ if(atoi(mail_row[4]))
+ priority++;
+ if(type==2 || type==3) {
+ if(atoi(mail_row[4])) {
+ //sprintf(message, "%d - From : %s (New - Priority)", i, mail_row[2]);
+ sprintf(message, msg_table[511], i, mail_row[2]);
- else if(type==2){
- //sprintf(message, "%d - From : %s", i, mail_row[2]);
- sprintf(message, msg_table[513], i, mail_row[2]);
+ clif_displaymessage(sd->fd, jstrescape(message));
+ } else {
+ //sprintf(message, "%d - From : %s (New)", i, mail_row[2]);
+ sprintf(message, msg_table[512], i, mail_row[2]);
clif_displaymessage(sd->fd, jstrescape(message));
}
-
- }
+ }
+ } else if(type==2){
+ //sprintf(message, "%d - From : %s", i, mail_row[2]);
+ sprintf(message, msg_table[513], i, mail_row[2]);
+ clif_displaymessage(sd->fd, jstrescape(message));
+ }
+ }
mysql_free_result(mail_res);
-
} else {
- printf("MySQL error (storing query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
+ printf("MySQL error (storing query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
return 0;
- }
+ }
if(i>0 && new_>0 && type==1) {
//sprintf(message, "You have %d new messages.", new_);
@@ -122,8 +115,7 @@ int mail_read(struct map_session_data *sd, int message_id)
char message[80];
- if(sd==NULL)
- return 0;
+ nullpo_retr (0, sd);
sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`message`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id` LIMIT %d, 1",mail_db,sd->status.account_id,message_id-1);
@@ -134,20 +126,19 @@ int mail_read(struct map_session_data *sd, int message_id)
mail_res = mysql_store_result(&mail_handle);
if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- mysql_free_result(mail_res);
+ if (mysql_num_rows(mail_res) == 0) {
+ mysql_free_result(mail_res);
//clif_displaymessage(sd->fd, "Message not found.");
clif_displaymessage(sd->fd, msg_table[517]);
- return 0;
- }
-
- if ((mail_row = mysql_fetch_row(mail_res))) {
+ return 0;
+ }
+ if ((mail_row = mysql_fetch_row(mail_res))) {
if(!atoi(mail_row[6])) {
sprintf(tmp_msql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_msql) ) {
- printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
- }
+ if(mysql_query(&mail_handle, tmp_msql) ) {
+ printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
+ }
}
//sprintf(message, "Reading message from %s", mail_row[2]);
@@ -158,25 +149,23 @@ int mail_read(struct map_session_data *sd, int message_id)
clif_displaymessage(sd->fd, jstrescape(message));
sprintf(tmp_msql,"UPDATE `%s` SET `read_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_msql) ) {
+ if(mysql_query(&mail_handle, tmp_msql) ) {
printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
- }
+ }
}
mysql_free_result(mail_res);
} else {
- printf("MySQL error (storing query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
- return 0;
- }
+ printf("MySQL error (storing query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
+ }
return 0;
}
int mail_delete(struct map_session_data *sd, int message_id)
{
- if(sd==NULL)
- return 0;
+ nullpo_retr (0, sd);
sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id` LIMIT %d, 1",mail_db,sd->status.account_id,message_id-1);
@@ -187,14 +176,14 @@ int mail_delete(struct map_session_data *sd, int message_id)
mail_res = mysql_store_result(&mail_handle);
if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- mysql_free_result(mail_res);
+ if (mysql_num_rows(mail_res) == 0) {
+ mysql_free_result(mail_res);
//clif_displaymessage(sd->fd, "Message not found.");
clif_displaymessage(sd->fd, msg_table[517]);
- return 0;
- }
+ return 0;
+ }
- if ((mail_row = mysql_fetch_row(mail_res))) {
+ if ((mail_row = mysql_fetch_row(mail_res))) {
if(!atoi(mail_row[2]) && atoi(mail_row[3])) {
mysql_free_result(mail_res);
//clif_displaymessage(sd->fd,"Cannot delete unread priority mail.");
@@ -221,17 +210,15 @@ int mail_delete(struct map_session_data *sd, int message_id)
mysql_free_result(mail_res);
} else {
- printf("MySQL error (delete query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
- return 0;
- }
+ printf("MySQL error (delete query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
+ }
return 0;
}
int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
{
- if(sd==NULL)
- return 0;
+ nullpo_retr (0, sd);
if(pc_isGM(sd) < 80 && sd->mail_counter > 0) {
//clif_displaymessage(sd->fd,"You must wait 10 minutes before sending another message");
@@ -258,14 +245,14 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
mail_res = mysql_store_result(&mail_handle);
if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
+ if (mysql_num_rows(mail_res) == 0) {
mysql_free_result(mail_res);
//clif_displaymessage(sd->fd,"Character does not exist.");
clif_displaymessage(sd->fd,msg_table[524]);
- return 0;
- }
+ return 0;
+ }
- while ((mail_row = mysql_fetch_row(mail_res))) {
+ while ((mail_row = mysql_fetch_row(mail_res))) {
if(strcmp(name,"*")==0) {
sprintf(tmp_msql, "INSERT DELAYED INTO `%s` (`to_account_id`,`from_account_id`,`from_char_name`,`message`,`priority`)"
" VALUES ('%d', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), sd->status.account_id, sd->status.name, jstrescape(message), flag);
@@ -282,7 +269,6 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
printf("DB server Error (insert `mail_db`)- %s\n", mysql_error(&mail_handle) );
return 0;
}
-
}
}
@@ -311,14 +297,13 @@ int mail_check_timer(int tid,unsigned int tick,int id,int data)
mail_res = mysql_store_result(&mail_handle);
if (mail_res) {
-
- if (mysql_num_rows(mail_res) == 0) {
+ if (mysql_num_rows(mail_res) == 0) {
mysql_free_result(mail_res);
mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
- return 0;
- }
+ return 0;
+ }
- while ((mail_row = mysql_fetch_row(mail_res))) {
+ while ((mail_row = mysql_fetch_row(mail_res))) {
for (i = 0; i < fd_max; i++) {
if (session[i] && (sd = session[i]->session_data) && sd->state.auth){
if(pc_isGM(sd) < 80 && sd->mail_counter > 0)
@@ -332,7 +317,7 @@ int mail_check_timer(int tid,unsigned int tick,int id,int data)
}
sprintf(tmp_msql,"UPDATE `%s` SET `check_flag`='1' WHERE `check_flag`= '0' ", mail_db);
- if(mysql_query(&mail_handle, tmp_msql) ) {
+ if(mysql_query(&mail_handle, tmp_msql) ) {
printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
}