summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--beerchat/LICENSE165
-rw-r--r--beerchat/README.md133
-rw-r--r--beerchat/init.lua710
-rw-r--r--beerchat/mod.conf1
-rw-r--r--beerchat/sounds/beerchat_chime.oggbin0 -> 11231 bytes
-rw-r--r--beerchat/sounds/beerchat_chirp.oggbin0 -> 10382 bytes
-rw-r--r--beerchat/sounds/beerchat_utter.oggbin0 -> 25028 bytes
7 files changed, 1009 insertions, 0 deletions
diff --git a/beerchat/LICENSE b/beerchat/LICENSE
new file mode 100644
index 0000000..65c5ca8
--- /dev/null
+++ b/beerchat/LICENSE
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ 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/beerchat/README.md b/beerchat/README.md
new file mode 100644
index 0000000..cf3be00
--- /dev/null
+++ b/beerchat/README.md
@@ -0,0 +1,133 @@
+## [Mod] Beerchat [beerchat]
+[Mod] Beerchat [beerchat] is a standalone completely dependency free Minetest mod that supports chat channels/ chat rooms, colored messages, muting players, message sounds and chat shortcuts. Full list of features:
+
+* Support for chat rooms, called channels, in which members can privately chat without flooding the main channel
+* The default chat has been turned into a channel as well, called main. You can leave (and rejoin) the main channel, e.g. when you are not interested or it is too spammy
+* Extremely easy to chat in a channel, just start your message with #your channel name: (in case of spaces in the channel name) or #my_channel (no colon needed if there are no spaces in the name)
+* You can still chat the old way. Just enter your message like you used to do and it will appear in the main chat automatically (no need to prepend with #main or do other difficult things)
+* Channels can be assigned a color so messages in that channel appear in that color. This way you can easily differentiate between main channel chats and private channel chats
+* Distance based chatting, called whispering. Players out of range will not see your message, players in range will see the message in a different color. Ideal to talk to nearby people and to differentiate messages
+* Provides shortcuts: @ for PMs, # for chat room messages and $ to whisper
+* Remebers the last player or last channel a message was sent to. So at first you can @player or #my_channel and after that just use @ or # only to send to that player/ channel again
+* Uses the console/ standard chat "window" for chat messages
+* Message formats fully configurable (currently in the init.lua but really easy to do, all settings are in the top of the file and documented). You can pass parameters to the message strings as well. So if you want to strip the channel name from the main channel you can do so. You can shuffle elements around e.g. placing the channel name at the end of a message. You can add a time. You can put from_player and to_player in all messages or just a few
+* State is stored in mod storage and player attributes so they survive a server restart. E.g. channels you have created and joined will still be there after server restart. Players you have muted will also survive a server restart.
+
+Depends: none
+Requires Minetest 0.4.16 because of mod storage and player attributes support in the mod
+Attribution: Some code used from orwell's atchat: https://forum.minetest.net/viewtopic.php?f=11&t=13593
+
+Future plans:
+
+* Setting a default channel, e.g. messages typed normally will appear in the channel of your choice
+* Beerchat formspec to tweak per player settings such as enabling/ disabling sounds, managing channels, overriding colors, etc.
+* Configurable color for private messages
+* A "talk to" feature where you can send a public message but it will appear as <from_player> to <to_player>, possibly highlighting the message for that player only using a selected color. This to avoid confusion as to who the message was meant for e.g. in the case of <player01> can i use mese ; <player02> can you give me some diamonds ; <player03> yes
+* Shout with ! support
+* Externalizing the settings from the init.lua and support using configuration file and the main minetest.conf
+* Improved channel management by server administrator, e.g. to avoid wild growth of channels. Adding a last used timestamp to identify channel that have not been used in a long time. Automatic cleanup of old unused channels
+* Message highlighting when your name is mentioned in a chat message or when a message contains a certain string a la chat2
+* Option to place certain messages in the HUD a la chat2 and allow users to enable/ disable this feature via preferences formspec on a per message type (PM, channel, name mentions, etc.) basis. Even easier to identify messages of interest
+
+## Using the Mod In-Game
+### Channel Management
+Channels are like chat rooms. Messages in channels are only sent to the members of that channel. They can be made private by password protecting it and a color to differentiate from the main chat. Channel management is done via chat commands. Parameters to these commands are comma separated. To create a channel, use the /create_channel or /cc command and supply channel name, optional password and optional color (defaults to white). Channels can be deleted via /delete_channel or /dc and this can only be done by the channel owner. The owner does not need to supply the channel's password to delete the channel. The /my_channels or /mc command shows the channels you are owner/ member of in json format. Some channel management examples below:
+
+ /create_channel my super secret room,mysecretpass01,#00ffff
+ /create_channel my public room
+ /create_channel my red colored room without password,,#ff0000
+ /delete_channel my super secret room
+
+To join a channel use the /join_channel or /jc command which takes the channel name and optionally a password. To leave a channel do /leave_channel or /lc and supply the channel name. If you are the owner of a channel, you can send an invite to a player using the /invite_channel or /ic command which will then send the channel name and password to the invited player.
+
+ /jc someone else's channel,pass01
+ /lc channel i got bored with
+ /ic my private room,NicePlayer01
+
+### Channel Chats
+When you chat normally, everything is written to the channel called main. Chats to main are prefixed with |#main| and given the default main channel color white. In order to write to a specific channel you have joined, start your chat with a #, then the channel name and then a colon. Messages sent this way will only be seen by the other members of the channel (unless someone has muted the sender, see also muting below). If you want to send another message to the same channel you can start it with just the # (without channel name):
+
+ #my channel: This will be sent to my channel
+ # This will also be sent to my channel as that was the last one used
+ #jokes In this case a colon is not needed as there is no space in the channel name
+ # We have now switched to the jokes channel so this will be sent there
+
+These "hash chats" are prefixed with |#channel name| and appear in the color of that particular channel as specified during channel creation (or default white if no color was supplied at that time).
+
+NOTE: You can leave the main channel! So if things are getting spammy, besides muting people (see below) you can leave the main channel and just chat in the other channels you are a member of.
+
+Muting Players
+To mute a player, just do /mute or /ignore player name. Unmuting is done via /unmute or /unignore player name. E.g.:
+
+ /mute Griefer666
+ /unmute NicePlayerAfterAll
+
+### Private Messages
+You can send private messages the old way using /msg but there is now a shorthand as well using the @ sign (like the at chat mod, code was inspired by this mod). To at chat a PM, just supply the user name or comma separated names you want to send the PM to. If you start the message with just @ without supplying player names, it will send the message to the last user(s) you sent a PM to, e.g.:
+
+ @JohnDoe How's life?
+ @JohnDoe,MaryJane Shall we have a party at spawn >8-)))
+ @ Hey John, Mary, I will be at spawn in 5 minutes ok?
+
+### Whispering
+You can whisper by starting your message with the $ sign. Only players within a range of 32 blocks will then be able to see your chat (which happens to be the same maximum range of seeing other players). The dollar chat will be sent to the main channel in a grey color. If you want to dollar chat with a larger or shorter range, you can supply the radius straight after the dollar. The maximum radius is (for now) 200 blocks (or you might just start using normal chat or use channels if you don't want others to hear you). Whispering is just there so that when used, chats from nearby players are colored differently (light grey) and can be more easily distinguished from the chat of players further away. The below dollar chats whisper the message to 16, 32 and 64 nodes respectively.
+
+ $16 Can you hear me major Tom
+ $ Can you hear me now, major Tom?
+ $64 Can you heeeeeeeeeere I am floating round my tin can
+
+## Mod Settings, Configuration and Customization
+### Configuration
+Configuration is currently done in the init.lua so make the changes in there. For the main channel (channel where messages are sent by default if no channel was specified), you can change the name, the owner and the color. Colors are defined in hexadecimal and start with a #.
+
+ local main_channel_name = "main" -- The main channel is the one you send messages to when no channel is specified
+ local main_channel_owner = "ADMIN" -- The owner of the main channel, usually ADMIN
+ local main_channel_color = "#ffffff" -- The color in hex of the main channel
+
+The default channel color specifies the color of channels for which no color was passed as argument when the channel was created.
+
+ local default_channel_color = "#ffffff" -- The default color of channels when no color is specified
+
+You can enable or disable sounds and when sounds are enabled you can specify what sounds to play by changing the sound file strings:
+
+ local enable_sounds = true -- Global flag to enable/ disable sounds
+
+Example of a sound string below, make sure that you specify the sound file here without the .ogg extension and that you have the sound file stored in the sounds directory and with the .ogg extension
+
+ local private_message_sound = "beerchat_chime" -- Sound when you receive a private message
+
+Whisper settings control the range controlled dollar chats. The default range is the range used when you do not pass a radius when whispering. You cannot specify a radius larger than the max range. If you would like to be able to whisper over larger distances, you can increase the value of 200 to something higher. The whisper color can be used to visually differentiate whispers from the normal chats. Please note that whispering is done in the main channel.
+
+ local whisper_default_range = 32
+ local whisper_max_range = 200
+ local whisper_color = "#aaaaaa"
+
+### Customizing the Message Formats
+In the settings section in the init.lua you can customize formatting of the messages. As you can see, parameters can be specified using ${parameter}:
+
+ local main_channel_message_string = "|#${channel_name}| <${from_player}> ${message}"
+
+You can remove the |#main| from main channel chats by removing the ${channel_name} parameter from the above string. This would format main channel messages using the default chat format from Minetest:
+
+ local main_channel_message_string = "<${from_player}> ${message}"
+
+The use of parameters not only allows you to add or remove elements, it also allows you to move elements around in the message string. E.g. to move the channel name to the end of the message:
+
+ local main_channel_message_string = "<${from_player}> ${message} |#${channel_name}|"
+
+The following parameters can be used in the message strings:
+* ${channel_name} name of the channel
+* ${channel_owner} owner of the channel
+* ${channel_password} password to use when joining the channel, used e.g. for invites
+* ${from_player} the player that is sending the message
+* ${to_player} player to which the message is sent, will contain multiple player names e.g. when sending a PM to multiple players
+* ${message} the actual message that is to be sent
+* ${time} the current time in 24 hour format, as returned from os.date("%X")
+
+You can completely customize the formatting of the chat system to your liking, e.g. if you do not like the default use of the | character around channel names, you can change this into whatever you like. The below example uses [ and ] around the channel name in the channel message strings:
+
+ local channel_message_string = "[#${channel_name}] <${from_player}> ${message}"
+ local main_channel_message_string = "[#${channel_name}] <${from_player}> ${message}"
+
+### About the Code
+Be warned, the code is not pretty and even though it was refactored after spinning it off from the beerarchy subgame, it may need quite some more refactoring. And it would be nicer if it actually supplied an API, but oh well it was hacked together in 2-3 days. Also, it requires Minetest 0.4.16 as it uses both mod storage and player attributes to keep track of the channels and muted players. Otherwise, the code *should* work pretty much out of the box. However be careful when running this mod together with other chat mods, as they could very likely interfere with each other. Have fun and let me know in case of issues!
diff --git a/beerchat/init.lua b/beerchat/init.lua
new file mode 100644
index 0000000..2d72304
--- /dev/null
+++ b/beerchat/init.lua
@@ -0,0 +1,710 @@
+local mod_storage = minetest.get_mod_storage()
+local channels = {}
+
+--
+-- Mod settings -- Change these to your liking
+--
+local main_channel_name = "main" -- The main channel is the one you send messages to when no channel is specified
+local main_channel_owner = "gabriel" -- The owner of the main channel, usually ADMIN
+local main_channel_color = "#ffffff" -- The color in hex of the main channel
+
+local default_channel_color = "#ffffff" -- The default color of channels when no color is specified
+
+local enable_sounds = false -- Global flag to enable/ disable sounds
+local channel_management_sound = "beerchat_chirp" -- General sound when managing channels like /cc, /dc etc
+local join_channel_sound = "beerchat_chirp" -- Sound when you join a channel
+local leave_channel_sound = "beerchat_chirp" -- Sound when you leave a channel
+local channel_invite_sound = "beerchat_chirp" -- Sound when sending/ receiving an invite to a channel
+local channel_message_sound = "beerchat_chime" -- Sound when a message is sent to a channel
+local private_message_sound = "beerchat_chime" -- Sound when you receive a private message
+local self_message_sound = "beerchat_utter" -- Sound when you send a private message to yourself
+
+local whisper_default_range = 32 -- Default whisper range when whispering without specifying a radius
+local whisper_max_range = 200 -- Maximum whisper range that can be specified when whispering
+local whisper_color = "#aaaaaa" -- Whisper color override
+
+-- Message string formats -- Change these if you would like different formatting
+--
+-- These can be changed to show "~~~#mychannel~~~ <player01> message" instead of "|#mychannel| or any
+-- other format you like such as removing the channel name from the main channel, putting channel or
+-- player names at the end of the chat message, etc.
+--
+-- The following parameters are available and can be specified :
+-- ${channel_name} name of the channel
+-- ${channel_owner} owner of the channel
+-- ${channel_password} password to use when joining the channel, used e.g. for invites
+-- ${from_player} the player that is sending the message
+-- ${to_player} player to which the message is sent, will contain multiple player names e.g. when sending a PM to multiple players
+-- ${message} the actual message that is to be sent
+-- ${time} the current time in 24 hour format, as returned from os.date("%X")
+--
+local channel_prefix = "|#${channel_name}| "
+local main_prefix = ""
+local channel_invitation_string = channel_prefix.."Channel invite from (${from_player}), to join the channel, do /jc ${channel_name} ${channel_password} after which you can send messages to the channel via #${channel_name}: message"
+local channel_invited_string = channel_prefix.."Invite sent to ${to_player}"
+local channel_created_string = channel_prefix.."Channel created"
+local channel_deleted_string = channel_prefix.."Channel deleted"
+local channel_joined_string = channel_prefix.."Joined channel"
+local channel_left_string = channel_prefix.."Left channel"
+local channel_already_deleted_string = channel_prefix.."Channel seems to have already been deleted, will unregister channel from your list of channels"
+local private_message_string = "[DM] from (${from_player}) ${message}"
+local self_message_string = "(${from_player} utters to him/ herself) ${message}"
+local private_message_sent_string = "[DM] sent to @(${to_player}) ${message}"
+local me_message_string = "* ${from_player} ${message}"
+local message_string = "<${from_player}> ${message}"
+local whisper_string = "<${from_player}> whispers: ${message}"
+
+beerchat = {}
+
+beerchat.get_channel_members= function (channel_name)
+ local members = {}
+ for _,player in ipairs(minetest.get_connected_players()) do
+ local target = player:get_player_name()
+ if playersChannels[target][channel_name] then
+ members[#members+1] = target
+ end
+ end
+ return members
+end
+
+beerchat.log = function (typ, msg)
+ minetest.log("action", typ..": "..minetest.strip_colors(msg))
+end
+
+beerchat.send_message= function (channel_name, name, str, message ,sound)
+ local msg
+
+ if channel_name == main_channel_name then
+ msg = format_message(main_prefix .. str, { channel_name = channel_name, from_player = name, message = message })
+ else
+ msg = format_message(channel_prefix .. str, { channel_name = channel_name, from_player = name, message = message })
+ end
+ beerchat.log("CHAT", msg)
+ for _,player in ipairs(minetest.get_connected_players()) do
+ local target = player:get_player_name()
+ -- Checking if the target is in this channel
+ if playersChannels[target][channel_name] then
+ if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
+ minetest.chat_send_player(target, msg)
+ end
+ end
+ end
+end
+
+
+function format_message(s, tab)
+ local owner
+ local password
+ local color = default_channel_color
+
+ if tab.channel_name and channels[tab.channel_name] then
+ owner = channels[tab.channel_name].owner
+ password = channels[tab.channel_name].password
+ color = channels[tab.channel_name].color
+ end
+
+ if tab.color then
+ color = tab.color
+ end
+
+ local params = {
+ channel_name = tab.channel_name,
+ channel_owner = owner,
+ channel_password = password,
+ from_player = tab.from_player,
+ to_player = tab.to_player,
+ message = tab.message,
+ time = os.date("%X")
+ }
+ return string.char(0x1b).."(c@"..color..")"..format_string(s, params)
+end
+
+function format_string(s, tab)
+ return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
+end
+
+if mod_storage:get_string("channels") == "" then
+ minetest.log("action", "[beerchat] One off initializing mod storage")
+ channels[main_channel_name] = { owner = main_channel_owner, color = main_channel_color }
+ mod_storage:set_string("channels", minetest.write_json(channels))
+end
+
+channels = minetest.parse_json(mod_storage:get_string("channels"))
+channels[main_channel_name] = { owner = main_channel_owner, color = main_channel_color }
+
+playersChannels = {}
+local currentPlayerChannel = {}
+
+beerchat.is_moderator = function(pname)
+ local has = minetest.check_player_privs(pname, { kick = true })
+ return has
+end
+
+beerchat.mod_message = function(pname, prefix, color, text_color ,message)
+ local msg = minetest.colorize("#ccf", "[ "..pname.." ] ").. minetest.colorize(color, prefix..": ") ..minetest.colorize(text_color,message)
+ beerchat.log("CHAT", msg)
+ minetest.chat_send_all(msg)
+end
+
+beerchat.get_current_channel = function(pname)
+ local channel_name = currentPlayerChannel[pname]
+ if not channels[channel_name] then
+ minetest.chat_send_player(pname, "Channel "..channel_name.." does not exist, switching back to "..main_channel_name..". Please resend your message")
+ currentPlayerChannel[pname] = main_channel_name
+ minetest.get_player_by_name(pname):set_attribute("beerchat:current_channel", main_channel_name)
+ return main_channel_name
+ end
+ return channel_name
+end
+
+
+minetest.register_on_joinplayer(function(player)
+ local str = player:get_attribute("beerchat:channels")
+ if str and str ~= "" then
+ playersChannels[player:get_player_name()] = {}
+ playersChannels[player:get_player_name()] = minetest.parse_json(str)
+ else
+ playersChannels[player:get_player_name()] = {}
+ playersChannels[player:get_player_name()][main_channel_name] = "joined"
+ player:set_attribute("beerchat:channels", minetest.write_json(playersChannels[player:get_player_name()]))
+ end
+
+ local current_channel = player:get_attribute("beerchat:current_channel")
+ if current_channel and current_channel ~= "" then
+ currentPlayerChannel[player:get_player_name()] = current_channel
+ else
+ currentPlayerChannel[player:get_player_name()] = main_channel_name
+ end
+
+end)
+
+minetest.register_on_leaveplayer(function(player)
+ playersChannels[player:get_player_name()] = nil
+ atchat_lastrecv[player:get_player_name()] = nil
+ currentPlayerChannel[player:get_player_name()] = nil
+end)
+
+local create_channel = {
+ params = "<Channel Name> <Password (optional)> <Color (optional, default is #ffffff)>",
+ description = "Create a channel named <Channel Name> with optional <Password> and hexadecimal <Color> "..
+ "starting with # (e.g. #00ff00 for green). Use spaces to separate the arguments.",
+ func = function(lname, param)
+ local lowner = lname
+
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum"
+ end
+
+ local str = string.split(param, " ")
+ if #str > 3 then
+ return false, "ERROR: Invalid number of arguments. 4 parameters passed, maximum of 3 allowed: <Channel Name> <Password> <Color>"
+ end
+
+ local lchannel_name = string.trim(str[1])
+ if lchannel_name == "" then
+ return false, "ERROR: You must supply a channel name"
+ end
+
+ if lchannel_name == main_channel_name then
+ return false, "ERROR: You cannot use channel name \""..main_channel_name.."\""
+ end
+
+ if channels[lchannel_name] then
+ return false, "ERROR: Channel "..lchannel_name.." already exists, owned by player "..channels[lchannel_name].owner
+ end
+
+ local arg2 = str[2]
+ local lcolor = default_channel_color
+ local lpassword = ""
+
+ if arg2 then
+ if string.sub(arg2, 1, 1) ~= "#" then
+ lpassword = arg2
+ else
+ lcolor = string.lower(str[2])
+ end
+ end
+
+ if #str == 3 then
+ lcolor = string.lower(str[3])
+ end
+
+ channels[lchannel_name] = { owner = lowner, name = lchannel_name, password = lpassword, color = lcolor }
+ mod_storage:set_string("channels", minetest.write_json(channels))
+
+ playersChannels[lowner][lchannel_name] = "owner"
+ minetest.get_player_by_name(lowner):set_attribute("beerchat:channels", minetest.write_json(playersChannels[lowner]))
+ if enable_sounds then
+ minetest.sound_play(channel_management_sound, { to_player = lowner, gain = 1.0 } )
+ end
+ minetest.chat_send_player(lowner, format_message(channel_created_string, { channel_name = lchannel_name }))
+
+ return true
+ end
+}
+
+local delete_channel = {
+ params = "<Channel Name>",
+ description = "Delete channel named <Channel Name>. You must be the owner of the channel or you are not allowed to delete the channel",
+ func = function(name, param)
+ local owner = name
+
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the channel name"
+ end
+
+ if param == main_channel_name then
+ return false, "ERROR: Cannot delete the main channel!!"
+ end
+
+ if not channels[param] then
+ return false, "ERROR: Channel "..param.." does not exist"
+ end
+
+ if name ~= channels[param].owner then
+ return false, "ERROR: You are not the owner of channel "..param
+ end
+
+ local color = channels[param].color
+ channels[param] = nil
+ mod_storage:set_string("channels", minetest.write_json(channels))
+
+ playersChannels[name][param] = nil
+ minetest.get_player_by_name(name):set_attribute("beerchat:channels", minetest.write_json(playersChannels[name]))
+
+ if enable_sounds then
+ minetest.sound_play(channel_management_sound, { to_player = name, gain = 1.0 } )
+ end
+
+ minetest.chat_send_player(name, format_message(channel_deleted_string, { channel_name = param, color = color }))
+
+ return true
+
+ end
+}
+
+local function pp(tab)
+ -- pretty print
+ ret = ""
+ for k,v in pairs(tab) do
+ ret = ret.."\n"..k..":\t"..v
+ end
+ return ret
+end
+
+local my_channels = {
+ params = "<Channel Name optional>",
+ description = "List the channels you have joined or are the owner of, or show channel information when passing channel name as argument",
+ func = function(name, param)
+ if not param or param == "" then
+ minetest.chat_send_player(name, pp(playersChannels[name]))
+ else
+ if playersChannels[name][param] then
+ minetest.chat_send_player(name, pp(channels[param]))
+ else
+ minetest.chat_send_player(name, "ERROR: Channel not in your channel list")
+ return false
+ end
+ end
+ return true
+ end
+}
+
+local join_channel = {
+ params = "<Channel Name> <Password (only mandatory if channel was created using a password)>",
+ description = "Join channel named <Channel Name>. After joining you will see messages sent to that channel (in addition to the other channels you have joined)",
+ func = function(name, param)
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum"
+ end
+
+ local str = string.split(param, " ")
+ local channel_name = str[1]
+
+ if not channels[channel_name] then
+ return false, "ERROR: Channel "..channel_name.." does not exist"
+ end
+
+ if playersChannels[name][channel_name] then
+ return false, "ERROR: You already joined "..channel_name..", no need to rejoin"
+ end
+
+ if channels[channel_name].password and channels[channel_name].password ~= "" then
+ if #str == 1 then
+ return false, "ERROR: This channel requires that you supply a password. Supply it in the following format: /jc my channel password01"
+ end
+ if str[2] ~= channels[channel_name].password then
+ return false, "ERROR: Invalid password"
+ end
+ end
+
+ playersChannels[name][channel_name] = "joined"
+ minetest.get_player_by_name(name):set_attribute("beerchat:channels", minetest.write_json(playersChannels[name]))
+ if enable_sounds then
+ minetest.sound_play(join_channel_sound, { to_player = name, gain = 1.0 } )
+ end
+ minetest.chat_send_player(name, format_message(channel_joined_string, { channel_name = channel_name }))
+
+ return true
+
+ end
+}
+
+local leave_channel = {
+ params = "<Channel Name>",
+ description = "Leave channel named <Channel Name>. When you leave the channel you can no longer send/ receive messages from that channel. NOTE: You can also leave the main channel",
+ func = function(name, param)
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the channel name"
+ end
+
+ local channel_name = param
+
+ if not playersChannels[name][channel_name] then
+ return false, "ERROR: You are not member of "..channel_name..", no need to leave"
+ end
+
+ playersChannels[name][channel_name] = nil
+ minetest.get_player_by_name(name):set_attribute("beerchat:channels", minetest.write_json(playersChannels[name]))
+
+ if enable_sounds then
+ minetest.sound_play(leave_channel_sound, { to_player = name, gain = 1.0 } )
+ end
+ if not channels[channel_name] then
+ minetest.chat_send_player(name, format_message(channel_already_deleted_string, { channel_name = channel_name }))
+ else
+ minetest.chat_send_player(name, format_message(channel_left_string, { channel_name = channel_name }))
+ end
+
+ return true
+
+ end
+}
+
+local invite_channel = {
+ params = "<Channel Name> <Player Name>",
+ description = "Invite player named <Player Name> to channel named <Channel Name>. You must be the owner of the channel in order to do invites",
+ func = function(name, param)
+ local owner = name
+
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the channel name and the player name"
+ end
+
+ local channel_name, player_name = string.match(param, "(%S+)%s+(.*)")
+
+ if not channel_name or channel_name == "" then
+ return false, "ERROR: Channel name is empty"
+ end
+
+ if not player_name or player_name == "" then
+ return false, "ERROR: Player name not supplied or empty"
+ end
+
+ if not channels[channel_name] then
+ return false, "ERROR: Channel "..channel_name.." does not exist"
+ end
+
+ if name ~= channels[channel_name].owner then
+ return false, "ERROR: You are not the owner of channel "..param
+ end
+
+ if not minetest.get_player_by_name(player_name) then
+ return false, "ERROR: "..player_name.." does not exist or is not online"
+ else
+ if not minetest.get_player_by_name(player_name):get_attribute("beerchat:muted:"..name) then
+ if enable_sounds then
+ minetest.sound_play(channel_invite_sound, { to_player = player_name, gain = 1.0 } )
+ end
+ -- Sending the message
+ minetest.chat_send_player(player_name, format_message(channel_invitation_string, { channel_name = channel_name, from_player = name }))
+ end
+ if enable_sounds then
+ minetest.sound_play(channel_invite_sound, { to_player = name, gain = 1.0 } )
+ end
+ minetest.chat_send_player(name, format_message(channel_invited_string, { channel_name = channel_name, to_player = player_name }))
+ end
+
+ return true
+ end
+}
+
+local mute_player = {
+ params = "<Player Name>",
+ description = "Mute a player. After muting a player, you will no longer see chat messages of this user, regardless of what channel his user sends messages to",
+ func = function(name, param)
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the name of the user to mute"
+ end
+
+ minetest.get_player_by_name(name):set_attribute("beerchat:muted:"..param, "true")
+ minetest.chat_send_player(name, "Muted player "..param)
+
+ return true
+
+ end
+}
+
+local unmute_player = {
+ params = "<Player Name>",
+ description = "Unmute a player. After unmuting a player, you will again see chat messages of this user",
+ func = function(name, param)
+ if not param or param == "" then
+ return false, "ERROR: Invalid number of arguments. Please supply the name of the user to mute"
+ end
+
+ minetest.get_player_by_name(name):set_attribute("beerchat:muted:"..param, nil)
+ minetest.chat_send_player(name, "Unmuted player "..param)
+
+ return true
+
+ end
+}
+
+local mod_info = {
+ params = "<message>",
+ description = "Send a moderator message",
+ privs = { kick = true },
+ func = function(name, param)
+ beerchat.mod_message(name, "MODERATOR INFO", "#d0ff00", "#dfdfff",param)
+ end
+}
+local mod_warning = {
+ params = "<message>",
+ description = "Send a moderator warning",
+ privs = { kick = true },
+ func = function(name, param)
+ beerchat.mod_message(name, "MODERATOR WARNING", "#ffdf00", "#ff7fff", param)
+ end
+}
+
+
+minetest.register_chatcommand("cc", create_channel)
+minetest.register_chatcommand("create_channel", create_channel)
+minetest.register_chatcommand("dc", delete_channel)
+minetest.register_chatcommand("delete_channel", delete_channel)
+
+minetest.register_chatcommand("mc", my_channels)
+minetest.register_chatcommand("my_channels", my_channels)
+
+minetest.register_chatcommand("mi", mod_info)
+minetest.register_chatcommand("mw", mod_warning)
+
+minetest.register_chatcommand("jc", join_channel)
+minetest.register_chatcommand("join_channel", join_channel)
+minetest.register_chatcommand("lc", leave_channel)
+minetest.register_chatcommand("leave_channel", leave_channel)
+minetest.register_chatcommand("ic", invite_channel)
+minetest.register_chatcommand("invite_channel", invite_channel)
+
+minetest.register_chatcommand("mute", mute_player)
+minetest.register_chatcommand("ignore", mute_player)
+minetest.register_chatcommand("unmute", unmute_player)
+minetest.register_chatcommand("unignore", unmute_player)
+
+-- @ chat a.k.a. at chat/ PM chat code, to PM players using @player1 only you can read this player1!!
+atchat_lastrecv = {}
+
+beerchat.send_pm = function(name, players, msg)
+ if players and msg then
+ if msg == "" then
+ minetest.chat_send_player(name, "Please enter the direct message you would like to send")
+ else
+ if players == "" then--reply
+ -- We need to get the target
+ players = atchat_lastrecv[name]
+ end
+ if players and players ~= "" then
+ local atleastonesent = false
+ local successplayers = ""
+ for target in string.gmatch(players..",", "([^,]+),") do
+ -- Checking if the target exists
+ if not minetest.get_player_by_name(target) then
+ minetest.chat_send_player(name, ""..target.." is not online")
+ else
+ if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
+ if target ~= name then
+ -- Sending the message
+ minetest.chat_send_player(target, format_message(private_message_string, { from_player = name, message = msg }))
+ if enable_sounds then
+ minetest.sound_play(private_message_sound, { to_player = target, gain = 1.0 } )
+ end
+ else
+ minetest.chat_send_player(target, format_message(self_message_string, { from_player = name, message = msg }))
+ if enable_sounds then
+ minetest.sound_play(self_message_sound, { to_player = target, gain = 1.0 } )
+ end
+ end
+ end
+ atleastonesent = true
+ successplayers = successplayers..target..","
+ end
+ end
+ -- Register the chat in the target persons last spoken to table
+ atchat_lastrecv[name] = players
+ if atleastonesent then
+ successplayers = successplayers:sub(1, -2)
+ beerchat.log("DM", "from "..name.." sent to @("..successplayers.."): "..msg)
+ if (successplayers ~= name) then
+ minetest.chat_send_player(name, format_message(private_message_sent_string, { to_player = successplayers, message = msg }))
+ end
+ end
+ else
+ minetest.chat_send_player(name, "You have not sent direct messages to anyone yet, please specify player names to send message to")
+ end
+ end
+ return true
+ end
+end
+
+minetest.register_on_chat_message(function(name, message)
+ local raw_msg = minetest.strip_colors(message)
+ local players, msg = string.match(raw_msg, "^@([^%s:]*)[%s:](.*)")
+ return beerchat.send_pm(name,players,msg)
+end)
+
+local msg_override = {
+ params = "<Player Name> <Message>",
+ description = "Send direct message to player, for compatibility with the old chat command but with new style chat muting support "..
+ "(players will not receive your message if they muted you) and multiple (comma separated) player support",
+ func = function(name, param)
+ local players, msg = string.match(param, "^(.-) (.*)")
+ beerchat.send_pm(name,players,msg)
+ return true
+ end
+}
+
+minetest.register_chatcommand("msg", msg_override)
+
+local me_override = {
+ params = "<Message>",
+ description = "Send message in the \"* player message\" format, e.g. /me eats pizza becomes |#"..main_channel_name.."| * Player01 eats pizza",
+ func = function(name, param)
+ local msg = param
+ local channel_name = beerchat.get_current_channel(name)
+ if not channels[channel_name] then
+ minetest.chat_send_player(name, "Channel "..channel_name.." does not exist")
+ elseif msg == "" then
+ minetest.chat_send_player(name, "Please enter the message you would like to send to the channel")
+ elseif not playersChannels[name][channel_name] then
+ minetest.chat_send_player(name, "You need to join this channel in order to be able to send messages to it")
+ else
+ beerchat.send_message(channel_name, name, me_message_string, msg)
+ end
+ return true
+ end
+}
+
+minetest.register_chatcommand("me", me_override)
+
+-- # chat a.k.a. hash chat/ channel chat code, to send messages in chat channels using # e.g. #my channel: hello everyone in my channel!
+hashchat_lastrecv = {}
+
+minetest.register_on_chat_message(function(name, message)
+ local raw_msg = minetest.strip_colors(message)
+ local channel_name, msg = string.match(raw_msg, "^#(.-): (.*)")
+ if not channels[channel_name] then
+ channel_name, msg = string.match(raw_msg, "^#(.-) (.*)")
+ end
+ if channel_name == "" then
+ channel_name = hashchat_lastrecv[name]
+ end
+
+ if channel_name and msg then
+ if not channels[channel_name] then
+ minetest.chat_send_player(name, "Channel "..channel_name.." does not exist. Make sure the channel still "..
+ "exists and you format its name properly, e.g. #channel message or #my channel: message")
+ elseif msg == "" then
+ minetest.chat_send_player(name, "Please enter the message you would like to send to the channel")
+ elseif not playersChannels[name][channel_name] then
+ minetest.chat_send_player(name, "You need to join this channel in order to be able to send messages to it")
+ else
+ if channel_name == "" then--use last used channel
+ -- We need to get the target
+ channel_name = hashchat_lastrecv[name]
+ end
+ if channel_name and channel_name ~= "" then
+ beerchat.send_message(channel_name, name, message_string, msg)
+ -- Register the chat in the target persons last spoken to table
+ hashchat_lastrecv[name] = channel_name
+ else
+ return false
+ end
+ end
+ return true
+ else
+ channel_name = string.match(raw_msg, "^#(.*)")
+ if channel_name then
+ if not channels[channel_name] then
+ minetest.chat_send_player(name, "Channel "..channel_name.." does not exist")
+ elseif not playersChannels[name][channel_name] then
+ minetest.chat_send_player(name, "You need to join this channel in order to be able to switch to it")
+ else
+ currentPlayerChannel[name] = channel_name
+ minetest.get_player_by_name(name):set_attribute("beerchat:current_channel", channel_name)
+ if channel_name == main_channel_name then
+ minetest.chat_send_player(name, "Switched to channel "..channel_name..", messages will now be sent to this channel")
+ else
+ minetest.chat_send_player(name, "Switched to channel "..channel_name..", messages will now be sent to this channel. To switch back "..
+ "to the main channel, type #"..main_channel_name)
+ end
+
+ if enable_sounds then
+ minetest.sound_play(channel_management_sound, { to_player = name, gain = 1.0 } )
+ end
+ end
+ return true
+ end
+ end
+end)
+
+-- $ chat a.k.a. dollar chat code, to whisper messages in chat to nearby players only using $, optionally supplying a radius e.g. $32 Hello
+minetest.register_on_chat_message(function(name, message)
+ local raw_msg = minetest.strip_colors(message)
+ local dollar, sradius, msg = string.match(raw_msg, "^($)(.-) (.*)")
+ if dollar == "$" then
+ local radius = tonumber(sradius)
+ if not radius then
+ radius = whisper_default_range
+ end
+
+ if radius > whisper_max_range then
+ minetest.chat_send_player(name, "You cannot whisper outside of a radius of "..whisper_max_range.." blocks")
+ elseif msg == "" then
+ minetest.chat_send_player(name, "Please enter the message you would like to whisper to nearby players")
+ else
+ local pl = minetest.get_player_by_name(name)
+ local all_objects = minetest.get_objects_inside_radius({x=pl:getpos().x, y=pl:getpos().y, z=pl:getpos().z}, radius)
+
+ for _,player in ipairs(all_objects) do
+ if player:is_player() then
+ local target = player:get_player_name()
+ -- Checking if the target is in this channel
+ if playersChannels[target][main_channel_name] then
+ if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
+ minetest.chat_send_player(target, format_message(whisper_string, {
+ channel_name = main_channel_name, from_player = name, message = msg, color = whisper_color
+ }))
+ end
+ end
+ end
+ end
+ return true
+ end
+ end
+end)
+
+minetest.register_on_chat_message(function(name, message)
+ channel_name = beerchat.get_current_channel(name)
+ if msg == "" then
+ minetest.chat_send_player(name, "Please enter the message you would like to send to the channel")
+ elseif not playersChannels[name][channel_name] then
+ minetest.chat_send_player(name, "You need to join this channel in order to be able to send messages to it")
+ else
+ beerchat.send_message(channel_name, name, message_string, message)
+ end
+ return true
+end)
+
+
+
diff --git a/beerchat/mod.conf b/beerchat/mod.conf
new file mode 100644
index 0000000..7f16cbe
--- /dev/null
+++ b/beerchat/mod.conf
@@ -0,0 +1 @@
+name=beerchat
diff --git a/beerchat/sounds/beerchat_chime.ogg b/beerchat/sounds/beerchat_chime.ogg
new file mode 100644
index 0000000..9685b3f
--- /dev/null
+++ b/beerchat/sounds/beerchat_chime.ogg
Binary files differ
diff --git a/beerchat/sounds/beerchat_chirp.ogg b/beerchat/sounds/beerchat_chirp.ogg
new file mode 100644
index 0000000..8a1630a
--- /dev/null
+++ b/beerchat/sounds/beerchat_chirp.ogg
Binary files differ
diff --git a/beerchat/sounds/beerchat_utter.ogg b/beerchat/sounds/beerchat_utter.ogg
new file mode 100644
index 0000000..f27fdec
--- /dev/null
+++ b/beerchat/sounds/beerchat_utter.ogg
Binary files differ