Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' WinProc message handler for receiving server data
- ' pumps it into a queue via ServerMessageToClient at READ
- Public Function ServerProc(ByVal localHwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Dim wsaError As Long
- Select Case uMsg
- Case WINSOCK_MESSAGE
- Select Case lParam
- Case FD_ACCEPT
- Case FD_CONNECT
- ' note, you should never see this message :-p
- PumpInternalMessage "Winsock Connected to the game server."
- Case FD_WRITE
- Case FD_READ
- Dim sTemp As String, lRet As Long, szBuf As String
- Do
- szBuf = String(4096, 0)
- lRet = recv(wParam, ByVal szBuf, Len(szBuf), 0)
- If lRet > 0 Then sTemp = sTemp + Left$(szBuf, lRet)
- Loop Until lRet <= 0
- ' original where it should be send action, to process the dataflow, we redirect it to the message pump
- ServerMessageToClient Replace$(sTemp, Chr$(0), "")
- Case Else
- wsaError = WSAGetLastError()
- If wsaError > 0 Then PumpInternalMessage GetWSAErrorString(wsaError)
- ' unlike the the client to server connection below, this on has a FD_CLOSE case
- ' I have no idea why the original coding was done this way, seemed best not to tamper with it
- ' it works after all, ...
- PumpInternalMessage "Lost connection with the game server."
- stopServices
- If BotScript.AutoConnect Then
- addAutomation axAutoConnect, axAutoTime * axAutoAttempts, "Reconnection in " & axAutoTime * axAutoAttempts & " seconds"
- proxy.btnConnect.Caption = "Abort " & axAutoTime * axAutoAttempts
- If axAutoAttempts < 10 Then axAutoAttempts = axAutoAttempts + 1
- End If
- End Select
- Exit Function
- Case WM_CLOSE
- ' only WinMessage processed here, might be redundant seeing as the Form_Unload also closes the sockets
- ' unlike the WINSOCK_MESSAGE case above, this one falls through to permit DefWindowProc to clean up
- ' fall through is is required by windows
- If socketServer <> INVALID_SOCKET Then
- closesocket socketServer
- socketServer = INVALID_SOCKET
- End If
- End Select
- ServerProc = DefWindowProc(localHwnd, uMsg, wParam, lParam)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment