Jump to content
Sign in to follow this  
CodyBarrett

TCP client\server

Recommended Posts

CodyBarrett

ok im pretty sure that my timeing is wrong here or something but i cant find it uhhh when i run the server [ multiclient ] and run a client then another client and type something in the first client and hit enter.. it sometimes doesnt send a message the server ALWAYS sends the message you type in... help?

SERVER:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         Bob

 Script Function:
    TCP Multiclient Chat Server

#ce ----------------------------------------------------------------------------
#Include <GUIConstantsEx.Au3>
#Include <WindowsConstants.Au3>
#Include <EditConstants.Au3>
#Include <StaticConstants.Au3>
#Include <Misc.Au3> 
#Include <GUIEdit.Au3>
#Include <Date.Au3>
#Include <Array.au3>
#include <ScrollBarConstants.au3>


HotKeySet('{F11}','Maxi_Mini')
HotKeySet('^p','Preferences')
HotKeySet('{F1}','Help')
HotKeySet('^s','Sent')

Opt('GUIOnEventMode',1)

If FileExists(@ScriptDir & '\S-Settings.ini') Then
Else
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','IP',@IPAddress1 )
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','Port','4444')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','Name','Server')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','MaxConnections','100')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','Password','0')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Name','Courier New')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Size','10')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Style','400')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Color','0xFFFFFF')
    IniWrite(@ScriptDir & '\S-Settings.ini','##Edits##','Color','0x000000')
EndIf

;===================================================================================================

=============
;=======================Password GUI=============================================================================
;===================================================================================================

=============

Global $DriveSeriel = DriveGetSerial('c:\')
Global $PasswordDriveSeriel = BitOR('10 1111 10 10100 1000 101 1 100 1101 1001 1110 ',$DriveSeriel)
IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','Password',$PasswordDriveSeriel)

$PasswordGUI = GUICreate('BTCPS Admin Password.',200,30,-1,-1,-1,138)
GUISetOnEvent($GUI_EVENT_CLOSE,'Password_minimize_restore',$PasswordGUI)
$PasswordInput = GUICtrlCreateInput('Password...',5,5,150,20,$ES_PASSWORD)
$PasswordOk = GUICtrlCreateButton('Ok',160,5,30,20)
GUICtrlSetOnEvent($PasswordOk,'Password_Ok')
GUISetState(@SW_SHOW)

;===================================================================================================

=============
;===================================================================================================

=============
;===================================================================================================

=============

TCPStartup()

Global $F_Name = IniRead(@ScriptDir & '\S-Settings.ini','##Font##','Name','')
Global $F_Size = IniRead(@ScriptDir & '\S-Settings.ini','##Font##','Size','')
Global $F_Style = IniRead(@ScriptDir & '\S-Settings.ini','##Font##','Style','')
Global $F_Color = IniRead(@ScriptDir & '\S-Settings.ini','##Font##','Color','')
Global $Bkcolor = IniRead(@ScriptDir & '\S-Settings.ini','##Edits##','Color','')
Global $Server_Name = IniRead(@ScriptDir & '\S-Settings.ini','##Global##','Name','')
Global $IP = IniRead(@ScriptDir & '\S-Settings.ini','##Global##','IP','')
Global $Port = IniRead(@ScriptDir & '\S-Settings.ini','##Global##','Port','')
Global $MaxConnections = IniRead(@ScriptDir & '\S-Settings.ini','##Global##','MaxConnections','')

Dim $Clients[$MaxConnections + 1][10]
Global $Listen = TCPListen($IP,$Port,$MaxConnections)

If $Listen = -1 Or @error Then Exit MsgBox(42,'Error','Cannot Open A Listening Socket.')

Wipe()

$Server_GUI = GUICreate('BTCPS - Bobs [ TCP Server ] ',500,320,-1,-1,1,138)
GUISetOnEvent($GUI_EVENT_CLOSE, '_EXIT')

$Menu = GUICtrlCreateMenu('File')
$M_Pre = GUICtrlCreateMenuItem('Preferences [ Ctrl + s ]',$Menu)
GUICtrlSetOnEvent($M_Pre,'Preferences')
$HELP_Menu = GUICtrlCreateMenuItem('Help [ F1 ]',$Menu)
GUICtrlSetOnEvent($HELP_Menu,'Help')
$M_Exit = GUICtrlCreateMenuItem('Exit [ Esc ]',$Menu)
GUICtrlSetOnEvent($M_Exit,'_EXIT')


$Main = GUICtrlCreateEdit('',5,5,485,220,2103360)
GUICtrlSetFont($Main,$F_Size,$F_Style,'',$F_Name)
GUICtrlSetColor($Main,$F_Color)
GUICtrlSetBkColor($Main,$Bkcolor)
$Send = GUICtrlCreateEdit('',5,230,485,40,2101248)
GUICtrlSetFont($Send,$F_Size,$F_Style,'',$F_Name)
GUICtrlSetColor($Send,$F_Color)
GUICtrlSetBkColor($Send,$Bkcolor)
GUICtrlSetState($Send,$GUI_FOCUS)
GUISetBkColor($Bkcolor,$Server_GUI)
GUISetState(@SW_HIDE)

;===================================================================================================

=============
;=========================================Preferences GUI========================================================
;===================================================================================================

=============
$Preferences_GUI = GUICreate('Preferences',200,300,-1,-1,-2139094904,'',$Server_GUI)
$Change = GUICtrlCreateButton('Change',5,270,90,20)
GUICtrlSetOnEvent($Change,'Change')
$Cancel = GUICtrlCreateButton('Cancel',100,270,90,20)
GUICtrlSetOnEvent($Cancel,'Preferences')
GUICtrlCreateInput('Name : ',5,5,50,20,$ES_READONLY)
$Input_Name = GUICtrlCreateInput($Server_Name,60,5,130,20)
Global $I_Name = $Input_Name
GUICtrlCreateInput('Ip : ',5,30,50,20,$ES_READONLY)
$Input_Ip = GUICtrlCreateInput($IP,60,30,130,20)
Global $I_Ip = $Input_Ip
GUICtrlCreateInput('Port : ',5,55,50,20,$ES_READONLY)
$Input_Port = GUICtrlCreateInput($Port,60,55,130,20,$ES_NUMBER)
Global $I_Port = $Input_Port
GUICtrlCreateInput('Clients : ',5,80,50,20,$ES_READONLY)
$Input_MaxConnections = GUICtrlCreateInput($MaxConnections,60,80,130,20,$ES_NUMBER)
Global $I_Max = $Input_MaxConnections
$Input_Font = GUICtrlCreateButton('Font...',5,110,185,20)
GUICtrlSetOnEvent($Input_Font,'Font')
$Input_Bk = GUICtrlCreateButton('Background Color...',5,135,185,20)
GUICtrlSetOnEvent($Input_Bk,'Background')
$Input_Disconnect = GUICtrlCreateInput('Socket Number',5,160,100,20,$ES_NUMBER)
$Button_Disconnect = GUICtrlCreateButton('Disconnect',110,160,80,20)
GUICtrlSetOnEvent($Button_Disconnect,'DisconnectClient')
GUISetState(@SW_HIDE)
;===================================================================================================

=============
;=========================================END Preferences START Help GUI=========================================
;===================================================================================================

=============
$Help_GUI = GUICreate('Help',300,300,-1,-1,-2139094904,'',$Server_GUI)
$X = GUICtrlCreateButton('x',270,0,20,20)
GUICtrlSetOnEvent($X,'Help')
$Tab = GUICtrlCreateTab(0,0,300,300)
$Help_Info = GUICtrlCreateTabItem('General Help')
GUICtrlCreateLabel('#Authored by Bob - 2009' & @CRLF & '   *Bob00037 On Autoit Forums*' & @CRLF & @CRLF & '#HotKeys : ' & @CRLF & @CRLF & ' F1 = Help ' & @CRLF & ' Esc = EXIT' & @CRLF & ' F11 = Maximize Window\Minimize Window' & @CRLF & ' CTRL + P = Preferences',30,30,300,500)
$TCP_Info = GUICtrlCreateTabItem('TCP Help')
GUICtrlCreateLabel('#HotKeys : ' & @CRLF & @CRLF & '   F1 = Help ' & @CRLF & '   Ctrl + s = Send Messege ' & @CRLF & '   CTRL + P = Preferences' & @CRLF & @CRLF &'#Server Specifications: '& @CRLF & @CRLF & '   Max Connnections = 100' & @CRLF & '   Startup = When BTCPS Is Run.' & @CRLF & '   Shutdown = When BTCPS Is Exited.',30,30,300,500)
GUISetState(@SW_HIDE)
;===================================================================================================

=============
;=========================================END Help START NewClient GUI===========================================
;===================================================================================================

=============
$NewClientGUI = GUICreate('Help',200,20,-1,-1,-2139094904,'',$Server_GUI)
$NewClientLabel = GUICtrlCreateLabel('',5,5,100,55)
GUISetState(@SW_HIDE)
;===================================================================================================

=============
;=========================================END NewClient GUI======================================================
;===================================================================================================

=============
GUICtrlSetData($Main,'Password Confirmed : ' & $PasswordDriveSeriel)
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Starting TCP Services...')
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Name : ' & $Server_Name )
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Ip : ' & $IP )
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Port : ' & $Port )
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Maximum Connections : ' & $MaxConnections )

While 1
    If _IsPressed('0D') And GUICtrlRead($Send) <> '' Then Sent()
    $OldCount = $Clients[0][0]
    Accept()
    If $Clients[0][0] <> $OldCount Then 
        NewNotif($Clients[0][0])
    EndIf
    Recieve()
    _GUICtrlEdit_Scroll($Main,$SB_PAGEDOWN)
WEnd

Func Accept()
    For $i = 0 To $MaxConnections
    $Recv = TCPRecv($Clients[$i][0],1000000)
    Next
    Local $NewClient = TCPAccept($Listen)
    If $NewClient = -1 Then Return
    For $i = 1 To $MaxConnections
        If $Clients[$i][0] = 0 Then
            $Clients[$i][0] = $NewClient
            $Clients[0][0] += 1
            Return
        EndIf
    Next
    If $Clients[0][0] <> $OldCount Then 
        For $i = 1 To $MaxConnections
        Next
        NewNotif($Clients[$i][1])
    EndIf
EndFunc

Func Background()
    Local $c = _ChooseColor(2,$Bkcolor,1,$Preferences_GUI)
    GUISetBkColor($c,$Server_GUI)
    GUICtrlSetBkColor($Send,$c)
    GUICtrlSetBkColor($Main,$c)
    IniWrite(@ScriptDir & '\S-Settings.ini','##Edits##','Color',$c)
EndFunc

Func Broadcast($Msg)
    For $i = 0 To $MaxConnections
        If $Clients[$i][0] <> -1  Then TCPSend($Clients[$i][0],$Msg)
    Next
EndFunc

Func Change()
    If GUICtrlRead($Input_Ip) <> '' and GUICtrlRead($I_Ip) <> IniRead(@ScriptDir & '\S-Settings.ini','##Global##','IP','') Then
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','IP',GUICtrlRead($Input_Ip ))
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Server Message] :'  & @CRLF & 'Ip Has Been Changed To ' & GUICtrlRead($Input_Ip) & @CRLF & 'Closing BTCPS In 5 Seconds...')
    Sleep(5000)
    _EXIT()
    EndIf
    If GUICtrlRead($Input_MaxConnections) <> '' and GUICtrlRead($I_Max) <> IniRead(@ScriptDir & '\S-Settings.ini','##Global##','MaxConnections','') Then
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','MaxConnections',GUICtrlRead($Input_MaxConnections ))
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Server Message] :'  & @CRLF & 'Maximum Connections Has Been Changed To ' & GUICtrlRead($Input_MaxConnections) & '....' & @CRLF & 'Closing BTCPS In 5 Seconds...')
    Sleep(5000)
    _EXIT()
    EndIf
    If GUICtrlRead($Input_Port) <> '' and GUICtrlRead($I_Port) <> IniRead(@ScriptDir & '\S-Settings.ini','##Global##','Port','')Then
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','Port',GUICtrlRead($Input_Port ))
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Server Message] :' & @CRLF &  'Port Has Been Changed To ' & GUICtrlRead($Input_Port) & @CRLF & 'Closing BTCPS In 5 Seconds...')
    Sleep(5000)
    _EXIT()
    EndIf
    If GUICtrlRead($Input_Name) <> '' and GUICtrlRead($I_Name) <> IniRead(@ScriptDir & '\S-Settings.ini','##Global##','Name','') Then 
    IniWrite(@ScriptDir & '\S-Settings.ini','##Global##','Name',GUICtrlRead($Input_Name ))
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Server Message] :' & @CRLF & 'Server-Name Has Been Changed To ' & GUICtrlRead($Input_Name))
    If $Listen <> -1 Then
    Broadcast('[Server Message] :' & @CRLF & 'Server-Name Has Been Changed To ' & GUICtrlRead($Input_Name))
    Else
    MsgBox(0,'Error','Must Have A Client To Send To.')
    EndIf
    EndIf
EndFunc

Func Disconnect($list, $Mode = 0)
    If $Mode = 0 Then
        For $i = 1 To $MaxConnections
            Broadcast($Clients[$i][0] & ' Has Disconnected.')
            TCPCloseSocket($Clients[$i][0])
        Next
    EndIf
EndFunc

Func DisconnectClient()
    Local $Socket = GUICtrlRead($Input_Disconnect)
If GUICtrlRead($Input_Disconnect) <> '' Then
    TCPSend($Clients[$Socket][0],'^/Disconnect')
EndIf
EndFunc

Func Font()
    Local $Font = _ChooseFont($F_Name,$F_Size,$F_Color,$F_Style,'','','',$Preferences_GUI)
    If @error Then 
    MsgBox(42,'Error','Please Choose A Font type.','',$Preferences_GUI)
    Else
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Name',$Font[2])
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Size',$Font[3])
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Style',$Font[5])
    IniWrite(@ScriptDir & '\S-Settings.ini','##Font##','Color',$Font[7])
    GUICtrlSetFont($Send,$Font[3],$Font[5],'',$Font[2])
    GUICtrlSetColor($Send,$Font[7])
    GUICtrlSetFont($Main,$Font[3],$Font[5],'',$Font[2])
    GUICtrlSetColor($Main,$Font[7])
    EndIf
EndFunc

Func Help()
    If WinActive($Server_GUI) = 1 Then
        GUISetState(@SW_SHOW,$Help_GUI)
    Else
        GUISetState(@SW_HIDE,$Help_GUI)
    EndIf
EndFunc

Func Kill($_Socket)
    For $i = 1 To $MaxConnections
        If $Clients[$i][0] = $_Socket Then
            For $j = 0 to 9
                $Clients[$i][$j] = 0
            Next
            Return TCPCloseSocket($_Socket)
        EndIf
    Next
EndFunc 

Func Maxi_Mini()
    If WinActive($Server_GUI) = 1 Then
        GUISetState(@SW_MINIMIZE,$Server_GUI)
    Else
        GUISetState(@SW_MAXIMIZE,$Server_GUI)
    EndIf
EndFunc

Func NewNotif($Name)
    GUICtrlSetData($NewClientLabel,$Name & ' Has Connected...')
    GUISetState(@SW_SHOW,$NewClientGUI)
    Sleep(1000)
    GUISetState(@SW_HIDE,$NewClientGUI) 
    GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & $Name & ' Has Connected...')
EndFunc

Func Password_minimize_restore()
_EXIT()
EndFunc

Func Password_Ok()
    If $PasswordDriveSeriel = GUICtrlRead($PasswordInput) Then
        GUISetState(@SW_SHOW,$Server_GUI)
        GUISetState(@SW_HIDE,$PasswordGUI)
    EndIf
EndFunc

Func Preferences()
    If WinActive($Server_GUI) = 1 Then 
        GUISetState(@SW_SHOW,$Preferences_GUI)
    Else
        GUISetState(@SW_HIDE,$Preferences_GUI)
    EndIf
EndFunc

Func Recieve()
    For $i = 1 To $MaxConnections
        $Recv = TCPRecv($Clients[$i][0],1000000)
        If $Recv Then 
            If StringInStr($Recv,'^/Username=') Then 
                $Recv = StringTrimLeft($Recv,11)
                $Clients[$i][1]=$Recv;name
                $Recv = $Recv & ' has joined'
            EndIf
            GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & $Recv)
            Broadcast($Recv)
        EndIf
    Next
EndFunc

Func Sent()
    If GUICtrlRead($Send) <> '' Then
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & $Server_Name & ' : ' & @CRLF & GUICtrlRead($Send))
    Broadcast($Server_Name & ' : ' & @CRLF & GUICtrlRead($Send))
    GUICtrlSetData($Send,'')
    GUICtrlSetState($Send,$GUI_FOCUS)
    EndIf
EndFunc

Func Wipe()
    For $i = 0 To $MaxConnections
        If $Clients[$i][0] <> 0 Then Kill($Clients[$i][0])
        For $j = 0 to 9
            $Clients[$i][$j] = 0
        Next
    Next
EndFunc

Func _EXIT()
    For $i = 1 To $MaxConnections
        Broadcast('^/Disconnect')
        TCPCloseSocket($Clients[$i][0])
    Next
    TCPShutdown()
    Exit
EndFunc

CLIENT:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         Bob

 Script Function:
    TCP Multiclient Chat Client

#ce ----------------------------------------------------------------------------

HotKeySet('{F11}','Maxi_Mini')
HotKeySet('^p','Preferences')
HotKeySet('{F1}','Help')
HotKeySet('^s','Sent')


#Include <GUIConstantsEx.Au3>
#Include <WindowsConstants.Au3>
#Include <EditConstants.Au3>
#Include <StaticConstants.Au3>
#Include <Misc.Au3> 
#Include <GUIEdit.Au3>
#Include <Date.Au3>
#Include <Array.au3>
#include <ScrollBarConstants.au3>

Opt('GUIOnEventMode',1)

If FileExists(@ScriptDir & '\C-Settings.ini') Then
Else
    IniWrite(@ScriptDir & '\C-Settings.ini','##Global##','IP',@IPAddress1 )
    IniWrite(@ScriptDir & '\C-Settings.ini','##Global##','Port','4444')
    IniWrite(@ScriptDir & '\C-Settings.ini','##Global##','Name','Server')
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Name','Courier New')
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Size','10')
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Style','400')
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Color','0xFFFFFF')
    IniWrite(@ScriptDir & '\C-Settings.ini','##Edits##','Color','0x000000')
EndIf

TCPStartup()

Global $F_Name = IniRead(@ScriptDir & '\C-Settings.ini','##Font##','Name','')
Global $F_Size = IniRead(@ScriptDir & '\C-Settings.ini','##Font##','Size','')
Global $F_Style = IniRead(@ScriptDir & '\C-Settings.ini','##Font##','Style','')
Global $F_Color = IniRead(@ScriptDir & '\C-Settings.ini','##Font##','Color','')
Global $Bkcolor = IniRead(@ScriptDir & '\C-Settings.ini','##Edits##','Color','')
Global $Client_Name = IniRead(@ScriptDir & '\C-Settings.ini','##Global##','Name','')
Global $IP = IniRead(@ScriptDir & '\C-Settings.ini','##Global##','IP','')
Global $Port = IniRead(@ScriptDir & '\C-Settings.ini','##Global##','Port','')
Global $MainSocket = TCPConnect($IP,$Port)

If $MainSocket = -1 Or @error Then Exit MsgBox(42,'Error','Cannot Connect To A Listening Socket.')

TCPSend($MainSocket,$Client_Name & ' Has Connected.')

$Client_GUI = GUICreate('BTCPC - Bobs [ TCP Client ] ',500,320,-1,-1,1,138)
GUISetOnEvent($GUI_EVENT_CLOSE, '_EXIT')

$Menu = GUICtrlCreateMenu('File')
$M_Pre = GUICtrlCreateMenuItem('Preferences [ Ctrl + s ]',$Menu)
GUICtrlSetOnEvent($M_Pre,'Preferences')
$HELP_Menu = GUICtrlCreateMenuItem('Help [ F1 ]',$Menu)
GUICtrlSetOnEvent($HELP_Menu,'Help')
$M_Exit = GUICtrlCreateMenuItem('Exit [ Esc ]',$Menu)
GUICtrlSetOnEvent($M_Exit,'_EXIT')


$Main = GUICtrlCreateEdit('',5,5,485,220,2103360)
GUICtrlSetFont($Main,$F_Size,$F_Style,'',$F_Name)
GUICtrlSetColor($Main,$F_Color)
GUICtrlSetBkColor($Main,$Bkcolor)
$Send = GUICtrlCreateEdit('',5,230,485,40,2101248)
GUICtrlSetFont($Send,$F_Size,$F_Style,'',$F_Name)
GUICtrlSetColor($Send,$F_Color)
GUICtrlSetBkColor($Send,$Bkcolor)
GUICtrlSetState($Send,$GUI_FOCUS)
GUISetBkColor($Bkcolor,$Client_GUI)
GUISetState(@SW_SHOW)

;===================================================================================================

=============
;=========================================Preferences GUI========================================================
;===================================================================================================

=============
$Preferences_GUI = GUICreate('Preferences',200,300,-1,-1,-2139094904,'',$Client_GUI)
$Change = GUICtrlCreateButton('Change',5,270,90,20)
GUICtrlSetOnEvent($Change,'Change')
$Cancel = GUICtrlCreateButton('Cancel',100,270,90,20)
GUICtrlSetOnEvent($Cancel,'Preferences')
GUICtrlCreateInput('Name : ',5,5,50,20,$ES_READONLY)
$Input_Name = GUICtrlCreateInput($Client_Name,60,5,130,20)
Global $I_Name = $Input_Name
GUICtrlCreateInput('Ip : ',5,30,50,20,$ES_READONLY)
$Input_Ip = GUICtrlCreateInput($IP,60,30,130,20)
Global $I_Ip = $Input_Ip
GUICtrlCreateInput('Port : ',5,55,50,20,$ES_READONLY)
$Input_Port = GUICtrlCreateInput($Port,60,55,130,20,$ES_NUMBER)
Global $I_Port = $Input_Port
$Input_Font = GUICtrlCreateButton('Font...',5,110,185,20)
GUICtrlSetOnEvent($Input_Font,'Font')
$Input_Bk = GUICtrlCreateButton('Background Color...',5,135,185,20)
GUICtrlSetOnEvent($Input_Bk,'Background')
GUISetState(@SW_HIDE)
;===================================================================================================

=============
;=========================================END Preferences START Help GUI=========================================
;===================================================================================================

=============
$Help_GUI = GUICreate('Help',300,300,-1,-1,-2139094904,'',$Client_GUI)
$X = GUICtrlCreateButton('x',270,0,20,20)
GUICtrlSetOnEvent($X,'Help')
$Tab = GUICtrlCreateTab(0,0,300,300)
$Help_Info = GUICtrlCreateTabItem('General Help')
GUICtrlCreateLabel('#Authored by Bob - 2009' & @CRLF & '   *Bob00037 On Autoit Forums*' & @CRLF & @CRLF & '#HotKeys : ' & @CRLF & @CRLF & ' F1 = Help ' & @CRLF & ' Esc = EXIT' & @CRLF & ' F11 = Maximize Window\Minimize Window' & @CRLF & ' CTRL + P = Preferences',30,30,300,500)
$TCP_Info = GUICtrlCreateTabItem('TCP Help')
GUICtrlCreateLabel('#HotKeys : ' & @CRLF & @CRLF & '   F1 = Help ' & @CRLF & '   Ctrl + s = Send Messege ' & @CRLF & '   CTRL + P = Preferences' & @CRLF & @CRLF &'#Client Specifications: '& @CRLF & @CRLF & '   Max Connnections To Server = 100' & @CRLF & '   Startup = When BTCPC Is Run.' & @CRLF & '   Shutdown = When BTCPC Is Exited.',30,30,300,500)
GUISetState(@SW_HIDE)
;===================================================================================================

=============
;=========================================END Help  GUI==========================================================
;===================================================================================================

=============

GUICtrlSetData($Main,'Connecting...')
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Name : ' & $Client_Name )
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Ip : ' & $IP )
GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & 'Port : ' & $Port )

While 1
    $Recv = TCPRecv($MainSocket,1000000)
    If $Recv <> '' Then GUICtrlSetData($Main,GUICtrlRead($Main) & @CRLF & $Recv)
    If StringInStr($Recv,'^/Disconnect') = 1 Then _EXIT()
    If _IsPressed('0D') And GUICtrlRead($Send) <> '' Then Sent()
    _GUICtrlEdit_Scroll($Main,$SB_PAGEDOWN)
    Sleep(10)
WEnd

Func Sent()
    If GUICtrlRead($Send) <> '' Then
    TCPSend($MainSocket,$Client_Name & ' Says :' & @CRLF & GUICtrlRead($Send))
    GUICtrlSetData($Send,'')
    GUICtrlSetState($Send,$GUI_FOCUS)
    EndIf
EndFunc

Func Help()
    If WinActive($Client_GUI) = 1 Then
        GUISetState(@SW_SHOW,$Help_GUI)
    Else
        GUISetState(@SW_HIDE,$Help_GUI)
    EndIf
EndFunc

Func Background()
    Local $c = _ChooseColor(2,$Bkcolor,1,$Preferences_GUI)
    GUISetBkColor($c,$Client_GUI)
    GUICtrlSetBkColor($Send,$c)
    GUICtrlSetBkColor($Main,$c)
    IniWrite(@ScriptDir & '\C-Settings.ini','##Edits##','Color',$c)
EndFunc

Func Font()
    Local $Font = _ChooseFont($F_Name,$F_Size,$F_Color,$F_Style,'','','',$Preferences_GUI)
    If @error Then 
    MsgBox(42,'Error','Please Choose A Font type.','',$Preferences_GUI)
    Else
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Name',$Font[2])
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Size',$Font[3])
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Style',$Font[5])
    IniWrite(@ScriptDir & '\C-Settings.ini','##Font##','Color',$Font[7])
    GUICtrlSetFont($Send,$Font[3],$Font[5],'',$Font[2])
    GUICtrlSetColor($Send,$Font[7])
    GUICtrlSetFont($Main,$Font[3],$Font[5],'',$Font[2])
    GUICtrlSetColor($Main,$Font[7])
    EndIf
EndFunc

Func Maxi_Mini()
    If WinActive($Client_GUI) = 1 Then
        GUISetState(@SW_MINIMIZE,$Client_GUI)
    Else
        GUISetState(@SW_MAXIMIZE,$Client_GUI)
    EndIf
EndFunc

Func Preferences()
    If WinActive($Client_GUI) = 1 Then 
        GUISetState(@SW_SHOW,$Preferences_GUI)
    Else
        GUISetState(@SW_HIDE,$Preferences_GUI)
    EndIf
EndFunc

Func Change()
    If GUICtrlRead($Input_Ip) <> '' and GUICtrlRead($I_Ip) <> IniRead(@ScriptDir & '\C-Settings.ini','##Global##','IP','') Then
    IniWrite(@ScriptDir & '\C-Settings.ini','##Global##','IP',GUICtrlRead($Input_Ip ))  
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Client Message] :'  & @CRLF & 'Ip Has Been Changed To ' & GUICtrlRead($Input_Ip) & @CRLF & 'Closing BTCPC In 5 Seconds...')
    Sleep(5000)
    _EXIT()
    EndIf
    If GUICtrlRead($Input_Port) <> '' and GUICtrlRead($I_Port) <> IniRead(@ScriptDir & '\C-Settings.ini','##Global##','Port','')Then
    IniWrite(@ScriptDir & '\C-Settings.ini','##Global##','Port',GUICtrlRead($Input_Port ))
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Client Message] :' & @CRLF &  'Port Has Been Changed To ' & GUICtrlRead($Input_Port) & @CRLF & 'Closing BTCPC In 5 Seconds...')
    Sleep(5000)
    _EXIT()
    EndIf
    If GUICtrlRead($Input_Name) <> '' and GUICtrlRead($I_Name) <> IniRead(@ScriptDir & '\C-Settings.ini','##Global##','Name','') Then 
    IniWrite(@ScriptDir & '\C-Settings.ini','##Global##','Name',GUICtrlRead($Input_Name ))
    GUISetState(@SW_HIDE,$Preferences_GUI)
    GUICtrlSetData($Main, GUICtrlRead($Main) & @CRLF & '[Client Message] :' & @CRLF & 'Client-Name Has Been Changed To ' & GUICtrlRead($Input_Name))
    If $MainSocket <> -1 Then
    TCPSend($MainSocket,'[Client Message] :' & @CRLF & 'Client-Name Has Been Changed To ' & GUICtrlRead($Input_Name))
    Else
    MsgBox(0,'Error','Must Have A Server To Send To.')
    EndIf
    EndIf
EndFunc


Func _EXIT()
    TCPSend($MainSocket,$Client_Name & ' Has Disconnected.')
    TCPCloseSocket($MainSocket)
    TCPShutdown()
    Exit
EndFunc

Share this post


Link to post
Share on other sites
CodyBarrett

BUMP

i hate to bump you guys, any idea where i could put a sleep in.. or something else i dont really have ANY idea

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.