Update Chatplus and Report
This commit is contained in:
parent
4a8be117f8
commit
e39bd82982
8 changed files with 485 additions and 401 deletions
|
@ -1,12 +1,13 @@
|
||||||
Chatplus
|
# Chatplus
|
||||||
--------
|
|
||||||
|
Adds ignoring and email style inboxes. Also provides a powerful API,
|
||||||
|
and optionally allows distance limiting.
|
||||||
|
|
||||||
License: GPL 3.0 or later.
|
License: GPL 3.0 or later.
|
||||||
|
|
||||||
Created by rubenwardy.
|
Created by rubenwardy.
|
||||||
|
|
||||||
Commands
|
## Chat commands
|
||||||
========
|
|
||||||
|
|
||||||
* /ignore [name] - ignore a player
|
* /ignore [name] - ignore a player
|
||||||
* /unignore [name] - unignore a player
|
* /unignore [name] - unignore a player
|
||||||
|
@ -17,7 +18,6 @@ Commands
|
||||||
* /inbox txt - alias of /inbox text
|
* /inbox txt - alias of /inbox text
|
||||||
* /inbox t - alias of /inbox text
|
* /inbox t - alias of /inbox text
|
||||||
|
|
||||||
HUD
|
## HUD
|
||||||
===
|
|
||||||
|
|
||||||
This mod adds a new message icon to the HUD. If HUDs are not supported, no icon is added.
|
This mod adds a new message icon to the HUD. If HUDs are not supported, no icon is added.
|
||||||
|
|
220
mods/chatplus/api.lua
Normal file
220
mods/chatplus/api.lua
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
-- Chat Plus
|
||||||
|
-- by rubenwardy
|
||||||
|
---------------------
|
||||||
|
-- api.lua
|
||||||
|
-- Core functionality
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
|
||||||
|
chatplus = {
|
||||||
|
version = 2.2,
|
||||||
|
_logpath = minetest.get_worldpath().."/chatplus-log.txt",
|
||||||
|
_defsettings = {
|
||||||
|
log = true,
|
||||||
|
use_gui = true,
|
||||||
|
distance = 0,
|
||||||
|
badwords = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function chatplus.init()
|
||||||
|
chatplus.load()
|
||||||
|
chatplus.clean_players()
|
||||||
|
|
||||||
|
if not chatplus.players then
|
||||||
|
chatplus.players = {}
|
||||||
|
end
|
||||||
|
chatplus.count = 0
|
||||||
|
chatplus.loggedin = {}
|
||||||
|
chatplus._handlers = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.setting(name)
|
||||||
|
local get = minetest.setting_get("chatplus_" .. name)
|
||||||
|
if get then
|
||||||
|
return get
|
||||||
|
elseif chatplus._defsettings[name]~= nil then
|
||||||
|
return chatplus._defsettings[name]
|
||||||
|
else
|
||||||
|
minetest.log("[Chatplus] Setting chatplus_" .. name .. " not found!")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.log(msg)
|
||||||
|
if chatplus._log then
|
||||||
|
chatplus._log:write(os.date("%Y-%m-%d %H:%M:%S") .. " " .. msg .. "\r\n")
|
||||||
|
chatplus._log:flush()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.load()
|
||||||
|
-- Initialize the log
|
||||||
|
if chatplus.setting("log") then
|
||||||
|
chatplus._log = io.open(chatplus._logpath, "a+")
|
||||||
|
if not chatplus._log then
|
||||||
|
minetest.log("error", "Unable to open the chatplus log file: " .. chatplus._logpath)
|
||||||
|
else
|
||||||
|
minetest.log("action", "Logging chat plus to: " .. chatplus._logpath)
|
||||||
|
end
|
||||||
|
chatplus.log("*** SERVER STARTED ***")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load player data
|
||||||
|
minetest.log("[Chatplus] Loading data")
|
||||||
|
local file = io.open(minetest.get_worldpath() .. "/chatplus.txt", "r")
|
||||||
|
if file then
|
||||||
|
local from_file = minetest.deserialize(file:read("*all"))
|
||||||
|
file:close()
|
||||||
|
if type(from_file) == "table" then
|
||||||
|
if from_file.players and from_file.version >= 2 then
|
||||||
|
chatplus.players = from_file.players
|
||||||
|
else
|
||||||
|
chatplus.players = {}
|
||||||
|
for name, data in pairs(from_file) do
|
||||||
|
chatplus.players[name] = data
|
||||||
|
local inbox = data.inbox
|
||||||
|
data.inbox = {}
|
||||||
|
for _, msg in pairs(inbox) do
|
||||||
|
table.insert(data.inbox, {
|
||||||
|
date = "?",
|
||||||
|
from = "?",
|
||||||
|
msg = msg
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.save()
|
||||||
|
minetest.log("[Chatplus] Saving data")
|
||||||
|
|
||||||
|
local file = io.open(minetest.get_worldpath().."/chatplus.txt", "w")
|
||||||
|
if file then
|
||||||
|
file:write(minetest.serialize({ version = 2, players = chatplus.players}))
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.clean_players()
|
||||||
|
if not chatplus.players then
|
||||||
|
chatplus.players = {}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("[Chatplus] Cleaning player lists")
|
||||||
|
for key,value in pairs(chatplus.players) do
|
||||||
|
if value.messages then
|
||||||
|
value.inbox = value.messages
|
||||||
|
value.messages = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if (
|
||||||
|
(not value.inbox or #value.inbox==0) and
|
||||||
|
(not value.ignore or #value.ignore==0)
|
||||||
|
) then
|
||||||
|
value[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
chatplus.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cp_tick()
|
||||||
|
chatplus.clean_players()
|
||||||
|
minetest.after(30*60, cp_tick)
|
||||||
|
end
|
||||||
|
minetest.after(30*60, cp_tick)
|
||||||
|
|
||||||
|
function chatplus.poke(name,player)
|
||||||
|
local function check(name,value)
|
||||||
|
if not chatplus.players[name][value] then
|
||||||
|
chatplus.players[name][value] = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not chatplus.players[name] then
|
||||||
|
chatplus.players[name] = {}
|
||||||
|
end
|
||||||
|
check(name, "ignore")
|
||||||
|
check(name, "inbox")
|
||||||
|
|
||||||
|
chatplus.players[name].enabled = true
|
||||||
|
|
||||||
|
if player then
|
||||||
|
if player=="end" then
|
||||||
|
chatplus.players[name].enabled = false
|
||||||
|
chatplus.loggedin[name] = nil
|
||||||
|
else
|
||||||
|
if not chatplus.loggedin[name] then
|
||||||
|
chatplus.loggedin[name] = {}
|
||||||
|
end
|
||||||
|
chatplus.loggedin[name].player = player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
chatplus.save()
|
||||||
|
|
||||||
|
return chatplus.players[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.register_handler(func,place)
|
||||||
|
if not place then
|
||||||
|
table.insert(chatplus._handlers, func)
|
||||||
|
else
|
||||||
|
table.insert(chatplus._handlers, place, func)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Allows overriding
|
||||||
|
function chatplus.log_message(from, msg)
|
||||||
|
chatplus.log("<" .. from .. "> " .. msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
function chatplus.send(from, msg)
|
||||||
|
if msg:sub(1, 1) == "/" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
chatplus.log_message(from, msg)
|
||||||
|
|
||||||
|
if #chatplus._handlers == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Loop through possible receivers
|
||||||
|
for to, value in pairs(chatplus.loggedin) do
|
||||||
|
if to ~= from then
|
||||||
|
-- Run handlers
|
||||||
|
local res = nil
|
||||||
|
for i = 1, #chatplus._handlers do
|
||||||
|
if chatplus._handlers[i] then
|
||||||
|
res = chatplus._handlers[i](from, to, msg)
|
||||||
|
|
||||||
|
if res ~= nil then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Send message
|
||||||
|
if res == nil or res == true then
|
||||||
|
minetest.chat_send_player(key, "<" .. from .. "> " .. msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Minetest callbacks
|
||||||
|
minetest.register_on_chat_message(chatplus.send)
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
chatplus.log(player:get_player_name() .. " joined")
|
||||||
|
end)
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
chatplus.poke(player:get_player_name(), "end")
|
||||||
|
chatplus.log(player:get_player_name() .. " disconnected")
|
||||||
|
end)
|
||||||
|
chatplus.init()
|
|
@ -1 +1,2 @@
|
||||||
Adds advanced chat features such as ignoring and inboxing.
|
Adds ignoring and email style inboxes. Also provides a powerful API,
|
||||||
|
and optionally allows distance limiting.
|
||||||
|
|
|
@ -1,212 +1,20 @@
|
||||||
-- Chat Plus
|
-- Chat Plus
|
||||||
-- =========
|
-- by rubenwardy
|
||||||
-- Advanced chat functionality
|
---------------------
|
||||||
-- =========
|
-- init.lua
|
||||||
|
-- Three handlers: ignoring, distance, and mail.
|
||||||
|
---------------------
|
||||||
|
|
||||||
chatplus = {
|
dofile(minetest.get_modpath("chatplus") .. "/api.lua")
|
||||||
log_file = minetest.get_worldpath().."/chatplus-log.txt",
|
dofile(minetest.get_modpath("chatplus") .. "/mail.lua")
|
||||||
_defsettings = {
|
|
||||||
log = true,
|
|
||||||
use_gui = true,
|
|
||||||
distance = 0,
|
|
||||||
badwords = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function chatplus.init()
|
|
||||||
chatplus.load()
|
|
||||||
chatplus.clean_players()
|
|
||||||
|
|
||||||
if not chatplus.players then
|
|
||||||
chatplus.players = {}
|
|
||||||
end
|
|
||||||
chatplus.count = 0
|
|
||||||
chatplus.loggedin = {}
|
|
||||||
chatplus._handlers = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.setting(name)
|
|
||||||
local get = minetest.setting_get("chatplus_"..name)
|
|
||||||
if get then
|
|
||||||
return get
|
|
||||||
elseif chatplus._defsettings[name]~= nil then
|
|
||||||
return chatplus._defsettings[name]
|
|
||||||
else
|
|
||||||
minetest.log("[Chatplus] Setting chatplus_"..name.." not found!")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.log(msg)
|
|
||||||
chatplus.log_handle:write(os.date("%d/%m/%Y %I:%M%p") .. " " .. msg .. "\r\n")
|
|
||||||
chatplus.log_handle:flush()
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.load()
|
|
||||||
-- Initialize the log
|
|
||||||
if chatplus.setting("log") then
|
|
||||||
chatplus.log_handle = io.open(chatplus.log_file,"a+")
|
|
||||||
if not chatplus.log_handle then
|
|
||||||
minetest.log("error","Unable to open chat plus log file: "..chatplus.log_file)
|
|
||||||
else
|
|
||||||
minetest.log("action","Logging chat plus to: "..chatplus.log_file)
|
|
||||||
end
|
|
||||||
chatplus.log("*** SERVER STARTED ***")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Load player data
|
|
||||||
minetest.log("[Chatplus] Loading data")
|
|
||||||
local file = io.open(minetest.get_worldpath().."/chatplus.txt", "r")
|
|
||||||
if file then
|
|
||||||
local table = minetest.deserialize(file:read("*all"))
|
|
||||||
file:close()
|
|
||||||
if type(table) == "table" then
|
|
||||||
chatplus.players = table
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.save()
|
|
||||||
minetest.log("[Chatplus] Saving data")
|
|
||||||
|
|
||||||
local file = io.open(minetest.get_worldpath().."/chatplus.txt", "w")
|
|
||||||
if file then
|
|
||||||
file:write(minetest.serialize(chatplus.players))
|
|
||||||
file:close()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.clean_players()
|
|
||||||
if not chatplus.players then
|
|
||||||
chatplus.players = {}
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.log("[Chatplus] Cleaning player lists")
|
|
||||||
for key,value in pairs(chatplus.players) do
|
|
||||||
if value.messages then
|
|
||||||
value.inbox = value.messages
|
|
||||||
value.messages = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if (
|
|
||||||
(not value.inbox or #value.inbox==0) and
|
|
||||||
(not value.ignore or #value.ignore==0)
|
|
||||||
) then
|
|
||||||
value[key] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
chatplus.save()
|
|
||||||
end
|
|
||||||
|
|
||||||
function cp_tick()
|
|
||||||
chatplus.clean_players()
|
|
||||||
minetest.after(30*60, cp_tick)
|
|
||||||
end
|
|
||||||
minetest.after(30*60, cp_tick)
|
|
||||||
|
|
||||||
function chatplus.poke(name,player)
|
|
||||||
local function check(name,value)
|
|
||||||
if not chatplus.players[name][value] then
|
|
||||||
chatplus.players[name][value] = {}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not chatplus.players[name] then
|
|
||||||
chatplus.players[name] = {}
|
|
||||||
end
|
|
||||||
check(name,"ignore")
|
|
||||||
check(name,"inbox")
|
|
||||||
|
|
||||||
chatplus.players[name].enabled = true
|
|
||||||
|
|
||||||
if player then
|
|
||||||
if player=="end" then
|
|
||||||
chatplus.players[name].enabled = false
|
|
||||||
chatplus.loggedin[name] = nil
|
|
||||||
else
|
|
||||||
if not chatplus.loggedin[name] then
|
|
||||||
chatplus.loggedin[name] = {}
|
|
||||||
end
|
|
||||||
chatplus.loggedin[name].player = player
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
chatplus.save()
|
|
||||||
|
|
||||||
return chatplus.players[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.register_handler(func,place)
|
|
||||||
if not place then
|
|
||||||
table.insert(chatplus._handlers,func)
|
|
||||||
else
|
|
||||||
table.insert(chatplus._handlers,place,func)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function chatplus.send(from, msg)
|
|
||||||
if msg:sub(1, 1) == "/" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Log chat message
|
|
||||||
if chatplus.log_handle ~= nil then
|
|
||||||
local tname = ctf.player(from).team or ""
|
|
||||||
chatplus.log(tname .. "<" .. from .. "> " .. msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Loop through senders
|
|
||||||
for key,value in pairs(chatplus.loggedin) do
|
|
||||||
local res = nil
|
|
||||||
if key ~= from then
|
|
||||||
for i=1, #chatplus._handlers do
|
|
||||||
if chatplus._handlers[i] then
|
|
||||||
res = chatplus._handlers[i](from,key,msg)
|
|
||||||
|
|
||||||
if res ~= nil then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if res == nil or res == true then
|
|
||||||
minetest.chat_send_player(key, "<"..from.."> "..msg,false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Minetest callbacks
|
|
||||||
minetest.register_on_chat_message(chatplus.send)
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
local _player = chatplus.poke(player:get_player_name(),player)
|
|
||||||
|
|
||||||
if chatplus.log_handle ~= nil then
|
|
||||||
chatplus.log_handle:write(os.date("%d/%m/%Y %I:%M%p").." "..player:get_player_name().." joined\r\n")
|
|
||||||
chatplus.log_handle:flush()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- inbox stuff!
|
|
||||||
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")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
chatplus.poke(player:get_player_name(),"end")
|
|
||||||
if chatplus.log_handle ~= nil then
|
|
||||||
chatplus.log_handle:write(os.date("%d/%m/%Y %I:%M%p").." "..player:get_player_name().." disconnected\r\n")
|
|
||||||
chatplus.log_handle:flush()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Init
|
|
||||||
chatplus.init()
|
|
||||||
|
|
||||||
|
--
|
||||||
-- Ignoring
|
-- Ignoring
|
||||||
chatplus.register_handler(function(from,to,msg)
|
--
|
||||||
if chatplus.players[to] and chatplus.players[to].ignore and chatplus.players[to].ignore[from]==true then
|
chatplus.register_handler(function(from, to, msg)
|
||||||
|
if chatplus.players[to] and chatplus.players[to].ignore and chatplus.players[to].ignore[from] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
|
@ -217,12 +25,12 @@ minetest.register_chatcommand("ignore", {
|
||||||
description = "ignore: Ignore a player",
|
description = "ignore: Ignore a player",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
chatplus.poke(name)
|
chatplus.poke(name)
|
||||||
if not chatplus.players[name].ignore[param]==true then
|
if not chatplus.players[name].ignore[param] then
|
||||||
chatplus.players[name].ignore[param]=true
|
chatplus.players[name].ignore[param] = true
|
||||||
minetest.chat_send_player(name,param.." has been ignored")
|
minetest.chat_send_player(name, param .. " has been ignored")
|
||||||
chatplus.save()
|
chatplus.save()
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name,"Player "..param.." is already ignored.")
|
minetest.chat_send_player(name, "Player " .. param .. " is already ignored.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -232,179 +40,41 @@ minetest.register_chatcommand("unignore", {
|
||||||
description = "unignore: Unignore a player",
|
description = "unignore: Unignore a player",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
chatplus.poke(name)
|
chatplus.poke(name)
|
||||||
if chatplus.players[name].ignore[param]==true then
|
if chatplus.players[name].ignore[param] then
|
||||||
chatplus.players[name].ignore[param]=false
|
chatplus.players[name].ignore[param] = false
|
||||||
minetest.chat_send_player(name,param.." has been unignored")
|
minetest.chat_send_player(name, param .. " has been unignored")
|
||||||
chatplus.save()
|
chatplus.save()
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name,"Player "..param.." is already unignored.")
|
minetest.chat_send_player(name, "Player " .. param .. " is already unignored.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- inbox
|
|
||||||
function chatplus.showInbox(name,forcetest)
|
|
||||||
if not chatplus.players[name] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local player = chatplus.players[name]
|
|
||||||
|
|
||||||
if not player.inbox or #player.inbox==0 then
|
--
|
||||||
minetest.chat_send_player(name,"Your inbox is empty!")
|
-- Distance
|
||||||
return false
|
--
|
||||||
end
|
chatplus.register_handler(function(from, to, msg)
|
||||||
local setting = chatplus.setting("use_gui")
|
local d = chatplus.setting("distance")
|
||||||
if (setting == true or setting == "true" or setting == "1") and not forcetest then
|
if d <= 0 then
|
||||||
minetest.chat_send_player(name,"Showing your inbox to you.")
|
|
||||||
local fs = "size[10,8]textarea[0.25,0.25;10.15,8;inbox;You have " .. #player.inbox .. " messages in your inbox:;"
|
|
||||||
|
|
||||||
for i=1,#player.inbox do
|
|
||||||
fs = fs .. minetest.formspec_escape(player.inbox[i])
|
|
||||||
fs = fs .. "\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
fs = fs .. "]"
|
|
||||||
fs = fs .. "button[0,7.25;2,1;clear;Clear Inbox]"
|
|
||||||
fs = fs .. "button_exit[8.1,7.25;2,1;close;Close]"
|
|
||||||
minetest.show_formspec(name, "chatplus:inbox", fs)
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name,"("..#player.inbox..") You have mail:")
|
|
||||||
for i=1,#player.inbox do
|
|
||||||
minetest.chat_send_player(name,player.inbox[i],false)
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(name,"("..#player.inbox..")",false)
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|
||||||
if fields.clear then
|
|
||||||
local name = player:get_player_name()
|
|
||||||
chatplus.poke(name).inbox = {}
|
|
||||||
chatplus.save()
|
|
||||||
minetest.chat_send_player(name,"Inbox cleared!")
|
|
||||||
chatplus.showInbox(name)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_chatcommand("inbox", {
|
|
||||||
params = "clear?",
|
|
||||||
description = "inbox: print the items in your inbox",
|
|
||||||
func = function(name, param)
|
|
||||||
if param == "clear" then
|
|
||||||
local player = chatplus.poke(name)
|
|
||||||
player.inbox = {}
|
|
||||||
chatplus.save()
|
|
||||||
minetest.chat_send_player(name,"Inbox cleared")
|
|
||||||
elseif param == "text" or param == "txt" or param == "t" then
|
|
||||||
chatplus.showInbox(name,true)
|
|
||||||
else
|
|
||||||
chatplus.showInbox(name,false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
function chatplus.send_mail(name, to, msg)
|
|
||||||
minetest.log("To: "..to..", From: "..name..", MSG: "..msg)
|
|
||||||
if chatplus.log_handle ~= nil then
|
|
||||||
chatplus.log("To: "..to..", From: "..name..", MSG: "..msg)
|
|
||||||
end
|
|
||||||
if chatplus.players[to] then
|
|
||||||
table.insert(chatplus.players[to].inbox,os.date("%d/%m").." <"..name..">: "..msg)
|
|
||||||
minetest.chat_send_player(name,"Message sent")
|
|
||||||
chatplus.save()
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name,"Player "..to.." does not exist")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_chatcommand("mail", {
|
|
||||||
params = "name msg",
|
|
||||||
description = "mail: add a message to a player's inbox",
|
|
||||||
func = function(name, param)
|
|
||||||
chatplus.poke(name)
|
|
||||||
local to, msg = string.match(param, "^([%a%d_-]+) (.+)")
|
|
||||||
|
|
||||||
if not to or not msg then
|
|
||||||
minetest.chat_send_player(name,"mail: <playername> <msg>",false)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
chatplus.send_mail(name, to, msg)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
chatplus.count = chatplus.count + dtime
|
|
||||||
if chatplus.count > 5 then
|
|
||||||
chatplus.count = 0
|
|
||||||
-- loop through player list
|
|
||||||
for key,value in pairs(chatplus.players) do
|
|
||||||
if (
|
|
||||||
chatplus.loggedin and
|
|
||||||
chatplus.loggedin[key] and
|
|
||||||
chatplus.loggedin[key].player and
|
|
||||||
value and
|
|
||||||
value.inbox and
|
|
||||||
chatplus.loggedin[key].player.hud_add and
|
|
||||||
chatplus.loggedin[key].lastcount ~= #value.inbox
|
|
||||||
) then
|
|
||||||
if chatplus.loggedin[key].msgicon then
|
|
||||||
chatplus.loggedin[key].player:hud_remove(chatplus.loggedin[key].msgicon)
|
|
||||||
end
|
|
||||||
|
|
||||||
if chatplus.loggedin[key].msgicon2 then
|
|
||||||
chatplus.loggedin[key].player:hud_remove(chatplus.loggedin[key].msgicon2)
|
|
||||||
end
|
|
||||||
|
|
||||||
if #value.inbox>0 then
|
|
||||||
chatplus.loggedin[key].msgicon = chatplus.loggedin[key].player:hud_add({
|
|
||||||
hud_elem_type = "image",
|
|
||||||
name = "MailIcon",
|
|
||||||
position = {x=0.52, y=0.52},
|
|
||||||
text="chatplus_mail.png",
|
|
||||||
scale = {x=1,y=1},
|
|
||||||
alignment = {x=0.5, y=0.5},
|
|
||||||
})
|
|
||||||
chatplus.loggedin[key].msgicon2 = chatplus.loggedin[key].player:hud_add({
|
|
||||||
hud_elem_type = "text",
|
|
||||||
name = "MailText",
|
|
||||||
position = {x=0.55, y=0.52},
|
|
||||||
text=#value.inbox .. " /inbox",
|
|
||||||
scale = {x=1,y=1},
|
|
||||||
alignment = {x=0.5, y=0.5},
|
|
||||||
})
|
|
||||||
end
|
|
||||||
chatplus.loggedin[key].lastcount = #value.inbox
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
chatplus.register_handler(function(from,to,msg)
|
|
||||||
if chatplus.setting("distance") <= 0 then
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local from_o = minetest.get_player_by_name(from)
|
local from_o = minetest.get_player_by_name(from)
|
||||||
local to_o = minetest.get_player_by_name(to)
|
local to_o = minetest.get_player_by_name(to)
|
||||||
|
|
||||||
if not from_o or not to_o then
|
if not from_o or not to_o then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if (
|
return not d or vector.distance(from_o:getpos(), to_o:getpos()) <= tonumber(d)
|
||||||
chatplus.setting("distance") ~= 0 and
|
|
||||||
chatplus.setting("distance") ~= nil and
|
|
||||||
(vector.distance(from_o:getpos(),to_o:getpos()) > tonumber(chatplus.setting("distance")))
|
|
||||||
)then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Bad words
|
||||||
|
--
|
||||||
chatplus.register_handler(function(from,to,msg)
|
chatplus.register_handler(function(from,to,msg)
|
||||||
local words = chatplus.setting("badwords"):split(",")
|
local words = chatplus.setting("badwords"):split(",")
|
||||||
for _,v in pairs(words) do
|
for _,v in pairs(words) do
|
||||||
|
|
195
mods/chatplus/mail.lua
Normal file
195
mods/chatplus/mail.lua
Normal file
|
@ -0,0 +1,195 @@
|
||||||
|
-- Chat Plus
|
||||||
|
-- by rubenwardy
|
||||||
|
---------------------
|
||||||
|
-- mail.lua
|
||||||
|
-- Adds C+'s email.
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
local _player = chatplus.poke(player:get_player_name(),player)
|
||||||
|
-- inbox stuff!
|
||||||
|
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")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- inbox
|
||||||
|
function chatplus.showInbox(name, text_mode)
|
||||||
|
-- Get player info
|
||||||
|
local player = chatplus.players[name]
|
||||||
|
|
||||||
|
-- Show
|
||||||
|
if text_mode then
|
||||||
|
if not player or not player.inbox or #player.inbox == 0 then
|
||||||
|
return true, "Your inbox is empty!"
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, #player.inbox .. " items in your inbox:")
|
||||||
|
for i = 1, #player.inbox do
|
||||||
|
local item = player.inbox[i]
|
||||||
|
minetest.chat_send_player(name, i .. ") " ..item.date ..
|
||||||
|
" <" .. item.from .. "> " .. item.msg)
|
||||||
|
end
|
||||||
|
return true, "End of mail (" .. #player.inbox .. " item)"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local fs = "size[12,8]"
|
||||||
|
fs = fs .. "vertlabel[0,0;Chatplus Mail]"
|
||||||
|
|
||||||
|
fs = fs .. "tablecolumns[color;text;color;text;text]"
|
||||||
|
fs = fs .. "tableoptions[highlight=#ffffff33]"
|
||||||
|
fs = fs .. "table[0.5,0;11.25,7;inbox;"
|
||||||
|
fs = fs .. "#ffffff,Date,,From,Message"
|
||||||
|
if not player or not player.inbox or #player.inbox == 0 then
|
||||||
|
fs = fs .. ",#d0d0d0,,#d0d0d0," ..
|
||||||
|
minetest.formspec_escape(":)") ..
|
||||||
|
"," ..
|
||||||
|
minetest.formspec_escape("Well done! Your inbox is empty!")
|
||||||
|
else
|
||||||
|
for i = 1, #player.inbox do
|
||||||
|
fs = fs .. ",#D0D0D0,"
|
||||||
|
fs = fs .. minetest.formspec_escape(player.inbox[i].date) .. ","
|
||||||
|
if minetest.check_player_privs(player.inbox[i].from, {kick = true, ban = true}) then
|
||||||
|
fs = fs .. "#FFD700,"
|
||||||
|
else
|
||||||
|
fs = fs .. "#ffffff,"
|
||||||
|
end
|
||||||
|
fs = fs .. minetest.formspec_escape(player.inbox[i].from) .. ","
|
||||||
|
fs = fs .. minetest.formspec_escape(player.inbox[i].msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
fs = fs .. "]"
|
||||||
|
|
||||||
|
fs = fs .. "button[0,7.25;2,1;clear;Delete All]"
|
||||||
|
--fs = fs .. "button[0,7.25;2,1;clear;Mark as read]"
|
||||||
|
fs = fs .. "button_exit[10.1,7.25;2,1;close;Close]"
|
||||||
|
fs = fs .. "label[2,7.4;Exit then type /mail username message to reply]"
|
||||||
|
|
||||||
|
minetest.show_formspec(name, "chatplus:inbox", fs)
|
||||||
|
|
||||||
|
return true, "Opened inbox!"
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player,formname,fields)
|
||||||
|
if fields.clear then
|
||||||
|
local name = player:get_player_name()
|
||||||
|
chatplus.poke(name).inbox = {}
|
||||||
|
chatplus.save()
|
||||||
|
minetest.chat_send_player(name, "Inbox cleared!")
|
||||||
|
chatplus.showInbox(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[if fields.mark_all_read then
|
||||||
|
if player and player.inbox and #player.inbox > 0 then
|
||||||
|
for i = 1, #player.inbox do
|
||||||
|
player.inbox[i].read = true
|
||||||
|
end
|
||||||
|
chatplus.save()
|
||||||
|
minetest.chat_send_player(name, "Marked all as read!")
|
||||||
|
chatplus.showInbox(name)
|
||||||
|
end
|
||||||
|
end]]--
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_chatcommand("inbox", {
|
||||||
|
params = "clear?",
|
||||||
|
description = "inbox: print the items in your inbox",
|
||||||
|
func = function(name, param)
|
||||||
|
if param == "clear" then
|
||||||
|
local player = chatplus.poke(name)
|
||||||
|
player.inbox = {}
|
||||||
|
chatplus.save()
|
||||||
|
|
||||||
|
return true, "Inbox cleared"
|
||||||
|
elseif param == "text" or param == "txt" or param == "t" then
|
||||||
|
return chatplus.showInbox(name, true)
|
||||||
|
else
|
||||||
|
return chatplus.showInbox(name, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
function chatplus.send_mail(name, to, msg)
|
||||||
|
minetest.log("ChatplusMail - To: "..to..", From: "..name..", MSG: "..msg)
|
||||||
|
chatplus.log("ChatplusMail - To: "..to..", From: "..name..", MSG: "..msg)
|
||||||
|
if chatplus.players[to] then
|
||||||
|
table.insert(chatplus.players[to].inbox, {
|
||||||
|
date = os.date("%Y-%m-%d %H:%M:%S"),
|
||||||
|
from = name,
|
||||||
|
msg = msg})
|
||||||
|
chatplus.save()
|
||||||
|
|
||||||
|
minetest.chat_send_player(to, name .. " sent you mail! Type /inbox to see it.")
|
||||||
|
|
||||||
|
return true, "Message sent to " .. to
|
||||||
|
else
|
||||||
|
return false, "Player '" .. to .. "' does not exist"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("mail", {
|
||||||
|
params = "name msg",
|
||||||
|
description = "mail: add a message to a player's inbox",
|
||||||
|
func = function(name, param)
|
||||||
|
chatplus.poke(name)
|
||||||
|
local to, msg = string.match(param, "^([%a%d_-]+) (.+)")
|
||||||
|
|
||||||
|
if not to or not msg then
|
||||||
|
minetest.chat_send_player(name,"mail: <playername> <msg>",false)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return chatplus.send_mail(name, to, msg)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
chatplus.count = chatplus.count + dtime
|
||||||
|
if chatplus.count > 5 then
|
||||||
|
chatplus.count = 0
|
||||||
|
-- loop through player list
|
||||||
|
for key,value in pairs(chatplus.players) do
|
||||||
|
if (
|
||||||
|
chatplus.loggedin and
|
||||||
|
chatplus.loggedin[key] and
|
||||||
|
chatplus.loggedin[key].player and
|
||||||
|
value and
|
||||||
|
value.inbox and
|
||||||
|
chatplus.loggedin[key].player.hud_add and
|
||||||
|
chatplus.loggedin[key].lastcount ~= #value.inbox
|
||||||
|
) then
|
||||||
|
if chatplus.loggedin[key].msgicon then
|
||||||
|
chatplus.loggedin[key].player:hud_remove(chatplus.loggedin[key].msgicon)
|
||||||
|
end
|
||||||
|
|
||||||
|
if chatplus.loggedin[key].msgicon2 then
|
||||||
|
chatplus.loggedin[key].player:hud_remove(chatplus.loggedin[key].msgicon2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #value.inbox>0 then
|
||||||
|
chatplus.loggedin[key].msgicon = chatplus.loggedin[key].player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
name = "MailIcon",
|
||||||
|
position = {x=0.52, y=0.52},
|
||||||
|
text="chatplus_mail.png",
|
||||||
|
scale = {x=1,y=1},
|
||||||
|
alignment = {x=0.5, y=0.5},
|
||||||
|
})
|
||||||
|
chatplus.loggedin[key].msgicon2 = chatplus.loggedin[key].player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
|
name = "MailText",
|
||||||
|
position = {x=0.55, y=0.52},
|
||||||
|
text=#value.inbox .. " /inbox",
|
||||||
|
scale = {x=1,y=1},
|
||||||
|
alignment = {x=0.5, y=0.5},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
chatplus.loggedin[key].lastcount = #value.inbox
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
|
@ -1,22 +0,0 @@
|
||||||
--[[
|
|
||||||
if #msg > 200 then
|
|
||||||
local warn = warned[from] or { count = 0 }
|
|
||||||
warned[from] = warn
|
|
||||||
warn.count = warn.count + 1
|
|
||||||
warn.time = minetest.get_gametime()
|
|
||||||
|
|
||||||
if warn.count > 3 then
|
|
||||||
if been_kicked[from] then
|
|
||||||
minetest.kick_player(from, "Too long chat message! ")
|
|
||||||
been_kicked =
|
|
||||||
else
|
|
||||||
minetest.kick_player(from, "Too long chat message! Next time is temp-ban.")
|
|
||||||
been_kicked
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(from, "That chat message was rather long! " ..
|
|
||||||
(2 - warn.count) .. " warnings remaining.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
]]
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit b70fb29a119db29f006be5b036b969f3c9d8ffac
|
Subproject commit e4e59970549d3ddeff842cb207d7afbb87a00061
|
|
@ -1,20 +1,40 @@
|
||||||
|
if not chatplus.send_mail then
|
||||||
|
error("You need to update chatplus!")
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("report", {
|
minetest.register_chatcommand("report", {
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local mods = ""
|
param = param:trim()
|
||||||
|
if param == "" then
|
||||||
|
return false, "Please add a message to your report. " ..
|
||||||
|
"If it's about (a) particular player(s), please also include their name(s)."
|
||||||
|
end
|
||||||
|
local _, count = string.gsub(param, " ", "")
|
||||||
|
if count == 0 then
|
||||||
|
minetest.chat_send_player(name, "If you're reporting a player, " ..
|
||||||
|
"you should also include a reason why. (Eg: swearing, sabotage)")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Send to online moderators / admins
|
||||||
|
-- Get comma separated list of online moderators and admins
|
||||||
|
local mods = {}
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if minetest.check_player_privs(name, {kick=true,ban=true}) then
|
if minetest.check_player_privs(name, {kick = true, ban = true}) then
|
||||||
if mods ~= "" then
|
table.insert(mods, name)
|
||||||
mods = mods .. ", "
|
|
||||||
end
|
|
||||||
mods = mods .. name
|
|
||||||
minetest.chat_send_player(name, "-!- " .. name .. " reported: " .. param)
|
minetest.chat_send_player(name, "-!- " .. name .. " reported: " .. param)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if mods == "" then
|
|
||||||
mods = "none"
|
if #mods > 0 then
|
||||||
end
|
mod_list = table.concat(mods, ", ")
|
||||||
chatplus.send_mail(name, minetest.setting_get("name"),
|
chatplus.send_mail(name, minetest.setting_get("name"),
|
||||||
"Report: " .. param .. " (mods online: " .. mods .. ")")
|
"Report: " .. param .. " (mods online: " .. mod_list .. ")")
|
||||||
|
return true, "Reported. Moderators currently online: " .. mod_list
|
||||||
|
else
|
||||||
|
chatplus.send_mail(name, minetest.setting_get("name"),
|
||||||
|
"Report: " .. param .. " (no mods online)")
|
||||||
|
return true, "Reported. We'll get back to you."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue