Sign in to follow this  
Followers 0
vikingnor

Chat Client

3 posts in this topic

i use a old Chat Client Script Posted here and i want it mostly fixed... but still it is bugged ^^ i did change the GUI Really much so you know :)

Client Side..

#include <guiconstants.au3>
global $connect_port = 34000

$ip = ("Server ip here.")

tcpstartup()

$socket = tcpconnect ($ip, $connect_port)
if $socket = -1 then
    Exit
EndIf

Do
    Do
        $user = InputBox ("Connected", "Connection established please type in your desired Username")
        if @error = 1 Then
            $end = msgbox (4, "End client", "Sure you want to exit?")
            if $end = 6 Then
                Exit
            EndIf
        EndIf
    until StringLen ($user) > 3 and StringLen ($user) < 12
    tcpsend ($socket, "~~us:" & $user)

    Do
        $recv = tcprecv ($socket, 512)
        if $recv = "~~password" Then
            $pw = InputBox ("Password required", "Please type in the password for " & $user, "", "*")
            tcpsend ($socket, "~~pw:" & $pw)
        EndIf
    until $recv = "~~accepted" or $recv = "~~rejected" or @error = 1
until $recv = "~~accepted" or $recv = "~~rejected"

if $recv = "~~rejected" Then
    msgbox (0, "Failure", "Maximum number of users reached or Server currently not availible, please try again later")
    Exit
EndIf

$main = GuiCreate("Chronos Chat @ " & $user, 450, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$input = GUICtrlCreateInput ("", 20, 170, 280, 20)
$edit = GUICtrlCreateEdit ("", 20, 30, 270, 120, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL)
$userlist = GUICtrlCreateEdit ("", 330, 30, 100, 120, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL)
$send = GUICtrlCreateButton ("Send", 320, 170, 120, 20, $BS_DEFPUSHBUTTON)
$chatgroup = GuiCtrlCreateGroup("Chat", 10, 10, 290, 150)
$usergroup = GuiCtrlCreateGroup("Users", 320, 10, 120, 150)
GUICtrlSetState ($input, $GUI_FOCUS)
GUISetState()

while 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        tcpsend ($socket, "~~bye")
        sleep (5000)
        tcpshutdown()
        Exit
    EndIf
    
    if $msg = $send Then
        if guictrlread ($input) <> "" Then
            tcpsend ($socket, guictrlread($input))
            GUICtrlSetData ($input, "")
        EndIf
    EndIf
    
    $recv = tcprecv ($socket, 512)
    $err = @error
    
    if $recv = "~~bye" Then
        GUICtrlSetData ($edit, "~~Connection Lost" & @CRLF & GUICtrlRead($edit))
        tcpshutdown()
        ExitLoop
    EndIf
    
    if $recv <> "" and $err = 0 and not StringInStr ($recv, "~~users:") Then
        GUICtrlSetData ($edit, $recv & @CRLF & GUICtrlRead($edit))
    EndIf
    
    if StringInStr($recv, "~~users:") then
        $users = StringTrimLeft ($recv, 8)
        $users = StringReplace ($users, "|", @crlf)
        GUICtrlSetData ($userlist, $users)
    EndIf
    
WEnd


Func OnAutoItExit()
   TCPSend( $socket, "~~bye" )
   TCPCloseSocket( $socket )
   TCPShutDown()
EndFunc

Server Side

#include <guiconstants.au3>
global $g_port = 34000
Global $g_IP = @IPADDRESS1
Global $MainSocket
dim $ConnectedSocket[101]
dim $recv[101]
dim $user[101]
dim $pw[101]
for $i = 1 to 100 step 1
    $ConnectedSocket[$i] = -1
Next


tcpstartup()

$MainSocket = TCPListen($g_IP, $g_port,  100 )
If $MainSocket = -1 Then Exit
$RogueSocket = -1

$input = GUICtrlCreateInput ("", 10, 10, 280)
$main = GUICreate ("Chat Server", 600, 400,-1, -1 )
Opt("GuiOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close")
$edit = GUICtrlCreateEdit ("", 20, 30, 270, 350, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL)
$userlist = GUICtrlCreateEdit ("Server", 440, 30, 140, 350, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_WANTRETURN)
$Group_3 = GuiCtrlCreateGroup("Users Connected", 430, 10, 160, 380)
$Group_4 = GuiCtrlCreateGroup("Chat Log", 10, 10, 290, 380)
$Button_5 = GuiCtrlCreateButton("test", 320, 30, 90, 30)
$Group_6 = GuiCtrlCreateGroup("Menu", 310, 10, 110, 380)
$Button_7 = GuiCtrlCreateButton("test", 320, 70, 90, 30)
$Button_8 = GuiCtrlCreateButton("test", 320, 110, 90, 30)
$Button_9 = GuiCtrlCreateButton("test", 320, 150, 90, 30)
$Button_10 = GuiCtrlCreateButton("test", 320, 190, 90, 30)
$Button_11 = GuiCtrlCreateButton("Stop Server", 320, 350, 90, 30)
GUICtrlSetOnEvent(-1, "GUI_Close")
$send = GuiCtrlCreateButton("Refresh", 320, 230, 90, 30, $BS_DEFPUSHBUTTON)
GUICtrlSetState ($input, $GUI_FOCUS)
GUISetState()

$users = "Server" & @CRLF
$users1 = $users
while 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        for $i = 1 to 100 step 1
            if $ConnectedSocket[$i] <> -1 Then
                tcpsend ($ConnectedSocket[$i], "~~bye")
            EndIf
        Next
        tcpshutdown()
        Exit
    EndIf
    
    if $msg = $send Then
        if GUICtrlRead ($input) <> "" Then
            for $i = 1 to 100 step 1
                if $ConnectedSocket[$i] <> -1 Then
                    tcpsend ($ConnectedSocket[$i], "Server: " & guictrlread ($input))
                EndIf
            Next
            GUICtrlSetData ($edit, guictrlread($input) & @crlf & guictrlread ($edit))
            GUICtrlSetData ($input, "")
        EndIf
    EndIf
    
    for $i = 1 to 100 step 1
        if $ConnectedSocket[$i] <> -1 Then
            $recv[$i] = tcprecv($ConnectedSocket[$i], 512)
            $err = @error
            if $recv[$i] = "~~bye" Then
                $ConnectedSocket[$i] = -1
                tcpclosesocket($ConnectedSocket[$i])
                $test = $user[$i] & "|"
                $users = StringReplace ($users, $test, "")
                GUICtrlSetData ($userlist, $users)
                if StringReplace ($users1, "|", @crlf) <> $users Then
                    for $j = 1 to 100
                        if $ConnectedSocket[$i] <> -1 Then
                            tcpsend($ConnectedSocket[$i], "~~users:" & $users1)
                        EndIf
                    Next
                EndIf
            EndIf
            
            if StringInStr ($recv[$i], "~~us:") Then
                $user[$i] = stringtrimleft ($recv[$i], 5)
                $test = $user[$i] & @CRLF
                if not StringInStr ($users, $test) Then
                    if iniread ("chat.ini", "Users", $user[$i], "") <> "" Then
                        tcpsend ($ConnectedSocket[$i], "~~password")
                    Else
                        tcpsend ($ConnectedSocket[$i], "~~accepted")
                        USERLIST()
                    EndIf
                EndIf
            EndIf
            
            if StringInStr ($recv[$i], "~~pw:") Then
                $pw[$i] = StringTrimLeft ($recv[$i], 5)
                if iniread ("chat.ini", "Users", $user[$i], "") = $pw[$i] then
                    tcpsend($ConnectedSocket[$i], "~~accepted")
                    USERLIST()
                Else
                    tcpsend ($ConnectedSocket[$i], "~~password")
                EndIf
            EndIf
            
            if $recv[$i] <> "" and $err = 0 and $recv[$i] <> "~~bye" and not StringInStr($recv[$i], "~~us:") and not StringInStr($recv[$i], "~~pw:") Then
                for $j = 1 to 100 step 1
                    if $ConnectedSocket[$j] <> -1 Then
                        tcpsend($ConnectedSocket[$j], $user[$i] & ": " & $recv[$i])
                    EndIf
                Next
                GUICtrlSetData ($edit, $user[$i] & ": " & $recv[$i] & @crlf & guictrlread($edit))
            EndIf
            
        Else
            $ConnectedSocket[$i] = tcpaccept($MainSocket)
        EndIf
    Next
WEnd

func USERLIST()
    for $i = 1 to 100 step 1
        if $ConnectedSocket[$i] <> -1 Then
            $test = $user[$i] & @CRLF
            if not stringinstr ($users, $test) Then
                $users = $users & $user[$i] & @CRLF
            EndIf
        Elseif $ConnectedSocket[$i] = -1 Then
       ;$users = stringreplace ($users, $user[$i], "")
        EndIf       
    Next
    
    $users1 = StringReplace ($users, @CRLF , "|")
    for $i = 1 to 100 step 1
        if $ConnectedSocket[$i] <> -1 Then
            tcpsend ($ConnectedSocket[$i], "~~users:" & $users1)
        EndIf
    Next
    
    GUICtrlSetData ($userlist, $users)
EndFunc

Func GUI_Close()
    Exit
EndFunc  ;==>GUI_Close

i dont know how but i looked true all the styles and so on to find someway to make a new message appear below not above.

also i want a auto refresh for the user's to check if their still online for either removing but still i am a bit Autoit newbie for this ^^

Share this post


Link to post
Share on other sites



i dont know how but i looked true all the styles and so on to find someway to make a new message appear below not above.

also i want a auto refresh for the user's to check if their still online for either removing but still i am a bit Autoit newbie for this ^^

Alright, it took me a bit to figure out what you were asking.

Question 1.) As far as I know, there is no Edit style that will allow the text to align to the bottom of the edit control. As a workaround you could possibly have the editbox start off with a set amount of @CRLF 's so the first entry would be at the bottom of the edit control. Then each time the chatbox has a new line of text added to it you'd have to remove a @CRLF until the chatbox had each visible line filled with text.. then it could operate as normal.

Question 2.) Do you mean you want it to automatically do a server-side refresh? Like when you hit the Refresh button on the server? If so, copy the code in the:

if $msg = $send Then
if GUICtrlRead ($input) <> "" Then
            for $i = 1 to 100 step 1
                if $ConnectedSocket[$i] <> -1 Then
                    tcpsend ($ConnectedSocket[$i], "Server: " & guictrlread ($input))
                EndIf
            Next
            GUICtrlSetData ($edit, guictrlread($input) & @crlf & guictrlread ($edit))
            GUICtrlSetData ($input, "")
        EndIf
    EndIf

Without the If statement surrounding it and place it in the scripts While loop so it does it each cycle.. or something similar.

-Simucal


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Alright, it took me a bit to figure out what you were asking.

Question 1.) As far as I know, there is no Edit style that will allow the text to align to the bottom of the edit control. As a workaround you could possibly have the editbox start off with a set amount of @CRLF 's so the first entry would be at the bottom of the edit control. Then each time the chatbox has a new line of text added to it you'd have to remove a @CRLF until the chatbox had each visible line filled with text.. then it could operate as normal.

Question 2.) Do you mean you want it to automatically do a server-side refresh? Like when you hit the Refresh button on the server? If so, copy the code in the:

if $msg = $send Then
if GUICtrlRead ($input) <> "" Then
            for $i = 1 to 100 step 1
                if $ConnectedSocket[$i] <> -1 Then
                    tcpsend ($ConnectedSocket[$i], "Server: " & guictrlread ($input))
                EndIf
            Next
            GUICtrlSetData ($edit, guictrlread($input) & @crlf & guictrlread ($edit))
            GUICtrlSetData ($input, "")
        EndIf
    EndIf

Without the If statement surrounding it and place it in the scripts While loop so it does it each cycle.. or something similar.

-Simucal

no i mean like a auto refresh :) that happens each 30 second.

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