summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-06-22 01:12:52 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-06-22 01:12:52 +0000
commit8ecd9729cb7da906470a88decb77620ed3d7ffdf (patch)
tree23486d0498a03b341b7f2a6bca2543a7705fe63d /src
parent0c74559d80136821bee587473b01dab5935ebf26 (diff)
downloadhercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.tar.gz
hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.tar.bz2
hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.tar.xz
hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.zip
- Tested and fixed resolve_hostbyname.
- Applied said function around most of the code where needed. Removed includes for the OS/network system pretty much from every file (our socket.c file should handle this) - Added clif_getip_long, which returns the ip as a long. Prevents having to include the files to define the int_addr structure in all files that include clif.h - Made the GM mute request bypass the manner_system setting. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7285 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c91
-rw-r--r--src/char_sql/char.c95
-rw-r--r--src/common/socket.c7
-rw-r--r--src/common/socket.h6
-rw-r--r--src/login/login.c38
-rw-r--r--src/login_sql/login.c46
-rw-r--r--src/map/chrif.c24
-rw-r--r--src/map/chrif.h2
-rw-r--r--src/map/clif.c71
-rw-r--r--src/map/clif.h13
-rw-r--r--src/map/intif.c12
-rw-r--r--src/map/irc.c32
-rw-r--r--src/map/map.c59
-rw-r--r--src/map/mercenary.c1
-rw-r--r--src/map/npc_chat.c10
15 files changed, 161 insertions, 346 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 784f6498b..d0c13c105 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2,20 +2,13 @@
// For more information, see LICENCE in the main folder
#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
#ifdef _WIN32
#include <winsock.h>
-typedef long in_addr_t;
#else
#include <sys/socket.h>
-#include <netinet/in.h>
+#include <netinet/in.h>
#include <arpa/inet.h>
-#include <netdb.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <unistd.h>
#endif
#include <time.h>
@@ -23,6 +16,8 @@ typedef long in_addr_t;
#include <fcntl.h>
#include <string.h>
#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <limits.h>
#include "../common/strlib.h"
@@ -54,15 +49,13 @@ char userid[24];
char passwd[24];
char server_name[20];
char wisp_server_name[NAME_LENGTH] = "Server";
-int login_ip_set_ = 0;
char login_ip_str[16];
in_addr_t login_ip;
int login_port = 6900;
-int char_ip_set_ = 0;
char char_ip_str[16];
-int bind_ip_set_ = 0;
-char bind_ip_str[16];
in_addr_t char_ip;
+char bind_ip_str[16];
+in_addr_t bind_ip;
int char_port = 6121;
int char_maintenance;
int char_new;
@@ -1798,7 +1791,6 @@ static int char_delete(struct mmo_charstatus *cs) {
int parse_tologin(int fd) {
int i;
struct char_session_data *sd;
- struct hostent *h;
RFIFOHEAD(fd);
// only login-server can have an access to here.
@@ -2296,14 +2288,16 @@ int parse_tologin(int fd) {
}
break;
case 0x2735:
+ {
+ unsigned char ip[4];
ShowInfo("IP Sync in progress...\n");
- h = char_server_dns?gethostbyname(char_server_dns):NULL;
- if(h){
+ if (char_server_dns && resolve_hostbyname(char_server_dns, ip, NULL))
+ {
WFIFOW(fd,0) = 0x2736;
- WFIFOB(fd,2) = h->h_addr[0];
- WFIFOB(fd,3) = h->h_addr[1];
- WFIFOB(fd,4) = h->h_addr[2];
- WFIFOB(fd,5) = h->h_addr[3];
+ WFIFOB(fd,2) = ip[0];
+ WFIFOB(fd,3) = ip[1];
+ WFIFOB(fd,4) = ip[2];
+ WFIFOB(fd,5) = ip[3];
WFIFOSET(fd, 6);
}
for(i = 0; i < MAX_MAP_SERVERS; i++){
@@ -2314,6 +2308,7 @@ int parse_tologin(int fd) {
}
RFIFOSKIP(fd,2);
break;
+ }
default:
ShowWarning("Unknown packet 0x%04x received from login-server, disconnecting.\n", RFIFOW(fd,0));
session[fd]->eof = 1;
@@ -3954,7 +3949,6 @@ int char_lan_config_read(const char *lancfgName) {
}
int char_config_read(const char *cfgName) {
- struct hostent *h = NULL;
char line[1024], w1[1024], w2[1024];
FILE *fp = fopen(cfgName, "r");
@@ -3994,35 +3988,24 @@ int char_config_read(const char *cfgName) {
wisp_server_name[sizeof(wisp_server_name) - 1] = '\0';
}
} else if (strcmpi(w1, "login_ip") == 0) {
- login_ip_set_ = 1;
- h = gethostbyname(w2);
- if(char_server_dns)
- aFree(char_server_dns);
- char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
- strcpy(char_server_dns, w2);
- if (h != NULL) {
- ShowStatus("Login server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(login_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(login_ip_str, w2, 16);
+ login_ip = resolve_hostbyname(w2, NULL, login_ip_str);
+ if (login_ip) {
+ if(char_server_dns)
+ aFree(char_server_dns);
+ char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
+ strcpy(char_server_dns, w2);
+ ShowStatus("Login server IP address : %s -> %s\n", w2, login_ip_str);
+ }
} else if (strcmpi(w1, "login_port") == 0) {
login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- char_ip_set_ = 1;
- h = gethostbyname(w2);
- if (h != NULL) {
- ShowStatus("Character server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(char_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(char_ip_str, w2, 16);
+ char_ip = resolve_hostbyname(w2, NULL, char_ip_str);
+ if (char_ip)
+ ShowStatus("Character server IP address : %s -> %s\n", w2, char_ip_str);
} else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip_set_ = 1;
- h = gethostbyname(w2);
- if (h != NULL) {
- ShowStatus("Character server binding IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(bind_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(bind_ip_str, w2, 16);
+ bind_ip = resolve_hostbyname(w2, NULL, bind_ip_str);
+ if (bind_ip)
+ ShowStatus("Character server binding IP address : %s -> %s\n", w2, bind_ip_str);
} else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2);
} else if (strcmpi(w1, "char_maintenance") == 0) {
@@ -4225,7 +4208,7 @@ int do_init(int argc, char **argv) {
// moved behind char_config_read in case we changed the filename [celest]
char_log("The char-server starting..." RETCODE);
- if ((naddr_ != 0) && (login_ip_set_ == 0 || char_ip_set_ == 0)) {
+ if ((naddr_ != 0) && (!login_ip || !char_ip)) {
// The char server should know what IP address it is running on
// - MouseJstr
int localaddr = ntohl(addr_[0]);
@@ -4236,18 +4219,19 @@ int do_init(int argc, char **argv) {
ShowStatus("Multiple interfaces detected.. using %s as our IP address\n", buf);
else
ShowStatus("Defaulting to %s as our IP address\n", buf);
- if (login_ip_set_ == 0)
+ if (!login_ip) {
strcpy(login_ip_str, buf);
- if (char_ip_set_ == 0)
+ login_ip = inet_addr(login_ip_str);
+ }
+ if (!char_ip) {
strcpy(char_ip_str, buf);
+ char_ip = inet_addr(char_ip_str);
+ }
if (ptr[0] == 192 && ptr[1] == 168)
ShowWarning("Firewall detected.. edit subnet_athena.conf and char_athena.conf\n");
}
- login_ip = inet_addr(login_ip_str);
- char_ip = inet_addr(char_ip_str);
-
for(i = 0; i < MAX_MAP_SERVERS; i++) {
memset(&server[i], 0, sizeof(struct mmo_map_server));
server_fd[i] = -1;
@@ -4266,10 +4250,7 @@ int do_init(int argc, char **argv) {
set_defaultparse(parse_char);
- if (bind_ip_set_)
- char_fd = make_listen_bind(inet_addr(bind_ip_str),char_port);
- else
- char_fd = make_listen_bind(INADDR_ANY,char_port);
+ char_fd = make_listen_bind(bind_ip?bind_ip:INADDR_ANY,char_port);
add_timer_func_list(check_connect_login_server, "check_connect_login_server");
add_timer_func_list(send_users_tologin, "send_users_tologin");
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 51f40b498..e1ba1455b 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -8,16 +8,10 @@
#ifdef _WIN32
#include <winsock.h>
-typedef long in_addr_t;
-//#pragma lib <libmysql.lib> // Not required [Lance]
#else
#include <sys/socket.h>
#include <netinet/in.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
#endif
#include <time.h>
@@ -81,15 +75,13 @@ char userid[24];
char passwd[24];
char server_name[20];
char wisp_server_name[NAME_LENGTH] = "Server";
-int login_ip_set_ = 0;
char login_ip_str[128];
-in_addr_t login_ip;
+in_addr_t login_ip = 0;
int login_port = 6900;
-int char_ip_set_ = 0;
char char_ip_str[128];
-int bind_ip_set_ = 0;
+in_addr_t char_ip = 0;
char bind_ip_str[128];
-in_addr_t char_ip;
+in_addr_t bind_ip = 0;
int char_port = 6121;
int char_maintenance;
int char_new;
@@ -1784,7 +1776,6 @@ int mmo_char_send006b(int fd, struct char_session_data *sd) {
int parse_tologin(int fd) {
int i;
struct char_session_data *sd;
- struct hostent *h;
// only login-server can have an access to here.
// so, if it isn't the login-server, we disconnect the session.
@@ -2182,15 +2173,17 @@ int parse_tologin(int fd) {
break;
case 0x2735:
+ {
+ unsigned char ip_str[4];
ShowInfo("IP Sync in progress...\n");
- h = char_server_dns?gethostbyname(char_server_dns):NULL;
- if(h){
+ if (char_server_dns && resolve_hostbyname(char_server_dns, ip_str, NULL))
+ {
WFIFOW(fd,0) = 0x2736;
- WFIFOB(fd,2) = h->h_addr[0];
- WFIFOB(fd,3) = h->h_addr[1];
- WFIFOB(fd,4) = h->h_addr[2];
- WFIFOB(fd,5) = h->h_addr[3];
- WFIFOSET(fd, 6);
+ WFIFOB(fd,2) = ip_str[0];
+ WFIFOB(fd,3) = ip_str[1];
+ WFIFOB(fd,4) = ip_str[2];
+ WFIFOB(fd,5) = ip_str[3];
+ WFIFOSET(fd,6);
}
for(i = 0; i < MAX_MAP_SERVERS; i++){
if(server_fd[i] >= 0){
@@ -2200,7 +2193,7 @@ int parse_tologin(int fd) {
}
RFIFOSKIP(fd,2);
break;
-
+ }
default:
ShowError("Unknown packet 0x%04x from login server, disconnecting.\n", RFIFOW(fd, 0));
session[fd]->eof = 1;
@@ -4064,7 +4057,6 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
}
int char_config_read(const char *cfgName) {
- struct hostent *h = NULL;
char line[1024], w1[1024], w2[1024];
FILE *fp;
@@ -4104,34 +4096,27 @@ int char_config_read(const char *cfgName) {
wisp_server_name[sizeof(wisp_server_name) - 1] = '\0';
}
} else if (strcmpi(w1, "login_ip") == 0) {
- login_ip_set_ = 1;
- h = gethostbyname (w2);
- if(char_server_dns)
- aFree(char_server_dns);
- char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
- if (h != NULL) {
- ShowStatus("Login server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(login_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(login_ip_str,w2,16);
+ unsigned char ip_str[4];
+ login_ip = resolve_hostbyname(w2, ip_str, login_ip_str);
+ if (login_ip) {
+ if(char_server_dns)
+ aFree(char_server_dns);
+ char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
+
+ ShowStatus("Login server IP address : %s -> %s\n", w2, login_ip_str);
+ }
} else if (strcmpi(w1, "login_port") == 0) {
login_port=atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- char_ip_set_ = 1;
- h = gethostbyname (w2);
- if(h != NULL) {
- ShowStatus("Character server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(char_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(char_ip_str, w2, 16);
+ unsigned char ip_str[4];
+ char_ip = resolve_hostbyname(w2, ip_str, char_ip_str);
+ if (char_ip)
+ ShowStatus("Character server IP address : %s -> %s\n", w2, char_ip_str);
} else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip_set_ = 1;
- h = gethostbyname (w2);
- if(h != NULL) {
- ShowStatus("Character server binding IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(bind_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(bind_ip_str, w2, 16);
+ unsigned char ip_str[4];
+ bind_ip = resolve_hostbyname(w2, ip_str, bind_ip_str);
+ if (bind_ip)
+ ShowStatus("Character server binging IP address : %s -> %s\n", w2, bind_ip_str);
} else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2);
} else if (strcmpi(w1, "char_maintenance") == 0) {
@@ -4293,7 +4278,7 @@ int do_init(int argc, char **argv){
// ShowDebug("set terminate function -> do_final().....\n");
- if ((naddr_ != 0) && (login_ip_set_ == 0 || char_ip_set_ == 0)) {
+ if ((naddr_ != 0) && (!login_ip || !char_ip)) {
// The char server should know what IP address it is running on
// - MouseJstr
int localaddr = ntohl(addr_[0]);
@@ -4304,24 +4289,20 @@ int do_init(int argc, char **argv){
ShowStatus("Multiple interfaces detected.. using %s as our IP address\n", buf);
else
ShowStatus("Defaulting to %s as our IP address\n", buf);
- if (login_ip_set_ == 0)
+ if (!login_ip) {
strcpy(login_ip_str, buf);
- if (char_ip_set_ == 0)
+ login_ip = inet_addr(login_ip_str);
+ }
+ if (!char_ip) {
strcpy(char_ip_str, buf);
-
+ char_ip = inet_addr(char_ip_str);
+ }
if (ptr[0] == 192 && ptr[1] == 168)
ShowWarning("Firewall detected.. edit subnet_athena.conf and char_athena.conf\n");
}
- login_ip = inet_addr(login_ip_str);
- char_ip = inet_addr(char_ip_str);
-
ShowInfo("open port %d.....\n",char_port);
- //char_fd = make_listen_port(char_port);
- if (bind_ip_set_)
- char_fd = make_listen_bind(inet_addr(bind_ip_str),char_port);
- else
- char_fd = make_listen_bind(INADDR_ANY,char_port);
+ char_fd = make_listen_bind(bind_ip?bind_ip:INADDR_ANY,char_port);
add_timer_func_list(check_connect_login_server, "check_connect_login_server");
add_timer_func_list(send_users_tologin, "send_users_tologin");
diff --git a/src/common/socket.c b/src/common/socket.c
index a9a9c628b..dc8162ee1 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1392,14 +1392,17 @@ bool session_isActive(int fd)
return ( session_isValid(fd) && !session[fd]->eof );
}
-in_addr_t resolve_hostbyname(char* hostname, char *ip) {
+in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str) {
struct hostent *h = gethostbyname(hostname);
- char ip_str[16];
+ unsigned char ip_buf[16];
+ char ip2[4];
if (!h) return 0;
+ if (ip == NULL) ip = ip2;
ip[0] = (unsigned char) h->h_addr[0];
ip[1] = (unsigned char) h->h_addr[1];
ip[2] = (unsigned char) h->h_addr[2];
ip[3] = (unsigned char) h->h_addr[3];
+ if (ip_str == NULL) ip_str = ip_buf;
sprintf(ip_str, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
return inet_addr(ip_str);
}
diff --git a/src/common/socket.h b/src/common/socket.h
index 4d8d36807..158759f9e 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -9,6 +9,7 @@
#ifdef __WIN32
#define __USE_W32_SOCKETS
#include <windows.h>
+typedef long in_addr_t;
#else
#include <sys/types.h>
#include <sys/socket.h>
@@ -157,7 +158,10 @@ void set_defaultconsoleparse(int (*defaultparse)(char*));
//Resolves the hostname and stores the string representation of the string in ip.
//Meant to simplify calls to gethostbyname without the need of all the
//required network includes.
-in_addr_t resolve_hostbyname(char* hostname, char *ip);
+//hostname is the name to resolve.
+//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)
+in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str);
extern unsigned int addr_[16]; // ip addresses of local host (host byte order)
extern unsigned int naddr_; // # of ip addresses
diff --git a/src/login/login.c b/src/login/login.c
index 949b1d80c..41d51220a 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -7,25 +7,10 @@
#ifdef __WIN32
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
-#include <time.h>
-void Gettimeofday(struct timeval *timenow)
-{
- time_t t;
- t = clock();
- timenow->tv_usec = (long)t;
- timenow->tv_sec = (long)(t / CLK_TCK);
- return;
-}
-#define gettimeofday(timenow, dummy) Gettimeofday(timenow)
-#define in_addr_t unsigned long
#else
#include <sys/socket.h>
#include <netinet/in.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
#include <arpa/inet.h>
-#include <netdb.h>
#endif
#include <stdio.h>
#include <stdlib.h>
@@ -55,7 +40,7 @@ void Gettimeofday(struct timeval *timenow)
int account_id_count = START_ACCOUNT_NUM;
int server_num;
int new_account_flag = 0;
-int bind_ip_set_ = 0;
+in_addr_t bind_ip= 0;
char bind_ip_str[128];
int login_port = 6900;
@@ -1180,14 +1165,14 @@ int mmo_auth(struct mmo_account* account, int fd) {
dnsbl_serv=strtok(dnsbl_servs,",");
sprintf(ip_dnsbl,"%s.%s",r_ip,dnsbl_serv);
- if(gethostbyname(ip_dnsbl)!=NULL) {
+ if(resolve_hostbyname(ip_dnsbl,NULL,NULL)) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n",ip);
return 3;
}
- while((dnsbl_serv=strtok(dnsbl_servs,","))!=NULL) {
+ while((dnsbl_serv=strtok(dnsbl_servs,","))) {
sprintf(ip_dnsbl,"%s.%s",r_ip,dnsbl_serv);
- if(gethostbyname(ip_dnsbl)!=NULL) {
+ if(resolve_hostbyname(ip_dnsbl,NULL,NULL)!=NULL) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n",ip);
return 3;
}
@@ -3651,13 +3636,9 @@ int login_config_read(const char *cfgName) {
} else if (strcmpi(w1, "new_account") == 0) {
new_account_flag = config_switch(w2);
} else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip_set_ = 1;
- h = gethostbyname (w2);
- if (h != NULL) {
- ShowStatus("Login server binding IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(bind_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(bind_ip_str,w2,16);
+ bind_ip = resolve_hostbyname(w2, NULL, bind_ip_str);
+ if (bind_ip)
+ ShowStatus("Login server binding IP address : %s -> %s\n", w2, bind_ip_str);
} else if (strcmpi(w1, "login_port") == 0) {
login_port = atoi(w2);
} else if (strcmpi(w1, "account_filename") == 0) {
@@ -4169,10 +4150,7 @@ int do_init(int argc, char **argv) {
online_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int)); // reinitialise
add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
- if (bind_ip_set_)
- login_fd = make_listen_bind(inet_addr(bind_ip_str),login_port);
- else
- login_fd = make_listen_bind(INADDR_ANY,login_port);
+ login_fd = make_listen_bind(bind_ip?bind_ip:INADDR_ANY,login_port);
add_timer_func_list(check_auth_sync, "check_auth_sync");
add_timer_interval(gettick() + 60000, check_auth_sync, 0, 0, 60000); // every 60 sec we check if we must save accounts file (only if necessary to save)
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index 14c71722c..a152b7dc4 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -5,32 +5,15 @@
#ifdef LCCWIN32
#include <winsock.h>
-#pragma lib <libmysql.lib>
#else
#ifdef __WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
-#include <time.h>
-void Gettimeofday(struct timeval *timenow)
-{
- time_t t;
- t = clock();
- timenow->tv_usec = (long)t;
- timenow->tv_sec = (long)(t / CLK_TCK);
- return;
-}
-#define gettimeofday(timenow, dummy) Gettimeofday(timenow)
-#define in_addr_t unsigned long
-#pragma comment(lib,"libmysql.lib")
#else
#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
+#include <netinet/in.h>
#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
#endif
#endif
@@ -69,7 +52,7 @@ int use_dnsbl=0; // [Zido]
char dnsbl_servs[1024];
int server_num;
int new_account_flag = 0; //Set from config too XD [Sirius]
-int bind_ip_set_ = 0;
+in_addr_t bind_ip= 0;
char bind_ip_str[128];
int login_port = 6900;
@@ -559,10 +542,6 @@ int mmo_auth_new(struct mmo_account* account, char sex)
return 0;
}
-#ifdef LCCWIN32
-extern void gettimeofday(struct timeval *t, struct timezone *dummy);
-#endif
-
// Send to char
int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len) {
int i, c;
@@ -613,14 +592,14 @@ int mmo_auth( struct mmo_account* account , int fd){
dnsbl_serv=strtok(dnsbl_servs,",");
sprintf(ip_dnsbl,"%s.%s",r_ip,dnsbl_serv);
- if(gethostbyname(ip_dnsbl)!=NULL) {
+ if(resolve_hostbyname(ip_dnsbl, NULL, NULL)) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n",ip);
return 3;
}
while((dnsbl_serv=strtok(dnsbl_servs,","))!=NULL) {
sprintf(ip_dnsbl,"%s.%s",r_ip,dnsbl_serv);
- if(gethostbyname(ip_dnsbl)!=NULL) {
+ if(resolve_hostbyname(ip_dnsbl, NULL, NULL)) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n",ip);
return 3;
}
@@ -2064,7 +2043,6 @@ int ip_ban_check(int tid, unsigned int tick, int id, int data){
//-----------------------------------------------------
int login_config_read(const char *cfgName){
int i;
- struct hostent *h = NULL;
char line[1024], w1[1024], w2[1024];
FILE *fp;
@@ -2092,13 +2070,9 @@ int login_config_read(const char *cfgName){
ShowInfo("Console Silent Setting: %d\n", atoi(w2));
msg_silent = atoi(w2);
} else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip_set_ = 1;
- h = gethostbyname (w2);
- if (h != NULL) {
- ShowStatus("Login server binding IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(bind_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- } else
- memcpy(bind_ip_str,w2,16);
+ bind_ip = resolve_hostbyname(w2, NULL, bind_ip_str);
+ if (bind_ip)
+ ShowStatus("Login server binding IP address : %s -> %s\n", w2, bind_ip_str);
} else if(strcmpi(w1,"login_port")==0){
login_port=atoi(w2);
ShowStatus("set login_port : %s\n",w2);
@@ -2344,11 +2318,7 @@ int do_init(int argc,char **argv){
online_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int)); // reinitialise
add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
- //login_fd=make_listen_port(login_port);
- if (bind_ip_set_)
- login_fd = make_listen_bind(inet_addr(bind_ip_str),login_port);
- else
- login_fd = make_listen_bind(INADDR_ANY,login_port);
+ login_fd = make_listen_bind(bind_ip?bind_ip:INADDR_ANY,login_port);
//Auth start
ShowInfo("Running mmo_auth_sqldb_init()\n");
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 2396f5175..19002eab4 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -4,14 +4,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef _WIN32
-#include <winsock.h>
-#else
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
#include <sys/types.h>
#include <time.h>
#include <limits.h>
@@ -151,10 +143,16 @@ void chrif_checkdefaultlogin(void)
*
*------------------------------------------
*/
-void chrif_setip(char *ip)
+int chrif_setip(char *ip)
{
- memcpy(&char_ip_str, ip, 16);
- char_ip = inet_addr(char_ip_str);
+ char_ip = resolve_hostbyname(ip,NULL,char_ip_str);
+
+ if (!char_ip) {
+ ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
+ return 0;
+ }
+ ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, char_ip_str);
+ return 1;
}
/*==========================================
@@ -239,7 +237,7 @@ int chrif_connect(int fd)
memcpy(WFIFOP(fd,2), userid, NAME_LENGTH);
memcpy(WFIFOP(fd,26), passwd, NAME_LENGTH);
WFIFOL(fd,50) = 0;
- WFIFOL(fd,54) = clif_getip();
+ WFIFOL(fd,54) = clif_getip_long();
WFIFOW(fd,58) = clif_getport(); // [Valaris] thanks to fov
WFIFOSET(fd,60);
@@ -1417,7 +1415,7 @@ int chrif_disconnect(int fd) {
void chrif_update_ip(int fd){
char ip[4];
ShowInfo("IP Sync in progress...\n");
- if (map_server_dns && resolve_hostbyname(map_server_dns, ip)) {
+ if (map_server_dns && resolve_hostbyname(map_server_dns, ip, NULL)) {
WFIFOW(fd, 0) = 0x2736;
WFIFOB(fd, 2) = ip[0];
WFIFOB(fd, 3) = ip[1];
diff --git a/src/map/chrif.h b/src/map/chrif.h
index cc427fe92..5902a628a 100644
--- a/src/map/chrif.h
+++ b/src/map/chrif.h
@@ -15,7 +15,7 @@ struct auth_node{
void chrif_setuserid(char*);
void chrif_setpasswd(char*);
void chrif_checkdefaultlogin(void);
-void chrif_setip(char*);
+int chrif_setip(char*);
void chrif_setport(int);
int chrif_isconnect(void);
diff --git a/src/map/clif.c b/src/map/clif.c
index cc7b16d76..c66c0adc9 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10,16 +10,6 @@
#include <string.h>
#include <stdarg.h>
#include <limits.h>
-#ifdef __WIN32
-#define __USE_W32_SOCKETS
-#include <windows.h>
-#else
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
#include <time.h>
#include "../common/socket.h"
@@ -160,15 +150,30 @@ static void clif_hpmeter_single(int fd, struct map_session_data *sd);
* map鯖のip設定
*------------------------------------------
*/
-void clif_setip(char *ip)
+int clif_setip(char *ip)
{
- memcpy(map_ip_str, ip, 16);
- map_ip = inet_addr(map_ip_str);
+ map_ip = resolve_hostbyname(ip,NULL,map_ip_str);
+ if (!map_ip) {
+ ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
+ return 0;
+ }
+ if(map_server_dns)
+ aFree(map_server_dns);
+ map_server_dns = aCalloc(strlen(ip)+1,1);
+ strcpy(map_server_dns, ip);
+ ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, map_ip_str);
+ return 1;
}
void clif_setbindip(char *ip)
{
- bind_ip = inet_addr(ip);
+ unsigned char ip_str[4];
+ bind_ip = resolve_hostbyname(ip,ip_str,NULL);
+ if (bind_ip) {
+ ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip, ip_str[0], ip_str[1], ip_str[2], ip_str[3]);
+ } else {
+ ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
+ }
}
/*==========================================
@@ -189,6 +194,12 @@ in_addr_t clif_getip(void)
return map_ip;
}
+//Returns the ip casted as a basic type, to avoid needing to include the socket/net related libs by calling modules.
+unsigned long clif_getip_long(void)
+{
+ return (unsigned long)map_ip;
+}
+
/*==========================================
* map鯖のport読み出し
*------------------------------------------
@@ -10601,16 +10612,13 @@ void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
|| (type == 2 && !level)) {
clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
- if (battle_config.manner_system)
+ dstsd->status.manner -= limit;
+ if(dstsd->status.manner < 0)
+ sc_start(bl,SC_NOCHAT,100,0,0);
+ else
{
- dstsd->status.manner -= limit;
- if(dstsd->status.manner < 0)
- sc_start(bl,SC_NOCHAT,100,0,0);
- else
- {
- dstsd->status.manner = 0;
- status_change_end(bl,SC_NOCHAT,-1);
- }
+ dstsd->status.manner = 0;
+ status_change_end(bl,SC_NOCHAT,-1);
}
ShowDebug("GMReqNoChat: name:%s type:%d limit:%d manner:%d\n", dstsd->status.name, type, limit, dstsd->status.manner);
}
@@ -11775,9 +11783,6 @@ static int packetdb_readdb(void)
*------------------------------------------
*/
int do_init_clif(void) {
-#ifndef __WIN32
- int i;
-#endif
clif_config.packet_db_ver = -1; // the main packet version of the DB
memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
@@ -11787,24 +11792,10 @@ int do_init_clif(void) {
packetdb_readdb();
set_defaultparse(clif_parse);
-#ifdef __WIN32
- //if (!make_listen_port(map_port)) {
if (!make_listen_bind(bind_ip,map_port)) {
ShowFatalError("cant bind game port\n");
exit(1);
}
-#else
- for(i = 0; i < 10; i++) {
- //if (make_listen_port(map_port))
- if (make_listen_bind(bind_ip,map_port))
- break;
- sleep(20);
- }
- if (i == 10) {
- ShowFatalError("cant bind game port\n");
- exit(1);
- }
-#endif
add_timer_func_list(clif_waitclose, "clif_waitclose");
add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
diff --git a/src/map/clif.h b/src/map/clif.h
index 3143cafb8..91f82662e 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -4,15 +4,6 @@
#ifndef _CLIF_H_
#define _CLIF_H_
-#ifdef __WIN32
-typedef unsigned int in_addr_t;
-#else
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
-
#include "map.h"
// protocol version
@@ -57,11 +48,11 @@ enum {
extern struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
-void clif_setip(char*);
+int clif_setip(char*);
void clif_setbindip(char*);
void clif_setport(int);
-in_addr_t clif_getip(void);
+unsigned long clif_getip_long(void);
int clif_getport(void);
int clif_countusers(void);
void clif_setwaitclose(int);
diff --git a/src/map/intif.c b/src/map/intif.c
index fff356d5c..09e83b831 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -2,20 +2,8 @@
// For more information, see LICENCE in the main folder
#include <sys/types.h>
-#ifdef _WIN32
-#include <winsock.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
-#ifndef _WIN32
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-#endif
#include <signal.h>
#include <fcntl.h>
#include <string.h>
diff --git a/src/map/irc.c b/src/map/irc.c
index 4c14d81d6..4cfe1fc7c 100644
--- a/src/map/irc.c
+++ b/src/map/irc.c
@@ -1,28 +1,7 @@
#include <ctype.h>
#include <string.h>
-
-#ifdef __WIN32
-#define __USE_W32_SOCKETS
-#include <windows.h>
-#include <io.h>
-typedef int socklen_t;
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <ctype.h>
#include <stdlib.h>
-#ifndef SIOCGIFCONF
-#include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
-#endif
-
-#endif
-
#include "../common/core.h"
#include "../common/socket.h"
#include "../common/malloc.h"
@@ -357,24 +336,17 @@ void do_final_irc(void)
void do_init_irc(void)
{
- struct hostent *irc_hostname;
-
if(!use_irc)
return;
if (irc_ip_str[strlen(irc_ip_str)-1] == '\n')
irc_ip_str[strlen(irc_ip_str)-1] = '\0';
- irc_hostname=gethostbyname(irc_ip_str);
- if (!irc_hostname)
+ irc_ip = resolve_hostbyname(irc_ip_str, NULL, irc_ip_str);
+ if (!irc_ip)
{
ShowError("Unable to resolve %s! Cannot connect to IRC server, disabling irc_bot.\n", irc_ip_str);
use_irc = 0;
return;
}
- irc_ip_str[0]='\0';
- sprintf(irc_ip_str, "%d.%d.%d.%d", (unsigned char)irc_hostname->h_addr[0], (unsigned char)irc_hostname->h_addr[1],
- (unsigned char)irc_hostname->h_addr[2], (unsigned char)irc_hostname->h_addr[3]);
-
- irc_ip=inet_addr(irc_ip_str);
irc_connect_timer(0, 0, 0, 0);
diff --git a/src/map/map.c b/src/map/map.c
index 569c32f26..34498bd89 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -5,13 +5,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#ifdef _WIN32
-#include <winsock.h>
-#else
-#include <netdb.h>
-#include <unistd.h>
-#endif
#include <math.h>
+#include <unistd.h>
#include "../common/core.h"
#include "../common/timer.h"
@@ -2300,7 +2295,7 @@ int map_setipport(unsigned short mapindex,unsigned long ip,int port) {
if(mdos->gat) //Local map,Do nothing. Give priority to our own local maps over ones from another server. [Skotlex]
return 0;
- if(ip == clif_getip() && port == clif_getport()) {
+ if(ip == clif_getip_long() && port == clif_getport()) {
//That's odd, we received info that we are the ones with this map, but... we don't have it.
ShowFatalError("map_setipport : received info that this map-server SHOULD have map '%s', but it is not loaded.\n",mapindex_id2name(mapindex));
exit(1);
@@ -3171,10 +3166,8 @@ int map_readallmaps (void)
}
////////////////////////////////////////////////////////////////////////
-
-static int map_ip_set_ = 0;
-static int char_ip_set_ = 0;
-//static int bind_ip_set_ = 0;
+static int map_ip_set = 0;
+static int char_ip_set = 0;
/*==========================================
* Console Command Parser [Wizputer]
@@ -3263,7 +3256,6 @@ int parse_console(char *buf) {
int map_config_read(char *cfgName) {
char line[1024], w1[1024], w2[1024];
FILE *fp;
- struct hostent *h = NULL;
fp = fopen(cfgName,"r");
if (fp == NULL) {
@@ -3285,34 +3277,12 @@ int map_config_read(char *cfgName) {
} else if (strcmpi(w1, "passwd") == 0) {
chrif_setpasswd(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- char_ip_set_ = 1;
- h = gethostbyname (w2);
- if(h != NULL) {
- ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(w2,"%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- }
- chrif_setip(w2);
+ char_ip_set = chrif_setip(w2);
} else if (strcmpi(w1, "char_port") == 0) {
chrif_setport(atoi(w2));
} else if (strcmpi(w1, "map_ip") == 0) {
- map_ip_set_ = 1;
- h = gethostbyname (w2);
- if(map_server_dns)
- aFree(map_server_dns);
- map_server_dns = aCalloc(strlen(w2)+1,1);
- strcpy(map_server_dns, w2);
- if (h != NULL) {
- ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(w2, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- }
- clif_setip(w2);
+ map_ip_set = clif_setip(w2);
} else if (strcmpi(w1, "bind_ip") == 0) {
- //bind_ip_set_ = 1;
- h = gethostbyname (w2);
- if (h != NULL) {
- ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- sprintf(w2, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
- }
clif_setbindip(w2);
} else if (strcmpi(w1, "map_port") == 0) {
clif_setport(atoi(w2));
@@ -3847,26 +3817,25 @@ int do_init(int argc, char *argv[]) {
irc_read_conf(IRC_CONF); // [Zido]
chrif_checkdefaultlogin();
- if ((naddr_ == 0) && (map_ip_set_ == 0 || char_ip_set_ == 0)) {
- ShowError("\nUnable to determine your IP address... please edit the map_athena.conf file and set it.\n");
- ShowError("(127.0.0.1 is valid if you have no network interface)\n");
- }
-
- if (map_ip_set_ == 0 || char_ip_set_ == 0) {
+ if (!map_ip_set || !char_ip_set) {
// The map server should know what IP address it is running on
// - MouseJstr
int localaddr = ntohl(addr_[0]);
unsigned char *ptr = (unsigned char *) &localaddr;
char buf[16];
+ if (naddr_ == 0) {
+ ShowError("\nUnable to determine your IP address... please edit the map_athena.conf file and set it.\n");
+ ShowError("(127.0.0.1 is valid if you have no network interface)\n");
+ }
sprintf(buf, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);;
if (naddr_ != 1)
ShowNotice("Multiple interfaces detected.. using %s as our IP address\n", buf);
else
ShowInfo("Defaulting to %s as our IP address\n", buf);
- if (map_ip_set_ == 0)
+ if (!map_ip_set)
clif_setip(buf);
- if (char_ip_set_ == 0)
- chrif_setip(buf);
+ if (!char_ip_set)
+ chrif_setip(buf);
if (ptr[0] == 192 && ptr[1] == 168)
ShowNotice("\nFirewall detected.. \n edit subnet_athena.conf and map_athena.conf\n\n");
}
diff --git a/src/map/mercenary.c b/src/map/mercenary.c
index 58e0e69a4..8f599be43 100644
--- a/src/map/mercenary.c
+++ b/src/map/mercenary.c
@@ -9,7 +9,6 @@
#include "../common/timer.h"
#include "../common/nullpo.h"
#include "../common/mmo.h"
-#include "../common/core.h"
#include "../common/showmsg.h"
#include "log.h"
diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c
index eaab82aff..1e5da1277 100644
--- a/src/map/npc_chat.c
+++ b/src/map/npc_chat.c
@@ -8,16 +8,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#ifdef __WIN32
-#define __USE_W32_SOCKETS
-#include <windows.h>
-#else
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
#include <time.h>
#include "../common/timer.h"