summaryrefslogtreecommitdiff
path: root/src/map
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/map
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/map')
-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
9 files changed, 61 insertions, 163 deletions
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"