Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' WinProc message handler for receiving client data
- ' pumps it into a queue via ClientMessageToServer at FD_READ
- Public Function ClientProc(ByVal localHwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Dim reConnect As Long
- Select Case uMsg
- Case WINSOCK_MESSAGE
- Select Case lParam
- Case FD_ACCEPT
- If socketClient = INVALID_SOCKET Then
- Dim tempAddr As sockaddr
- socketClient = accept(wParam, tempAddr, Len(tempAddr))
- closesocket socketListen
- PumpInternalMessage "Client connected:" & socketClient
- StandAloneMode = BotScript.KeepConnection
- End If
- Exit Function
- Case FD_WRITE
- PumpInternalMessage "Client Write Detected:"
- ' this seemed to be the best point to cause connection to the server
- ' winsock services generate a write event to the socket once the client connection is solid
- ' so if the client is now talking to the proxy, proxy must now start talking to the server
- If socketServer = INVALID_SOCKET Then
- socketServer = ConnectSock(IIf(CTRL.cfgUseProxyFile = True, CTRL.cfgUseProxyAddress, "lightbringer.furcadia.com"), _
- IIf(CTRL.cfgUseProxyPort = 0, CTRL.cfgPreferredUserPort, CTRL.cfgUseProxyPort), _
- vbNullString, hServerSocket, False)
- If socketServer = INVALID_SOCKET Then
- PumpInternalMessage "Failed to connect to the game server."
- ' ConnectSocket will generate the WSAError message, duplication not needed here
- If ClientPID <> 0 Then
- PumpMessageToClient "(Whoops! Could not connect to the game server, everything go boom now." & vbCrLf & "Dismissing attempt in 5 seconds."
- axAutoAttempts = IIf(axAutoAttempts >= 10, 24, axAutoAttempts)
- End If
- addAutomation axStopServices, 2
- addAutomation axRestoreSettings, 6
- If BotScript.AutoConnect Then
- reConnect = axAutoTime * axAutoAttempts + axAutoTime
- addAutomation axAutoConnect, reConnect, "Reconnection in " & reConnect & " seconds"
- proxy.btnConnect.Caption = "Abort " & axAutoTime * axAutoAttempts
- If axAutoAttempts < 10 Then axAutoAttempts = axAutoAttempts + 1
- End If
- Exit Function
- Else
- PumpInternalMessage "Connected to the game server."
- proxy.MainStatus.Panels(pStatus) = "Connected to server, Port: " & CTRL.cfgPreferredUserPort
- MessagePump.processTrigger "", tConnectOpen, True
- End If
- End If
- Exit Function
- Case FD_READ
- If socketClient = INVALID_SOCKET Then Exit Function
- Dim sTemp As String, lRet As Long, szBuf As String
- Do
- szBuf = String(1024, 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
- ClientMessageToServer Replace$(sTemp, Chr$(0), "")
- Exit Function
- Case Else 'FD_CLOSE
- ' possible a strange message from winsock will also cause this
- ' unknown what that strange message would be
- PumpInternalMessage "Client DisConnected"
- ClientPID = 0
- Exit Function
- End Select
- 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 socketListen <> INVALID_SOCKET Then
- closesocket socketListen
- socketListen = INVALID_SOCKET
- End If
- If socketClient <> INVALID_SOCKET Then
- closesocket socketClient
- socketClient = INVALID_SOCKET
- End If
- End Select
- ClientProc = DefWindowProc(localHwnd, uMsg, wParam, lParam)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment