From 8646940e06a2148d31cc7364ff06457c46164401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teodor=20Sp=C3=A6ren?= Date: Sun, 14 Oct 2012 20:26:19 +0200 Subject: [PATCH] Added licence and /msg command. --- LICENSE.txt | 26 ++++++++++++++++++++++++++ conf.lua | 11 +++++++++-- init.lua | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..8f7c046 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,26 @@ +Copyright (c) 2012, Teodor Spæren +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. \ No newline at end of file diff --git a/conf.lua b/conf.lua index dbac1dc..bcda59d 100644 --- a/conf.lua +++ b/conf.lua @@ -1,10 +1,17 @@ +-- Care about small and BIG letters? +careLetters = true + -- List command useList = true -listprivs = {shout=true} +listprivs = {shout = true} -- Kill command useKill = true -killprivs = {shout=true} +killprivs = {shout = true} + +-- MSG command +useMSG = true +msgprivs = {shout = true} --MOTD useMOTD = true diff --git a/init.lua b/init.lua index d0a3fad..714850a 100644 --- a/init.lua +++ b/init.lua @@ -7,15 +7,25 @@ function get_player_obj (name) goodname = string.match(name, "^([^ ]+) *$") if goodname == nil then print("ERROR!") - return + return nil end + -- Looping trough all the players currently online for _,player in ipairs(minetest.get_connected_players()) do - local name = player:get_player_name() + local name = player:get_player_name() + + -- Caring about letters or not? + if not careLetters then + if string.lower(name) == string.lower(goodname) then + return player + end + else if name == goodname then return player end + end end + return nil end -- !!! COMMANDS !!! --- @@ -51,6 +61,34 @@ if useKill then end, }) end + +--[[ MSG command ]]--- +if useMSG then + minetest.register_chatcommand("msg", { + params = " ", + description = "Talk to someone!", + privs = msgprivs, + func = function(name, param) + if string.match(param, "([^ ]+) (.+)") == nil then + minetest.chat_send_player(name, "Missing parameters") + return + end + + -- Generating the variables out of the parameters + local targetName, msg = string.match(param, "([^ ]+) (.+)") + target = get_player_obj(targetName) + + -- Checking if the target exists + if not target then + minetest.chat_send_player(name, "The target was not found") + return + end + + -- Sending the message + minetest.chat_send_player(target:get_player_name(), string.format("From %s: %s", name, msg)) + end, + }) +end -- !!! EVENTS !!! -- --[[ What happens when a player joins? ]]--