profileNr = { }
count = {
chat = 0,
connected = 0,
startdate = date(),
}
--// This function is fired at the serving start
function Main()
setlocale("swe")
if BotName == nil then
layout = "*** "
else
layout = "<"..BotName.."> "
end
SetTimer(MessageDelay*60000)
if UseTimer == 1 then
StartTimer()
end
end
--// This function is fired when a new data arrives
function DataArrival(curUser, sData)
if strsub(sData, 1, 1) == "<" then
count.chat = count.chat + 1
end
end
--// This function is fired when a new user finishes the login
function NewUserConnected(curUser)
getmessages(curUser, "in")
end
--// This function is fired when an operator enters the hub
function OpConnected(curUser)
getmessages(curUser, "in")
end
--// This function is fired when an user disconnects
function UserDisconnected(curUser)
getmessages(curUser, "out")
end
--// This function is fired when an operator disconnects
function OpDisconnected(curUser)
getmessages(curUser, "out")
end
function OnTimer()
if timetag == nil then
timetag = 0
count.chat = MinChat
count.connected = MinUserConnect
end
timetag = timetag + 1
if timetag == 1 then
if MinChat > 0 then
reset = 0
if count.chat < MinChat then
timetag = 0
local reset = 0
else
count.chat = 0
count.connected = 0
local reset = 1
end
end
if MinUserConnect > 0 and reset == 0 then
if count.connected < MinUserConnect then
timetag = 0
else
count.chat = 0
count.connected = 0
end
end
end
if tmessages[timetag] then
message = tmessages[timetag]
if strsub(message, 1, 5)=="file:" then
local filename = strsub(message, 6, strlen(message))
readfrom(filename)
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\r\n"
end
end
announce(BotName, message)
readfrom()
else
announce(BotName, message)
end
else
timetag = 0
end
end
--// Help functions ----------------------------------------------------
function announce(user, string)
local arrTmp = substitute(user, string)
SendToAll(layout..arrTmp)
end
function pm(user, string)
local arrTmp = substitute(user, string)
if privatemode == "pm" then
user:SendPM(BotName, arrTmp)
elseif privatemode == "main" then
user:SendData(layout..arrTmp)
end
end
function substitute(user, string)
local arrTmp = gsub(string, "%[usercount%]", frmHub:GetUsersCount())
arrTmp = gsub(arrTmp, "%[maxusers%]", frmHub:GetMaxUsers())
arrTmp = FormatSize(arrTmp, "totalshare", frmHub:GetCurrentShareAmount());
arrTmp = gsub(arrTmp, "%[minshare%]", frmHub:GetMinShare()/1024)
arrTmp = gsub(arrTmp, "%[hubname%]", frmHub:GetHubName())
arrTmp = gsub(arrTmp, "%[hubowner%]", HubOwner)
arrTmp = gsub(arrTmp, "%[crlf%]", "\r\n")
if type(user) == "table" then
local myinfo = user.sMyInfoString
local _, _, desc, speed, email, sharesize = strfind(myinfo, "$ALL %S+ (.*)%$ %$(.+)%$(.*)%$(%d+)%$");
if (desc and strfind(desc, "(.+)%b<>")) then
desc = gsub(desc, "(.+)%b<>", "%1");
else
desc = "none";
end
if (speed == nil or strlen(speed) == 0) then speed = "none" end;
if (email == nil or strlen(email) == 0) then email = "none"; end;
if (sharesize == nil) then sharesize = 0; end;
arrTmp = gsub(arrTmp, "%[user%]", user.sName)
arrTmp = gsub(arrTmp, "%[userdesc%]", desc)
arrTmp = gsub(arrTmp, "%[userspeed%]", strsub(speed, 1, strlen(speed)-1))
arrTmp = gsub(arrTmp, "%[useremail%]", email)
arrTmp = FormatSize(arrTmp, "usershare", tonumber(sharesize));
arrTmp = gsub(arrTmp, "%[userip%]", user.sIP)
end
return arrTmp
end
function getmessages(user, io)
local userprofile = GetProfileName(user.iProfile)
if user.iProfile == -1 then
userprofile = "unreg$"
end
if userprofile == nil then userprofile = "qwertyuiopasdfghjkl" end
if io == "in" then
if iprofiles["$"..user.sName] then
if iprofiles["$"..user.sName] ~= "@" then
announce(user, iprofiles["$"..user.sName])
count.chat = count.chat + 1
else
count.connected = count.connected + 1
end
elseif iprofiles[userprofile] then
announce(user, iprofiles[userprofile])
count.chat = count.chat + 1
else
count.connected = count.connected + 1
end
if iprofiles["$pm$"..user.sName] then
pm(user, iprofiles["$pm$"..user.sName])
end
if iprofiles["!"..userprofile] then
pm(user, iprofiles["!"..userprofile])
end
else
if oprofiles["$"..user.sName] then
if oprofiles["$"..user.sName] ~= "@" then
announce(user, oprofiles["$"..user.sName])
count.chat = count.chat + 1
end
elseif oprofiles[userprofile] then
announce(user, oprofiles[userprofile])
count.chat = count.chat + 1
end
end
end
function FormatSize(sString, sTag, iVal)
assert(type(sString) == "string", "FormatSize(): bad argument #1 (string expected)");
assert(type(iVal) == "number", "FormatSize(): bad argument #2 (numerical value expected)");
local _, _, sFormat = strfind(sString, "%["..sTag.."%.[mgtp]b(%.%d+)%]");
if (sFormat) then
sFormat = "%"..sFormat.."f";
sString = gsub(sString, "%["..sTag.."%.mb%.%d+%]", format(sFormat, toMB(iVal)).." MB");
sString = gsub(sString, "%["..sTag.."%.gb%.%d+%]", format(sFormat, toGB(iVal)).." GB");
sString = gsub(sString, "%["..sTag.."%.tb%.%d+%]", format(sFormat, toTB(iVal)).." TB");
sString = gsub(sString, "%["..sTag.."%.pb%.%d+%]", format(sFormat, toPB(iVal)).." PB");
else
sString = gsub(sString, "%["..sTag.."%.bb%]", iVal.." B");
end
return sString;
end -- bonki
function toMB(bytes)
return (bytes / 1024 / 1024);
end
function toGB(bytes)
return (bytes / 1024 / 1024 / 1024);
end
function toTB(bytes)
return (bytes / 1024 / 1024 / 1024 / 1024);
end
function toPB(bytes)
return (bytes / 1024 / 1024 / 1024 / 1024 / 1024);
end