mirror of
				https://github.com/sys4-fr/server-nalc.git
				synced 2025-10-31 20:45:22 +01:00 
			
		
		
		
	Updated chatplus mod
This commit is contained in:
		
							
								
								
									
										4
									
								
								mods/chatplus/README.md
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										4
									
								
								mods/chatplus/README.md
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @@ -1,7 +1,9 @@ | |||||||
| Chatplus | Chatplus | ||||||
| -------- | -------- | ||||||
|  |  | ||||||
| License: CC-BY-SA to Rubenwardy | License: GPL 3.0 or later. | ||||||
|  |  | ||||||
|  | Created by rubenwardy. | ||||||
|  |  | ||||||
| Commands | Commands | ||||||
| ======== | ======== | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								mods/chatplus/description.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								mods/chatplus/description.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | Adds advanced chat features such as ignoring and inboxing. | ||||||
							
								
								
									
										108
									
								
								mods/chatplus/init.lua
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										108
									
								
								mods/chatplus/init.lua
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @@ -4,12 +4,12 @@ | |||||||
| -- ========= | -- ========= | ||||||
|  |  | ||||||
| chatplus = { | chatplus = { | ||||||
| 	log_file = minetest.get_worldpath().."/chat_log.txt", | 	log_file = minetest.get_worldpath().."/chatplus-log.txt", | ||||||
| 	_defsettings = { | 	_defsettings = { | ||||||
| 		log = false, -- Set to true to log chat in a file found in the world directory. | 		log = true, | ||||||
| 		use_gui = true, | 		use_gui = true, | ||||||
| 		distance = 0, | 		distance = 0, | ||||||
| 		badwords = "" -- Words not allowed to be said in chat, separated by commas. Uncomment the code near the end to make this work. | 		badwords = "" | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -32,7 +32,7 @@ function chatplus.setting(name) | |||||||
| 	elseif chatplus._defsettings[name]~= nil then | 	elseif chatplus._defsettings[name]~= nil then | ||||||
| 		return chatplus._defsettings[name] | 		return chatplus._defsettings[name] | ||||||
| 	else | 	else | ||||||
| 		minetest.log("[chatplus] Setting chatplus_"..name.." not found.") | 		minetest.log("[Chatplus] Setting chatplus_"..name.." not found!") | ||||||
| 		return nil | 		return nil | ||||||
| 	end	 | 	end	 | ||||||
| end | end | ||||||
| @@ -49,7 +49,7 @@ function chatplus.load() | |||||||
| 	end | 	end | ||||||
| 	 | 	 | ||||||
| 	-- Load player data | 	-- Load player data | ||||||
| 	minetest.log("[chatplus] Loading data.") | 	minetest.log("[Chatplus] Loading data") | ||||||
| 	local file = io.open(minetest.get_worldpath().."/chatplus.txt", "r") | 	local file = io.open(minetest.get_worldpath().."/chatplus.txt", "r") | ||||||
| 	if file then | 	if file then | ||||||
| 		local table = minetest.deserialize(file:read("*all")) | 		local table = minetest.deserialize(file:read("*all")) | ||||||
| @@ -62,7 +62,7 @@ function chatplus.load() | |||||||
| end | end | ||||||
|  |  | ||||||
| function chatplus.save() | function chatplus.save() | ||||||
| 	minetest.log("[chatplus] Saving data.") | 	minetest.log("[Chatplus] Saving data") | ||||||
| 	 | 	 | ||||||
| 	local file = io.open(minetest.get_worldpath().."/chatplus.txt", "w") | 	local file = io.open(minetest.get_worldpath().."/chatplus.txt", "w") | ||||||
| 	if file then | 	if file then | ||||||
| @@ -77,7 +77,7 @@ function chatplus.clean_players() | |||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	minetest.log("[chatplus] Cleaning player lists.") | 	minetest.log("[Chatplus] Cleaning player lists") | ||||||
| 	for key,value in pairs(chatplus.players) do | 	for key,value in pairs(chatplus.players) do | ||||||
| 		if value.messages then | 		if value.messages then | ||||||
| 			value.inbox = value.messages | 			value.inbox = value.messages | ||||||
| @@ -88,12 +88,12 @@ function chatplus.clean_players() | |||||||
| 			(not value.inbox or #value.inbox==0) and | 			(not value.inbox or #value.inbox==0) and | ||||||
| 			(not value.ignore or #value.ignore==0) | 			(not value.ignore or #value.ignore==0) | ||||||
| 		) then | 		) then | ||||||
| 			minetest.log("Deleting blank player "..key..".") | 			minetest.log("Deleting blank player "..key) | ||||||
| 			value[key] = nil | 			value[key] = nil | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| 	chatplus.save() | 	chatplus.save() | ||||||
| 	minetest.log("[chatplus] Cleaning complete.") | 	minetest.log("[Chatplus] Clean complete") | ||||||
| end | end | ||||||
|  |  | ||||||
| function chatplus.poke(name,player) | function chatplus.poke(name,player) | ||||||
| @@ -139,16 +139,14 @@ function chatplus.send(from,msg) | |||||||
| 	-- Log chat message | 	-- Log chat message | ||||||
| 	if chatplus.log_handle ~= nil then | 	if chatplus.log_handle ~= nil then | ||||||
| 		chatplus.log_handle:write( | 		chatplus.log_handle:write( | ||||||
| 			os.date("%Y-%m-%d, %I:%M%p").. | 			os.date("%Y/%m/%d %I:%M%p").. | ||||||
| 			" | <"..from.."> ".. | 			" <"..from.."> ".. | ||||||
| 			msg.. | 			msg.. | ||||||
| 			"\r\n" | 			"\r\n" | ||||||
| 		) | 		) | ||||||
| 		chatplus.log_handle:flush() | 		chatplus.log_handle:flush() | ||||||
| 	end | 	end | ||||||
| 	 | 	 | ||||||
| 	minetest.log("action", "<"..from.."> "..msg) |  | ||||||
| 	 |  | ||||||
| 	-- Loop through senders | 	-- Loop through senders | ||||||
| 	for key,value in pairs(chatplus.loggedin) do | 	for key,value in pairs(chatplus.loggedin) do | ||||||
| 		local res = nil | 		local res = nil | ||||||
| @@ -175,19 +173,19 @@ minetest.register_on_joinplayer(function(player) | |||||||
| 	local _player = chatplus.poke(player:get_player_name(),player) | 	local _player = chatplus.poke(player:get_player_name(),player) | ||||||
|  |  | ||||||
| 	if chatplus.log_handle ~= nil then | 	if chatplus.log_handle ~= nil then | ||||||
| 		chatplus.log_handle:write(os.date("%Y-%m-%d, %I:%M%p").." O "..player:get_player_name().." joined the game.\r\n") | 		chatplus.log_handle:write(os.date("%d/%m/%Y %I:%M%p").." "..player:get_player_name().." joined\r\n") | ||||||
| 		chatplus.log_handle:flush() | 		chatplus.log_handle:flush() | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	-- Inbox stuff. | 	-- inbox stuff! | ||||||
| 	if _player.inbox and #_player.inbox>0 then | 	if _player.inbox and #_player.inbox>0 then | ||||||
| 		minetest.after(10,minetest.chat_send_player,player:get_player_name(),"("..#_player.inbox..") You have mail! Type /inbox to view them.")	 | 		minetest.after(10,minetest.chat_send_player,player:get_player_name(),"("..#_player.inbox..") You have mail! Type /inbox to recieve")	 | ||||||
| 	end | 	end | ||||||
| end) | end) | ||||||
| minetest.register_on_leaveplayer(function(player) | minetest.register_on_leaveplayer(function(player) | ||||||
| 	chatplus.poke(player:get_player_name(),"end") | 	chatplus.poke(player:get_player_name(),"end") | ||||||
| 	if chatplus.log_handle ~= nil then | 	if chatplus.log_handle ~= nil then | ||||||
| 		chatplus.log_handle:write(os.date("%Y-%m-%d, %I:%M%p").." X "..player:get_player_name().." left the game.\r\n") | 		chatplus.log_handle:write(os.date("%d/%m/%Y %I:%M%p").." "..player:get_player_name().." disconnected\r\n") | ||||||
| 		chatplus.log_handle:flush() | 		chatplus.log_handle:flush() | ||||||
| 	end | 	end | ||||||
| end) | end) | ||||||
| @@ -204,23 +202,23 @@ chatplus.register_handler(function(from,to,msg) | |||||||
| end) | end) | ||||||
|  |  | ||||||
| minetest.register_chatcommand("ignore", { | minetest.register_chatcommand("ignore", { | ||||||
| 	params = "<name>", | 	params = "name", | ||||||
| 	description = "Ignore a player", | 	description = "ignore: Ignore a player", | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		chatplus.poke(name) | 		chatplus.poke(name) | ||||||
| 		if not chatplus.players[name].ignore[param]==true then | 		if not chatplus.players[name].ignore[param]==true then | ||||||
| 			chatplus.players[name].ignore[param]=true | 			chatplus.players[name].ignore[param]=true | ||||||
| 			minetest.chat_send_player(name,param.." has been ignored.") | 			minetest.chat_send_player(name,param.." has been ignored") | ||||||
| 			chatplus.save() | 			chatplus.save() | ||||||
| 		else | 		else | ||||||
| 			minetest.chat_send_player(name,param.." is already ignored.") | 			minetest.chat_send_player(name,"Player "..param.." is already ignored.") | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| }) | }) | ||||||
|  |  | ||||||
| minetest.register_chatcommand("unignore", { | minetest.register_chatcommand("unignore", { | ||||||
| 	params = "<name>", | 	params = "name", | ||||||
| 	description = "Stop ignoring a player", | 	description = "unignore: Unignore a player", | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		chatplus.poke(name) | 		chatplus.poke(name) | ||||||
| 		if chatplus.players[name].ignore[param]==true then | 		if chatplus.players[name].ignore[param]==true then | ||||||
| @@ -228,7 +226,7 @@ minetest.register_chatcommand("unignore", { | |||||||
| 			minetest.chat_send_player(name,param.." has been unignored") | 			minetest.chat_send_player(name,param.." has been unignored") | ||||||
| 			chatplus.save() | 			chatplus.save() | ||||||
| 		else | 		else | ||||||
| 			minetest.chat_send_player(name,param.." is already unignored.") | 			minetest.chat_send_player(name,"Player "..param.." is already unignored.") | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| }) | }) | ||||||
| @@ -242,20 +240,22 @@ function chatplus.showInbox(name,forcetest) | |||||||
| 	local player = chatplus.players[name] | 	local player = chatplus.players[name] | ||||||
|  |  | ||||||
| 	if not player.inbox or #player.inbox==0 then | 	if not player.inbox or #player.inbox==0 then | ||||||
| 		minetest.chat_send_player(name,"Your inbox is empty.") | 		minetest.chat_send_player(name,"Your inbox is empty!") | ||||||
| 		return false | 		return false | ||||||
| 	end | 	end | ||||||
| 	local setting = chatplus.setting("use_gui") | 	local setting = chatplus.setting("use_gui") | ||||||
| 	if (setting == true or setting == "true" or setting == "1") and not forcetest then | 	if (setting == true or setting == "true" or setting == "1") and not forcetest then | ||||||
| 		local fs = "size[10,5]textlist[0,0;9.75,5;inbox;" | 		minetest.chat_send_player(name,"Showing your inbox to you.") | ||||||
|  | 		local fs = "size[10,8]textarea[0.25,0.25;10.15,8;inbox;You have " .. #player.inbox .. " messages in your inbox:;" | ||||||
|  |  | ||||||
| 		for i=1,#player.inbox do | 		for i=1,#player.inbox do | ||||||
| 			if i > 1 then |  | ||||||
| 				fs = fs .. "," |  | ||||||
| 			end |  | ||||||
| 			fs = fs .. minetest.formspec_escape(player.inbox[i]) | 			fs = fs .. minetest.formspec_escape(player.inbox[i]) | ||||||
|  | 			fs = fs .. "\n" | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		fs = fs .. "]" | 		fs = fs .. "]" | ||||||
| 		print(fs) | 		fs = fs .. "button[0,7.25;2,1;clear;Clear Inbox]" | ||||||
|  | 		fs = fs .. "button_exit[8.1,7.25;2,1;close;Close]" | ||||||
| 		minetest.show_formspec(name, "chatplus:inbox", fs) | 		minetest.show_formspec(name, "chatplus:inbox", fs) | ||||||
| 	else | 	else | ||||||
| 		minetest.chat_send_player(name,"("..#player.inbox..") You have mail:") | 		minetest.chat_send_player(name,"("..#player.inbox..") You have mail:") | ||||||
| @@ -268,15 +268,25 @@ function chatplus.showInbox(name,forcetest) | |||||||
| 	return true | 	return true | ||||||
| end | end | ||||||
|  |  | ||||||
|  | minetest.register_on_player_receive_fields(function(player,formname,fields) | ||||||
|  | 	if fields.clear then | ||||||
|  | 		local name = player:get_player_name() | ||||||
|  | 		chatplus.poke(name).inbox = {} | ||||||
|  | 		chatplus.save() | ||||||
|  | 		minetest.chat_send_player(name,"Inbox cleared!") | ||||||
|  | 		chatplus.showInbox(name) | ||||||
|  | 	end | ||||||
|  | end) | ||||||
|  |  | ||||||
| minetest.register_chatcommand("inbox", { | minetest.register_chatcommand("inbox", { | ||||||
| 	params = "[clear]", | 	params = "clear?", | ||||||
| 	description = "Shows your inbox", | 	description = "inbox: print the items in your inbox", | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		if param == "clear" then | 		if param == "clear" then | ||||||
| 			local player = chatplus.poke(name) | 			local player = chatplus.poke(name) | ||||||
| 			player.inbox = {} | 			player.inbox = {} | ||||||
| 			chatplus.save() | 			chatplus.save() | ||||||
| 			minetest.chat_send_player(name,"Inbox cleared.") | 			minetest.chat_send_player(name,"Inbox cleared") | ||||||
| 		elseif param == "text" or param == "txt" or param == "t" then | 		elseif param == "text" or param == "txt" or param == "t" then | ||||||
| 			chatplus.showInbox(name,true) | 			chatplus.showInbox(name,true) | ||||||
| 		else | 		else | ||||||
| @@ -286,35 +296,32 @@ minetest.register_chatcommand("inbox", { | |||||||
| }) | }) | ||||||
|  |  | ||||||
| minetest.register_chatcommand("mail", { | minetest.register_chatcommand("mail", { | ||||||
| 	params = "<name> <message>", | 	params = "name msg", | ||||||
| 	description = "Add a message to a player's inbox", | 	description = "mail: add a message to a player's inbox", | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		chatplus.poke(name) | 		chatplus.poke(name) | ||||||
| 		local to, msg = string.match(param, "([%a%d_]+) (.+)") | 		local to, msg = string.match(param, "([%a%d_]+) (.+)") | ||||||
| 		 | 		 | ||||||
| 		if not to or not msg then | 		if not to or not msg then | ||||||
| 			minetest.chat_send_player(name,"Usage: /mail <player> <message>",false) | 			minetest.chat_send_player(name,"mail: <playername> <msg>",false) | ||||||
| 			return | 			return | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		--[[ | 		minetest.log("To: "..to..", From: "..name..", MSG: "..msg) | ||||||
| 		minetest.log("To: "..to..", From: "..name..", Message: "..msg) |  | ||||||
| 		if chatplus.log_handle ~= nil then | 		if chatplus.log_handle ~= nil then | ||||||
| 			chatplus.log_handle:write(os.date("%Y-%m-%d, %I:%M%p").." @ To: "..to..", From: "..name..", Message: "..msg) | 			chatplus.log_handle:write(os.date("%d/%m/%Y %I:%M%p").." To: "..to..", From: "..name..", MSG: "..msg) | ||||||
| 			chatplus.log_handle:flush() | 			chatplus.log_handle:flush() | ||||||
| 		end | 		end | ||||||
| 		--]] |  | ||||||
| 		if chatplus.players[to] then | 		if chatplus.players[to] then | ||||||
| 			table.insert(chatplus.players[to].inbox,os.date("%Y-%m-%d, %I:%M%p").." | <"..name.."> "..msg) | 			table.insert(chatplus.players[to].inbox,os.date("%d/%m").." <"..name..">: "..msg) | ||||||
| 			minetest.chat_send_player(name,"Message sent.") | 			minetest.chat_send_player(name,"Message sent") | ||||||
| 			chatplus.save() | 			chatplus.save() | ||||||
| 		else | 		else | ||||||
| 			minetest.chat_send_player(name,to.." does not exist.") | 			minetest.chat_send_player(name,"Player "..to.." does not exist") | ||||||
| 		end | 		end | ||||||
| 	end, | 	end, | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  |  | ||||||
| minetest.register_globalstep(function(dtime) | minetest.register_globalstep(function(dtime) | ||||||
| 	chatplus.count = chatplus.count + dtime | 	chatplus.count = chatplus.count + dtime | ||||||
| 	if chatplus.count > 5 then | 	if chatplus.count > 5 then | ||||||
| @@ -351,7 +358,7 @@ minetest.register_globalstep(function(dtime) | |||||||
| 						hud_elem_type = "text", | 						hud_elem_type = "text", | ||||||
| 						name = "MailText", | 						name = "MailText", | ||||||
| 						position = {x=0.55, y=0.52}, | 						position = {x=0.55, y=0.52}, | ||||||
| 						text=#value.inbox.." /inbox", | 						text=#value.inbox, | ||||||
| 						scale = {x=1,y=1}, | 						scale = {x=1,y=1}, | ||||||
| 						alignment = {x=0.5, y=0.5}, | 						alignment = {x=0.5, y=0.5}, | ||||||
| 					})					 | 					})					 | ||||||
| @@ -362,8 +369,6 @@ minetest.register_globalstep(function(dtime) | |||||||
| 	end | 	end | ||||||
| end) | end) | ||||||
|  |  | ||||||
|  |  | ||||||
| --[[ |  | ||||||
| chatplus.register_handler(function(from,to,msg) | chatplus.register_handler(function(from,to,msg) | ||||||
| 	if chatplus.setting("distance") <= 0 then | 	if chatplus.setting("distance") <= 0 then | ||||||
| 		return nil | 		return nil | ||||||
| @@ -385,21 +390,14 @@ chatplus.register_handler(function(from,to,msg) | |||||||
| 	end | 	end | ||||||
| 	return nil | 	return nil | ||||||
| end) | end) | ||||||
| --]] |  | ||||||
|  |  | ||||||
| --[[ |  | ||||||
| chatplus.register_handler(function(from,to,msg) | chatplus.register_handler(function(from,to,msg) | ||||||
| 	local words = chatplus.setting("badwords"):split(",") | 	local words = chatplus.setting("badwords"):split(",") | ||||||
| 	for _,v in pairs(words) do | 	for _,v in pairs(words) do | ||||||
| 		if (v:trim()~="") and ( msg:find(v:trim(), 1, true) ~= nil ) then | 		if (v:trim()~="") and ( msg:find(v:trim(), 1, true) ~= nil ) then | ||||||
| 			minetest.chat_send_player(from, "Swearing is not allowed.") | 			minetest.chat_send_player(from, "Swearing is banned") | ||||||
| 			return false | 			return false | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| 	return nil | 	return nil | ||||||
| end) | end) | ||||||
| --]] |  | ||||||
|  |  | ||||||
| if minetest.setting_getbool("log_mods") then |  | ||||||
| 	minetest.log("action", "Carbone: [chatplus] loaded.") |  | ||||||
| end |  | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								mods/chatplus/textures/chatplus_mail.png
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								mods/chatplus/textures/chatplus_mail.png
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 171 B After Width: | Height: | Size: 270 B | 
		Reference in New Issue
	
	Block a user