* Some source code cleaning

- Fixed the badly worded messages during mapserver startup
- Cleaned up socket config reading
- Split resolve_hostbyname() into 2 separate functions for clarity
- Moved the probably obsolete LOWER/UPPER macros to db.c (TODO: remove)
- Moved the badly placed compare_item() function to storage.c (see r779)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10119 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2007-04-02 13:46:11 +00:00
parent 99fb323a0a
commit a167b6ae62
16 changed files with 135 additions and 142 deletions

View File

@ -4,6 +4,12 @@ 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/04/03 2007/04/03
* Some source code cleaning
- Fixed the badly worded messages during mapserver startup
- Cleaned up socket config reading
- Split resolve_hostbyname() into 2 separate functions for clarity
- Moved the probably obsolete LOWER/UPPER macros to db.c (TODO: remove)
- Moved the badly placed compare_item() function to storage.c (see r779)
* Fully removed the msvcr80.dll dependency from the vs8 project files * Fully removed the msvcr80.dll dependency from the vs8 project files
2007/04/02 2007/04/02
* Removed some overly verbose item group messages & code * Removed some overly verbose item group messages & code

View File

@ -2478,11 +2478,11 @@ int parse_tologin(int fd) {
WBUFW(buf,0) = 0x2b1e; WBUFW(buf,0) = 0x2b1e;
mapif_sendall(buf, 2); mapif_sendall(buf, 2);
new_ip = resolve_hostbyname(login_ip_str, NULL, NULL); new_ip = host2ip(login_ip_str);
if (new_ip && new_ip != login_ip) if (new_ip && new_ip != login_ip)
login_ip = new_ip; //Update login up. login_ip = new_ip; //Update login up.
new_ip = resolve_hostbyname(char_ip_str, NULL, NULL); new_ip = host2ip(char_ip_str);
if (new_ip && new_ip != char_ip) if (new_ip && new_ip != char_ip)
{ //Update ip. { //Update ip.
WFIFOHEAD(fd,6); WFIFOHEAD(fd,6);
@ -4113,26 +4113,26 @@ int char_config_read(const char *cfgName) {
} }
} else if (strcmpi(w1, "login_ip") == 0) { } else if (strcmpi(w1, "login_ip") == 0) {
char ip_str[16]; char ip_str[16];
login_ip = resolve_hostbyname(w2, NULL, ip_str); login_ip = host2ip(w2);
if (login_ip) { if (login_ip) {
strncpy(login_ip_str, w2, sizeof(login_ip_str)); strncpy(login_ip_str, w2, sizeof(login_ip_str));
ShowStatus("Login server IP address : %s -> %s\n", w2, ip_str); ShowStatus("Login server IP address : %s -> %s\n", w2, ip2str(login_ip, ip_str));
} }
} else if (strcmpi(w1, "login_port") == 0) { } else if (strcmpi(w1, "login_port") == 0) {
login_port = atoi(w2); login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) { } else if (strcmpi(w1, "char_ip") == 0) {
char ip_str[16]; char ip_str[16];
char_ip = resolve_hostbyname(w2, NULL, ip_str); char_ip = host2ip(w2);
if (char_ip){ if (char_ip){
strncpy(char_ip_str, w2, sizeof(char_ip_str)); strncpy(char_ip_str, w2, sizeof(char_ip_str));
ShowStatus("Character server IP address : %s -> %s\n", w2, ip_str); ShowStatus("Character server IP address : %s -> %s\n", w2, ip2str(char_ip, ip_str));
} }
} else if (strcmpi(w1, "bind_ip") == 0) { } else if (strcmpi(w1, "bind_ip") == 0) {
char ip_str[16]; char ip_str[16];
bind_ip = resolve_hostbyname(w2, NULL, ip_str); bind_ip = host2ip(w2);
if (bind_ip) { if (bind_ip) {
strncpy(bind_ip_str, w2, sizeof(bind_ip_str)); strncpy(bind_ip_str, w2, sizeof(bind_ip_str));
ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip_str); ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip2str(bind_ip, ip_str));
} }
} else if (strcmpi(w1, "char_port") == 0) { } else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2); char_port = atoi(w2);

View File

@ -2245,11 +2245,11 @@ int parse_tologin(int fd) {
WBUFW(buf,0) = 0x2b1e; WBUFW(buf,0) = 0x2b1e;
mapif_sendall(buf, 2); mapif_sendall(buf, 2);
new_ip = resolve_hostbyname(login_ip_str, NULL, NULL); new_ip = host2ip(login_ip_str);
if (new_ip && new_ip != login_ip) //Update login ip, too. if (new_ip && new_ip != login_ip) //Update login ip, too.
login_ip = new_ip; login_ip = new_ip;
new_ip = resolve_hostbyname(char_ip_str, NULL, NULL); new_ip = host2ip(char_ip_str);
if (new_ip && new_ip != char_ip) if (new_ip && new_ip != char_ip)
{ //Update ip. { //Update ip.
char_ip = new_ip; char_ip = new_ip;
@ -4059,27 +4059,27 @@ int char_config_read(const char *cfgName) {
wisp_server_name[sizeof(wisp_server_name) - 1] = '\0'; wisp_server_name[sizeof(wisp_server_name) - 1] = '\0';
} }
} else if (strcmpi(w1, "login_ip") == 0) { } else if (strcmpi(w1, "login_ip") == 0) {
unsigned char ip_str[16]; char ip_str[16];
login_ip = resolve_hostbyname(w2, NULL, ip_str); login_ip = host2ip(w2);
if (login_ip) { if (login_ip) {
strncpy(login_ip_str, w2, sizeof(login_ip_str)); strncpy(login_ip_str, w2, sizeof(login_ip_str));
ShowStatus("Login server IP address : %s -> %s\n", w2, ip_str); ShowStatus("Login server IP address : %s -> %s\n", w2, ip2str(login_ip, ip_str));
} }
} else if (strcmpi(w1, "login_port") == 0) { } else if (strcmpi(w1, "login_port") == 0) {
login_port=atoi(w2); login_port=atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) { } else if (strcmpi(w1, "char_ip") == 0) {
unsigned char ip_str[16]; char ip_str[16];
char_ip = resolve_hostbyname(w2, NULL, ip_str); char_ip = host2ip(w2);
if (char_ip){ if (char_ip){
strncpy(char_ip_str, w2, sizeof(char_ip_str)); strncpy(char_ip_str, w2, sizeof(char_ip_str));
ShowStatus("Character server IP address : %s -> %s\n", w2, ip_str); ShowStatus("Character server IP address : %s -> %s\n", w2, ip2str(char_ip, ip_str));
} }
} else if (strcmpi(w1, "bind_ip") == 0) { } else if (strcmpi(w1, "bind_ip") == 0) {
unsigned char ip_str[16]; char ip_str[16];
bind_ip = resolve_hostbyname(w2, NULL, ip_str); bind_ip = host2ip(w2);
if (bind_ip) { if (bind_ip) {
strncpy(bind_ip_str, w2, sizeof(bind_ip_str)); strncpy(bind_ip_str, w2, sizeof(bind_ip_str));
ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip_str); ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip2str(bind_ip, ip_str));
} }
} else if (strcmpi(w1, "char_port") == 0) { } else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2); char_port = atoi(w2);

View File

@ -75,6 +75,10 @@
#include "../common/showmsg.h" #include "../common/showmsg.h"
#include "../common/ers.h" #include "../common/ers.h"
//TODO: get rid of this
#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c))
/*****************************************************************************\ /*****************************************************************************\
* (1) Private typedefs, enums, structures, defines and global variables of * * (1) Private typedefs, enums, structures, defines and global variables of *
* the database system. * * the database system. *

View File

@ -846,8 +846,7 @@ int access_ipmask(const char* str, AccessControl* acc)
} }
} }
if( access_debug ){ if( access_debug ){
ShowMessage("access_ipmask: Loaded IP:%d.%d.%d.%d mask:%d.%d.%d.%d\n", ShowMessage("access_ipmask: Loaded IP:%d.%d.%d.%d mask:%d.%d.%d.%d\n", CONVIP(ip), CONVIP(mask));
CONVIP(ip), CONVIP(mask));
} }
acc->ip = ip; acc->ip = ip;
acc->mask = mask; acc->mask = mask;
@ -857,8 +856,8 @@ int access_ipmask(const char* str, AccessControl* acc)
#endif #endif
////////////////////////////// //////////////////////////////
int socket_config_read(const char *cfgName) { int socket_config_read(const char *cfgName)
int i; {
char line[1024],w1[1024],w2[1024]; char line[1024],w1[1024],w2[1024];
FILE *fp; FILE *fp;
@ -867,59 +866,52 @@ int socket_config_read(const char *cfgName) {
ShowError("File not found: %s\n", cfgName); ShowError("File not found: %s\n", cfgName);
return 1; return 1;
} }
while(fgets(line,1020,fp)){
while(fgets(line,1020,fp))
{
if(line[0] == '/' && line[1] == '/') if(line[0] == '/' && line[1] == '/')
continue; continue;
i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2); if(sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
if(i!=2)
continue; continue;
if(strcmpi(w1,"stall_time")==0){
if (!strcmpi(w1, "stall_time"))
stall_time = atoi(w2); stall_time = atoi(w2);
#ifndef MINICORE #ifndef MINICORE
} else if( strcmpi(w1,"enable_ip_rules") == 0 ){ else if (!strcmpi(w1, "enable_ip_rules")) {
if( strcmpi(w2,"yes") == 0 ) ip_rules = config_switch(w2);
ip_rules = 1; } else if (!strcmpi(w1, "order")) {
else if( strcmpi(w2,"no") == 0 ) if (!strcmpi(w2, "deny,allow"))
ip_rules = 0;
else
ip_rules = atoi(w2);
} else if( strcmpi(w1,"order") == 0 ){
access_order = atoi(w2);
if( strcmpi(w2,"deny,allow") == 0 )
access_order = ACO_DENY_ALLOW; access_order = ACO_DENY_ALLOW;
else if( strcmpi(w2,"allow,deny") == 0 ) else if (!strcmpi(w2, "allow,deny"))
access_order = ACO_ALLOW_DENY; access_order = ACO_ALLOW_DENY;
else if( strcmpi(w2,"mutual-failure") == 0 ) else if (!strcmpi(w2, "mutual-failure"))
access_order = ACO_MUTUAL_FAILURE; access_order = ACO_MUTUAL_FAILURE;
} else if( strcmpi(w1,"allow") == 0 ){ } else if (!strcmpi(w1, "allow")) {
RECREATE(access_allow, AccessControl, access_allownum+1); RECREATE(access_allow, AccessControl, access_allownum+1);
if (access_ipmask(w2, &access_allow[access_allownum])) if (access_ipmask(w2, &access_allow[access_allownum]))
++access_allownum; ++access_allownum;
else else
ShowError("socket_config_read: Invalid ip or ip range '%s'!\n", line); ShowError("socket_config_read: Invalid ip or ip range '%s'!\n", line);
} else if( strcmpi(w1,"deny") == 0 ){ } else if (!strcmpi(w1, "deny")) {
RECREATE(access_deny, AccessControl, access_denynum+1); RECREATE(access_deny, AccessControl, access_denynum+1);
if (access_ipmask(w2, &access_deny[access_denynum])) if (access_ipmask(w2, &access_deny[access_denynum]))
++access_denynum; ++access_denynum;
else else
ShowError("socket_config_read: Invalid ip or ip range '%s'!\n", line); ShowError("socket_config_read: Invalid ip or ip range '%s'!\n", line);
} else if( strcmpi(w1,"ddos_interval") == 0){ }
else if (!strcmpi(w1,"ddos_interval"))
ddos_interval = atoi(w2); ddos_interval = atoi(w2);
} else if( strcmpi(w1,"ddos_count") == 0){ else if (!strcmpi(w1,"ddos_count"))
ddos_count = atoi(w2); ddos_count = atoi(w2);
} else if( strcmpi(w1,"ddos_autoreset") == 0){ else if (!strcmpi(w1,"ddos_autoreset"))
ddos_autoreset = atoi(w2); ddos_autoreset = atoi(w2);
} else if( strcmpi(w1,"debug") == 0){ else if (!strcmpi(w1,"debug"))
if( strcmpi(w2,"yes") == 0 ) access_debug = config_switch(w2);
access_debug = 1;
else if( strcmpi(w2,"no") == 0 )
access_debug = 0;
else
access_debug = atoi(w2);
#endif #endif
} else if (strcmpi(w1, "import") == 0) else if (!strcmpi(w1, "import"))
socket_config_read(w2); socket_config_read(w2);
} }
fclose(fp); fclose(fp);
return 0; return 0;
} }
@ -1107,18 +1099,16 @@ int session_isActive(int fd)
return ( session_isValid(fd) && !session[fd]->eof ); return ( session_isValid(fd) && !session[fd]->eof );
} }
in_addr_t resolve_hostbyname(const char* hostname, unsigned char* ip, char* ip_str)
in_addr_t host2ip(const char* hostname)
{ {
struct hostent* h = gethostbyname(hostname); struct hostent* h = gethostbyname(hostname);
char ip_buf[16]; return (h != NULL) ? *(in_addr_t*)h->h_addr : 0;
unsigned char ip2[4]; }
if (!h) return 0;
if (ip == NULL) ip = ip2; const char* ip2str(in_addr_t ip, char ip_str[16])
ip[0] = (unsigned char) h->h_addr[0]; {
ip[1] = (unsigned char) h->h_addr[1]; in_addr_t addr = ntohl(ip);
ip[2] = (unsigned char) h->h_addr[2]; sprintf(ip_str, "%d.%d.%d.%d", (addr>>24)&0xFF, (addr>>16)&0xFF, (addr>>8)&0xFF, (addr>>0)&0xFF);
ip[3] = (unsigned char) h->h_addr[3]; return ip_str;
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);
} }

View File

@ -125,13 +125,10 @@ extern void set_nonblocking(int fd, int yes);
void set_defaultparse(ParseFunc defaultparse); void set_defaultparse(ParseFunc defaultparse);
//Resolves the hostname and stores the string representation of the string in ip. // hostname/ip conversion functions
//Meant to simplify calls to gethostbyname without the need of all the in_addr_t host2ip(const char* hostname);
//required network includes. const char* ip2str(in_addr_t ip, char ip_str[16]);
//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(const char* hostname, unsigned char* ip, char* ip_str);
int socket_getips(uint32* ips, int max); int socket_getips(uint32* ips, int max);

View File

@ -10,9 +10,6 @@
#define NULL (void *)0 #define NULL (void *)0
#endif #endif
#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c) )
void dump(unsigned char *buffer, int num); void dump(unsigned char *buffer, int num);
struct StringBuf { struct StringBuf {

View File

@ -3636,10 +3636,10 @@ int login_config_read(const char* cfgName)
} else if (strcmpi(w1, "new_account") == 0) { } else if (strcmpi(w1, "new_account") == 0) {
new_account_flag = config_switch(w2); new_account_flag = config_switch(w2);
} else if (strcmpi(w1, "bind_ip") == 0) { } else if (strcmpi(w1, "bind_ip") == 0) {
char login_ip_str[128]; char ip_str[16];
login_ip = resolve_hostbyname(w2, NULL, login_ip_str); login_ip = host2ip(w2);
if (login_ip) if (login_ip)
ShowStatus("Login server binding IP address : %s -> %s\n", w2, login_ip_str); ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_ip, ip_str));
} else if (strcmpi(w1, "login_port") == 0) { } else if (strcmpi(w1, "login_port") == 0) {
login_port = atoi(w2); login_port = atoi(w2);
} else if (strcmpi(w1, "account_filename") == 0) { } else if (strcmpi(w1, "account_filename") == 0) {

View File

@ -1899,10 +1899,10 @@ int login_config_read(const char* cfgName)
msg_silent = atoi(w2); msg_silent = atoi(w2);
} }
else if (!strcmpi(w1, "bind_ip")) { else if (!strcmpi(w1, "bind_ip")) {
char login_ip_str[128]; char ip_str[16];
login_config.login_ip = resolve_hostbyname(w2, NULL, login_ip_str); login_config.login_ip = host2ip(w2);
if (login_config.login_ip) if (login_config.login_ip)
ShowStatus("Login server binding IP address : %s -> %s\n", w2, login_ip_str); ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_config.login_ip, ip_str));
} else if(!strcmpi(w1,"login_port")) { } else if(!strcmpi(w1,"login_port")) {
login_config.login_port = (unsigned short)atoi(w2); login_config.login_port = (unsigned short)atoi(w2);
ShowStatus("set login_port : %s\n",w2); ShowStatus("set login_port : %s\n",w2);

View File

@ -143,17 +143,16 @@ void chrif_checkdefaultlogin(void)
* *
*------------------------------------------ *------------------------------------------
*/ */
int chrif_setip(char *ip) int chrif_setip(const char *ip)
{ {
char ip_str[16]; char ip_str[16];
char_ip = resolve_hostbyname(ip,NULL,ip_str); char_ip = host2ip(ip);
if (!char_ip) { if (!char_ip) {
ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip); ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
return 0; return 0;
} }
strncpy(char_ip_str, ip, sizeof(char_ip_str)); strncpy(char_ip_str, ip, sizeof(char_ip_str));
ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str); ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str));
return 1; return 1;
} }
@ -1418,10 +1417,11 @@ int chrif_disconnect(int fd) {
return 0; return 0;
} }
void chrif_update_ip(int fd){ void chrif_update_ip(int fd)
{
unsigned long new_ip; unsigned long new_ip;
WFIFOHEAD(fd, 6); WFIFOHEAD(fd, 6);
new_ip = resolve_hostbyname(char_ip_str, NULL, NULL); new_ip = host2ip(char_ip_str);
if (new_ip && new_ip != char_ip) if (new_ip && new_ip != char_ip)
char_ip = new_ip; //Update char_ip char_ip = new_ip; //Update char_ip

View File

@ -15,7 +15,7 @@ struct auth_node{
void chrif_setuserid(char*); void chrif_setuserid(char*);
void chrif_setpasswd(char*); void chrif_setpasswd(char*);
void chrif_checkdefaultlogin(void); void chrif_checkdefaultlogin(void);
int chrif_setip(char*); int chrif_setip(const char*);
void chrif_setport(int); void chrif_setport(int);
int chrif_isconnect(void); int chrif_isconnect(void);

View File

@ -116,23 +116,23 @@ static void clif_hpmeter_single(int fd, struct map_session_data *sd);
int clif_setip(const char* ip) int clif_setip(const char* ip)
{ {
char ip_str[16]; char ip_str[16];
map_ip = resolve_hostbyname(ip,NULL,ip_str); map_ip = host2ip(ip);
if (!map_ip) { if (!map_ip) {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip); ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
return 0; return 0;
} }
strncpy(map_ip_str, ip, sizeof(map_ip_str)); strncpy(map_ip_str, ip, sizeof(map_ip_str));
ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str); ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
return 1; return 1;
} }
void clif_setbindip(const char* ip) void clif_setbindip(const char* ip)
{ {
unsigned char ip_str[4]; char ip_str[16];
bind_ip = resolve_hostbyname(ip,ip_str,NULL); bind_ip = host2ip(ip);
if (bind_ip) { 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]); ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
} else { } else {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip); ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
} }
@ -162,12 +162,12 @@ unsigned long clif_getip_long(void)
return (unsigned long)map_ip; return (unsigned long)map_ip;
} }
//Refreshes map_server ip, returns the new ip if the ip changed, otherwise it //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
//returns 0. unsigned long clif_refresh_ip(void)
unsigned long clif_refresh_ip(void) { {
in_addr_t new_ip; in_addr_t new_ip;
new_ip = resolve_hostbyname(map_ip_str, NULL, NULL); new_ip = host2ip(map_ip_str);
if (new_ip && new_ip != map_ip) { if (new_ip && new_ip != map_ip) {
map_ip = new_ip; map_ip = new_ip;
ShowInfo("Updating IP resolution of [%s].\n",map_ip_str); ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);

View File

@ -351,7 +351,7 @@ void do_init_irc(void)
return; return;
if (irc_ip_str[strlen(irc_ip_str)-1] == '\n') if (irc_ip_str[strlen(irc_ip_str)-1] == '\n')
irc_ip_str[strlen(irc_ip_str)-1] = '\0'; irc_ip_str[strlen(irc_ip_str)-1] = '\0';
irc_ip = resolve_hostbyname(irc_ip_str, NULL, irc_ip_str); irc_ip = host2ip(irc_ip_str);
if (!irc_ip) if (!irc_ip)
{ {
ShowError("Unable to resolve %s! Cannot connect to IRC server, disabling irc_bot.\n", irc_ip_str); ShowError("Unable to resolve %s! Cannot connect to IRC server, disabling irc_bot.\n", irc_ip_str);

View File

@ -3228,13 +3228,14 @@ void map_versionscreen(int flag) {
/*====================================================== /*======================================================
* Map-Server Init and Command-line Arguments [Valaris] * Map-Server Init and Command-line Arguments [Valaris]
*------------------------------------------------------ *------------------------------------------------------*/
*/
void set_server_type(void) void set_server_type(void)
{ {
SERVER_TYPE = ATHENA_SERVER_MAP; SERVER_TYPE = ATHENA_SERVER_MAP;
} }
int do_init(int argc, char *argv[]) {
int do_init(int argc, char *argv[])
{
int i; int i;
#ifdef GCOLLECT #ifdef GCOLLECT
@ -3284,24 +3285,22 @@ int do_init(int argc, char *argv[]) {
chrif_checkdefaultlogin(); chrif_checkdefaultlogin();
if (!map_ip_set || !char_ip_set) { if (!map_ip_set || !char_ip_set) {
// The map server should know what IP address it is running on char ip_str[16];
// - MouseJstr ip2str(addr_[0], ip_str);
int localaddr = ntohl(addr_[0]);
unsigned char *ptr = (unsigned char *) &localaddr; ShowError("\nNot all IP addresses in map_athena.conf configured, autodetecting...\n");
char buf[16];
if (naddr_ == 0) { if (naddr_ == 0)
ShowError("\nUnable to determine your IP address... please edit the map_athena.conf file and set it.\n"); ShowError("Unable to determine your IP address...\n");
ShowError("(127.0.0.1 is valid if you have no network interface)\n"); else if (naddr_ > 1)
} ShowNotice("Multiple interfaces detected...\n");
sprintf(buf, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);;
if (naddr_ != 1) ShowInfo("Defaulting to %s as our IP address\n", ip_str);
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) if (!map_ip_set)
clif_setip(buf); clif_setip(ip_str);
if (!char_ip_set) if (!char_ip_set)
chrif_setip(buf); chrif_setip(ip_str);
} }
if (SHOW_DEBUG_MSG) if (SHOW_DEBUG_MSG)
@ -3375,17 +3374,3 @@ int do_init(int argc, char *argv[]) {
return 0; return 0;
} }
int compare_item(struct item *a, struct item *b) {
if (a->nameid == b->nameid &&
a->identify == b->identify &&
a->refine == b->refine &&
a->attribute == b->attribute)
{
int i;
for (i = 0; i < MAX_SLOTS && (a->card[i] == b->card[i]); i++);
return (i == MAX_SLOTS);
}
return 0;
}

View File

@ -1349,7 +1349,6 @@ void map_foreachpc(int (*func)(DBKey,void*,va_list),...);
int map_foreachiddb(int (*)(DBKey,void*,va_list),...); int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
void map_addnickdb(struct map_session_data *); void map_addnickdb(struct map_session_data *);
struct map_session_data * map_nick2sd(const char*); struct map_session_data * map_nick2sd(const char*);
int compare_item(struct item *a, struct item *b);
char *map_normalize_name(char *mapname); char *map_normalize_name(char *mapname);
// その他 // その他

View File

@ -41,13 +41,13 @@ int storage_comp_item(const void *_i1, const void *_i2)
return i1->nameid - i2->nameid; return i1->nameid - i2->nameid;
} }
void sortage_sortitem (struct storage *stor) void storage_sortitem (struct storage *stor)
{ {
nullpo_retv(stor); nullpo_retv(stor);
qsort(stor->storage_, MAX_STORAGE, sizeof(struct item), storage_comp_item); qsort(stor->storage_, MAX_STORAGE, sizeof(struct item), storage_comp_item);
} }
void sortage_gsortitem (struct guild_storage* gstor) void storage_gsortitem (struct guild_storage* gstor)
{ {
nullpo_retv(gstor); nullpo_retv(gstor);
qsort(gstor->storage_, MAX_GUILD_STORAGE, sizeof(struct item), storage_comp_item); qsort(gstor->storage_, MAX_GUILD_STORAGE, sizeof(struct item), storage_comp_item);
@ -158,6 +158,21 @@ int storage_storageopen(struct map_session_data *sd)
return 0; return 0;
} }
// helper function
int compare_item(struct item *a, struct item *b) {
if (a->nameid == b->nameid &&
a->identify == b->identify &&
a->refine == b->refine &&
a->attribute == b->attribute)
{
int i;
for (i = 0; i < MAX_SLOTS && (a->card[i] == b->card[i]); i++);
return (i == MAX_SLOTS);
}
return 0;
}
/*========================================== /*==========================================
* Internal add-item function. * Internal add-item function.
*------------------------------------------ *------------------------------------------
@ -452,7 +467,7 @@ int storage_storage_saved(int account_id)
if (stor->dirty && stor->storage_status == 0) if (stor->dirty && stor->storage_status == 0)
{ //Only mark it clean if it's not in use. [Skotlex] { //Only mark it clean if it's not in use. [Skotlex]
stor->dirty = 0; stor->dirty = 0;
sortage_sortitem(stor); storage_sortitem(stor);
return 1; return 1;
} }
return 0; return 0;
@ -716,7 +731,7 @@ int storage_guild_storagesaved(int guild_id)
if (stor->dirty && stor->storage_status == 0) if (stor->dirty && stor->storage_status == 0)
{ //Storage has been correctly saved. { //Storage has been correctly saved.
stor->dirty = 0; stor->dirty = 0;
sortage_gsortitem(stor); storage_gsortitem(stor);
} }
return 1; return 1;
} }