-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UpdateHint: create_if_not_exists (Allows clients to hint own items in other worlds) #4316
Changes from 4 commits
d4466f6
e283910
48782d1
b53f9ae
c987da3
925e5da
9201439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1903,32 +1903,90 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): | |
|
||
elif cmd == 'UpdateHint': | ||
location = args["location"] | ||
player = args["player"] | ||
status = args["status"] | ||
if not isinstance(player, int) or not isinstance(location, int) \ | ||
or (status is not None and not isinstance(status, int)): | ||
location_player = args["player"] | ||
create_if_not_exists = args.get("create_if_not_exists", False) | ||
status_int = args.get("status") | ||
|
||
if not isinstance(location_player, int) or not isinstance(location, int) \ | ||
or (status_int is not None and not isinstance(status_int, int)): | ||
await ctx.send_msgs(client, | ||
[{'cmd': 'InvalidPacket', "type": "arguments", "text": 'UpdateHint', | ||
"original_cmd": cmd}]) | ||
return | ||
hint = ctx.get_hint(client.team, player, location) | ||
if not hint: | ||
return # Ignored safely | ||
if hint.receiving_player != client.slot: | ||
await ctx.send_msgs(client, | ||
[{'cmd': 'InvalidPacket', "type": "arguments", "text": 'UpdateHint: No Permission', | ||
"original_cmd": cmd}]) | ||
return | ||
new_hint = hint | ||
if status is None: | ||
return | ||
|
||
hint = ctx.get_hint(client.team, location_player, location) | ||
|
||
if status_int is None: | ||
if hint is None: | ||
# New hints are created with unspecified by default | ||
status_int = HintStatus.HINT_UNSPECIFIED | ||
else: | ||
# If the hint already exists and no status was provided, there is no point to the packet | ||
return | ||
|
||
try: | ||
status = HintStatus(status) | ||
status = HintStatus(status_int) | ||
except ValueError: | ||
await ctx.send_msgs(client, | ||
[{'cmd': 'InvalidPacket', "type": "arguments", | ||
"text": 'UpdateHint: Invalid Status', "original_cmd": cmd}]) | ||
return | ||
|
||
if hint is None: | ||
if not create_if_not_exists: | ||
await ctx.send_msgs(client, | ||
[{ | ||
"cmd": "InvalidPacket", | ||
"type": "arguments", | ||
"text": 'UpdateHint: Desired hint does not already exist. ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would remove |
||
'Use with create_if_not_exists = True if the hint should be created.', | ||
"original_cmd": cmd | ||
}], | ||
) | ||
return | ||
|
||
# UpdateHint can be used as an "Upsert", creating a new hint. | ||
# The newly created hint must either be for a location in the requesting slot's world, | ||
# or a location containing an item for the requesting slot (including item links). | ||
|
||
target_item, item_player, flags = ctx.locations[location_player][location] | ||
|
||
if client.slot not in ctx.slot_set(item_player): | ||
if status != HintStatus.HINT_UNSPECIFIED: | ||
await ctx.send_msgs( | ||
client, | ||
[{ | ||
"cmd": "InvalidPacket", | ||
"type": "arguments", | ||
"text": 'UpdateHint: Must use "unspecified"/None status for items for other players.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"original_cmd": cmd | ||
}], | ||
) | ||
return | ||
|
||
if client.slot != location_player: | ||
await ctx.send_msgs( | ||
client, | ||
[{ | ||
"cmd": "InvalidPacket", | ||
"type": "arguments", | ||
"text": "UpdateHint: No Permission", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"original_cmd": cmd | ||
}], | ||
) | ||
return | ||
|
||
new_hint = collect_hint_location_id(ctx, client.team, location_player, location, status) | ||
ctx.notify_hints(client.team, new_hint) | ||
ctx.save() | ||
return | ||
|
||
if hint.receiving_player != client.slot: | ||
await ctx.send_msgs(client, | ||
[{'cmd': 'InvalidPacket', "type": "arguments", "text": 'UpdateHint: No Permission', | ||
"original_cmd": cmd}]) | ||
return | ||
new_hint = hint | ||
new_hint = new_hint.re_prioritize(ctx, status) | ||
if hint == new_hint: | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the try/catch for
status = HintStatus(status_int)
above thehint = ctx.get_hint(client.team, location_player, location)
as it breaks the flow that there is a check for if hint is None right below it