浏览代码

Cleaning up of the socket code
- Shuffled includes around for files that were leeching off of socket.h
- Added code that enforces standard shutdown behavior for sockets

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

ultramage 18 年之前
父节点
当前提交
148f3fca88

+ 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/02/07
 2007/02/07
+	* Cleaning up of the socket code [ultramage]
+	- Shuffled includes around for files that were leeching off of socket.h
+	- Added code that enforces standard shutdown behavior for sockets
 	* Removed old script bonuses bMatk, bMatk1, bMatk2.
 	* Removed old script bonuses bMatk, bMatk1, bMatk2.
 	* Fixed char-server not sending online notification when a party member
 	* Fixed char-server not sending online notification when a party member
 	  logs in.
 	  logs in.

+ 1 - 0
src/char/int_guild.c

@@ -7,6 +7,7 @@
 
 
 #include "../common/cbasetypes.h"
 #include "../common/cbasetypes.h"
 #include "../common/mmo.h"
 #include "../common/mmo.h"
+#include "../common/malloc.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/lock.h"
 #include "../common/lock.h"

+ 1 - 0
src/char/int_homun.c

@@ -6,6 +6,7 @@
 #include <string.h>
 #include <string.h>
 
 
 #include "../common/mmo.h"
 #include "../common/mmo.h"
+#include "../common/malloc.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/lock.h"
 #include "../common/lock.h"

+ 1 - 0
src/char/int_party.c

@@ -7,6 +7,7 @@
 
 
 #include "../common/cbasetypes.h"
 #include "../common/cbasetypes.h"
 #include "../common/mmo.h"
 #include "../common/mmo.h"
+#include "../common/malloc.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/lock.h"
 #include "../common/lock.h"

+ 1 - 0
src/char/int_pet.c

@@ -6,6 +6,7 @@
 #include <string.h>
 #include <string.h>
 
 
 #include "../common/mmo.h"
 #include "../common/mmo.h"
+#include "../common/malloc.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/lock.h"
 #include "../common/lock.h"

+ 2 - 0
src/char/int_storage.c

@@ -1,10 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 // For more information, see LICENCE in the main folder
 
 
+#include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #include "../common/mmo.h"
 #include "../common/mmo.h"
+#include "../common/malloc.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/lock.h"
 #include "../common/lock.h"

+ 1 - 0
src/char/inter.c

@@ -1,6 +1,7 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 // For more information, see LICENCE in the main folder
 
 
+#include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 

+ 1 - 0
src/char_sql/int_homun.c

@@ -6,6 +6,7 @@
 #include <string.h>
 #include <string.h>
 
 
 #include "char.h"
 #include "char.h"
+#include "../common/malloc.h"
 #include "../common/strlib.h"
 #include "../common/strlib.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
 
 

+ 1 - 0
src/char_sql/int_party.c

@@ -10,6 +10,7 @@
 
 
 #include "../common/cbasetypes.h"
 #include "../common/cbasetypes.h"
 #include "../common/db.h"
 #include "../common/db.h"
+#include "../common/malloc.h"
 #include "../common/strlib.h"
 #include "../common/strlib.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"

+ 1 - 0
src/char_sql/int_pet.c

@@ -9,6 +9,7 @@
 #include <string.h>
 #include <string.h>
 
 
 #include "char.h"
 #include "char.h"
+#include "../common/malloc.h"
 #include "../common/strlib.h"
 #include "../common/strlib.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
 
 

+ 2 - 0
src/char_sql/int_storage.c

@@ -4,11 +4,13 @@
 // original code from athena
 // original code from athena
 // SQL conversion by Jioh L. Jung
 // SQL conversion by Jioh L. Jung
 
 
+#include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #include "char.h"
 #include "char.h"
 #include "itemdb.h"
 #include "itemdb.h"
+#include "../common/malloc.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
 
 
 #define STORAGE_MEMINC	16
 #define STORAGE_MEMINC	16

+ 2 - 0
src/char_sql/inter.c

@@ -4,10 +4,12 @@
 // original code from athena
 // original code from athena
 // SQL conversion by Jioh L. Jung
 // SQL conversion by Jioh L. Jung
 
 
+#include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #include "char.h"
 #include "char.h"
+#include "../common/malloc.h"
 #include "../common/strlib.h"
 #include "../common/strlib.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
 #include "inter.h"
 #include "inter.h"

+ 1 - 0
src/char_sql/itemdb.c

@@ -10,6 +10,7 @@
 #include "inter.h"
 #include "inter.h"
 #include "char.h"
 #include "char.h"
 #include "utils.h"
 #include "utils.h"
+#include "../common/malloc.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
 
 
 #define MAX_RANDITEM	2000
 #define MAX_RANDITEM	2000

+ 2 - 0
src/common/lock.h

@@ -4,6 +4,8 @@
 #ifndef _LOCK_H_
 #ifndef _LOCK_H_
 #define _LOCK_H_
 #define _LOCK_H_
 
 
+#include <stdio.h>
+
 FILE* lock_fopen(const char* filename,int *info);
 FILE* lock_fopen(const char* filename,int *info);
 int   lock_fclose(FILE *fp,const char* filename,int *info);
 int   lock_fclose(FILE *fp,const char* filename,int *info);
 
 

+ 22 - 24
src/common/socket.c

@@ -103,10 +103,9 @@ void set_defaultparse(int (*defaultparse)(int))
 
 
 void set_nonblocking(int fd, int yes)
 void set_nonblocking(int fd, int yes)
 {
 {
-	// I don't think we need this
 	// TCP_NODELAY BOOL Disables the Nagle algorithm for send coalescing.
 	// TCP_NODELAY BOOL Disables the Nagle algorithm for send coalescing.
 	if(mode_neg)
 	if(mode_neg)
-		setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes);
+		setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,(char *)&yes, sizeof yes);
 	
 	
 	// FIONBIO Use with a nonzero argp parameter to enable the nonblocking mode of socket s. 
 	// FIONBIO Use with a nonzero argp parameter to enable the nonblocking mode of socket s. 
 	// The argp parameter is zero if nonblocking is to be disabled. 
 	// The argp parameter is zero if nonblocking is to be disabled. 
@@ -129,16 +128,16 @@ static void setsocketopts(int fd)
 	setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof(yes));
 	setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof(yes));
 //	setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &wfifo_size , sizeof(rfifo_size ));
 //	setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &wfifo_size , sizeof(rfifo_size ));
 //	setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &rfifo_size , sizeof(rfifo_size ));
 //	setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &rfifo_size , sizeof(rfifo_size ));
-#ifdef __WIN32
-{	//set SO_LINGER option (from Freya)
+
+	// force the socket into no-wait, graceful-close mode (should be the default, but better make sure)
 	//(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/closesocket_2.asp)
 	//(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/closesocket_2.asp)
+	{
 	struct linger opt;
 	struct linger opt;
-	opt.l_onoff = 1;
-	opt.l_linger = 0;
+	opt.l_onoff = 0; // SO_DONTLINGER
+	opt.l_linger = 0; // Do not care
 	if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char*)&opt, sizeof(opt)))
 	if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char*)&opt, sizeof(opt)))
 		ShowWarning("setsocketopts: Unable to set SO_LINGER mode for connection %d!\n",fd);
 		ShowWarning("setsocketopts: Unable to set SO_LINGER mode for connection %d!\n",fd);
-}
-#endif
+	}
 }
 }
 
 
 /*======================================
 /*======================================
@@ -148,14 +147,14 @@ static void setsocketopts(int fd)
 static void set_eof(int fd)
 static void set_eof(int fd)
 {	//Marks a connection eof and invokes the parse_function to disconnect it right away. [Skotlex]
 {	//Marks a connection eof and invokes the parse_function to disconnect it right away. [Skotlex]
 	if (session_isActive(fd))
 	if (session_isActive(fd))
-		session[fd]->eof=1;
+		session[fd]->eof = 1;
 }
 }
 
 
 static int recv_to_fifo(int fd)
 static int recv_to_fifo(int fd)
 {
 {
 	int len;
 	int len;
 
 
-	if( (fd < 0) || (fd >= FD_SETSIZE) || (NULL == session[fd]) || (session[fd]->eof) )
+	if( !session_isActive(fd) )
 		return -1;
 		return -1;
 
 
 	len = recv(fd, (char *) session[fd]->rdata + session[fd]->rdata_size, RFIFOSPACE(fd), 0);
 	len = recv(fd, (char *) session[fd]->rdata + session[fd]->rdata_size, RFIFOSPACE(fd), 0);
@@ -218,8 +217,7 @@ static int send_from_fifo(int fd)
 	return 0;
 	return 0;
 }
 }
 
 
-/// Best effort
-/// There's no warranty that the data will be sent.
+/// Best effort - there's no warranty that the data will be sent.
 void flush_fifo(int fd)
 void flush_fifo(int fd)
 {
 {
 	if(session[fd] != NULL && session[fd]->func_send == send_from_fifo)
 	if(session[fd] != NULL && session[fd]->func_send == send_from_fifo)
@@ -229,9 +227,8 @@ void flush_fifo(int fd)
 void flush_fifos(void)
 void flush_fifos(void)
 {
 {
 	int i;
 	int i;
-	for(i=1;i<fd_max;i++)
-		if(session[i] != NULL &&
-		   session[i]->func_send == send_from_fifo)
+	for(i = 1; i < fd_max; i++)
+		if(session[i] != NULL && session[i]->func_send == send_from_fifo)
 			send_from_fifo(i);
 			send_from_fifo(i);
 }
 }
 
 
@@ -327,7 +324,7 @@ int make_listen_bind(long ip,int port)
 		exit(1);
 		exit(1);
 	}
 	}
 
 
-	if(fd_max<=fd) fd_max=fd+1;
+	if(fd_max <= fd) fd_max = fd + 1;
 	FD_SET(fd, &readfds );
 	FD_SET(fd, &readfds );
 
 
 	CREATE(session[fd], struct socket_data, 1);
 	CREATE(session[fd], struct socket_data, 1);
@@ -489,7 +486,7 @@ int realloc_writefifo(int fd, size_t addition)
 	return 0;
 	return 0;
 }
 }
 
 
-int WFIFOSET(int fd,int len)
+int WFIFOSET(int fd, int len)
 {
 {
 	size_t newreserve;
 	size_t newreserve;
 	struct socket_data *s = session[fd];
 	struct socket_data *s = session[fd];
@@ -668,7 +665,7 @@ int do_parsepacket(void)
 {
 {
 	int i;
 	int i;
 	struct socket_data *sd;
 	struct socket_data *sd;
-	for(i = 1; i < fd_max; i++){
+	for(i = 1; i < fd_max; i++) {
 		sd = session[i];
 		sd = session[i];
 		if(!sd)
 		if(!sd)
 			continue;
 			continue;
@@ -1017,7 +1014,7 @@ int RFIFOSKIP(int fd,int len)
 {
 {
     struct socket_data *s;
     struct socket_data *s;
 
 
-	if ( !session_isActive(fd) ) //Nullpo error here[Kevin]
+	if ( !session_isActive(fd) )
 		return 0;
 		return 0;
 
 
 	s = session[fd];
 	s = session[fd];
@@ -1195,9 +1192,9 @@ void socket_init(void)
 	// initialise last send-receive tick
 	// initialise last send-receive tick
 	last_tick = time(0);
 	last_tick = time(0);
 
 
-	// session[0] is for disconnected sessions of the map server, and as such, 
+	// session[0] is now currently used for disconnected sessions of the map server, and as such,
 	// should hold enough buffer (it is a vacuum so to speak) as it is never flushed. [Skotlex]
 	// should hold enough buffer (it is a vacuum so to speak) as it is never flushed. [Skotlex]
-	//##TODO "flush" this session periodically O.O [FlavioJS]
+	// ##TODO "flush" this session periodically O.O [FlavioJS]
 	CREATE(session[0], struct socket_data, 1);
 	CREATE(session[0], struct socket_data, 1);
 	CREATE(session[0]->rdata, unsigned char, 2*rfifo_size);
 	CREATE(session[0]->rdata, unsigned char, 2*rfifo_size);
 	CREATE(session[0]->wdata, unsigned char, 2*wfifo_size);
 	CREATE(session[0]->wdata, unsigned char, 2*wfifo_size);
@@ -1218,8 +1215,8 @@ void socket_init(void)
 
 
 
 
 int session_isValid(int fd)
 int session_isValid(int fd)
-{	//End of Exam has pointed out that fd==0 is actually an unconnected session! [Skotlex]
-	return ( (fd>0) && (fd<FD_SETSIZE) && (NULL!=session[fd]) );
+{
+	return ( (fd > 0) && (fd < FD_SETSIZE) && (session[fd] != NULL) );
 }
 }
 
 
 int session_isActive(int fd)
 int session_isActive(int fd)
@@ -1227,7 +1224,8 @@ int session_isActive(int fd)
 	return ( session_isValid(fd) && !session[fd]->eof );
 	return ( session_isValid(fd) && !session[fd]->eof );
 }
 }
 
 
-in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str) {
+in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str)
+{
 	struct hostent *h = gethostbyname(hostname);
 	struct hostent *h = gethostbyname(hostname);
 	char ip_buf[16];
 	char ip_buf[16];
 	unsigned char ip2[4];
 	unsigned char ip2[4];

+ 16 - 42
src/common/socket.h

@@ -4,10 +4,7 @@
 #ifndef	_SOCKET_H_
 #ifndef	_SOCKET_H_
 #define _SOCKET_H_
 #define _SOCKET_H_
 
 
-#include "../common/cbasetypes.h"
-
 #ifdef WIN32
 #ifdef WIN32
-	#define __USE_W32_SOCKETS
 	#include <windows.h>
 	#include <windows.h>
 	typedef long in_addr_t;
 	typedef long in_addr_t;
 #else
 #else
@@ -16,30 +13,24 @@
 	#include <netinet/in.h>
 	#include <netinet/in.h>
 #endif
 #endif
 
 
-#include <stdio.h>
-#include <time.h>
-#include "../common/malloc.h"
-
-extern time_t last_tick;
-extern time_t stall_time;
+#include "../common/cbasetypes.h"
 
 
 // define declaration
 // define declaration
 
 
-#define RFIFOSPACE(fd) (session[fd]->max_rdata-session[fd]->rdata_size)
 #ifdef TURBO
 #ifdef TURBO
 #define RFIFOVAR(fd) rbPtr ## fd
 #define RFIFOVAR(fd) rbPtr ## fd
 #define RFIFOHEAD(fd) uint8 *RFIFOVAR(fd) = session[fd]->rdata+session[fd]->rdata_pos
 #define RFIFOHEAD(fd) uint8 *RFIFOVAR(fd) = session[fd]->rdata+session[fd]->rdata_pos
 #define RFIFOP(fd,pos) ( &RFIFOVAR(fd) + (pos) )
 #define RFIFOP(fd,pos) ( &RFIFOVAR(fd) + (pos) )
 #else
 #else
-//Make it a comment so it does not disrupts the rest of code.
-#define RFIFOHEAD(fd) //
-#define RFIFOP(fd,pos) (session[fd]->rdata+session[fd]->rdata_pos+(pos))
+#define RFIFOHEAD(fd)
+#define RFIFOP(fd,pos) (session[fd]->rdata + session[fd]->rdata_pos + (pos))
 #endif
 #endif
-// use function instead of macro.
 #define RFIFOB(fd,pos) (*(uint8*)RFIFOP(fd,pos))
 #define RFIFOB(fd,pos) (*(uint8*)RFIFOP(fd,pos))
 #define RFIFOW(fd,pos) (*(uint16*)RFIFOP(fd,pos))
 #define RFIFOW(fd,pos) (*(uint16*)RFIFOP(fd,pos))
 #define RFIFOL(fd,pos) (*(uint32*)RFIFOP(fd,pos))
 #define RFIFOL(fd,pos) (*(uint32*)RFIFOP(fd,pos))
-#define RFIFOREST(fd)  (session[fd]->rdata_size-session[fd]->rdata_pos)
+#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size)
+#define RFIFOREST(fd)  (session[fd]->rdata_size - session[fd]->rdata_pos)
+//#define RFIFOSKIP(fd,len) ((session[fd]->rdata_size - session[fd]->rdata_pos - (len) < 0) ? (fprintf(stderr,"too many skip\n"),exit(1)) : (session[fd]->rdata_pos += (len)))
 #define RFIFOFLUSH(fd) \
 #define RFIFOFLUSH(fd) \
 	do { \
 	do { \
 		if(session[fd]->rdata_size == session[fd]->rdata_pos){ \
 		if(session[fd]->rdata_size == session[fd]->rdata_pos){ \
@@ -47,31 +38,26 @@ extern time_t stall_time;
 		} else { \
 		} else { \
 			session[fd]->rdata_size -= session[fd]->rdata_pos; \
 			session[fd]->rdata_size -= session[fd]->rdata_pos; \
 			memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \
 			memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \
-			session[fd]->rdata_pos=0; \
+			session[fd]->rdata_pos = 0; \
 		} \
 		} \
 	} while(0)
 	} while(0)
-
-//#define RFIFOSKIP(fd,len) ((session[fd]->rdata_size-session[fd]->rdata_pos-(len)<0) ? (fprintf(stderr,"too many skip\n"),exit(1)) : (session[fd]->rdata_pos+=(len)))
-
-#define RBUFP(p,pos) (((uint8*)(p))+(pos))
+#define RBUFP(p,pos) (((uint8*)(p)) + (pos))
 #define RBUFB(p,pos) (*(uint8*)RBUFP((p),(pos)))
 #define RBUFB(p,pos) (*(uint8*)RBUFP((p),(pos)))
 #define RBUFW(p,pos) (*(uint16*)RBUFP((p),(pos)))
 #define RBUFW(p,pos) (*(uint16*)RBUFP((p),(pos)))
 #define RBUFL(p,pos) (*(uint32*)RBUFP((p),(pos)))
 #define RBUFL(p,pos) (*(uint32*)RBUFP((p),(pos)))
 
 
-#define WFIFOSPACE(fd) (session[fd]->max_wdata-session[fd]->wdata_size)
 #ifdef TURBO
 #ifdef TURBO
 #define WFIFOVAR(fd) wbPtr ## fd
 #define WFIFOVAR(fd) wbPtr ## fd
 #define WFIFOHEAD(fd, x) uint8 *WFIFOVAR(fd) = ( (fd) > 0 && session[fd] ? session[fd]->wdata+session[fd]->wdata_size : NULL )
 #define WFIFOHEAD(fd, x) uint8 *WFIFOVAR(fd) = ( (fd) > 0 && session[fd] ? session[fd]->wdata+session[fd]->wdata_size : NULL )
 #define WFIFOP(fd,pos) ( &WFIFOVAR(fd) + (pos) )
 #define WFIFOP(fd,pos) ( &WFIFOVAR(fd) + (pos) )
 #else
 #else
 #define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo(fd, size); }while(0)
 #define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo(fd, size); }while(0)
-
 #define WFIFOP(fd,pos) (session[fd]->wdata+session[fd]->wdata_size+(pos))
 #define WFIFOP(fd,pos) (session[fd]->wdata+session[fd]->wdata_size+(pos))
 #endif
 #endif
 #define WFIFOB(fd,pos) (*(uint8*)WFIFOP(fd,pos))
 #define WFIFOB(fd,pos) (*(uint8*)WFIFOP(fd,pos))
 #define WFIFOW(fd,pos) (*(uint16*)WFIFOP(fd,pos))
 #define WFIFOW(fd,pos) (*(uint16*)WFIFOP(fd,pos))
 #define WFIFOL(fd,pos) (*(uint32*)WFIFOP(fd,pos))
 #define WFIFOL(fd,pos) (*(uint32*)WFIFOP(fd,pos))
-// use function instead of macro.
+#define WFIFOSPACE(fd) (session[fd]->max_wdata-session[fd]->wdata_size)
 //#define WFIFOSET(fd,len) (session[fd]->wdata_size = (session[fd]->wdata_size + (len) + 2048 < session[fd]->max_wdata) ? session[fd]->wdata_size + len : session[fd]->wdata_size)
 //#define WFIFOSET(fd,len) (session[fd]->wdata_size = (session[fd]->wdata_size + (len) + 2048 < session[fd]->max_wdata) ? session[fd]->wdata_size + len : session[fd]->wdata_size)
 #define WBUFP(p,pos) (((uint8*)(p)) + (pos))
 #define WBUFP(p,pos) (((uint8*)(p)) + (pos))
 #define WBUFB(p,pos) (*(uint8*)((p) + (pos)))
 #define WBUFB(p,pos) (*(uint8*)((p) + (pos)))
@@ -82,22 +68,6 @@ extern time_t stall_time;
 #define TOW(n) ((uint16)((n)&UINT16_MAX))
 #define TOW(n) ((uint16)((n)&UINT16_MAX))
 #define TOL(n) ((uint32)((n)&UINT32_MAX))
 #define TOL(n) ((uint32)((n)&UINT32_MAX))
 
 
-//FD_SETSIZE must be modified on the project files/Makefile, since a change here won't affect
-// dependant windows libraries.
-/*
-#ifdef __WIN32
-//The default FD_SETSIZE is kinda small for windows systems.
-	#ifdef FD_SETSIZE
-	#undef FD_SETSIZE
-	#endif
-#define FD_SETSIZE 4096
-#endif
-*/
-#ifdef __INTERIX
-#define FD_SETSIZE 4096
-#endif // __INTERIX
-
-/* Removed Cygwin FD_SETSIZE declarations, now are directly passed on to the compiler through Makefile [Valaris] */
 
 
 // Session type
 // Session type
 enum SessionType {
 enum SessionType {
@@ -110,7 +80,7 @@ enum SessionType {
 
 
 // Struct declaration
 // Struct declaration
 
 
-struct socket_data{
+struct socket_data {
 	unsigned char eof;
 	unsigned char eof;
 	unsigned char *rdata, *wdata;
 	unsigned char *rdata, *wdata;
 	size_t max_rdata, max_wdata;
 	size_t max_rdata, max_wdata;
@@ -140,6 +110,9 @@ extern struct socket_data *session[FD_SETSIZE];
 
 
 extern int fd_max;
 extern int fd_max;
 
 
+extern time_t last_tick;
+extern time_t stall_time;
+
 //////////////////////////////////
 //////////////////////////////////
 // some checking on sockets
 // some checking on sockets
 extern int session_isValid(int fd);
 extern int session_isValid(int fd);
@@ -175,10 +148,11 @@ void set_defaultparse(int (*defaultparse)(int));
 //hostname is the name to resolve.
 //hostname is the name to resolve.
 //ip is an array of char[4] where the individual parts of the ip are stored (optional)
 //ip is an array of char[4] where the individual parts of the ip are stored (optional)
 //ip_str is a char[16] where the whole ip is stored in string notation (optional)
 //ip_str is a char[16] where the whole ip is stored in string notation (optional)
-in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str);
+in_addr_t resolve_hostbyname(char* hostname, unsigned char* ip, char* ip_str);
 
 
-int socket_getips(uint32 *ips, int max);
+int socket_getips(uint32* ips, int max);
 
 
 extern uint32 addr_[16];   // ip addresses of local host (host byte order)
 extern uint32 addr_[16];   // ip addresses of local host (host byte order)
 extern int naddr_;   // # of ip addresses
 extern int naddr_;   // # of ip addresses
+
 #endif	// _SOCKET_H_
 #endif	// _SOCKET_H_

+ 1 - 1
src/map/atcommand.c

@@ -9347,7 +9347,7 @@ int atcommand_homhungry(const int fd, struct map_session_data* sd, const char* c
 }
 }
 
 
 /*==========================================
 /*==========================================
- * modify homunculus hunger [orn]
+ * make the homunculus speak [orn]
  *------------------------------------------
  *------------------------------------------
  */
  */
 int atcommand_homtalk(const int fd, struct map_session_data* sd, const char* command, const char* message)
 int atcommand_homtalk(const int fd, struct map_session_data* sd, const char* command, const char* message)

+ 6 - 0
src/map/irc.c

@@ -1,4 +1,8 @@
+#ifndef _IRC_H_
+#define _IRC_H_
+
 #include <ctype.h>
 #include <ctype.h>
+#include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
@@ -541,3 +545,5 @@ int irc_read_conf(char *file) {
 
 
 	return 1;
 	return 1;
 }
 }
+
+#endif //_IRC_H_

+ 1 - 0
src/map/mercenary.c

@@ -5,6 +5,7 @@
 #include <math.h>
 #include <math.h>
 
 
 #include "../common/cbasetypes.h"
 #include "../common/cbasetypes.h"
+#include "../common/malloc.h"
 #include "../common/socket.h"
 #include "../common/socket.h"
 #include "../common/timer.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
 #include "../common/nullpo.h"