PtokaX forum

Development Section => Your Developing Problems => Topic started by: Stravides on 04 September, 2004, 23:27:10

Title: Help: number of hubs on request
Post by: Stravides on 04 September, 2004, 23:27:10
Ok, I'm getting lazy now ... not with the coding, just with the opping.

I want to be able to type a command ie !hubscan and it then looks at all the users and PM's the ops with all the users above the max hub level.

there are some that are getting through the hubsoftware n I want to limit the searching and adding I need to perform.

I have this in dataarrival, but this is a bit of an overhead as it is checked a lot I believe (when its on it cripples the hub)

please can you help me out on this one as I'm not sure what I should be looking at :)

if (strsub(data,1,7)=="$MyINFO") then
local _,_,a,b,c = strfind(data, "H:(%d+)/(%d+)/(%d+)")
local hub1 = tonumber(a)
local hub2 = tonumber(b)
local hub3 = tonumber(c)
local maxhub = tonumber(maxhub)
local tothub = hub1 + hub2 + hub3
if maxhub ~= 0 then
if tothub > maxhub and not user.bOperator then
SendToNick("Stravides"," "..user.." Was disconnected for having "..tostring(tohub).." Hubs Open")
return 1
end
end
end

Title:
Post by: nErBoS on 05 September, 2004, 02:09:05
Hi,

Try this...

--## HUB Scan BOT
--## Requested by Stravides
--## Made by nErBoS
--## Commands:
--## !hubscan - Check if there are users with more them Max HUBs

sBot = "Scan-BOT"

arrUser = {}
fUser = "user.dat"

--## Configuration ##--

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

iMaxHubs = 5 -- Number of Max HUBs allowed in your HUB

--## END ##--

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

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

function NewUserConnected(user)
arrUser[user.sName] = 1
if (uLaterPtokax == 1) then
OnExit()
end
end

function UserDisconnected(user)
arrUser[user.sName] = nil
if (uLaterPtokax == 1) then
OnExit()
end
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 == "!hubscan" and user.bOperator) then
CheckHUBs(user)
return 1
end
end
end

function CheckHUBs(user)
local sTmp,usr,aux = "Users that are more then "..iMaxHubs.." HUBs:\r\n\r\n"
for usr, aux in arrUser do
if (GetItemByName(usr) ~= nil and GetItemByName(usr).sMyInfoString ~= nil) then
local s,e,hubs = strfind(GetItemByName(usr).sMyInfoString, "H:(%S+),")
if (tonumber(hubs) ~= nil) then
if (tonumber(hubs) > iMaxHubs) then
sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
end
else
local s,e,a,b,c = strfind(hubs, "(%d+)/(%d+)/(%d+)")
if (a ~= nil and b ~= nil and c ~= nil) then
hubs = tonumber(a) + tonumber(b) + tonumber(c)
if (tonumber(hubs) > iMaxHubs) then
sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
end
end
end
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

Best regards, nErBoS
Title:
Post by: Stravides on 05 September, 2004, 07:45:30
Ok not quite working here...

I have added a line to PM to OPS ie so it outputs the info.

Have tested it with another account

on max 5 hubs...

6/0/0 is detected
5/1/0 is not detected
5/0/1 is not detected

these should be counted as > 5

sorry to be a pain :)

Stravides
Title:
Post by: BottledHate on 05 September, 2004, 13:52:41
try this function in place ofthe old... not tested.. but it
looks like it should work ;)

function CheckHUBs(user)
   local sTmp,usr,aux = "Users that are more then "..iMaxHubs.." HUBs:\r\n\r\n"
   for usr, aux in arrUser do
      if (GetItemByName(usr) ~= nil and GetItemByName(usr).sMyInfoString ~= nil) then
         local s,e,hubs = strfind(GetItemByName(usr).sMyInfoString, "H:(%d+)/")
         if tonumber(hubs) ~= nil then
            if tonumber(hubs) >= tonumber(iMaxHubs) then
               sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
            end
         else
            s,e,hubs = strfind(GetItemByName(usr).sMyInfoString, "H:(%S+),")
            local s,e,a,b,c = strfind(hubs, "(%d+)/(%d+)/(%d+)")
            if (a ~= nil and b ~= nil and c ~= nil) then
               hubs = tonumber(a) + tonumber(b) + tonumber(c)
               if hubs >= iMaxHubs then
                  sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
               end
            end
         end
      end
   end
end

-BH
Title:
Post by: nErBoS on 05 September, 2004, 14:46:14
Hi,

Forgot the output and i have tested and caugth every one...

--## HUB Scan BOT
--## Requested by Stravides
--## Made by nErBoS
--## Commands:
--## !hubscan - Check if there are users with more them Max HUBs

sBot = "Scan-BOT"

arrUser = {}
fUser = "user.dat"

--## Configuration ##--

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

iMaxHubs = 5 -- Number of Max HUBs allowed in your HUB

--## END ##--

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

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

function NewUserConnected(user)
arrUser[user.sName] = 1
if (uLaterPtokax == 1) then
OnExit()
end
end

function UserDisconnected(user)
arrUser[user.sName] = nil
if (uLaterPtokax == 1) then
OnExit()
end
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 == "!hubscan" and user.bOperator) then
CheckHUBs(user)
return 1
end
end
end

function CheckHUBs(user)
local sTmp,usr,aux = "Users that are more then "..iMaxHubs.." HUBs:\r\n\r\n"
for usr, aux in arrUser do
if (GetItemByName(usr) ~= nil and GetItemByName(usr).sMyInfoString ~= nil) then
local s,e,hubs = strfind(GetItemByName(usr).sMyInfoString, "H:(%S+),")
if (tonumber(hubs) ~= nil) then
if (tonumber(hubs) > iMaxHubs) then
sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
end
else
local s,e,a,b,c = strfind(hubs, "(%d+)/(%d+)/(%d+)")
if (a ~= nil and b ~= nil and c ~= nil) then
hubs = tonumber(a) + tonumber(b) + tonumber(c)
if (tonumber(hubs) > iMaxHubs) then
sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
end
end
end
end
end
user:SendPM(sBot, sTmp)
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

BH...

Your function will not catch DC with H:(number), with only one field in the HUB area.

Best regards, nErBoS
Title:
Post by: BottledHate on 05 September, 2004, 19:07:39
oh bleh... i see... becasue of the "/"

well give me a lil break, it was 4:30 or so in the morning when i did that. :D


-BH
Title:
Post by: nErBoS on 05 September, 2004, 20:56:32
Hi,

hehe, i am like that  ;)  (We should sleep more  :)) )

Best regards, nErBoS
Title:
Post by: Stravides on 11 September, 2004, 09:19:34
Thanks for this - we're nearly there !! :)

I have been running it for a few days now, but i have to keep restarting the scripts and deleting the user.dat file as I keep on getting errors.

I have been trying to locate the error and as yet have not had any joy :(

The script runs and does not give any output via messaging as it should, I just get an error in the hub which is
syntax error: bad arguement #1 to 'strfind' (string expected, got nil)

it captures a user offending I kick them and its ok - but leave it running a while (hour or two) and it stops working it just displays the command !hubscan in main chat even tho return 1 is enabled

I kick users for not having the correct allocation of slots and hubs etc. and then I get errors. not all of the time.

I have set it to "LaterPtokax = 1" as I am using ptokax 0.3.2.6 td4

Any help would be appreciated...
Title:
Post by: Stravides on 11 September, 2004, 23:22:51
its as tho the script isnt even running
Title:
Post by: nErBoS on 14 September, 2004, 23:15:26
Hi,

I belive that the problem is from NMDC or any client with no tag, this should fixed...

--## HUB Scan BOT
--## Requested by Stravides
--## Made by nErBoS
--## Commands:
--## !hubscan - Check if there are users with more them Max HUBs

sBot = "Scan-BOT"

arrUser = {}
fUser = "user.dat"

--## Configuration ##--

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

iMaxHubs = 5 -- Number of Max HUBs allowed in your HUB

--## END ##--

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

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

function NewUserConnected(user)
arrUser[user.sName] = 1
if (uLaterPtokax == 1) then
OnExit()
end
end

function UserDisconnected(user)
arrUser[user.sName] = nil
if (uLaterPtokax == 1) then
OnExit()
end
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 == "!hubscan" and user.bOperator) then
CheckHUBs(user)
return 1
end
end
end

function CheckHUBs(user)
local sTmp,usr,aux = "Users that are more then "..iMaxHubs.." HUBs:\r\n\r\n"
for usr, aux in arrUser do
if (GetItemByName(usr) ~= nil and GetItemByName(usr).sMyInfoString ~= nil) then
local s,e,hubs = strfind(GetItemByName(usr).sMyInfoString, "H:(%S+),")
if (tonumber(hubs) ~= nil) then
if (tonumber(hubs) > iMaxHubs) then
sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
end
elseif (hubs ~= nil) then
local s,e,a,b,c = strfind(hubs, "(%d+)/(%d+)/(%d+)")
if (a ~= nil and b ~= nil and c ~= nil) then
hubs = tonumber(a) + tonumber(b) + tonumber(c)
if (tonumber(hubs) > iMaxHubs) then
sTmp = sTmp.."User: "..usr.."\tHUBs: "..hubs.."\r\n"
end
end
end
end
end
user:SendPM(sBot, sTmp)
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

Best regards, nErBoS
Title:
Post by: Stravides on 15 September, 2004, 01:39:56
thanks - I'll give it a  try