Valhalla Legends Forums Archive | Visual Basic Programming | [RESOLVED] Disappearing Packets?

AuthorMessageTime
shadypalm88
I'm writing a bot in VB that uses the Winsock 2 API directly and not the control. It uses WSAAsyncSelect to have notifications of connects, disconnects, and data waiting to be read sent to a hidden text field whose message handler has been replaced. It first makes a connection to BNLS, and after it has recieved the version byte, connects to b.net and fires off an SID_AUTH_INFO. After it gets the response back, it sends a BNLS_CDKEY_EX packet to BNLS. Ethereal shows that the reply arrives, but no notification is sent to my bot. Any ideas on what might be happening here?
May 2, 2004, 10:10 PM
Grok
[quote author=shadypalm88 link=board=31;threadid=6625;start=0#msg58149 date=1083535848]
I'm writing a bot in VB that uses the Winsock 2 API directly and not the control. It uses WSAAsyncSelect to have notifications of connects, disconnects, and data waiting to be read sent to a hidden text field whose message handler has been replaced. It first makes a connection to BNLS, and after it has recieved the version byte, connects to b.net and fires off an SID_AUTH_INFO. After it gets the response back, it sends a BNLS_CDKEY_EX packet to BNLS. Ethereal shows that the reply arrives, but no notification is sent to my bot. Any ideas on what might be happening here?
[/quote]

Well, judging from your source code ....






Oh wait. we can't do that, now can we?
May 2, 2004, 10:54 PM
shadypalm88
Knock yourself out...

Here's the message handler, along with the code it uses to find out which bot a given message is for.[code]Public Type whData
Active As Boolean
BotKey As String
WindowHandle As Long
SockType As mSocketType
End Type

Public Enum mSocketType
sBattleNet
sBNLS
sInvalid
End Enum

Public Enum mSocketEvent
sConnect
sDisconnect
sData
End Enum

'-----------------------------------------------------------------------------------
' Variables
'-----------------------------------------------------------------------------------

Public WindowMap() As whData, NextWindowMap&

'-----------------------------------------------------------------------------------
' Message Handler
'-----------------------------------------------------------------------------------

Private Function GetBotFromWindow(hWnd As Long, BotKey As String, SockType As mSocketType) As Boolean
Dim i&
SockType = sInvalid
GetBotFromWindow = False
For i = LBound(WindowMap) To UBound(WindowMap)
If WindowMap(i).Active And WindowMap(i).WindowHandle = hWnd Then
With WindowMap(i)
BotKey = .BotKey
SockType = .SockType
End With
GetBotFromWindow = True
Exit Function
End If
Next i
End Function

Public Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim evType&, Bot$, Count&, Buf$, SocketType As mSocketType, Sock&
Select Case wMsg
Case WM_SOCKEVENT
evType = lParam And &HFFFF&
If Not GetBotFromWindow(hWnd, Bot, SocketType) Then Exit Function
Select Case evType
Case FD_CONNECT
Bots(Bot).SocketEvent sConnect, SocketType
Case FD_CLOSE
Bots(Bot).SocketEvent sDisconnect, SocketType
Case FD_READ
If SocketType = sBattleNet Then
'Debug.Print "[B.NET] DATA"
Sock = Bots(Bot).GetSock()
ElseIf SocketType = sBNLS Then
'Debug.Print "[BNLS] DATA"
Sock = Bots(Bot).GetBNLSSock()
Else
Debug.Print "[?] DATA"
Exit Function
End If
Call ioctlsocket(Sock, FIONREAD, Count)
Buf = String$(Count&, Chr$(0))
Call recv(Sock, Buf, Count, 0)
Bots(Bot).SocketEvent sData, SocketType, Buf, Count
End Select
Case WM_CLOSE
AddC "Socket closed.", vbRed
End Select

End Function[/code]

All relevant parts of the socket encapsulator class (named Arbiter):[code]Option Explicit

Private Ready As Boolean
Private sType As mSocketType
Private sBot As String
Private LastTransmission$
Public Sock As Long

Public Enum PuppetResult
spOK
spErrSockAllocate
spErrSockSelect
spErrBind
spErrListen
End Enum

Private Type CreateSocketResult
Sock As Long
Result As PuppetResult
End Type


Private Sub Class_Initialize()
Ready = False
End Sub

Public Function Initialize(msgReciever As Long, Bot As String, SockType As mSocketType) As Boolean
Dim Result As CreateSocketResult
Result = CreateSocket(msgReciever, Bot, SockType)
If (Result.Result = spOK) Then
Initialize = True
Ready = True
sType = SockType
sBot = Bot
Sock = Result.Sock
Else
Initialize = False
End If
End Function

Public Function Connect(Location As String, Port As Long) As Boolean
Dim sockBuf As sockaddr, Host As HostEnt, RealError&
sockBuf.sin_family = AF_INET
sockBuf.sin_port = htons(Port)
sockBuf.sin_addr = GetHostByNameAlias(Location)
If (Winsock.Connect(Sock, sockBuf, Len(sockBuf)) = -1) Then
RealError = WSAGetLastError()
If (RealError <> WSAEWOULDBLOCK And RealError > 0) Then
MsgBox "Socket Error " & RealError & ": " & GetWSAErrorString(RealError), vbExclamation, "Arbiter Network Class"
Connect = False
Else
Connect = True
End If
Else
Connect = True
End If
End Function

Private Function CreateSocket(wh As Long, Bot As String, SockType As mSocketType) As CreateSocketResult
Dim socketBuffer As sockaddr, Host As HostEnt, RealError As Long, Sock As Long
Sock = Socket(AF_INET, SOCK_STREAM, 0)
CreateSocket.Sock = Sock
If Sock = -1 Then
MsgBox "Socket error: " & WSAGetLastError()
CreateSocket.Result = spErrSockAllocate
Else
ReDim Preserve WindowMap(NextWindowMap) As whData
With WindowMap(NextWindowMap)
.Active = True
.BotKey = Bot
.SockType = SockType
.WindowHandle = wh
End With
Call SetWindowLong(wh, GWL_WNDPROC, AddressOf WindowProc)
If (WSAAsyncSelect(Sock&, wh, ByVal WM_SOCKEVENT, ByVal FD_READ + FD_CLOSE + FD_CONNECT) = -1) Then
CreateSocket.Result = spErrSockSelect
Exit Function
Else
CreateSocket.Result = spOK
End If
End If
End Function[/code]

And the actual code used to make a socket...[code]Private BNLS As New Arbiter
<..snip..>
Public Function Connect() As Boolean
'Load frmMain.txtRecv(0)
Dim tR As Integer
If UseBNLS Then
Set BNLS = New Arbiter
tR = frmMain.txtRecv.Count
Debug.Print "txtRecv.Count: " & tR
Load frmMain.txtRecv(tR)
Debug.Print "txtRecv.Count: " & frmMain.txtRecv.Count
If BNLS.Initialize(frmMain.txtRecv(tR).hWnd, bKey, sBNLS) Then
BotEvent bKey, evBnlsConnecting
If Not BNLS.Connect("bnls.valhallalegends.com", 9367) Then
BotEvent bKey, evConError, "Could not connect to BNLS."
End If
Else
BotEvent bKey, evConError, "Could not initialize BNLS socket."
End If
End If
End Function[/code]

Judging from my source code... it's long and I'm baffled as to where in all that the fault lies, so I didn't post it at first. frmMain.txtRecv is the hidden "listener" textbox.
May 2, 2004, 11:13 PM
shadypalm88
If I don't open the connection to b.net, the BNLS connection is not affected. Help anyone?
May 3, 2004, 2:16 AM
shadypalm88
Oy vay. Stupid reason. Fixed.
May 3, 2004, 2:19 AM

Search