FreeSlot Checker malfunction...
 

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

FreeSlot Checker malfunction...

Started by nErBoS, 03 March, 2004, 19:07:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nErBoS

Hi all,

Help me out where...
I get this part of code from guibs channelbot to put on my  bot but it seems not working well, where is the code..

Bot = "Teste"

tabSlots = {n=0}
tmrSlots = 10

function Main()
frmHub:RegBot(Bot)
end

function DataArrival(user, data)

if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
	data=strsub(data,1,strlen(data)-1)
	s,e,cmd = strfind(data,"%b<>%s+(%S+)")
		if (cmd=="!slots") then 
			user:SendData(Bot, "SEARCHING...")
			tinsert(tabSlots, { sName = user.sName, iClock = clock(), tItems = {} })
			DoCheckFreeSlots = "on"
			SendToAll("$Search Hub:"..Bot.." T?F?0?1?.|")
		end
end

if DoCheckFreeSlots == "on" then
	frmHub:EnableSearchData(1)
	if (strsub(data, 1, 3) == "$SR") then
		slots = 0
		local s, e, nickname, descri, size, free, all = strfind(data, "%s+(%S+)%s+(.*)(%d+)%s(%d+)/(%d+)")
		local i = 1 
		while tabSlots[i] do
		local table = tabSlots[i]
		local usr = GetItemByName(table.sName)
			if not table.tItems[user.sName] then
				slots = 0
				if ((free ~= "0") and (all ~= nil) and (size~= nil) and (free ~= nil)) then
					table.tItems[user.sName] = free.."/"..all
					usr:SendData(Bot, " user "..user.sName.." "..free.."/"..all)
				end
			end

			if (clock() >= table.iClock + tmrSlots) then
				if slots==0 then
					usr:SendData(Bot, "NO SLOTS FOUND")
				end
				usr:SendData(Bot, "DONE")
				tremove(tabSlots, i)
				DoCheckFreeSlots = "off"
				frmHub:EnableSearchData(0)
			else 
				i = i + 1 
			end
		end
	end
end
end

The problem is when i do !slots the script sends this..
[17:57] SEARCHING...
[17:57]  user nErBoS 2/2
and i wait more then 10 secs and i doesn't nothing else, but he should send me DONE.
When i type again !slots the script sends this..
[17:57] SEARCHING...
[17:57] NO SLOTS FOUND
[17:57] DONE
[17:57]  user nErBoS 2/2

In my opinion is missing a break on the while, but it wouldn't make any affect because the bug still happens

Can any one help me out here ??

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

NotRabidWombat

I am assuming there are only two users on your test hub.

Here is what is happening when you test:

1) You begin a slot check.
   a) Sends out a search to all users
   b) Creates a table entry of the user that began the slot check. This table has an element that is the clock cycle this was started at
2) The first and only search result is returned. This block is executed:
if not table.tItems[user.sName] then
   slots = 0

   if ((free ~= "0") and (all ~= nil) and (size~= nil) and (free ~= nil)) then
      table.tItems[user.sName] = free.."/"..all

      usr:SendData(Bot, " user "..user.sName.." "..free.."/"..all)
   end
end
Here lies the first problem (not related to what you're doing). What if two people searched at exactly the same time? You will see doubles of everything AND the two users who intialized the search will not see each other's names. "not table.tItems[user.sName]" So this code is not designed for many users using it at the same time.

The next section of code is what annouces the stop:
if (clock() >= table.iClock + tmrSlots) then
   if slots==0 then
      usr:SendData(Bot, "NO SLOTS FOUND")
   end
   usr:SendData(Bot, "DONE")
   tremove(tabSlots, i)
   DoCheckFreeSlots = "off"
   frmHub:EnableSearchData(0)
else 
   i = i + 1 
end
This section of code is only executed upon receiving a $SR (Search Response).  So if there is only one user responding (and this user responds very quickly), there will be no way to detect if you have passed the timeout (10 milliseconds?). I suggest making a OnTimer function that handles removing the users from the tabSlots table.

It may also be wise to maintain an entire table of slot results. That way you can eliminate doubles and handle to slot requests within 0.5 seconds without sending out another search request.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

nErBoS

Hi,

Thanks RabidWombat for the good explanion. Made a timer and solved the problem.

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

Snooze

Any chance of you posting the finished slot script ? ;)


**Snooze

Herodes

QuoteOriginally posted by Snooze
Any chance of you posting the finished slot script ? ;)


true... :rolleyes:

plop

#5
opiumvollage and 2 other have rewriten this script with the help from wombat in the past  2 make work it a bit better (testdrive+ only).
it's on my site on the page of opium.

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 <----<<

SMF spam blocked by CleanTalk