update rom name handling
This commit is contained in:
parent
ead9a0ef15
commit
ea9e103cb0
7
Main.py
7
Main.py
|
@ -19,7 +19,7 @@ from Dungeons import create_dungeons, fill_dungeons, fill_dungeons_restrictive
|
|||
from Fill import distribute_items_cutoff, distribute_items_staleness, distribute_items_restrictive, flood_items, \
|
||||
balance_multiworld_progression
|
||||
from ItemList import generate_itempool, difficulties, fill_prizes
|
||||
from Utils import output_path, parse_player_names, get_options, __version__
|
||||
from Utils import output_path, parse_player_names, get_options, __version__, _version_tuple
|
||||
import Patch
|
||||
|
||||
seeddigits = 20
|
||||
|
@ -228,7 +228,7 @@ def main(args, seed=None):
|
|||
rom.write_to_file(rompath)
|
||||
if args.create_diff:
|
||||
Patch.create_patch_file(rompath)
|
||||
return (player, team, list(rom.name))
|
||||
return player, team, bytes(rom.name).decode()
|
||||
|
||||
if not args.suppress_rom:
|
||||
import concurrent.futures
|
||||
|
@ -273,7 +273,8 @@ def main(args, seed=None):
|
|||
type(location.address) is int],
|
||||
"server_options": get_options()["server_options"],
|
||||
"er_hint_data": er_hint_data,
|
||||
"precollected_items": precollected_items
|
||||
"precollected_items": precollected_items,
|
||||
"version": _version_tuple
|
||||
}).encode("utf-8"), 9)
|
||||
|
||||
with open(output_path('%s.multidata' % outfilebase), 'wb') as f:
|
||||
|
|
|
@ -800,7 +800,7 @@ async def process_server_cmd(ctx: Context, cmd, args):
|
|||
'Invalid ROM detected, please verify that you have loaded the correct rom and reconnect your snes (/snes)')
|
||||
if 'SlotAlreadyTaken' in args:
|
||||
Utils.persistent_store("servers", "default", ctx.server_address)
|
||||
Utils.persistent_store("servers", "".join(chr(x) for x in ctx.rom), ctx.server_address)
|
||||
Utils.persistent_store("servers", ctx.rom, ctx.server_address)
|
||||
raise Exception('Player slot already in use for that team')
|
||||
if 'IncompatibleVersion' in args:
|
||||
raise Exception('Server reported your client version as incompatible')
|
||||
|
@ -808,7 +808,7 @@ async def process_server_cmd(ctx: Context, cmd, args):
|
|||
|
||||
elif cmd == 'Connected':
|
||||
Utils.persistent_store("servers", "default", ctx.server_address)
|
||||
Utils.persistent_store("servers", "".join(chr(x) for x in ctx.rom), ctx.server_address)
|
||||
Utils.persistent_store("servers", ctx.rom, ctx.server_address)
|
||||
ctx.team, ctx.slot = args[0]
|
||||
ctx.player_names = {p: n for p, n in args[1]}
|
||||
msgs = []
|
||||
|
@ -922,7 +922,7 @@ async def server_auth(ctx: Context, password_requested):
|
|||
ctx.ui_node.log_info('No ROM detected, awaiting snes connection to authenticate to the multiworld server (/snes)')
|
||||
return
|
||||
ctx.awaiting_rom = False
|
||||
ctx.auth = ctx.rom.copy()
|
||||
ctx.auth = ctx.rom if ctx.server_version > (2, 4, 0) else list(bytes(ctx.rom))
|
||||
await ctx.send_msgs([['Connect', {
|
||||
'password': ctx.password, 'rom': ctx.auth, 'version': Utils._version_tuple, 'tags': get_tags(ctx),
|
||||
'uuid': Utils.get_unique_identifier()
|
||||
|
@ -1147,11 +1147,11 @@ async def game_watcher(ctx : Context):
|
|||
if rom is None or rom == bytes([0] * ROMNAME_SIZE):
|
||||
continue
|
||||
|
||||
ctx.rom = list(rom)
|
||||
ctx.rom = rom.decode()
|
||||
if not ctx.prev_rom or ctx.prev_rom != ctx.rom:
|
||||
ctx.locations_checked = set()
|
||||
ctx.locations_scouted = set()
|
||||
ctx.prev_rom = ctx.rom.copy()
|
||||
ctx.prev_rom = ctx.rom
|
||||
|
||||
if ctx.awaiting_rom:
|
||||
await server_auth(ctx, False)
|
||||
|
|
|
@ -111,7 +111,12 @@ class Context(Node):
|
|||
for team, names in enumerate(jsonobj['names']):
|
||||
for player, name in enumerate(names, 1):
|
||||
self.player_names[(team, player)] = name
|
||||
self.rom_names = {tuple(rom): (team, slot) for slot, team, rom in jsonobj['roms']}
|
||||
version = jsonobj.get("version", [1, 0, 0])
|
||||
if version > [2, 4, 0]:
|
||||
self.rom_names = {rom: (team, slot) for slot, team, rom in jsonobj['roms']}
|
||||
else:
|
||||
self.rom_names = {bytes(letter for letter in rom).decode(): (team, slot) for slot, team, rom in
|
||||
jsonobj['roms']}
|
||||
self.remote_items = set(jsonobj['remote_items'])
|
||||
self.locations = {tuple(k): tuple(v) for k, v in jsonobj['locations']}
|
||||
if "er_hint_data" in jsonobj:
|
||||
|
@ -206,8 +211,12 @@ class Context(Node):
|
|||
def set_save(self, savedata: dict):
|
||||
rom_names = savedata["rom_names"]
|
||||
received_items = {tuple(k): [ReceivedItem(*i) for i in v] for k, v in savedata["received_items"]}
|
||||
if not all([self.rom_names[tuple(rom)] == (team, slot) for rom, (team, slot) in rom_names]):
|
||||
raise Exception('Save file mismatch, will start a new game')
|
||||
|
||||
if rom_names != self.rom_names:
|
||||
adjusted = {rom: (team, slot) for (rom, (team, slot)) in rom_names}
|
||||
if self.rom_names != adjusted:
|
||||
raise Exception('Save file mismatch, will start a new game')
|
||||
|
||||
self.received_items = received_items
|
||||
self.hints_used.update({tuple(key): value for key, value in savedata["hints_used"]})
|
||||
if "hints" in savedata:
|
||||
|
@ -870,18 +879,20 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args):
|
|||
if cmd == 'Connect':
|
||||
if not args or type(args) is not dict or \
|
||||
'password' not in args or type(args['password']) not in [str, type(None)] or \
|
||||
'rom' not in args or type(args['rom']) is not list:
|
||||
'rom' not in args or type(args['rom']) not in (list, str):
|
||||
await ctx.send_msgs(client, [['InvalidArguments', 'Connect']])
|
||||
return
|
||||
|
||||
errors = set()
|
||||
if ctx.password is not None and args['password'] != ctx.password:
|
||||
errors.add('InvalidPassword')
|
||||
if type(args["rom"]) == list:
|
||||
args["rom"] = bytes(letter for letter in args["rom"]).decode()
|
||||
|
||||
if tuple(args['rom']) not in ctx.rom_names:
|
||||
if args['rom'] not in ctx.rom_names:
|
||||
errors.add('InvalidRom')
|
||||
else:
|
||||
team, slot = ctx.rom_names[tuple(args['rom'])]
|
||||
team, slot = ctx.rom_names[args['rom']]
|
||||
# this can only ever be 0 or 1 elements
|
||||
clients = [c for c in ctx.endpoints if c.auth and c.slot == slot and c.team == team]
|
||||
if clients:
|
||||
|
|
2
Rom.py
2
Rom.py
|
@ -1282,7 +1282,7 @@ def patch_rom(world, rom, player, team, enemized):
|
|||
# set rom name
|
||||
# 21 bytes
|
||||
from Main import __version__
|
||||
rom.name = bytearray(f'ER{__version__.split("-")[0].replace(".","")[0:3]}_{team+1}_{player}_{world.seed:09}\0', 'utf8')[:21]
|
||||
rom.name = bytearray(f'BM{__version__.replace(".", "")[0:3]}_{team + 1}_{player}_{world.seed:09}\0', 'utf8')[:21]
|
||||
rom.name.extend([0] * (21 - len(rom.name)))
|
||||
rom.write_bytes(0x7FC0, rom.name)
|
||||
|
||||
|
|
Loading…
Reference in New Issue