DarkAngel Posted December 13, 2011 Posted December 13, 2011 (edited) Trying to achieve something like a collaborative editing tool . Something like ACE#. But mine isnt anywhere near i know. This is a pretty lame effort though . My sems are on and this is all i could think of now at this moment . Haven't tested it properly . But somehow it acts wierdly . Can't think of anything that might put the text in the typing area of the other users too . I tried updating the typing area every 1 sec or so .. but its sick cuz the cursor moves to the end of teh line everytime its updated .. I need some help on this .. Is this a good approach of doing what i want to achieve ? If not i want some ideas soon . And i thing theres some problem with the tcp buffer . cuz everytime i update the main screen, the previous texts arrives and then vanishes suddenly. do i need to reduce the size of the buffer ? please help.Server :expandcollapse popup#Include <ButtonConstants.Au3> #Include <EditConstants.Au3> #Include <GUIConstantsEx.Au3> #Include <StaticConstants.Au3> #Include <WindowsConstants.Au3> #Include <File.Au3> #Include <String.Au3> #include <Date.au3> Opt ('GUIOnEventMode', 1) Global $Max = 10, $Socket[$Max + 1], $User[$Max + 1], $Server = -1, $Admin = -1, $Admin_Pw = 'password', $Connected = 0 For $A = 1 To $Max $Socket[$A] = -1 $User[$A] = -1 Next $GUI = GUICreate ('Server Settings', 180, 100, -1, -1, -1, 128) GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateGroup ('', 5, 0, 170, 94) $IP = GUICtrlCreateInput (@IpAddress1, 12, 13, 100, 21, 1) $Port = GUICtrlCreateInput (50, 117, 13, 50, 21, 1) $Start = GUICtrlCreateButton ('Start', 12, 39, 46, 20, $WS_GROUP) GUICtrlSetOnEvent ($Start, '_Start') $Stop = GUICtrlCreateButton ('Stop', 63, 39, 49, 20, $WS_GROUP) GUICtrlSetState ($Stop, $GUI_DISABLE) GUICtrlSetOnEvent ($Stop, '_Stop') $Pw = GUICtrlCreateInput ($Admin_Pw, 12, 65, 100, 21, BitOr (1, $ES_PASSWORD)) $Set = GUICtrlCreateButton ('Set Pw', 118, 66, 49, 20, $WS_GROUP) GUICtrlSetOnEvent ($Set, '_Set') GUISetState (@SW_SHOW) WinSetOnTop ($GUI, '', 1) While 1 If $Server <> -1 Then If $Connected < $Max Then $Accept = TcpAccept ($Server) If $Accept <> -1 Then If _IsBanned (_SocketGetIP ($Accept)) = 0 Then $Open = _Open () $Timer = TimerInit () Do Sleep (15) $Recv = TcpRecv ($Accept, 1000000) Until $Recv <> '' Or TimerDiff ($Timer) >= 500 If $Recv <> '' Then If _Check ($Recv) = 1 Then $User[$Open] = $Recv $Socket[$Open] = $Accept $Connected = $Connected + 1 _SendAll ($User[$Open] & ' has connected.') Else TcpSend ($Accept, 'Error:Username.Exists;') Sleep (250) TcpCloseSocket ($Accept) EndIf Else TcpCloseSocket ($Accept) EndIf Else TcpSend ($Accept, 'Error:IP.Banned;') Sleep (250) TcpCloseSocket ($Accept) EndIf EndIf ElseIf $Connected = $Max Then $Accept = TcpAccept ($Server) If $Accept <> -1 Then $Timer = TimerInit () Do Sleep (15) $Recv = TcpRecv ($Accept, 1000000) Until $Recv <> '' Or TimerDiff ($Timer) >= 500 Sleep (250) TcpSend ($Accept, 'Error:Max.Connections;') TcpCloseSocket ($Accept) EndIf EndIf For $A = 1 To $Max If $Socket[$A] <> -1 And $User[$A] <> -1 Then $Recv = TcpRecv ($Socket[$A], 1000000) If @Error Then _Disconnect ($A) If $Recv <> '' Then _SendAll ($Recv) EndIf EndIf Next EndIf WEnd Func _IsBanned ($Data) For $A = 1 To _FileCountLines ('Banned.txt') If FileReadLine ('Banned.txt', $A) = $Data Then Return 1 Next Return 0 EndFunc Func _SocketGetIP ($Data) Local $Struct, $Return $Struct = DllStructCreate ('short;ushort;uint;char[8]') $Return = DllCall ('Ws2_32.dll','int','getpeername','int', $Data, 'ptr', DllStructGetPtr ($Struct), 'int*', DllStructGetSize($Struct)) If @Error Or $Return[0] <> 0 Then Return 0 $Return = DllCall ('Ws2_32.dll','str','inet_ntoa','int', DllStructGetData ($Struct, 3)) If @Error Then Return 0 $Struct = 0 Return $Return[0] EndFunc Func _UserGetSocket ($Data) For $A = 1 To $Max If $User[$A] = $Data Then Return $A Next Return -1 EndFunc Func _Check ($Data) For $A = 1 To $Max If $User[$A] = $Data Then Return 0 Next Return 1 EndFunc Func _Disconnect ($ID) _SendAll ($User[$ID] & ' has disconnected.') If $User[$ID] = $Admin Then $Admin = -1 TcpCloseSocket ($Socket[$ID]) $Socket[$ID] = -1 $User[$ID] = -1 $Connected = $Connected - 1 EndFunc Func _SendAll ($Msg) For $A = 1 To $Max If $Socket[$A] <> -1 And $User[$A] <> -1 Then TcpSend ($Socket[$A], $Msg) EndIf Next EndFunc Func _Open () For $A = 1 To $Max If $Socket[$A] = -1 And $User[$A] = -1 Then Return $A Next EndFunc Func _Start () If GUICtrlRead ($IP) == '' Or GUICtrlRead ($Port) == '' Then Return @Error TcpStartUp () $Server = TcpListen (GUICtrlRead ($IP), GUICtrlRead ($Port)) If $Server = -1 Or @Error Then WinSetOnTop ($GUI, '', 0) Sleep (100) MsgBox (16, 'Fatal Error','Unable to start the server, change your settings and try again.') WinSetOnTop ($GUI, '', 1) TcpCloseSocket ($Server) _Reset () Else GUICtrlSetState ($IP, $GUI_DISABLE) GUICtrlSetState ($Port, $GUI_DISABLE) GUICtrlSetState ($Start, $GUI_DISABLE) GUICtrlSetState ($Stop, $GUI_ENABLE) EndIf EndFunc Func _Stop () TcpCloseSocket ($Server) $Server = -1 $Connected = 0 $Admin = -1 _Reset () EndFunc Func _Set () $Admin_Pw = GUICtrlRead ($Pw) EndFunc Func _Reset () For $A = 1 To $Max If $Socket[$A] <> -1 Or $User[$A] <> -1 Then TcpCloseSocket ($Socket[$A]) $Socket[$A] = -1 $User[$A] = -1 EndIf Next TcpShutDown () GUICtrlSetState ($IP, $GUI_ENABLE) GUICtrlSetState ($Port, $GUI_ENABLE) GUICtrlSetState ($Start, $GUI_ENABLE) GUICtrlSetState ($Stop, $GUI_DISABLE) EndFunc Func _Exit () Exit EndFuncClient :expandcollapse popup#NoTrayIcon #include <ButtonConstants.Au3> #include <EditConstants.Au3> #include <GUIConstantsEx.Au3> #include <StaticConstants.Au3> #include <WindowsConstants.Au3> #include <GUIEdit.Au3> #include <Misc.Au3> #include <WinAPI.au3> Opt('GUIOnEventMode', 1) TCPStartup() Global $Server = -1, $Logs $Settings = GUICreate('Connection Settings', 180, 100, -1, -1, -1, 128) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateGroup('', 5, 0, 170, 94) $IP = GUICtrlCreateInput(IniRead('Settings.ini', 'Settings', 'IP', @IPAddress1), 12, 13, 100, 21, 1) $Port = GUICtrlCreateInput(IniRead('Settings.ini', 'Settings', 'Port', 50), 117, 13, 50, 21, 1) $User = GUICtrlCreateInput(IniRead('Settings.ini', 'Settings', 'User', 'John'), 12, 39, 156, 21, 1) $Connect = GUICtrlCreateButton('Connect', 12, 66, 100, 20, $WS_GROUP) GUICtrlSetOnEvent($Connect, '_Start') $Exit = GUICtrlCreateButton('Exit', 117, 66, 50, 20, $WS_GROUP) GUICtrlSetOnEvent($Exit, '_Exit') GUISetState(@SW_SHOW) WinSetOnTop($Settings, '', 1) $GUI = GUICreate('Test', 375, 275, -1, -1, -1, 128) GUISetOnEvent($GUI_EVENT_CLOSE, '_Toggle') $History = GUICtrlCreateEdit('', 0, 1, 375, 203, 2103360 + $ES_MULTILINE) GUICtrlSetFont($History, 10, -1, -1, 'Lucida Sans Unicode') GUICtrlSetBkColor($History, 0x83B4FC) GUICtrlSetColor($History, 0xFFFFFF) $Send = GUICtrlCreateEdit('', 0, 205, 375, 70, 2101248) GUICtrlSetFont($Send, 10, -1, -1, 'Lucida Sans Unicode') GUICtrlSetColor($Send, 0x83B4FC) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;AdlibRegister("refresh",1000) ;Func refresh() ; GUICtrlSetData($Send,"") ; $bEditedx=(GUICtrlRead($History)) ; GUICtrlSetData($Send,$bEditedx) ;EndFunc Func WM_COMMAND($hWinHandle, $iMsg, $wParam, $lParam) If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $Send Then ;tooltip("typing") $bEdited = (GUICtrlRead($Send)) TCPSend($Server, $bEdited) EndIf If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $History Then $bEditedx = (GUICtrlRead($History)) GUICtrlSetData($Send, $bEditedx) EndIf EndFunc ;==>WM_COMMAND While 1 Sleep(15) If $Server <> -1 Then $Recv = TCPRecv($Server, 1000000) If @error Then GUISetState(@SW_HIDE, $GUI) ;WinSetOnTop ($GUI, '', 0) Sleep(100) MsgBox(48, 'Server Notice', 'You have been disconnected from the server.') _Disconnect() EndIf If $Recv = 'Error:Username.Exists;' Then GUISetState(@SW_HIDE, $GUI) WinSetOnTop($GUI, '', 0) Sleep(100) MsgBox(48, 'Server Notice', 'Your username is already in use, please change it and try again.') _Disconnect() ElseIf $Recv = 'Error:Max.Connections;' Then GUISetState(@SW_HIDE, $GUI) WinSetOnTop($GUI, '', 0) Sleep(100) MsgBox(48, 'Server Notice', 'Max amount of connections reached, try again later.') _Disconnect() ElseIf $Recv = 'Error:IP.Banned;' Then GUISetState(@SW_HIDE, $GUI) WinSetOnTop($GUI, '', 0) Sleep(100) MsgBox(48, 'Server Notice', 'Your IP address has been banned.') _Disconnect() ElseIf StringLeft($Recv, 4) = '.log' Then FileWriteLine('Logged.txt', StringTrimLeft($Recv, 5)) ElseIf $Recv <> '' Then _Log($Recv) EndIf EndIf WEnd Func _Disconnect() GUICtrlSetData($History, '') TCPCloseSocket($Server) $Server = -1 GUISetState(@SW_HIDE, $GUI) WinSetOnTop($GUI, '', 0) GUISetState(@SW_SHOW, $Settings) WinSetOnTop($Settings, '', 1) EndFunc ;==>_Disconnect Func _Toggle() GUICtrlSetData($History, '') TCPCloseSocket($Server) $Server = -1 GUISetState(@SW_HIDE, $GUI) WinSetOnTop($GUI, '', 0) GUISetState(@SW_SHOW, $Settings) WinSetOnTop($Settings, '', 1) EndFunc ;==>_Toggle Func _Log($Data) ;GUICtrlSetData ($History, GUICtrlRead ($History) & $Data & @CRLF & @CRLF) ;_WinAPI_SetFocus($History) GUICtrlSetData($History, $Data) ;GUICtrlSetData($Send,GUICtrlRead($History)) _GUICtrlEdit_LineScroll($History, 0, _GUICtrlEdit_GetLineCount($History) - 1) EndFunc ;==>_Log Func _Start() If GUICtrlRead($User) == '' Or GUICtrlRead($IP) == '' Or GUICtrlRead($Port) == '' Then Return @error $Server = TCPConnect(GUICtrlRead($IP), GUICtrlRead($Port)) If $Server = -1 Or @error Then WinSetOnTop($Settings, '', 0) Sleep(100) MsgBox(16, 'Fatal Error', 'Unable to connect to the server, change your settings and try again.') WinSetOnTop($Settings, '', 1) Return @error EndIf Sleep(150) TCPSend($Server, GUICtrlRead($User)) GUISetState(@SW_HIDE, $Settings) WinSetOnTop($Settings, '', 0) GUISetState(@SW_SHOW, $GUI) WinSetOnTop($GUI, '', 1) EndFunc ;==>_Start Func _Exit() IniWrite('Settings.ini', 'Settings', 'IP', GUICtrlRead($IP)) IniWrite('Settings.ini', 'Settings', 'Port', GUICtrlRead($Port)) IniWrite('Settings.ini', 'Settings', 'User', GUICtrlRead($User)) Exit EndFunc ;==>_Exit Edited December 13, 2011 by DarkAngel
DarkAngel Posted December 13, 2011 Author Posted December 13, 2011 no one ? Sorry for bumping though ... i really need some help or ideas regarding this one !
Moderators Melba23 Posted December 13, 2011 Moderators Posted December 13, 2011 DarkAngel,Sorry for bumpingPlease do not bump within 24hrs. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
DarkAngel Posted December 15, 2011 Author Posted December 15, 2011 IS there any way to detect change in an edit box if it doesn't have focus at that time ?
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