Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=MCTelnet GUI.ico
#AutoIt3Wrapper_outfile=MCTelnet GUI.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Interface graphique pour MCTelnet
#AutoIt3Wrapper_Res_Fileversion=0.0.0.1
#AutoIt3Wrapper_Res_Language=1036
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Constants.au3>
#include <GuiConstantsEx.au3>
#Include <Misc.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
If not FileExists(@ScriptDir & "\config.ini") Then
$file = FileOpen("config.ini", 1)
FileWrite($file, "[host]" & @CRLF & "ip=" & @CRLF & "port=" & @CRLF & "[user]" & @CRLF & "login=" & @CRLF & "password=")
FileClose($file)
Endif
Global $hostip = IniRead ("config.ini", "host", "ip", "")
Global $hostport = IniRead ("config.ini", "host", "port", "")
Global $login = IniRead ("config.ini", "user", "login", "")
Global $pass = IniRead ("config.ini", "user", "password", "")
Global $dll = DllOpen("user32.dll")
Global $Paused, $base
Global $test
Global $data
Global $envoi
HotKeySet("{PAUSE}", "TogglePause")
$form1 = GuiCreate("MCTelnet GUI - Remote Console Access using Telnet", 480, 350,-1,-1,$WS_OVERLAPPEDWINDOW)
GUISetState(@SW_SHOW)
GuiCtrlCreateLabel("Messages des joueurs:", 10, 10)
$messagejoueur = GUICtrlCreateEdit("",10,30,225,280,$ES_READONLY)
GuiCtrlCreateLabel("Messages du serveur:", 245, 10)
$messageconsole = GUICtrlCreateEdit("",245,30,225,280,$ES_READONLY )
$send = GuiCtrlCreateInput("",10,320,380,20)
$boutonsend = GuiCtrlCreateButton("Envoyer", 400, 320, 70, 20)
TCPStartUp()
$hostip = TCPNameToIP($hostip)
$socket = TCPConnect($hostip,$hostport)
_WaitRecvMsg("Username:")
TCPSend($socket, $Login & @CRLF)
_WaitRecvMsg("Password:")
TCPSend($socket, $pass & @CRLF)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Terminate()
Case $msg = $boutonsend
$envoi = GUICtrlRead($send)
If $envoi <> "" Then
TCPSend($socket, $envoi & @CRLF)
GUICtrlSetData($send, "")
EndIf
EndSelect
$test = TCPRecv($socket, 1024)
If $test <> "" Then
$base = GUICtrlRead($messageconsole)
GUICtrlSetData($messageconsole, $base & $test)
EndIf
If _IsPressed("0D", $dll) Then
$envoi = GUICtrlRead($send)
If $envoi <> "" Then
TCPSend($socket, $envoi & @CRLF)
GUICtrlSetData($send, "")
EndIf
EndIf
WEnd
; #FUNCTIONS# ;===============================================================================
; Permit to Pause the script
Func TogglePause()
$Paused = Not $Paused
While $Paused
Sleep(100)
ToolTip('Le script est en pause', 0, 0)
WEnd
ToolTip("")
EndFunc ;==>TogglePause
; Permit to quit the script with ESC
Func Terminate()
TCPCloseSocket($socket)
TCPShutdown()
Exit 0
EndFunc ;==>Terminate
Func _WaitRecvMsg($szMsg)
Local $Begin = TimerInit()
While 1
Local $SrvMes = TCPRecv($socket, 1024)
If StringInStr($SrvMes, $szMsg) Then Return $SrvMes
If TimerDiff($begin) > 5000 Then
SetError(1)
Return 0
EndIf
WEnd
EndFunc