Switch on and off announcer messages.
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Switch on and off announcer messages.

Started by NemeziS, 26 February, 2005, 21:32:07

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NemeziS

Hi!

I have already created this post, but nobody helped me that time.

I want every user could switch on and off  connect/disconnect announcer messages for himself on my hub.

here is my Announcer script:

function Main()
	frmHub:EnableFullData(1)
end

function DataArrival(user, data)
	if strsub(data, 1, 7) == "$UserIP" then
		local s, e, nick = strfind(data, "^%$UserIP (%S+)%|$" )
		if nick == user.sName then
			user:SendData( "$UserIP "..nick.." "..user.sIP)
		elseif user.bOperator then
			local tmp = GetItemByName(nick)
			if tmp then user:SendData( "$UserIP "..nick.." "..tmp.sIP) end
		end return 1
	end
end 

function NewUserConnected(user)
_,b, tag,con,mail,share = strfind(user.sMyInfoString, "%$MyINFO%s+%$ALL%s+%S+%s+([^$]+)%$%s+%$([^$]*)%$([^$]*)%$([^$]+)%$")

if tag == nil or con == nil or mail == nil then
end

if (share == nil or tonumber(share) == nil) then
share = 0
elseif tonumber(share) == 0 then
share = "0.00 Gb"
else
if (tonumber(share) > 1000000000000) then
share = format("%0.2f", tonumber(share)/(1024*1024*1024*1024)).." Tb"
elseif (tonumber(share) > 1000000000) then
share = format("%0.2f", tonumber(share)/(1024*1024*1024)).." Gb"
elseif (tonumber(share) > 1000000) then
share = format("%0.2f", tonumber(share)/(1024*1024)).." Mb"
elseif (tonumber(share) > 1000) then
share = format("%0.2f", tonumber(share)/(1024)).." Kb"
else
share = share.." b"
end
end

SendToAll("-=::["..GetProfileName(user.iProfile).."]::["..user.sName.."]::["..user.sIP.."]::["..share.."]::=-") 
end

OpConnected = NewUserConnected

function UserDisconnected(user)
SendToAll("-=::["..GetProfileName(user.iProfile).."]::["..user.sName.."]::["..user.sIP.."]::[Left the hub]::=-")
end

OpDisconnected = UserDisconnected

Some of my users don't like this messages, but some of them like it. That is why I decided to make a switch on/off function for every user.

I've already tryed to make a script myself, but I haven't got enough experience.

My idea is that all user IP's will be written in Array by a scheme like this:

Array = {
	["announce"] = {
		[1] = "IP1",
		[2] = "IP2",
		[3] = "IP3",
	},
	["do_not_announce"] = {
		[1] = "IP3",
		[2] = "IP4",
		[3] = "IP5",
	},
}

When user connects or disconnects a hub, the script will check the users who want to get announcer message and will send a message to them. But users who don't want to see this messages at all will not see them.

And every user can enable/disable this messages for himself by the commands: +enablemsgs   or   +disablemsgs. By default this messages ENABLED for all users.

Could somebody help me with this? I really need this! :(
--LUA forever! =)

NemeziS

#1
Here is a script I began to write:
sBot = "Joker"

ArrANN = {}
usertxt = "txt/announce.txt"

function Main()
	LoadFromFile(usertxt)
ArrANN[strlower("announce")]={}
ArrANN[strlower("noannounce")]={}
end

function DataArrival(user, data)
if strsub(data,1,1) == "<" then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
	local pos = 0
	local accept = 0

		if (cmd == "!announce") then
	if (ArrANN[strlower("announce")][1] == nil) then
	ArrANN[strlower("announce")][1] = user.sName
	end
	for i=1, getn(ArrANN[strlower("announce")]) do
		if (ArrANN[strlower("announce")][i] == user.sName) then
			accept = 1
		end
		pos = i
	end
	if (accept == 0) then
		ArrANN[strlower("announce")][pos+1] = user.sName
	end

ArrANN[strlower("noannounce")][GetItemByName(user.sName)] = nil
		 	user:SendData(sBot, "OK")
		 	SaveToFile(usertxt , ArrANN , "ArrANN")
		 	return accept



		elseif (cmd == "!notannounce") then

	if (ArrANN[strlower("noannounce")][1] == nil) then
		LoadFromFile(usertxt)
	end
	for i=1, getn(ArrANN[strlower("noannounce")]) do
		if (ArrANN[strlower("noannounce")][i] == user.sName) then
			accept = 1
		end
		pos = i
	end
	if (accept == 0) then
		ArrANN[strlower("noannounce")][pos+1] = user.sName
	end

ArrANN[strlower("announce")][GetItemByName(user.sName)] = nil

		 	user:SendData(sBot, "OK")
		 	SaveToFile(usertxt , ArrANN , "ArrANN")
		 	return accept
		end
end
end

function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");

	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");

	sTab = sTab or "";
	sTmp = ""

	sTmp = sTmp..sTab..sTableName.." = {\n"

	for key, value in tTable do
		local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end

		sTmp = sTmp..",\n"
	end

	sTmp = sTmp..sTab.."}"
	return sTmp
end

function SaveToFile(file , table , tablename)
	writeto(file)
	write(Serialize(table, tablename))
	writeto()
end

function LoadFromFile(file)
	if (readfrom(file) ~= nil) then
		readfrom(file)
		dostring(read("*all"))
		readfrom()
	end
end

but I cant realize switch on/off function and check function. My idea is: when someone writes !announce his IP/Name will be removed from "noannounce" table and will be added to "announce" table. Opposite - !notannounce command.

Thanx a lot.

[*edit]  

Please help!! It's very important function for my hub.   :)

Best regards,
NemeziS
--LUA forever! =)

SMF spam blocked by CleanTalk