summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c4
-rw-r--r--src/char_sql/char.c4
-rw-r--r--src/common/cbasetypes.h2
-rw-r--r--src/common/socket.c7
-rw-r--r--src/common/socket.h1
-rw-r--r--src/login/login.c4
-rw-r--r--src/login_sql/login.c4
-rw-r--r--src/map/clif.c24
-rw-r--r--src/map/clif.h4
9 files changed, 31 insertions, 23 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 5b9b5d87b..66601f644 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -3499,8 +3499,8 @@ int parse_char(int fd)
// Advanced subnet check [LuzZza]
subnet_map_ip = lan_subnetcheck(ipl);
- WFIFOL(fd,22) = (subnet_map_ip) ? htonl(subnet_map_ip) : htonl(server[i].ip);
- WFIFOW(fd,26) = server[i].port; // /!\ must be sent in intel host byte order /!\ (client bug)
+ WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip);
+ WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
WFIFOSET(fd,28);
ShowInfo("Character selection '%s' (account: %d, slot: %d).\n",
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index d9fcea839..dcec47c42 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -3349,8 +3349,8 @@ int parse_char(int fd)
// Advanced subnet check [LuzZza]
subnet_map_ip = lan_subnetcheck(ipl);
- WFIFOL(fd,22) = (subnet_map_ip) ? htonl(subnet_map_ip) : htonl(server[i].ip);
- WFIFOW(fd,26) = server[i].port; // /!\ must be sent in intel host byte order /!\ (client bug)
+ WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip);
+ WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
WFIFOSET(fd,28);
}
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index c066c1ebd..ae6430a62 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -291,7 +291,7 @@ typedef char bool;
//////////////////////////////////////////////////////////////////////////
// Has to be unsigned to avoid problems in some systems
-// Problems arise when these functions expect an argument in the range [0,256[ and are feed a signed char.
+// Problems arise when these functions expect an argument in the range [0,256[ and are fed a signed char.
#include <ctype.h>
#define ISALNUM(c) (isalnum((unsigned char)(c)))
#define ISALPHA(c) (isalpha((unsigned char)(c)))
diff --git a/src/common/socket.c b/src/common/socket.c
index f8bdcdc7a..f406a0eea 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1117,3 +1117,10 @@ uint32 str2ip(const char* ip_str)
{
return ntohl(inet_addr(ip_str));
}
+
+// Reorders bytes from network to little endian (Windows).
+// Neccessary for sending port numbers to the RO client until Gravity notices that they forgot ntohs() calls.
+uint16 ntows(uint16 neshort)
+{
+ return ((neshort & 0xFF) << 8) | ((neshort & 0xFF00) >> 8);
+}
diff --git a/src/common/socket.h b/src/common/socket.h
index 41acbeabd..801da8807 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -130,6 +130,7 @@ uint32 host2ip(const char* hostname);
const char* ip2str(uint32 ip, char ip_str[16]);
uint32 str2ip(const char* ip_str);
#define CONVIP(ip) (ip>>24)&0xFF,(ip>>16)&0xFF,(ip>>8)&0xFF,(ip>>0)&0xFF
+uint16 ntows(uint16 netshort);
int socket_getips(uint32* ips, int max);
diff --git a/src/login/login.c b/src/login/login.c
index e948264b2..e18396b23 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -3079,8 +3079,8 @@ int parse_login(int fd)
if (server_fd[i] >= 0) {
// Advanced subnet check [LuzZza]
uint32 subnet_char_ip = lan_subnetcheck(ipl);
- WFIFOL(fd,47+server_num*32) = (subnet_char_ip) ? htonl(subnet_char_ip) : htonl(server[i].ip);
- WFIFOW(fd,47+server_num*32+4) = server[i].port; // /!\ must be sent in intel host byte order /!\ (client bug)
+ WFIFOL(fd,47+server_num*32) = htonl((subnet_char_ip) ? subnet_char_ip : server[i].ip);
+ WFIFOW(fd,47+server_num*32+4) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
WFIFOW(fd,47+server_num*32+26) = server[i].users;
WFIFOW(fd,47+server_num*32+28) = server[i].maintenance;
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index af0621d80..74e32f740 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -1426,8 +1426,8 @@ int parse_login(int fd)
if (server_fd[i] >= 0) {
// Advanced subnet check [LuzZza]
uint32 subnet_char_ip = lan_subnetcheck(ipl);
- WFIFOL(fd,47+server_num*32) = (subnet_char_ip) ? htonl(subnet_char_ip) : htonl(server[i].ip);
- WFIFOW(fd,47+server_num*32+4) = server[i].port; // /!\ must be sent in intel host byte order /!\ (client bug)
+ WFIFOL(fd,47+server_num*32) = htonl((subnet_char_ip) ? subnet_char_ip : server[i].ip);
+ WFIFOW(fd,47+server_num*32+4) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
WFIFOW(fd,47+server_num*32+26) = server[i].users;
WFIFOW(fd,47+server_num*32+28) = server[i].maintenance;
diff --git a/src/map/clif.c b/src/map/clif.c
index 62ea6169c..4e4a701c5 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -50,7 +50,7 @@ struct Clif_Config {
int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
} clif_config;
-struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
+struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
//Converts item type in case of pet eggs.
#define itemtype(a) (a == 7)?4:a
@@ -1684,7 +1684,7 @@ int clif_changemapserver(struct map_session_data* sd, const char* mapname, int x
WFIFOW(fd,18) = x;
WFIFOW(fd,20) = y;
WFIFOL(fd,22) = htonl(ip);
- WFIFOW(fd,26) = port; // /!\ must be sent in intel host byte order /!\ (client bug)
+ WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
WFIFOSET(fd, packet_len(0x92));
return 0;
@@ -11903,7 +11903,7 @@ int clif_parse(int fd)
}
// ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
- if (cmd >= MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
+ if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
session[fd]->eof = 1;
return 0;
@@ -12259,10 +12259,13 @@ static int packetdb_readdb(void)
clif_config.packet_db_ver = MAX_PACKET_VER;
packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
- while(fgets(line,1020,fp)){
+ while( fgets(line,sizeof(line),fp) )
+ {
+ ln++;
if(line[0]=='/' && line[1]=='/')
continue;
- if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
+ if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
+ {
if(strcmpi(w1,"packet_ver")==0) {
int prev_ver = packet_ver;
skip_ver = 0;
@@ -12319,7 +12322,8 @@ static int packetdb_readdb(void)
continue; // Skipping current packet version
memset(str,0,sizeof(str));
- for(j=0,p=line;j<4 && p;j++){
+ for(j=0,p=line;j<4 && p; ++j)
+ {
str[j]=p;
p=strchr(p,',');
if(p) *p++=0;
@@ -12329,7 +12333,7 @@ static int packetdb_readdb(void)
cmd=strtol(str[0],(char **)NULL,0);
if(max_cmd < cmd)
max_cmd = cmd;
- if(cmd<=0 || cmd>=MAX_PACKET_DB)
+ if(cmd <= 0 || cmd > MAX_PACKET_DB)
continue;
if(str[1]==NULL){
ShowError("packet_db: packet len error\n");
@@ -12349,7 +12353,7 @@ static int packetdb_readdb(void)
{
if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
{ //If we are updating a function, we need to zero up the previous one. [Skotlex]
- for(i=0;i<MAX_PACKET_DB;i++){
+ for(i=0;i<=MAX_PACKET_DB;i++){
if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
{
memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
@@ -12377,10 +12381,6 @@ static int packetdb_readdb(void)
// if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
packet_db[packet_ver][cmd].pos[j] = k;
}
-
- ln++;
-// if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
-// printf("packet_db ver %d: %d 0x%x %d %s %p\n",packet_ver,ln,cmd,packet_db[packet_ver][cmd].len,str[2],packet_db[packet_ver][cmd].func);
}
fclose(fp);
if(max_cmd > MAX_PACKET_DB)
diff --git a/src/map/clif.h b/src/map/clif.h
index 947f63a9d..13506be11 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -8,7 +8,7 @@
// packet DB
#define MAX_PACKET_DB 0x300
-#define MAX_PACKET_VER 25
+#define MAX_PACKET_VER 21
struct packet_db {
short len;
@@ -48,7 +48,7 @@ enum {
// packet_db[SERVER] is reserved for server use
#define SERVER 0
#define packet_len(x) packet_db[SERVER][x].len
-extern struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
+extern struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
int clif_setip(const char* ip);
void clif_setbindip(const char* ip);