Rename to mosfet.py, delete linux bash scripts

This commit is contained in:
Tanner
2026-11-03 20:07:47 +00:00
parent d43533bcfe
commit 891f14b988
7 changed files with 82 additions and 254 deletions
+4 -7
View File
@@ -1,5 +1,5 @@
if __name__ == '__main__':
print('Run main.py instead.')
print('Run mosfet.py instead.')
exit(1)
import os
@@ -251,11 +251,8 @@ def bot(global_state):
if not SERVER:
print()
print('You must specify a server to connect to. For example:')
print('SERVER=minecraft.example.com ./run_linux.sh')
print('SERVER=localhost PORT=12345 ./run_linux.sh')
print()
print('If you want to use your own account:')
print('EMAIL=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh')
print('SERVER=minecraft.example.com python mosfet.py')
print('SERVER=localhost PORT=12345 python mosfet.py')
os._exit(0)
elif not g.connection:
if EMAIL and PASSWORD:
@@ -274,7 +271,7 @@ def bot(global_state):
print('')
print('Did you forget to specify an email?')
print('If you want to use your own account:')
print('EMAIL=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh')
print('Set SERVER and run python mosfet.py.')
os._exit(0)
else:
print('No username or password provided, using burner minecraft account...')
+30 -2
View File
@@ -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__':