Author Topic: FreeSlot Checker malfunction...  (Read 2069 times)

0 Members and 1 Guest are viewing this topic.

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
FreeSlot Checker malfunction...
« on: 03 March, 2004, 19:07:11 »
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..

Code: [Select]
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 ##--

PtokaX forum

FreeSlot Checker malfunction...
« on: 03 March, 2004, 19:07:11 »

Offline NotRabidWombat

  • Lord
  • ***
  • Posts: 384
  • Karma: +2/-0
(No subject)
« Reply #1 on: 03 March, 2004, 19:51:40 »
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:
Code: [Select]
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:
Code: [Select]
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.

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #2 on: 03 March, 2004, 20:53:39 »
Hi,

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

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

Offline Snooze

  • Scripter
  • Viking
  • ******
  • Posts: 606
  • Karma: +54/-3
    • DiXBoT Website
(No subject)
« Reply #3 on: 20 March, 2004, 03:26:07 »
Any chance of you posting the finished slot script ? ;)


**Snooze

Herodes

  • Guest
(No subject)
« Reply #4 on: 17 June, 2004, 02:51:42 »
Quote
Originally posted by Snooze
Any chance of you posting the finished slot script ? ;)


true... :rolleyes:

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #5 on: 17 June, 2004, 03:09:13 »
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
« Last Edit: 17 June, 2004, 03:09:51 by 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 <----<<

PtokaX forum

(No subject)
« Reply #5 on: 17 June, 2004, 03:09:13 »