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

Add web player authentication. Closes GH-48 #76

Merged
merged 12 commits into from May 27, 2017
Merged

Add web player authentication. Closes GH-48 #76

merged 12 commits into from May 27, 2017

Conversation

satoshinm
Copy link
Owner

@satoshinm satoshinm commented May 27, 2017

#48

@satoshinm
Copy link
Owner Author

The client currently accepts two command-line arguments, server address and port:

    // CHECK COMMAND LINE ARGUMENTS //
    if (argc == 2 || argc == 3) {
        g->mode = MODE_ONLINE;
        strncpy(g->server_addr, argv[1], MAX_ADDR_LENGTH);
        g->server_port = argc == 3 ? atoi(argv[2]) : DEFAULT_PORT;
        set_db_path();
    }

This plugin prepends window.DEFAULT_ARGV = ['-']; to craft.js, for the web client to connect back to document.domain. document.hash (in the URL after #) is accepted as a command-line argument override. Maybe extend this functionality to support specifying the username sth like #u=foo, to automatically run /login <username>, or equivalent (the centralized auth of Craft may not be appropriate for decentralized web-based usage: satoshinm/NetCraft#143), which sends:

    snprintf(buffer, 1024, "A,%s,%s\n", username, identity_token);

The client always sends this command on login, but is usually blank:

22:32:07 [INFO] handle:V,1
22:32:07 [INFO] handle:A,,

@satoshinm
Copy link
Owner Author

This now works but the authentication key is untenably long to type by hand, it needs to be copyable or clickable. Found an API request GlowstoneMC/Glowkit-Legacy#8 to add RichMessage support to Glowstone and also a dead Bukkit/Bukkit#1111 [B+C] Add API to use 1.7 chat features. Adds BUKKIT-5245.

player.spigot().sendMessage(textcomponent) seems to be way to do it now, per https://www.spigotmc.org/threads/colors-in-config-and-clickevent-action-open_url.61753/ and https://www.spigotmc.org/threads/clickevent-doesnt-work.65457/ but Glowstone 498 fails:

11:30:09 [SEVERE] Exception while executing command: /websandbox auth
org.bukkit.command.CommandException: Unhandled exception executing command 'websandbox' in plugin WebSandboxMC v1.8.3
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:188)
        at net.glowstone.GlowServer.dispatchCommand(GlowServer.java:1365)
        at net.glowstone.entity.GlowPlayer.lambda$chat$13(GlowPlayer.java:1793)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at net.glowstone.scheduler.GlowTask.run(GlowTask.java:167)
        at net.glowstone.scheduler.GlowScheduler.pulse(GlowScheduler.java:152)
        at net.glowstone.scheduler.GlowScheduler.lambda$start$0(GlowScheduler.java:83)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.UnsupportedOperationException: Not supported yet.
        at org.bukkit.entity.Player$Spigot.sendMessage(Player.java:1734)
        at io.github.satoshinm.WebSandboxMC.bukkit.WsCommand.onCommand(WsCommand.java:148)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more

This may need to be implemented in Glowstone to proceed further, clickable links are really important for this plugin feature.

@satoshinm
Copy link
Owner Author

Testing on 1.12-pre5, this code works - the link is clickable. But the game also speaks the text?! There is a text-to-speech engine in the Minecraft client now apparently: https://minecraft.net/en-us/accessibility/ "Text-To-Speech Accessibility Minecraft includes text-to-speech functionality for in-game text chat.", who knew...

As for Glowstone or older versions, could try using http://minecraft.gamepedia.com/Commands#Raw_JSON_text clickEvent action open_url, maybe hoverEvent too while at it. And for even older versions without either, a third option (also used when /websandbox auth from the server console, instead of as a player) is to send the URL as plain text.

@satoshinm satoshinm changed the title [WIP] Add web player authentication. Closes GH-48 Add web player authentication. Closes GH-48 May 27, 2017
@satoshinm satoshinm merged commit eb10de4 into master May 27, 2017
@satoshinm satoshinm deleted the auth branch May 27, 2017 23:41
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

1 participant