Record pathfinding context on flying disconnects
This commit is contained in:
1 parent
0b462f4a76
commit
d4eae5ee5f
5 files changed
+141
-2
No files matched your search
+44
-2
@@ -4,10 +4,12 @@ Run with SERVER=... PLAYER_NAME=mosfet1 GAME_PASSWORD=... python -m mosfet.conne
|
||||
"""
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
from minecraft.networking.connection import Connection
|
||||
from minecraft.networking.modern import (
|
||||
CancelPostjoinDialog, ChatCommand, PlayGameEventPacket, PlayShowDialog,
|
||||
PlayLogin, SubmitPostjoinLoginDialog, SystemChat, TeleportPosition,
|
||||
CancelPostjoinDialog, ChatCommand, PlayDisconnect, PlayGameEventPacket,
|
||||
PlayShowDialog, PlayLogin, SubmitPostjoinLoginDialog, SystemChat,
|
||||
TeleportPosition,
|
||||
)
|
||||
from mosfet.chat_log import append_chat_event
|
||||
from mosfet.protocol.managers import WorldState
|
||||
@@ -99,6 +101,41 @@ def _system_chat_log_entry(message):
|
||||
return 'system', None, message
|
||||
|
||||
|
||||
def _log_flying_pathfinding(global_state, packet):
|
||||
reason = component_text(getattr(packet, 'reason', None))
|
||||
if ('multiplayer.disconnect.flying' not in reason and
|
||||
'flying' not in reason.lower()):
|
||||
return
|
||||
|
||||
now = time.monotonic()
|
||||
print('[pathfinding] flying disconnect diagnostics:', reason, flush=True)
|
||||
active = global_state.get('pathfinding_active', {})
|
||||
for search in sorted(active.values(),
|
||||
key=lambda item: item.get('started_at', now)):
|
||||
elapsed = max(0.0, now - search.get('started_at', now))
|
||||
print('[pathfinding] active for {:.3f}s (budget {:.3f}s): '
|
||||
'{} -> {} on {}'.format(
|
||||
elapsed, search.get('timeout', 0.0),
|
||||
search.get('start'), search.get('goal'),
|
||||
search.get('thread', 'unknown')), flush=True)
|
||||
|
||||
history = global_state.get('pathfinding_history', ())
|
||||
recent = [search for search in history
|
||||
if now - search.get('finished_at', now) <= 10.0]
|
||||
for search in recent[-5:]:
|
||||
age = max(0.0, now - search.get('finished_at', now))
|
||||
print('[pathfinding] {} {:.3f}s, finished {:.3f}s before kick: '
|
||||
'{} -> {} (budget {:.3f}s, {})'.format(
|
||||
search.get('status', 'unknown'),
|
||||
search.get('duration', 0.0), age,
|
||||
search.get('start'), search.get('goal'),
|
||||
search.get('timeout', 0.0),
|
||||
search.get('thread', 'unknown')), flush=True)
|
||||
if not active and not recent:
|
||||
print('[pathfinding] no A* search active or completed in the '
|
||||
'10s before the kick', flush=True)
|
||||
|
||||
|
||||
def main(global_state=None, *, server=None, port=None, username=None,
|
||||
password=None):
|
||||
server = server or os.environ.get('SERVER', '127.0.0.1')
|
||||
@@ -225,6 +262,11 @@ def main(global_state=None, *, server=None, port=None, username=None,
|
||||
'authenticate', 'authentication required')):
|
||||
send_auth_command('login')
|
||||
|
||||
@connection.listener(PlayDisconnect)
|
||||
def on_play_disconnect(packet):
|
||||
if global_state is not None:
|
||||
_log_flying_pathfinding(global_state, packet)
|
||||
|
||||
connection.connect()
|
||||
print('Connected as {} to {}:{} using offline protocol 777.'.format(
|
||||
username, server, port), flush=True)
|
||||
|
||||
Reference in new issue
Block a user