Sign in to follow this  
Followers 0
Aceguy

LAN Chat...

21 posts in this topic

#1 ·  Posted (edited)

Lan chat, confirmed works with 3 pc's

Still lots to do

#include<Array.au3>
#include<GuiListView.au3>
#include<Misc.au3>
#include<GUIConstantsEx.au3>
#include<ListViewConstants.au3>
#include<WindowsConstants.au3>
#include<StructureConstants.au3>
#include <ButtonConstants.au3>
#include <Sound.au3>


Opt("GUIOnEventMode", 1)
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chat.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $contactserver, $buddy, $contactdata, $msgdata, $sel, $rename, $menu1, $ms_
Global $hlistview, $c_list, $chat_gui, $buttoncontext, $buttonitem, $msg, $me
Dim $buddy[1]
Dim $inifile = @MyDocumentsDir & "\chat.ini"

$chat_gui = GUICreate("chat 1.1", 212, 390, 526, 146, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUISetBkColor(0xC8C8FF, $chat_gui)

$c_list = GUICtrlCreateListView("", 8, 278, 193, 103, $LVS_LIST, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetColumnWidth($c_list, 0, 100)
_GUICtrlListView_SetExtendedListViewStyle($c_list, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetView($c_list, 3)

$input = GUICtrlCreateInput("", 5, 5, 150, 25)
GUICtrlSetOnEvent(-1, "sendit")

$hlistview = GUICtrlCreateListView("", 8, 45, 193, 230, $LVS_LIST, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetColumnWidth($hlistview, 0, 100)
_GUICtrlListView_SetExtendedListViewStyle($hlistview, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetView($hlistview, 3)

GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()
$me = ""
load()
If $me = "" Then
    $me = InputBox("Who Are you", "Your name", "")
    Global $me
    IniWrite($inifile, "me", 0, $me)
    _GUICtrlListView_AddItem($c_list, $me)
    _ArrayAdd($buddy, $me)
EndIf

$PrivateIP = @IPAddress1
; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================

$contactserver = UDPBind($PrivateIP, 65335)

Sleep(1000)
;create multicast address
$splitaddress = StringSplit($PrivateIP, ".")
$changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255"

;send packet
$contactcast = UDPOpen($changeaddress, 65335)

AdlibEnable("check", 1000)

While 1
    $contactdata = UDPRecv($contactserver, 50)
    If StringInStr($contactdata, "|") > 0 Then
        $str = StringSplit($contactdata, "|")
        
        If $contactdata <> "" And StringInStr($str[1], ".") = 4 And StringInStr($str[1], ".", 0, 2) = 8 Then
            $ar = _ArraySearch($buddy, $str[2])
            If @error Then
                ConsoleWrite("Adding via Buddy")
                _ArrayAdd($buddy, $str[2])
                _GUICtrlListView_AddItem($c_list, $str[2])
            Else
                $c = _GUICtrlListView_GetItemText($c_list, $ar - 1)
                If StringInStr($c, "On-line") = 0 Then
                    _GUICtrlListView_SetItemText($c_list, $ar - 1, $str[2] & " On-line")

                    If $str[2] <> $me Then _GUICtrlListView_AddItem($hlistview, $str[2] & " Has signed on")
                    _SoundPlay("C:\Windows\Media\Speech on.wav",0)
                EndIf
            EndIf
            
        EndIf
    EndIf
    
    If $contactdata <> "" Then

        $tmp = StringSplit($contactdata, "|")
        
        $msgdata = $tmp[2]

        If StringInStr($msgdata, $me) = 0 And StringInStr($tmp[1], ".") <> 4 And StringInStr($tmp[2], "Has signed") = 0 Then
            $str = StringSplit($msgdata, "|")
            $last = $str[0]
            _SoundPlay("Windows Shutdown.wav", 0)
            _GUICtrlListView_AddItem($hlistview, $str[$last] & " Says: " & $tmp[1])
            _GUICtrlListView_Scroll($hlistview, 0, 50)
        ElseIf StringInStr($msgdata, $me) = 0 And StringInStr($tmp[1], ".") <> 4 And StringInStr($tmp[2], "Has signed") > 0 Then
            $str = StringSplit($msgdata, "|")
            $last = $str[0]
            If StringInStr($tmp[2], "Has signed off") > 0 Then
                _GUICtrlListView_AddItem($hlistview, $tmp[1] & " " & $str[$last])
                _GUICtrlListView_Scroll($hlistview, 0, 50)
                $ar = _ArraySearch($buddy, $tmp[1])
                _GUICtrlListView_SetItemText($c_list, $ar - 1, $tmp[1] & " Off-line")
                
            EndIf
            
        EndIf
    EndIf
    
    If _IsPressed("OD") Then sendit()
    Sleep(50)
    
WEnd

Func check()
    If $me <> "" Then UDPSend($contactcast, @IPAddress1 & "|" & $me)
EndFunc   ;==>check

Func quit()
    _SoundPlay("C:\Windows\Media\Speech Off.wav",0)
    AdlibDisable()
    Sleep(1000)
    UDPSend($contactcast, $me & "|Has signed off")
    UDPCloseSocket($PrivateIP)
    UDPShutdown()
    For $i = 1 To UBound($buddy) - 1
        IniWrite($inifile, "contacts", $i - 1, $buddy[$i])
    Next
    
    Exit
EndFunc   ;==>quit

Func load()
    $me = IniRead($inifile, "me", 0, "")
    $var = IniReadSection($inifile, "contacts")
    
    If Not @error Then
        For $x = 1 To $var[0][0]
            If $var[$x][1] <> @IPAddress1 Then
                _GUICtrlListView_AddItem($c_list, $var[$x][1] & " Off-line")
                _ArrayAdd($buddy, $var[$x][1])
            Else
                If $me <> "" Then
                    _GUICtrlListView_AddItem($c_list, $me & " Off-line")
                    _ArrayAdd($buddy, $me)
                EndIf
            EndIf
        Next
    EndIf
    
    
EndFunc   ;==>load

Func sendit()
    ConsoleWrite("SEND" & @LF)
    UDPSend($contactcast, GUICtrlRead($input) & "|" & $me)
    _GUICtrlListView_AddItem($hlistview, $me & " Sends: " & GUICtrlRead($input))
    GUICtrlSetData($input, "")
    _GUICtrlListView_Scroll($hlistview, 0, 50)
EndFunc   ;==>sendit

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $iCode, $tInfo, $iItem
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iCode
        Case $NM_RCLICK
            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
            $sel = DllStructGetData($tInfo, "Index")
            ConsoleWrite("Right click")
    
            Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
            If $iItem = _GUICtrlListView_GetColumnCount($hListView) - 1 Then Return 1
            ConsoleWrite("double click")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func rename()
    ConsoleWrite("func rename")
EndFunc   ;==>rename
Edited by Aceguy

Share this post


Link to post
Share on other sites



Not necessarily, but it sounds like he might be looking for something like VNC.

Share this post


Link to post
Share on other sites

KEY LOGGER NOOOOOOO.....

the keys pressed on pc 1 will not be saved... just used to start a command on 2nd pc... like running a file, sending file to pc1.. or even a lan chat...

i know if search the net i could find the right program, but would like ot know if autoit can do it... i love autoit and would like to make my own...

i have 5 pc's yes 5 in my house and a lan chat would be great... can this be done with 1 proggy.

and the key press idea would be, (silly though it sound) if i press f1 on my pc, all other pc's get an alert box or something.... (dinners ready).

i have a large house 4 floors...????????????

Hopefull i have exapliained my intentions fully and would apreciate some input... so key logger NO NO NO NO NO NO..

Share this post


Link to post
Share on other sites

I have also been considering making my own LanChat program, though I haven't had time to research if it could be done in AutoIT yet. I think C# might be a better alternative, but I would love to make it in AutoIT. I plan to start looking into it soon once my schedule frees up a bit. I'll watch this thread to see if any good info comes about.

Share this post


Link to post
Share on other sites

A Lan chat can be done in autoit using sockets and TCP...

Look for TCPRecv() and TCPSend() in the help file...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

the bassic nuts and bolts done.....

Same prog on 2 pc's..... both register if the other program is online.???

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chat.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <array.au3>

Global $socket, $contactserver, $buddy
Dim $buddy[2]

$chat_gui = GUICreate("chat", 212, 390, 1126, 146)
$c_list = GUICtrlCreateList("", 8, 128, 193, 253)
$messages = GUICtrlCreateListView("", 8, 8, 193, 113)
GUISetState(@SW_SHOW)



Opt("GUIOnEventMode", 1)


ConsoleWrite(@IPAddress1 & @LF)

$PrivateIP = @IPAddress1
; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================
UDPStartup()
$contactserver = UDPBind($PrivateIP, 65335)

Sleep(2000)
;create multicast address
$splitaddress = StringSplit($PrivateIP, ".")

$changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255"

;send packet   AdlibEnable("cont",5000)
$contactcast = UDPOpen($changeaddress, 65335)

AdlibEnable("check", 5000)

While 1
    $contactdata = UDPRecv($contactserver, 50)
    
    If $contactdata <> "" Then
        $ar = _ArraySearch($buddy, $contactdata)
        If @error Then
            ConsoleWrite("ADDing")
            _ArrayAdd($buddy, $contactdata)
            GUICtrlSetData($c_list, $contactdata)
        EndIf
    EndIf
    Sleep(50)
WEnd


Func check()
    UDPSend($contactcast, $PrivateIP)
    
EndFunc   ;==>check
Edited by Aceguy

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I wrote a very simple TCP chatting program, but it was very specific. You could only talk one with one person and you had to know their IP. I pretty well just wrote it for use at a friend's house so that we didn't have to start MSN just to trade URLs back and forth, but like I said we both had to use IP's.

*Edit: And the point of my mention this was that I think it exemplifies that you can indeed write a "chat" program in AutoIt. Enumerating the other computers on the network is the only thing I'm unsure of how to do.

Edited by RobSaunders

Share this post


Link to post
Share on other sites

progress so far......

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chat.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <array.au3>
#Include <Misc.au3>

Global $contactserver, $buddy, $contactdata,$msgdata
Dim $buddy[1]
Dim $inifile = @MyDocumentsDir & "\chat.ini"


$chat_gui = GUICreate("chat", 212, 390, 1126, 146)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
$c_list = GUICtrlCreateList("", 8, 128, 193, 253)
;$messages = GUICtrlCreateListView("", 8, 8, 193, 113)
$input=GUICtrlCreateInput("",5,5,150,25)
GUICtrlSetOnEvent(-1,"sendit")

GUISetState(@SW_SHOW)

Opt("GUIOnEventMode", 1)

$PrivateIP = @IPAddress1
; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================

$contactserver = UDPBind($PrivateIP, 65335)

Sleep(1000)
;create multicast address
$splitaddress = StringSplit($PrivateIP, ".")
$changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255"

;send packet
$contactcast = UDPOpen($changeaddress, 65335)

AdlibEnable("check", 1000)

While 1
    
    $msgdata = UDPRecv($contactserver, 50)
    Local $match=0
    for $j=1 to UBound($buddy)-1
        if StringInStr($msgdata,$buddy[$j])=1 Then
            $match+=1   
        EndIf
    Next
    if $match=0 and $msgdata<> "" and StringInStr($msgdata,@IPAddress1)=0 then MsgBox(0,"",$msgdata,2)

    if _IsPressed("OD") then sendit()
    Sleep(50)
    if _IsPressed("OD") then sendit()
WEnd


Func check()
    UDPSend($contactcast, $PrivateIP)
    $contactdata = UDPRecv($contactserver, 50)
    If $contactdata <> "" and StringInStr($contactdata,".")=4 and StringInStr($contactdata,".",0,2)=8 Then
        $ar = _ArraySearch($buddy, $contactdata)
        If @error Then
            ConsoleWrite("ADDing")
            _ArrayAdd($buddy, $contactdata)
            GUICtrlSetData($c_list, $contactdata)
            
        EndIf
    EndIf
EndFunc   ;==>check

Func quit()
    UDPCloseSocket($PrivateIP)
    UDPShutdown()
    For $i = 1 To UBound($buddy) - 1
        IniWrite($inifile, "contacts", $i - 1, $buddy[$i])
    Next
    Exit
EndFunc   ;==>quit

Func load()
EndFunc   ;==>load

func sendit()
Consolewrite("SEND"&@LF)
UDPSend($contactcast,GUICtrlRead($input)&" "&@IPAddress1)

EndFunc

everything working with 2 lan pc's.....

not happy with way it sends a message.... (didnt want to use _ispressed )

gonna check with 3 pc's and get back to you.

Share this post


Link to post
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chat.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <array.au3>
#Include <Misc.au3>

Global $contactserver, $buddy, $contactdata,$msgdata
Dim $buddy[1]
Dim $inifile = @MyDocumentsDir & "\chat.ini"


$chat_gui = GUICreate("chat 1.1", 212, 390, 526, 146)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
$c_list = GUICtrlCreateList("", 8, 128, 193, 253)
;$messages = GUICtrlCreateListView("", 8, 8, 193, 113)
$input=GUICtrlCreateInput("",5,5,150,25)
GUICtrlSetOnEvent(-1,"sendit")

GUISetState(@SW_SHOW)

Opt("GUIOnEventMode", 1)

$PrivateIP = @IPAddress1
; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================

$contactserver = UDPBind($PrivateIP, 65335)

Sleep(1000)
;create multicast address
$splitaddress = StringSplit($PrivateIP, ".")
$changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255"

;send packet
$contactcast = UDPOpen($changeaddress, 65335)

AdlibEnable("check", 500)

While 1
    
    $msgdata = UDPRecv($contactserver, 50)
    Local $match=0
    for $j=1 to UBound($buddy)-1
        if StringInStr($msgdata,$buddy[$j])=1 Then
            $match+=1   
        EndIf
    Next
    if $match=0 and $msgdata<> "" and StringInStr($msgdata,@IPAddress1)=0 then 
    $str=StringSplit($msgdata,".")
    if $str[0]<>4  or  StringLen($str[1])<>3 Then
    MsgBox(0,"",$msgdata,2)
EndIf
EndIf
    if _IsPressed("OD") then sendit()
    Sleep(100)
    if _IsPressed("OD") then sendit()
WEnd


Func check()
    UDPSend($contactcast, $PrivateIP)
    sleep(250)
    $contactdata = UDPRecv($contactserver, 50)
    If $contactdata <> "" and StringInStr($contactdata,".")=4 and StringInStr($contactdata,".",0,2)=8 Then
        $ar = _ArraySearch($buddy, $contactdata)
        If @error Then
            ConsoleWrite("ADDing")
            _ArrayAdd($buddy, $contactdata)
            GUICtrlSetData($c_list, $contactdata)
            
        EndIf
    EndIf
EndFunc   ;==>check

Func quit()
    UDPCloseSocket($PrivateIP)
    UDPShutdown()
    For $i = 1 To UBound($buddy) - 1
        IniWrite($inifile, "contacts", $i - 1, $buddy[$i])
    Next
    Exit
EndFunc   ;==>quit

Func load()
EndFunc   ;==>load

func sendit()
Consolewrite("SEND"&@LF)
UDPSend($contactcast,GUICtrlRead($input)&" "&@IPAddress1)

EndFunc

Share this post


Link to post
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chat.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <array.au3>
#Include <Misc.au3>

Global $contactserver, $buddy, $contactdata,$msgdata
Dim $buddy[1]
Dim $inifile = @MyDocumentsDir & "\chat.ini"


$chat_gui = GUICreate("chat 1.1", 212, 390, 526, 146)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
$c_list = GUICtrlCreateList("", 8, 128, 193, 253)
;$messages = GUICtrlCreateListView("", 8, 8, 193, 113)
$input=GUICtrlCreateInput("",5,5,150,25)
GUICtrlSetOnEvent(-1,"sendit")

GUISetState(@SW_SHOW)

Opt("GUIOnEventMode", 1)

$PrivateIP = @IPAddress1
; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================

$contactserver = UDPBind($PrivateIP, 65335)

Sleep(1000)
;create multicast address
$splitaddress = StringSplit($PrivateIP, ".")
$changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255"

;send packet
$contactcast = UDPOpen($changeaddress, 65335)

AdlibEnable("check", 500)

While 1
    
    $msgdata = UDPRecv($contactserver, 50)
    Local $match=0
    for $j=1 to UBound($buddy)-1
        if StringInStr($msgdata,$buddy[$j])=1 Then
            $match+=1   
        EndIf
    Next
    if $match=0 and $msgdata<> "" and StringInStr($msgdata,@IPAddress1)=0 then 
    $str=StringSplit($msgdata,".")
    if $str[0]<>4  or  StringLen($str[1])<>3 Then
    MsgBox(0,"",$msgdata,2)
EndIf
EndIf
    if _IsPressed("OD") then sendit()
    Sleep(100)
    if _IsPressed("OD") then sendit()
WEnd


Func check()
    UDPSend($contactcast, $PrivateIP)
    sleep(250)
    $contactdata = UDPRecv($contactserver, 50)
    If $contactdata <> "" and StringInStr($contactdata,".")=4 and StringInStr($contactdata,".",0,2)=8 Then
        $ar = _ArraySearch($buddy, $contactdata)
        If @error Then
            ConsoleWrite("ADDing")
            _ArrayAdd($buddy, $contactdata)
            GUICtrlSetData($c_list, $contactdata)
            
        EndIf
    EndIf
EndFunc   ;==>check

Func quit()
    UDPCloseSocket($PrivateIP)
    UDPShutdown()
    For $i = 1 To UBound($buddy) - 1
        IniWrite($inifile, "contacts", $i - 1, $buddy[$i])
    Next
    Exit
EndFunc   ;==>quit

Func load()
EndFunc   ;==>load

func sendit()
Consolewrite("SEND"&@LF)
UDPSend($contactcast,GUICtrlRead($input)&" "&@IPAddress1)

EndFunc
Seriously...edit your posts. Stop double and triple posting,it's rude.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

It's rude the same way bumping your post within 24 hours is considered rude. It's meant for nothing but increasing your post count. If it was a good improvement you could edit to something like

...

Edit: This code works better.

some code
See? Was that so hard?

Edit: Typo from bad (old) keyboard.

Edited by dbzfanatic

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

no wasnt hard. just wanted to show the code as it develops......

if i wanted to BUMP my project i will just *BUMP* it.... and not show the 2 DIFFERENT codes.. as in the past people have asked me for the precvious code..

and as for

See? Was that so hard?

Sarcasm is the lowest form of wit.

so if your going to post anymore on this project please help not hinder.

Edited by Aceguy

Share this post


Link to post
Share on other sites

You've been here longer so you should know the forum etiquette, as for your problem I haven't really reviewed the code by if you're still only seeing sent messages on the other scripts I say append the text manually to the sending client.

Share this post


Link to post
Share on other sites

I am working on a server for a MUD that has to send to multiple computers at the same time I have found for a chat program makeing a while loop the doesn't end untill it reaches a certain # my first problem with this was it then shut down the server after that I nested it in another loop and then made the variable equal back to 0 it wored great for sending out messages like chat input to multiple computers instantly. If you have questions about my codeing on this send me a private message.

Share this post


Link to post
Share on other sites

If it is working well, you may want to start a new thread in example scripts.

Mine is a huge work in progress that is still at the very beginning. Once I have most of it done up to some propriatary stuff for my server I plan on posting opensource code for people to run their own mud server off of.

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