Add some way for addons to communicate with external programs. This will be useful for minigame servers, for example for storing and retrieving player data.
The following is an example of how it can work. However, these specific details aren't important. It is OK to implement it a bit differently. :)
- ExternalConnection object:
a) disconnect() method
b) sendMessage(msg) method
c) listenForMessage(callback) method - event on_external_conection with externalConnection as parameter
- /scriptconnect command to connect to a websocket server
Example use:
- user starts an external program which creates a websocket server listening on port 1234
- user starts BDS and loads the world
- user types "/scriptconnect localhost:1234" into BDS console
- Minecraft connects to the websocket server
- the on_external_conection event is triggered
- the script uses the connection object to send and receive messages
Example script:
system.listenForEvent("minecraft:on_external_conection", function(connection) {
connection.listenForMessage(function(msg) {
// msg is the message external program sent
});
connection.sendMessage({greeting:"hello world"}); // external program will recieve this message
});
This command should require the highest permission level and only the host should be able to execute it!
Also see this: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
Please sign in to leave a comment.
3 Comments