Minecraft-Console-Client icon indicating copy to clipboard operation
Minecraft-Console-Client copied to clipboard

Added a WebSocket Chat Bot

Open milutinke opened this issue 3 years ago • 9 comments

Added a Web Socket bot that enables remote control and sends all events from ChatBot API over the network.

The motivation for this Chat Bot:

  • Enables people who know other languages and do not want to learn C# to make Chat Bots in a language of their choice
  • Enables people to make nice UIs for controlling their MCC instances

Current state of the Chat Bot:

  • All events from the ChatBot API are being sent
  • Has authentication
  • Can support multiple connections at the same time
  • Can receive and execute MCC commands

Plans:

  1. To add some Pre-Made utility commands that could be called using the WebSocket
  2. In the following days I am going to write a JavaScript library which will enable people to make Chat Bots in JS. (I've tried embedding JavaScript as a second scripting way with ClearScript, but it turned out to be too complex of a task to make a clean looking API, maybe someone else can give it a try).
  3. To make an application that will use the library from above and Vue JS and release a: Web, Electron (Desktop) and a mobile versions.

Additional notes:

I've tested this only by myself on the local network, I need more people to test it out. I'm using a fork of WebSocketSharp by sta: https://www.nuget.org/packages/SIPSorcery.WebSocketSharp/0.0.1?_src=template

Here is a screenshot: image

milutinke avatar Aug 26 '22 15:08 milutinke

The JS library is almost done image

milutinke avatar Aug 28 '22 15:08 milutinke

PS: Not ready for merge yet, I still need to add an ability to execute ChatBot functions. Only opened a PR so people can test it out and give a feedback. I'll do documentation and finish a library before it is ready for merging, so people have everything from beginning.

milutinke avatar Aug 29 '22 16:08 milutinke

Added a functionality for RPC, so basically people can execute methods from the ChatBot over websocket asynchronously, the tracking will be done by the JS library, so people can execute and fetch the result of the execution. I still need to enable all useful methods and test out everything.

milutinke avatar Aug 31 '22 21:08 milutinke

Looks very promising! Indeed, that requires duplicating the API (implementing each method from ChatBot.cs and adding new methods here as well) but this is a good idea to add a standard way to communicate with MCC from another program written in any language 👍

I've made a quick security-related comment:

I am not that familiar with all things that C# offers with reflection like I am in Java. I had an idea to make schemas for checking the incoming procedures/method calls, then executing them and auto convert parameters to types that methods need too, but I have no C# knowledge on this level yet. Seems kinda tricky with auto converting types to proper ones, so I opted for a manual way. Do you have any ideas on this?

milutinke avatar Sep 03 '22 18:09 milutinke

I think it is feasible like in Java, but I'm not sure how you would convert complex classes like Entity, maybe with JSON serialization 🤔

ORelio avatar Sep 04 '22 15:09 ORelio

The Bot is almost done, I've added all useful methods (only skipped a few that can't work over the network), ~~I need to test all methods and fix if something isn't working~~, then I need to finish the JS library and document everything.

Edit: Tested, only the JS library is remaining

milutinke avatar Sep 10 '22 16:09 milutinke

I'll most likely drop the front end support for the time being since I could not find a way to solve the issue with code loading on the front end, I'll most likely use some bundler later for the front end version of the JS library. Also, might close this PR in favor of a new one to avoid dealing with a bunch of merge conflicts, there are quite a lot because the branch is really dated.

milutinke avatar Sep 29 '22 23:09 milutinke

Waiting for toml branch to merge.

milutinke avatar Oct 09 '22 17:10 milutinke

Waiting for toml branch to merge.

Ready to merge it, some people have been using the pre-release version for a while. (Manually releasing a release is a bit of a pain)

BruceChenQAQ avatar Oct 10 '22 02:10 BruceChenQAQ