8000 feat: add cookies by BorisP1234 · Pull Request #507 · minekube/gate · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add cookies #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed

feat: add cookies #507

wants to merge 8 commits into from

Conversation

BorisP1234
Copy link
Contributor
@BorisP1234 BorisP1234 commented Feb 20, 2025

Hello, cookie packets were introduced in Minecraft 1.20.5 along with transfer packets, an underrated feature that can be particularly useful in multi-proxy scenarios. That’s why I found it unfortunate that this functionality wasn’t included in the Gate API, so I decided to add it myself!

I added three functions to the player variable:

  • player.CookieStore(key key.Key, payload []byte) error
    This function sends a cookie to the player, storing it even between transfers until the player disconnects. It returns an error if:

    • The key is empty.
    • The payload is too large.
    • The player's state is not "play" or "config."
    • The player is using a version lower than 1.20.5.
    • An error occurs while sending the packet.
  • player.CookieRequest(key key.Key) error
    This function requests a cookie from the player. The player then sends a response packet, which can be handled with the PlayerCookieResponseEvent (explained later). It returns an error if:

    • The key is empty.
    • The player is using a version lower than 1.20.5.
    • An error occurs while sending the packet.
  • player.CookieRequestWithResult(key key.Key) ([]byte, error)
    This function retrieves a cookie immediately instead of relying on PlayerCookieResponseEvent. It waits for a response from the player for up to 5 seconds. It returns an error if:

    • The key is empty.
    • The player is using a version lower than 1.20.5.
    • An error occurs while sending the packet.
    • The response takes longer than 5 seconds.

I added a new event called PlayerCookieResponseEvent, which listens for cookie response packets. This event contains the player, key, and payload. If the requested cookie is not found, an empty payload is returned.

You can test the features with this wonderful mod that I found called: CookieJar by Tis_awesomeness.

@robinbraemer
Copy link
Member

Thank you! I'll try to merge when I find the time

@robinbraemer
Copy link
Member

As an afterthought, can we move all public cookie logic into a standalone package? I'm trying to avoid adding more functions to the Player interface. I'm thinking a cookie package similar to https://github.com/minekube/gate/tree/master/pkg/edition/java/bossbar.

@BorisP1234
Copy link
Contributor Author

Okay I'll take a look at it 👍

@BorisP1234 BorisP1234 reopened this May 1, 2025
@BorisP1234 BorisP1234 requested a review from robinbraemer May 1, 2025 22:40
@BorisP1234
Copy link
Contributor Author

Okay I think i managed to resolve every requested change. @robinbraemer Is this how you visioned the cookie package?

The only thing I don't really like is how the CookieResponseEvent doesn't return the Cookie structure, since its not possible due to import cycle. This also made it so I needed to put the map in the proxy package instead of the cookie package but I don't think that is a problem.

@SinonCute
Copy link

When this can be merged, I’m waiting for it

@robinbraemer
Copy link
Member
robinbraemer commented May 15, 2025

There are a few things I have to iterate on.

  • thinking ideal interface
  • avoid full proxy.Player
  • channel handling
  • thinking sync Pool is the right choice (there is a potential leak when it is created when doesn’t exist yet)
  • testing with varint + writebytes or writebytesraw should be used

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
0