Fixed mishandling of public/private IP addresses
This commit is contained in:
parent
0f259307df
commit
db4542dd7a
6
.idea/encodings.xml
Normal file
6
.idea/encodings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
@ -735,10 +735,11 @@ typedef struct SEmpireSelectPacket
|
||||
|
||||
typedef struct SPacketGDSetup
|
||||
{
|
||||
char szPublicIP[16]; // Public IP which listen to users
|
||||
BYTE bChannel; // 채널
|
||||
WORD wListenPort; // 클라이언트가 접속하는 포트 번호
|
||||
WORD wP2PPort; // 서버끼리 연결 시키는 P2P 포트 번호
|
||||
BYTE bChannel;
|
||||
char szPublicIP[16]; // Public IP which clients connect to
|
||||
WORD wListenPort; // Port number which clients connect to
|
||||
char szInternalIP[16]; // Internal IP which other servers connect to
|
||||
WORD wP2PPort; // Port number which other servers connect to
|
||||
LONG alMaps[MAP_ALLOW_MAX_LEN];
|
||||
DWORD dwLoginCount;
|
||||
BYTE bAuthServer;
|
||||
|
@ -1145,9 +1145,10 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
|
||||
return;
|
||||
}
|
||||
|
||||
peer->SetChannel(p->bChannel);
|
||||
peer->SetPublicIP(p->szPublicIP);
|
||||
peer->SetChannel(p->bChannel);
|
||||
peer->SetListenPort(p->wListenPort);
|
||||
peer->SetInternalIP(p->szInternalIP);
|
||||
peer->SetP2PPort(p->wP2PPort);
|
||||
peer->SetMaps(p->alMaps);
|
||||
|
||||
@ -1264,9 +1265,9 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
|
||||
SPDLOG_DEBUG("SETUP: channel {} listen {} p2p {} count {}", peer->GetChannel(), p->wListenPort, p->wP2PPort, bMapCount);
|
||||
|
||||
TPacketDGP2P p2pSetupPacket;
|
||||
p2pSetupPacket.wPort = peer->GetP2PPort();
|
||||
p2pSetupPacket.bChannel = peer->GetChannel();
|
||||
strlcpy(p2pSetupPacket.szHost, peer->GetPublicIP(), sizeof(p2pSetupPacket.szHost));
|
||||
strlcpy(p2pSetupPacket.szHost, peer->GetInternalIP(), sizeof(p2pSetupPacket.szHost));
|
||||
p2pSetupPacket.wPort = peer->GetP2PPort();
|
||||
|
||||
for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end();++i)
|
||||
{
|
||||
|
@ -38,15 +38,18 @@ class CPeer : public CPeerBase
|
||||
DWORD GetUserCount();
|
||||
void SetUserCount(DWORD dwCount);
|
||||
|
||||
void SetPublicIP(const char * ip) { m_stPublicIP = ip; }
|
||||
const char * GetPublicIP() { return m_stPublicIP.c_str(); }
|
||||
|
||||
void SetChannel(BYTE bChannel) { m_bChannel = bChannel; }
|
||||
BYTE GetChannel() { return m_bChannel; }
|
||||
|
||||
void SetPublicIP(const char * ip) { m_stPublicIP = ip; }
|
||||
const char * GetPublicIP() { return m_stPublicIP.c_str(); }
|
||||
|
||||
void SetListenPort(WORD wPort) { m_wListenPort = wPort; }
|
||||
WORD GetListenPort() { return m_wListenPort; }
|
||||
|
||||
void SetInternalIP(const char * ip) { m_stInternalIP = ip; }
|
||||
const char * GetInternalIP() { return m_stInternalIP.c_str(); }
|
||||
|
||||
void SetP2PPort(WORD wPort);
|
||||
WORD GetP2PPort() { return m_wP2PPort; }
|
||||
|
||||
@ -72,6 +75,7 @@ class CPeer : public CPeerBase
|
||||
TItemIDRangeTable m_itemSpareRange;
|
||||
|
||||
std::string m_stPublicIP;
|
||||
std::string m_stInternalIP;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -21,12 +21,12 @@
|
||||
using std::string;
|
||||
|
||||
// Networking
|
||||
char g_szPublicBindIP[16] = "0.0.0.0";
|
||||
char g_szPublicIP[16] = "0";
|
||||
string g_szPublicBindIP = "0.0.0.0";
|
||||
string g_szPublicIP;
|
||||
WORD mother_port = 50080;
|
||||
|
||||
char g_szInternalBindIP[16] = "0.0.0.0";
|
||||
char g_szInternalIP[16] = "0";
|
||||
string g_szInternalBindIP = "0.0.0.0";
|
||||
string g_szInternalIP;
|
||||
WORD p2p_port = 50900;
|
||||
|
||||
char db_addr[ADDRESS_MAX_LEN + 1];
|
||||
@ -263,16 +263,16 @@ bool GetIPInfo()
|
||||
sai->sin_addr.s_addr == 16777343) // ignore if address is 127.0.0.1
|
||||
continue;
|
||||
|
||||
if (IsPrivateIP(sai->sin_addr) && g_szInternalIP[0] == '0')
|
||||
if (IsPrivateIP(sai->sin_addr) && g_szInternalIP.empty())
|
||||
{
|
||||
char * ip = inet_ntoa(sai->sin_addr);
|
||||
strlcpy(g_szInternalIP, ip, sizeof(g_szInternalIP));
|
||||
g_szInternalIP = string(ip);
|
||||
SPDLOG_WARN("Internal IP automatically configured: {} interface {}", ip, ifap->ifa_name);
|
||||
}
|
||||
else if (g_szPublicIP[0] == '0')
|
||||
else if (g_szPublicIP.empty())
|
||||
{
|
||||
char * ip = inet_ntoa(sai->sin_addr);
|
||||
strlcpy(g_szPublicIP, ip, sizeof(g_szPublicIP));
|
||||
g_szPublicIP = string(ip);
|
||||
SPDLOG_WARN("Public IP automatically configured: {} interface {}", ip, ifap->ifa_name);
|
||||
}
|
||||
}
|
||||
@ -355,6 +355,10 @@ void config_init(const string& st_localeServiceName)
|
||||
{
|
||||
parse_token(buf, token_string, value_string);
|
||||
|
||||
// If the configuration string is empty, ignore this line
|
||||
if (strcmp(value_string, "") == 0)
|
||||
continue;
|
||||
|
||||
TOKEN("BLOCK_LOGIN")
|
||||
{
|
||||
g_stBlockDate = value_string;
|
||||
@ -662,6 +666,10 @@ void config_init(const string& st_localeServiceName)
|
||||
{
|
||||
parse_token(buf, token_string, value_string);
|
||||
|
||||
// If the configuration string is empty, ignore this line
|
||||
if (strcmp(value_string, "") == 0)
|
||||
continue;
|
||||
|
||||
TOKEN("empire_whisper")
|
||||
{
|
||||
bool b_value = 0;
|
||||
@ -699,13 +707,14 @@ void config_init(const string& st_localeServiceName)
|
||||
|
||||
TOKEN("public_ip")
|
||||
{
|
||||
strlcpy(g_szPublicIP, value_string, sizeof(g_szPublicIP));
|
||||
g_szPublicIP = string(value_string);
|
||||
SPDLOG_INFO("Setting public IP address to '{}'...", g_szPublicIP);
|
||||
continue;
|
||||
}
|
||||
|
||||
TOKEN("public_bind_ip")
|
||||
{
|
||||
strlcpy(g_szPublicBindIP, value_string, sizeof(g_szPublicBindIP));
|
||||
g_szPublicBindIP = string(value_string);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -717,13 +726,14 @@ void config_init(const string& st_localeServiceName)
|
||||
|
||||
TOKEN("internal_ip")
|
||||
{
|
||||
strlcpy(g_szInternalIP, value_string, sizeof(g_szInternalIP));
|
||||
g_szInternalIP = string(value_string);
|
||||
SPDLOG_INFO("Setting internal IP address to '{}'...", g_szInternalIP);
|
||||
continue;
|
||||
}
|
||||
|
||||
TOKEN("internal_bind_ip")
|
||||
{
|
||||
strlcpy(g_szInternalBindIP, value_string, sizeof(g_szInternalBindIP));
|
||||
g_szInternalBindIP = string(value_string);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,12 @@ enum
|
||||
|
||||
void config_init(const std::string& st_localeServiceName); // default "" is CONFIG
|
||||
|
||||
extern char g_szPublicBindIP[16];
|
||||
extern char g_szPublicIP[16];
|
||||
extern std::string g_szPublicBindIP;
|
||||
extern std::string g_szPublicIP;
|
||||
extern WORD mother_port;
|
||||
|
||||
extern char g_szInternalBindIP[16];
|
||||
extern char g_szInternalIP[16];
|
||||
extern std::string g_szInternalBindIP;
|
||||
extern std::string g_szInternalIP;
|
||||
extern WORD p2p_port;
|
||||
|
||||
extern char db_addr[ADDRESS_MAX_LEN + 1];
|
||||
|
@ -158,7 +158,7 @@ void CLIENT_DESC::SetPhase(int iPhase)
|
||||
TPacketGDBoot p;
|
||||
p.dwItemIDRange[0] = 0;
|
||||
p.dwItemIDRange[1] = 0;
|
||||
memcpy(p.szIP, g_szPublicIP, 16);
|
||||
memcpy(p.szIP, g_szPublicIP.c_str(), 16);
|
||||
DBPacket(HEADER_GD_BOOT, 0, &p, sizeof(p));
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,8 @@ void CLIENT_DESC::SetPhase(int iPhase)
|
||||
TPacketGDSetup p;
|
||||
|
||||
memset(&p, 0, sizeof(p));
|
||||
strlcpy(p.szPublicIP, g_szPublicIP, sizeof(p.szPublicIP));
|
||||
strlcpy(p.szPublicIP, g_szPublicIP.c_str(), sizeof(p.szPublicIP));
|
||||
strlcpy(p.szInternalIP, g_szInternalIP.c_str(), sizeof(p.szInternalIP));
|
||||
|
||||
if (!g_bAuthServer)
|
||||
{
|
||||
|
@ -1304,13 +1304,13 @@ void CInputDB::P2P(const char * c_pData)
|
||||
extern event_base* ev_base;
|
||||
extern evdns_base* dns_base;
|
||||
|
||||
TPacketDGP2P * p = (TPacketDGP2P *) c_pData;
|
||||
auto * p = (TPacketDGP2P *) c_pData;
|
||||
|
||||
P2P_MANAGER& mgr = P2P_MANAGER::instance();
|
||||
|
||||
if (false == DESC_MANAGER::instance().IsP2PDescExist(p->szHost, p->wPort))
|
||||
if (!DESC_MANAGER::instance().IsP2PDescExist(p->szHost, p->wPort))
|
||||
{
|
||||
LPCLIENT_DESC pkDesc = NULL;
|
||||
LPCLIENT_DESC pkDesc = nullptr;
|
||||
SPDLOG_DEBUG("InputDB:P2P {}:{}", p->szHost, p->wPort);
|
||||
pkDesc = DESC_MANAGER::instance().CreateConnectionDesc(ev_base, dns_base, p->szHost, p->wPort, PHASE_P2P, false);
|
||||
mgr.RegisterConnector(pkDesc);
|
||||
|
@ -513,9 +513,9 @@ int start(int argc, char **argv)
|
||||
switch (ch)
|
||||
{
|
||||
case 'I': // IP
|
||||
strlcpy(g_szPublicIP, optarg, sizeof(g_szPublicIP));
|
||||
g_szPublicIP = std::string(optarg);
|
||||
|
||||
printf("IP %s\n", g_szPublicIP);
|
||||
printf("IP %s\n", g_szPublicIP.c_str());
|
||||
|
||||
break;
|
||||
|
||||
@ -596,11 +596,11 @@ int start(int argc, char **argv)
|
||||
// Initialize the network stack
|
||||
|
||||
// Check if the public and internal IP addresses were configured
|
||||
if (g_szInternalIP[0] == '0') {
|
||||
SPDLOG_CRITICAL("Public IP address could not be automatically detected. Manually set the IP and try again.");
|
||||
if (g_szInternalIP.empty()) {
|
||||
SPDLOG_CRITICAL("Internal IP address could not be automatically detected. Manually set the IP and try again.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (g_szPublicIP[0] == '0') {
|
||||
if (g_szPublicIP.empty()) {
|
||||
SPDLOG_CRITICAL("Public IP address could not be automatically detected. Manually set the IP and try again.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -622,7 +622,7 @@ int start(int argc, char **argv)
|
||||
|
||||
// Main TCP listener
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = inet_addr(g_szPublicBindIP);
|
||||
sin.sin_addr.s_addr = inet_addr(g_szPublicBindIP.c_str());
|
||||
sin.sin_port = htons(mother_port);
|
||||
|
||||
tcp_listener = evconnlistener_new_bind(
|
||||
@ -640,7 +640,7 @@ int start(int argc, char **argv)
|
||||
|
||||
// Game P2P listener
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = inet_addr(g_szInternalBindIP);
|
||||
sin.sin_addr.s_addr = inet_addr(g_szInternalBindIP.c_str());
|
||||
sin.sin_port = htons(p2p_port);
|
||||
|
||||
p2p_listener = evconnlistener_new_bind(
|
||||
|
Loading…
Reference in New Issue
Block a user