Sign in to follow this  
Followers 0
feeltheroyal

Need Help WIth chat Client / Server .au3

2 posts in this topic

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiEdit.au3>
#Include <GuiListView.au3>
#Include <GuiMenu.au3>
#include <TCP.au3>
#include <WindowsConstants.au3>

;Tester()
;Func Tester()
Local $msg
$tester= GUICreate("Vindictus Hack Community By.mikehan", 360, 110, 200, 95)
GUICtrlCreateLabel("Username :", 20, 25)
GUICtrlCreateLabel("Password :", 20, 50)
$pw= GUICtrlCreateInput("", 95, 46, 190, 0, 0x0020)
$usr= GUICtrlCreateInput("", 95, 21, 190, 0)
$login= GUICtrlCreateButton("Click To Login", 95, 71, 0, 0)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $login
            $clientdisconnect = 0
            Dim $clients[10]
            Dim $clientname[10]
            $kick = GUICtrlCreateButton("Kick", 10, 420, 115)
            $clientsconnected = 1
            $clients[0] = GUICtrlRead($usr)
            $clientname[0] = GUICtrlRead($usr) & " - Host"
            Global $old_url = ''
            If Not FileExists("") Then
                IniWrite("http://www.mpgh.net/forum/267-vindictus-hacks/","URL","URL","http://www.mpgh.net/forum/267-vindictus-hacks/")
            EndIf
            $urlHome = IniRead("http://www.mpgh.net/forum/267-vindictus-hacks/","URL","URL","http://www.mpgh.net/forum/267-vindictus-hacks/")
            _IEErrorHandlerRegister ()
            $oIE = _IECreateEmbedded ()
            GUICreate("Welcome To MPGH Vindictus Hack Community", 1024, 786, _
                    (@DesktopWidth - 900) / 2, (@DesktopHeight - 900) / 2, _
                    $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
            $GUIActiveX = GUICtrlCreateObj($oIE, 57, 35, 942, 400)
            $GUI_Address_Bar = GUICtrlCreateInput($urlHome, 157, 10, 600, 20)
            GUICtrlSetData($GUI_Address_Bar,$urlHome)
            $GUI_Button_Back = GUICtrlCreateButton("<-", 55, 10, 50, 20)
            $GUI_Button_Forward = GUICtrlCreateButton("->", 105, 10, 50, 20)
            $GUI_Button_Refresh = GUICtrlCreateButton("@", 3, 10, 50, 20)
            $GUI_Button_HD = GUICtrlCreateButton("", 760, 10, 80, 20) ;// 1
            $GUI_Button_E = GUICtrlCreateButton("", 840, 10, 80, 20)  ;// 2
            $GUI_Button_TK = GUICtrlCreateButton("", 920, 10, 80, 20)  ;// 3
            GUISetState() 
            _IENavigate ($oIE, $urlHome)
            $o_form = _IEFormGetCollection ($oIE, 0) 
            $o_login = _IEFormElementGetCollection ($o_form, 0) 
            $o_password = _IEFormElementGetCollection ($o_form, 2) 
            $username = GUICtrlRead($usr)
            $password = GUICtrlRead($pw)
            _IEFormElementSetValue ($o_login, $username)
            _IEFormElementSetValue ($o_password, $password)
            _IEFormSubmit ($o_form)
            _IELoadWait ($oIE)
            $clist = GUICtrlCreateListView("Username", 800, 460, 200, 260)
            $chatbox = GUICtrlCreateEdit("", 280, 462, 520, 260, BitOR($ES_READONLY, $ES_AUTOVSCROLL, $WS_VSCROLL), $WS_EX_CLIENTEDGE)
            $chatinput = GUICtrlCreateEdit("", 280, 720, 520, 20, BitOR($ES_MULTILINE, $WS_VSCROLL), $WS_EX_CLIENTEDGE)
            $send = GUICtrlCreateButton("Send", 800, 720, 200, 20, $BS_DEFPUSHBUTTON )
    
            GUICtrlCreateListViewItem($clients[0], $clist)

            $filemenu = GUICtrlCreateMenu("File")
            $exit = GUICtrlCreateMenuItem("Exit", $filemenu)
            $optionmenu = GUICtrlCreateMenu("Options")
            $timestamp = GUICtrlCreateMenuItem("Timestamp", $optionmenu, 0 , 1)
            GUISetState()

            $hServer = _TCP_Server_Create(12345, @IPAddress1) ;Forward the port 12345 so u can succesfully host the chat server.
            _TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient")
            _TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect") 
            _TCP_RegisterEvent($hServer, $TCP_RECEIVE, "Received")


            $msg = GUIGetMsg()
            $time = TimerInit()
            While $msg <> -3 or $msg <> $exit
                $msg = GUIGetMsg()
                    Select
                        Case $msg = $send
                        If GUICtrlRead($chatinput) <> "" Then
                            _TCP_Server_Broadcast($usr & ": " & GUICtrlRead($chatinput))
                            If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
                                _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] " & GUICtrlRead($usr) & ": " & GUICtrlRead($chatinput))
                            Else
                                ;_GUICtrlEdit_AppendText($chatbox, @CRLF & GUICtrlRead($usr) & ": " & GUICtrlRead($chatinput))
                                _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] " & GUICtrlRead($usr) & ": " & GUICtrlRead($chatinput))
                            EndIf
                            GUICtrlSetData($chatinput, "")
                            ControlFocus("Server","",$chatinput)
                        EndIf
                    Case $msg = $kick
            ;$selected = _GUICtrlListView_GetSelectedIndices($clist, True)
            ;$kickname = _GUICtrlListView_GetItemText($clist, $selected)
            ;$kickip = _GUICtrlListView_GetItemText($clist, $selected, 1)
            ;MsgBox(0, "", $kickname & @CRLF & $kickip)
                    Case $msg = -3 or $msg = $exit
                        Exit
                EndSelect
                If TimerDiff($time) >= 5000 Then
                    $clientlist = "##list" & $clientsconnected & _ArrayToString($clientname, "|", 0, $clientsconnected)
                    $time = TimerInit()
                    _TCP_Server_Broadcast($clientlist)
                EndIf
            WEnd

            Func Received($hServer, $sReceived, $iError)
                If StringLeft($sReceived, 10) = "##username" Then
                    If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
                        _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] Client Connected!")
                    Else
                        _GUICtrlEdit_AppendText($chatbox, @CRLF & "Client Connected!")
                    EndIf

                    $clientnamestripped = StringMid($sReceived, 11)
                    $clients[$clientsconnected] = GUICtrlCreateListViewItem($clientnamestripped & "|" & _TCP_Server_ClientIP($hServer), $clist)
                    $clientname[$clientsconnected] = $clientnamestripped
                    $clientsconnected = $clientsconnected + 1
                    _GUICtrlEdit_AppendText($chatbox, @CRLF & $clientsconnected)
                    ReDim $clients[$clientsconnected + 1]
                    ReDim $clientname[$clientsconnected + 1]
                ElseIf StringLeft($sReceived, 12) = "##disconnect" Then
                    If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
                        _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] Client Disconnected!")
                    Else
                        _GUICtrlEdit_AppendText($chatbox, @CRLF & "Client Disconnected!")
                    EndIf
                    For $i = 0 To ($clientsconnected - 1) Step 1
                        If StringMid($sReceived, 13) = $clientname[$i] Then
                            GUICtrlDelete($clients[$i])
                            $clientsconnected = $clientsconnected - 1
                            _ArrayDelete($clientname, $i)
                            _GUICtrlEdit_AppendText($chatbox, @CRLF & $clientsconnected)
                            ReDim $clients[$clientsconnected + 1]
                            ReDim $clientname[$clientsconnected + 1]
                            ExitLoop
                        EndIf
                    Next
                Else
                    If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
                        _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] " & $sReceived)
                    Else
                        _GUICtrlEdit_AppendText($chatbox, @CRLF & $sReceived)
                    EndIf
                    _TCP_Server_Broadcast($sReceived)
                EndIf
            EndFunc

            Func OnAutoItExit()
                _TCP_Server_Broadcast("##serversd")
                _TCP_Server_Stop()
            EndFunc
            
            While 1
                _inputChk()
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        Exit
                    Case $msg = $GUI_Button_Back
                        _IEAction ($oIE, "back")
                    Case $msg = $GUI_Button_Forward
                        _IEAction ($oIE, "forward")
                    Case $msg = $GUI_Button_Refresh
                        _IEAction ($oIE, "refresh")
                    Case $msg = $GUI_Button_HD
                        _IENavigate ($oIE, "")
                    Case $msg = $GUI_Button_E
                        _IENavigate ($oIE, "")
                    Case $msg = $GUI_Button_TK
                        _IENavigate ($oIE, "")
                    Case $msg = $GUI_Address_Bar
                        $urlValue = GUICtrlRead($GUI_Address_Bar)
                        _IENavigate($oIE,$urlValue)
                        $urlGet = _IEPropertyGet($oIE,"locationurl")
                        GUICtrlSetData($GUI_Address_Bar,$urlGet)
            ;       Case $msg = $GUI_Button_Stop
            ;          _IEAction ($oIE, "stop")
                EndSelect
            WEnd
    EndSelect       
WEnd
;EndFunc
Func _inputChk()
    $current_url = _IEPropertyGet ($oIE, "locationurl")
    If $old_url <> $current_url Then
            $old_url = $current_url
        GUICtrlSetData($GUI_Address_Bar, $current_url)
    EndIf
EndFunc

Server on top

Client on bottom

#Region 
#AutoIt3Wrapper_outfile=Client.exe
#EndRegion 
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiEdit.au3>
#Include <GuiListView.au3>
#Include <GuiMenu.au3>
#include <TCP.au3>
#include <WindowsConstants.au3>

;Tester()
;Func Tester()
Local $msg
$tester= GUICreate("Vindictus Hack Community By.mikehan", 360, 110, 200, 95)
GUICtrlCreateLabel("Username :", 20, 25)
GUICtrlCreateLabel("Password :", 20, 50)
$pw= GUICtrlCreateInput("", 95, 46, 190, 0, 0x0020)
$usr= GUICtrlCreateInput("mikehan", 95, 21, 190, 0)
$login= GUICtrlCreateButton("Click To Login", 95, 71, 0, 0)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $login
            Global $old_url = ''
            If Not FileExists("http://www.mpgh.net/forum/267-vindictus-hacks/") Then
                IniWrite("http://www.mpgh.net/forum/267-vindictus-hacks/","URL","URL","http://www.mpgh.net/forum/267-vindictus-hacks/")
            EndIf
            $urlHome = IniRead("http://www.mpgh.net/forum/267-vindictus-hacks/","URL","URL","http://www.mpgh.net/forum/267-vindictus-hacks/")
            _IEErrorHandlerRegister ()
            $oIE = _IECreateEmbedded ()
            GUICreate("Welcome To MPGH Vindictus Hack Community", 1024, 786, _
                    (@DesktopWidth - 900) / 2, (@DesktopHeight - 900) / 2, _
                    $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
            $GUIActiveX = GUICtrlCreateObj($oIE, 57, 35, 942, 400)
            $GUI_Address_Bar = GUICtrlCreateInput($urlHome, 157, 10, 600, 20)
            GUICtrlSetData($GUI_Address_Bar,$urlHome)
            $GUI_Button_Back = GUICtrlCreateButton("<-", 55, 10, 50, 20)
            $GUI_Button_Forward = GUICtrlCreateButton("->", 105, 10, 50, 20)
            $GUI_Button_Refresh = GUICtrlCreateButton("@", 3, 10, 50, 20)
            $GUI_Button_HD = GUICtrlCreateButton("", 760, 10, 80, 20) ;// 1
            $GUI_Button_E = GUICtrlCreateButton("", 840, 10, 80, 20)  ;// 2
            $GUI_Button_TK = GUICtrlCreateButton("", 920, 10, 80, 20)  ;// 3
            GUISetState() 
            _IENavigate ($oIE, $urlHome)
            $o_form = _IEFormGetCollection ($oIE, 0) 
            $o_login = _IEFormElementGetCollection ($o_form, 0) 
            $o_password = _IEFormElementGetCollection ($o_form, 2) 
            $username = GUICtrlRead($usr)
            $password = GUICtrlRead($pw)
            _IEFormElementSetValue ($o_login, $username)
            _IEFormElementSetValue ($o_password, $password)
            _IEFormSubmit ($o_form)
            _IELoadWait ($oIE)
            While 1
                _inputChk()
                Chat()
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        Exit
                    Case $msg = $GUI_Button_Back
                        _IEAction ($oIE, "back")
                    Case $msg = $GUI_Button_Forward
                        _IEAction ($oIE, "forward")
                    Case $msg = $GUI_Button_Refresh
                        _IEAction ($oIE, "refresh")
                    Case $msg = $GUI_Button_HD
                        _IENavigate ($oIE, "")
                    Case $msg = $GUI_Button_E
                        _IENavigate ($oIE, "")
                    Case $msg = $GUI_Button_TK
                        _IENavigate ($oIE, "")
                    Case $msg = $GUI_Address_Bar
                        $urlValue = GUICtrlRead($GUI_Address_Bar)
                        _IENavigate($oIE,$urlValue)
                        $urlGet = _IEPropertyGet($oIE,"locationurl")
                        GUICtrlSetData($GUI_Address_Bar,$urlGet)
            ;       Case $msg = $GUI_Button_Stop
            ;          _IEAction ($oIE, "stop")
                EndSelect
            WEnd
    EndSelect       
WEnd
;EndFunc
Func _inputChk()
    $current_url = _IEPropertyGet ($oIE, "locationurl")
    If $old_url <> $current_url Then
            $old_url = $current_url
        GUICtrlSetData($GUI_Address_Bar, $current_url)
    EndIf
EndFunc

Func Chat()
    $name = GUICtrlRead($usr)
    Dim $clientlist[1]
    $clist = GUICtrlCreateListView("Username", 800, 460, 200, 260)
    $chatbox = GUICtrlCreateEdit("", 280, 462, 520, 260, BitOR($ES_READONLY, $ES_AUTOVSCROLL, $WS_VSCROLL), $WS_EX_CLIENTEDGE)
    $chatinput = GUICtrlCreateEdit("", 280, 720, 520, 20, BitOR($ES_MULTILINE, $WS_VSCROLL), $WS_EX_CLIENTEDGE)
    $send = GUICtrlCreateButton("Send", 800, 720, 200, 20, $BS_DEFPUSHBUTTON )
    ;GUICtrlCreateListViewItem($clients[0], $clist)
    
    $filemenu = GUICtrlCreateMenu("File")
    $exit = GUICtrlCreateMenuItem("Exit", $filemenu)
    $optionmenu = GUICtrlCreateMenu("Options")
    $timestamp = GUICtrlCreateMenuItem("Timestamp", $optionmenu, 0 , 1)
    GUISetState()
    $hClient = _TCP_Client_Create("173.70.134.132", 12345); <- put your IP here
    _TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received")
    _TCP_RegisterEvent($hClient, $TCP_CONNECT, "Connected")
    _TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected")
            

    $msg = GUIGetMsg()
    While $msg <> -3 Or $msg <> $exit
        $msg = GUIGetMsg()
        Select
            Case $msg = $send
                If GUICtrlRead($chatinput) <> "" Then
                    _TCP_Send($hClient, $name & ": " & GUICtrlRead($chatinput))
                    GUICtrlSetData($chatinput, "")
                    ControlFocus("Server","",$chatinput)
                EndIf
            Case $msg = -3 Or $msg = $exit
                Exit
        EndSelect
    WEnd
EndFunc
Func Received($hClient, $sReceived, $iError)
    If $sReceived == "##serversd" Then
        If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
            _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] Lost connection to server or disconnected!")
        Else
            _GUICtrlEdit_AppendText($chatbox, @CRLF & "Lost connection to server or disconnected!")
        EndIf
    ElseIf StringLeft($sReceived, 6) = "##list" Then
        _GUICtrlListView_DeleteAllItems($clist)
        
        ReDim $clientlist[StringMid($sReceived, 7, 1)]
        $clientlist = StringSplit(StringMid($sReceived, 8), "|")
        For $i = 1 To ($clientlist[0] - 1)
            GUICtrlCreateListViewItem($clientlist[$i], $clist)
        Next
    Else
        If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
            _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] " & $sReceived)
        Else
            ;_GUICtrlEdit_AppendText($chatbox, @CRLF & $sReceived)
            _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] " & $sReceived)
        EndIf
    EndIf
EndFunc
Func Connected($hClient, $iError)
    If not $iError Then
        Sleep(1000)
        _TCP_Send($hClient, "##username" & $name)
        If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
            _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] Connected to server!")
        Else
            _GUICtrlEdit_AppendText($chatbox, "Connected to server!")
        EndIf
    Else; ,else...
        MsgBox(0, "Error", "Could not connect to server!")
    EndIf
EndFunc



Func Disconnect($hClient, $iError) 
    Sleep(1000)
    _TCP_Send($hClient, "##disconnect" & $name)
    If BitAnd(GUICtrlRead($timestamp),$GUI_CHECKED) = $GUI_CHECKED Then
        _GUICtrlEdit_AppendText($chatbox, @CRLF & "[" &@HOUR & ":" & @MIN & ":" & @SEC & "] Lost connection to server or disconnected!")
    Else
        _GUICtrlEdit_AppendText($chatbox, "Lost connection to server or disconnected!")
    EndIf
EndFunc

Func OnAutoItExit()
    Sleep(1)
    _TCP_Send($hClient, "##disconnect" & $name)
    _TCP_Client_Stop($hClient)
EndFunc

Clinet On the Top

Server On The Bottom

Type Log in Name and Password as anything or just press enter to go in

im making a chat server with the IE browser included

when i put on the server and turn on client .

it shows me

line 165

_TCP_Send($hClient, "##username" & $name)

_TCP_Send($hClient, "##username" & ^ ERROR

Error : Variable used without being declared.

somebody can help me with this??

Share this post


Link to post
Share on other sites



The error tells you exactly what happened, the variable $name is never declared (initialized/created) before attempting to use it. What value do you expect to be in that variable, and where do you expect it to come from?

:huh2:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0