[Help]oDC hub/slot check
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

[Help]oDC hub/slot check

Started by Snooze, 30 April, 2004, 13:34:08

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Snooze

I've made this little hub/slot check :

--------oDC Check----------
	if not (user.bOperator) then 
		ratio = tonumber(frmHub:GetSlotRatio())
		arg = frmHub:GetRedirectAddress()
		arg2 = frmHub:GetMaxHubs()
		arg3 = frmHub:GetMinSlots()
		if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
			s,e,hubs1,hubs2,hubs3 = strfind(data,"H:([^$])/([^$])/([^$])")
			s,e,slots = strfind(data,"S:([^$])")
			hubc = (hubs1 + hubs2 + hubs3)
			if tonumber(slots) < (ratio*hubc) then
				user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubc * ratio)
				user:SendData("$ForceMove "..arg)
			elseif hubc > arg2 then
				user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
				user:SendData("$ForceMove "..arg)
			elseif slots < arg3 then
				user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
				user:SendData("$ForceMove "..arg)
			end
		end
	end
--------oDC Check----------

It's a part of my DataArrival.

My problem is that im getting this error when running it in a public hub with ALOT of connect attempts..

Error:

Syntax error: attempt to perform arithmetic on global `hubs1' (a nil value)

Though when running it in my test hub it works just fine ...

Any ideas on how to fix this error ?


**Snooze

plop

give this a try.
it works on both the old and new style hub tag, if the new tag is found it converts it 2 the old style.
              hubs = 0
               s,e,thubs,slots = strfind(tag,  "H:([%d%/]+),S:(%d+)%S*>")
               if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                     hubs = hubs +tonumber(num)
                  end)
               else
                  hubs = tonumber(thubs)
               end
               slots = tonumber(slots)
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Snooze

Thanks for you quick reply plop :)

I hope this what what you had in mind:

--------oDC Check----------
	if not (user.bOperator) then 
		ratio = tonumber(frmHub:GetSlotRatio())
		arg = frmHub:GetRedirectAddress()
		arg2 = frmHub:GetMaxHubs()
		arg3 = frmHub:GetMinSlots()
               hubs = 0
               s,e,thubs,slots = strfind(tag,  "H:([%d%/]+),S:(%d+)%S*>")
               if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                     hubs = hubs +tonumber(num)
                  end)
               else
                  hubs = tonumber(thubs)
               end
               slots = tonumber(slots)
			if tonumber(slots) < (ratio*hubc) then
				user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubc * ratio)
				user:SendData("$ForceMove "..arg)
			elseif hubc > arg2 then
				user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
				user:SendData("$ForceMove "..arg)
			elseif slots < arg3 then
				user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
				user:SendData("$ForceMove "..arg)

		end
	end
--------oDC Check----------

This way i get the following error:

Syntax error: bad argument #1 to `strfind' (string expected, got function)
stack traceback:
   1:  function `strfind' [C]
   2:  function `DataArrival' at line 440

Any ideas ?


**Snooze

nErBoS

Hi,

That sounds me the delay of MyInfoString, try to put in the beggining of DataArrival if (user.sMyInfoString ~= nil) then...

Best regards, nErBoS
--## nErBoS Spot ##--

NightLitch

Here use this one:

--------oDC Check----------
	if not (user.bOperator) then 
		ratio = tonumber(frmHub:GetSlotRatio())
		arg = frmHub:GetRedirectAddress()
		arg2 = frmHub:GetMaxHubs()
		arg3 = frmHub:GetMinSlots()
               hubs = 0
-- HERE IS YOUR PROBLEM, you had tag here it should be data.
--               s,e,thubs,slots = strfind(tag,  "H:([%d%/]+),S:(%d+)%S*>")
               s,e,thubs,slots = strfind(data,  "H:([%d%/]+),S:(%d+)%S*>")

-- HERE IS YOUR PROBLEM, you had tag here it should be data.

               if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                     hubs = hubs +tonumber(num)
                  end)
               else
                  hubs = tonumber(thubs)
               end
               slots = tonumber(slots)
			if tonumber(slots) < (ratio*hubc) then
				user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubc * ratio)
				user:SendData("$ForceMove "..arg)
			elseif hubc > arg2 then
				user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
				user:SendData("$ForceMove "..arg)
			elseif slots < arg3 then
				user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
				user:SendData("$ForceMove "..arg)

		end
	end
--------oDC Check----------

/NightLitch
//NL

NightLitch

#5
I asuming you have this in your code I fixed above the function you needed help with.

if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then

/NightLitch
//NL

Snooze

Thanks guys ..

what i have now is this:

--------oDC Check----------
	if not (user.bOperator) then 
		ratio = tonumber(frmHub:GetSlotRatio())
		arg = frmHub:GetRedirectAddress()
		arg2 = frmHub:GetMaxHubs()
		arg3 = frmHub:GetMinSlots()
               hubs = 0
	       if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
               s,e,thubs,slots = strfind(data,  "H:([%d%/]+),S:(%d+)%S*>")
               if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                     hubs = hubs +tonumber(num)
                  end)
               else
                  hubs = tonumber(thubs)
               end
               slots = tonumber(slots)
			if slots < (ratio*hubs) then
				user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubs * ratio)
				user:SendData("$ForceMove "..arg)
			elseif hubc > arg2 then
				user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
				user:SendData("$ForceMove "..arg)
			elseif slots < arg3 then
				user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
				user:SendData("$ForceMove "..arg)

			end
		end
	end
--------oDC Check----------

This gives me:

Syntax error: attempt to compare nil with number
stack traceback:
   1:  function `DataArrival' at line 453

i cant really see where that nil should come from ... looks like its all covered now .. ?

Snooze

oops .. fixed the "elseif hubc > arg2 then
" part too... though still getting the same error ..

**Snooze

NightLitch

You get that nil when a user logs in without a proper tag -notag-

you need to resolve the nil like this:

s,e,thubs,slots = strfind(data,  "H:([%d%/]+),S:(%d+)%S*>")
if thubs==nil or slots==nil then
user:SendData(Bot, "You are hiding your tag !!")
user:Disconnect()
end
               if tonumber(thubs) == nil then
                  gsub(thubs, "(%d+)", function (num)
                     hubs = hubs +tonumber(num)
                  end)
               else
                  hubs = tonumber(thubs)
               end
//NL

Snooze

Thats it !!! :D

Thanks plop, nErBoS and NightLitch :-)

You've just saved me tons of trouble :D



**Snooze

plop

yw snooze.
sorry about that small error on "tag", i just copyed that piece of code from a bot i made in the past for trucker.
didn't think of the fact that i handle the tag slightly different then most of you guy's.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Snooze

No problem at all plop .. i should really have found that error myself .. were goin "blind" on this piece of code :(

Thanks again :)

Snooze

SMF spam blocked by CleanTalk