move cheating to server, with option to turn it off

also, don't overwrite multisave if the resulting object is borked
This commit is contained in:
Fabian Dill
2020-02-22 19:42:44 +01:00
parent 5c6815c1f6
commit 1fb7ed30eb
2 changed files with 31 additions and 22 deletions

View File

@@ -2,7 +2,7 @@ import argparse
import asyncio
import json
import logging
import shlex
import typing
import urllib.parse
import atexit
@@ -23,11 +23,11 @@ import Items
import Regions
import Utils
class ReceivedItem:
def __init__(self, item, location, player):
self.item = item
self.location = location
self.player = player
class ReceivedItem(typing.NamedTuple):
item: int
location: int
player: int
class Context:
def __init__(self, snes_address, server_address, password):
@@ -764,9 +764,11 @@ async def console_loop(ctx : Context):
if precommand == 'exit':
ctx.exit_event.set()
elif precommand == 'snes':
ctx.snes_reconnect_address = None
asyncio.create_task(snes_connect(ctx, command[1] if len(command) > 1 else ctx.snes_address))
elif precommand in {'snes_close', 'snes_quit'}:
ctx.snes_reconnect_address = None
if ctx.snes_socket is not None and not ctx.snes_socket.closed:
@@ -775,6 +777,7 @@ async def console_loop(ctx : Context):
elif precommand in {'connect', 'reconnect'}:
ctx.server_address = None
asyncio.create_task(connect(ctx, command[1] if len(command) > 1 else None))
elif precommand == 'disconnect':
ctx.server_address = None
asyncio.create_task(disconnect(ctx))
@@ -792,15 +795,7 @@ async def console_loop(ctx : Context):
for location in [k for k, v in Regions.location_table.items() if type(v[0]) is int]:
if location not in ctx.locations_checked:
logging.info('Missing: ' + location)
elif precommand == 'getitem' and len(command) > 1:
item = input[9:]
item_id = Items.item_table[item][3] if item in Items.item_table else None
if type(item_id) is int and item_id in range(0x100):
logging.info('Sending item: ' + item)
snes_buffered_write(ctx, RECV_ITEM_ADDR, bytes([item_id]))
snes_buffered_write(ctx, RECV_ITEM_PLAYER_ADDR, bytes([0]))
else:
logging.info('Invalid item: ' + item)
elif precommand == "license":
with open("LICENSE") as f:
logging.info(f.read())