PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Snooze on 11 June, 2004, 03:42:10

Title: [Q?]slot,share,client check
Post by: Snooze on 11 June, 2004, 03:42:10
I were just wondering what the fastes way to check for:

Minshare
Maxshare
Minslot
Maxslot
etc

Right now I'm doing it from the "NewUserConnected" witch seems really fast, though users still gets in long enough to get the MOTD and UserList ??
How can i avoid that ?

Well... any help would be really great ..


**Snooze
Title:
Post by: bastya_elvtars on 11 June, 2004, 04:11:16
IMHO its better they get motd and userlist... they can decide whether they wanna enter @ all  :D
Title:
Post by: tezlo on 11 June, 2004, 04:36:30
best check every time a new $MyINFO comes
Title:
Post by: Herodes on 11 June, 2004, 05:10:48
Carefull!!
This one dont work ! ! !

function DataArrival(user, data)
if strsub(data, 1, 7) == "$MyINFO" then
data = strsub(data, 1, (strlen(data)-1))
local s,e,description,tag,_,_, share = strfind(data, "^%$MyINFO $ALL %S+%s+(.*)<([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
SendData(bot, tag)
slots = strfind(tag, "S:%d+>")
ushare = strfind(data "$(%d+)%$")
SendData(bot, "Slots: "..slots)
SendData(bot, "Share:"..ushare)
end
end

I was playing with this earlier ...
but I need to get a whole lot better with my string operations ...

Not now anyhow ,,,
going to sleep first ..  

I just thought " What a coincidence ... "  nn all .. :D
Title:
Post by: Snooze on 11 June, 2004, 11:13:36
QuoteIMHO its better they get motd and userlist... they can decide whether they wanna enter @ all
Well.. they better be really fast readers ;) - they get to hang in the hub for less than ? a sec.

So.. Is it that much faster to get it from dataarrival ?


**Snooze
Title:
Post by: tezlo on 11 June, 2004, 15:28:14
it's not any faster but rather obvious to check whenever it changes
NewUserConnected gets called right after the first $MyINFO is received
Title:
Post by: Snooze on 12 June, 2004, 00:49:44
This is my current hub/slot check - if you can see anywhere I can uptimize it, please let me know.


function DataArrival(user,data)
               hubsc = 0
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
if not (user.bOperator) or (GetProfileName(user.iProfile) == "VIP" or (GetProfileName(user.iProfile) == "Special")) then
              s,e,thubs,slots = strfind(data,  "H:([%d%/]+),S:(%d+)%S*>")
if thubs==nil or slots==nil then
user:SendData(Bot, "Your Client did not respond with proper tag!! - Latest allowed clients can be found here: [URL]http://www.snooze.no-ip.com/sk/viewforum.php?f=25[/URL]")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
SKHUBSTAT["hBadClient"] = SKHUBSTAT["hBadClient"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Bad Client tag. "..user.sMyInfoString) end
return 1
end
              if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                      hubsc = hubsc +tonumber(num)
                  end)
                else
                  hubsc = tonumber(thubs)
              end
                slots = tonumber(slots)
if slots < (tonumber(SKCONF["sHSRatio"])*hubsc) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..tonumber(SKCONF["sHSRatio"]).." Slot per Hub'")
user:SendData("$ForceMove "..arg)
SKHUBSTAT["hSlotRatio"] = SKHUBSTAT["hSlotRatio"] + 1
SaveSKHUBSTAT() --// Hub/Slot Ratio
return 1
elseif (hubsc > tonumber(SKCONF["sMaxHubs"])) and (tonumber(SKCONF["sMaxHubs"]) > 0) then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..tonumber(SKCONF["sMaxHubs"]).." Hubs.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
SKHUBSTAT["hMaxhubs"] = SKHUBSTAT["hMaxhubs"] + 1
SaveSKHUBSTAT() --// Max Hubs
elseif ((slots < tonumber(SKCONF["sMinSlots"])) or (slots > tonumber(SKCONF["sMaxSlots"]))) and (tonumber(SKCONF["sMinSlots"]) > 0) then
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:SendData(Bot, "Your are in violation with this hubs Slots Rule: Min "..tonumber(SKCONF["sMinSlots"]).." Slots. - Max "..tonumber(SKCONF["sMaxSlots"]).." Slots.")
SKHUBSTAT["hMinslots"] = SKHUBSTAT["hMinslots"] + 1
SaveSKHUBSTAT() --// Min/Max Slots
return 1
end
end
end

There gotta be a faster way to do ... I see doing it alot faster ..

Well... any suggestions are more than welcome :)

**Snooze
Title:
Post by: Snooze on 12 June, 2004, 03:00:44
This solved it ..

function DataArrival(user,data)
----------------------------------------DataArrival-------------------------------------------
----------------------------------- Rules Check START (hub/slots)--------------------------------
               hubsc = 0
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
if not (user.bOperator) or (GetProfileName(user.iProfile) == "VIP" or (GetProfileName(user.iProfile) == "Special")) then
              s,e,thubs,slots = strfind(data,  "H:([%d%/]+),S:(%d+)%S*>")
if thubs==nil or slots==nil then
user:SendData(Bot, "Your Client did not respond with proper tag!! - Latest allowed clients can be found here: [URL]http://www.snooze.no-ip.com/sk/viewforum.php?f=25[/URL]")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hBadClient"] = SKHUBSTAT["hBadClient"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Bad Client tag - ("..data..")") end
return
end
              if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                      hubsc = hubsc +tonumber(num)
                  end)
                else
                  hubsc = tonumber(thubs)
              end
                slots = tonumber(slots)
if slots < (tonumber(SKCONF["sHSRatio"])*hubsc) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..tonumber(SKCONF["sHSRatio"]).." Slot per Hub'")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hSlotRatio"] = SKHUBSTAT["hSlotRatio"] + 1
SaveSKHUBSTAT() --// Hub/Slot Ratio
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Ratio - ("..(tonumber(SKCONF["sHSRatio"])*hubsc)..")") end
return 1
elseif (hubsc > tonumber(SKCONF["sMaxHubs"])) and (tonumber(SKCONF["sMaxHubs"]) > 0) then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..tonumber(SKCONF["sMaxHubs"]).." Hubs.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hMaxhubs"] = SKHUBSTAT["hMaxhubs"] + 1
SaveSKHUBSTAT() --// Max Hubs
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Max Hubs - ("..hubsc..")") end
return 1
elseif ((slots < tonumber(SKCONF["sMinSlots"])) or (slots > tonumber(SKCONF["sMaxSlots"]))) and (tonumber(SKCONF["sMinSlots"]) > 0) then
user:SendData(Bot, "Your are in violation with this hubs Slots Rule: Min "..tonumber(SKCONF["sMinSlots"]).." Slots. - Max "..tonumber(SKCONF["sMaxSlots"]).." Slots.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hMinslots"] = SKHUBSTAT["hMinslots"] + 1
SaveSKHUBSTAT() --// Min/Max Slots
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Min/Max Slots - ("..slots..")") end
return 1
end
end
end
Title:
Post by: Herodes on 12 June, 2004, 03:02:53
Good Job Snooze !!
A good way of doing it was missing from this forum ....
This one is spot on !
Bravo again :D
Title:
Post by: Snooze on 12 June, 2004, 03:06:19
In that case ... here comes the rest ..


**NOTE**
- I have an extra profile added (Special)
- I only allow dc++ and oDC Clients


function DataArrival(user,data)
----------------------------------------DataArrival-------------------------------------------
----------------------------------- Rules Check START (hub/slots)--------------------------------
               hubsc = 0
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
if not (user.bOperator) or (GetProfileName(user.iProfile) == "VIP" or (GetProfileName(user.iProfile) == "Special")) then
              s,e,thubs,slots = strfind(data,  "H:([%d%/]+),S:(%d+)%S*>")
if thubs==nil or slots==nil then
user:SendData(Bot, "Your Client did not respond with proper tag!! - Latest allowed clients can be found here: [URL]http://www.snooze.no-ip.com/sk/viewforum.php?f=25[/URL]")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hBadClient"] = SKHUBSTAT["hBadClient"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Bad Client tag - ("..data..")") end
return
end
              if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                      hubsc = hubsc +tonumber(num)
                  end)
                else
                  hubsc = tonumber(thubs)
              end
                slots = tonumber(slots)
if slots < (tonumber(SKCONF["sHSRatio"])*hubsc) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..tonumber(SKCONF["sHSRatio"]).." Slot per Hub'")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hSlotRatio"] = SKHUBSTAT["hSlotRatio"] + 1
SaveSKHUBSTAT() --// Hub/Slot Ratio
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Ratio - ("..(tonumber(SKCONF["sHSRatio"])*hubsc)..")") end
return 1
elseif (hubsc > tonumber(SKCONF["sMaxHubs"])) and (tonumber(SKCONF["sMaxHubs"]) > 0) then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..tonumber(SKCONF["sMaxHubs"]).." Hubs.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hMaxhubs"] = SKHUBSTAT["hMaxhubs"] + 1
SaveSKHUBSTAT() --// Max Hubs
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Max Hubs - ("..hubsc..")") end
return 1
elseif ((slots < tonumber(SKCONF["sMinSlots"])) or (slots > tonumber(SKCONF["sMaxSlots"]))) and (tonumber(SKCONF["sMinSlots"]) > 0) then
user:SendData(Bot, "Your are in violation with this hubs Slots Rule: Min "..tonumber(SKCONF["sMinSlots"]).." Slots. - Max "..tonumber(SKCONF["sMaxSlots"]).." Slots.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hMinslots"] = SKHUBSTAT["hMinslots"] + 1
SaveSKHUBSTAT() --// Min/Max Slots
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Min/Max Slots - ("..slots..")") end
return 1
end
end
end
----------------------------------- Rules Check (share)--------------------------------
if (GetProfileName(user.iProfile) == "VIP") then
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
local s,e,iUserShare = strfind(data, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
iUserShare = format("%0.2f", iUserShare/(1024*1024*1024))
if tonumber(iUserShare) < tonumber(SKCONF["VipShare"]) then
user:SendData(Bot, "You have not met the minimum VIP share size of "..SKCONF["VipShare"].." GB.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hVIPMinshare"] = SKHUBSTAT["hVIPMinshare"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - VIP Share - ("..tonumber(iUserShare)..")") end
return 1
end
end
elseif (GetProfileName(user.iProfile) == "Special") then
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
local s,e,iUserShare = strfind(data, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
iUserShare = format("%0.2f", iUserShare/(1024*1024*1024))
if tonumber(iUserShare) < tonumber(SKCONF["SpecialShare"]) then
user:SendData(Bot, "You have not met the minimum Special share size of "..SKCONF["SpecialShare"].." GB.")
user:SendData(Bot, "You are being redirected to another cool hub... Thanx for stopping here.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hSpecialMinshare"] = SKHUBSTAT["hSpecialMinshare"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Special Share - ("..tonumber(iUserShare)..")") end
return 1
end
end
elseif not (user.bOperator) or (GetProfileName(user.iProfile) == "VIP" or (GetProfileName(user.iProfile) == "Special")) then
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
local s,e,iUserShare = strfind(data, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
iUserShare = format("%0.2f", iUserShare/(1024*1024*1024))
hMinShare = tonumber(SKCONF["sMinShare"])
if tonumber(iUserShare) < hMinShare then
user:SendData(Bot, "You have not met the minimum share size of "..hMinShare.." GB.")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hMinshare"] = SKHUBSTAT["hMinshare"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Min Share - ("..tonumber(iUserShare)..")") end
return 1
end
end
----------------------------------- Rules Check (client check)--------------------------------
if SKCONF.BadClient == "ON" then
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
if not (user.bOperator) or (GetProfileName(user.iProfile) == "VIP" or (GetProfileName(user.iProfile) == "Special")) then
if not (strfind(data," user:SendData(Bot, "This hub ONLY allow DC++ and oDC++ Clients. - Latest allowed clients can be found here: [URL]http://www.snooze.no-ip.com/sk/viewforum.php?f=25[/URL]")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hBadClient"] = SKHUBSTAT["hBadClient"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Bad Client - ("..data..")") end
return 1
end
s,e,dcVers = strfind(data,  "++ V:0.(%d+)")
if (tonumber(dcVers) ~= nil) and (tonumber(dcVers) < 300) then
user:SendData(Bot, "Please update your client - Latest allowed clients can be found here: [URL]http://www.snooze.no-ip.com/sk/viewforum.php?f=25[/URL]")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hBadClient"] = SKHUBSTAT["hBadClient"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Bad Client - ("..data..")") end
return 1
end
s,e,odcVers = strfind(data,  "oDC V:5.(%d+)")
if (tonumber(odcVers) ~= nil) and (tonumber(odcVers) < 21) then
user:SendData(Bot, "Please update your client - Latest allowed clients can be found here: [URL]http://www.snooze.no-ip.com/sk/viewforum.php?f=25[/URL]")
user:SendData("$ForceMove "..frmHub:GetRedirectAddress())
user:Disconnect()
SKHUBSTAT["hBadClient"] = SKHUBSTAT["hBadClient"] + 1
SaveSKHUBSTAT()
if SKCONF["sDeBug"] == "ON" then SendPmToNick(HubOwner,Bot, user.sName.." - Bad Client - ("..data..")") end
return 1
end
end
end
end
end
----------------------------------- Rules Check END ----------------------------------

This is made with alot of help from user in here ... so I'm only happy to give something back ;)

Please post any updates you may make here ;)


**Snooze
Title:
Post by: Snooze on 12 June, 2004, 03:22:59
Wondering - would it be an idea to stop the $GetNickList from being executed from the clients being disconnected ?