Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

7 changed files with 13 additions and 31 deletions

1
depends.txt Normal file
View File

@ -0,0 +1 @@
default?

1
description.txt Normal file
View File

@ -0,0 +1 @@
Adds a server-wide commodities (item) exchange.

View File

@ -1066,13 +1066,13 @@ function ex_methods.sell(self, p_name, ex_name, item_name, wear, amount, rate)
local red_del_stmt local red_del_stmt
if row_sold < row_amount then if row_sold < row_amount and not out_of_funds then
red_stmt:bind_names({ red_stmt:bind_names({
id = row.Id, id = row.Id,
delta = row_sold, delta = row_sold,
}) })
red_del_stmt = red_stmt red_del_stmt = red_stmt
else else -- row_sold == row_amount or out_of_funds
del_stmt:bind_values(row.Id) del_stmt:bind_values(row.Id)
red_del_stmt = del_stmt red_del_stmt = del_stmt
end end

View File

@ -135,26 +135,12 @@ minetest.after(0, function()
pagemax = math.max(math.ceil(#selectable_list / pageitems), 1) pagemax = math.max(math.ceil(#selectable_list / pageitems), 1)
end) end)
local function filter_list(p_name, filter) local function filter_list(filter)
local filtered_list = {} local filtered_list = {}
if not filter or filter == "" then return nil, pagemax end if not filter or filter == "" then return nil, pagemax end
-- search by translated language
local player_info = minetest.get_player_information(p_name)
local lang = player_info and player_info.lang_code or ""
local can_translate = minetest.get_translated_string and lang ~= ""
for index, name in ipairs(selectable_list) do for index, name in ipairs(selectable_list) do
local match = string.find(name, filter) -- search in name local match = string.match(name, filter) or nil
if not match then -- si not found, search in description and translated description ie:(filter="pomme", description="pomme d'or" )
local def = minetest.registered_items[name]
if def and def.description and def.description ~= "" then
if string.find(string.lower(def.description), filter) or
can_translate and string.find(string.lower(minetest.get_translated_string(lang, def.description)), filter) then
match = true
end
end
end
if match then if match then
filtered_list[#filtered_list+1] = name filtered_list[#filtered_list+1] = name
end end
@ -473,14 +459,14 @@ local function handle_main(player, fields)
end end
if fields.filter then if fields.filter then
state.filtered_list, state.buy_pagemax = filter_list(p_name, string.lower(minetest.formspec_escape(state.buy_filter))) state.filtered_list, state.buy_pagemax = filter_list(state.buy_filter)
state.buy_page = 1 state.buy_page = 1
show_main(p_name) show_main(p_name)
end end
if fields.reset_filter then if fields.reset_filter then
state.buy_filter = "" state.buy_filter = ""
state.filtered_list, state.buy_pagemax = filter_list(p_name, nil) state.filtered_list, state.buy_pagemax = filter_list(nil)
state.buy_page = 1 state.buy_page = 1
show_main(p_name) show_main(p_name)
end end

View File

@ -3,8 +3,6 @@ assert(insecure_env, "global_exchange needs to be trusted to run under mod secur
local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/" local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
local S = minetest.get_translator("global_exchange")
local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env). local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
open_exchange(minetest.get_worldpath() .. "/global_exchange.db") open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
@ -19,13 +17,13 @@ local function handle_setbalance_command(caller, name, newbalance)
end end
minetest.register_privilege("balance", { minetest.register_privilege("balance", {
description = S("Can use /setbalance"), description = "Can use /setbalance",
give_to_singleplayer = false give_to_singleplayer = false
}) })
minetest.register_chatcommand("setbalance", { minetest.register_chatcommand("setbalance", {
params = S("[<name>] <balance>"), params = "[<name>] <balance>",
description = S("set a player's trading balance"), description = "set a player's trading balance",
privs = {balance=true}, privs = {balance=true},
func = function(caller, param) func = function(caller, param)
local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)") local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
@ -33,7 +31,7 @@ minetest.register_chatcommand("setbalance", {
name = caller name = caller
balancestr = string.match(param, "([0-9]+)") balancestr = string.match(param, "([0-9]+)")
if not balancestr then if not balancestr then
return false, S("Invalid parameters (see /help setbalance)") return false, "Invalid parameters (see /help setbalance)"
end end
end end
return handle_setbalance_command(caller, name, tonumber(balancestr)) return handle_setbalance_command(caller, name, tonumber(balancestr))

View File

@ -21,7 +21,6 @@ No such order.=Pas un tel ordre.
Order does not exist.=L'ordre n'existe pas. Order does not exist.=L'ordre n'existe pas.
### init.lua ### ### init.lua ###
Can use /setbalance=Peut utiliser /setbalance
set a player's trading balance=définir le solde commercial d'un joueur set a player's trading balance=définir le solde commercial d'un joueur
Invalid parameters (see /help setbalance)=Paramètres invalides (voir /help setbalance) Invalid parameters (see /help setbalance)=Paramètres invalides (voir /help setbalance)

View File

@ -1,4 +1 @@
name = global_exchange name=global_exchange
title = Global Exchange
description = Adds a server-wide commodities (item) exchange.
optional_depends = default