diff --git a/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd b/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd index 321fc1ba..6d274e53 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd @@ -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( @@ -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 diff --git a/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd b/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd index 8c11dc0c..55f04771 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd @@ -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( @@ -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]) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd index e7ecb191..88328b5f 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd @@ -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( @@ -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(