2022/05/25

Notes on "mojang-net" and "mojang-minecraft-server-admin"

I'm not going to try to organize this post lol

So these libraries are amazing. They allow for web access.

Due to security concerns, these are currently exclusive to only BDS. And the Preview BDS just showed up today :D


This is a simple example:

BP

import { world } from 'mojang-minecraft'; import { http, HttpHeader, HttpRequest, HttpRequestMethod } from 'mojang-net'; import { secrets, variables } from 'mojang-minecraft-server-admin'; world.events.chat.subscribe(evd => {     const { message, sender } = evd;     const request = new HttpRequest(variables.get('host'))         .setBody(JSON.stringify({             name: sender.name,             message         }))         .setHeaders([             new HttpHeader('auth', secrets.get('host'))         ])         .setMethod(HttpRequestMethod.POST);     http.request(request).catch(err => console.warn(err)); });

NodeJS Server Script

const port = 49152;
const http = require('http');
const server = http.createServer();
server.listen(port);
server.on('request', (req, res) => {
    res.setHeader('Content-Type', 'text/plain');
    console.log(req.headers);
    let body = [];
    req.on('data', d => body.push(d)).on('end', async () => {
        try { body = JSON.parse(Buffer.concat(body).toString()); } catch {}
        console.log(body);
        res.end('');
    });
    console.log('Received request');
});

console.log('Server Ready');

Variables can be used to store data in a way that's more easily accessible to the server admin.

Secrets store information that shouldn't be obtained anywhere. As of now, I've only been able to use secrets.get() in an HTTP Header. Used for things like authentication to a server.


In a BDS server, variables.json and secrets.json are located in config/default. I haven't checked if any custom subfolders beneath config work. They're just a normal key/value pair, and the get method takes the key as the argument. Objects are supported, as well as anything other JSON data type.


Update 2022/06/07: The subfolders can be the module UUID (not header), which essentially limits configured variables and secrets to only that specific add-on

2022/05/24

It's Too Much.

I hate politics. This shouldn't even be political. But, here we go.

These acts are simply too much. You've heard it already, and I'll repeat it. Sandy Hook Elementary School all over again. As I am writing this tweet, the full lives of 18 students aged below 10 were cut short.

What ARE we doing? Senator Chris Murphy, thank you for that emotional speech. As a nation, not just those 100 members of Congress, what are we doing?

We don't need 5 year olds asking, "Am I going to die today?" There's enough going on in this world to add on that question.

This is personal for me, too. On March 8, a shooter opened fire on the grounds of Des Moines East High School, in Des Moines, Iowa. You've probably never even heard of it, and that's exactly the problem. There's simply too many shootings going on to cover all of them.

I don't know everything. I certainly never will. But shootings? That's pure evil. What happened in Uvalde never should've happened.

Remember that Americans boast freedom and opportunity. But you can't have opportunity if you're dead. You're arguably less free after murdering.

Better gun control is long overdue, but it's better late than never. Tell your senators to work to accomplish the reforms that Sandy Hook could not. If you can't get it done nationally, get it done in your state. Tell anyone that represents you to fight for this.

It's simply enough. I can't bear waking up every day expecting the worst. But that's what I'm doing, as well as countless others.

I'll probably regret and delete this thread later, but at least I got it out there.

Originally Sent on Twitter, May 24, 2022 @ 9:31 PM CDT


I might add to this if I feel like it, but who knows 👀


Update 2022/06/07 - The East High School Shooting occurred on March 7, not March 8