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! :(
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