• Welcome to Valhalla Legends Archive.
 

Grok's Anti-Flood

Started by BlazingKnight, March 25, 2003, 08:35 PM

Previous topic - Next topic

BlazingKnight

Hey Grok, I just made a bot w/ a auto-welcome in it, and if there's more than 2 people in the channel, it will flood itself. I want to use your anti-flood script, but I don't know what you mean by "mySendProc" and "myMessage" are they supposed to be the send button and the txtField? Just fill me in, so I can adjust it to my bot, so I don't get a compile error.

MrRaza

If you private messaged him, you'd probably get a faster response.

Banana fanna fo fanna

They're exactly what he said they were. Use your head, if you don't know what a proc is, you shouldn't be writing a bot.

Grok

"mySendProc" would represent the procedure you write to transmit the specific message for which you just did the calculation.  Because you just verified the message won't flood you (using 2-year old battle.net flood rules), go ahead and send that message.

FYI, the anti-flood algorithm was derived by Adron.  I converted it to VB for the community.

FYI #2, it begins to fail after 35 messages.  Blizzard added in another variable for which nobody has yet derived how it fits in the formula.

MrRaza

Quote from: Grok on March 26, 2003, 11:21 AM
"mySendProc" would represent the procedure you write to transmit the specific message for which you just did the calculation.  

You might want to dumb it down for him.

Grok

I thought I did, but ok...

Pretend you wrote a well-structured program.  Because you need "flood control", you would probably write a single send function, where you can check if it is safe to send a message.  For shits and giggles, call that function "mySendProc".

I suggest creating a class for managing your message queue.  It should present an add method, getnextmessage, count, and an eof (eomessages anyway), at the least.  Use this class to add your message to the queue.

Inside this mySendProc function, we get the next message from the queue, then see if it is safe to send it.  Let's pretend it returned the value 0.  That means we have to wait 0 or more milliseconds to send our message.  Thus, it is safe to go ahead and send.

So "if waittime = 0 then ws.send mymessage".  Now we probably want to immediately see if it is safe to send the next message in the queue.  That indicates we are probably in some kind of loop, like

sub MySendProc( .... )

waitttime = CalculateWaitTime(msgqueue.getnextmessage)
do while waittime = 0 or msgqueue.eof = false     'no wait time and messages exist
   mymessage = msgqueue.removemessage    'gets top message and removes from queue
   ws.send mymessage
   'do other smart maintenance stuff here
   'get next message waittime
   waittime = CalculateWaitTime(msgqueue.getnextmessage)   'or whatever it is called
loop
'exited for some reason.  if waittime > 0, reason was a message was not safe to send.
'in this case, we want to schedule the next send
if waittime > 0 then
   lRet = CreateTimer( .... waittime, MySendProc() .... )   'look it up in msdn or arta's docs or botdev docs
end if

msgqueue might be some class you created to make it easy to queue messages and manage their add/delete and status like EOF (eomessages).

anyway, there's enough information here to create a clean design.  it's only one possibility and there are others.  it's probably how i would do it on my first try if i were writing a bot.

Banana fanna fo fanna

Grok stop giving out code, it hurts the community.

Just look at CSB (ok, not quite code, but you know what I mean).