diff --git a/MultiServer.py b/MultiServer.py index b9ac9eef..a454284f 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -1466,7 +1466,13 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): elif cmd == "GetDataPackage": exclusions = args.get("exclusions", []) - if exclusions: + if "games" in args: + games = {name: game_data for name, game_data in network_data_package["games"].items() + if name in set(args.get("games", []))} + await ctx.send_msgs(client, [{"cmd": "DataPackage", + "data": {"games": games}}]) + # TODO: remove exclusions behaviour around 0.5.0 + elif exclusions: exclusions = set(exclusions) games = {name: game_data for name, game_data in network_data_package["games"].items() if name not in exclusions} @@ -1474,6 +1480,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): package["games"] = games await ctx.send_msgs(client, [{"cmd": "DataPackage", "data": package}]) + else: await ctx.send_msgs(client, [{"cmd": "DataPackage", "data": network_data_package}]) diff --git a/Utils.py b/Utils.py index a764dea9..b353e9a7 100644 --- a/Utils.py +++ b/Utils.py @@ -58,8 +58,7 @@ RetType = typing.TypeVar("RetType") def cache_argsless(function: typing.Callable[[], RetType]) -> typing.Callable[[], RetType]: - if function.__code__.co_argcount: - raise Exception("Can only cache 0 argument functions with this cache.") + assert not function.__code__.co_argcount, "Can only cache 0 argument functions with this cache." sentinel = object() result: typing.Union[object, RetType] = sentinel @@ -482,7 +481,8 @@ class VersionException(Exception): pass -def format_SI_prefix(value, power=1000, power_labels=('', 'k', 'M', 'G', 'T', "P", "E", "Z", "Y")): +# noinspection PyPep8Naming +def format_SI_prefix(value, power=1000, power_labels=('', 'k', 'M', 'G', 'T', "P", "E", "Z", "Y")) -> str: n = 0 while value > power: diff --git a/docs/network protocol.md b/docs/network protocol.md index ae93e369..48b8448d 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -305,9 +305,9 @@ Basic chat command which sends text to the server to be distributed to other cli Requests the data package from the server. Does not require client authentication. #### Arguments -| Name | Type | Notes | -| ------ | ----- | ------ | -| exclusions | list\[str\] | Optional. If specified, will not send back the specified data. Such as, \["Factorio"\] -> Datapackage without Factorio data.| +| Name | Type | Notes | +|-------| ----- |---------------------------------------------------------------------------------------------------------------------------------| +| games | list\[str\] | Optional. If specified, will only send back the specified data. Such as, \["Factorio"\] -> Datapackage with only Factorio data. | ### Bounce Send this message to the server, tell it which clients should receive the message and @@ -569,7 +569,6 @@ Note: | Name | Type | Notes | | ------ | ----- | ------ | | games | dict[str, GameData] | Mapping of all Games and their respective data | -| version | int | Sum of all per-game version numbers, for clients that don't bother with per-game caching/updating. | #### GameData GameData is a **dict** but contains these keys and values. It's broken out into another "type" for ease of documentation.