Skip to content

Implement publishing and joining worlds#258

Open
lactyy wants to merge 17 commits intoSandertv:masterfrom
lactyy:multiplayer
Open

Implement publishing and joining worlds#258
lactyy wants to merge 17 commits intoSandertv:masterfrom
lactyy:multiplayer

Conversation

@lactyy
Copy link

@lactyy lactyy commented Aug 11, 2024

Adds a support for publishing and joining worlds displayed in the friend list. Closes #219.

WIP. I might separate these packages into a different module to reduce usage of huge dependencies added for WebRTC.

Task Lists:

  • Implement listening on NetherNet
  • Implement publishing worlds
  • Implement dialing on NetherNet
  • Implement looking up worlds
  • Properly write a documentation on types, methods, fields, etc. (Help needed...)
  • Implement LAN discovery

@lactyy lactyy marked this pull request as ready for review August 26, 2024 16:08
@lactyy
Copy link
Author

lactyy commented Sep 15, 2024

The changes in pull request and other packages, which have been split into separate modules, has been fully documented.

// Credentials blocks until [nethernet.Credentials] are received from the server or the [context.Context]
// is done. It returns a [nethernet.Credentials] or an error if the Conn is closed or the [context.Context]
// is canceled or exceeded a deadline.
func (c *Conn) Credentials(ctx context.Context) (*nethernet.Credentials, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment says this method is blocking but the select has a default case

ConnectionType uint32 `json:"ConnectionType"`
HostIPAddress string `json:"HostIpAddress"`
HostPort uint16 `json:"HostPort"`
NetherNetID uint64 `json:"NetherNetId"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont forget to change this to a string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually its sent as either a string UUID or a uint64, not a string-based uint64 so this needs a custom type which supports string | uint64 decoding

}
}

func NetherNetID(status Status) (uint64, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would change this to func (status Status) NetherNetID()

r.mu.Lock()
defer r.mu.Unlock()

if r.t == nil || !r.t.Valid() || r.x == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should check x.Valid() but the whole function can be improved like this

func (r *refreshTokenSource) Token() (_ xsapi.Token, err error) {
	r.mu.Lock()
	defer r.mu.Unlock()

	// Return the cached XBL token if it is valid.
	if r.x != nil && r.x.Valid() {
		return r.x, nil
	}

	// Request a new underlying token if it is not valid.
	if r.t == nil || !r.t.Valid() {
		r.t, err = r.underlying.Token()
		if err != nil {
			return nil, fmt.Errorf("request underlying token: %w", err)
		}
	}

	// Request a new XBL token using the underlying token.
	r.x, err = auth.RequestXBLToken(r.ctx, r.t, r.relyingParty)
	if err != nil {
		return nil, fmt.Errorf("request xbox live token: %w", err)
	}

	return r.x, nil
}

@Sandertv
Copy link
Owner

Sandertv commented Feb 5, 2026

What needs to be done to get this updated to use the new auth that was merged?

@lactyy
Copy link
Author

lactyy commented Feb 5, 2026

First, we need an implementation for connecting to the signaling service provided by Minecraft.

At the moment, Minecraft uses two different signaling methods:

  • JSON-over-WebSocket
  • JSONRPC-over-WebSocket (referred to as Player Messaging), which is being gradually rolled out to users depending on treatment contexts.

On top of that, we need support for announcing, discovering, and joining worlds via Xbox Live, with compatibility for both signaling methods mentioned above.

Finally, on the protocol, we need:

  • support for custom batch headers in packets (for example, 0xfe is used by RakNet, but this is not present in NetherNet packets), and
  • a way to disable encryption in packet.Encoder and packet.Decoder.

@lactyy
Copy link
Author

lactyy commented Feb 5, 2026

I’m currently rewriting df-mc/go-xsapi to make it more usable for this PR, and it includes a new implementation for Xbox Live authentication.

During this work, I found that the relying party for XBL tokens can be determined automatically based on the request URL, so my fork includes support for that as well.

I’m planning to submit a PR to df-mc/go-xsapi, but it isn’t ready yet.

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.

Ability to join xbox friend worlds

3 participants