Day 1 - Minetest Code
While waiting in the car for some stuff I had the laptop but couldn’t get online to look at the Minetest modding book. So I spent some time look at the Minetest code itself.
Finding the entry point
So my idea is that I need to create a new command for the server to send to clients. So I’m looking for the place where such commands are implemented. Finding that place I can look at what is required to add new stuff.
I quickly found main and then tracked that through…
No I didn’t. Looking at main first is generally the least useful thing when looking to modify a code base. Almost nothing should be happening there, what is should be quite well established and far removed from any sort of feature other than “start this program”. It’s an entry point, not a place to do everything.
I looked in src/client for something that might seem like the place where the client might get its commands. This also turned out to be pretty fruitless. Nothing in there seems right.
Eventually I ended up in src/network and found clientopcodes and serveropcodes files. Inside of them I find tables like so:
const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{
null_command_handler, // 0x00 (never use this)
null_command_handler, // 0x01
{ "TOCLIENT_HELLO", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_Hello }, // 0x02
{ "TOCLIENT_AUTH_ACCEPT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AuthAccept }, // 0x03
{ "TOCLIENT_ACCEPT_SUDO_MODE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_AcceptSudoMode}, // 0x04
{ "TOCLIENT_DENY_SUDO_MODE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DenySudoMode}, // 0x05
null_command_handler, // 0x06
null_command_handler, // 0x07
null_command_handler, // 0x08
null_command_handler, // 0x09
{ "TOCLIENT_ACCESS_DENIED", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AccessDenied }, // 0x0A
null_command_handler, // 0x0B
// ...
This is clearly a dispatch table. This is going to be the thing I need to alter in order to get my new command injected into the protocol. Next is to understand what’s going on here.
Unit testing
Next step was figuring out how to unit test. Skipping way ahead in the book from where I was (nodes) to unit testing I learn about busted. This turns out to be a de-facto standard in the Lua community. There are others, but they mostly seem to follow the same standard.
I was not familiar with the describe/it but it seemed to ring a bell. Looking further I find that I was right in my inkling that it was BDD related as it turns out that’s exactly what approach to testing is. But then, where is the ‘given’, ‘when’, ‘then’ that I am familiar with?
So I run to DuckDuckGo and look at the wiki page first. There I find that it’s an alternative approach to BDD, or perhaps to be better thought of as responding to different levels–an analysis I may do later as this seems usefull.
I followed that information to RSpec. This would seem to be what given/when/then is to Cucumber.
I think I get it. It doesn’t seem like a huge leap from one to the other. This is getting interesting.