PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: skandaluz on 13 September, 2004, 23:34:44

Title: Advanced Upload Blocker for vip and ops
Post by: skandaluz on 13 September, 2004, 23:34:44
I'm looking for a script that would give ops and vips first priority on downloads from users even when the user they wish to download from has all slots taken...so it would either disconnect a user already connected to open up a slot or it would create a new one for the op or vip to download from if thats possible
now I have tied the script below and it works great except that when the user already has all slots taken the ops still have to wait so maybe it could be modified to do the above....thnx

code:----------------------------------------------------------------------------------## Upload Blocker
--## Requested by charlie
--## Made by nErBoS
--## Commands (only for OPs):
--##   !addblock    -- Will block uploads from the user (only OPs can download from him)
--##   !delblock    -- Will remove the block from the user uploads
--##   !allow    -- Will allow the user "nick" to make downloads from the user "who"
--##   !restrict    -- Will remove the allow from the user "nick" to make downloads from the user "who"
--##   !blocked      -- Will show all user that are blocked and who is allowed to make downloads from him

sBot = "U-Blocker"

arrUser = {}
fUser = "user.dat"

--## Configuration ##--

uLaterPtokax = 0   -- Choose 0 if you are using a Ptokax version 0.3.3.0 or higher
         -- Choose 1 if you are using a Ptokax version lower then 0.3.3.0

--## END ##--

function Main()
   frmHub:RegBot(sBot)
   frmHub:EnableFullData(1)
   LoadFromFile(fUser)
end

function OnExit()
   SaveToFile(fUser , arrUser , "arrUser")
end

function DataArrival(user, data)
   if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
      data = strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data, "%b<>%s+(%S+)")
      if (cmd == "!addblock" and user.bOperator) then
         local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
         if (nick == nil) then
            user:SendPM(sBot, "Syntax Error, !addblock , you must write a nick.")
         elseif (type(arrUser[strlower(nick)]) == "table") then
            user:SendPM(sBot, "The user "..nick.." is already blocked.")
         else
            arrUser[strlower(nick)] ={}
            if (uLaterPtokax == 1) then
               OnExit()
            end
            user:SendPM(sBot, "The user has been added a block. Now only OPs can download from him.")
            user:SendPM(sBot, "If you want a user to download from him just use !allow.")
         end
         return 1
      elseif (cmd == "!delblock" and user.bOperator) then
         local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
         if (nick == nil) then
            user:SendPM(sBot, "Syntax Error, !delblock , you must write a nick.")
         elseif (arrUser[strlower(nick)] == nil) then
            user:SendPM(sBot, "The user "..nick.." is not blocked.")
         else
            arrUser[strlower(nick)] = nil
            if (uLaterPtokax == 1) then
               OnExit()
            end
            user:SendPM(sBot, "The user has been removed the block. Now anyone can download from him.")
         end
         return 1
      elseif (cmd == "!allow" and user.bOperator) then
         local s,e,who,nick = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
         if (nick == nil or who == nil) then
            user:SendPM(sBot, "Syntax Error, !allow , you must both nicks.")
         elseif (arrUser[strlower(who)] == nil) then
            user:SendPM(sBot, "The user "..who.." is not blocked.")
         elseif (arrUser[strlower(who)][strlower(nick)] ~= nil) then
            user:SendPM(sBot, "The user "..nick.." is already allow to download from "..who)
         else
            arrUser[strlower(who)][strlower(nick)] = user.sName
            if (uLaterPtokax == 1) then
               OnExit()
            end
            user:SendPM(sBot, "The user "..nick.." has been allowed to download from "..who)
         end
         return 1
      elseif (cmd == "!restrict" and user.bOperator) then
         local s,e,who,nick = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
         if (nick == nil or who == nil) then
            user:SendPM(sBot, "Syntax Error, !restrict , you must both nicks.")
         elseif (arrUser[strlower(who)] == nil) then
            user:SendPM(sBot, "The user "..who.." is not blocked.")
         elseif (arrUser[strlower(who)][strlower(nick)] == nil) then
            user:SendPM(sBot, "The user "..nick.." is not allow to download from "..who)
         else
            arrUser[strlower(who)][strlower(nick)] = nil
            if (uLaterPtokax == 1) then
               OnExit()
            end
            user:SendPM(sBot, "The user "..nick.." is no more allowed to download from "..who)
         end
         return 1
      elseif (cmd == "!blocked" and user.bOperator) then
         local sTmp,usr,aux,usr2 = "The Users the have uploads blocked:"
         for usr, aux in arrUser do
            sTmp = sTmp.."\r\n\r\n--## Users that can download from "..usr..":\r\n\r\n"
            for usr2, aux in arrUser[usr] do
               sTmp = sTmp.."\t"..usr2.." Allowed by: "..aux.."\r\n"
            end
         end
         user:SendPM(sBot, sTmp)
      end
   end

   if (strsub(data,1,12) == "$ConnectToMe" and not user.bOperator) then
      local s,e,from,toip = strfind(data, "$ConnectToMe%s+(%S+)%s+(%d+%.%d+%.%d+%.%d+):")
      if (type(arrUser[strlower(from)]) == "table") then
         if (CheckForPermission(arrUser[strlower(from)],toip) == 0) then
            user:SendPM(sBot, "You can't download from "..from..". If you have any doubt talk with a OP.")
            return 1
            end
      end
   end

   if (strsub(data,1,15) == "$RevConnectToMe" and not user.bOperator) then
      local s,e,to,from = strfind(data, "$RevConnectToMe%s+(%S+)%s+(%S+)")
      if (type(arrUser[strlower(from)]) == "table") then
         if (arrUser[strlower(from)][strlower(to)] == nil) then
            user:SendPM(sBot, "You can't download from "..from..". If you have any doubt talk with a OP.")
            return 1
         end
      end
   end
end

function CheckForPermission(table,ip)
   local usr,aux
   for usr, aux in table do
      if (GetItemByName(usr) ~= nil and GetItemByName(usr).sIP == ip) then
         return 1
      end
   end
   return 0
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--------------------------------------------------------------------------------
Title:
Post by: BottledHate on 14 September, 2004, 02:07:38
what you are asking can not be done.


-BH
Title:
Post by: LYKEN on 14 September, 2004, 03:08:25
sorry thought the point of all this in dc was to share

and to be wanting to kick users from somthing they are geting cos other peeps cant be bother to wait of look else wer strikes me as wrong   why not try asking niclt 4 a slot


respect
Title:
Post by: bastya_elvtars on 14 September, 2004, 03:25:41
QuoteOriginally posted by skandaluz
I'm looking for a script that would give ops and vips first priority on downloads from users even when the user they wish to download from has all slots taken...so it would either disconnect a user already connected to open up a slot or it would create a new one for the op or vip to download from if thats possible
now I have tied the script below and it works great except that when the user already has all slots taken the ops still have to wait so maybe it could be modified to do the above....thnx


it can not be done technically, dc protocol does not make it possible.
Title:
Post by: skandaluz on 14 September, 2004, 04:04:10
QuoteOriginally posted by LYKEN
sorry thought the point of all this in dc was to share

and to be wanting to kick users from somthing they are geting cos other peeps cant be bother to wait of look else wer strikes me as wrong   why not try asking niclt 4 a slot


respect

yes i agree dc is to share thats y i said if it was possible to open up a slot but as a hub owner my fellow ops come first i'm using my line to allow others to share now y should i have to wait in my own house....its not like i download everyday but if i saw sumthing i liked it would be nice to have it ....but since i have read that it is not possible this thread is now closed.....thnx for the reply though
Title:
Post by: honda on 15 September, 2004, 13:37:39
Ask your Op to grant a slot  ;)


Edit:

What one thing is.. Set your Op's and favo users in your favorites users list.
Then set on grant slot then the will get always a slot of you..

Title:
Post by: bastya_elvtars on 15 September, 2004, 14:25:07
Quotein my own house

you made it for others, not yourself, i guess
Title:
Post by: skandaluz on 15 September, 2004, 17:51:44
you made it for others, not yourself, i guess
[/QUOTE]

lol ok buddy why would i make it for others but not myself what is the reasoning behind that