• Welcome to Valhalla Legends Archive.
 

Packet/Message Query

Started by turtles, May 08, 2003, 10:50 AM

Previous topic - Next topic

turtles

Has anyone had trouble getting messages to to query properly?
I have this problem solved, but im hoping someone would have a more flexible script for querying messages and then sending them.
One of the Main problems was that
Doevents kept processing the same command twice.. i cant leave out Doevents cuz if i dont have it. the message wont send until EVERYTHING is done processing then it would send. and if u have more the 5 messages in query . instead of leaking out one packet send at a time despite a timer delay. it would send all 5 at same time and cause a flood out =)
As i have said b4. i have this problem solved.
just curious about who else had this minor problem and what kinda code they used. plus. i didnt see a post of this type within the last 40 topics

Yoni

What problem were you having? Your message was not clear.

Keep in mind not everyone here uses VB (I conclude you're using VB because you're talking about "DoEvents").
Also, there is not one correct way to do something - there are many. Not everyone writes code in the same style as you. For example, you use DoEvents. It is possible (and advisable, in most situations) to refrain from using this statement/function at all - and it is certainly possible to write a bot without it.

You say you have this problem (which I'm not yet sure what it is) solved, but are hoping someone has a better way to do it. Better than what? You didn't explain how you solved it, nor posted any code.

turtles

since doevents in my code causes some commands to process twice. i used a stopper at the begginning of Case &HF where it checks the previous data to match with the new one. if the new one was a spawn brought on by doevents. it cancels it out.
Doevents for some reason pulls the same information out of winsock a second time.
and another reason why i use doevents is for my delay timer.
if i just use sleep. the bot gui will become inaccessible during the wait time inside the do loop
the code serves that function + it works ok as anti abuse. so wont have a lamer spamming the same command.

erm. yoni. so what do u suggest i use other then doevents. im fairly new at vB and im learning as i go along.

and got any other suggestion other then a do loop / sleep timer ?

Yoni

Don't use Sleep in VB.

Actually, don't use Sleep.

turtles

Quote from: Yoni on May 08, 2003, 12:26 PM
Don't use Sleep in VB.

Actually, don't use Sleep.

erm. so do loop should be used. got that down already. kudos.

tA-Kane

Quote from: turtles on May 08, 2003, 12:12 PM
and wtf is up with the karma.. i got +0/-2 . i bet Raza did that to me. ;\ ..
b¡tch.. -_-
MrRaza couldn't do it more than once in a single 12 hour period. Oh, and by the way, it's not really that nice to bring topics back from the dead with your first post on the dead topic being "AHAHAHA I BROUGHT THIS TOPIC BACK" or something of that nature. Also, you should be a whole lot more clear on what you're trying to say. To me, you have yet to clearly state what your problem is.

Quote from: turtles on May 08, 2003, 12:29 PM
Quote from: Yoni on May 08, 2003, 12:26 PM
Don't use Sleep in VB.

Actually, don't use Sleep.

erm. so do loop should be used. got that down already. kudos.
Do ... Loop should only be used when appropriate. Are you sure it's appropriate? Maybe if you were to clearly state what you are trying to do, and perhaps post some code to how you're doing it, people here may be more forthcoming with help.
Macintosh programmer and enthusiast.
Battle.net Bot Programming: http://www.bash.org/?240059
I can write programs. Can you right them?

http://www.clan-mac.com
http://www.eve-online.com

turtles

Scenario:
Sent a message 5 times in less then a second.

Each has a delay of 3 seconds each.

Problem1:
Without DoEvents the bot will wait 15 seconds. Then it will spam 5 sends and flood out.

Problem2:
With DoEvents the bot will send one message every three seconds but...
it sends more then 5 sends..
it processed one of the commands more then once. the first one i believe.

Yoni

Pseudo-VB-code:

Private Sub MessageDelay_Timer()
   If MessageQueue.Empty Then
       MessageDelay.Enabled = False
   Else
       Call BinaryBot.Talk(MessageQueue.Pop)
   End If
End Sub

Private Sub OnMessage(ByVal Message As String)
   If MessageDelay.Enabled Then
       Call MessageQueue.Push(Message)
   Else
       Call BinaryBot.Talk(Message)
   End If
   MessageDelay.Enabled = True
End Sub

' If you wish to use DoEvents, uncomment this:
'Private Sub MagicButton_Click()
'    DoEvents
'End Sub

tA-Kane

Quote from: turtles on May 08, 2003, 04:20 PM
Scenario:
Sent a message 5 times in less then a second.

Each has a delay of 3 seconds each.

Problem1:
Without DoEvents the bot will wait 15 seconds. Then it will spam 5 sends and flood out.

Problem2:
With DoEvents the bot will send one message every three seconds but...
it sends more then 5 sends..
it processed one of the commands more then once. the first one i believe.
I beleive DoEvents causes VB to fire any pending events.

An alternative way to do this is to create a timer and a string array. Whenever you need to send a string, you add the string to the array. Then, whenever the timer fires, you can then send a string from the array and then remove it. There've been plenty of topics on the forum regarding Timer problems and such, so do a search for "timer" to find a way around them.
Macintosh programmer and enthusiast.
Battle.net Bot Programming: http://www.bash.org/?240059
I can write programs. Can you right them?

http://www.clan-mac.com
http://www.eve-online.com

Camel

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

turtles

Quote from: tA-Kane on May 08, 2003, 04:30 PM
Quote from: turtles on May 08, 2003, 04:20 PM
Scenario:
Sent a message 5 times in less then a second.

Each has a delay of 3 seconds each.

Problem1:
Without DoEvents the bot will wait 15 seconds. Then it will spam 5 sends and flood out.

Problem2:
With DoEvents the bot will send one message every three seconds but...
it sends more then 5 sends..
it processed one of the commands more then once. the first one i believe.
I beleive DoEvents causes VB to fire any pending events.

An alternative way to do this is to create a timer and a string array. Whenever you need to send a string, you add the string to the array. Then, whenever the timer fires, you can then send a string from the array and then remove it. There've been plenty of topics on the forum regarding Timer problems and such, so do a search for "timer" to find a way around them.

i used search and looked for timer.  many of the posts referred to

setTimer / killTimer

does setTimer work in milliseconds or seconds ?

tA-Kane

Quote from: turtles on May 08, 2003, 09:37 PMdoes setTimer work in milliseconds or seconds ?
I don't know, look it up on MSN.net.
Macintosh programmer and enthusiast.
Battle.net Bot Programming: http://www.bash.org/?240059
I can write programs. Can you right them?

http://www.clan-mac.com
http://www.eve-online.com

Camel

milliseconds
why dont you just try it? real men don't need instructions...they just look at the picture :)

turtles

Quote from: Camel on May 09, 2003, 01:03 AM
milliseconds
why dont you just try it? real men don't need instructions...they just look at the picture :)

im just lazy.  :-X

i work on my bot whenever i need to keep my mind off of things...  ;D