A plugin that serving completely in-game webview based console backend for grasscutter

Overview

MojoConsolePlus

EN|中文

MojoConsolePlus(MCP) is a Grasscutter plugin (Apart from 4Benj's GCGM plugin) and it's goal is to implement fully in-game webwiew based .

Currently Features:

  • Send console link in game
  • Do what players can do in the in-game chat based console
    • Inherit the original permission system
    • Capture command response to plugin instead of send chat to player
  • More configurable
  • Use external CDN

Important Notes:

This plugin is made to run on the current Development branch of Grasscutter.
This plugin is in very early development and only have the backend now. Frontend is extermely hardcore. If you require support please ask on the Grasscutter Discord. However, support is not guarenteed.

MojoConsolePlus is decoupled with any frontend yet, feel free to open a PR to introduce your implented frontend.

Development frontend for MojoConsolePlus don't have to restart the Grasscutter server. Just refresh page! There will be a URL printed to the console as log to help you access the console in your browser for development.

Setup

Download Plugin Jar

See realeases.

Compile yourself

  1. Pull the latest code from github using git clone https://github.com/mingjun97/gc-mojoconsole-plus in your terminal of choice.
  2. Locate your grasscutter server and copy the grasscutter server jar into the newly created gc-mojoconsole-backend/gc-plugin/lib folder
  3. Navigate back into the project root folder called gc-mojoconsole-plus folder and run gradlew build (cmd) or ./gradlew build (Powershell, Linux & Mac).
  4. Assuming the build succeeded, in your file explorer navigate to the gc-plugin folder, you should have a mojoconsole.jar file, copy it.
  5. Navigate to your Grasscutter server, find the plugins folder and paste the mojoconsole.jar into it.
  6. Start your server.

...Jump to next section...

Usage

You have two options for hosting frontend.

Use CDN hosted frontend(Recommended)

  1. Pull the file mojoconfig.json into your plugins folder, set the useCDN to true. Alternatively, you can launch the grasscutter first, then the mojoconfig.json will be auto generated.
  2. Modify the config.json of Grasscutter, make sure the cors is enabled. It's required in CDN mode. See config.json->server->policies->cors.

CDN serving frontend is hosted by us via the github pages. The credentials will be passed via the hash paramets, which means the credentials(i.e. User session key, access address for your grasscutter server) will not be passed through the network. We will update our CDN frontend regularly, so that you don't have to handle the frontend update by yourself and always enjoy the latest version. Enabling CORS will not put your grasscutter in dangerous. It's just for protecting users accessed on browser from potential information leakage in some rare circumstances, and grasscutter actually don't have this concern.

Self hosted frontend

  1. Put the all the frontend files into the folder GRASSCUTTER_ROOT/plugins/mojoconsole/. Note that your must have console.html for now. You are free to put any other dynamiclly loaded file(e.g. .js, .css) in that folder. Check the last section for current avialable frontend.

Commands for mojo

  1. Send command /mojoconsole or /mojo to server in game, and you will receive mail in your mailbox. Then follow the instructions there. Note that you may use o option to use the pop out browser instead of in-game webwiew, e.g. /mojo o. By default, the console is in-game webview.

Your final plugins folder's directory structure should look similar to this

GRASSCUTTER_ROOT
|   grasscutter.jar
|   resources
|   data
|   ...
└───plugins
    │   mojoconsole.jar
    │   ...
    └───mojoconsole
        │   console.html
        |   ...
        └───any other file that you want to include in your frontend
            │   ...

API

URL: /mojoplus/api

Request: Content-Type: application/json

    {
        "k": "SESSION_KEY", // **DEPRECATED** sesssion key is embedded in the mail, can be retreved via the GET params.
        "k2": "AUTH_KEY",   // auth key, this is the second version auth key, choose either `k` or `k2`
        "request": "invoke", // set request to ping will ignore the payload, which just check the aliveness of current sessionKey 
        "payload": "command just like what you do in your in game chat console" // example: "heal" for heal all avatars
    }

Response: Content-Type: application/json

    {
        "message": "success", // message saying the execution status,
        "code": 200, // could be 200 - success, 403 - SessionKey invalid, 500 - Command execution error (should from command), 400 - request not supported
        "payload": "response for the command", // example: got "All characters have been healed." when invoking with "heal"
    }

URL: /mojoplus/auth Request a auth key for player

Request: Content-Type: application/json

    {
        "uid": "UID", // player uid to be requested
        "otp": "OTP", // **OPTIONAL**, use the OTP returned from previous `auth` request to check the status of the ticket.
    }

Response: Content-Type: application/json

    {
        "message": "success", // message saying the execution status,
        "code": 200, // could be 200 - success, check content in `key` field,
                     // 404 - Player not found or offline
                     // 201 - Not ready yet, player has not confirmed yet
                     // 400 - request not supported
        "key": "OTP or AUTH_KEY", // with `otp` field: AUTH_KEY for that player
                                  // without `otp` field: `OTP` for further request
    }

Resources

You can use the following function to send the request, just plug it after you finished the command generation job. payload is the command you wish to send.

function sendCommand(payload){
    var client = new XMLHttpRequest();
    var key = new window.URLSearchParams(window.location.search).get("k");
    var url = '/mojoplus/api';
    client.open("POST", url, true);
    client.setRequestHeader("Content-Type", "application/json");
    client.onreadystatechange = function () {
        if (client.readyState === 4 && client.status === 200) {
            var result = document.getElementById("c2");
            // Print received data from server
            result.innerHTML = JSON.parse(this.responseText).payload.replace(/\n/g, "<p/>");
        }
    };

    // Converting JSON data to string
    var data = JSON.stringify({ "k": key, "request": "invoke", "payload": payload });
    // Sending data with the request
    client.send(data);
}

Frontend

By SpikeHD: https://github.com/SpikeHD/MojoFrontend (under development) CDN hosted frontend:https://github.com/gc-mojoconsole/gc-mojoconsole.github.io

Desktop version on Windows https://github.com/SwetyCore/MojoDesktop
...You can develop your own frontend and make PR to put yours here...

You might also like...

Simple Design for Java bridge with Javascript. Also can get javascript console.log.

Simple Design for Java bridge with Javascript. Also can get javascript console.log.

SDBridgeKotlin is here. If your h5 partner confused about how to deal with iOS and Android. This Demo maybe help. 最常见的问题. WebViewJavascriptBridge is n

Dec 18, 2022

Make the Velocity proxy run commands based on backend input.

Command Sync Server This plugin allows the Velocity proxy to run commands based on backend input. Purpose The purpose of this is to allow easy access

May 23, 2022

A minecraft plugin that let's you suicide in game

A minecraft plugin that let's you suicide in game

Suicide A minecraft plugin that let's you suicide in game Command /suicide - Let's you suicide Permission me.suicide - You can edit this in config.yml

Feb 16, 2022

Community-Driven Game Server Development solution for Java Developers based on DEEPINTHINK MagOKO Project.

MagOKO Stack Community-Driven Game Server Development solution for Java Developers based on DEEPINTHINK MagOKO Project. License Copyright 2021-present

Jun 1, 2021

A Java-based template project for the FastJ Game Engine.

A Java-based template project for the FastJ Game Engine.

FastJ Java Template Program Requirements Java 16 JDK Basic understanding of Java Initial Setup Download the Template You have a few options for gettin

May 15, 2022

Desktop browser based game using the popular Pokemon franchise.

Project Title: Pokemon Auto-Battler Description: Desktop browser based game using the popular Pokemon franchise. Why? Its a topic we are interested in

Feb 3, 2022

A backend for Asciidoctor used to produce Spring styled HTML

Asciidoctor Spring Backends Alternative HTML conversion for Asciidoctor with a Spring "look and feel". Maven build integration You can use the Asciido

Dec 14, 2022

Backendini Javada Frontendini ise React ile yazacağım insan kaynakları yönetim kısmınının backend kısmıdır

Backendini Javada Frontendini ise React ile yazacağım insan kaynakları yönetim kısmınının backend kısmıdır

İnsan Kaynakları Yönetim Sistemi insan kaynaklarının, iş süreçlerinin ve verilerin kolay yönetimini sağlamak için bir dizi sistemi ve işlemi birleştir

Dec 5, 2022

backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3.

backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3.

moments_v2_backend (Work In Progress) backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3. This is the second version of my project S

Dec 26, 2022
Comments
  • [feature request] support third-party clients

    [feature request] support third-party clients

    Request to open the third-party client player authorization port. When the client uses the player's UID to request authorization, send an email to the player for authorization. After the player agrees, the third-party client is allowed to use the UID to execute commands.

    enhancement 
    opened by jie65535 3
  • Failing to enable plugin

    Failing to enable plugin

    I have done all the instructions for CDN hosted frontend but I still keep getting error Failed to enable plugin: mojoconsole-plus java.lang.AbstractMethodError: Receiver class com.mojo.consoleplus.RequestHandler does not define or inherit an implementation of the resolved method 'abstract void applyRoutes(io.javalin.Javalin)' of interface emu.grasscutter.server.http.Router. at emu.grasscutter.server.http.HttpServer.addRouter(HttpServer.java:121) at com.mojo.consoleplus.ConsolePlus.onEnable(ConsolePlus.java:59) at emu.grasscutter.plugin.PluginManager.lambda$enablePlugins$2(PluginManager.java:201) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) at emu.grasscutter.plugin.PluginManager.enablePlugins(PluginManager.java:198) at emu.grasscutter.Grasscutter.main(Grasscutter.java:160)

    opened by Moglibogli 0
  • [Bug] java.lang.IllegalAccessError: class com.mojo.consoleplus.ConsolePlus tried to access private field

    [Bug] java.lang.IllegalAccessError: class com.mojo.consoleplus.ConsolePlus tried to access private field

    After upgrade Grasscutter version to newest Development branch (version 1.1.2-dev commit:58df221). there is an IllegalAccessError may cause main console running interrupt.

    Here''s the Error report:

    16:44:22 <INFO:PluginManager> Enabling plugin: mojoconsole-plus
    Exception in thread "main" java.lang.IllegalAccessError: class com.mojo.consoleplus.ConsolePlus tried to access private field emu.grasscutter.Configuration.PLUGINS_FOLDER (com.mojo.consoleplus.ConsolePlus is in unnamed module of loader java.net.URLClassLoader @f10d055; emu.grasscutter.Configuration is in unnamed module of loader 'app')
            at com.mojo.consoleplus.ConsolePlus.onEnable(ConsolePlus.java:27)
            at emu.grasscutter.plugin.PluginManager.lambda$enablePlugins$3(PluginManager.java:131)
            at java.base/java.util.HashMap.forEach(HashMap.java:1421)
            at emu.grasscutter.plugin.PluginManager.enablePlugins(PluginManager.java:129)
            at emu.grasscutter.Grasscutter.main(Grasscutter.java:153)
    
    opened by aquawius 0
Releases(latest)
Owner
null
The in-game login system for Grasscutter is based on oauth and GCAuth.

GCAuth OAuth The in-game login system for Grasscutter is based on oauth and GCAuth. Current Features: Use Twitter oauth to login Custom pages Importan

Xtao-Team 36 Nov 14, 2022
The in-game login system for Grasscutter is based on oauth and GCAuth.

GCAuth OAuth The in-game login system for Grasscutter is based on oauth and GCAuth. Current Features: Use Twitter oauth to login Custom pages Importan

Xtao-Labs 29 Aug 3, 2022
A Text Based, Turn-Based, Strategy Game to be played in console

ConsoleGame A Text Based, Turn-Based, Strategy Game to be played in console. Feel free to fix any retardation in my code (meaning bugs, stupid/spaghet

Bertrahm 2 Jul 17, 2022
Anime game server software reimplementation. Planning to replace @Grasscutters/Grasscutter.

NOTE This is a rewritten version of Grasscutter. Find the original project at Grasscutters/Grasscutter. Grasscutter TODO: Write README.md Players Guid

Magix 11 Dec 1, 2022
This is a database system, completely based on java!

AstralPathSQL Creator BestLoveForYou website:website email:[email protected] 2022-07-17 0:4 Beijing time Brief Introduction: This is a database syst

茸 2 Jul 16, 2022
A plugin of Grasscutter for send regular notice.

MeaNotice - Grasscutter Regular Notice Plugin MeaNotice is a plugin of Grasscutter, you can use this plugin to publish notifications in-game regularly

ButterCookies 39 Oct 17, 2022
Completely customizable lightshows for everyone

Please view the new WIKI for set-up instructions! Music visualiser plugin for vanilla minecraft which uses beat saber beatmaps (including chroma suppo

Hydrogen 18 Dec 28, 2022
Spring boot backend for marble guessing game inspired by Squid Game TV series.

Back-end for marble guessing game inspired by Squid Game TV series. Built with Spring-boot and WebSocket.

Zaid 4 Sep 3, 2022
GodType is a very simple Bukkit plugin to allow the console (or a player) to chat as a defined name.

GodType GodType is a very simple Bukkit plugin to allow the console (or a player) to chat as a defined name. Config A config.yml file will be created

null 1 Dec 24, 2021
🎯 ConsoleCaptor captures console output for unit testing purposes

ConsoleCaptor Install library with: Install with maven <dependency> <groupId>io.github.hakky54</groupId> <artifactId>consolecaptor</artifactId

Hakan Altındağ 15 Dec 9, 2022