Skip to content

Commit fdded27

Browse files
committed
feat(api): validate state in the usage of API functions
1 parent 9a9280f commit fdded27

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lua/api.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ API.functions["start_run"] = function(args)
181181
end
182182

183183
API.functions["skip_or_select_blind"] = function(args)
184+
-- Validate current game state is appropriate for blind selection
185+
if G.STATE ~= G.STATES.BLIND_SELECT then
186+
API.send_error_response("Cannot skip or select blind when not in blind selection", { current_state = G.STATE })
187+
return
188+
end
189+
184190
local current_blind = G.GAME.blind_on_deck
185191
local blind_obj = G.blind_select_opts[string.lower(current_blind)]
186192
if args.action == "select" then
@@ -220,6 +226,12 @@ API.functions["skip_or_select_blind"] = function(args)
220226
end
221227

222228
API.functions["play_hand_or_discard"] = function(args)
229+
-- Validate current game state is appropriate for playing hand or discarding
230+
if G.STATE ~= G.STATES.SELECTING_HAND then
231+
API.send_error_response("Cannot play hand or discard when not selecting hand", { current_state = G.STATE })
232+
return
233+
end
234+
223235
if args.action == "discard" and G.GAME.current_round.discards_left == 0 then
224236
API.send_error_response(
225237
"No discards left to perform discard",

0 commit comments

Comments
 (0)