Sfoglia il codice sorgente

* Removed confusing map_nick2sd_nocase(), let the charserver handle it
* Added correct packet for attachment retrieval failure when overweight
* Fixed one more mistake in r11571 (Sql->SqlStmt)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11579 54d463be-8e91-2dee-dedb-b68131a5f0ec

ultramage 17 anni fa
parent
commit
e0cccf7d12
7 ha cambiato i file con 60 aggiunte e 85 eliminazioni
  1. 3 0
      Changelog-Trunk.txt
  2. 1 0
      src/char/int_guild.c
  3. 22 24
      src/char_sql/int_mail.c
  4. 6 19
      src/map/clif.c
  5. 28 26
      src/map/intif.c
  6. 0 15
      src/map/map.c
  7. 0 1
      src/map/map.h

+ 3 - 0
Changelog-Trunk.txt

@@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
 2007/10/26
 2007/10/26
+	* Removed confusing map_nick2sd_nocase(), let the charserver handle it
+	* Added correct packet for attachment retrieval failure when overweight
+	* Fixed one more mistake in r11571 (Sql->SqlStmt) [ultramage]
 	* Removed the config setting firewall_hits_on_undead setting, Firewall and
 	* Removed the config setting firewall_hits_on_undead setting, Firewall and
 	  kaensin now automatically calculate the number of hits they should do per
 	  kaensin now automatically calculate the number of hits they should do per
 	  iteration based on the skill trigger frequency (you may want to raise that
 	  iteration based on the skill trigger frequency (you may want to raise that

+ 1 - 0
src/char/int_guild.c

@@ -8,6 +8,7 @@
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/lock.h"
 #include "../common/lock.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
+#include "../common/strlib.h"
 #include "char.h"
 #include "char.h"
 #include "inter.h"
 #include "inter.h"
 #include "int_storage.h"
 #include "int_storage.h"

+ 22 - 24
src/char_sql/int_mail.c

@@ -128,10 +128,10 @@ static int mail_savemessage(struct mail_message* msg)
 	||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 3, SQLDT_STRING, msg->body, strnlen(msg->body, MAIL_BODY_LENGTH))
 	||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 3, SQLDT_STRING, msg->body, strnlen(msg->body, MAIL_BODY_LENGTH))
 	||  SQL_SUCCESS != SqlStmt_Execute(stmt) )
 	||  SQL_SUCCESS != SqlStmt_Execute(stmt) )
 	{
 	{
-		Sql_ShowDebug(sql_handle);
+		SqlStmt_ShowDebug(stmt);
 		j = 0;
 		j = 0;
 	} else
 	} else
-		j = (int)Sql_LastInsertId(sql_handle);
+		j = (int)SqlStmt_LastInsertId(stmt);
 
 
 	StringBuf_Destroy(&buf);
 	StringBuf_Destroy(&buf);
 
 
@@ -190,7 +190,8 @@ static bool mail_loadmessage(int char_id, int mail_id, struct mail_message* msg)
 	StringBuf_Destroy(&buf);
 	StringBuf_Destroy(&buf);
 	Sql_FreeResult(sql_handle);
 	Sql_FreeResult(sql_handle);
 
 
-	ShowDebug("Loaded message (had read flag %d)\n", msg->read);
+	// this thing converts the database value (0,1,2) into a boolean yes/no
+	//TODO: provide decent enum instead of using 'magic' values
 	if (msg->read == 1)
 	if (msg->read == 1)
 	{
 	{
 		msg->read = 0;
 		msg->read = 0;
@@ -374,7 +375,8 @@ static void mapif_Mail_send(int fd, struct mail_message* msg)
 static void mapif_parse_Mail_send(int fd)
 static void mapif_parse_Mail_send(int fd)
 {
 {
 	struct mail_message msg;
 	struct mail_message msg;
-	int mail_id = 0, account_id = 0;
+	char esc_name[NAME_LENGTH*2+1];
+	int account_id = 0;
 
 
 	if(RFIFOW(fd,2) != 8 + sizeof(struct mail_message))
 	if(RFIFOW(fd,2) != 8 + sizeof(struct mail_message))
 		return;
 		return;
@@ -383,32 +385,28 @@ static void mapif_parse_Mail_send(int fd)
 
 
 	account_id = RFIFOL(fd,4);
 	account_id = RFIFOL(fd,4);
 
 
-	if( !msg.dest_id )
+	// 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) )
 	{
 	{
-		// Try to find the Dest Char by Name
-		char esc_name[NAME_LENGTH*2+1];
-
-		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);
-			}
+		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);
 	}
 	}
+	Sql_FreeResult(sql_handle);
 
 
 	if( msg.dest_id > 0 )
 	if( msg.dest_id > 0 )
-		mail_id = mail_savemessage(&msg);
+		msg.id = mail_savemessage(&msg);
+	else
+		msg.id = 0;
 
 
-	msg.id = mail_id;
 	mapif_Mail_send(fd, &msg);
 	mapif_Mail_send(fd, &msg);
 }
 }
 
 

+ 6 - 19
src/map/clif.c

@@ -11465,7 +11465,10 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
 		weight = data->weight * sd->mail.inbox.msg[i].item.amount;
 		weight = data->weight * sd->mail.inbox.msg[i].item.amount;
 		if (weight > sd->max_weight - sd->weight)
 		if (weight > sd->max_weight - sd->weight)
 		{
 		{
-			clif_displaymessage(fd, "Attachment to heavy for you...");
+			WFIFOHEAD(fd,packet_len(0x245));
+			WFIFOW(fd,0) = 0x245;
+			WFIFOB(fd,2) = 2;
+			WFIFOSET(fd,packet_len(0x245));
 			return;
 			return;
 		}
 		}
 	}
 	}
@@ -11635,7 +11638,6 @@ void clif_Mail_send(int fd, unsigned char flag)
 /// S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B
 /// S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B
 void clif_parse_Mail_send(int fd, struct map_session_data *sd)
 void clif_parse_Mail_send(int fd, struct map_session_data *sd)
 {
 {
-	struct map_session_data *rd;
 	struct mail_message msg;
 	struct mail_message msg;
 	int body_len;
 	int body_len;
 	nullpo_retv(sd);
 	nullpo_retv(sd);
@@ -11653,14 +11655,6 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd)
 	}
 	}
 
 
 	body_len = RFIFOB(fd,68);
 	body_len = RFIFOB(fd,68);
-	rd = map_nick2sd_nocase(RFIFOP(fd,4));
-
-	if (rd && rd == sd) {
-		clif_Mail_send(fd, 1);
-		mail_removeitem(sd,0);
-		mail_removezeny(sd,0);
-		return;
-	}
 
 
 	if (body_len > MAIL_BODY_LENGTH)
 	if (body_len > MAIL_BODY_LENGTH)
 		body_len = MAIL_BODY_LENGTH;
 		body_len = MAIL_BODY_LENGTH;
@@ -11674,16 +11668,9 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd)
 	}
 	}
 
 
 	msg.send_id = sd->status.char_id;
 	msg.send_id = sd->status.char_id;
+	msg.dest_id = 0; // will attempt to resolve name
 	safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
 	safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
-
-	if (rd) {
-		msg.dest_id = rd->status.char_id;
-		safestrncpy(msg.dest_name, rd->status.name, NAME_LENGTH);
-	} else {
-		msg.dest_id = 0;
-		safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
-	}
-
+	safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
 	safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
 	safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
 	
 	
 	if (body_len)
 	if (body_len)

+ 28 - 26
src/map/intif.c

@@ -1669,44 +1669,46 @@ int intif_Mail_send(int account_id, struct mail_message *msg)
 
 
 int intif_parse_Mail_send(int fd)
 int intif_parse_Mail_send(int fd)
 {
 {
-	struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
+	struct map_session_data* sd = map_charid2sd(RFIFOL(fd,4));
 	int mail_id = RFIFOL(fd,8);
 	int mail_id = RFIFOL(fd,8);
 	int dest_id = RFIFOL(fd,12);
 	int dest_id = RFIFOL(fd,12);
+	struct map_session_data* rd;
 
 
-	if (sd == NULL && mail_id > 0)
-	{
-		if (battle_config.error_log)
+	if( mail_id == 0 )
+	{// nick->charid lookup failed, no such char
+		// Return the items to the owner
+		mail_removeitem(sd, 0);
+		mail_removezeny(sd, 0);
+		clif_Mail_send(sd->fd, 1); // failed
+		return 0;
+	}
+
+	if( sd == NULL )
+	{// original sender disconnected, item cannot be deleted!
+		if( battle_config.error_log )
 			ShowError("intif_parse_Mail_send: char not found %d\n",RFIFOL(fd,2));
 			ShowError("intif_parse_Mail_send: char not found %d\n",RFIFOL(fd,2));
 
 
-		// If sd = NULL attachment haven't been removed from sender inventory.
+		// the best thing we can do at this point is requesting removal of the mail with the duped item
 		intif_Mail_delete(dest_id, mail_id);
 		intif_Mail_delete(dest_id, mail_id);
 		return 0;
 		return 0;
 	}
 	}
 
 
-	if (mail_id > 0)
+	// physically delete the item
+	mail_removeitem(sd, 1);
+	mail_removezeny(sd, 1);
+	clif_Mail_send(sd->fd, 0); // success
+
+	// notify recipient about new mail
+	rd = map_charid2sd(dest_id);
+	if( rd != NULL )
 	{
 	{
-		struct map_session_data *rd = map_charid2sd(dest_id);
-		
-		mail_removeitem(sd, 1);
-		mail_removezeny(sd, 1);
-
-		if (rd != NULL)
-		{
-			char title[MAIL_TITLE_LENGTH];
-			memcpy(title, RFIFOP(fd,16), RFIFOW(fd,2) - 16);
-
-			rd->mail.inbox.changed = 1;
-			clif_Mail_new(rd->fd, mail_id, sd->status.name, title);
-		}
-	}
-	else
-	{ // Return the items to the owner
-		mail_removeitem(sd, 0);
-		mail_removezeny(sd, 0);
+		char title[MAIL_TITLE_LENGTH];
+		memcpy(title, RFIFOP(fd,16), RFIFOW(fd,2) - 16);
+
+		rd->mail.inbox.changed = 1;
+		clif_Mail_new(rd->fd, mail_id, sd->status.name, title);
 	}
 	}
 
 
-	clif_Mail_send(sd->fd, (mail_id > 0)?0:1);
-	
 	return 0;
 	return 0;
 }
 }
 
 

+ 0 - 15
src/map/map.c

@@ -1847,21 +1847,6 @@ struct map_session_data * map_nick2sd(const char *nick)
 	return NULL;
 	return NULL;
 }
 }
 
 
-struct map_session_data * map_nick2sd_nocase(const char *nick)
-{
-	int i, users;
-	struct map_session_data **pl_allsd;
-
-	pl_allsd = map_getallusers(&users);
-	for (i = 0; i < users; i++)
-	{
-		if ( !strcmp(pl_allsd[i]->status.name, nick) )
-			return pl_allsd[i];
-	}
-
-	return NULL;
-}
-
 /*==========================================
 /*==========================================
  * id番?の物を探す
  * id番?の物を探す
  * 一三bjectの場合は配列を引くのみ
  * 一三bjectの場合は配列を引くのみ

+ 0 - 1
src/map/map.h

@@ -1344,7 +1344,6 @@ struct map_session_data** map_getallusers(int *users);
 void map_foreachpc(int (*func)(DBKey,void*,va_list),...);
 void map_foreachpc(int (*func)(DBKey,void*,va_list),...);
 int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
 int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
 struct map_session_data * map_nick2sd(const char*);
 struct map_session_data * map_nick2sd(const char*);
-struct map_session_data * map_nick2sd_nocase(const char *);
 
 
 // ‚»‚Ì‘¼
 // ‚»‚Ì‘¼
 int map_check_dir(int s_dir,int t_dir);
 int map_check_dir(int s_dir,int t_dir);