When I searched for a Minecraft library on Pypi, there was a library called Quarry, so I tried using it.
only this.
pip install quarry
From the conclusion, it works with this.
from twisted.internet import reactor
from quarry.net.server import ServerFactory, ServerProtocol
class QuarryProtocol(ServerProtocol):
def player_joined(self):
ServerProtocol.player_joined(self)
self.close("Pong!")
class QuarryFactory(ServerFactory):
protocol = QuarryProtocol
motd = "Powered by Quarry!"
def main():
factory = QuarryFactory()
factory.listen("")
reactor.run()
if __name__ == "__main__":
main()
Even if you run the script, nothing will come out, but that is the correct answer.
Now if you connect with Minecraft, you should get a disconnect message saying Pong !.
ServerFactory
A class that allows you to turn on / off the server motd and online mode (cracking countermeasure function), change the server image, and so on.
protocol
Required. Assign the `` `ServerProtocol``` class. Details will be described later.
motd
A description of the server. That is displayed in the server list.
icon_path
Specify the server icon. Sizes up to 64x64 in PNG format (should have been).
max_players
Maximum number of player connections. You have to set it to at least 1.
online_mode
Do you want to enable Mojang online authentication? If there is no particular reason, leave it as True.
ServerProtocol
This class handles processing such as when a player is connected.
There are some functions, but I will write only as much as I can understand.
-- player_joined
(replacement function)
What to do when a player comes in. If online mode is turned on, this function will be called when authentication is complete.
Also, it seems that the player_joined
function of the parent class is called.
close
Calling this function will disconnect the player. If you enter a character in the argument, that character will be displayed in the disconnection message on the player side.
If you use this library, you may be able to use it as some kind of authentication server. I think it's a pretty interesting library.
If you are interested, there seems to be a document, so please take a look there. (English)
https://quarry.readthedocs.io/en/latest/index.html
Recommended Posts