SHARE
TWEET

backend_srv.au3

untoha Oct 26th, 2019 (edited) 303 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GUIConstantsEx.au3>
  2. #include <MsgBoxConstants.au3>
  3.  
  4. #cs
  5. взять ремонтный пистолет перед тем как водителю садиться в машину!
  6. #ce
  7.  
  8. local $repair = false
  9.  
  10. Example()
  11.  
  12. Func Example()
  13.     TCPStartup() ; Start the TCP service.
  14.  
  15.     ; Register OnAutoItExit to be called when the script is closed.
  16.     OnAutoItExitRegister("OnAutoItExit")
  17.  
  18.     ; Assign Local variables the loopback IP Address and the Port.
  19.     Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer.
  20.     Local $iPort = 65432 ; Port used for the connection.
  21.  
  22.     #Region GUI
  23.     Local $sTitle = "TCP Start"
  24.     Local $hGUI = GUICreate($sTitle, 250, 70)
  25.  
  26.     Local $idBtnServer = GUICtrlCreateButton("1. Server", 65, 10, 130, 22)
  27.  
  28.     Local $idBtnClient = GUICtrlCreateButton("2. Client", 65, 40, 130, 22)
  29.  
  30.     GUISetState(@SW_SHOW, $hGUI)
  31.  
  32.     While 1
  33.         Switch GUIGetMsg()
  34.             Case $GUI_EVENT_CLOSE
  35.                 ExitLoop
  36.             Case $idBtnServer
  37.                 WinSetTitle($sTitle, "", "TCP Server started")
  38.                 GUICtrlSetState($idBtnClient, $GUI_HIDE)
  39.                 GUICtrlSetState($idBtnServer, $GUI_DISABLE)
  40.                 If Not MyTCP_Server("192.168.0.6", $iPort) Then ExitLoop
  41.             Case $idBtnClient
  42.                 WinSetTitle($sTitle, "", "TCP Client started")
  43.                 GUICtrlSetState($idBtnServer, $GUI_HIDE)
  44.                 GUICtrlSetState($idBtnClient, $GUI_DISABLE)
  45.                 If Not MyTCP_Client("192.168.0.6", $iPort) Then ExitLoop
  46.         EndSwitch
  47.  
  48.         Sleep(1)
  49.     WEnd
  50.  
  51.     #EndRegion GUI
  52. EndFunc   ;==>Example
  53.  
  54. Func MyTCP_Client($sIPAddress, $iPort)
  55.     ; Assign a Local variable the socket and connect to a listening socket with the IP Address and Port specified.
  56.     Local $iSocket = TCPConnect($sIPAddress, $iPort)
  57.     Local $iError = 0
  58.  
  59.     ; If an error occurred display the error code and return False.
  60.     If @error Then
  61.         ; The server is probably offline/port is not opened on the server.
  62.         $iError = @error
  63.         MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError)
  64.         Return False
  65.     EndIf
  66.  
  67.     ; Send the string "tata" to the server.
  68.     TCPSend($iSocket, "00")
  69.  
  70.     ; If an error occurred display the error code and return False.
  71.     If @error Then
  72.         $iError = @error
  73.         MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not send the data, Error code: " & $iError)
  74.         Return False
  75.     EndIf
  76.  
  77.     ; Close the socket.
  78.     TCPCloseSocket($iSocket)
  79. EndFunc   ;==>MyTCP_Client
  80.  
  81. Func MyTCP_Server($sIPAddress, $iPort)
  82.    ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions.
  83.    Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)
  84.    Local $iError = 0
  85.    local $current = "000";
  86.    local $send[20]
  87.    $send[1] = "NUMPAD8"
  88.    $send[2] = "NUMPAD5"
  89.    $send[3] = "NUMPAD4"
  90.    $send[4] = "NUMPAD6"
  91.    $send[11] = "NUMPADADD"
  92.    $send[12] = "RSHIFT"
  93.    $send[13] = "RSHIFT"
  94.    $send[14] = "G"
  95.    $send[15] = "NUMPADDOT"
  96.  
  97.     If @error Then
  98.         ; Someone is probably already listening on this IP Address and Port (script already running?).
  99.         $iError = @error
  100.         MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError)
  101.         Return False
  102.     EndIf
  103.  
  104.    ; Assign a Local variable to be used by the Client socket.
  105.    Local $iSocket = 0;  TCPAccept($iListenSocket)
  106.    WinActivate("Planetside2 v1.0.1064.408819 x64");
  107.    Sleep(1000);
  108.  
  109.    Do ; Wait for someone to connect (Unlimited).
  110.         ; Accept incomming connexions if present (Socket to close when finished; one socket per client).
  111.         $iSocket = TCPAccept($iListenSocket)
  112.  
  113.         ; If an error occurred display the error code and return False.
  114.         If @error Then
  115.             $iError = @error
  116.             MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not accept the incoming connection, Error code: " & $iError)
  117.             Return False
  118.         EndIf
  119.  
  120.       If GUIGetMsg() = $GUI_EVENT_CLOSE Then Return False
  121.       if $iSocket <> -1 then
  122.          Local $sReceived = TCPRecv($iSocket, 4)
  123.          ;MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "Received: " & $sReceived)
  124.  
  125.          local $code = $sReceived;
  126.          if StringLeft($code,1) <> "0" Then
  127.             if StringLeft($code,1) <> StringLeft($current,1) then
  128.                Send("{"&$send[int(StringLeft($code,1))]&" down}")
  129.                Send("{"&$send[getalter(int(StringLeft($code,1)))]&" up}")
  130.                $current = StringReplace($current,1,StringLeft($code,1))
  131.             EndIf
  132.          Else
  133.             if StringLeft($code,1) <> StringLeft($current,1) then
  134.                Send("{"&$send[int(StringLeft($current,1))]&" up}")
  135.                $current = StringReplace($current,1,"0")
  136.             EndIf
  137.          EndIf
  138.  
  139.          if StringMid($code,2,1) <> "0" Then
  140.             if StringMid ($code,2,1) <> StringMid ($current,2,1) then
  141.                Send("{"&$send[int(StringMid($code,2,1))]&" down}")
  142.                Send("{"&$send[getalter(int(StringMid($code,2,1)))]&" up}")
  143.                $current = StringReplace($current,2,StringMid($code,2,1))
  144.             EndIf
  145.          Else
  146.             if StringMid($code,2,1) <> StringMid($current,2,1) then
  147.                Send("{"&$send[int(StringMid($current,2,1))]&" up}")
  148.                $current = StringReplace($current,2,"0")
  149.             EndIf
  150.          EndIf
  151.  
  152.          if StringMid($code,3,1) <> "0" Then                        ;; 3rd byte
  153.             If StringMid($code,3,1) = "6" Then      ;; set mines by driverThen
  154.                set_mines();
  155.             ElseIf StringMid($code,3,1) = "7" Then
  156.                set_squadonly();
  157.             ElseIf StringMid($code,3,1) = "8" Then
  158.                saygoaway();
  159.             Elseif StringMid($code,3,1) <> "3" then
  160.                if StringMid ($code,3,1) <> StringMid ($current,3,1) then
  161.                   Send("{"&$send[10+int(StringMid($code,3,1))]&" down}")
  162.                   $current = StringReplace($current,3,StringMid($code,3,1))
  163.                EndIf
  164.             Else                ;repair
  165.                if not $repair Then
  166.                   repair()
  167.                Else
  168.                   $repair = false;
  169.                   Send("{F1}");
  170.                   MouseUp("left")
  171.                   Send("{] up}");
  172.                EndIf
  173.             EndIf
  174.          Else
  175.             if StringMid($code,3,1) <> StringMid($current,3,1) then
  176.                Send("{"&$send[10+int(StringMid($current,3,1))]&" up}")
  177.                $current = StringReplace($current,3,"0")
  178.             EndIf
  179.          EndIf
  180.  
  181.       EndIf
  182.  
  183.     ;Until $iSocket <> -1 ;if different from -1 a client is connected.
  184.    Until 1 <> 1
  185.     ; Close the Listening socket to allow afterward binds.
  186.     TCPCloseSocket($iListenSocket)
  187.  
  188.     ; Assign a Local variable the data received.
  189.     Local $sReceived = TCPRecv($iSocket, 4) ;we're waiting for the string "tata" OR "toto" (example script TCPRecv): 4 bytes length.
  190.  
  191.     ; Notes: If you don't know how much length will be the data,
  192.     ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error.
  193.  
  194.     ; Display the string received.
  195.     MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "Received: " & $sReceived)
  196.  
  197.     ; Close the socket.
  198.     TCPCloseSocket($iSocket)
  199. EndFunc   ;==>MyTCP_Server
  200.  
  201. Func OnAutoItExit()
  202.     TCPShutdown() ; Close the TCP service.
  203.  EndFunc   ;==>OnAutoItExit
  204.  
  205.  Func getalter($num)
  206.    Switch $num
  207.    Case "1"
  208.       return "2"
  209.    Case "2"
  210.       return "1"
  211.    Case "3"
  212.       return "4"
  213.    Case "4"
  214.       return "3"
  215.    EndSwitch
  216. EndFunc
  217.  
  218. Func repair()
  219.    $repair = true
  220.    Send("{F3}");
  221.    MouseDown("left")
  222.    Send("{] down}");
  223. EndFunc
  224.  
  225. Func set_mines()
  226.    Send("{F3}");
  227.    Sleep(500)
  228.    Send("{4}");
  229.    Sleep(1000)
  230.    MouseClick("left")
  231.    Sleep(1250)
  232.    MouseClick("left")
  233.    Sleep(1250)
  234.    MouseClick("left")
  235.    Sleep(1250)
  236.    Send("{3}");     ;; get repair tool
  237.    Send("{F1}");
  238. EndFunc
  239.  
  240. Func set_squadonly()
  241.    Send("\");
  242.    Sleep(1000);
  243.    MouseClick("left",610,359);
  244.    Sleep(500);
  245.    MouseClick("left",695,467);
  246. EndFunc
  247.  
  248. Func saygoaway()
  249.   Send("{ENTER}");
  250.   Sleep(200)
  251.   Send("{BACKSPACE}")
  252.   Sleep(200)
  253.   ClipPut("/say test")
  254.   Send("^v")
  255.   Sleep(200)
  256.   Send("{ENTER}");
  257.   Send("{"&$send[15]&"}");
  258. EndFunc
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top