Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RequireAdmin
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <ScrollBarConstants.au3>
- #include <SendMessage.au3>
- #include <GUIRichEdit.au3>
- #include <GUIEdit.au3>
- #include <Array.au3>
- #include <File.au3>
- #include <Misc.au3>
- #include <Timers.au3>
- TCPStartup()
- OnAutoItExitRegister("_Exit")
- AutoItSetOption("GUIOnEventMode", 1)
- AutoItSetOption("TrayIconHide", 0)
- Break(0)
- Dim $dll = DllOpen("user32.dll"), $Mainsocket = -1, $Bool = True
- $IP = InputBox("IP", "Bitte IP eingeben:", "127.0.0.1")
- Do
- Sleep(100)
- Until _IsPressed("0D", $dll) = False
- $Mainsocket = TCPConnect($IP, 12000)
- If @error Then
- MsgBox(16, "Fehler", "Konnte nicht zum Server verbinden!")
- _Exit()
- EndIf
- $Form1 = GUICreate("Chatclient", 615, 394, 192, 124)
- GUISetBkColor(0x000000)
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
- $Edit1 = _GUICtrlRichEdit_Create($Form1, "", 8, 8, 593, 313, BitOR($ES_MULTILINE, $WS_VSCROLL,$WS_CHILD, $WS_VISIBLE, $WS_TABSTOP))
- _GUICtrlRichEdit_SetReadOnly($Edit1)
- _GUICtrlRichEdit_SetFont($Edit1, 10, "Comic Sans MS")
- _GUICtrlRichEdit_SetBkColor($Edit1, 0x000000)
- $Label1 = GUICtrlCreateLabel("Name:", 8, 360, 35, 17)
- GUICtrlSetColor($Label1, 0xFFFFFF)
- $Input1 = GUICtrlCreateInput("", 48, 360, 209, 21)
- GUICtrlSetFont(-1, 9, 400, 0, "Comic Sans MS")
- GUICtrlSetBkColor($Input1, 0x000000)
- GUICtrlSetColor($Input1, 0xFFFFFF)
- $Input2 = GUICtrlCreateInput("", 48, 328, 553, 21)
- GUICtrlSetFont(-1, 9, 400, 0, "Comic Sans MS")
- GUICtrlSetBkColor($Input2, 0x000000)
- GUICtrlSetColor($Input2, 0xFFFFFF)
- $Label2 = GUICtrlCreateLabel("Text:", 16, 336, 28, 17)
- GUICtrlSetColor($Label2, 0xFFFFFF)
- $Button1 = GUICtrlCreateButton("Senden", 264, 360, 339, 25)
- Dim $Arr[1][2]
- $Arr[0][0] = "{ENTER}"
- $Arr[0][1] = $Button1
- GUISetAccelerators($Arr, $Form1)
- GUICtrlSetOnEvent($Button1, "_ButtonFunc")
- GUISetState(@SW_SHOW)
- While True
- $Msg = TCPRecv($Mainsocket, 1024)
- If $Msg <> "" Then
- If StringInStr($Msg, "IPLIST") = True Then
- $Str = StringSplit($Msg, "|")
- For $i = 1 To $Str[0] Step 1
- RTBInsertColoredText($Edit1, $Str[$i] & @CRLF, 0xFF0000)
- Next
- ElseIf StringInStr($Msg, "NAMELIST") = True Then
- $Str = StringSplit($Msg, "|")
- For $i = 1 To $Str[0] Step 1
- RTBInsertColoredText($Edit1, $Str[$i] & @CRLF, 0xFF0000)
- Next
- ElseIf $Msg = "NONAME" Then
- RTBInsertColoredText($Edit1, "Name existiert nicht!" & @CRLF, 0x0000FF)
- ElseIf StringInStr($Msg, "PING", 1) = True Then
- TCPSend($Mainsocket, "PONG")
- ElseIf StringInStr($Msg, "Server: Ping beendet!") = True Then
- RTBInsertColoredText($Edit1, $Msg, 0x00FF00)
- $Bool = True
- ElseIf StringInStr($Msg, "Server: Ping wird durchgeführt! Bitte nichts schreiben!") = True Then
- RTBInsertColoredText($Edit1, $Msg, 0x00FF00)
- $Bool = False
- Else
- If StringMid($Msg, 1, 7) = "Server:" Then
- RTBInsertColoredText($Edit1, $Msg, 0x00FF00)
- Else
- RTBInsertColoredText($Edit1, $Msg, 0xFFFFFF)
- EndIf
- If WinGetState($Form1) = 23 Then
- TrayTip("Nachricht", StringTrimRight($Msg, 2), 3000)
- EndIf
- If $Msg = "Server Shutting down..." Then
- _SendMessage($Edit1 ,$WM_VSCROLL, $SB_BOTTOM, 0)
- GUICtrlSetState($Input2, $GUI_FOCUS)
- _GUICtrlEdit_SetSel($Input2, -1, -1)
- Sleep(5000)
- TCPCloseSocket($Mainsocket)
- TCPShutdown()
- Exit
- EndIf
- EndIf
- _SendMessage($Edit1 ,$WM_VSCROLL, $SB_BOTTOM, 0)
- GUICtrlSetState($Input2, $GUI_FOCUS)
- _GUICtrlEdit_SetSel($Input2, -1, -1)
- EndIf
- WEnd
- Func _ButtonFunc()
- If $Bool = True Then
- If WinGetState($Form1) = 15 Then
- If GUICtrlRead($Input2) = "" Or GUICtrlRead($Input1) = "" Then
- TrayTip("Chathelper", "Text und Name dürfen nicht leer sein!", 1000)
- Else
- If GUICtrlRead($Input2) = "hilfe" Then
- _GUICtrlRichEdit_SetSel($Edit1, -1, -1)
- _GUICtrlRichEdit_InsertText($Edit1, "/IPLIST, um IPs anzeigen zu lassen!" & @CRLF)
- _GUICtrlRichEdit_InsertText($Edit1, "/NAMELIST, um die Namen anzeigen zu lassen!" & @CRLF)
- _GUICtrlRichEdit_InsertText($Edit1, "/WHISPER NAME NACHRICHT, um private Nachricht zu senden!" & @CRLF)
- _GUICtrlRichEdit_InsertText($Edit1, "Enter ist der Hotkey zum senden!" & @CRLF)
- _GUICtrlRichEdit_SetSel($Edit1, -1, -1)
- _SendMessage($Edit1 ,$WM_VSCROLL, $SB_BOTTOM, 0)
- GUICtrlSetState($Input2, $GUI_FOCUS)
- GUICtrlSetData($Input2, "")
- Else
- GUICtrlSetData($Input1, StringReplace(GUICtrlRead($Input1), " ", ""))
- TCPSend($Mainsocket, GUICtrlRead($Input1) & "(" & @HOUR & ":" & @MIN & ":" & @SEC & "): " & GUICtrlRead($Input2) & @CRLF)
- GUICtrlSetData($Input2, "")
- EndIf
- EndIf
- Else
- WinFlash(GUICtrlRead($Form1), 0, 5, 1000)
- EndIf
- EndIf
- EndFunc
- Func RTBInsertColoredText($hwnd, $Text, $0xBGR, $Font = "Comic Sans MS", $Size = 10)
- _GUICtrlRichEdit_SetSel($hwnd, -1, -1)
- $RichEditLength = _GUICtrlRichEdit_GetTextLength($hwnd, True, True)
- $RichEditLines = _GUICtrlRichEdit_GetLineCount($hwnd)
- _GUICtrlRichEdit_SetFont($hwnd, $Size, $Font)
- _GUICtrlRichEdit_InsertText($hwnd, $Text)
- _GUICtrlRichEdit_SetSel($hwnd, $RichEditLength - $RichEditLines + 1, -1)
- _GUICtrlRichEdit_SetCharColor($hwnd, $0xBGR)
- _GUICtrlRichEdit_SetSel($hwnd, -1, -1)
- EndFunc
- Func _Exit()
- If $Mainsocket <> -1 Then
- TCPSend($Mainsocket, "USERQUIT|" & GUICtrlRead($Input1))
- TCPCloseSocket($Mainsocket)
- EndIf
- TCPShutdown()
- DllClose($dll)
- Exit
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment