• Welcome to Valhalla Legends Archive.
 

Adron's Flood Protection

Started by FuZe, July 27, 2003, 05:40 PM

Previous topic - Next topic

FuZe

I looked up Adron's Flood protection in documents, and the delay that I get is wayyy too long. Has anyone gotten this to work?

Camel

This code is a little old, but should still be quite functional.

http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=1256;start=msg9485#msg9485

Quote from: Camel on May 08, 2003, 07:18 PM
chat.bas:

Option Explicit

Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public LastChat As Long, TimerID As Long
Dim SendBuf As String, LastChatLen As Integer
Public Const AntiIdleTimerID As Long = 0

Public Sub DelQueue()
   SendBuf = ""
   If TimerID Then
       KillTimer frmMain.hwnd, 1
       TimerID = 0
   End If
   LastChat = 0
   If frmMain.SCK.State = sckConnected Then SendText "queue flushed"
End Sub

Private Sub CheckSend(Optional ForceTimerUse As Long = 0)
   Dim delay As Long
   
#If DEBUG_ Then
   delay = 0
#Else
   delay = LastChatLen 'CVI(Mid(sendbuf, 3, 2))
   delay = delay * 15 + 2700
#End If
   
   delay = (delay + LastChat) - GetTickCount
   If delay < 0 Then delay = 0
   
   delay = delay + ForceTimerUse

   If delay > 0 Then
       If TimerID <> 0 Then KillTimer frmMain.hwnd, TimerID
       TimerID = SetTimer(frmMain.hwnd, 2, delay, AddressOf SendQueue)
   Else
       SendQueue
   End If
End Sub

Public Sub SendQueue()
   If TimerID <> 0 Then
       'debug.assert false
       KillTimer frmMain.hwnd, TimerID '1
       TimerID = 0
   End If
   
   If Not frmMain.SendChatOK Then
       'if its disconnected, clear buffer
       If frmMain.SCK.State = sckConnected Then
           CheckSend 1000 'start another timer
       Else
           
       End If
   Else
       If Len(SendBuf) > 0 Then
           Dim plen As Integer
           plen = CVI(Mid(SendBuf, 3, 2))
           
           LastChat = GetTickCount
           LastChatLen = plen - 4
           
           If frmMain.SCK.State = sckConnected Then
               'Dim strText As String
               'strText = Mid(SendBuf, 5, plen - 5)
               'strText = Left(strText, InStr(1, strText, Chr(0)) - 1)
               
               On Error GoTo error
               
               frmMain.SCK.SendData Left(SendBuf, plen)
               If Mid(SendBuf, 5, 1) <> "/" Then
                   UserChats MyName, Mid(SendBuf, 5, plen - 5), GetFlags(MyName, MyFlags) 'frmMain.Script.Run("GetFlags", MyName, MyFlags)
               Else
                   'Addtext ColInfo, "SENDING COMMAND: " & Mid(SendBuf, 5, plen - 5) & vbCrLf, True
               End If
               
               SendBuf = Right(SendBuf, Len(SendBuf) - plen)
               ResetAntiIdle
           Else
               Debug.Assert False
               SendBuf = ""
           End If
       End If
   
       If Len(SendBuf) > 0 Then CheckSend
   End If
   
   Exit Sub
error:
   Addtext ColAnError, "Error in SendQueue(): " & ERR.Number & " - " & ERR.Description & vbCrLf, True
End Sub

Public Sub SendText(strText As String, Optional WhisperBack As String = "", Optional ForceTimerUse As Long, Optional DontChange As Boolean = False, Optional SkipUTF8Encode As Boolean = False)
   Const m = 200
   
#If DEBUG_ <> 0 Then
   If InStr(strText, Chr(0)) <> 0 Then Debug.Assert False
#End If

   If Not SkipUTF8Encode Then strText = UTF8Encode(strText)

   If DontChange Then GoTo sendnow
   
   If InStr(strText, "%ver%") Then strText = Replace(strText, "%ver%", version)
   If InStr(strText, "%running%") Then strText = Replace(strText, "%running%", GetTime(GetTickCount - StartTime))
   If InStr(strText, "%connected%") Then strText = Replace(strText, "%connected%", GetTime(GetTickCount - LogTime))
   If InStr(strText, "%uptime%") Then strText = Replace(strText, "%uptime%", GetTime(GetTickCount))
   strText = Replace(strText, "%channel%", Channel)
   strText = Replace(strText, "%server%", frmSetup.SAddr)
   If InStr(strText, "%mp3%") Then strText = Replace(strText, "%mp3%", winamp.GetSongTitle(False))
   If InStr(strText, "%mp3full%") Then strText = Replace(strText, "%mp3full%", winamp.GetSongTitle(True))
   If InStr(strText, "%cpu%") Then strText = Replace(strText, "%cpu%", GetCPUInfo)
   
   If (WhisperBack = MyName) And (MyName <> "") Then
       Addtext D2LtYellow, strText & vbCrLf, True
       Exit Sub
   End If
   
   If (Left(strText, 1) <> "/") And (WhisperBack <> "") Then
       strText = "/m " & WhisperBack & " " & strText
   End If
   
   Dim s() As String
   s = Split(strText, " ", 2)
   
   If Not MyFlags And 2 Then
       Select Case s(0)
           Case "/kick", "/ban"
               Addtext ColAnError, "WARNING: Supressing command due to lack of ops (use /quote to override): " & strText & vbCrLf, True
               Exit Sub
       End Select
   End If
   
   Select Case GetID
       Case "VD2D", "PX2D"
           If (Left(strText, 1) = "/") And (InStr(1, strText, " ") > 0) Then
               Dim Name As String
               Name = s(1)
               If InStr(1, Name, " ") Then Name = Left(Name, InStr(1, Name, " ") - 1)
               
               If (InStr(Name, "*") = 0) Then
                   Select Case s(0)
                       Case "/w", "/m", "/msg", "/whisper", "/whois", "/kick", "/ban", "/unban", "/designate", "/ignore", "/squelch", "/unignore", "/unsquelch"
                           strText = s(0) & " *" & s(1)
                   End Select
               End If
           End If
   End Select
   
sendnow:
   
   SendBuf = SendBuf & MakePacket(&HE, Left(strText, m) & Chr(0))
   CheckSend ForceTimerUse
End Sub

Public Sub ResetAntiIdle()
   KillTimer frmMain.hwnd, AntiIdleTimerID
   SetTimer frmMain.hwnd, AntiIdleTimerID, frmSetup.IdleTime, AddressOf AntiIdle
End Sub

Public Sub AntiIdle()
   If frmSetup.Idle <> "" Then SendText frmSetup.Idle
End Sub


DarkMinion

And with all that crap, you can still flood off.

*claps*

FuZe


unsigned long tick = GetTickCount();
   if(lasttick - tick > sentbytes * msperbyte)
       sentbytes = 0;
   else
       sentbytes -= (lasttick-tick) / msperbyte;
   lasttick = tick;


I think one of the reasons I get such a high number is because the first lasttick-tick will be a huge number since lasttick will = 0 and tick will equal whatever milliseconds.  How would I go about bypassing this?

Maddox

Quote from: DarkMinion on July 27, 2003, 05:58 PM
And with all that crap, you can still flood off.

*claps*

And notice Adron's flood protection is in C++ not VB.
asdf.

Camel

Eh, nobody explicitly said C so I assumed it was VB. Oh well.

And DM, what? I havnt flooded off in...well I can't remember that long ago. I automatically flush the queue if I get a 'that user is not logged on' message from battle.net. That prevents virtually all floodbots from doing any damage.

FuZe

#6
Quote from: Maddox on July 27, 2003, 07:13 PM
Quote from: DarkMinion on July 27, 2003, 05:58 PM
And with all that crap, you can still flood off.

*claps*

And notice Adron's flood protection is in C++ not VB.

I changed his to vb

Private Function RequiredDelay(ByVal Bytes As Long) As Long
   

   Static lastTick As Long
   Static sentBytes As Long
   Const perPacket = 200
   Const msPerByte = 10
   Const maxBytes = 600
   Dim Tick As Long
 
   Tick = GetTickCount()    
   
   If lastTick - Tick > sentBytes * msPerByte Then
       sentBytes = 0
   Else
       sentBytes = sentBytes - (lastTick - Tick) / msPerByte
   End If
   lastTick = Tick
   If sentBytes + perPacket + Bytes > maxBytes Then
       RequiredDelay = (sentBytes + perPacket + Bytes - maxBytes) * msPerByte
       Exit Function
   End If
   sentBytes = sentBytes + perPacket + Bytes
   RequiredDelay = 0
   

   
   
   
   
End Function


o yeh and I did see groks vb version but I just wanted to change it by myself..

Adron

Quote from: FuZe- on July 27, 2003, 06:38 PM
I think one of the reasons I get such a high number is because the first lasttick-tick will be a huge number since lasttick will = 0 and tick will equal whatever milliseconds.  How would I go about bypassing this?

You could initialize lasttick to GetTickCount() when starting.
You could have a special case for lasttick = 0.

I think there's a bug with sign somewhere in my posted code. Something that should be a small positive number comes out a small negative or huge positive number.  Look on the forum for exact details, I'm pretty sure someone pointed out in a post not too long ago.


UserLoser

Warcraft III has a flood protection on it that will never allow you to flood off on it.  Couldn't someone who *knows how* to disassemble just find out and use the method that the game uses?

Mesiah / haiseM

i bet i could flood off via the war3 client.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

UserLoser


Kp

Quote from: UserLoser on July 29, 2003, 02:25 PM
Warcraft III has a flood protection on it that will never allow you to flood off on it.  Couldn't someone who *knows how* to disassemble just find out and use the method that the game uses?
Making a flood protection algorithm that keeps you from flooding and making one that doesn't become a pain to use are different things.  The former could be achieved by simply imposing some large delay between every message and tacking on several seconds for each message beyond the first.  After a while, you wouldn't be able to talk - but you'd never flood. :p
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Camel

you could text in short bursts, too...