BotName = "IP/Nick DataBase"
IPNicksFile = "IPNicksFile.txt"
function Is2ndIPHigher( IP1, IP2 )
local _,_,dec1 = strfind( IP1, "^(%d+)%.?" )
local _,_,dec2 = strfind( IP2, "^(%d+)%.?" )
if not( strfind( IP1, ".", 1, 1 ) ) or not( strfind( IP2, ".", 1, 1 ) ) or ( dec1 ~= dec2 ) then
return tonumber( dec1 ) < tonumber( dec2 )
else
IP1 = strsub( IP1, strlen( dec1 ) + 2 )
IP2 = strsub( IP2, strlen( dec2 ) + 2 )
return Is2ndIPHigher( IP1, IP2 )
end
end
function FoundNick( nick, searchIn )
local _,_,tmpNick = strfind( searchIn, "^(%S+)%s?" )
if ( tmpNick == nick ) or ( not( strfind( searchIn, " ", 1, 1 ) ) ) then
return tmpNick == nick
else
searchIn = strsub( searchIn, strlen( tmpNick ) + 2 )
return FoundNick( nick, searchIn )
end
end
function SavedIPNick( curUser )
local found = nil
local lines = ""
readfrom( IPNicksFile )
while 1 do
local line = read()
if ( line ~= nil ) and ( line ~= "" ) then
if not found then
local _,_,nextIP = strfind( line, "^(%S+)%s" )
if Is2ndIPHigher( curUser.sIP, nextIP ) then
line = curUser.sIP.." = "..curUser.sName.."\n"..line
found = 0
else
if strsub( line, 1, strlen( curUser.sIP ) ) == curUser.sIP then
local nicks = strsub( line, strlen( curUser.sIP ) + 4 )
if FoundNick( curUser.sName, nicks ) then
readfrom()
return 0
else
line = line.." "..curUser.sName
found = 1
end
end
end
end
lines = lines..line.."\n"
else
if ( lines == "" ) or ( not found ) then
lines = lines..curUser.sIP.." = "..curUser.sName.."\n"
found = 0
end
readfrom()
writeto( IPNicksFile )
write( lines )
writeto()
return 2 - found
end
end
end
function OpConnected( curUser )
SavedIPNick( curUser )
end
function NewUserConnected( curUser )
SavedIPNick( curUser )
end
function Main()
frmHub:UnregBot( BotName )
end
lil' script building some kind of DataBase, which lookes like that:
IP1 = Nick11 Nick12 Nick13 .. Nick1n
IP2 = Nick21 .. Nick2k
:
:
IPm = Nickm1 .. Nickmn
where IPs are sorted from the "lowest" at the begining to the "highest" at the end of file. so when i login from IP 666.666.666.666 as Jaras, next i'll logout and f.e. after 2 hours i'll login again but as Pussy line will look like that:
666.666.666.666 = Jaras Pussy
so u'll know, that i'm "acting suspicious" =]. i dont have time for adding commands, but using plop's texter or setting output file to unused file from other script (like "txt/network.txt" i my case - using RC 8.0) will make it. i'll also add cmd for searching database for IP or Nick (strfind will do the job) and when found returning whole line, but as i said, don't have time now (exams). hope someone will find this script useful.
for some yet unknown purposes function returns:
0 - when no data were written to file (user already exists)
1 - when added another Nick to existing IP
2 - added new entry (IP and Nick)
don't forget to make empty file specified in IPNicksFile variable and do not modify it (the file itself) ever unless u know what u're doin'=].
P.S. anyone can tell me what should i do to prevent typed commands from showing on main chat?