Minetest Debug Parsing

     I've been playing Minetest on a certain server, and have been watching things through the IRC quite a bit, and I've noticed multiple times while just watching the IRC that people are talking about being griefed so I thought to myself, there must be a way to create a little script that can run through the logs and detect bad behavior. I'm no expert when it comes to the command line and bash, but I bashed a little something together, (pun intended) and created a working script.


cd $(dirname $0)

TIME=$(date "+%y-%m-%d")

grep 'ACTION\[Server\]: CHAT:' debug.txt | sed 's/ACTION\[Server\]\: CHAT\: //g' > chat_$TIME.txt
grep 'invoked /giveme' debug.txt  | sed 's/ACTION\[Server\]\: //g' > give_$TIME.txt
egrep -i 'bad|words|separated|by|pipes' chat_$TIME.txt > bad_$TIME.txt

Be sure and escape any special characters that could be interpreted as commands in the grep and sed commands.

     This script can be copied and pasted in to a file in the minetest directory, and then made executable. Then to simplify things even more you can add it to your crontab and have it run whenever you want. The beauty of this system is that you don't have to do anything, other than set it up, and then scan through the outputs. Currently the script runs through the debug.txt and saves a file with all the chat messages, and a file with all the giveme commands that were used. Helpful if you have an admin you think might be cheating the system, or somebody that somehow is using a hacked client or has privs they shouldn't. The last line looks for specific words being used in the chat, this could be used for anything, for example if you have a rule about not talking about the server on the server you put put the server name and the word server with pipes separating them and get a file with every time somebody used those words.
     I have the files set up to have the date trailing behind the file name, that's what the $TIME does, in a year-month-day format, of course you can modify it to your liking. The options here are endless, you could parse for any attempted digging or placing in protected areas, check for griefing by seeing if anybody placed water or lava, though you'd want to manually check those out, because there can be good reasons for placing both of those.
     This system does have one problem, and that is that it parses the entire debug file every time it runs, now you could delete the debug file after the script runs, but you'd have to make sure that Minetest wasn't running when you do that, so you'd have to have this set up to run when the server restarts, which might not be a big deal as long as the server restart is something that is constant. If it isn't you'd have to implement this into the restart script. If you don't want to delete the debug, and there is good reason not to, if you do find something that looks bad in any of your output files you can go and look at the entire debug log to see exactly what was going on. I would recommend adding a line like this.
mv debug.txt debug_$TIME.txt
which will just rename the debug file to debug_year-month-day. There is probably some script that could also be written to purge any file older than x amount of days, because that information is all saved right in the file names, but I haven't explored that at all, as I don't have a sever, and did this as more of a proof of concept than because of any actual need I had.

Add new comment