minetest servers CLI search tool

Post Reply
erlehmann
Member
Posts: 62
Joined: Mon Jan 31, 2022 00:41
GitHub: erlehmann
IRC: erlehmann

minetest servers CLI search tool

by erlehmann » Post

The tool is called minetest-servers and is written in Python 3.
Given no argument, it outputs an annoying licensing & usage text.

Code: Select all

; minetest-servers
minetest-servers – output info about minetest servers

Copyright © 2021-2022  Nils Dagsson Moskopp (erlehmann)
License AGPLv3+: GNU AGPL version 3 or later<https://gnu.org/licenses/agpl.html>
This is free software: feel free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

No argument given. Valid arguments:
	address can_see_far_names clients clients_list clients_max clients_top creative damage dedicated description game_time gameid geo_continent ip lag mapgen mods name password ping pop_v port privs proto proto_max proto_min pvp rollback server_id start total_clients update_time updates uptime url version

Given an argument, the tool outputs tab-separated-lines with two fields:
The first field is the server hostname & the second is the value queried.

Code: Select all

; minetest-servers clients |head
jt2.intraversal.net:30002	19
your-land.de:30000	15
server.minetest.one:30001	15
ugxaero.dynu.net:33151	10
ctf.rubenwardy.com:30001	8
edgy1.net:30025	37
skyblock.telesight.nl:30011	7
linux-forks.de:30000	6
80.240.216.69:30002	6
joesworld.zapto.org:30001	5
In case of a list value, there can be multiple lines for the same hostname.

Code: Select all

; minetest-servers clients_list |head
jt2.intraversal.net:30002	Minear105
jt2.intraversal.net:30002	paul
jt2.intraversal.net:30002	why
jt2.intraversal.net:30002	ojvkh
jt2.intraversal.net:30002	Stalma0
jt2.intraversal.net:30002	Mclaen386
jt2.intraversal.net:30002	TUGA
jt2.intraversal.net:30002	CRIATIAN
jt2.intraversal.net:30002	Guitard484
jt2.intraversal.net:30002	kdj
This structure makes it possible to filter results easily.

You can find where another user plays right now:

Code: Select all

; minetest-servers clients_list |grep paul
jt2.intraversal.net:30002	paul
You can find out how many servers use a particular mod:

Code: Select all

; minetest-servers mods |cut -f2 |grep -c '^doors$'
128
In case you feel lonely, you can even find a dating server:

Code: Select all

; minetest-servers description |grep -i dating
oy.edgy1.net:30420	Mineclonia anarchy server: dating hack greef kill ok. No moderation. No rules except don't mess with server operation.  Discord: https://discord.gg/pwgbUdH9Fp IRC: #oysterity on irc.libera.chat. This is the spiritual successor of Clamity anarchy.
Here is the full code of the program – save it as minetest-servers
and then make it executable using

Code: Select all

chmod a+x minetest-servers
.

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# minetest-servers – output info about minetest servers
# Copyright © 2021-2022  Nils Dagsson Moskopp (erlehmann)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# Dieses Programm hat das Ziel, die Medienkompetenz der Leser zu
# steigern. Gelegentlich packe ich sogar einen handfesten Buffer
# Overflow oder eine Format String Vulnerability zwischen die anderen
# Codezeilen und schreibe das auch nicht dran.

from requests import get
from sys import argv, exit, stdout, stderr


w = stderr.write


def print_usage():
    w('minetest-servers – output info about minetest servers\n')
    w('\n')
    w('Copyright © 2021-2022  Nils Dagsson Moskopp (erlehmann)\n')
    w('License AGPLv3+: GNU AGPL version 3 or later')
    w('<https://gnu.org/licenses/agpl.html>\n')
    w('This is free software: feel free to change and redistribute it.\n')
    w('There is NO WARRANTY, to the extent permitted by law.\n')
    w('\n')


def print_sorted_keys(possible_keys):
    w("\t%s\n" % " ".join(sorted(possible_keys)))


def get_servers():
    response = get("https://servers.minetest.net/list")
    payload = response.json()
    return payload["list"]


def get_keys(servers):
    return set(
        [
            item
            for sublist
            in [
                list(dict_keys)
                for dict_keys
                in [
                    server.keys()
                    for server
                    in servers
                ]
            ]
            for item
            in sublist
        ]
    )


def output(server, value):
    try:
        stdout.write(
            '%s:%s\t%s\n' % (
                server['address'],
                server['port'],
                value,
            )
        )
    except BrokenPipeError:
        exit(0)


if __name__ == '__main__':
    try:
        key = argv[1]
    except IndexError:
        print_usage()
        servers = get_servers()
        possible_keys = get_keys(servers)
        w('No argument given. Valid arguments:\n')
        print_sorted_keys(possible_keys)
        exit(1)

    servers = get_servers()
    possible_keys = get_keys(servers)
    if key not in possible_keys:
        print_usage()
        w("Argument “%s” is not valid. Valid arguments:\n" % key)
        print_sorted_keys(possible_keys)
        exit(2)

    # suppress interpreter output about ignored exception
    # see <https://bugs.python.org/issue11380,#msg153320>
    stderr.close()

    for server in servers:
        try:
            value = server[key]
        except KeyError:
            continue
        if type(value) == list:
            for element in value:
                output(server, element)
        else:
            output(server, value)
cdb_b9da8bbc6338

ronoaldo
Member
Posts: 177
Joined: Mon Dec 07, 2020 01:04
GitHub: ronoaldo
IRC: ronoaldo
In-game: RonoaldoKakashi
Location: São Paulo, Brasil
Contact:

Re: minetest servers CLI search tool

by ronoaldo » Post

Nice one! First time I see the power or Lispython :D

Code: Select all

def get_keys(servers):
    return set(
        [
            item
            for sublist
            in [
                list(dict_keys)
                for dict_keys
                in [
                    server.keys()
                    for server
                    in servers
                ]
            ]
            for item
            in sublist
        ]
    )
Servers: Mercurio | Tools: ContentDB CLI | Mods: minenews

User avatar
Festus1965
Member
Posts: 4181
Joined: Sun Jan 03, 2016 11:58
GitHub: Festus1965
In-game: Festus1965 Thomas Thailand Explorer
Location: Thailand ChiangMai
Contact:

Re: minetest servers CLI search tool

by Festus1965 » Post

mhh should I consider, server admin LinuxForks.de as on the right way to anonymize his gamer ?
And I also got some steps to that point ...

just funny you used paul ...
copied it, before maybe get forbidden ... but your are right, easy to use the list for

as even I told last that it is easy to generate a gamer profile as of what server play and what time out of this

thanks to proof my ... thoughts
Human has no future (climate change)
If urgend, you find me in Roblox (as CNXThomas)

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests