Skip to content

Add IPv6/Dual Stack + read servers.dat#816

Open
12brendon34 wants to merge 1 commit intosmartcmd:mainfrom
12brendon34:Dual-Stack-IPv6-Support
Open

Add IPv6/Dual Stack + read servers.dat#816
12brendon34 wants to merge 1 commit intosmartcmd:mainfrom
12brendon34:Dual-Stack-IPv6-Support

Conversation

@12brendon34
Copy link

Description

Modifies WinsockNetLayer.cpp to use Dual stack/IPv6 support
Modifies PlatformNetworkManagerStub.cpp to read Java "servers.dat"
fix flaw in SetupHeadlessServerConsole()

Changes

Add a little helper WinsockNetLayer::IsNumericAddress,
Modify HostGame, AcceptThreadProc

Modify CPlatformNetworkManagerStub::SearchForGames() to read java "servers.dat"
I also changed the "servers.txt" logic slightly to make sure it works with IPv6 addresses

SetupHeadlessServerConsole() now attempts AttachConsole(ATTACH_PARENT_PROCESS) first

Previous Behavior

IPv6 support just didn't exist

Root Cause

It's old

New Behavior

It now uses the IPv6 flags and IP parsing logic

Fix Implementation

bool WinsockNetLayer::HostGame(int port, const char* bindIp)
{
...
	hints.ai_family = AF_UNSPEC;
...
	if (resolvedBindIp == NULL)
		hints.ai_flags = AI_PASSIVE;
	else if (IsNumericAddress(resolvedBindIp))
		hints.ai_flags = AI_NUMERICHOST;
	else
		hints.ai_flags = 0;
...
	DWORD ipv6only = 0;
	setsockopt(s_listenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&ipv6only, sizeof(ipv6only));
...
}

bool WinsockNetLayer::JoinGame(const char* ip, int port)
{
...
	if (IsNumericAddress(ip))
		hints.ai_flags = AI_NUMERICHOST;
	else
		hints.ai_flags = 0;

	hints.ai_family = AF_UNSPEC;
...
}


bool WinsockNetLayer::IsNumericAddress(const char* addr)
{
	if (addr == NULL)
		return false;

	if (strchr(addr, ':') != NULL)
		return true;// IPv6

	if (inet_addr(addr) != INADDR_NONE)
		return true;// IPv4

	return false;// hostname
}

AI Use Disclosure

No AI was used for this

@void2012
Copy link
Collaborator

void2012 commented Mar 7, 2026

Related to #498 ?

@12brendon34
Copy link
Author

12brendon34 commented Mar 7, 2026

Related to #498 ?

I would say so

@void2012
Copy link
Collaborator

void2012 commented Mar 7, 2026

Consider collaborating with that PR author

@12brendon34
Copy link
Author

12brendon34 commented Mar 7, 2026

Consider collaborating with that PR author

I think I broke IPv4 slightly, need to figure that out first.
maybe not, I just tested on a diff server and it connected fine

@kuwacom
Copy link
Contributor

kuwacom commented Mar 7, 2026

Consider collaborating with that PR author

Basically, the separated dedicated server works by calling functionality from the Minecraft.Client side, so once these features are merged into main, they will automatically apply here as well.

@void2012
Copy link
Collaborator

void2012 commented Mar 7, 2026

Okay. Ask someone to test your PR

@12brendon34
Copy link
Author

Okay. Ask someone to test your PR

I'll see if I can get someone to test tmr, it's 3:04 AM right now for me.

@12brendon34
Copy link
Author

12brendon34 commented Mar 7, 2026

I just realized I think I accidentally reverted some of #722, no clue how I messed that up.
I'll fix that real quick

@12brendon34 12brendon34 force-pushed the Dual-Stack-IPv6-Support branch 2 times, most recently from c1e8c97 to ba3ab32 Compare March 7, 2026 22:43
Also Fix SetupHeadlessServerConsole() to use an existing console if possible.
Read Java servers.dat, I like it more then the text file, but it's optional.
@12brendon34 12brendon34 force-pushed the Dual-Stack-IPv6-Support branch from ba3ab32 to b867c27 Compare March 7, 2026 22:46
@12brendon34
Copy link
Author

I've amended it now, I'll see if I can get some friends to test it a bit later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants