• Welcome to Valhalla Legends Archive.
 

Avoiding Flooding out

Started by Don Cullen, July 26, 2006, 05:17 PM

Previous topic - Next topic

Don Cullen

This is the sub that sends the SID_CHATCOMMAND packet:

Public Sub Transmit(TextToSend As String) 'SID_CHATCOMMAND (0x0E)
    RaiseEvent OCXDebugger("Generating SID_CHATCOMMAND (0x0E) packet...")
    With PacketBuf
        .InsertNTString TextToSend
        .SendPacket Winsock1, &HE  'Send 0x0E packet
    End With
    RaiseEvent OCXDebugger("Sent with text of: " & TextToSend)
End Sub


How would I go about putting in code that would pretty much protect the bot against accidental flooding out? I found this:

http://www.valhallalegends.com/docs/groksantiflood.htm

Is that the best code to use, or are there more efficent ways? I've experimented with my own delay codes, but all of them delayed too much when a long text was inputted. If Adron's AntiFlood Algorithm is the best one to use, then how would I implement this in the code I just provided above? From what I imagine, all SID_CHATCOMMAND's would be inserted into a queue (which I have not set up, it currently sends as soon as the user inputs something), then a timer set to a specific timer interval would fire (what's the best interval?), in doing so, it'd check queue, and use RequiredDelay (passing along the SID_CHATCOMMAND byte length to it- how would I get byte length?). Once RequiredDelay came up zero, it'd send the first item in the queue, then erase the first item in the queue and resort the queue.

I'd love to implement this. I was also wondering- is it possible to set up a prioritized queue- perhaps multi-dimensioned? Example using pseudo-code:

Type Queue(200)
    DataToSend as String
    Priority as String
End Type

Then in resorting:

Sort(Queue, Priority)

DataToSend would remain in the same row as its corresponding priority, the higher the number, the higher the priority. I've been trying to wrap my mind around this, I can understand how it works, but as to how to accomplish this via code? I'm completely lost... Any guidance would be appreciated!

Many thanks in advance!
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

MyndFyre

Well a question first:

Why are you storing priority as a String instead of as an Integer?

Aside from that, your queue should be in the subroutine that transmits your data, not in the send-chat part.  The only packet that shouldn't be enqueued (IMO) is SID_PING.  You can flood off sending any combination of packets, so if you're repeatedly requesting a ladder list (for instance) you could flood off.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Don Cullen

Ack, sorry, didn't think. Tired, only had three hours of sleep.

Priority'd be an integer.

As for the rest, in that case, would this be the best one to use (I didn't code this one so I can't take credit for it):

Public Function SendPacket(sck As Winsock, Optional PacketID As Long, Optional mode As Integer = 1) As Boolean
    On Error GoTo DumpHex
    If sck.State = sckConnected Then
        If mode = 1 Then    'Game mode
            sck.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer
        ElseIf mode = 2 Then 'bnFTP mode
            sck.SendData MakeWORD(Len(Buffer) + 4) & Buffer
            'DumpPacket MakeWORD(Len(Buffer) + 3) & Buffer
            'AddC "BNFTP Packet Sent! Packet: " & MakeWORD(Len(Buffer) + 3) & Buffer
        End If
        SendPacket = True
    End If
    Clear
    On Error GoTo 0
    Exit Function
DumpHex:
End Function


Would that be the best place to pop the RequiredDelay in?
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.