2020-09-06 21:39:21 +00:00
|
|
|
from flask import Flask
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2020-09-06 22:10:00 +00:00
|
|
|
USERNAME = ''
|
|
|
|
PASSWORD = ''
|
|
|
|
SERVER = ''
|
|
|
|
|
2020-09-06 22:43:20 +00:00
|
|
|
from custom.managers import DataManager, ChunksManager, ChatManager
|
2020-09-06 22:10:00 +00:00
|
|
|
|
|
|
|
from minecraft import authentication
|
|
|
|
from minecraft.exceptions import YggdrasilError
|
|
|
|
from minecraft.networking.connection import Connection
|
|
|
|
from minecraft.networking.packets import Packet, clientbound, serverbound
|
|
|
|
|
2020-09-06 21:39:21 +00:00
|
|
|
@app.route('/')
|
|
|
|
def hello_world():
|
|
|
|
return 'Hello, World!'
|
|
|
|
|
2020-09-06 22:10:00 +00:00
|
|
|
def main():
|
|
|
|
mcdata = DataManager('./mcdata')
|
|
|
|
|
|
|
|
auth_token = authentication.AuthenticationToken()
|
|
|
|
try:
|
|
|
|
auth_token.authenticate(USERNAME, PASSWORD)
|
|
|
|
except YggdrasilError as e:
|
|
|
|
print(e)
|
|
|
|
sys.exit()
|
|
|
|
print("Logged in as %s..." % auth_token.username)
|
|
|
|
connection = Connection(
|
|
|
|
SERVER, 25565, auth_token=auth_token)
|
|
|
|
|
|
|
|
def handle_join_game(join_game_packet):
|
|
|
|
print('Connected.')
|
|
|
|
|
|
|
|
connection.register_packet_listener(
|
|
|
|
handle_join_game, clientbound.play.JoinGamePacket)
|
|
|
|
|
|
|
|
chunks = ChunksManager(mcdata)
|
|
|
|
chunks.register(connection)
|
|
|
|
|
2020-09-06 22:43:20 +00:00
|
|
|
chat = ChatManager()
|
|
|
|
chat.register(connection)
|
|
|
|
|
2020-09-06 22:10:00 +00:00
|
|
|
connection.connect()
|
|
|
|
|
|
|
|
print('connected')
|
|
|
|
|
|
|
|
app.run()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|