浏览代码

- Added more helpfull error messages when packet_ver=-1. (no more "clif_parse: Disconnecting session #XX for not having latest client version (has version -1)." messages)
- Joined normal and MINICORE's main function.
- Put malloc_init() first and malloc_final() last as it's needed for Show* in display_title().

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

FlavioJS 18 年之前
父节点
当前提交
d4185ce10e
共有 3 个文件被更改,包括 112 次插入69 次删除
  1. 5 0
      Changelog-Trunk.txt
  2. 27 38
      src/common/core.c
  3. 80 31
      src/map/clif.c

+ 5 - 0
Changelog-Trunk.txt

@@ -3,6 +3,11 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 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.
 
 
+2006/12/10
+	* Added more helpfull messages when packet_ver=-1.
+	* Joined normal and MINICORE's main function.
+	* Put malloc_init() first and malloc_final() last as it's needed for Show* 
+	  in display_title(). [FlavioJS]
 2006/12/09
 2006/12/09
 	* Reversed revision #9415 (messages with server_tick field being sent as 
 	* Reversed revision #9415 (messages with server_tick field being sent as 
 	  soon as possible) since it didn't fix the client synchronization issue.
 	  soon as possible) since it didn't fix the client synchronization issue.

+ 27 - 38
src/common/core.c

@@ -11,15 +11,17 @@
 #include <ctype.h>
 #include <ctype.h>
 
 
 #include "core.h"
 #include "core.h"
-#include "../common/db.h"
 #include "../common/mmo.h"
 #include "../common/mmo.h"
+#include "../common/version.h"
+#include "../common/showmsg.h"
 #include "../common/malloc.h"
 #include "../common/malloc.h"
+#ifndef MINICORE
+#include "../common/db.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/timer.h"
 #include "../common/timer.h"
 #include "../common/graph.h"
 #include "../common/graph.h"
 #include "../common/plugins.h"
 #include "../common/plugins.h"
-#include "../common/version.h"
-#include "../common/showmsg.h"
+#endif
 
 
 #ifndef _WIN32
 #ifndef _WIN32
 	#include "svnversion.h"
 	#include "svnversion.h"
@@ -129,7 +131,7 @@ void signals_init (void)
 	{
 	{
 		return xstringify(SVNVERSION);
 		return xstringify(SVNVERSION);
 	}
 	}
-#else
+#else// not SVNVERSION
 const char* get_svn_revision(void)
 const char* get_svn_revision(void)
 {
 {
 	FILE *fp;
 	FILE *fp;
@@ -178,7 +180,6 @@ const char* get_svn_revision(void)
  *	CORE : Display title
  *	CORE : Display title
  *--------------------------------------
  *--------------------------------------
  */
  */
-
 static void display_title(void)
 static void display_title(void)
 {
 {
 	//The clearscreeen is usually more of an annoyance than anything else... [Skotlex]
 	//The clearscreeen is usually more of an annoyance than anything else... [Skotlex]
@@ -220,13 +221,9 @@ void usercheck(void){
  *	CORE : MAINROUTINE
  *	CORE : MAINROUTINE
  *--------------------------------------
  *--------------------------------------
  */
  */
-#ifndef MINICORE	// minimalist Core
 int main (int argc, char **argv)
 int main (int argc, char **argv)
 {
 {
-	int next;
-
-	// initialise program arguments
-	{
+	{// initialize program arguments
 		char *p1 = SERVER_NAME = argv[0];
 		char *p1 = SERVER_NAME = argv[0];
 		char *p2 = p1;
 		char *p2 = p1;
 		while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL)
 		while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL)
@@ -241,11 +238,18 @@ int main (int argc, char **argv)
 		#endif
 		#endif
 	}
 	}
 
 
+	malloc_init();// needed for Show* in display_title() [FlavioJS]
+
+#ifdef MINICORE // minimalist Core
+	display_title();
+	usercheck();
+	do_init(argc,argv);
+	do_final();
+#else// not MINICORE
 	set_server_type();
 	set_server_type();
 	display_title();
 	display_title();
-      usercheck();
+	usercheck();
 
 
-	malloc_init(); /* 一番最初に実行する必要がある */
 	db_init();
 	db_init();
 	signals_init();
 	signals_init();
 
 
@@ -257,12 +261,15 @@ int main (int argc, char **argv)
 	graph_init();
 	graph_init();
 	plugin_event_trigger("Athena_Init");
 	plugin_event_trigger("Athena_Init");
 
 
-	while (runflag) {
-		next = do_timer(gettick_nocache());
-		do_sendrecv(next);
-#ifndef TURBO
-		do_parsepacket();
-#endif
+	{// Main runtime cycle
+		int next;
+		while (runflag) {
+			next = do_timer(gettick_nocache());
+			do_sendrecv(next);
+	#ifndef TURBO
+			do_parsepacket();
+	#endif
+		}
 	}
 	}
 
 
 	plugin_event_trigger("Athena_Final");
 	plugin_event_trigger("Athena_Final");
@@ -273,30 +280,12 @@ int main (int argc, char **argv)
 	plugins_final();
 	plugins_final();
 	socket_final();
 	socket_final();
 	db_final();
 	db_final();
-	malloc_final();
-
-	return 0;
-}
-#else
-int main (int argc, char **argv)
-{
-	// initialise program arguments
-	{
-		char *p = SERVER_NAME = argv[0];
-		while ((p = strchr(p, '/')) != NULL)
-			SERVER_NAME = ++p;
-		arg_c = argc;
-		arg_v = argv;
-	}
+#endif
 
 
-	display_title();
-      usercheck();
-	do_init(argc,argv);
-	do_final();
+	malloc_final();
 
 
 	return 0;
 	return 0;
 }
 }
-#endif
 
 
 #ifdef BCHECK
 #ifdef BCHECK
 unsigned int __invalid_size_argument_for_IOC;
 unsigned int __invalid_size_argument_for_IOC;

+ 80 - 31
src/map/clif.c

@@ -8101,42 +8101,72 @@ void clif_feel_hate_reset(struct map_session_data *sd)
 // clif_guess_PacketVer
 // clif_guess_PacketVer
 // ---------------------
 // ---------------------
 // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
 // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
-static int clif_guess_PacketVer(int fd, int get_previous)
-{
+// error codes:
+// 0 - Success
+// 1 - Unknown packet_ver
+// 2 - Invalid account_id
+// 3 - Invalid char_id
+// 4 - Invalid login_id1 (reserved)
+// 5 - Invalid client_tick (reserved)
+// 6 - Invalid sex
+// Only the first 'invalid' error that appears is used.
+static int clif_guess_PacketVer(int fd, int get_previous, int *error)
+{
+	static int err = 1;
 	static int packet_ver = -1;
 	static int packet_ver = -1;
 	int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
 	int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
 	RFIFOHEAD(fd);
 	RFIFOHEAD(fd);
-	
-	if (get_previous) //For quick reruns, since the normal code flow is to fetch this once to identify the packet version, then again in the wanttoconnect function. [Skotlex]
+
+	if (get_previous)
+	{//For quick reruns, since the normal code flow is to fetch this once to identify the packet version, then again in the wanttoconnect function. [Skotlex]
+		if( error )
+			*error = err;
 		return packet_ver;
 		return packet_ver;
+	}
 
 
-	//By default, start searching on the default one. 
+	//By default, start searching on the default one.
+	err = 1;
 	packet_ver = clif_config.packet_db_ver;
 	packet_ver = clif_config.packet_db_ver;
 	cmd = RFIFOW(fd,0);
 	cmd = RFIFOW(fd,0);
 	packet_len = RFIFOREST(fd);
 	packet_len = RFIFOREST(fd);
 
 
-#define IS_PACKET_VER \
-(\
-	( cmd == clif_config.connect_cmd[packet_ver] ) /* it's the wanttoconnection for this version. */ &&\
-	( packet_len == packet_db[packet_ver][cmd].len ) /* has the right size */ &&\
-	( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) >= START_ACCOUNT_NUM && value <= max_account_id ) /* valid account ID */ &&\
-	( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && value <= max_char_id ) /* valid char ID */ &&\
-	/*            RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
-	/*            RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
-	( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1 ) /* valid sex */\
-)
-
-	if (IS_PACKET_VER)
-		return clif_config.packet_db_ver; //Default packet version found.
+#define SET_ERROR(n) \
+	if( err == 1 )\
+		err = n;\
+//define SET_ERROR
+
+#define CHECK_PACKET_VER() \
+	if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
+		;/* not wanttoconnection or wrong length */\
+	else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
+	{ SET_ERROR(2); }/* invalid account_id */\
+	else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
+	{ SET_ERROR(3); }/* invalid char_id */\
+	/*                   RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
+	/*                   RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
+	else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
+	{ SET_ERROR(6); }/* invalid sex */\
+	else\
+	{\
+		err = 0;\
+		if( error )\
+			*error = 0;\
+		return packet_ver;\
+	}\
+//define CHECK_PACKET_VER
+
+	CHECK_PACKET_VER();//Default packet version found.
 	
 	
 	for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
 	for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
 	{	//Start guessing the version, giving priority to the newer ones. [Skotlex]
 	{	//Start guessing the version, giving priority to the newer ones. [Skotlex]
-		if (IS_PACKET_VER)
-			return packet_ver; //This is our best guess.
+		CHECK_PACKET_VER();
 	}
 	}
+	if( error )
+		*error = err;
 	packet_ver = -1;
 	packet_ver = -1;
 	return -1;
 	return -1;
-#undef IS_PACKET_VER
+#undef SET_ERROR
+#undef CHECK_PACKET_VER
 }
 }
 
 
 // ------------
 // ------------
@@ -8161,7 +8191,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
 		return;
 		return;
 	}
 	}
 
 
-	packet_ver = clif_guess_PacketVer(fd, 1);
+	packet_ver = clif_guess_PacketVer(fd, 1, NULL);
 	cmd = RFIFOW(fd,0);
 	cmd = RFIFOW(fd,0);
 	
 	
 	if (packet_ver <= 0)
 	if (packet_ver <= 0)
@@ -11729,7 +11759,7 @@ void clif_parse_debug(int fd,struct map_session_data *sd)
  *------------------------------------------
  *------------------------------------------
  */
  */
 int clif_parse(int fd) {
 int clif_parse(int fd) {
-	int packet_len = 0, cmd, packet_ver, dump = 0;
+	int packet_len = 0, cmd, packet_ver, err, dump = 0;
 	TBL_PC *sd;
 	TBL_PC *sd;
 	RFIFOHEAD(fd);
 	RFIFOHEAD(fd);
 
 
@@ -11820,27 +11850,46 @@ int clif_parse(int fd) {
 	if (sd) {
 	if (sd) {
 		packet_ver = sd->packet_ver;
 		packet_ver = sd->packet_ver;
 		if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) {	// This should never happen unless we have some corrupted memory issues :X [Skotlex]
 		if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) {	// This should never happen unless we have some corrupted memory issues :X [Skotlex]
-			ShowWarning("clif_parse: Invalid packet_ver=%d (AID/CID: %d:%d), disconnecting session #%d.", packet_ver, sd->status.account_id, sd->status.char_id, fd);
+			ShowWarning("clif_parse: Disconnecting session #%d (AID:%d/CID:%d) for having invalid packet_ver=%d.", fd, sd->status.account_id, sd->status.char_id, packet_ver);
 			session[fd]->eof = 1;
 			session[fd]->eof = 1;
 			return 0;
 			return 0;
 		}
 		}
 	} else {
 	} else {
 		// check authentification packet to know packet version
 		// check authentification packet to know packet version
-		packet_ver = clif_guess_PacketVer(fd, 0);
-		// check if version is accepted
-		if (packet_ver < 5 ||	// reject really old client versions
+		err = clif_guess_PacketVer(fd, 0, &packet_ver);
+		if (err || // unknown packet version
+			packet_ver < 5 ||	// reject really old client versions
 			(packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) ||	// older than 6sept04
 			(packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) ||	// older than 6sept04
 			(packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
 			(packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
 			packet_ver > MAX_PACKET_VER)	// no packet version support yet
 			packet_ver > MAX_PACKET_VER)	// no packet version support yet
 		{
 		{
-			ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
-			WFIFOHEAD(fd, 23);
+			if( err )
+			{// failed to identify
+				ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
+					err == 1 ? "" :
+					err == 2 ? ", possibly for having an invalid account_id" :
+					err == 3 ? ", possibly for having an invalid char_id." :
+					/* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
+					err == 4 ? ", possibly for having an invalid login_id1." :
+					err == 5 ? ", possibly for having an invalid client_tick." :
+					*/
+					err == 6 ? ", possibly for having an invalid sex." :
+					". ERROR invalid error code"));
+				err = 3; // 3 = Rejected from Server
+			}
+			else
+			{// version not accepted
+				ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
+				err = 5; // 05 = Game's EXE is not the latest version
+			}
+			WFIFOHEAD(fd,packet_len_table[0x6a]);
 			WFIFOW(fd,0) = 0x6a;
 			WFIFOW(fd,0) = 0x6a;
-			WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
-			WFIFOSET(fd,23);
+			WFIFOB(fd,2) = err; 
+			WFIFOSET(fd,packet_len_table[0x6a]);
 			packet_len = RFIFOREST(fd);
 			packet_len = RFIFOREST(fd);
 			RFIFOSKIP(fd, packet_len);
 			RFIFOSKIP(fd, packet_len);
 			clif_setwaitclose(fd);
 			clif_setwaitclose(fd);
+			//## TODO check if it still doesn't send and why. [FlavioJS]
 			if (session[fd]->func_send)  //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
 			if (session[fd]->func_send)  //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
 				session[fd]->func_send(fd);
 				session[fd]->func_send(fd);
 			return 0;
 			return 0;