Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GUIConstantsEx.au3>
- #include <MsgBoxConstants.au3>
- #cs
- взять ремонтный пистолет перед тем как водителю садиться в машину!
- #ce
- local $repair = false
- Example()
- Func Example()
- TCPStartup() ; Start the TCP service.
- ; Register OnAutoItExit to be called when the script is closed.
- OnAutoItExitRegister("OnAutoItExit")
- ; Assign Local variables the loopback IP Address and the Port.
- Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer.
- Local $iPort = 65432 ; Port used for the connection.
- #Region GUI
- Local $sTitle = "TCP Start"
- Local $hGUI = GUICreate($sTitle, 250, 70)
- Local $idBtnServer = GUICtrlCreateButton("1. Server", 65, 10, 130, 22)
- Local $idBtnClient = GUICtrlCreateButton("2. Client", 65, 40, 130, 22)
- GUISetState(@SW_SHOW, $hGUI)
- While 1
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE
- ExitLoop
- Case $idBtnServer
- WinSetTitle($sTitle, "", "TCP Server started")
- GUICtrlSetState($idBtnClient, $GUI_HIDE)
- GUICtrlSetState($idBtnServer, $GUI_DISABLE)
- If Not MyTCP_Server("192.168.0.6", $iPort) Then ExitLoop
- Case $idBtnClient
- WinSetTitle($sTitle, "", "TCP Client started")
- GUICtrlSetState($idBtnServer, $GUI_HIDE)
- GUICtrlSetState($idBtnClient, $GUI_DISABLE)
- If Not MyTCP_Client("192.168.0.6", $iPort) Then ExitLoop
- EndSwitch
- Sleep(1)
- WEnd
- #EndRegion GUI
- EndFunc ;==>Example
- Func MyTCP_Client($sIPAddress, $iPort)
- ; Assign a Local variable the socket and connect to a listening socket with the IP Address and Port specified.
- Local $iSocket = TCPConnect($sIPAddress, $iPort)
- Local $iError = 0
- ; If an error occurred display the error code and return False.
- If @error Then
- ; The server is probably offline/port is not opened on the server.
- $iError = @error
- MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError)
- Return False
- EndIf
- ; Send the string "tata" to the server.
- TCPSend($iSocket, "00")
- ; If an error occurred display the error code and return False.
- If @error Then
- $iError = @error
- MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not send the data, Error code: " & $iError)
- Return False
- EndIf
- ; Close the socket.
- TCPCloseSocket($iSocket)
- EndFunc ;==>MyTCP_Client
- Func MyTCP_Server($sIPAddress, $iPort)
- ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions.
- Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)
- Local $iError = 0
- local $current = "000";
- local $send[20]
- $send[1] = "NUMPAD8"
- $send[2] = "NUMPAD5"
- $send[3] = "NUMPAD4"
- $send[4] = "NUMPAD6"
- $send[11] = "NUMPADADD"
- $send[12] = "RSHIFT"
- $send[13] = "RSHIFT"
- $send[14] = "G"
- $send[15] = "NUMPADDOT"
- If @error Then
- ; Someone is probably already listening on this IP Address and Port (script already running?).
- $iError = @error
- MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError)
- Return False
- EndIf
- ; Assign a Local variable to be used by the Client socket.
- Local $iSocket = 0; TCPAccept($iListenSocket)
- WinActivate("Planetside2 v1.0.1064.408819 x64");
- Sleep(1000);
- Do ; Wait for someone to connect (Unlimited).
- ; Accept incomming connexions if present (Socket to close when finished; one socket per client).
- $iSocket = TCPAccept($iListenSocket)
- ; If an error occurred display the error code and return False.
- If @error Then
- $iError = @error
- MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not accept the incoming connection, Error code: " & $iError)
- Return False
- EndIf
- If GUIGetMsg() = $GUI_EVENT_CLOSE Then Return False
- if $iSocket <> -1 then
- Local $sReceived = TCPRecv($iSocket, 4)
- ;MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "Received: " & $sReceived)
- local $code = $sReceived;
- if StringLeft($code,1) <> "0" Then
- if StringLeft($code,1) <> StringLeft($current,1) then
- Send("{"&$send[int(StringLeft($code,1))]&" down}")
- Send("{"&$send[getalter(int(StringLeft($code,1)))]&" up}")
- $current = StringReplace($current,1,StringLeft($code,1))
- EndIf
- Else
- if StringLeft($code,1) <> StringLeft($current,1) then
- Send("{"&$send[int(StringLeft($current,1))]&" up}")
- $current = StringReplace($current,1,"0")
- EndIf
- EndIf
- if StringMid($code,2,1) <> "0" Then
- if StringMid ($code,2,1) <> StringMid ($current,2,1) then
- Send("{"&$send[int(StringMid($code,2,1))]&" down}")
- Send("{"&$send[getalter(int(StringMid($code,2,1)))]&" up}")
- $current = StringReplace($current,2,StringMid($code,2,1))
- EndIf
- Else
- if StringMid($code,2,1) <> StringMid($current,2,1) then
- Send("{"&$send[int(StringMid($current,2,1))]&" up}")
- $current = StringReplace($current,2,"0")
- EndIf
- EndIf
- if StringMid($code,3,1) <> "0" Then ;; 3rd byte
- If StringMid($code,3,1) = "6" Then ;; set mines by driverThen
- set_mines();
- ElseIf StringMid($code,3,1) = "7" Then
- set_squadonly();
- ElseIf StringMid($code,3,1) = "8" Then
- saygoaway();
- Elseif StringMid($code,3,1) <> "3" then
- if StringMid ($code,3,1) <> StringMid ($current,3,1) then
- Send("{"&$send[10+int(StringMid($code,3,1))]&" down}")
- $current = StringReplace($current,3,StringMid($code,3,1))
- EndIf
- Else ;repair
- if not $repair Then
- repair()
- Else
- $repair = false;
- Send("{F1}");
- MouseUp("left")
- Send("{] up}");
- EndIf
- EndIf34
- Else
- if StringMid($code,3,1) <> StringMid($current,3,1) then
- Send("{"&$send[10+int(StringMid($current,3,1))]&" up}")
- $current = StringReplace($current,3,"0")
- EndIf
- EndIf
- EndIf
- ;Until $iSocket <> -1 ;if different from -1 a client is connected.
- Until 1 <> 1
- ; Close the Listening socket to allow afterward binds.
- TCPCloseSocket($iListenSocket)
- ; Assign a Local variable the data received.
- Local $sReceived = TCPRecv($iSocket, 4) ;we're waiting for the string "tata" OR "toto" (example script TCPRecv): 4 bytes length.
- ; Notes: If you don't know how much length will be the data,
- ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error.
- ; Display the string received.
- MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "Received: " & $sReceived)
- ; Close the socket.
- TCPCloseSocket($iSocket)
- EndFunc ;==>MyTCP_Server
- Func OnAutoItExit()
- TCPShutdown() ; Close the TCP service.
- EndFunc ;==>OnAutoItExit
- Func getalter($num)
- Switch $num
- Case "1"
- return "2"
- Case "2"
- return "1"
- Case "3"
- return "4"
- Case "4"
- return "3"
- EndSwitch
- EndFunc
- Func repair()
- $repair = true
- Send("{F3}");
- MouseDown("left")
- Send("{] down}");
- EndFunc
- Func set_mines()
- Send("{F3}");
- Sleep(500)
- Send("{4}");
- Sleep(1000)
- MouseClick("left")
- Sleep(1250)
- MouseClick("left")
- Sleep(1250)
- MouseClick("left")
- Sleep(1250)
- Send("{3}"); ;; get repair tool
- Send("{F1}");
- EndFunc
- Func set_squadonly()
- Send("\");
- Sleep(1000);
- MouseClick("left",610,359);
- Sleep(500);
- MouseClick("left",695,467);
- EndFunc
- Func saygoaway()
- Send("{ENTER}");
- Sleep(200)
- Send("{BACKSPACE}")
- Sleep(200)
- ClipPut("/say test")
- Send("^v")
- Sleep(200)
- Send("{ENTER}");
- Send("{"&$send[15]&"}");
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement