1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-09 18:39:04 +08:00

Fix: [ALAS] handle serial like 5555,16384

This commit is contained in:
LmeSzinc 2026-01-28 03:38:11 +08:00
parent f552360951
commit 912c74b8e1
2 changed files with 26 additions and 15 deletions

View File

@ -71,28 +71,39 @@ class ConnectionAttr:
self.config.DEVICE_OVER_HTTP = self.is_over_http self.config.DEVICE_OVER_HTTP = self.is_over_http
@staticmethod @staticmethod
def revise_serial(serial): def revise_serial(serial: str):
serial = serial.replace(' ', '') """
Tons of fool-proof fixes to handle manual serial input
To load a serial:
serial = SerialStr.revise_serial(serial)
"""
serial = serial.strip().replace(' ', '')
# 127。0。0。15555 # 127。0。0。15555
serial = serial.replace('', '.').replace('', '.').replace(',', '.').replace('', ':') serial = serial.replace('', '.').replace('', '.').replace(',', '.').replace('', ':')
# 127.0.0.1.5555 # 127.0.0.1.5555
serial = serial.replace('127.0.0.1.', '127.0.0.1:') serial = serial.replace('127.0.0.1.', '127.0.0.1:')
# Mumu12 5.0 shows double serials, some people may just copy-paste it # 5555,16384 (actually "5555.16384" because replace(',', '.'))
# 5555,16384 -> replaced to 5555.16384
if '.' in serial: if '.' in serial:
left, _, right = serial.partition('.') left, _, right = serial.partition('.')
if left.startswith('55') and right.startswith('16'): try:
serial = right left = int(left)
right = int(right)
if 5500 < left < 6000 and 16300 < right < 20000:
serial = str(right)
except ValueError:
pass
# 16384 # 16384
try: if serial.isdigit():
port = int(serial) try:
if 1000 < port < 65536: port = int(serial)
serial = f'127.0.0.1:{port}' if 1000 < port < 65536:
except ValueError: serial = f'127.0.0.1:{port}'
pass except ValueError:
pass
# 夜神模拟器 127.0.0.1:62001 # 夜神模拟器 127.0.0.1:62001
# MuMu模拟器12127.0.0.1:16384 # MuMu模拟器12127.0.0.1:16384
if '模拟' in serial: if '模拟' in serial:
import re
res = re.search(r'(127\.\d+\.\d+\.\d+:\d+)', serial) res = re.search(r'(127\.\d+\.\d+\.\d+:\d+)', serial)
if res: if res:
serial = res.group(1) serial = res.group(1)

View File

@ -279,19 +279,19 @@ def get_serial_pair(serial):
serial (str): serial (str):
Returns: Returns:
str, str: `127.0.0.1:5555+{X}` and `emulator-5554+{X}`, 0 <= X <= 32 tuple[Optional[str], Optional[str]]: `127.0.0.1:5555+{X}` and `emulator-5554+{X}`, 0 <= X <= 32
""" """
if serial.startswith('127.0.0.1:'): if serial.startswith('127.0.0.1:'):
try: try:
port = int(serial[10:]) port = int(serial[10:])
if 5555 <= port <= 5555 + 32: if 5555 <= port <= 5555 + 64:
return f'127.0.0.1:{port}', f'emulator-{port - 1}' return f'127.0.0.1:{port}', f'emulator-{port - 1}'
except (ValueError, IndexError): except (ValueError, IndexError):
pass pass
if serial.startswith('emulator-'): if serial.startswith('emulator-'):
try: try:
port = int(serial[9:]) port = int(serial[9:])
if 5554 <= port <= 5554 + 32: if 5554 <= port <= 5554 + 64:
return f'127.0.0.1:{port + 1}', f'emulator-{port}' return f'127.0.0.1:{port + 1}', f'emulator-{port}'
except (ValueError, IndexError): except (ValueError, IndexError):
pass pass