Skip to content
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

Cookie Api - Fabric Networking Api #3547

Open
wants to merge 42 commits into
base: 1.20.5
Choose a base branch
from

Conversation

MrNavaStar
Copy link
Contributor

@MrNavaStar MrNavaStar commented Jan 22, 2024

This Pr adds an api for the new 1.20.5 transfer packets and cookie system. Currently the api can be accessed through any of the network handlers (except handshake).

Transfer api:

public interface ServerTransferable {

    void transferToServer(String host, int port);

    boolean wasTransferred();
}

Cookie Api:

public interface ServerCookieStore {

    void setCookie(Identifier cookieId, byte[] cookie);

    CompletableFuture<byte[]> getCookie(Identifier cookieId);
}

@MrNavaStar
Copy link
Contributor Author

MrNavaStar commented Jan 23, 2024

Hmmm, The injected interfaces don't seem to be working without a cast (testing in an external dev environment). Does any one see anything obviously wrong? (Could also be my dev env lol)

@apple502j
Copy link
Contributor

Try run genSource on the networking project.

@MrNavaStar
Copy link
Contributor Author

Yeah doesn't seem to fix it. Issue happens both in the test mod & in a full external environment

@@ -117,6 +139,13 @@ public void onInitialize() {
}
}
});

ServerLoginConnectionEvents.INIT.register((handler, server) -> {
Copy link
Member

Choose a reason for hiding this comment

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

Add the same test for configuration

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to ensure that configuration can wait until the cookies have been returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the test. I'm not sure if we need to? A mod that wants that behaviour would probably just implement that in the rest of its configuration stuff

Copy link
Member

Choose a reason for hiding this comment

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

Login also needs testing.

I think its imporant that login and/or configuation can be bocked until the cookie has been returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would the best way to hold the network stage be?

public void fabric_invokeCookieCallback(Identifier cookieId, byte[] cookie) {
CompletableFuture<byte[]> future = pendingCookieRequests.remove(cookieId);
if (future == null) return;
future.complete(cookie);
Copy link
Member

Choose a reason for hiding this comment

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

Question: What thread does this complete on? I would expect the network thread during config, and the main thread during play

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it always runs the network thread, as its triggered by the packet response (unless packets process in the main thread in play? I didn't think they did)

@@ -172,4 +178,25 @@ public final void handleDisconnect() {
* @return whether the channel is reserved
*/
protected abstract boolean isReservedChannel(Identifier channelName);

public boolean triggerCookieFuture(Identifier cookieId, byte[] cookie) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a prime target for some unit tests :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how would you prime the underlying map with data so you can test this function?

@@ -117,6 +139,13 @@ public void onInitialize() {
}
}
});

ServerLoginConnectionEvents.INIT.register((handler, server) -> {
Copy link
Member

Choose a reason for hiding this comment

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

Login also needs testing.

I think its imporant that login and/or configuation can be bocked until the cookie has been returned.

@MrNavaStar
Copy link
Contributor Author

@modmuss50 Just wanted to put it out there, would a pre transfer event be useful? In case mods want to set cookies when another mod triggers a transfer? This may also work nicely with the new /transfer command

@MrNavaStar
Copy link
Contributor Author

Hey, sorry for being so slow to get back on this. Once my exams are done this week I should hopefully be able to finish this up. Thanks for your help!

@MrNavaStar MrNavaStar changed the title Transfer / Cookie Api - Fabric Networking Api Cookie Api - Fabric Networking Api Apr 16, 2024
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.

None yet

6 participants