int mail_read(struct map_session_data *sd, int message_id) { char message[80]; nullpo_retr (0, sd); sprintf(tmp_sql,"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); if (mysql_query(&mail_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } mail_res = mysql_store_result(&mail_handle); if(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_txt(517)); return 0; } if ((mail_row = mysql_fetch_row(mail_res))) { if(!atoi(mail_row[6])) { sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0])); if(mysql_query(&mail_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } //sprintf(message, "Reading message from %s", mail_row[2]); sprintf(message, msg_txt(518), mail_row[2]); clif_displaymessage(sd->fd, jstrescape(message)); sprintf(message, "%s", mail_row[3]); clif_displaymessage(sd->fd, jstrescape(message)); sprintf(tmp_sql,"UPDATE `%s` SET `read_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0])); if(mysql_query(&mail_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } mysql_free_result(mail_res); } else { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } return 0; }
int mail_check(struct map_session_data *sd,int type) { int i = 0, new_ = 0, priority = 0; char message[80]; nullpo_retr (0, sd); sprintf(tmp_sql,"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_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } mail_res = mysql_store_result(&mail_handle); if(mail_res) { if (mysql_num_rows(mail_res) == 0) { //clif_displaymessage(sd->fd,"You have no messages."); clif_displaymessage(sd->fd, msg_txt(516)); mysql_free_result(mail_res); return 0; } while ((mail_row = mysql_fetch_row(mail_res))) { i++; if(!atoi(mail_row[5])) { sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0])); if(mysql_query(&mail_handle, tmp_sql) ) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } if(!atoi(mail_row[3])) { new_++; if(atoi(mail_row[4])) priority++; if(type==2 || type==3) { if(atoi(mail_row[4])) { snprintf(message, 80, msg_txt(511), i, mail_row[2]); clif_displaymessage(sd->fd, message); } else { //sprintf(message, "%d - From : %s (New)", i, mail_row[2]); snprintf(message, 80, msg_txt(512), i, mail_row[2]); clif_displaymessage(sd->fd, message); } } } else if(type==2){ snprintf(message, 80, msg_txt(513), i, mail_row[2]); clif_displaymessage(sd->fd, message); } } mysql_free_result(mail_res); } else { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } if(i>0 && new_>0 && type==1) { //sprintf(message, "You have %d new messages.", new_); sprintf(message, msg_txt(514), new_); clif_displaymessage(sd->fd, jstrescape(message)); } if(i>0 && new_>0 && priority>0 && type==1) { //sprintf(message, "You have %d unread priority messages.", priority); sprintf(message, msg_txt(515), priority); clif_displaymessage(sd->fd, jstrescape(message)); } if(!new_) { //clif_displaymessage(sd->fd, "You have no new messages."); clif_displaymessage(sd->fd, msg_txt(516)); } return 0; }
int mail_send(struct map_session_data *sd, char *name, char *message, int flag) { 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"); clif_displaymessage(sd->fd,msg_txt(522)); return 0; } if(strcmp(name,"*")==0) { if(pc_isGM(sd) < 80) { //clif_displaymessage(sd->fd, "Access Denied."); clif_displaymessage(sd->fd, msg_txt(523)); return 0; } else sprintf(tmp_sql,"SELECT DISTINCT `account_id` FROM `%s` WHERE `account_id` <> '%d' ORDER BY `account_id`", char_db, sd->status.account_id); } else sprintf(tmp_sql,"SELECT `account_id`,`name` FROM `%s` WHERE `name` = \"%s\"", char_db, jstrescape(name)); if (mysql_query(&mail_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } mail_res = mysql_store_result(&mail_handle); if(mail_res) { 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_txt(524)); return 0; } while ((mail_row = mysql_fetch_row(mail_res))) { if(strcmp(name,"*")==0) { sprintf(tmp_sql, "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); } else { sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`to_account_id`,`to_char_name`,`from_account_id`,`from_char_name`,`message`,`priority`)" " VALUES ('%d', '%s', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), mail_row[1], sd->status.account_id, sd->status.name, jstrescape(message), flag); if(pc_isGM(sd) < 80) sd->mail_counter=5; } if(mysql_query(&mail_handle, tmp_sql) ) { mysql_free_result(mail_res); ShowSQL("DB error - %s\n",mysql_error(&mail_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); return 0; } } } //clif_displaymessage(sd->fd,"Mail has been sent."); clif_displaymessage(sd->fd,msg_txt(525)); return 0; }
// Save party to mysql int inter_party_tosql(int party_id,struct party *p) { // 'party' ('party_id','name','exp','item','leader') char t_name[100]; int party_member = 0, party_online_member = 0; int party_exist = 0; int leader_id = 0; printf("Request save party: %d.......\n",party_id); jstrescapecpy(t_name, p->name); if (p==NULL || party_id==0 || p->party_id ==0 || party_id!=p->party_id) { printf("- Party pointer or party_id error \n"); return 0; } // Check if party exists sprintf(tmp_sql,"SELECT count(*) FROM `party` WHERE `party_id`='%d'",party_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); return 0; } sql_res = mysql_store_result(&mysql_handle) ; if (mysql_num_rows(sql_res)>0) { sql_row = mysql_fetch_row(sql_res); party_exist = atoi (sql_row[0]); printf("- Check if party %d exists : %s\n",party_id,party_exist==0?"No":"Yes"); } mysql_free_result(sql_res) ; //resource free if (party_exist >0){ // Check members in party sprintf(tmp_sql,"SELECT count(*) FROM `char` WHERE `party_id`='%d'",party_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); return 0; } sql_res = mysql_store_result(&mysql_handle) ; if (mysql_num_rows(sql_res)>0) { sql_row = mysql_fetch_row(sql_res); party_member = atoi (sql_row[0]); printf("- Check members in party %d : %d \n",party_id,party_member); } mysql_free_result(sql_res) ; //resource free party_online_member = 0; while (party_online_member<MAX_PARTY&&p->member[party_online_member].account_id<=0) party_online_member++; if (party_online_member==MAX_PARTY) printf("- No member online \n"); else printf("- Some member %d online \n", party_online_member); if (party_member <= 0 && party_online_member == MAX_PARTY) { // Delete the party, if has no member. sprintf(tmp_sql,"DELETE FROM `party` WHERE `party_id`='%d'",party_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); } printf("No member in party %d, break it \n",party_id); memset(p, 0, sizeof(struct party)); return 0; } else { // Update party information, if exists int i=0; for (i=0;i<MAX_PARTY;i++){ if (p->member[i].account_id>0){ sprintf(tmp_sql,"UPDATE `char` SET `party_id`='%d', `online`='%d' WHERE `account_id`='%d' AND BINARY `name`='%s';",party_id, p->member[i].online, p->member[i].account_id, jstrescape(p->member[i].name)); //printf("%s",tmp_sql); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (update `char`)- %s\n", mysql_error(&mysql_handle) ); } } } sprintf(tmp_sql,"UPDATE `party` SET `name`='%s', `exp`='%d', `item`='%d', `leader_id`=`leader_id` WHERE `party_id`='%d';",t_name,p->exp,p->item,party_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (inset/update `party`)- %s\n", mysql_error(&mysql_handle) ); } printf("- Update party %d information \n",party_id); } } else { // Add new party, if not exist int i = 0; while (i<MAX_PARTY&&((p->member[i].account_id>0&&p->member[i].leader==0)||(p->member[i].account_id<0))) i++; if (i<MAX_PARTY) leader_id = p->member[i].account_id; sprintf(tmp_sql,"INSERT INTO `party` (`party_id`, `name`, `exp`, `item`, `leader_id`) VALUES ('%d', '%s', '%d', '%d', '%d');",party_id, t_name, p->exp, p->item,leader_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (inset/update `party`)- %s\n", mysql_error(&mysql_handle) ); } sprintf(tmp_sql,"UPDATE `char` SET `party_id`='%d', `online`='1' WHERE `account_id`='%d' AND BINARY `name`='%s';",party_id,leader_id, jstrescape(p->member[i].name)); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (inset/update `party`)- %s\n", mysql_error(&mysql_handle) ); } printf("- Insert new party %d \n",party_id); } printf("Party save success.......\n"); return 0; }