Skip to content

Commit

Permalink
fix: disallows the use of specified strings in the name argument for …
Browse files Browse the repository at this point in the history
…these commands
  • Loading branch information
BHSDuncan authored and StraToN committed Aug 24, 2022
1 parent 57f7d94 commit 5be887c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ extends ESCBaseCommand
class_name InventoryAddCommand


const ILLEGAL_STRINGS = ["/"]


# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
Expand All @@ -27,13 +30,15 @@ func validate(arguments: Array):
if not .validate(arguments):
return false

if arguments[0].begins_with("i/"):
escoria.logger.error(
self,
"[%s]: invalid item name. Item name %s cannot start with 'i/'."
% [get_command_name(), arguments[0]]
)
return false
for s in ILLEGAL_STRINGS:
if s in arguments[0]:
escoria.logger.error(
self,
"[%s]: invalid item name. Item name %s cannot contain the string '%s'."
% [get_command_name(), arguments[0], s]
)
return false

return true


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ extends ESCBaseCommand
class_name InventoryRemoveCommand


const ILLEGAL_STRINGS = ["/"]


# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
Expand All @@ -22,6 +25,23 @@ func configure() -> ESCCommandArgumentDescriptor:
)


# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
if not .validate(arguments):
return false

for s in ILLEGAL_STRINGS:
if s in arguments[0]:
escoria.logger.error(
self,
"[%s]: invalid item name. Item name %s cannot contain the string '%s'."
% [get_command_name(), arguments[0], s]
)
return false

return true


# Run the command
func run(command_params: Array) -> int:
escoria.inventory_manager.remove_item(command_params[0])
Expand Down
20 changes: 20 additions & 0 deletions addons/escoria-core/game/core-scripts/esc/commands/set_global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extends ESCBaseCommand
class_name SetGlobalCommand


const ILLEGAL_STRINGS = ["/"]


# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
Expand All @@ -25,6 +28,23 @@ func configure() -> ESCCommandArgumentDescriptor:
)


# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
if not .validate(arguments):
return false

for s in ILLEGAL_STRINGS:
if s in arguments[0]:
escoria.logger.error(
self,
"[%s]: invalid global variable. Global variable %s cannot contain the string '%s'."
% [get_command_name(), arguments[0], s]
)
return false

return true


# Run the command
func run(command_params: Array) -> int:
escoria.globals_manager.set_global(
Expand Down

0 comments on commit 5be887c

Please sign in to comment.