MultiServer: check for correct game
This commit is contained in:
		
							parent
							
								
									1943586221
								
							
						
					
					
						commit
						3858a12f26
					
				
							
								
								
									
										40
									
								
								Main.py
								
								
								
								
							
							
						
						
									
										40
									
								
								Main.py
								
								
								
								
							| 
						 | 
				
			
			@ -493,8 +493,10 @@ def main(args, seed=None):
 | 
			
		|||
                rom_names.append(rom_name)
 | 
			
		||||
            client_versions = {}
 | 
			
		||||
            minimum_versions = {"server": (0, 0, 3), "clients": client_versions}
 | 
			
		||||
            games = {}
 | 
			
		||||
            for slot in world.player_ids:
 | 
			
		||||
                client_versions[slot] = (0, 0, 3)
 | 
			
		||||
                games[slot] = world.game[slot]
 | 
			
		||||
            connect_names = {base64.b64encode(rom_name).decode(): (team, slot) for
 | 
			
		||||
                              slot, team, rom_name in rom_names}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -503,24 +505,26 @@ def main(args, seed=None):
 | 
			
		|||
                    if player not in world.alttp_player_ids:
 | 
			
		||||
                        connect_names[name] = (i, player)
 | 
			
		||||
 | 
			
		||||
            multidata = zlib.compress(pickle.dumps({"names": parsed_names,
 | 
			
		||||
                                                    "connect_names": connect_names,
 | 
			
		||||
                                                    "remote_items": {player for player in range(1, world.players + 1) if
 | 
			
		||||
                                                                     world.remote_items[player] or
 | 
			
		||||
                                                                     world.game[player] != "A Link to the Past"},
 | 
			
		||||
                                                    "locations": {
 | 
			
		||||
                                                        (location.address, location.player):
 | 
			
		||||
                                                            (location.item.code, location.item.player)
 | 
			
		||||
                                                        for location in world.get_filled_locations() if
 | 
			
		||||
                                                        type(location.address) is int},
 | 
			
		||||
                                                    "checks_in_area": checks_in_area,
 | 
			
		||||
                                                    "server_options": get_options()["server_options"],
 | 
			
		||||
                                                    "er_hint_data": er_hint_data,
 | 
			
		||||
                                                    "precollected_items": precollected_items,
 | 
			
		||||
                                                    "version": tuple(_version_tuple),
 | 
			
		||||
                                                    "tags": ["AP"],
 | 
			
		||||
                                                    "minimum_versions": minimum_versions,
 | 
			
		||||
                                                    }), 9)
 | 
			
		||||
            multidata = zlib.compress(pickle.dumps({
 | 
			
		||||
                "games": games,
 | 
			
		||||
                "names": parsed_names,
 | 
			
		||||
                "connect_names": connect_names,
 | 
			
		||||
                "remote_items": {player for player in range(1, world.players + 1) if
 | 
			
		||||
                                 world.remote_items[player] or
 | 
			
		||||
                                 world.game[player] != "A Link to the Past"},
 | 
			
		||||
                "locations": {
 | 
			
		||||
                    (location.address, location.player):
 | 
			
		||||
                        (location.item.code, location.item.player)
 | 
			
		||||
                    for location in world.get_filled_locations() if
 | 
			
		||||
                    type(location.address) is int},
 | 
			
		||||
                "checks_in_area": checks_in_area,
 | 
			
		||||
                "server_options": get_options()["server_options"],
 | 
			
		||||
                "er_hint_data": er_hint_data,
 | 
			
		||||
                "precollected_items": precollected_items,
 | 
			
		||||
                "version": tuple(_version_tuple),
 | 
			
		||||
                "tags": ["AP"],
 | 
			
		||||
                "minimum_versions": minimum_versions,
 | 
			
		||||
            }), 9)
 | 
			
		||||
 | 
			
		||||
            with open(output_path('%s.archipelago' % outfilebase), 'wb') as f:
 | 
			
		||||
                f.write(bytes([1]))  # version of format
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,6 +110,7 @@ class Context(Node):
 | 
			
		|||
        self.auto_saver_thread = None
 | 
			
		||||
        self.save_dirty = False
 | 
			
		||||
        self.tags = ['AP']
 | 
			
		||||
        self.games = {}
 | 
			
		||||
        self.minimum_client_versions: typing.Dict[int, Utils.Version] = {}
 | 
			
		||||
 | 
			
		||||
    def load(self, multidatapath: str, use_embedded_server_options: bool = False):
 | 
			
		||||
| 
						 | 
				
			
			@ -127,6 +128,7 @@ class Context(Node):
 | 
			
		|||
        return restricted_loads(zlib.decompress(data[1:]))
 | 
			
		||||
 | 
			
		||||
    def _load(self, decoded_obj: dict, use_embedded_server_options: bool):
 | 
			
		||||
 | 
			
		||||
        mdata_ver = decoded_obj["minimum_versions"]["server"]
 | 
			
		||||
        if mdata_ver > Utils._version_tuple:
 | 
			
		||||
            raise RuntimeError(f"Supplied Multidata requires a server of at least version {mdata_ver},"
 | 
			
		||||
| 
						 | 
				
			
			@ -145,6 +147,7 @@ class Context(Node):
 | 
			
		|||
        self.locations = decoded_obj['locations']
 | 
			
		||||
        self.er_hint_data = {int(player): {int(address): name for address, name in loc_data.items()}
 | 
			
		||||
                             for player, loc_data in decoded_obj["er_hint_data"].items()}
 | 
			
		||||
        self.games = decoded_obj["games"]
 | 
			
		||||
        if use_embedded_server_options:
 | 
			
		||||
            server_options = decoded_obj.get("server_options", {})
 | 
			
		||||
            self._set_options(server_options)
 | 
			
		||||
| 
						 | 
				
			
			@ -976,6 +979,9 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
 | 
			
		|||
            errors.add('InvalidSlot')
 | 
			
		||||
        else:
 | 
			
		||||
            team, slot = ctx.connect_names[args['name']]
 | 
			
		||||
            game = ctx.games[slot]
 | 
			
		||||
            if args['game'] != game:
 | 
			
		||||
                errors.add('InvalidSlot')
 | 
			
		||||
            # 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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue