Valhalla Legends Forums Archive | Battle.net Bot Development | Avoiding Flooding out

AuthorMessageTime
LockesRabb
This is the sub that sends the SID_CHATCOMMAND packet:

[code]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[/code]

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!
July 26, 2006, 10:17 PM
Myndfyr
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.
July 26, 2006, 10:33 PM
LockesRabb
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):

[code]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[/code]

Would that be the best place to pop the RequiredDelay in?
July 26, 2006, 10:41 PM

Search