allow ghosted slots with same ID to be replaced
This commit is contained in:
parent
3fbb959622
commit
bd1c9f896b
|
@ -91,6 +91,7 @@ class Context(Node):
|
||||||
self.auto_shutdown = 0
|
self.auto_shutdown = 0
|
||||||
self.commandprocessor = ServerCommandProcessor(self)
|
self.commandprocessor = ServerCommandProcessor(self)
|
||||||
self.embedded_blacklist = {"host", "port"}
|
self.embedded_blacklist = {"host", "port"}
|
||||||
|
self.client_ids: typing.Dict[typing.Tuple[int, int], datetime.datetime] = {}
|
||||||
|
|
||||||
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
||||||
with open(multidatapath, 'rb') as f:
|
with open(multidatapath, 'rb') as f:
|
||||||
|
@ -815,7 +816,16 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args):
|
||||||
errors.add('InvalidRom')
|
errors.add('InvalidRom')
|
||||||
else:
|
else:
|
||||||
team, slot = ctx.rom_names[tuple(args['rom'])]
|
team, slot = ctx.rom_names[tuple(args['rom'])]
|
||||||
if any([c.slot == slot and c.team == team for c in ctx.endpoints if c.auth]):
|
# 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:
|
||||||
|
# likely same player with a "ghosted" slot. We bust the ghost.
|
||||||
|
if "uuid" in args and ctx.client_ids[team, slot] == args["uuid"]:
|
||||||
|
await clients[0].socket.close() # we have to await the DC of the ghost, so not to create data pasta
|
||||||
|
client.name = ctx.player_names[(team, slot)]
|
||||||
|
client.team = team
|
||||||
|
client.slot = slot
|
||||||
|
else:
|
||||||
errors.add('SlotAlreadyTaken')
|
errors.add('SlotAlreadyTaken')
|
||||||
else:
|
else:
|
||||||
client.name = ctx.player_names[(team, slot)]
|
client.name = ctx.player_names[(team, slot)]
|
||||||
|
@ -825,6 +835,7 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args):
|
||||||
if errors:
|
if errors:
|
||||||
await ctx.send_msgs(client, [['ConnectionRefused', list(errors)]])
|
await ctx.send_msgs(client, [['ConnectionRefused', list(errors)]])
|
||||||
else:
|
else:
|
||||||
|
ctx.client_ids[client.team, client.slot] = args.get("uuid", None)
|
||||||
client.auth = True
|
client.auth = True
|
||||||
client.version = args.get('version', Client.version)
|
client.version = args.get('version', Client.version)
|
||||||
client.tags = args.get('tags', Client.tags)
|
client.tags = args.get('tags', Client.tags)
|
||||||
|
|
Loading…
Reference in New Issue