소스 검색

* Added flag.server to indicate interserver sockets
- replaces the previous way (setting 'client_addr' to 0)

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

ultramage 17 년 전
부모
커밋
5790585d16
13개의 변경된 파일53개의 추가작업 그리고 45개의 파일을 삭제
  1. 3 0
      Changelog-Trunk.txt
  2. 8 8
      src/char/char.c
  3. 8 8
      src/char_sql/char.c
  4. 11 11
      src/common/socket.c
  5. 8 5
      src/common/socket.h
  6. 2 1
      src/ladmin/ladmin.c
  7. 1 1
      src/login/admin.c
  8. 3 3
      src/login/login.c
  9. 3 3
      src/login_sql/login.c
  10. 2 2
      src/map/chrif.c
  11. 1 1
      src/map/clif.c
  12. 2 1
      src/map/guild.c
  13. 1 1
      src/map/irc.c

+ 3 - 0
Changelog-Trunk.txt

@@ -3,6 +3,9 @@ Date	Added
 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.
 
+2007/12/17
+	* Added flag.server to indicate interserver sockets
+	- replaces the previous way (setting 'client_addr' to 0)
 2007/12/14
 	* Guardian hp handling code removal (see bugreport:342)
 	- removed guardian hp from the castle data structure, database,

+ 8 - 8
src/char/char.c

@@ -348,7 +348,7 @@ void set_char_online(int map_id, int char_id, int account_id)
 		delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
 		character->waiting_disconnect = -1;
 	}
-	if (login_fd > 0 && !session[login_fd]->eof)
+	if (login_fd > 0 && !session[login_fd]->flag.eof)
 	{	
 		WFIFOHEAD(login_fd,6);
 		WFIFOW(login_fd,0) = 0x272b;
@@ -374,7 +374,7 @@ void set_char_offline(int char_id, int account_id)
 		}
 	}
 	
-	if (login_fd > 0 && !session[login_fd]->eof)
+	if (login_fd > 0 && !session[login_fd]->flag.eof)
 	{
 		WFIFOHEAD(login_fd,6);
 		WFIFOW(login_fd,0) = 0x272c;
@@ -424,7 +424,7 @@ void set_all_offline(int id)
 		ShowNotice("Sending users of map-server %d offline.\n",id);
 	online_char_db->foreach(online_char_db,char_db_kickoffline,id);
 
-	if (id >= 0 || login_fd <= 0 || session[login_fd]->eof)
+	if (id >= 0 || login_fd <= 0 || session[login_fd]->flag.eof)
 		return;
 	//Tell login-server to also mark all our characters as offline.
 	WFIFOHEAD(login_fd,2);
@@ -1954,7 +1954,7 @@ int parse_fromlogin(int fd)
 	if( fd != login_fd )
 		set_eof(fd);
 
-	if(session[fd]->eof) {
+	if(session[fd]->flag.eof) {
 		if (fd == login_fd) {
 			ShowWarning("Connection to login-server lost (connection #%d).\n", fd);
 			login_fd = -1;
@@ -2605,7 +2605,7 @@ int parse_frommap(int fd)
 	ARR_FIND( 0, MAX_MAP_SERVERS, id, server[id].fd == fd );
 	if(id == MAX_MAP_SERVERS)
 		set_eof(fd);
-	if(session[fd]->eof) {
+	if(session[fd]->flag.eof) {
 		if (id < MAX_MAP_SERVERS) {
 			unsigned char buf[16384];
 			ShowStatus("Map-server %d (session #%d) has disconnected.\n", id, fd);
@@ -3225,7 +3225,7 @@ int parse_char(int fd)
 	if(login_fd < 0)
 		set_eof(fd);
 
-	if(session[fd]->eof)
+	if(session[fd]->flag.eof)
 	{
 		if (sd != NULL)
 		{
@@ -3639,7 +3639,7 @@ int parse_char(int fd)
 				server[i].users = 0;
 				memset(server[i].map, 0, sizeof(server[i].map));
 				session[fd]->func_parse = parse_frommap;
-				session[fd]->client_addr = 0;
+				session[fd]->flag.server = 1;
 				realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 				char_mapif_init(fd);
 				// send gm acccounts level to map-servers
@@ -3852,7 +3852,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
 		return 0;
 	}
 	session[login_fd]->func_parse = parse_fromlogin;
-	session[login_fd]->client_addr = 0;
+	session[login_fd]->flag.server = 1;
 	realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 	
 	WFIFOHEAD(login_fd,86);

+ 8 - 8
src/char_sql/char.c

@@ -258,7 +258,7 @@ void set_char_online(int map_id, int char_id, int account_id)
 		cp = idb_get(char_db_,char_id);
  		inter_guild_CharOnline(char_id, cp?cp->guild_id:-1);
 	}
-	if (login_fd > 0 && !session[login_fd]->eof)
+	if (login_fd > 0 && !session[login_fd]->flag.eof)
 	{	
 		WFIFOHEAD(login_fd,6);
 		WFIFOW(login_fd,0) = 0x272b;
@@ -301,7 +301,7 @@ void set_char_offline(int char_id, int account_id)
 		}
 	}
 	
-	if (login_fd > 0 && !session[login_fd]->eof)
+	if (login_fd > 0 && !session[login_fd]->flag.eof)
 	{
 		WFIFOHEAD(login_fd,6);
 		WFIFOW(login_fd,0) = 0x272c;
@@ -351,7 +351,7 @@ void set_all_offline(int id)
 		ShowNotice("Sending users of map-server %d offline.\n",id);
 	online_char_db->foreach(online_char_db,char_db_kickoffline,id);
 
-	if (id >= 0 || login_fd <= 0 || session[login_fd]->eof)
+	if (id >= 0 || login_fd <= 0 || session[login_fd]->flag.eof)
 		return;
 	//Tell login-server to also mark all our characters as offline.
 	WFIFOHEAD(login_fd,2);
@@ -1623,7 +1623,7 @@ int parse_fromlogin(int fd)
 	if( fd != login_fd )
 		set_eof(fd);
 
-	if(session[fd]->eof) {
+	if(session[fd]->flag.eof) {
 		if (fd == login_fd) {
 			ShowWarning("Connection to login-server lost (connection #%d).\n", fd);
 			login_fd = -1;
@@ -2126,7 +2126,7 @@ int parse_frommap(int fd)
 	ARR_FIND( 0, MAX_MAP_SERVERS, id, server[id].fd == fd );
 	if(id == MAX_MAP_SERVERS)
 		set_eof(fd);
-	if(session[fd]->eof) {
+	if(session[fd]->flag.eof) {
 		if (id < MAX_MAP_SERVERS) {
 			unsigned char buf[16384];
 			ShowStatus("Map-server %d (session #%d) has disconnected.\n", id, fd);
@@ -2801,7 +2801,7 @@ int parse_char(int fd)
 	if(login_fd < 0)
 		set_eof(fd);
 
-	if(session[fd]->eof)
+	if(session[fd]->flag.eof)
 	{
 		if (sd != NULL)
 		{	// already authed client
@@ -3189,7 +3189,7 @@ int parse_char(int fd)
 				server[i].users = 0;
 				memset(server[i].map, 0, sizeof(server[i].map));
 				session[fd]->func_parse = parse_frommap;
-				session[fd]->client_addr = 0;
+				session[fd]->flag.server = 1;
 				realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 				char_mapif_init(fd);
 				// send gm acccounts level to map-servers
@@ -3398,7 +3398,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
 		return 0;
 	}
 	session[login_fd]->func_parse = parse_fromlogin;
-	session[login_fd]->client_addr = 0;
+	session[login_fd]->flag.server = 1;
 	realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 	
 	WFIFOHEAD(login_fd,86);

+ 11 - 11
src/common/socket.c

@@ -282,7 +282,7 @@ void set_eof(int fd)
 		// Add this socket to the shortlist for eof handling.
 		send_shortlist_add_fd(fd);
 #endif
-		session[fd]->eof = 1;
+		session[fd]->flag.eof = 1;
 	}
 }
 
@@ -460,15 +460,15 @@ int make_listen_bind(uint32 ip, uint16 port)
 	sFD_SET(fd, &readfds);
 
 	create_session(fd, connect_client, null_send, null_parse);
+	session[fd]->client_addr = 0; // just listens
 	session[fd]->rdata_tick = 0; // disable timeouts on this socket
-	session[fd]->client_addr = 0;
 
 	return fd;
 }
 
 int make_connection(uint32 ip, uint16 port)
 {
-	struct sockaddr_in server_address;
+	struct sockaddr_in remote_address;
 	int fd;
 	int result;
 
@@ -493,13 +493,13 @@ int make_connection(uint32 ip, uint16 port)
 
 	setsocketopts(fd);
 
-	server_address.sin_family      = AF_INET;
-	server_address.sin_addr.s_addr = htonl(ip);
-	server_address.sin_port        = htons(port);
+	remote_address.sin_family      = AF_INET;
+	remote_address.sin_addr.s_addr = htonl(ip);
+	remote_address.sin_port        = htons(port);
 
 	ShowStatus("Connecting to %d.%d.%d.%d:%i\n", CONVIP(ip), port);
 
-	result = sConnect(fd, (struct sockaddr *)(&server_address), sizeof(struct sockaddr_in));
+	result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in));
 	if( result == SOCKET_ERROR ) {
 		ShowError("make_connection: connect failed (socket #%d, code %d)!\n", fd, sErrno);
 		do_close(fd);
@@ -512,7 +512,7 @@ int make_connection(uint32 ip, uint16 port)
 	sFD_SET(fd,&readfds);
 
 	create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse);
-	session[fd]->client_addr = 0;
+	session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr);
 
 	return fd;
 }
@@ -1252,7 +1252,7 @@ bool session_isValid(int fd)
 
 bool session_isActive(int fd)
 {
-	return ( session_isValid(fd) && !session[fd]->eof );
+	return ( session_isValid(fd) && !session[fd]->flag.eof );
 }
 
 // Resolves hostname into a numeric ip.
@@ -1327,12 +1327,12 @@ void send_shortlist_do_sends()
 
 			// If it's been marked as eof, call the parse func on it so that
 			// the socket will be immediately closed.
-			if( session[fd]->eof )
+			if( session[fd]->flag.eof )
 				session[fd]->func_parse(fd);
 
 			// If the session still exists, is not eof and has things left to
 			// be sent from it we'll keep it in the shortlist.
-			if( session[fd] && !session[fd]->eof && session[fd]->wdata_size )
+			if( session[fd] && !session[fd]->flag.eof && session[fd]->wdata_size )
 			{
 				send_shortlist_set[fd/32] |= 1<<(fd%32);
 				++i;

+ 8 - 5
src/common/socket.h

@@ -35,7 +35,7 @@
 #define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size)
 #define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size)
 
-#define RFIFOREST(fd)  (session[fd]->eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos)
+#define RFIFOREST(fd)  (session[fd]->flag.eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos)
 #define RFIFOFLUSH(fd) \
 	do { \
 		if(session[fd]->rdata_size == session[fd]->rdata_pos){ \
@@ -70,16 +70,19 @@ typedef int (*ParseFunc)(int fd);
 
 struct socket_data
 {
-	unsigned char eof;
+	struct {
+		unsigned char eof : 1;
+		unsigned char server : 1;
+	} flag;
 
-	unsigned char *rdata, *wdata;
+	uint32 client_addr; // remote client address
+
+	uint8 *rdata, *wdata;
 	size_t max_rdata, max_wdata;
 	size_t rdata_size, wdata_size;
 	size_t rdata_pos;
 	time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled
 
-	uint32 client_addr; // remote client address (0 for server connections)
-
 	RecvFunc func_recv;
 	SendFunc func_send;
 	ParseFunc func_parse;

+ 2 - 1
src/ladmin/ladmin.c

@@ -3239,7 +3239,7 @@ int parse_fromlogin(int fd)
 	struct char_session_data *sd;
 	int id;
 	RFIFOHEAD(fd);
-	if (session[fd]->eof) {
+	if (session[fd]->flag.eof) {
 		if (defaultlanguage == 'F') {
 			ShowMessage("Impossible de se connecter au serveur de login [%s:%d] !\n", loginserverip, loginserverport);
 			ladmin_log("Impossible de se connecter au serveur de login [%s:%d] !\n", loginserverip, loginserverport);
@@ -4201,6 +4201,7 @@ int Connect_login_server(void)
 		ShowMessage("Error: Failed to connect to Login Server\n");
 		exit(EXIT_FAILURE);
 	}
+	session[login_fd]->flag.server = 1;
 	if (passenc == 0) {
 		WFIFOHEAD(login_fd,28);
 		WFIFOW(login_fd,0) = 0x7918; // Request for administation login

+ 1 - 1
src/login/admin.c

@@ -45,7 +45,7 @@ int parse_admin(int fd)
 	char ip[16];
 	ip2str(ipl, ip);
 
-	if( session[fd]->eof )
+	if( session[fd]->flag.eof )
 	{
 		do_close(fd);
 		ShowInfo("Remote administration has disconnected (session #%d).\n", fd);

+ 3 - 3
src/login/login.c

@@ -1230,7 +1230,7 @@ int parse_fromchar(int fd)
 		return 0;
 	}
 
-	if( session[fd]->eof )
+	if( session[fd]->flag.eof )
 	{
 		ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
 		online_db->foreach(online_db, online_db_setoffline, id); //Set all chars from this char server to offline.
@@ -1820,7 +1820,7 @@ int parse_login(int fd)
 	uint32 ipl;
 	char ip[16];
 
-	if( session[fd]->eof )
+	if( session[fd]->flag.eof )
 	{
 		do_close(fd);
 		return 0;
@@ -2059,7 +2059,7 @@ int parse_login(int fd)
 				WFIFOSET(fd,3);
 
 				session[fd]->func_parse = parse_fromchar;
-				session[fd]->client_addr = 0;
+				session[fd]->flag.server = 1;
 				realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 
 				send_GM_accounts(fd); // send GM account to char-server

+ 3 - 3
src/login_sql/login.c

@@ -616,7 +616,7 @@ int parse_fromchar(int fd)
 		return 0;
 	}
 
-	if( session[fd]->eof )
+	if( session[fd]->flag.eof )
 	{
 		ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
 		online_db->foreach(online_db, online_db_setoffline, id); //Set all chars from this char server to offline.
@@ -1220,7 +1220,7 @@ int parse_login(int fd)
 	uint32 ipl;
 	char ip[16];
 
-	if( session[fd]->eof )
+	if( session[fd]->flag.eof )
 	{
 		do_close(fd);
 		return 0;
@@ -1523,7 +1523,7 @@ int parse_login(int fd)
 				WFIFOSET(fd,3);
 
 				session[fd]->func_parse = parse_fromchar;
-				session[fd]->client_addr = 0;
+				session[fd]->flag.server = 1;
 				realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 
 				send_GM_accounts(fd); // send GM account to char-server

+ 2 - 2
src/map/chrif.c

@@ -1245,7 +1245,7 @@ int chrif_parse(int fd)
 		return 0;
 	}
 
-	if (session[fd]->eof)
+	if (session[fd]->flag.eof)
 	{
 		if (chrif_connected == 1)
 			chrif_disconnect(fd);
@@ -1393,7 +1393,7 @@ int check_connect_char_server(int tid, unsigned int tick, int id, int data)
 		}
 
 		session[char_fd]->func_parse = chrif_parse;
-		session[char_fd]->client_addr = 0;
+		session[char_fd]->flag.server = 1;
 		realloc_fifo(char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
 
 		chrif_connect(char_fd);

+ 1 - 1
src/map/clif.c

@@ -11494,7 +11494,7 @@ int clif_parse(int fd)
 	{ // begin main client packet processing loop
 
 	sd = (TBL_PC *)session[fd]->session_data;
-	if (session[fd]->eof) {
+	if (session[fd]->flag.eof) {
 		if (sd) {
 			if (sd->state.autotrade) {
 				//Disassociate character from the socket connection.

+ 2 - 1
src/map/guild.c

@@ -233,7 +233,7 @@ struct guild_castle* guild_castle_search(int gcid)
 struct guild_castle* guild_mapindex2gc(short mapindex)
 {
 	struct guild_castle* gc;
-	
+
 	DBIterator* iter = castle_db->iterator(castle_db);
 	for( gc = iter->first(iter,NULL); iter->exists(iter); gc = iter->next(iter,NULL) )
 	{
@@ -277,6 +277,7 @@ int guild_getindex(struct guild *g,int account_id,int char_id)
 int guild_getposition(struct guild* g, struct map_session_data* sd)
 {
 	int i;
+
 	if( g == NULL && (g=guild_search(sd->status.guild_id)) == NULL )
 		return -1;
 	

+ 1 - 1
src/map/irc.c

@@ -121,7 +121,7 @@ void irc_announce_mvp(struct map_session_data *sd, struct mob_data *md)
 
 int irc_parse(int fd)
 {
-	if (session[fd]->eof)
+	if (session[fd]->flag.eof)
 	{
 		do_close(fd);
 		irc_si = NULL;