satoshinm / WebSandboxMC

Bukkit plugin providing a web-based interface with an interactive WebGL 3D preview or glimpse of your server 🕷⏳📦 ⛺
https://www.spigotmc.org/resources/websandboxmc.39415/
MIT License
19 stars 5 forks source link

Add web player authentication. Closes GH-48 #76

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

https://github.com/satoshinm/WebSandboxMC/issues/48

satoshinm commented 7 years ago

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: https://github.com/satoshinm/NetCraft/issues/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 commented 7 years ago

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 https://github.com/GlowstoneMC/Glowkit-Legacy/pull/8 to add RichMessage support to Glowstone and also a dead https://github.com/Bukkit/Bukkit/pull/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 commented 7 years ago

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.