Rename to mosfet.py, delete linux bash scripts
This commit is contained in:
+30
-2
@@ -6,7 +6,7 @@ import os
|
||||
from minecraft.networking.connection import Connection
|
||||
from minecraft.networking.modern import (
|
||||
CancelPostjoinDialog, ChatCommand, PlayShowDialog,
|
||||
SubmitPostjoinLoginDialog, SystemChat, TeleportPosition,
|
||||
PlayLogin, SubmitPostjoinLoginDialog, SystemChat, TeleportPosition,
|
||||
)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ def component_text(value):
|
||||
return str(value)
|
||||
|
||||
|
||||
def main():
|
||||
def main(global_state=None):
|
||||
server = os.environ.get('SERVER', 'games.protospace.ca')
|
||||
port = int(os.environ.get('PORT', '25565'))
|
||||
username = os.environ.get('PLAYER_NAME', 'mosfet1')
|
||||
@@ -48,6 +48,19 @@ def main():
|
||||
allowed_versions=['26.3'])
|
||||
connection.authme_password = password
|
||||
sent_auth_commands = set()
|
||||
if global_state is not None:
|
||||
global_state.connection = connection
|
||||
global_state.name = username
|
||||
global_state.connected = False
|
||||
global_state.connection_status = 'connecting'
|
||||
global_state.player_position = None
|
||||
|
||||
@connection.listener(PlayLogin)
|
||||
def on_play_login(packet):
|
||||
if global_state is not None:
|
||||
global_state.connected = True
|
||||
global_state.connection_status = 'in_game'
|
||||
|
||||
|
||||
def send_auth_command(action):
|
||||
if action in sent_auth_commands:
|
||||
@@ -61,6 +74,8 @@ def main():
|
||||
|
||||
@connection.listener(TeleportPosition)
|
||||
def on_spawn(packet):
|
||||
if global_state is not None:
|
||||
global_state.player_position = (packet.x, packet.y, packet.z)
|
||||
if getattr(connection, 'authme_mode', 'register') == 'register':
|
||||
send_auth_command('register')
|
||||
|
||||
@@ -79,6 +94,8 @@ def main():
|
||||
@connection.listener(SystemChat)
|
||||
def on_system_chat(packet):
|
||||
message = component_text(packet.content)
|
||||
if global_state is not None:
|
||||
global_state.last_chat = message
|
||||
print('[server] ' + message, flush=True)
|
||||
lowered = message.lower()
|
||||
if 'already registered' in lowered:
|
||||
@@ -96,16 +113,27 @@ def main():
|
||||
username, server, port), flush=True)
|
||||
try:
|
||||
while connection.connected:
|
||||
if global_state is not None and not global_state.get('running', True):
|
||||
break
|
||||
thread = connection.networking_thread
|
||||
if thread is None:
|
||||
break
|
||||
thread.join(timeout=0.5)
|
||||
if connection.connected:
|
||||
connection.disconnect()
|
||||
if connection.exception:
|
||||
raise connection.exception
|
||||
print('Connection ended.', flush=True)
|
||||
except KeyboardInterrupt:
|
||||
print('Disconnecting...', flush=True)
|
||||
connection.disconnect()
|
||||
finally:
|
||||
if connection.connected:
|
||||
connection.disconnect()
|
||||
if global_state is not None:
|
||||
global_state.connection = False
|
||||
global_state.connected = False
|
||||
global_state.connection_status = 'disconnected'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user