summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c16
-rw-r--r--src/char_sql/char.c22
-rw-r--r--src/common/db.c4
-rw-r--r--src/common/socket.c94
-rw-r--r--src/common/socket.h11
-rw-r--r--src/common/utils.h3
-rw-r--r--src/login/login.c6
-rw-r--r--src/login_sql/login.c6
-rw-r--r--src/map/chrif.c12
-rw-r--r--src/map/chrif.h2
-rw-r--r--src/map/clif.c18
-rw-r--r--src/map/irc.c2
-rw-r--r--src/map/map.c51
-rw-r--r--src/map/map.h1
-rw-r--r--src/map/storage.c23
15 files changed, 129 insertions, 142 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 68d67f56c..a09ca72dd 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2478,11 +2478,11 @@ int parse_tologin(int fd) {
WBUFW(buf,0) = 0x2b1e;
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)
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)
{ //Update ip.
WFIFOHEAD(fd,6);
@@ -4113,26 +4113,26 @@ int char_config_read(const char *cfgName) {
}
} else if (strcmpi(w1, "login_ip") == 0) {
char ip_str[16];
- login_ip = resolve_hostbyname(w2, NULL, ip_str);
+ login_ip = host2ip(w2);
if (login_ip) {
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) {
login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
char ip_str[16];
- char_ip = resolve_hostbyname(w2, NULL, ip_str);
+ char_ip = host2ip(w2);
if (char_ip){
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) {
char ip_str[16];
- bind_ip = resolve_hostbyname(w2, NULL, ip_str);
+ bind_ip = host2ip(w2);
if (bind_ip) {
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) {
char_port = atoi(w2);
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 4e325700e..5cc0191e5 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -2245,11 +2245,11 @@ int parse_tologin(int fd) {
WBUFW(buf,0) = 0x2b1e;
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.
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)
{ //Update 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';
}
} else if (strcmpi(w1, "login_ip") == 0) {
- unsigned char ip_str[16];
- login_ip = resolve_hostbyname(w2, NULL, ip_str);
+ char ip_str[16];
+ login_ip = host2ip(w2);
if (login_ip) {
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) {
login_port=atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- unsigned char ip_str[16];
- char_ip = resolve_hostbyname(w2, NULL, ip_str);
+ char ip_str[16];
+ char_ip = host2ip(w2);
if (char_ip){
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) {
- unsigned char ip_str[16];
- bind_ip = resolve_hostbyname(w2, NULL, ip_str);
+ char ip_str[16];
+ bind_ip = host2ip(w2);
if (bind_ip) {
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) {
char_port = atoi(w2);
diff --git a/src/common/db.c b/src/common/db.c
index 87b6e7c4f..f25afb5c3 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -75,6 +75,10 @@
#include "../common/showmsg.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 *
* the database system. *
diff --git a/src/common/socket.c b/src/common/socket.c
index 4e001c512..f7b5ebc2f 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -846,8 +846,7 @@ int access_ipmask(const char* str, AccessControl* acc)
}
}
if( access_debug ){
- ShowMessage("access_ipmask: Loaded IP:%d.%d.%d.%d mask:%d.%d.%d.%d\n",
- CONVIP(ip), CONVIP(mask));
+ ShowMessage("access_ipmask: Loaded IP:%d.%d.%d.%d mask:%d.%d.%d.%d\n", CONVIP(ip), CONVIP(mask));
}
acc->ip = ip;
acc->mask = mask;
@@ -857,69 +856,62 @@ int access_ipmask(const char* str, AccessControl* acc)
#endif
//////////////////////////////
-int socket_config_read(const char *cfgName) {
- int i;
+int socket_config_read(const char *cfgName)
+{
char line[1024],w1[1024],w2[1024];
FILE *fp;
- fp=fopen(cfgName, "r");
- if(fp==NULL){
+ fp = fopen(cfgName, "r");
+ if(fp == NULL) {
ShowError("File not found: %s\n", cfgName);
return 1;
}
- while(fgets(line,1020,fp)){
+
+ while(fgets(line,1020,fp))
+ {
if(line[0] == '/' && line[1] == '/')
continue;
- i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
- if(i!=2)
+ if(sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
continue;
- if(strcmpi(w1,"stall_time")==0){
+
+ if (!strcmpi(w1, "stall_time"))
stall_time = atoi(w2);
#ifndef MINICORE
- } else if( strcmpi(w1,"enable_ip_rules") == 0 ){
- if( strcmpi(w2,"yes") == 0 )
- ip_rules = 1;
- else if( strcmpi(w2,"no") == 0 )
- ip_rules = 0;
- else
- ip_rules = atoi(w2);
- } else if( strcmpi(w1,"order") == 0 ){
- access_order = atoi(w2);
- if( strcmpi(w2,"deny,allow") == 0 )
+ else if (!strcmpi(w1, "enable_ip_rules")) {
+ ip_rules = config_switch(w2);
+ } else if (!strcmpi(w1, "order")) {
+ if (!strcmpi(w2, "deny,allow"))
access_order = ACO_DENY_ALLOW;
- else if( strcmpi(w2,"allow,deny") == 0 )
- access_order=ACO_ALLOW_DENY;
- else if( strcmpi(w2,"mutual-failure") == 0 )
- access_order=ACO_MUTUAL_FAILURE;
- } else if( strcmpi(w1,"allow") == 0 ){
+ else if (!strcmpi(w2, "allow,deny"))
+ access_order = ACO_ALLOW_DENY;
+ else if (!strcmpi(w2, "mutual-failure"))
+ access_order = ACO_MUTUAL_FAILURE;
+ } else if (!strcmpi(w1, "allow")) {
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;
else
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);
- if( access_ipmask(w2,&access_deny[access_denynum]) )
+ if (access_ipmask(w2, &access_deny[access_denynum]))
++access_denynum;
else
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);
- } else if( strcmpi(w1,"ddos_count") == 0){
+ else if (!strcmpi(w1,"ddos_count"))
ddos_count = atoi(w2);
- } else if( strcmpi(w1,"ddos_autoreset") == 0){
+ else if (!strcmpi(w1,"ddos_autoreset"))
ddos_autoreset = atoi(w2);
- } else if( strcmpi(w1,"debug") == 0){
- if( strcmpi(w2,"yes") == 0 )
- access_debug = 1;
- else if( strcmpi(w2,"no") == 0 )
- access_debug = 0;
- else
- access_debug = atoi(w2);
+ else if (!strcmpi(w1,"debug"))
+ access_debug = config_switch(w2);
#endif
- } else if (strcmpi(w1, "import") == 0)
+ else if (!strcmpi(w1, "import"))
socket_config_read(w2);
}
+
fclose(fp);
return 0;
}
@@ -1107,18 +1099,16 @@ int session_isActive(int fd)
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);
+ return (h != NULL) ? *(in_addr_t*)h->h_addr : 0;
+}
+
+const char* ip2str(in_addr_t ip, char ip_str[16])
{
- struct hostent *h = gethostbyname(hostname);
- char ip_buf[16];
- unsigned 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);
+ in_addr_t addr = ntohl(ip);
+ sprintf(ip_str, "%d.%d.%d.%d", (addr>>24)&0xFF, (addr>>16)&0xFF, (addr>>8)&0xFF, (addr>>0)&0xFF);
+ return ip_str;
}
diff --git a/src/common/socket.h b/src/common/socket.h
index c56fb8387..b7b8ce839 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -125,13 +125,10 @@ extern void set_nonblocking(int fd, int yes);
void set_defaultparse(ParseFunc defaultparse);
-//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.
-//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);
+// hostname/ip conversion functions
+in_addr_t host2ip(const char* hostname);
+const char* ip2str(in_addr_t ip, char ip_str[16]);
+
int socket_getips(uint32* ips, int max);
diff --git a/src/common/utils.h b/src/common/utils.h
index 3e74374bc..496cbdde3 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -10,9 +10,6 @@
#define NULL (void *)0
#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);
struct StringBuf {
diff --git a/src/login/login.c b/src/login/login.c
index b6b2c6402..95a55f5fe 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -3636,10 +3636,10 @@ 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) {
- char login_ip_str[128];
- login_ip = resolve_hostbyname(w2, NULL, login_ip_str);
+ char ip_str[16];
+ login_ip = host2ip(w2);
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) {
login_port = atoi(w2);
} else if (strcmpi(w1, "account_filename") == 0) {
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index 0c4b77b61..24feeff8a 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -1899,10 +1899,10 @@ int login_config_read(const char* cfgName)
msg_silent = atoi(w2);
}
else if (!strcmpi(w1, "bind_ip")) {
- char login_ip_str[128];
- login_config.login_ip = resolve_hostbyname(w2, NULL, login_ip_str);
+ char ip_str[16];
+ login_config.login_ip = host2ip(w2);
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")) {
login_config.login_port = (unsigned short)atoi(w2);
ShowStatus("set login_port : %s\n",w2);
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 403cfdcb1..d432320d3 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -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 = resolve_hostbyname(ip,NULL,ip_str);
-
+ char_ip = host2ip(ip);
if (!char_ip) {
ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
return 0;
}
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;
}
@@ -1418,10 +1417,11 @@ int chrif_disconnect(int fd) {
return 0;
}
-void chrif_update_ip(int fd){
+void chrif_update_ip(int fd)
+{
unsigned long new_ip;
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)
char_ip = new_ip; //Update char_ip
diff --git a/src/map/chrif.h b/src/map/chrif.h
index a80543d1a..92a719929 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);
-int chrif_setip(char*);
+int chrif_setip(const char*);
void chrif_setport(int);
int chrif_isconnect(void);
diff --git a/src/map/clif.c b/src/map/clif.c
index a9214a137..4844f0ac5 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -116,23 +116,23 @@ static void clif_hpmeter_single(int fd, struct map_session_data *sd);
int clif_setip(const char* ip)
{
char ip_str[16];
- map_ip = resolve_hostbyname(ip,NULL,ip_str);
+ map_ip = host2ip(ip);
if (!map_ip) {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
return 0;
}
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;
}
void clif_setbindip(const char* ip)
{
- unsigned char ip_str[4];
- bind_ip = resolve_hostbyname(ip,ip_str,NULL);
+ char ip_str[16];
+ bind_ip = host2ip(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 {
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;
}
-//Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
-//returns 0.
-unsigned long clif_refresh_ip(void) {
+//Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
+unsigned long clif_refresh_ip(void)
+{
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) {
map_ip = new_ip;
ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
diff --git a/src/map/irc.c b/src/map/irc.c
index 8760efc11..c5e707dd9 100644
--- a/src/map/irc.c
+++ b/src/map/irc.c
@@ -351,7 +351,7 @@ void do_init_irc(void)
return;
if (irc_ip_str[strlen(irc_ip_str)-1] == '\n')
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)
{
ShowError("Unable to resolve %s! Cannot connect to IRC server, disabling irc_bot.\n", irc_ip_str);
diff --git a/src/map/map.c b/src/map/map.c
index 9cf047d56..a28ac20c5 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -3228,13 +3228,14 @@ void map_versionscreen(int flag) {
/*======================================================
* Map-Server Init and Command-line Arguments [Valaris]
- *------------------------------------------------------
- */
+ *------------------------------------------------------*/
void set_server_type(void)
{
SERVER_TYPE = ATHENA_SERVER_MAP;
}
-int do_init(int argc, char *argv[]) {
+
+int do_init(int argc, char *argv[])
+{
int i;
#ifdef GCOLLECT
@@ -3284,24 +3285,22 @@ int do_init(int argc, char *argv[]) {
chrif_checkdefaultlogin();
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);
+ char ip_str[16];
+ ip2str(addr_[0], ip_str);
+
+ ShowError("\nNot all IP addresses in map_athena.conf configured, autodetecting...\n");
+
+ if (naddr_ == 0)
+ ShowError("Unable to determine your IP address...\n");
+ else if (naddr_ > 1)
+ ShowNotice("Multiple interfaces detected...\n");
+
+ ShowInfo("Defaulting to %s as our IP address\n", ip_str);
+
if (!map_ip_set)
- clif_setip(buf);
+ clif_setip(ip_str);
if (!char_ip_set)
- chrif_setip(buf);
+ chrif_setip(ip_str);
}
if (SHOW_DEBUG_MSG)
@@ -3375,17 +3374,3 @@ int do_init(int argc, char *argv[]) {
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;
-}
diff --git a/src/map/map.h b/src/map/map.h
index a6f0cf614..244bc18b3 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -1349,7 +1349,6 @@ void map_foreachpc(int (*func)(DBKey,void*,va_list),...);
int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
void map_addnickdb(struct map_session_data *);
struct map_session_data * map_nick2sd(const char*);
-int compare_item(struct item *a, struct item *b);
char *map_normalize_name(char *mapname);
// ‚»‚Ì‘¼
diff --git a/src/map/storage.c b/src/map/storage.c
index 4d652903b..12d5b5696 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -41,13 +41,13 @@ int storage_comp_item(const void *_i1, const void *_i2)
return i1->nameid - i2->nameid;
}
-void sortage_sortitem (struct storage *stor)
+void storage_sortitem (struct storage *stor)
{
nullpo_retv(stor);
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);
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;
}
+// 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.
*------------------------------------------
@@ -452,7 +467,7 @@ int storage_storage_saved(int account_id)
if (stor->dirty && stor->storage_status == 0)
{ //Only mark it clean if it's not in use. [Skotlex]
stor->dirty = 0;
- sortage_sortitem(stor);
+ storage_sortitem(stor);
return 1;
}
return 0;
@@ -716,7 +731,7 @@ int storage_guild_storagesaved(int guild_id)
if (stor->dirty && stor->storage_status == 0)
{ //Storage has been correctly saved.
stor->dirty = 0;
- sortage_gsortitem(stor);
+ storage_gsortitem(stor);
}
return 1;
}