diff --git a/README.md b/README.md index 4541591..954bafc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,51 @@ -# multichat -Adiciona funcionalidades ao chat +# MultiChat v1.0.0 + +[![Baixar](https://img.shields.io/badge/Baixar-v1.0.0-green.svg)](https://github.com/BrunoMine/multichat/archive/v1.0.0.zip) +[![Projeto](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/multichat) +[![!Bower](https://img.shields.io/badge/Bower-Projeto-green.svg)](https://minetest-bower.herokuapp.com/mods/multichat) +[![Licença](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/multichat/blob/master/LICENSE) + +## Descrição +Adiciona funcionalidades ao chat +* Prefixos para administradores e moderadores? +* Grupo privado? +* Ignorar jogadores no chat ? + +## Recursos do projeto + +* [Baixar](https://github.com/BrunoMine/multichat/archive/v1.0.0.zip) +* [Projeto](https://github.com/BrunoMine/multichat) +* [Bower](https://minetest-bower.herokuapp.com/mods/multichat) + +## Requisitos + +* Minetest 0.4.16 ou superior +* Mod default + +## Comandos + +* `/chat` : Abre o painel de configuração do bate-papo + +## Privilégios + +* `chat_admin` : Adiciona prefixo de adminstrador (`[ADMIN]`, configurável) nas falas no bate-papo +* `chat_staff` : Adiciona prefixo de moderador (`[MODERADOR]`, configurável) nas falas no bate-papo + +## Licença +Veja LICENSE.txt para informações detalhadas da licença LGPL 3.0 + +### Autores do código fonte +Originalmente por BrunoMine, Bruno Borges (LGPL 3.0) + +### Autores de mídias (texturas, modelos and sons) +Todos que não estao listados aqui: +BrunoMine, Bruno Borges (CC BY-SA 3.0) + +Desconhecido (CC0) + multichat_aviso.ogg + +UnderlinedDesigns (CC0) + multichat_chamada.ogg + + + diff --git a/chat.lua b/chat.lua new file mode 100644 index 0000000..b819b28 --- /dev/null +++ b/chat.lua @@ -0,0 +1,133 @@ +--[[ + Mod MultiChat para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Chat + + ]] + + +minetest.register_privilege("chat_admin", "Usar char como administrador") +minetest.register_privilege("chat_staff", "Usar char como moderador") + +-- Grupos privados de cada jogador +multichat.grupos = {} + +-- Pegar prefixos +multichat.admin_prefix = minetest.setting_get("multichat_admin_prefix") or "ADMIN" +multichat.staff_prefix = minetest.setting_get("multichat_staff_prefix") or "MODERADOR" + +local tocar_som = function(player) minetest.sound_play("multichat_aviso", {object = player,gain = 0.5,max_hear_distance = 1}) end +local tocar_chamada = function(player) minetest.sound_play("multichat_chamada", {object = player,gain = 0.5,max_hear_distance = 1}) end +-- Emitir som de aviso +multichat.som_avisar = function(name, msg) + local player = minetest.get_player_by_name(name) + + -- Verificar se vai ser som de chamada + if msg + and player:get_attribute("multichat_chamada") ~= "false" + and string.find(msg, name) ~= nil + then + tocar_chamada(player) + -- Verifica se vai ser som normal + elseif player:get_attribute("multichat_som") ~= "false" then + tocar_som(player) + end + +end +local som_avisar = multichat.som_avisar + +-- Pegar prefixo +multichat.prefixo = function(name) + if minetest.check_player_privs(name, {chat_admin=true}) then return "["..multichat.admin_prefix.."]" end + if minetest.check_player_privs(name, {chat_staff=true}) then return "["..multichat.staff_prefix.."]" end + return "" +end + +-- Enviar mensagem para jogador +local enviar_msg = function(name, msg, falante) + local player = minetest.get_player_by_name(name) + local status = player:get_attribute("multichat_status") + + -- Verifica se o jogador está no bate-papo público + if status == nil or status == "pub" then + minetest.chat_send_player(name, "<"..multichat.prefixo(falante)..falante.."> "..msg) + + -- Evita avisar a si mesmo + if name ~= falante then + som_avisar(name, msg) + else + som_avisar(name) + end + + -- Verificar se está desativado + elseif status == "off" then + return + + -- Verifica se jogador está ouvindo apenas seu grupo + elseif status == "grupo" and multichat.grupos[name] then + + -- Verifica se falante está no grupo + if multichat.grupos[name][falante] then + minetest.chat_send_player(name, "<"..multichat.prefixo(falante)..falante.."> "..msg) + som_avisar(name, msg) + end + end + +end + +-- Chamada para envio de mensagens de jogadores +minetest.register_on_chat_message(function(name, msg) + -- Verifica se tem privilegio para falar + if minetest.check_player_privs(name, {shout=true}) ~= true then return true end + + local player = minetest.get_player_by_name(name) + local status = player:get_attribute("multichat_status") + + -- Verifica se o jogador está no bate-papo público + if status == nil or status == "pub" then + + -- Envia a mensagem para todos os jogadores + for _,player in ipairs(minetest.get_connected_players()) do + enviar_msg(player:get_player_name(), msg, name) + end + + -- Verificar se está desativado + elseif status == "off" then + minetest.chat_send_player(name, "Bate-papo desativado") + + -- Verifica se jogador está falando apenas com seu grupo + elseif status == "grupo" then + + -- Envia a mensagem para todos os jogadores do grupo + for np,v in pairs(multichat.grupos[name] or {}) do + enviar_msg(np, msg, name) + end + + -- Envia a si mesmo tambem para aparecer no console + minetest.chat_send_player(name, "<"..multichat.prefixo(falante)..falante.."> "..msg) + som_avisar(name) + end + return true +end) + + +-- Verificador de jogadores offline para remover grupos +local timer = 0 +local tlim = tonumber(minetest.setting_get("multichat_tempo_verif_grupo") or 3600) +minetest.register_globalstep(function(dtime) + timer = timer + dtime; + if timer >= 3600 then + -- Mantar apenas grupos de jogadores online + local ntb = {} + for _,player in ipairs(minetest.get_connected_players()) do + local name = player:get_player_name() + ntb[name] = multichat.grupos[name] + end + multichat.grupos = ntb + end +end) diff --git a/comandos.lua b/comandos.lua new file mode 100644 index 0000000..baecab3 --- /dev/null +++ b/comandos.lua @@ -0,0 +1,19 @@ +--[[ + Mod MultiChat para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Comandos + + ]] + +minetest.register_chatcommand("chat", { + description = "Abrir painel do bate-papo", + privs = {}, + func = function(name) + multichat.acessar_menu(name) + end, +}) diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..3893058 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Adiciona funcionalidades no chat diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..c149211 --- /dev/null +++ b/init.lua @@ -0,0 +1,48 @@ +--[[ + Mod MultiChat para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + ]] + + +-- Variavel global +multichat = {} + +-- Notificador de Inicializador +local notificar = function(msg) + if minetest.setting_get("log_mods") then + minetest.debug("[MULTICHAT]"..msg) + end +end + +-- Verificar compatibilidades de versão +-- Versão do servidor +if minetest.get_version().string and string.find(minetest.get_version().string, "0.4.15") then + minetest.log("error", "[MULTICHAT] Versao imcompativel (use 0.4.16 ou superior)") +end +-- Versão do cliente +if minetest.setting_get("strict_protocol_version_checking") ~= "true" then + minetest.log("error", "[MULTICHAT] Incompativel com clientes inferiores a 0.4.16 (defina strict_protocol_version_checking para evitar erros)") +end + + +-- Modpath +local modpath = minetest.get_modpath("multichat") + +-- Carregar scripts +notificar("Carregando...") +dofile(modpath.."/lib/memor/init.lua") + +-- Variavel temporaria de jogadores online +multichat.online = memor.online() + +dofile(modpath.."/chat.lua") +dofile(modpath.."/menu.lua") +dofile(modpath.."/msg.lua") +dofile(modpath.."/me.lua") +dofile(modpath.."/comandos.lua") +notificar("OK!") diff --git a/lib/memor/API.txt b/lib/memor/API.txt new file mode 100644 index 0000000..d7e4227 --- /dev/null +++ b/lib/memor/API.txt @@ -0,0 +1,99 @@ +Mod Memor para Minetest +Memor v1.2 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine) + +Recebeste uma cópia da GNU Lesser General +Public License junto com esse software, +se não, veja em . + +API + +===================================> Montar um banco de dados rápido <=================================== +Esse banco de dados fica em uma subpasta com o nome do mod especificado portanto não deve existir nenhum +arquivo ou pasta com o nome do mod dentro da pasta do mundo pois isso ocasionaria um conflito de nomes + +memor.montar_bd() -- Função que retorna uma tabela de funções para gerenciar o banco de + dados do mod + + OPCIONAL é o nome do mod que usará o banco de dados + Se nulo, fica sendo o nome do mod que executar a função + +Chamadas de função para o banco de dados criado + + salvar(tb, index, valor) -- Salva um valor no banco de dados (cria as tabelas se não existirem) + + é o nome da tabela (exemplo: players, nodes, casas) + é o endereço do valor (exemplo: fome, altura, dono) + é o valor armazenado (exemplo: 6, 30, "Caio") + + pegar(index, valor) -- Retorna o valor armazenado (ou nulo caso seja inexistente) + + é o nome da tabela (exemplo: players, nodes, casas) + é o endereço do valor (exemplo: fome, altura, dono) + + verif(index, valor) -- Verifica se um determinado registro existe (retorna 'true' se existir) + + é o nome da tabela (exemplo: players, nodes, casas) + é o endereço do valor (exemplo: fome, altura, dono) + + remover(tb, index) -- Remove um valor da tabela (apaga o dado armazenado) + + é o nome da tabela (exemplo: players, nodes, casas) + é o endereço do valor (exemplo: fome, altura, dono) + + drop_tb(tb) -- Remove uma tabela (apagando todos os seus dados) + + é o nome da tabela (exemplo: players, nodes, casas) + + listar(tb) -- Retorna uma tabela ordenada com strings dos nomes de tabelas ou indices + + OPICIONAL é uma tabela a qual desejar listar os sues indices + ^ Se nulo, retorna as listagem das tabelas do banco de dados + +Exemplo de uso: + +-- Montar um banco de dados na variavel 'registro' +local registro = memor.montar_bd(minetest.get_current_modname()) + +-- Criar uma tabela de "medalhas" onde "Maria" terá 15 +registro:salvar("medalhas", "Maria", 15) + +-- Verifica se "Maria" existe na tabela de "Medalhas" +if registro:verif("medalhas", "Maria") then + + -- Consulta quantas "medalhas" "Maria" tem + local medalhas = registro:pegar("medalhas", "Maria") -- retorna 15 + + minetest.chat_send_all("Maria tem " .. medalhas .. " medalhas") + +end + +-- Remover "Maria" da tabela "medalhas" +registro:remover("medalhas", "Maria") + +-- Remove a tabela "medalhas" +registro:drop_tb("medalhas") + +========================================================================================================= + +=====================================> Tabela de jogadores online <====================================== + +memor.online() -- Retorna uma tabela desordenada com índices com nomes dos jogadores online + ^ A tabela só mantém dados dos índices de jogadores online + ^ Caso um nome de jogador que não esteja online for inserido, ele vai + ser apagado assim que algum jogador sair do servidor + + OPCIONAL é uma string com o nome do mod dono da tabela (o que opera a tabela) + Se nulo, fica sendo o nome do mod que executar a função + +Exemplo de uso: + +-- Tabela que guarda quem é o convidado de um jogador (controlada para manter apenas jogadores online) +local convidados = memor.online() + +-- Jogador "Arnaldo" tem "Luiz" como convidado +convidados["Arnaldo"] = "Luiz" + +-- Quando o jogador "Arnaldo" sair do servidor, esse dado será apagado da memória + +========================================================================================================= + diff --git a/lib/memor/LICENSE b/lib/memor/LICENSE new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/lib/memor/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/lib/memor/README.md b/lib/memor/README.md new file mode 100644 index 0000000..5eb2e46 --- /dev/null +++ b/lib/memor/README.md @@ -0,0 +1,9 @@ +# Memor v1.2 + +por BrunoMine + +Gerencia dados rápidos de forma simples em formato de banco de dados ou tabela de dados temporários. + +LICENÇA LGPL v3 + +Memor é um software livre; você pode redistribuí-lo e/ou modificá-lo dentro dos termos da Licença Pública Geral Menor GNU como publicada pela Fundação do Software Livre (FSF); na versão 3 da Licença, ou (na sua opinião) qualquer versão. Este programa é distribuído na esperança de que possa ser útil, mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral Menor GNU para maiores detalhes. Você deve ter recebido uma cópia da Licença Pública Geral Menor GNU junto com este programa, se não, veja http://www.gnu.org/licenses/. diff --git a/lib/memor/arquivo.lua b/lib/memor/arquivo.lua new file mode 100644 index 0000000..4d4561b --- /dev/null +++ b/lib/memor/arquivo.lua @@ -0,0 +1,105 @@ +--[[ + Mod Memor para Minetest + Memor v1.2 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Operadores de arquivamento e leitura + ]] + + +-- Diretorio do mundo +local wpath = minetest.get_worldpath() + +-- Cria um diretório na pasta do mundo +function memor.mkdir(dir, sub) + if not dir then + minetest.log("error", "[Memor] Nenhum diretorio especificado (em memor.mkdir)") + return false + end + + dir = wpath.."/"..dir + + if minetest.mkdir then + minetest.mkdir(dir) + else + os.execute('mkdir "' .. dir .. '"') + end + return true +end + +-- Criar um arquivo com os dados serializados (Salvar) +function memor.escrever(mod, dir, arquivo, dados) + if mod == nil or dir == nil or arquivo == nil or dados == nil then + minetest.log("error", "[Memor] Faltou dados (em memor.escrever)") + return false + end + + local dados = minetest.serialize(dados) + if dados == "" then + minetest.log("error", "[Memor] Dado fornecido invalido (em memor.escrever)") + return false + end + + local saida = io.open(wpath .. "/" .. mod .. "/" .. dir .. "/" .. arquivo, "w") + if saida then + saida:write(dados) + io.close(saida) + return true + else + minetest.log("info", "[Memor] memor.escrever tentou escrever num diretorio inexistente") + return false + end +end + +-- Ler dados de um arquivo de memória (Carregar) +function memor.ler(mod, dir, arquivo) + if mod == nil or dir == nil or arquivo == nil then + minetest.log("error", "[Memor] Faltou dados (em memor.ler)") + return nil + end + + local entrada = io.open(wpath .. "/" .. mod .. "/" .. dir .. "/" .. arquivo, "r") + if entrada then + local dados = entrada:read("*l") + if dados ~= "" or dados ~= nil then + dados = minetest.deserialize(dados) + end + io.close(entrada) + return dados + else + minetest.log("error", "[Memor] pasta e/ou arquivo inexiste(s) (em memor.ler)") + return nil + end +end + +-- Deletar um arquivo +function memor.deletar(mod, dir, arquivo) + if not mod or not dir or not arquivo then + minetest.log("error", "[Memor] Faltou dados (em memor.deletar)") + return false + end + + os.remove(wpath .. "/" .. mod .. "/" .. dir .. "/" .. arquivo) + return true +end + + +-- Deletar um diretório +function memor.deletar_dir(mod, dir) + if not mod or not dir then + minetest.log("error", "[Memor] Faltou dados (em memor.deletar_dir)") + return false + end + + local list = minetest.get_dir_list(wpath .. "/" .. mod .. "/" .. dir) + + for n, arquivo in ipairs(list) do + os.remove(wpath .. "/" .. mod .. "/" .. dir .. "/" .. arquivo) + end + + os.remove(wpath .. "/" .. mod .. "/" .. dir) + return true +end diff --git a/lib/memor/consulta.lua b/lib/memor/consulta.lua new file mode 100644 index 0000000..d540edc --- /dev/null +++ b/lib/memor/consulta.lua @@ -0,0 +1,129 @@ +--[[ + Mod Memor para Minetest + Memor v1.2 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Operadores de consulta + ]] + +-- Diretório do Mundo +local wpath = minetest.get_worldpath() + +-- Verifica diretorios e corrige +verificar = function(dir, subdir) + + -- Verifica e corrige diretorio + local list = minetest.get_dir_list(minetest.get_worldpath(), true) + local r = false + for n, ndir in ipairs(list) do + if ndir == dir then + r = true + break + end + end + -- Diretorio inexistente + if r == false then + memor.mkdir(dir) + end + + -- Verifica e corrige subdiretorio + list = minetest.get_dir_list(minetest.get_worldpath().."/"..dir, true) + r = false + for n, ndir in ipairs(list) do + if ndir == subdir then + r = true + break + end + end + -- Subdiretorio inexistente + if r == false then + memor.mkdir(dir.."/"..subdir) + end + +end + + +-- Inserir dados +memor.inserir = function(mod, tb, index, valor) + + -- Tenta inserir direto + if memor.escrever(mod, tb, index, valor) == true then return true end + + verificar(mod, tb) + + if memor.escrever(mod, tb, index, valor) then + return true + else + minetest.log("error", "[Memor] Impossivel salvar dados (em memor.inserir)") + return false + end + +end + + +-- Ler dados +memor.consultar = function(mod, tb, index) + + local r = memor.ler(mod, tb, index) + if r == nil then + minetest.log("error", "[Memor] Registro acessado inexistente ("..dump(mod).."/"..dump(tb).."/"..dump(index)..") (em memor.consultar)") + end + + return r + +end + + +-- Verificar dados +memor.verificar = function(dir, subdir, arquivo) + + list = minetest.get_dir_list(wpath .. "/" .. dir .. "/" .. subdir) + r = false + for n, arq in ipairs(list) do + if arq == arquivo then + r = true + break + end + end + + if r then + return true + else + return false + end +end + +-- Listar +memor.listar = function(dir, subdir) + if dir == nil then + minetest.log("error", "[Memor] Diretorio inexistente (em memor.listar)") + return false + end + + if subdir then + + local list = minetest.get_dir_list(wpath .. "/" .. dir .. "/" .. subdir) + + if list == nil then + minetest.log("error", "[Memor] Impossivel listar diretorio (em memor.listar)") + return false + else + return list + end + + else + local list = minetest.get_dir_list(wpath .. "/" .. dir) + + if list == nil then + minetest.log("error", "[Memor] Impossivel listar diretorio (em memor.listar)") + return false + else + return list + end + end +end + + diff --git a/lib/memor/depends.txt b/lib/memor/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/lib/memor/init.lua b/lib/memor/init.lua new file mode 100644 index 0000000..4afcc38 --- /dev/null +++ b/lib/memor/init.lua @@ -0,0 +1,35 @@ +--[[ + Mod Memor para Minetest + Memor v1.2 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Inicializador de scripts + ]] + +-- Verifica se o mod memor original esta ativo +if minetest.get_modpath("memor") then return end + + +-- Notificador de Inicializador +local notificar = function(msg) + if minetest.setting_get("log_mods") then + minetest.debug("[MEMOR]"..msg) + end +end + +local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/lib/memor" + +-- Variavel global +memor = {} + +-- Carregar scripts +notificar("Carregando scripts...") +dofile(modpath.."/arquivo.lua") +dofile(modpath.."/consulta.lua") +dofile(modpath.."/montagem.lua") +dofile(modpath.."/online.lua") +notificar("OK") + diff --git a/lib/memor/montagem.lua b/lib/memor/montagem.lua new file mode 100644 index 0000000..15244ea --- /dev/null +++ b/lib/memor/montagem.lua @@ -0,0 +1,49 @@ +--[[ + Mod Memor para Minetest + Memor v1.2 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Montagem de bando de dados + ]] + + +-- Montar banco de dados em um mod +function memor.montar_bd(mod) + v = {} + v.mod = mod or minetest.get_current_modname() + + -- Inserir dados + v.salvar = function(v, tb, index, valor) + return memor.inserir(v.mod, tb, index, valor) + end + + -- Consultar dados + v.pegar = function(v, tb, index) + return memor.consultar(v.mod, tb, index) + end + + -- Verificar dados + v.verif = function(v, tb, index) + return memor.verificar(v.mod, tb, index) + end + + -- Remover dados + v.remover = function(v, tb, index) + return memor.deletar(v.mod, tb, index) + end + + -- Remover tabela + v.drop_tb = function(v, tb) + return memor.deletar_dir(v.mod, tb) + end + + -- Listar dados + v.listar = function(v, tb) + return memor.listar(v.mod, tb) + end + + return v +end diff --git a/lib/memor/online.lua b/lib/memor/online.lua new file mode 100644 index 0000000..6fbd7a8 --- /dev/null +++ b/lib/memor/online.lua @@ -0,0 +1,45 @@ +--[[ + Mod Memor para Minetest + Memor v1.2 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Controle de jogadores online + ]] + + +-- Controle de jogadores de cada mod +memor.online_mods = {} + +-- Montar banco de dados simples de jogadores online +function memor.online(mod) + local mod = mod or minetest.get_current_modname() + + memor.online_mods[mod] = {} + + return memor.online_mods[mod] +end + +-- Adiciona o jogador em todas listas quando entrar no servidor +minetest.register_on_joinplayer(function(player) + for mod,l in pairs(memor.online_mods) do + memor.online_mods[mod][player:get_player_name()] = {} + end +end) + +-- Remove o jogador de todas listas quando entrar no servidor +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + for mod,l in pairs(memor.online_mods) do + local np = {} + for _,p in ipairs(minetest.get_connected_players()) do + local n = p:get_player_name() + if n ~= name then + np[n] = memor.online_mods[mod][n] + end + end + memor.online_mods[mod] = np + end +end) diff --git a/me.lua b/me.lua new file mode 100644 index 0000000..bbae32f --- /dev/null +++ b/me.lua @@ -0,0 +1,58 @@ +--[[ + Mod MultiChat para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Ajuste no comando /msg + + ]] + + +local som_avisar = multichat.som_avisar + +-- Enviar mensagem para jogador +local enviar_msg = function(name, msg, falante) + local player = minetest.get_player_by_name(name) + local status = player:get_attribute("multichat_status") + + -- Verifica se o jogador está no bate-papo público + if status == nil or status == "pub" then + minetest.chat_send_player(name, "* "..falante.." "..msg) + + -- Evita avisar a si mesmo + if name ~= falante then + som_avisar(name, msg) + else + som_avisar(name) + end + + -- Verificar se está desativado + elseif status == "off" then + return + + -- Verifica se jogador está ouvindo apenas seu grupo + elseif status == "grupo" and multichat.grupos[name] then + + -- Verifica se falante está no grupo + if multichat.grupos[name][falante] then + minetest.chat_send_player(name, "* "..falante.." "..msg) + som_avisar(name, msg) + end + end + +end + +local old_func = minetest.chatcommands.me.func + +function minetest.chatcommands.me.func(name, param) + + -- Enviar chamada em todos os jogadores + for _,player in ipairs(minetest.get_connected_players()) do + local np = player:get_player_name() + enviar_msg(np, param, name) + end + +end diff --git a/menu.lua b/menu.lua new file mode 100644 index 0000000..04bb706 --- /dev/null +++ b/menu.lua @@ -0,0 +1,189 @@ +--[[ + Mod MultiChat para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Menu Multichat + + ]] + +-- Remover grupo de um jogador offline +local remover_grupo = function(name) + multichat.salas[name] = nil +end + +-- Comando de acesso ao menu +multichat.acessar_menu = function(name) + if not name then return end + local player = minetest.get_player_by_name(name) + local st = player:get_attribute("multichat_status") + + local status = "Atualmente\n" + + -- Caso esteja no Publico + if st == nil or st == "pub" then + status = status .. minetest.colorize("#00FF00", "em Publico") + + -- Caso esteja Desativado + elseif st == "off" then + status = status .. minetest.colorize("#FF0000", "Desativado") + + -- Caso esteja no Grupo + elseif st == "grupo" then + status = status .. minetest.colorize("#3366FF", "em Privado") + + -- Caso nenhuma situação prevista + else + status = status .. "Erro" + end + + -- Avisos sonoros + local st_som = player:get_attribute("multichat_som") or "true" + local st_chamada = player:get_attribute("multichat_chamada") or "true" + + minetest.show_formspec(name, "multichat:menu", "size[4,5]" + ..default.gui_bg + ..default.gui_bg_img + .."label[0,0;Meu Bate-Papo \n"..status.."]" + .."image[3,0;1,1;multichat_botao.png]" + .."checkbox[0,1;som;Som;"..st_som.."]" + .."checkbox[0,1.5;chamada;Chamada;"..st_chamada.."]" + .."button_exit[3,1.2;1,1;sair;Sair]" + .."button_exit[0,2.2;4,1;desativar;Desativar]" + .."button_exit[0,3.2;4,1;publico;Publico]" + .."button_exit[0,4.2;3.3,1;privado;Privado]" + .."image_button[3.15,4.3;0.825,0.825;default_book_written.png;grupo;]") +end + +-- Acessar menu do grupo +local acessar_menu_grupo = function(name) + + -- Prepara e armazena tabelas exibidas + local tb_grupo = multichat.grupos[name] or {} + multichat.online[name].tb_grupo = {} + local st_grupo = "" + for np,v in pairs(tb_grupo) do + if st_grupo ~= "" then st_grupo = st_grupo .. "," end + st_grupo = st_grupo .. np + table.insert(multichat.online[name].tb_grupo, np) + end + + local tb_online = minetest.get_connected_players() + multichat.online[name].tb_online = {} + local st_online = "" + for n,p in ipairs(tb_online) do + local np = p:get_player_name() + -- Remove o proprio nome da lista + if np == name then + table.remove(tb_online, n) + -- Remove nomes que estao no grupo + elseif tb_grupo[np] then + table.remove(tb_online, n) + else + if st_online ~= "" then st_online = st_online .. "," end + st_online = st_online .. np + table.insert(multichat.online[name].tb_online, np) + end + end + + minetest.show_formspec(name, "multichat:menu_grupo", "size[8,6]" + ..default.gui_bg + ..default.gui_bg_img + .."label[0,0;Meu Bate-Papo Privado]" + .."button[6.1,-0.1;2,1;voltar;Voltar]" + + .."label[0,1.1;Ignorados]" + .."textlist[0,1.6;3,4.5;online;"..st_online.."]" + + .."image[3.5,1.7;1,1;gui_furnace_arrow_bg.png^[transformR270]" + .."button[3.1,2.5;1.9,1;adicionar;Adicionar]" + + .."button[3.1,4.3;1.9,1;remover;Remover]" + .."image[3.5,5;1,1;gui_furnace_arrow_bg.png^[transformR90]" + + .."label[4.85,1.1;Conversando]" + .."textlist[4.85,1.6;3,4.5;grupo;"..st_grupo.."]" + ) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "multichat:menu" then + + -- Botao de desativar bate-papo + if fields.desativar then + player:set_attribute("multichat_status", "off") + minetest.chat_send_player(player:get_player_name(), "Bate-papo desativado") + + elseif fields.publico then + player:set_attribute("multichat_status", "pub") + minetest.chat_send_player(player:get_player_name(), "Foste para o bate-papo publico") + + elseif fields.privado then + player:set_attribute("multichat_status", "grupo") + minetest.chat_send_player(player:get_player_name(), "Foste para o bate-papo privado") + + elseif fields.grupo then + acessar_menu_grupo(player:get_player_name()) + + -- Caixas de seleção (avisos sonoros) + elseif fields.som then + player:set_attribute("multichat_som", fields.som) + elseif fields.chamada then + player:set_attribute("multichat_chamada", fields.chamada) + + end + + elseif formname == "multichat:menu_grupo" then + + -- Verifica seleções + if fields.online then + multichat.online[player:get_player_name()].sl_tb_online = string.split(fields.online, ":")[2] + elseif fields.grupo then + multichat.online[player:get_player_name()].sl_tb_grupo = string.split(fields.grupo, ":")[2] + + -- Voltar ao menu principal + elseif fields.voltar then + multichat.acessar_menu(player:get_player_name()) + return + + -- Adicionar jogador para conversar + elseif fields.adicionar then + -- Verifica se tem algum jogador na tabela + if table.maxn(multichat.online[player:get_player_name()].tb_online) == 0 then return end + + local name = player:get_player_name() + + -- Caso o grupo esteja vazio cria + if multichat.grupos[name] == nil then multichat.grupos[name] = {} end + + -- Adiciona jogador + multichat.grupos[name][multichat.online[name].tb_online[tonumber(multichat.online[name].sl_tb_online)]] = true + + -- Atualiza menu do grupo + acessar_menu_grupo(name) + + return + + -- Remover jogador + elseif fields.remover then + + -- Verifica se tem algum jogador na tabela + if table.maxn(multichat.online[player:get_player_name()].tb_grupo) == 0 then return end + + local name = player:get_player_name() + + -- Remove jogador do grupo + multichat.grupos[name][multichat.online[name].tb_grupo[tonumber(multichat.online[name].sl_tb_grupo)]] = nil + + -- Atualiza menu do grupo + acessar_menu_grupo(name) + + return + end + + end +end) + diff --git a/msg.lua b/msg.lua new file mode 100644 index 0000000..25a246c --- /dev/null +++ b/msg.lua @@ -0,0 +1,62 @@ +--[[ + Mod MultiChat para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Ajuste no comando /msg + + ]] + +local som_avisar = multichat.som_avisar + +local old_func = minetest.chatcommands.msg.func + +function minetest.chatcommands.msg.func(name, param) + local sendto, message = param:match("^(%S+)%s(.+)$") + if not sendto then + return false, "Invalid usage, see /help msg." + end + + local ouvinte = sendto + + -- Verifica o jogador pode ouvir + if minetest.player_exists(ouvinte) and minetest.get_player_by_name(ouvinte) then + local player = minetest.get_player_by_name(ouvinte) + local status = player:get_attribute("multichat_status") + + -- Verifica se o jogador está no bate-papo público + if status == nil or status == "pub" then + + -- Verificar se está desativado + elseif status == "off" then + som_avisar(name) + return true, "Message sent." -- Tenta enganar jogador que enviou a mensagem + + -- Verifica se jogador está ouvindo apenas seu grupo + elseif status == "grupo" and multichat.grupos[ouvinte] then + + -- Verifica se falante está no grupo + if multichat.grupos[name][falante] == nil then + som_avisar(name) + return true, "Message sent." -- Tenta enganar jogador que enviou a mensagem + + end + end + end + + local r, msg = old_func(name, param) + + if r == true then + if ouvinte == name then + som_avisar(name) + else + som_avisar(ouvinte, message) + som_avisar(name) + end + end + + return r, msg +end diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..9f70e71 Binary files /dev/null and b/screenshot.png differ diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..31c3d2b --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,16 @@ +# Configurações aplicaveis para o menu gráfico + +# Aparece para jogadores com o provilegio chat_admin. +multichat_admin_prefix (Prefixo usado para administradores no chat) string ADMIN + +# Aparece para jogadores com o provilegio chat_staff. +multichat_staff_prefix (Prefixo usado para moderadores no chat) string MODERADOR + +# A cada certo tempo todos os dados de bate-papo privado +# de jogadores que estejam offline sao removidos para manter a memoria +# limpa. +# Tempo dado em segundos. +multichat_tempo_verif_grupo (Tempo para verificar grupos) int 3600 + + + diff --git a/sounds/multichat_aviso.ogg b/sounds/multichat_aviso.ogg new file mode 100644 index 0000000..80efe68 Binary files /dev/null and b/sounds/multichat_aviso.ogg differ diff --git a/sounds/multichat_chamada.ogg b/sounds/multichat_chamada.ogg new file mode 100644 index 0000000..c90008e Binary files /dev/null and b/sounds/multichat_chamada.ogg differ diff --git a/textures/multichat_botao.png b/textures/multichat_botao.png new file mode 100644 index 0000000..6841fd5 Binary files /dev/null and b/textures/multichat_botao.png differ