Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/11/2017 in all areas

  1. An adaption of an adaption. A good while back, I created a program, KindEbook Wishlist, that I use most days and is still available here at the forum. It works well, keeping tabs on price changes for Kindle ebooks at Amazon ... at least for my modest wants. About a year or so later, I struck upon the idea of adapting that program for CDs, DVDs, Blu-rays etc from the JB Hifi store, where there was a limit of about 50 items on the in-store wishlist. JB Wishlist is kind of a niche program, really only suitable for those from AUS, at the AutoIt Forum, who would want such a thing ... so not many I imagine, so it has never been available here. However, if you meet that criteria etc, and are willing to register at the AutoIt4Life Clubrooms, then it is available in the Project Chat section there ... though not the more recent updates (you need to ask me about them). That too, works quite well for my modest needs, and even includes an additional Preview & Summary window, which KindEbook Wishlist doesn't have ... though both programs do have access to a Details window per item, that is like the Preview window ... just doesn't constantly display alongside the Main program window (see later for an example with IonGoG Wishlist). So, now we come to IonGoG Wishlist, which is an adaption of the JB Wishlist program, and used for keeping tabs on GOG Games ... prices, history of changes, bought list, etc. IonGoG Wishlist is an incomplete adaption, so still in beta ... though all the really important elements work well enough. I have been working on it in dribs and drabs, and I now think it has come to a reasonable enough stage to share it ... just be advised, that some of the features accessed via the right-click menu etc, may not work or give strange results. Any of the options that I have given an Accelerator key facility to, should be working fine ... and most of the others are too ... and I am not even sure at this point, of what remains to be adapted ... not much I imagine. The name by the way, in case you were wondering, is a phonetic mangling on the words - keep an Eye On your GOG Wishlist. Here is a screenshot, with the Preview window on left. The Preview window can be placed at right instead or even turned off. Download, includes source files. IonGoG Wishlist v0.0_b28.zip (see detail at Post#23) Enjoy! OLDER DOWNLOADS SUPPLEMENTARY I have another program that GOG users may be interested in, that can assist with getting game images that IonGoG Wishlist gets and doesn't get ... larger versions taken from modified thumbnail links in their GOG Library. Downloads Dropbox (see the GOG example in Post #7) ADDENDUM In reality, compared to most stores I have come across, the GOG store is great, well setup and laid out. and for most things, including their Wishlist, is more than adequate. So I rarely do a full list Price Query ... so much quicker and easier to just check the two pages of my in-store wishlist. When I first started work on IonGoG Wishlist, the in-store wishlist wasn't as good as it is now. All that said, I still find it handy to use IonGoG Wishlist, for a variety of things - Offline browsing, Cover images to use with my bought & downloaded game folders, price changes history (and patterns of GOG behavior for sales etc), a bought list (with price I paid and date etc), Game Notes & Warnings, etc. And while not as quick as just checking the pages of your in-store wishlist, you can just set the full, favorites or non-favorites Query going, while you go away and do something else, and then later come back and look at the highlighted changes that may have occurred.
    1 point
  2. j0kky

    Winsock UDF

    Hi guys, some time ago I tried to deal with client\server application using native winsock functions, but I encountered some difficult because their limitations, so I decided to write a new UDF based on winsock library. Some functions are simply wrappers of native function, but some other are completely renewed and there are a lot of improvements. Check it out! Each function has a detailed description and I attached 5 simple example script ; #INDEX# ======================================================================================================================= ; Title .........: Winsock ; AutoIt Version : 3.3.14.2 ; Language ......: English ; Description ...: Functions that assist with Winsock library management. ; Author(s) .....: j0kky ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $TCP_DATA_EOT = 2 ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _TCPStartup ; _TCPListen ; _TCPAccept ; _TCPRecv ; _TCPConnect ; _TCPSend ; _TCPNameToIP ; _TCPCloseSocket ; _TCPShutdown ; _GetIps ; _UDPStartup ; _UDPBind ; _UDPSendTo ; _UDPRecvFrom ; _UDPCloseSocket ; _UDPShutdown ; =============================================================================================================================== ; #WRAPPER# ===================================================================================================================== Func _TCPStartup() $iResult = TCPStartup() Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPStartup ; #WRAPPER# ===================================================================================================================== Func _TCPListen($iIPAddr, $iPort, $iMaxPendingConnection = 0) If Not $iMaxPendingConnection Then $iResult = TCPListen($iIPAddr, $iPort) Else $iResult = TCPListen($iIPAddr, $iPort, $iMaxPendingConnection) EndIf Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPListen ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPAccept ; Description ...: Permits an incoming connection attempt on a socket. ; Syntax.........: _TCPAccept($iMainsocket) ; Parameters ....: $iMainsocket - The main socket identifier (SocketID) as returned by _TCPListen function. ; Return values .: On success it returns an array: ; |[0] - The connected socket identifier. ; |[1] - The external address of the client ; |[2] - The external port which the client are communicating on ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter (not used in this function) ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: accept: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737526(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPAccept($iMainsocket) $iMainsocket = Number($iMainsocket) If $iMainsocket < 0 Then Return SetError(-4, 0, -1) ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $hSock = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) $aRet = DllCall($hWs2, "uint", "accept", "uint", $iMainsocket, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf ($aRet[0] = 4294967295) Or ($aRet[0] = -1) Then ;INVALID_SOCKET $bError = 1 $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf ($aRet[0] = 0) Or ($aRet[0] = 10035) Then ;WSAEWOULDBLOCK $nCode = -10 ;internal function value, it means no error EndIf Else $hSock = $aRet[0] $aRet = DllCall($hWs2, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, "S_addr")) If @error Then $bError = -1 ElseIf $aRet[0] = Null Then $bError = 1 Else $sIPAddr = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) $aRet = DllCall($hWs2, "ushort", "ntohs", "ushort", DllStructGetData($tSockAddr, "sin_port")) If @error Then $bError = -1 Else $nPort = $aRet[0] Local $aResult[3] = [$hSock, $sIPAddr, $nPort] EndIf EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure If $hSock Then TCPCloseSocket($hSock) ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = -1 If $hSock Then TCPCloseSocket($hSock) Else $nReturn = $aResult EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_TCPAccept ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPRecv ; Description ...: Receives data from a connected socket. ; Syntax.........: _TCPRecv($iMainsocket, $iMaxLen, $iFlag = 0) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPConnect. ; $iMaxLen - max # of characters to receive (usually 2048). ; $iFlag - values can be added together ; |$TCP_DATA_DEFAULT (0) - Text data. [Default] ; |$TCP_DATA_BINARY (1) - Binary data. ; |$TCP_DATA_EOT (2) - Returns data received and ; set @error to -6 when it reaches the End of Text ASCII character (Chr(3)) ; Return values .: On success it returns the binary/string sent by the connected socket. ; On failure it returns "" and sets the @error or @extended flag to non-zero: ; @error values: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; @extended values: ; |1 - connection closed ; |2 - End of Text reached ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: If Unicode strings need to be transmitted they must be encoded/decoded with StringToBinary()/BinaryToString(). ; $iFlag = 2 must be set in couple with _TCPSend ; You must check for both @error and @extended, @extended could be set with @error set to zero ; Links .........: recv: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPRecv($iMainsocket, $iMaxLen, $iFlag = 0) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] If $iFlag = Default Then $iFlag = 0 $iMainsocket = Number($iMainsocket) $iMaxLen = Number($iMaxLen) $iFlag = Number($iFlag) If $iMainsocket < 0 Or _ $iMaxLen < 1 Or _ Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(-4, 0, -1) ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $nExtended = 0 If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf Local $tBuf If $iFlag Then $tBuf = DllStructCreate("byte[" & $iMaxLen & "]") Else $tBuf = DllStructCreate("char[" & $iMaxLen & "]") EndIf $aRet = DllCall($hWs2, "int", "recv", "uint", $iMainsocket, "ptr", DllStructGetPtr($tBuf), "int", $iMaxLen, "int", 0) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf $aRet[0] = 0 Or $aRet[0] = 10035 Then ;WSAEWOULDBLOCK $nCode = -10 ;internal function value, it means no error EndIf ElseIf $aRet[0] = 0 Then $bError = 1 $nCode = -10 $nExtended = 1 ;connection closed Else Local $sResult = DllStructGetData($tBuf, 1) ;data If BitAND($iFlag, 2) = 2 Then ;EOT If StringRight($sResult, 1) = Chr(3) Then $sResult = StringTrimRight($sResult, 1) $nExtended = 2 ;End of Text reached EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = "" ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = "" Else $nReturn = $sResult EndIf DllClose($hWs2) Return SetError($nCode, $nExtended, $nReturn) EndFunc ;==>_TCPRecv ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPConnect ; Description ...: Create a socket connected to an existing server. ; Syntax.........: _TCPConnect($sIPAddr, $iDestPort, $sSourceAddr = "", $iSourcePort = 0, $iTimeOut = 0) ; Parameters ....: $sIPAddr - Destination IP. ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". ; $iDestPort - Destination port. ; |1 : 65534 - port on which the created socket will be connected. ; $sSourceAddr - Source IP ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". [Default = ""] ; $iSourcePort - Source port. ; |1 : 65534 - port on which the created socket will be bind (on the local PC). [Default = 0] ; $iTimeOut - The maximum time in milliseconds for _TCPConnect to wait for connection. ; |Any value > 0 [Default = 0 and it will be equal to Opt("TCPTimeout")]. ; Return values .: On success it returns the main socket identifier. ; |Any value > 0 ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |-5 - not connected ; |-6 - timed out ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: This function is used by a client to communicate with the server and it allows to choose a source IP, ; a source port and to set a timeout for the connection. ; Links .........: bind: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737550(v=vs.85).aspx ; connect: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737625(v=vs.85).aspx ; select: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPConnect($sIPAddr, $iDestPort, $sSourceAddr = "", $iSourcePort = 0, $iTimeOut = 0) If $sSourceAddr = Default Then $sSourceAddr = "" If $iSourcePort = Default Then $iSourcePort = 0 If $iTimeOut = Default Then $iTimeOut = 0 $sIPAddr = String($sIPAddr) $iDestPort = Number($iDestPort) $sSourceAddr = String($sSourceAddr) $iSourcePort = Number($iSourcePort) $iTimeOut = Number($iTimeOut) If Not ($iDestPort > 0 And $iDestPort < 65535) Or _ Not ($iSourcePort >= 0 And $iSourcePort < 65535) Or _ Not ($iTimeOut >= 0) Then Return SetError(-4, 0, -1) ; invalid parameter StringRegExp($sIPAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) If $sSourceAddr <> "" Then StringRegExp($sSourceAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) EndIf Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6); AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf If Not $bError Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sIPAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sIPAddr = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iDestPort) If @error Then $bError = -1 Else $iDestPort = $aRet[0] EndIf EndIf If (Not $bError) And ($sSourceAddr <> "") Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sSourceAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sSourceAddr = $aRet[0] EndIf EndIf If (Not $bError) And $iSourcePort Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iSourcePort) If @error Then $bError = -1 Else $iSourcePort = $aRet[0] EndIf EndIf If (Not $bError) And ($sSourceAddr Or $iSourcePort) Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET If $iSourcePort Then DllStructSetData($tSockAddr, "sin_port", $iSourcePort) Else DllStructSetData($tSockAddr, "sin_port", 0) EndIf If $sSourceAddr Then DllStructSetData($tSockAddr, "S_addr", $sSourceAddr) Else DllStructSetData($tSockAddr, "S_addr", 0x00000000) ;INADDR_ANY EndIf $aRet = DllCall($hWs2, "int", "bind", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf $tSockAddr = 0 EndIf If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $hSock, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET DllStructSetData($tSockAddr, "sin_port", $iDestPort) DllStructSetData($tSockAddr, "S_addr", $sIPAddr) $aRet = DllCall($hWs2, "int", "connect", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR -> functional with connect() on non-blocking sockets $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf ($aRet[0] <> 0) And ($aRet[0] <> 10035) Then ;WSAEWOULDBLOCK $bError = 1 EndIf EndIf $tSockAddr = 0 EndIf If Not $bError Then If $iTimeOut = 0 Then $iTimeOut = Opt("TCPTimeout") If $iTimeOut < 1 Then $iTimeOut = 100 Local $tagFd_set = "uint fd_count; uint fd_array[64]" Local $tFd_set_writefds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_writefds, "fd_count", 1) DllStructSetData($tFd_set_writefds, "fd_array", $hSock, 1) Local $tFd_set_exceptfds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_exceptfds, "fd_count", 1) DllStructSetData($tFd_set_exceptfds, "fd_array", $hSock, 1) Local $tTimeval = DllStructCreate("long tv_sec; long tv_usec") DllStructSetData($tTimeval, "tv_sec", Floor($iTimeOut / 1000)) DllStructSetData($tTimeval, "tv_usec", Round(Mod($iTimeOut, 1000) * 1000)) $aRet = DllCall($hWs2, "int", "select", _ "int", $hSock, "ptr", 0, "ptr", DllStructGetPtr($tFd_set_writefds), "ptr", DllStructGetPtr($tFd_set_exceptfds), "ptr", DllStructGetPtr($tTimeval)) If @error Then $bError = -1 ElseIf $aRet[0] = 0 Then ;time expired $bError = 1 $nCode = -6 ;timed out, similar to WSAETIMEDOUT ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 Else If Not (DllStructGetData($tFd_set_writefds, "fd_count") = 1) Then $bError = 1 If DllStructGetData($tFd_set_exceptfds, "fd_count") = 1 Then $tBuf = DllStructCreate("int") $aRet = DllCall("Ws2_32.dll", "int", "getsockopt", _ "uint", $hSock, "int", 0xffff, "int", 0x1007, "ptr", DllStructGetPtr($tBuf), "int*", DllStructGetSize($tBuf)) ;SO_ERROR If @error Then $bError = -1 ElseIf $aRet[0] = 0 Then $nCode = DllStructGetData($tBuf, 1) EndIf Else $nCode = -5 ;NOT_CONNECTED EndIf EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure If $hSock Then TCPCloseSocket($hSock) ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 If $hSock Then TCPCloseSocket($hSock) Else $nReturn = $hSock EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_TCPConnect ; #MODIFIED WRAPPER# ============================================================================================================ ; Name...........: _TCPSend ; Description ...: Wrapper of _TCPSend function, see the guide. ; Syntax.........: _TCPSend($iMainsocket, $iData, $iFlag = 0) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPConnect. ; $iData - Data sent. ; |Text or binary data ; $iFlag - values can be added together ; |$TCP_DATA_DEFAULT (0) - It doesn't add anything at the end of the string [Default] ; |$TCP_DATA_EOT (2) - It adds an End of Text ASCII character (Chr(3)) at the end of the string ; Return values .: see the guide. ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: If Unicode strings need to be transmitted they must be encoded/decoded with StringToBinary()/BinaryToString(). ; $iFlag = $TCP_DATA_EOT must be set in couple with _TCPRecv, so don't use it for external application ; Links .........: send: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740149(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPSend($iMainsocket, $iData, $iFlag = 0) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] If BitAND($iFlag, 2) = 2 Then $iData = String($iData) & Chr(3) $iResult = TCPSend($iMainsocket, $iData) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPSend ; #WRAPPER# ===================================================================================================================== Func _TCPNameToIP($sName) $iResult = TCPNameToIP($sName) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPNameToIP ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetIps ; Description ...: Get local and public IP address of a network/computer ; Syntax.........: _GetIps($iServerName = "") ; Parameters ....: $iServerName - The server name which can retrieve your public IP ; |For example: "www.something.com/somethingelse" [Default = ""] ; Return values .: On success it returns an array: ; |[0] - Local IP (on LAN) of the adapter used to connect to Internet. ; |[1] - Public IP. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter (not used) ; |-5 - servers are offline ; |-6 - IP retrieving failed ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: It works with Winsock library, so it must be initialized with _TCPStartup(). ; Local and public IPs are both retrieved through internet. ; Links .........: error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _GetIps($iServerName = "") If $iServerName = Default Then $iServerName = "" $iServerName = String($iServerName) $iServerName = StringRegExpReplace($iServerName, "^http.?://", "") If StringInStr($iServerName, "/") Then If StringRegExp($iServerName, "/(.*)", 1)[0] Then If StringRight($iServerName, 1) = "/" Then $iServerName = StringTrimRight($iServerName, 1) EndIf Else $iServerName &= "/" EndIf If Not StringRegExp($iServerName, ".+\..{2,}") Then $iServerName = "" ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $sLocalIP = "", $sPublicIP = "" Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6); AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf If Not $bError Then If $iServerName Then Local $aGetIPURL[][2] = [["www.myexternalip.com/raw"], ["checkip.dyndns.org/"], ["bot.whatismyipaddress.com/"], [$iServerName]], $nElements = 0 Else Local $aGetIPURL[][2] = [["www.myexternalip.com/raw"], ["checkip.dyndns.org/"], ["bot.whatismyipaddress.com/"]], $nElements = 0 EndIf For $i = 0 To (UBound($aGetIPURL) - 1) $sServerIp = TCPNameToIP(StringRegExp($aGetIPURL[$i][0], "(.*?)/", 1)[0]) If $sServerIp <> "" Then $aGetIPURL[$nElements][0] = $aGetIPURL[$i][0] $aGetIPURL[$nElements][1] = $sServerIp $nElements += 1 EndIf Next If $nElements Then ReDim $aGetIPURL[$nElements][2] Else $bError = 1 $nCode = -5 ;there is no valid server for checking IP EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", 80) If @error Then $bError = -1 Else $iDestPort = $aRet[0] EndIf EndIf If Not $bError Then For $i = 0 To (UBound($aGetIPURL) - 1) $sServerIp = $aGetIPURL[$i][1] If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $hSock, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sServerIp) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sServerIp = $aRet[0] EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET DllStructSetData($tSockAddr, "sin_port", $iDestPort) DllStructSetData($tSockAddr, "S_addr", $sServerIp) $aRet = DllCall($hWs2, "int", "connect", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR -> functional with connect() on non-blocking sockets $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf ($aRet[0] <> 0) And ($aRet[0] <> 10035) Then ;WSAEWOULDBLOCK $bError = 1 EndIf EndIf $tSockAddr = 0 EndIf If Not $bError Then Local $tagFd_set = "uint fd_count; uint fd_array[64]" Local $tFd_set_writefds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_writefds, "fd_count", 1) DllStructSetData($tFd_set_writefds, "fd_array", $hSock, 1) Local $tFd_set_exceptfds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_exceptfds, "fd_count", 1) DllStructSetData($tFd_set_exceptfds, "fd_array", $hSock, 1) Local $tTimeval = DllStructCreate("long tv_sec; long tv_usec") DllStructSetData($tTimeval, "tv_sec", Floor(500 / 1000)) DllStructSetData($tTimeval, "tv_usec", Round(Mod(500, 1000) * 1000)) $aRet = DllCall($hWs2, "int", "select", _ "int", $hSock, "ptr", 0, "ptr", DllStructGetPtr($tFd_set_writefds), "ptr", DllStructGetPtr($tFd_set_exceptfds), "ptr", DllStructGetPtr($tTimeval)) If @error Then $bError = -1 ElseIf ($aRet[0] = 0) Or ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then $bError = 1 Else If Not (DllStructGetData($tFd_set_writefds, "fd_count") = 1) Then $bError = 1 EndIf EndIf If Not $bError And Not $sLocalIP Then $tSockAddr = DllStructCreate($tagSockAddr) $aRet = DllCall($hWs2, "int", "getsockname", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 Else $aRet = DllCall($hWs2, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, "S_addr")) If @error Then $bError = -1 ElseIf $aRet[0] = Null Then $bError = 1 Else $sLocalIP = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) ;IP address EndIf EndIf $tSockAddr = 0 EndIf If Not $bError Then $sRequest = "GET /" & StringRegExp($aGetIPURL[$i][0], "/(.*)", 1)[0] & " HTTP/1.1" & @CRLF & _ "Host: " & StringRegExp($aGetIPURL[$i][0], "(.*?)/", 1)[0] & @CRLF & _ "Connection: close" & @CRLF & @CRLF TCPSend($hSock, $sRequest) Local $sRecv = "", $hTimer = TimerInit() While 1 $sRecv &= _TCPRecv($hSock, 2048) If @error Or @extended Then If @error Then $bError = 1 ExitLoop EndIf If TimerDiff($hTimer) > 2500 Then ExitLoop Sleep(10) WEnd EndIf If Not $bError Then $aPublicIP = StringRegExp($sRecv, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;STR_REGEXPARRAYGLOBALMATCH If Not @error Then $sPublicIP = $aPublicIP[0] ExitLoop Else $bError = 1 EndIf EndIf If $bError And $i = (UBound($aGetIPURL) - 1) Then $nCode = -6 ExitLoop Else $bError = 0 $nCode = 0 TCPCloseSocket($hSock) EndIf Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6); AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf Next EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 Else Local $nReturn[2] = [$sLocalIP, $sPublicIP] EndIf If $hSock Then TCPCloseSocket($hSock) DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_GetIps ; #MODIFIED WRAPPER# ============================================================================================================ ; Name...........: _TCPCloseSocket ; Description ...: Wrapper of TCPCloseSocket function, see the guide. ; Syntax.........: _TCPCloseSocket($iMainsocket) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPListen and _TCPConnect. ; Return values .: see the guide. ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: recv: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPCloseSocket($iMainsocket) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] $iResult = TCPCloseSocket($iMainsocket) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPCloseSocket ; #WRAPPER# ===================================================================================================================== Func _TCPShutdown() $iResult = TCPShutdown() Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPShutdown ; #WRAPPER# ===================================================================================================================== Func _UDPStartup() $iResult = UDPStartup() Return SetError(@error, 0, $iResult) EndFunc ;==>_UDPStartup ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPBind ; Description ...: Creates and bind a socket to a local IP and a local port. ; Syntax.........: _UDPBind($sSourceAddr = "", $iSourcePort = 0) ; Parameters ....: $sSourceAddr - Source IP ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". [Default = ""] ; $iSourcePort - Source port. ; |1 : 65534 - port on which the created socket will be bind (on the local PC). [Default = 0] ; Return values .: On success it returns the main socket identifier. ; |Any value > 0 ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: It could be used before both of _UDPSendTo (client app) and _UDPRecvFrom (server app) functions ; Links .........: bind: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737550(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPBind($sSourceAddr = "", $iSourcePort = 0) If $sSourceAddr = Default Then $sSourceAddr = "" If $iSourcePort = Default Then $iSourcePort = 0 $sSourceAddr = String($sSourceAddr) $iSourcePort = Number($iSourcePort) If Not ($iSourcePort >= 0 And $iSourcePort < 65535) Then Return SetError(-4, 0, -1) ; invalid parameter If $sSourceAddr <> "" Then StringRegExp($sSourceAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) EndIf Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 2, "int", 17); AF_INET, SOCK_DGRAM, IPPROTO_UDP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf If (Not $bError) And ($sSourceAddr <> "") Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sSourceAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sSourceAddr = $aRet[0] EndIf EndIf If (Not $bError) And $iSourcePort Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iSourcePort) If @error Then $bError = -1 Else $iSourcePort = $aRet[0] EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET If $iSourcePort Then DllStructSetData($tSockAddr, "sin_port", $iSourcePort) Else DllStructSetData($tSockAddr, "sin_port", 0) EndIf If $sSourceAddr Then DllStructSetData($tSockAddr, "S_addr", $sSourceAddr) Else DllStructSetData($tSockAddr, "S_addr", 0x00000000) ;INADDR_ANY EndIf $aRet = DllCall($hWs2, "int", "bind", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf $tSockAddr = 0 EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure If $hSock Then UDPCloseSocket($hSock) ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 If $hSock Then UDPCloseSocket($hSock) Else $nReturn = $hSock EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPBind ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPSendTo ; Description ...: Sends data to an address/port, it uses a socket created by _UDPBind or it creates a socket itself ; Syntax.........: _UDPSendTo($sIPAddr, $iDestPort, $iData, $iMainsocket = 0) ; Parameters ....: $sIPAddr - Destination IP. ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". ; $iDestPort - Destination port. ; |1 : 65534 - port which the created socket will connect on. ; $iData - Data sent. ; |Text or binary data ; $iMainsocket - Main socket identifier returned by _UDPBind. ; |Any value > 0 [Default = 0] ; Return values .: On success it returns an array: ; |[0] - The number of bytes sent. ; |[1] - The main socket identifier used. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: sendto: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740148(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPSendTo($sIPAddr, $iDestPort, $iData, $iMainsocket = 0) If $iMainsocket = Default Then $iMainsocket = 0 $iMainsocket = Number($iMainsocket) $sIPAddr = String($sIPAddr) $iDestPort = Number($iDestPort) If Not IsBinary($iData) Then $iData = String($iData) If Not ($iDestPort > 0 And $iDestPort < 65535) Or _ $iMainsocket < 0 Then Return SetError(-4, 0, -1) ; invalid parameter StringRegExp($sIPAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" If Not $iMainsocket Then Local $aRet = DllCall($hWs2, "uint", "socket", "int", 2, "int", 2, "int", 17); AF_INET, SOCK_DGRAM, IPPROTO_UDP If @error Then $bError = -1 ElseIf ($aRet[0] = 4294967295) Or ($aRet[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $iMainsocket = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sIPAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sIPAddr = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iDestPort) If @error Then $bError = -1 Else $iDestPort = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then Local $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET DllStructSetData($tSockAddr, "sin_port", $iDestPort) DllStructSetData($tSockAddr, "S_addr", $sIPAddr) Local $nLenght, $tBuf If IsBinary($iData) Then $nLenght = BinaryLen($iData) $tBuf = DllStructCreate("byte[" & $nLenght & "]") DllStructSetData($tBuf, 1, $iData) Else $nLenght = StringLen($iData) $tBuf = DllStructCreate("char[" & $nLenght & "]") DllStructSetData($tBuf, 1, $iData) EndIf $aRet = DllCall($hWs2, "int", "sendto", _ "uint", $iMainsocket, "ptr", DllStructGetPtr($tBuf), "int", $nLenght, "int", 0, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 Else Local $aReturn[2] = [$aRet[0], $iMainsocket] EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 Else $nReturn = $aReturn EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPSendTo ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPRecvFrom ; Description ...: Receives data from a bound socket on the local PC. ; Syntax.........: _UDPRecvFrom($iMainsocket, $iMaxLen, $iFlag = 0) ; Parameters ....: $iMainsocket - Main socket identifier. ; |Any value > 0 ; $iMaxLen - Max # of characters to receive (usually 2048). ; $iFlag ; |0 - Text data. [Default] ; |1 - Binary data. ; Return values .: On success it returns an array: ; |[0] - The data received. ; |[1] - The IP address of the sender. ; |[2] - The port used by the sender for connection. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: recvfrom: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPRecvFrom($iMainsocket, $iMaxLen, $iFlag = 0) If $iFlag = Default Then $iFlag = 0 $iMainsocket = Number($iMainsocket) $iMaxLen = Number($iMaxLen) $iFlag = Number($iFlag) If $iMainsocket < 0 Or _ $iMaxLen < 1 Or _ Not ($iFlag = 0 Or $iFlag = 1) Then Return SetError(-4, 0, -1) ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf Local $tSockAddr = DllStructCreate($tagSockAddr) Local $tBuf If $iFlag Then $tBuf = DllStructCreate("byte[" & $iMaxLen & "]") Else $tBuf = DllStructCreate("char[" & $iMaxLen & "]") EndIf $aRet = DllCall($hWs2, "int", "recvfrom", _ "uint", $iMainsocket, "ptr", DllStructGetPtr($tBuf), "int", $iMaxLen, "int", 0, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf $aRet[0] = 0 Or $aRet[0] = 10035 Then ;WSAEWOULDBLOCK $nCode = -10 ;internal function value, it means no error EndIf Else Local $aResult[3] = [DllStructGetData($tBuf, 1)] ;data $aRet = DllCall($hWs2, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, "S_addr")) If @error Then $bError = -1 ElseIf $aRet[0] = Null Then $bError = 1 Else $aResult[1] = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) ;IP address $aRet = DllCall($hWs2, "ushort", "ntohs", "ushort", DllStructGetData($tSockAddr, "sin_port")) If @error Then $bError = -1 Else $aResult[2] = $aRet[0] ;port EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = -1 Else $nReturn = $aResult EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPRecvFrom ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPCloseSocket ; Description ...: Close a UDP socket. ; Syntax.........: _UDPCloseSocket($iMainsocket) ; Parameters ....: $iMainsocket - Main socket identifier returned by _UDPBind or the array returned by _UDPSendTo. ; |Any value > 0 ; Return values .: On success it returns 1. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: closesocket: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737582(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPCloseSocket($iMainsocket) If IsArray($iMainsocket) Then If Not ((UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) = 2)) Then Return SetError(-1, 0, -4) $iMainsocket = $iMainsocket[1] Else If $iMainsocket < 1 Then Return SetError(-1, 0, -4) EndIf Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 $aRet = DllCall($hWs2, "int", "closesocket", "uint", $iMainsocket) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 Else $nReturn = 1 EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPCloseSocket ; #WRAPPER# ===================================================================================================================== Func _UDPShutdown() $iResult = UDPShutdown() Return SetError(@error, 0, $iResult) EndFunc ;==>_UDPShutdown Obviously there can be a lot of errors, so please report here any problem\suggestion! Updated to: 11/01/16 winsock.zip
    1 point
  3. TheSaint

    KindEbook Wishlist

    KindEbook Wishlist and the other programs are now being updated at a new topic - KindEbook Suite Formerly known as KindEbook Price Query. Please read IMPORTANT ADVICE here at Post #57. (9th May 2016) Reading some sections of the previous topic could be helpful. There is also a Disclaimer reference etc. OLDER DOWNLOADS Screenshots in second post. See Post #51 for information about the Bonus program (AZWPlug). See Post #96 for Instructions & Screenshots for Bonus program (Add Book & All Formats To Calibre). (11-12-2017) KindEbook Wishlist updated to v5.8 Added a 'Both' option to the Search category dropdown, though it only works for selection display, plus copy to clipboard with the new clipboard button. Star button relocated to left of selection display (input) field, with the new clipboard button taking its prior location at right. NOTE - This now provides a quick easy way to copy Author &/or Title text for the selected entry, to the clipboard. Added a 'Simple' option to the Search category dropdown, which justs finds the specified text in the chosen column (Title or Author), and selects that row. Search starts at the selected entry and will wrap around at need. The Clipboard button, can now be set in the program settings (or used with CTRL), to minimize the program window when clicked. Moved the right-click 'Save the Ebook list to file' option to a sub-menu entry, and added a 'Save to List for Excel' option there to, which is mostly just for my specific personal use, but others might find it useful (includes SHIFT+X accelerator key usage). NOTES - This new feature assists me, when I want to add new entries to my Booklist.xls file (in batch mode). It just helps to quickly create the basic entries, which I then flesh out later at my leisure, and helps avoid a lot of repetitive clicking. Used in conjunction with my related Excel macros. Add Book & All Formats To Calibre updated to v1.7 (NOTE - This has only been tested with calibre v2.x.x, not the newer v3.x.x.) A bugfix for duplicate title issue - I had not realized that a failure due to a duplicate was based solely on a title match. All duplicates are now added unless an ID match occurs. VIEW button can now view a saved specified format. (30-11-2017) KindEbook Wishlist updated to v5.5 Improved the Copy/Move input box dimensions, to more easily accommodate long titles. Mode for troubleshooting (me only) has been improved, to avoid me losing my sanity again (I'd forgotten it even existed). Replaced the (last version update) new CTRL option at program start, with a 5 second dialog prompt instead. (11-11-2017) AZWPlug updated to v2.8 Database list can now be set not to display when starting that window, plus a LOAD button added to load that list when desired. CTRL used with the open Kindle Content folder button, will now close the program. If CTRL used when selecting the MODE on the Results window, it will just save the setting without making changes to existing results. Option added for slicker loading of list, plus alternate list lines are now pale pink. Two find options added for the Author and Title, with FIND jumping to each entry found and SHOW just displaying all found. NOTE - With LOAD deselected, the list will only show the added ebook title (if any). ---------------------------------------------------------------------------------------------------- KindEbook Wishlist - Most controls get disabled now during a Query, plus the same occurs during an 'Exchange Rate Query'. Plus if 'Please Wait' splash is disabled for Query, then a splash is no longer shown during an 'Exchange Rate Query', with that text shown instead in both the 'Please Wait' and 'Timer' labels, which are temporarily unhidden for that purpose. The Timer label can also be reshown if hidden by the new feature, by clicking the FIND label. Mouse cursor now changes during Query and Ebook list loading etc, to indicate when busy working. Extended the 'Please Wait' label to loading & sorting the Ebooks list, which also applies to any other process that re-populates or changes number of list entries (ebook removal, changing user, relocating bought, etc). Those are all dependent on the "Use a flashing 'Please Wait' ..." setting being set. NOTE - This feature was added to this and the previous version, so that having a 'Please Wait' splash displayed on top of all windows, for a lengthy period perhaps, could be avoided, if desired. Previous Versions (newer) Previous Versions (older) The KindEbook Wishlist, is basically a compliment to your regular store wishlist, but has a history element and allows you to check current and previous prices etc in a better, quicker and more organized fashion. Essentially it assists and hopefully improves with decision making, when it comes to determining whether to make a purchase yet or not. You could compare it to manually and painfully creating something like an Excel spreadsheet for the same purpose, without the time, complexity and pain involved. You can sort by Title, Author, Current Price, Lowest Price, Add Order, Favorites, etc. You can view details - Book Description, Price Changes, etc. You can open the ebook URL in your web browser, where you can elect to make the purchase. The program supports multiple users, shared titles, shared comments and private comments, etc. After purchase, an ebook can be relocated to a bought list (per user). Price can be queried on an individual title basis or ALL titles (starting at first or selected or only favorites or not favorites). Dates are recorded for most processes, with various reporting options. I call it a wishlist on steroids.
    1 point
  4. Jefrey

    RC4 (PHP/JS compatible)

    I found an interesting RC4 implementation on Github that was available in PHP and Javascript in a compatible way. So I ported it to AutoIt keeping it compatible with the PHP/Javascript versions. The problem with RC4 is that most of the implementations are only based on the original spec, and not compatible to it. Therefore if you are developing something that must communicate between different platforms (for example, encrypt at the AutoIt side and decrypt at the PHP side), you're usually out of luck. But what about Crypt.au3? It uses Windows implementation, which is also not standard and therefore isn't compatible with the PHP/JS versions as well (with "compatible" I mean: "giving the same string and encryption key, you'll get the same output"). What about huge data/files? I'd suggest not to use this version for huge amounts of data since it's entirely AU3 based and may be slow for that. So why would I use this version? Because you are developing something that uses PHP, Javascript and/or AutoIt and they must speak the same language (I mean: they must produce the same outputs and be able to decrypt strings encrypted on a different programming language). But it's giving me unreadable outputs. Yeah RC4 does it. It's up to you to use Base64 or hex encoding if you really need it. Then why don't I use base64 directly? Base64 isn't meant to protect data. It's meant to make binary data easy and safe to store by converting it to readable characters. That's why it doesn't include password protection. Here's the code: Func rc4($sKey, $sStr) Local $s[256], $j = 0, $x, $res, $y, $i Local $uBound For $i = 0 To 255 $s[$i] = $i Next For $i = 0 To 255 $j = Mod(($j + $s[$i] + Asc(StringMid($sKey, Mod($i, StringLen($sKey))+1, 1))), 256) $x = $s[$i] $s[$i] = $s[$j] $s[$j] = $x Next $i = 0 $j = 0 For $y = 0 To StringLen($sStr)-1 $i = Mod(($i + 1), 256) $j = Mod(($j + $s[$i]), 256) $x = $s[$i] $s[$i] = $s[$j] $s[$j] = $x $res &= Chr(BitXOR(Asc(StringMid($sStr, $y+1, 1)), ($s[Mod(($s[$i] + $s[$j]), 256)]))) Next Return $res EndFunc Note that since rc4 is dual-way, doing rc4("same key here", "encrypted string") will get back your decrypted string (there's no need to a separated decrypt function).
    1 point
  5. who you kidding. Pull the other one ... no not that one, the other one, the one that plays Jingle Bells, not Jingle Balls.
    1 point
  6. Good work, a great program, I might use it but I am not really into games, GoG is awesome though, got many freebies overtime .
    1 point
  7. He used visual studio and started a new windforms project And I think that would be the easiest thing for you to do. If you follow that tutorial with the free version of visual studio 2017 it should turn out just like his then you can call your program instead of the Calculator application
    1 point
  8. I recommend Microsoft visual code and or the free community version of visual studio 2017. C-sharp is just like python take that example you saw in instead of Calc make it your program that gets called and is a child of your form. That example you show is exactly how to do it and he’s using C-sharp
    1 point
  9. YES that would be awesome, is this possible to say run this .exe program inside of limited 1024x768? to lets say develop in the VB or any other language, where you limit the size of program that is started? That would be great solution!
    1 point
  10. Hi mLipok Since PS and C# is mentioned you have the tools available to make it work one way or the or, correct ? https://www.autoitscript.com/forum/topic/188158-net-common-language-runtime-clr-framework/ rgds ptrex
    1 point
  11. Uncommon way : One Ring (To Get Them All) Most usual way : make the first step to get the wanted parts of text into an array then loop through this array #include <Array.au3> $Path ="test.html" $parts = StringRegExp(FileRead($Path), '(?s)<div class="app-details">(.*?)</div>' , 3) Local $aResults[0] For $i = 0 to UBound($parts)-1 $lines = StringRegExp($parts[$i], '\S\N+', 3) _ArrayAdd($aResults, $lines) Next _ArrayDisplay($aResults)
    1 point
  12. TheSaint

    KindEbook Wishlist

    KindEbook Wishlist updated to v5.4, see first post. Bugfix for '/gp/' and/or '/product/' in ebook URL. Holding down CTRL when the program starts will prevent the last user list from loading (if you are quick enough). Minor improvements to COPY and MOVE options. Accelerator Keys for COPY and MOVE now changed to (Shift-C) and (Shift-M) from (Ctrl-C) and (Ctrl-M) respectively, to avoid possibility of hotkey conflicts. Accelerator Keys added for Shared Comments (Shift-S) and Private Comments (Shift-P). ------------------------------------------------------------------------------------------------------- AZWPlug also updated, to v2.8, see first post. Database list can now be set not to display when starting that window, plus a LOAD button added to load that list when desired. CTRL used with the open Kindle Content folder button, will now close the program. If CTRL used when selecting the MODE on the Results window, it will just save the setting without making changes to existing results. Option added for slicker loading of list, plus alternate list lines are now pale pink. Two find options added for the Author and Title, with FIND jumping to each entry found and SHOW just displaying all found. NOTE - With LOAD deselected, the list will only show the added ebook title (if any). Latest screenshot. ------------------------------------------------------------------------------------------------------- Add Book & All Formats To Calibre v1.4 added to the suite, see first post. Another bonus complimentary program added to the mix, that has a dropbox for adding an ebook and all associated ebook formats to calibre, using the OPF metadata file. NOTE - This has only been tested with calibre v2.x.x, not the newer v3.x.x. Here's some screenshots of it, followed by instructions/explanation. A small floating dropbox that stays on top of other windows, plus the FIND window (to use after) for added titles via cycling through recorded author names, using NEXT and BACK. The FIND window utilizes the CTRL+F hotkey in calibre. So essentially. 1. You run the program (dropbox). 2. If calibre is running you get prompted to close it. You can leave it running, but to see results afterward, you will need to restart calibre or toggle (switch) databases. The program can close calibre for you or you can do it manually. 3. You setup a few things when you first run the dropbox, but they might be auto-detected for you (calibre path, calibre library path, etc). 4. You drag and drop an OPF file onto the drop field, and the related ebook gets checked for, and then added if it doesn't already exist. All existing ebook formats for that title that share the same parent folder as the OPF file also get added. 5. Add any other ebook titles the same way, one by one. 6. When finished (all have been added), and with the 'Run calibre on exit' option enabled, you close the dropbox. 7. Calibre will be executed or restored if still running. If still running, you now need to toggle databases before continuing. 8. The dropbox FIND window will be displayed, and show the author name of the last ebook title you added via drag & drop. 9. Clicking the FIND button will send the author name to the calibre find field, and all books by that author should be isolated in the find results window. 10. Check (etc) the result of what you added. 11. If more than one ebook title was added (by a different author) click the NEXT button on the dropbox FIND window to recall the next author name. You are basically cycling through the author names in the reverse order of how they were added to calibre. 12. Click FIND again. 13. Repeat for all those authors you added by drag & drop. Very quick simple and efficient. Enjoy!
    1 point
  13. @augumentum: excellent work! It worked like you indicated it would. And by changing one statement, I was able to have a colored backdrop for the PNGs, which was something I was hoping for. _WinAPI_SetLayeredWindowAttributes( $hGUI, 0xABCDEe, 255 ) Granted, I haven't fully explored things in the context of a real application—like having text and JPGs on the layout—but it's a great start. Thanks for posting.
    1 point
  14. I think i am lucky enough to answer my question. I found a remedy. When you creating controls, write them orderly. Which will give you a tab order.
    1 point
  15. Just want to update from a user's side: This dll & udf is still working in 2017 using Win 10 current releases and it still seems to me the best option for complex printing tasks handled by AutoIt. NONETHELESS there are a few caveats: 1) Since Martin never had time to implement a "set page size" function, this REALLY calls for some additional work for anyone not working with A4 paper sizes! I use this DLL extensively to work with label printers and I can only tell you all the drivers I have used (TMC, Zebra, Novexx, Avery) all had problems with the paper size. It drives you nuts unless you know what to do: Don't use the function to programmatically chose the printer. It will often chose a completely wrong paper size, even if you set everything in the printer defaults (of printer and driver and everywhere). So the quite strange way to overcome this is to use the alternative function and call up the printer selection window. I then wrote a small compiled AutoIt script that is called BEFORE the printer selection function and waits for the printer dialog to open. It then fills out all the necessary values for label sizes, printer head temperature, etc. and closes the windows again. So the user only sees a few windows (printer properties) quickly popping up and closing again. I am afraid (and quite sure!) this is the only way to get Martin's dll to work with label paper sizes in modern Windows versions. For me it now works very reliably. 2) I have found that if you rename your printer, the function to programmatically set the printer sometimes doesn't work. It is a very weird behavior that I can't completely explain, but it drives you nuts if you think you have chosen the correct printer, but actually you have not. A work around here is also the way I have described in 1). 3) YOU NEED TO HAVE A STANDARD PRINTER SET. I came across a Windows Installation where one user has no standard printer set (Win10) and the DLL crashes when selecting a printer (both ways). Just define a standard printer and the crash is gone. Good luck! Jandings
    1 point
×
×
  • Create New...