1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 17:50:37 +01:00

Updated chatlog mods : invalid commands are hidden

- From now on, invalid commands are hidden when launched, like in
  realchat.
NOTE: The update have been checked with git diff : no differencies, the
mod have never been changed by us.
This commit is contained in:
LeMagnesium 2015-01-17 22:18:52 +01:00
parent 20aa788dd6
commit 3c81d35a59

View File

@ -16,7 +16,7 @@ chatplus = {
function chatplus.init() function chatplus.init()
chatplus.load() chatplus.load()
chatplus.clean_players() chatplus.clean_players()
if not chatplus.players then if not chatplus.players then
chatplus.players = {} chatplus.players = {}
end end
@ -34,7 +34,7 @@ function chatplus.setting(name)
else else
minetest.log("[Chatplus] Setting chatplus_"..name.." not found!") minetest.log("[Chatplus] Setting chatplus_"..name.." not found!")
return nil return nil
end end
end end
function chatplus.load() function chatplus.load()
@ -45,9 +45,9 @@ function chatplus.load()
minetest.log("error","Unable to open chat plus log file: "..chatplus.log_file) minetest.log("error","Unable to open chat plus log file: "..chatplus.log_file)
else else
minetest.log("action","Logging chat plus to: "..chatplus.log_file) minetest.log("action","Logging chat plus to: "..chatplus.log_file)
end end
end end
-- Load player data -- Load player data
minetest.log("[Chatplus] Loading data") minetest.log("[Chatplus] Loading data")
local file = io.open(minetest.get_worldpath().."/chatplus.txt", "r") local file = io.open(minetest.get_worldpath().."/chatplus.txt", "r")
@ -58,12 +58,12 @@ function chatplus.load()
chatplus.players = table chatplus.players = table
return return
end end
end end
end end
function chatplus.save() function chatplus.save()
minetest.log("[Chatplus] Saving data") minetest.log("[Chatplus] Saving data")
local file = io.open(minetest.get_worldpath().."/chatplus.txt", "w") local file = io.open(minetest.get_worldpath().."/chatplus.txt", "w")
if file then if file then
file:write(minetest.serialize(chatplus.players)) file:write(minetest.serialize(chatplus.players))
@ -81,9 +81,9 @@ function chatplus.clean_players()
for key,value in pairs(chatplus.players) do for key,value in pairs(chatplus.players) do
if value.messages then if value.messages then
value.inbox = value.messages value.inbox = value.messages
value.messages = nil value.messages = nil
end end
if ( if (
(not value.inbox or #value.inbox==0) and (not value.inbox or #value.inbox==0) and
(not value.ignore or #value.ignore==0) (not value.ignore or #value.ignore==0)
@ -107,23 +107,23 @@ function chatplus.poke(name,player)
end end
check(name,"ignore") check(name,"ignore")
check(name,"inbox") check(name,"inbox")
chatplus.players[name].enabled = true chatplus.players[name].enabled = true
if player then if player then
if player=="end" then if player=="end" then
chatplus.players[name].enabled = false chatplus.players[name].enabled = false
chatplus.loggedin[name] = nil chatplus.loggedin[name] = nil
else else
if not chatplus.loggedin[name] then if not chatplus.loggedin[name] then
chatplus.loggedin[name] = {} chatplus.loggedin[name] = {}
end end
chatplus.loggedin[name].player = player chatplus.loggedin[name].player = player
end end
end end
chatplus.save() chatplus.save()
return chatplus.players[name] return chatplus.players[name]
end end
@ -135,7 +135,11 @@ function chatplus.register_handler(func,place)
end end
end end
function chatplus.send(from,msg) function chatplus.send(from, msg)
if msg:sub(1, 1) == "/" then
return false
end
-- Log chat message -- Log chat message
if chatplus.log_handle ~= nil then if chatplus.log_handle ~= nil then
chatplus.log_handle:write( chatplus.log_handle:write(
@ -146,14 +150,14 @@ function chatplus.send(from,msg)
) )
chatplus.log_handle:flush() chatplus.log_handle:flush()
end end
-- Loop through senders -- Loop through senders
for key,value in pairs(chatplus.loggedin) do for key,value in pairs(chatplus.loggedin) do
local res = nil local res = nil
for i=1,#chatplus._handlers do for i=1,#chatplus._handlers do
if chatplus._handlers[i] then if chatplus._handlers[i] then
res = chatplus._handlers[i](from,key,msg) res = chatplus._handlers[i](from,key,msg)
if res ~= nil then if res ~= nil then
break break
end end
@ -179,7 +183,7 @@ minetest.register_on_joinplayer(function(player)
-- inbox stuff! -- inbox stuff!
if _player.inbox and #_player.inbox>0 then if _player.inbox and #_player.inbox>0 then
minetest.after(10,minetest.chat_send_player,player:get_player_name(),"("..#_player.inbox..") You have mail! Type /inbox to recieve") minetest.after(10,minetest.chat_send_player,player:get_player_name(),"("..#_player.inbox..") You have mail! Type /inbox to recieve")
end end
end) end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
@ -301,7 +305,7 @@ minetest.register_chatcommand("mail", {
func = function(name, param) func = function(name, param)
chatplus.poke(name) chatplus.poke(name)
local to, msg = string.match(param, "([%a%d_]+) (.+)") local to, msg = string.match(param, "([%a%d_]+) (.+)")
if not to or not msg then if not to or not msg then
minetest.chat_send_player(name,"mail: <playername> <msg>",false) minetest.chat_send_player(name,"mail: <playername> <msg>",false)
return return
@ -336,7 +340,7 @@ minetest.register_globalstep(function(dtime)
value.inbox and value.inbox and
chatplus.loggedin[key].player.hud_add and chatplus.loggedin[key].player.hud_add and
chatplus.loggedin[key].lastcount ~= #value.inbox chatplus.loggedin[key].lastcount ~= #value.inbox
) then ) then
if chatplus.loggedin[key].msgicon then if chatplus.loggedin[key].msgicon then
chatplus.loggedin[key].player:hud_remove(chatplus.loggedin[key].msgicon) chatplus.loggedin[key].player:hud_remove(chatplus.loggedin[key].msgicon)
end end
@ -361,7 +365,7 @@ minetest.register_globalstep(function(dtime)
text=#value.inbox, text=#value.inbox,
scale = {x=1,y=1}, scale = {x=1,y=1},
alignment = {x=0.5, y=0.5}, alignment = {x=0.5, y=0.5},
}) })
end end
chatplus.loggedin[key].lastcount = #value.inbox chatplus.loggedin[key].lastcount = #value.inbox
end end