string escaping
parent
13d3a5d305
commit
0b49973d11
20
api.lua
20
api.lua
|
@ -20,6 +20,23 @@ function x_marketplace.isnan(value)
|
||||||
return value ~= value
|
return value ~= value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function esc(x)
|
||||||
|
return (x:gsub('%%', '%%%%')
|
||||||
|
:gsub('^%^', '%%^')
|
||||||
|
:gsub('%$$', '%%$')
|
||||||
|
:gsub('%(', '%%(')
|
||||||
|
:gsub('%)', '%%)')
|
||||||
|
:gsub('%.', '%%.')
|
||||||
|
:gsub('%,', '%%,')
|
||||||
|
:gsub('%;', '%%;')
|
||||||
|
:gsub('%[', '%%[')
|
||||||
|
:gsub('%]', '%%]')
|
||||||
|
:gsub('%*', '%%*')
|
||||||
|
:gsub('%+', '%%+')
|
||||||
|
:gsub('%-', '%%-')
|
||||||
|
:gsub('%?', '%%?'))
|
||||||
|
end
|
||||||
|
|
||||||
-- rounds a number to the nearest decimal places
|
-- rounds a number to the nearest decimal places
|
||||||
local function round(val, decimal)
|
local function round(val, decimal)
|
||||||
if (decimal) then
|
if (decimal) then
|
||||||
|
@ -34,8 +51,9 @@ end
|
||||||
-- @return string with found items, if no items found returns boolean false
|
-- @return string with found items, if no items found returns boolean false
|
||||||
function x_marketplace.store_find(string)
|
function x_marketplace.store_find(string)
|
||||||
local found = ""
|
local found = ""
|
||||||
|
local str = esc(string)
|
||||||
for k, v in pairs(x_marketplace.store_list) do
|
for k, v in pairs(x_marketplace.store_list) do
|
||||||
if string.find(k, string) then
|
if string.find(k, str) then
|
||||||
found = found..k.." buy: "..string.format("%.2f", v.buy).." sell: "..string.format("%.2f", v.sell).."\n"
|
found = found..k.." buy: "..string.format("%.2f", v.buy).." sell: "..string.format("%.2f", v.sell).."\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ minetest.register_chatcommand("mp", {
|
||||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: You need to write the item name you want to find. example: /mp find default:stone. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: You need to write the item name you want to find. example: /mp find default:stone. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||||
end
|
end
|
||||||
|
|
||||||
local items = x_marketplace.store_find(minetest.formspec_escape(params[2]))
|
local items = x_marketplace.store_find(params[2])
|
||||||
|
|
||||||
if not items then
|
if not items then
|
||||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: Oops there is no item like this in the store. Check out other items in the store: ")..x_marketplace.store_get_random()
|
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: Oops there is no item like this in the store. Check out other items in the store: ")..x_marketplace.store_get_random()
|
||||||
|
@ -353,7 +353,7 @@ minetest.register_chatcommand("mp", {
|
||||||
|
|
||||||
-- item not in store
|
-- item not in store
|
||||||
if not x_marketplace.store_list[params[2]] then
|
if not x_marketplace.store_list[params[2]] then
|
||||||
local suggestions = x_marketplace.store_find(minetest.formspec_escape(params[2]))
|
local suggestions = x_marketplace.store_find(params[2])
|
||||||
|
|
||||||
-- try suggest item from store, else show random items
|
-- try suggest item from store, else show random items
|
||||||
if suggestions then
|
if suggestions then
|
||||||
|
|
Loading…
Reference in New Issue