Jump to content

Select character on 40k for Local Server and VPS


Karbust

Recommended Posts

  • Management

Sup bois and grils

I still see a lot of people not being able to select the character when using a local server for friends or VPS behind a internal router or firewall.

Disclaimer: This code (apart from the changes to support DNS names) wasn't made by me, it was originally posted on the metin2dev's French brother Funky-Emu by @Veltor88.

 

On service.h add this:

#define ENABLE_PROXY_IP

 

On char.cpp:
After:

	p.lAddr	= lAddr;

Add:

	#ifdef ENABLE_PROXY_IP
	if (!g_stProxyIP.empty())
		p.lAddr = inet_addr(g_stProxyIP.c_str());
	#endif

Like this:

1406391.png

 

On config.cpp:
After (or anywhere within the global variables definition): 

char		g_szInternalIP[16]

Add:

#ifdef ENABLE_PROXY_IP
std::string	g_stProxyIP = "";
#endif

Like this:
1406392.png

 

Still on config.cpp:
After: the last TOKEN
Add:

#ifdef ENABLE_PROXY_IP
		TOKEN("proxy_ip")
		{
#ifndef WIN32
			if (validateIpAddress(value_string))
				g_stProxyIP = value_string;
			else {
				struct hostent *host = gethostbyname(value_string);
				g_stProxyIP = inet_ntoa(*(struct in_addr *)host->h_addr_list[0]);
				fprintf(stderr, "PROXY_IP: [%s] resolves to [%s]\n", value_string, g_stProxyIP.c_str());
			}
#else
			g_stProxyIP = value_string;
#endif
			fprintf(stderr, "PROXY_IP: %s\n", g_stProxyIP.c_str());
		}
#endif

Like this:.png

 

Still on config.cpp:
Before: 

void config_init(const string& st_localeServiceName)

Add:

bool validateIpAddress(const std::string &ipAddress)
{
#ifndef WIN32
    struct sockaddr_in sa;
    int result = inet_pton(AF_INET, ipAddress.c_str(), &(sa.sin_addr));
    return result != 0;
#else
    return true;
#endif
}

Like this:

.png

On config.h:
After (or anywhere in the file):

extern char		g_szInternalIP[16];

Add:

#ifdef ENABLE_PROXY_IP
extern std::string	g_stProxyIP;
#endif

Like this:
1406394.png

 

On desc.cpp:
Within the function:

void DESC::SendLoginSuccessPacket()

Inside: 

for (int i = 0; i < PLAYER_PER_ACCOUNT; ++i)


Add in the beginning:

		#ifdef ENABLE_PROXY_IP
		if (!g_stProxyIP.empty())
			rTable.players[i].lAddr=inet_addr(g_stProxyIP.c_str());
		#endif

Like this:
1406395.png

 

On input_db.cpp:
Withing the function:

bool GetServerLocation(TAccountTable & rTab, BYTE bEmpire)

After:

						rTab.players[i].szName);

Add:

				#ifdef ENABLE_PROXY_IP
				if (!g_stProxyIP.empty())
					rTab.players[i].lAddr=inet_addr(g_stProxyIP.c_str());
				#endif


                
Still on input_db.cpp and within the same function:
After:

struct in_addr in;

Add:

		#ifdef ENABLE_PROXY_IP
		if (!g_stProxyIP.empty())
			rTab.players[i].lAddr=inet_addr(g_stProxyIP.c_str());
		#endif

Like this:
1406396.png

 

Still on the same file:
Within the function:

void CInputDB::PlayerCreateSuccess(LPDESC d, const char * data)

After:

	pack.player = pPacketDB->player;

Add:

	#ifdef ENABLE_PROXY_IP
	if (!g_stProxyIP.empty())
		pack.player.lAddr=inet_addr(g_stProxyIP.c_str());
	#endif

Like this:
1406397.png

 

Done on the source, you can compile.


On every channel config, add this:

BIND_IP: <Private IPv4 IP> (it will be something within a private IP class. Check the IP of the machine using the "ifconfig" command)
PROXY_IP: <Public IPv4 IP or a domain name (like example.com)> (check out something like https://www.whatismyip.com)

 

DNS names will only work on FreeBSD. I didn't make the code for Windows.

 

Private IPv4 classes:

1406398.png

On some sources (like the one from vanilla, BIND_IP was renamed to PUBLIC_IP, just check which TOKEN is responsible to set the value on the variable g_szPublicIP.

You will need to open the ports on your router, even for yourself on localhost with the virtual machine because the game server will try to "proxy" you through the public IP you defined.

This wasn't tested using a VPN, like Hamachi or ZeroTier.

  • Metin2 Dev 2
  • Good 1
  • Love 2
  • Love 5

raw

raw

Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...
  • 10 months later...

Hello developers, I apologize for reaching out here, but something seems to be not working for me with this content, or perhaps I am doing something wrong 😕 Everything is set up exactly as described, including the server files and the recommended TMP... After choosing the character, the game still returns to the login screen. There are no syserr logs. From this, I suspect it might not be an error but some other issue. Ports are open and verified. I will attach images of the AUTH and GAME first log files. If you could help me figure out where to start looking for the problem, I would appreciate it 🙂

auth and game first,and DB log file:
spacer.png
spacer.png

sorry for my English, I'm not asking to be replaced! I just want to finally figure out what could be wrong with being able to play with 10-15 friends online. I might even pay for the help if the information is really useful for me or if this problem can be solved 🙂 DC: it can be found on my profile or I can be reached here 🙂

Thanks in advance!!!!

Edited by Metin2 Dev International
Core X - External 2 Internal
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.