blademonkey Posted August 11, 2006 Share Posted August 11, 2006 (edited) Hey all,Well I started out trying to figure out if a Tail app could be done in Autoit, and now ended forking into a wild tangent. here's the original post:http://www.autoitscript.com/forum/index.ph...293&hl=TailNot only does it retain its original purpose, Tails now impersonates a chat system, the catch is that it's all filebased. What that means is the CHAT server is a text file that you point it to. Play around with it, send it to your friends, enjoy.oh, and you can comment on it too, {= )Here's the code:expandcollapse popup#include <File.au3> #include <GUIConstants.au3> #Include <GuiEdit.au3> #Include <array.au3> #Include <Misc.au3> Opt("GUIOnEventMode", 1) Opt('GUICloseOnESC', 1) Dim $aCurrentUSers[1] ; Start GUI Window and Elements creation --> $W_size_w = 450 $Wsize_h = 610 $mainWindow = GUICreate("Tailchat", $W_size_w, $Wsize_h) $notify_on_minimize = 0 ;~ HotKeySet("^{ENTER}","ChatButton") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState(@SW_SHOW) GUICtrlCreateLabel("Please select the file you want to tail", 30, 10) $fileopenButton = GUICtrlCreateButton("Open File", 30, 40, -1, 20) GUICtrlSetOnEvent($fileopenButton, "FileopenButton") $showusers = GUICtrlCreateButton("Show Users", 120, 40, -1, 20) GUICtrlSetOnEvent($showusers, "ShowUsers") $PushButton = GUICtrlCreateCheckbox("Alwaysontop",250 , 560, -1, 20) GUICtrlSetOnEvent($PushButton, "PushButton") $AwayCheck = GUICtrlCreateCheckbox("Away Notification?",250 , 540, -1, 20) GUICtrlSetOnEvent($AwayCheck, "Notification") $ChatButton = GUICtrlCreateButton("Send", 30, 580, -1, 20) GUICtrlSetOnEvent($ChatButton, "ChatButton") $usercheck = GUICtrlCreateCheckbox("Include Username?", 250, 580) GUICtrlSetState($usercheck,1) $editControl = GUICtrlCreateEdit("", 30, 120, $W_size_w - 60, ($Wsize_h - 350), $WS_VSCROLL + $ES_MULTILINE + $ES_AUTOVSCROLL + $ES_READONLY) $chatControl = GUICtrlCreateEdit("", 30, 385, $W_size_w - 60, 80,$ES_WANTRETURN) $InputControl = GUICtrlCreateInput("Choose file", 30, 80, 300, 20,$ES_READONLY) ;~ $linecountcontrol = GUICtrlCreateInput("Lines : ", 360, 80, 75, 20, $ES_READONLY) $initial = 0 $File_opened = 0 $count2 = 0 $scan2 = "" While 1 Tailit() Sleep(100) WEnd Func Tailit() ; Function Environment settings --> $error = 0 $file = ControlGetText("Tailchat", "", $InputControl) $count = _FileCountLines($file) $scan = FileReadLine($file, $count) $file_contents = "" If _IsPressed("0D") Then ChatButton() EndIf For $x = 1 To $count ;~ $scan3 = FileReadLine($file, $x) $display = _isSystemLine($file, $scan3,$x) if $display = 1 Then $file_contents &= $scan3 & @CRLF Elseif $display = 0 Then EndIf Next ; Displays the file contents on first open. if ($File_opened = 1) and ($initial = 0) Then GUICtrlSetData($editControl, $file_contents) ;~ GUICtrlSetData($linecountcontrol, "Lines : " & $count) _GUICtrlEditLineScroll($editControl, 0, $count) $initial = 1 EndIf If $File_opened = 1 Then Select Case $count2 <> $count GUICtrlSetData($editControl, $file_contents) ;~ GUICtrlSetData($linecountcontrol, "Lines : " & $count) If BitAnd(Wingetstate("Tailchat"), 16) then if $notify_on_minimize = 1 Then TrayTip("TailChat", $scan, 5, 1) EndIf EndIf _GUICtrlEditLineScroll($editControl, 0, $count) Case $scan2 <> $scan GUICtrlSetData($editControl, $file_contents) ;~ GUICtrlSetData($linecountcontrol, "Lines : " & $count) _GUICtrlEditLineScroll($editControl, 0, $count) EndSelect EndIf $count2 = $count $scan2 = $scan EndFunc ;==>Tailit Func FileopenButton() if $File_opened = 1 Then _logout() EndIf Global $selected_file = FileOpenDialog("Open", @ScriptDir, "Text Files (*.*)") GUICtrlSetData($InputControl, $selected_file) Global $openfile = FileOpen($selected_file, 0) $File_opened = 1 _login() EndFunc ;==>FileopenButton Func CLOSEClicked() _logout() FileClose($openfile) Exit EndFunc ;==>CLOSEClicked Func ChatButton() $check_status= GUICtrlRead($usercheck) $inputtext = ControlGetText("", "", $chatControl) if $check_status = 1 Then $inputtext = @HOUR & ":" & @MIN &" " &@UserName & ": " & $inputtext EndIf $openfilewrite = FileOpen($selected_file, 1) FileWriteLine($openfilewrite, $inputtext) GUICtrlSetData($chatControl, "") FileClose($openfilewrite) EndFunc ;==>ChatButton func PushButton() if GUICtrlRead($PushButton) = 1 Then WinSetOnTop("Tailchat", "", 1) Elseif GUICtrlRead($PushButton) = 4 Then WinSetOnTop("Tailchat", "", 0) EndIf EndFunc Func _login() $openfilewrite = FileOpen($selected_file, 1) _FileWriteToLine($selected_file,1,"##~~!!" & @UserName &"|" & @hour &@min & "|" & Random(1,20,1),0) FileWriteLine($openfilewrite, @username & " has joined this chat at " &@HOUR & ":" & @MIN) FileClose($openfilewrite) EndFunc Func _logout() $openfilewrite = FileOpen($selected_file, 1) _RemoveOnlineUser() FileWriteLine($openfilewrite, @username & " has left at " & @HOUR & ":" & @MIN) FileClose($openfilewrite) EndFunc Func Notification() if GUICtrlRead($AwayCheck) = 1 Then $notify_on_minimize = 1 Elseif GUICtrlRead($AwayCheck) = 4 Then $notify_on_minimize = 0 EndIf EndFunc Func _isSystemLine($file,$scan3,$x) if StringInStr($scan3,"##~~!!")<>0 Then Return 0 Else return 1 EndIf EndFunc Func _RemoveOnlineUser() Dim $atest, $aloc[1] _filereadtoarray($selected_file,$atest) for $x = 1 to (UBound($atest)-1 ) $isme = stringinstr($atest[$x],"##~~!!" & @UserName) if $isme <> 0 Then _ArrayAdd($aloc, $x) EndIf next for $y = (Ubound($aloc)-1) to 1 step -1 _FileWriteToLine($selected_file,$aloc[$y],"",1) Next EndFunc func ShowUsers() Dim $aEntFile, $afileusers[1] _FileReadToArray($selected_file,$aEntFile) for $x = 1 to UBound($aEntFile)-1 if StringInStr($aEntFile[$x], "##~~!!")<>0 Then $sUser = StringTrimLeft($aEntFile[$x], 6) $aSubUser = Stringsplit($sUser, "|") _arrayadd($afileusers, $aSubUser[1]) EndIf next _ArrayDisplay($afileusers, "Array : aFileUsers " ) EndFuncOh yea, i didnt even give it a description, sorry. I modeled this program after the unix utility Tail, which shows you the last lines of a given text file. Edited August 14, 2006 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
blademonkey Posted August 14, 2006 Author Share Posted August 14, 2006 (edited) 08/14/2006 Major Updates: Forked TailChat from Tail completely per Echobinary's suggestions. **Added Builtin Login Logout Functions **Added System line(used for user tracking) **Added Show user function: currently works when users logs in but doesn't update on log out. **Added Away Notification that only works if user has checked the option and the window is minimized. **Fixed currentuser list to show new list when a user logs out. **Fix non-logout when clicking open while a file is already opened bug. *Set Include Username to default *Reset dimensions. *moved all checkboxes to one area. Planned updates: -Change tab order of elements -Make Enter default send key. -Remember last file opened.Tailchat_2.1.au3 Edited August 14, 2006 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
blademonkey Posted August 14, 2006 Author Share Posted August 14, 2006 Hey all, I'm bumping this to see if there's any interest in this kind of app, and also to get some GUI design feedback. Let me know what you all think of it so far. -Blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
blademonkey Posted August 14, 2006 Author Share Posted August 14, 2006 (edited) Updates *Fixed Enter Key as send Chat. (woot) *Took out the line numbers. (thinking about making it optional, dunno yet though)Tailchat_2.1.au3 Edited August 14, 2006 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
WTS Posted August 14, 2006 Share Posted August 14, 2006 i've never heard of tail gone crazy but it looks good. Link to comment Share on other sites More sharing options...
blademonkey Posted August 15, 2006 Author Share Posted August 15, 2006 i've never heard of tail gone crazy but it looks good. Thanks.I tried changing the titile from Tail Gone Crazy to TailChat, which is now the name of this application, but apparently you cannot change Topic Subject once you have created them.oh well.Let me know what you like, dislike about the app. ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
blademonkey Posted August 15, 2006 Author Share Posted August 15, 2006 (edited) Major Updates 08/15/2006: **Change tab order of elements **Make Enter default send key. **Fixed Open File Dialog Bug when no file was selected. **Fixed Logic when a file/chat is already open. **Replaced Some controls with File Menu and File Menu Items **-->Added FileMenu with Open and Exit items **-->Added View Menu with CurrentUsers item **-->Added Tools Menu with Options item **-->Added Help Menu with About items **Made GUI Resizable **Set Controls to scale based on window resize. **Resized initial window and repositioned controlsTailchat_2.2.au3 Edited August 15, 2006 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
erifash Posted August 15, 2006 Share Posted August 15, 2006 This is pretty cool. I actually made something a little bit like this called FTPChat but I never released it. You could sign up with a username and password and it didn't need to use any TCP functions. Because my FTP server was down I decided to test it by changing all the _FTP*() functions to File*() functions. After a few bugs I finally got it working. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
blademonkey Posted August 15, 2006 Author Share Posted August 15, 2006 This is pretty cool. I actually made something a little bit like this called FTPChat but I never released it. You could sign up with a username and password and it didn't need to use any TCP functions. Because my FTP server was down I decided to test it by changing all the _FTP*() functions to File*() functions. After a few bugs I finally got it working. Cool! got any tips for this newbster? ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
erifash Posted August 15, 2006 Share Posted August 15, 2006 FTPChat could only send messages to a user if you knew their username, much like email. I could modify it to be like a chat room with multiple rooms per server but then it would have pretty much the same functionality as AU3Chat (in my signature). You should check out AU3Chat, it might give you some ideas! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
blademonkey Posted August 16, 2006 Author Share Posted August 16, 2006 will do thanks. right now i have to get back to my term paper. ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
blademonkey Posted August 17, 2006 Author Share Posted August 17, 2006 (edited) Version 2.2.1 Major Updates: **Fixed Menuitem issues with Tools **add submenuitems ** Cleaned up some functions Planned improvments: Configuration file.Tailchat_2.2.1.au3 Edited August 17, 2006 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
blademonkey Posted August 25, 2006 Author Share Posted August 25, 2006 Current Code, no major updates: expandcollapse popup#include <File.au3> #include <GUIConstants.au3> #Include <GuiEdit.au3> #Include <array.au3> #Include <Misc.au3> Opt("GUIOnEventMode", 1) Opt('GUICloseOnESC', 1) $selected_file = "" $openfile = "" $notify_on_minimize = 0 $EnableChatHistory = 1 $initial = 0 $File_opened = 0 $count2 = 0 $scan2 = "" Dim $aCurrentUSers[1] ; Start GUI Window and Elements creation --> $W_size_w = 320 $Wsize_h = 400 $mainWindow = GUICreate("Tailchat", $W_size_w, $Wsize_h, (@DesktopWidth / 2) - ($W_size_w / 2) , (@DesktopHeight / 2) - ($Wsize_h / 2), BitOR($WS_SIZEBOX, $WS_SYSMENU, $WS_MINIMIZEBOX)) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $exitButton = GUICtrlCreateButton("Exit", $W_size_w - 90, $Wsize_h - 68, 70, 30) GUICtrlSetOnEvent($exitButton, "CLOSEclicked") $filemenu = GUICtrlCreateMenu("&File") $fileitem = GUICtrlCreateMenuitem("Open", $filemenu) GUICtrlSetOnEvent($fileitem, "FileopenButton") $separator1 = GUICtrlCreateMenuitem("", $filemenu, 2) $exititem = GUICtrlCreateMenuitem("Exit", $filemenu) GUICtrlSetOnEvent($exititem, "CLOSEClicked") $Viewmenu = GUICtrlCreateMenu("&View") $currentusersitem = GUICtrlCreateMenuitem("Current_Users", $Viewmenu) GUICtrlSetOnEvent($currentusersitem, "ShowUsers") $Toolsmenu = GUICtrlCreateMenu("&Tools") $optionsitem = GUICtrlCreateMenu("Options", $Toolsmenu) $AwayCheck = GUICtrlCreateMenuitem("Away Notification", $optionsitem) GUICtrlSetOnEvent($AwayCheck, "Notification") $PushButton = GUICtrlCreateMenuitem("Always on top", $optionsitem) GUICtrlSetOnEvent($PushButton, "PushButton") $configcheck = GUICtrlCreateMenuitem("Remember Chatroom", $optionsitem) GUICtrlSetOnEvent($configcheck, "ConfigCheck") GUICtrlSetState($configcheck, $GUI_checked) $helpmenu = GUICtrlCreateMenu("&Help") $aboutitem = GUICtrlCreateMenuitem("About TailChat", $helpmenu) GUICtrlSetOnEvent($aboutitem, "About") $editControl = GUICtrlCreateEdit("", 10, 10, 300, $Wsize_h - 200, $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_READONLY) $chatControl = GUICtrlCreateEdit("", 10, $Wsize_h - 180, 300, 80, $ES_WANTRETURN) $ChatButton = GUICtrlCreateButton("Send", 10, $Wsize_h - 90, 70, -1) GUICtrlSetOnEvent($ChatButton, "ChatButton") $InputControl = GUICtrlCreateInput("", 0, 20, $W_size_w, 20, $ES_READONLY) GUICtrlSetState(-1, $gui_hide) If (WinActive("Tailchat") = 1) and (_IsPressed("0D")) Then ChatButton() EndIf While 1 Tailit() Sleep(50) WEnd Func Tailit() $error = 0 $file = ControlGetText("Tailchat", "", $InputControl) $count = _FileCountLines($file) $scan = FileReadLine($file, $count) $file_contents = "" For $x = 1 To $count $scan3 = FileReadLine($file, $x) $display = _isSystemLine($file, $scan3, $x) If $display = 1 Then $file_contents &= $scan3 & @CRLF ElseIf $display = 0 Then EndIf Next if ($File_opened = 1) and ($initial = 0) Then GUICtrlSetData($editControl, $file_contents) _GUICtrlEditLineScroll($editControl, 0, $count) $initial = 1 EndIf If $File_opened = 1 Then Select Case $count2 <> $count GUICtrlSetData($editControl, $file_contents) If BitAND(WinGetState("Tailchat"), 16) Then If $notify_on_minimize = 1 Then TrayTip("TailChat", $scan, 5, 1) EndIf EndIf _GUICtrlEditLineScroll($editControl, 0, $count) Case $scan2 <> $scan GUICtrlSetData($editControl, $file_contents) _GUICtrlEditLineScroll($editControl, 0, $count) EndSelect EndIf $count2 = $count $scan2 = $scan EndFunc ;==>Tailit Func FileopenButton() $nologin = 0 $old_file = "" If $File_opened = 1 Then $old_file = $selected_file EndIf Global $selected_file = FileOpenDialog("Open", @ScriptDir, "Text Files (*.*)") If $selected_file = "" Then $selected_file = $old_file $nologin = 1 Else _logout() EndIf GUICtrlSetData($InputControl, $selected_file) Global $openfile = FileOpen($selected_file, 0) $error = @error $File_opened = 1 If $nologin <> 1 Then _login() EndIf EndFunc ;==>FileopenButton Func CLOSEClicked() If @GUI_WinHandle == $mainWindow Then _logout() FileClose($openfile) Exit Else GUIDelete(@GUI_WinHandle) EndIf EndFunc ;==>CLOSEClicked Func ChatButton() $inputtext = ControlGetText("", "", $chatControl) If $File_opened = 1 Then $inputtext = @HOUR & ":" & @MIN & " " & @UserName & ": " & $inputtext $openfilewrite = FileOpen($selected_file, 1) FileWriteLine($openfilewrite, $inputtext) GUICtrlSetData($chatControl, "") FileClose($openfilewrite) Else MsgBox(0, "No chat", "No chat has been logged into, nothing to send") GUICtrlSetData($chatControl, "") EndIf EndFunc ;==>ChatButton Func PushButton() Local $ischecked = _togglecheck($PushButton) If $ischecked = 1 Then WinSetOnTop("Tailchat", "", 1) ElseIf $ischecked = 0 Then WinSetOnTop("Tailchat", "", 0) EndIf EndFunc ;==>PushButton Func _login() $openfilewrite = FileOpen($selected_file, 1) _FileWriteToLine($selected_file, 1, "##~~!!" & @UserName & "|" & @HOUR & @MIN & "|" & Random(1, 20, 1), 0) FileWriteLine($openfilewrite, "--> " & @UserName & " has joined this chat at " & @HOUR & ":" & @MIN) FileClose($openfilewrite) EndFunc ;==>_login Func _logout() $openfilewrite = FileOpen($selected_file, 1) _RemoveOnlineUser() FileWriteLine($openfilewrite, "--> " & @UserName & " has left at " & @HOUR & ":" & @MIN) FileClose($openfilewrite) EndFunc ;==>_logout Func Notification() Local $ischecked = _togglecheck($AwayCheck) If $ischecked = 1 Then $notify_on_minimize = 1 ElseIf $ischecked = 0 Then $notify_on_minimize = 0 EndIf EndFunc ;==>Notification Func _isSystemLine($file, $scan3, $x) If StringInStr($scan3, "##~~!!") <> 0 Then Return 0 Else Return 1 EndIf EndFunc ;==>_isSystemLine Func _RemoveOnlineUser() Dim $atest, $aloc[1] _FileReadToArray($selected_file, $atest) For $x = 1 to (UBound($atest) - 1) $isme = StringInStr($atest[$x], "##~~!!" & @UserName) If $isme <> 0 Then _ArrayAdd($aloc, $x) EndIf Next For $y = (UBound($aloc) - 1) To 1 Step - 1 _FileWriteToLine($selected_file, $aloc[$y], "", 1) Next EndFunc ;==>_RemoveOnlineUser Func ShowUsers() If $File_opened = 1 Then Dim $aEntFile, $afileusers[1] _FileReadToArray($selected_file, $aEntFile) For $x = 1 To UBound($aEntFile) - 1 If StringInStr($aEntFile[$x], "##~~!!") <> 0 Then $sUser = StringTrimLeft($aEntFile[$x], 6) $aSubUser = StringSplit($sUser, "|") _ArrayAdd($afileusers, $aSubUser[1]) EndIf Next _ArrayDisplay($afileusers, "Array : aFileUsers ") Else MsgBox(0, "No Chat opened", "There are no users to display since you are not currently logged into a chat") GUICtrlSetData($chatControl, "") EndIf EndFunc ;==>ShowUsers Func About() MsgBox(64, "About Tail Chat 2.2.1", "Tailchat was written in AutoIT V3.2" & @LF & @LF & "Written by : Blademonkey") EndFunc ;==>About Func _togglecheck($guihandle) If GUICtrlRead($guihandle) = 68 Then GUICtrlSetState($guihandle, $GUI_checked) Return 1 Else GUICtrlSetState($guihandle, $GUI_unchecked) Return 0 EndIf EndFunc ;==>_togglecheck Func ConfigCheck() Local $ischecked = _togglecheck($configcheck) If $ischecked = 1 Then $EnableChatHistory = 1 ElseIf $ischecked = 0 Then $EnableChatHistory = 0 EndIf EndFunc ;==>ConfigCheck Func ConfigfileSet() $inifile = "c:\tailchat.ini" If FileExists($inifile) = 0 Then IniWrite($inifile, "Session", "LastChat", $selected_file) Else IniRead($inifile, "Session", "EnableLastChat", "1") EndIf EndFunc ;==>ConfigfileSet ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
themax90 Posted August 25, 2006 Share Posted August 25, 2006 You might want to look into TCP. I tried this before in MChat and it didn't work well. Otherwse good job. Link to comment Share on other sites More sharing options...
blademonkey Posted August 25, 2006 Author Share Posted August 25, 2006 You might want to look into TCP. I tried this before in MChat and it didn't work well.Otherwse good job.First of all, thanks for the good word, that means alot to me coming from you.I didnt use TCP functions because chat applications using specific ports on our lan are not allowed (I work for the Gov), however this application was able to pass security criterias.{= DEventually i would like to create a seperate interface module that will give the user a choice between TCP or File based communications.-B ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now