AlmarM Posted November 13, 2009 Share Posted November 13, 2009 Hiya, It turned out that my last project became a chat-program, and now im having some trouble with the spam filter. Each time you send the $SpamFilter gets += 1. When the $SpamFilter becomes 5 in 2 seconds, the gui gets disabled and you have been "muted" for then 10 seconds. The problem im having now is that I dont know how to set the $SpamFilter to 0 each 2 seconds and my "ResetStatus" function isnt working. Heres the code: expandcollapse popup#include "TCP.au3" Global $hClient = _TCP_Client_Create("5.124.35.0", 1337) Global $Name = StringLower(@ComputerName) Global $Chat, $SpamFilter = 0, $Timer = 0 _TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received") _TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected") $GUI = GUICreate("Example Chat", 520, 380) $Chat = GUICtrlCreateEdit("", 10, 10, 500, 300) $Text = GUICtrlCreateInput("", 10, 320, 450, 20) $Send = GUICtrlCreateButton("Send", 465, 317, 47) $Exit = GUICtrlCreateButton("", -100, -100) $Action = GUICtrlCreateCombo("greet", 10, 350, 70) $Action_Name = GUICtrlCreateInput("<User>", 90, 350, 100, 21) $Action_Send = GUICtrlCreateButton("Send", 195, 349, 50, 23) Dim $AccelKeys[2][2] = [["{ENTER}", $Send], ["{ESC}", $Exit]] GUISetAccelerators($AccelKeys) GUISetState() GUISetBkColor(0x000000) GUICtrlSetFont($Chat, 8) GUICtrlSetBkColor($Chat, 0x6a6a6a) GUICtrlSetBkColor($Text, 0x6a6a6a) GUICtrlSetColor($Chat, 0x00ff00) GUICtrlSetColor($Text, 0x00ff00) GUICtrlSetData($Action, "wave|slap|kick|spank|kiss|own|swaffel|9mm|care") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit Case $Send $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC _TCP_Send($hClient, "[" & $TimeStamp & "] " & $Name & " says: " & GUICtrlRead($Text)) GUICtrlSetData($Text, "") $SpamFilter += 1 Case $Action_Send $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC $___Get = _Get_Action(GUICtrlRead($Action), GUICtrlRead($Action_Name)) _TCP_Send($hClient, "[" & $TimeStamp & "] " & $___Get) $SpamFilter += 1 Case $Exit Exit EndSwitch ___CheckFilter() WEnd Func Received($hSocket, $sReceived, $iError) If Not WinActive("Example Chat") Then WinFlash("Example Chat") GUICtrlSetData($Chat, $sReceived & @CRLF, "|") SoundPlay(@ScriptDir & "\sounds\beep2.wav") Else GUICtrlSetData($Chat, $sReceived & @CRLF, "|") SoundPlay(@ScriptDir & "\sounds\beep1.wav") EndIf EndFunc Func _Get_Action($__Action, $__Name) Switch $__Action Case "greet" Return $Name & " greets " & $__Name & "." Case "wave" Return $Name & " waves to " & $__Name & "." Case "slap" Return $Name & " slaps " & $__Name & " in the face!" Case "kick" Return $Name & " kicks " & $__Name & " into the hospital." Case "spank" Return $Name & " spanks " & $__Name & " on the ass!" Case "kiss" Return $Name & " gives " & $__Name & " a kiss on the cheek." Case "own" Return $Name & " owns the freaking hell out of " & $__Name & "." Case "swaffel" Return $Name & " swaffels " & $__Name & " to death." Case "9mm" Return $Name & " 9mm'ed " & $__Name & "." Case "care" Return $Name & " gives " & $__Name & " the careface." EndSwitch EndFunc Func ResetFilter() $SpamFilter = 0 EndFunc Func ___CheckFilter() If $SpamFilter >= 5 Then GUISetState(@SW_DISABLE, $GUI) HotKeySet("{ENTER}", "Protect") GUICtrlSetData($Text, "Spam detected! You have been muted for 10 seconds.") AdlibEnable("ResetStatus", 100) EndIf EndFunc Func ResetStatus() AdlibEnable() GUISetState(@SW_ENABLE, $GUI) GUICtrlSetData($Text, "") HotKeySet("{ENTER}") ResetFilter() EndFunc Func Protect() EndFunc ;Func RandomName($nChar) ; $___Array = StringSplit("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789", "") ; ; $___Name = "" ; For $X = 1 to $nChar ; $___Name &= $___Array[Random (1, $___Array[0], 1)] ; Next ; Return $___Name ;EndFunc Hope somebody could help me ^^, Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2009 Moderators Share Posted November 13, 2009 AlmarM,I have produced this single function which I think does what you want in place of your CheckFilter, ResetFilter and ResetStatus functions. Just alter the Sleep in the <<<<<<<<<<< line to see the effect of getting the count up within/over 2 secs. The $Count label is just for testing, of course. expandcollapse popup#include <GUIConstantsEx.au3> Global $iBegin, $SpamFilter = 0 $GUI = GUICreate("Test", 500, 500) $Text = GUICtrlCreateLabel("", 10, 10, 400, 20) $Count = GUICtrlCreateLabel("", 10, 50, 50, 20) GUISetState() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ;... Sleep(100) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 100 = Spam, 500 = OK ; Increase filter $SpamFilter += 1 GUICtrlSetData($Count, $SpamFilter) ; If first after reset then set timer If $SpamFilter = 1 Then $iBegin = TimerInit() ;... If $SpamFilter = 5 Then ___CheckFilter() WEnd Func ___CheckFilter() ; Check if 2 secs have elapsed If TimerDiff($iBegin) < 2000 Then ; 5 hits in less than 2 secs so disable GUI GUISetState(@SW_DISABLE, $GUI) ;HotKeySet("{ENTER}", "Protect") GUICtrlSetData($Text, "Spam detected! You have been muted for 10 seconds.") ; Wait the 10 secs $iBegin = TimerInit() While TimerDiff($iBegin) < 10000 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ; or Sleep(10) WEnd ; Reset GUI GUISetState(@SW_ENABLE, $GUI) GUICtrlSetData($Text, "") ;HotKeySet("{ENTER}") EndIf ; Either 5 hits in more than 2 secs or we have waited 10 secs ; Reset filter and timer $SpamFilter = 0 $iBegin = TimerInit() EndFunc ;==>___CheckFilterIf this is not what you were after, please ask again. 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 Link to comment Share on other sites More sharing options...
AlmarM Posted November 13, 2009 Author Share Posted November 13, 2009 (edited) If this is not what you were after, please ask again. Thats pretty nice! But as you already saw, its a chat program, can I just add a sleep into a chat program? Doens't that makes it laggy? AlmarM EDIT: I used the While TimerDiff() and it works now. Mayby not as simple as your example, but it works. Thanks! expandcollapse popup#include "TCP.au3" AdlibEnable("ResetFilter", 2000) Global $hClient = _TCP_Client_Create("5.124.35.0", 1337) Global $Name = StringLower(@ComputerName) Global $Chat, $SpamFilter = 0, $Timer = 0 _TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received") _TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected") $GUI = GUICreate("ZFire - Chat", 520, 380) $Chat = GUICtrlCreateEdit("", 10, 10, 500, 300) $Text = GUICtrlCreateInput("", 10, 320, 450, 20) $Send = GUICtrlCreateButton("Send", 465, 317, 47) $Exit = GUICtrlCreateButton("", -100, -100) $Action = GUICtrlCreateCombo("greet", 10, 350, 70) $Action_Name = GUICtrlCreateInput("<User>", 90, 350, 100, 21) $Action_Send = GUICtrlCreateButton("Send", 195, 349, 50, 23) Dim $AccelKeys[2][2] = [["{ENTER}", $Send], ["{ESC}", $Exit]] GUISetAccelerators($AccelKeys) GUISetState() GUISetBkColor(0x000000) GUICtrlSetFont($Chat, 8) GUICtrlSetBkColor($Chat, 0x6a6a6a) GUICtrlSetBkColor($Text, 0x6a6a6a) GUICtrlSetColor($Chat, 0x00ff00) GUICtrlSetColor($Text, 0x00ff00) GUICtrlSetData($Action, "wave|slap|kick|spank|kiss|own|swaffel|9mm|care") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC _TCP_Send($hClient, "[" & $TimeStamp & "] " & $Name & " has disconnected from the server.") Exit Case $Send $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC _TCP_Send($hClient, "[" & $TimeStamp & "] " & $Name & " says: " & GUICtrlRead($Text)) GUICtrlSetData($Text, "") SoundPlay(@ScriptDir & "\sounds\send.wav") $SpamFilter += 1 Case $Action_Send $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC $___Get = _Get_Action(GUICtrlRead($Action), GUICtrlRead($Action_Name)) _TCP_Send($hClient, "[" & $TimeStamp & "] " & $___Get) SoundPlay(@ScriptDir & "\sounds\send.wav") $SpamFilter += 1 Case $Exit $TimeStamp = @HOUR & ":" & @MIN & ":" & @SEC _TCP_Send($hClient, "[" & $TimeStamp & "] " & $Name & " has disconnected from the server.") Exit EndSwitch ___CheckFilter() WEnd Func Received($hSocket, $sReceived, $iError) If Not WinActive("ZFire - Chat") Then WinFlash("ZFire - Chat") GUICtrlSetData($Chat, $sReceived & @CRLF, "|") SoundPlay(@ScriptDir & "\sounds\recv2.wav") Else GUICtrlSetData($Chat, $sReceived & @CRLF, "|") SoundPlay(@ScriptDir & "\sounds\recv.wav") EndIf EndFunc Func _Get_Action($__Action, $__Name) Switch $__Action Case "greet" Return $Name & " greets " & $__Name & "." Case "wave" Return $Name & " waves to " & $__Name & "." Case "slap" Return $Name & " slaps " & $__Name & " in the face!" Case "kick" Return $Name & " kicks " & $__Name & " into the hospital." Case "spank" Return $Name & " spanks " & $__Name & " on the ass!" Case "kiss" Return $Name & " gives " & $__Name & " a kiss on the cheek." Case "own" Return $Name & " owns the freaking hell out of " & $__Name & "." Case "swaffel" Return $Name & " swaffels " & $__Name & " to death." Case "9mm" Return $Name & " 9mm'ed " & $__Name & "." Case "care" Return $Name & " gives " & $__Name & " the careface." EndSwitch EndFunc Func ResetFilter() $SpamFilter = 0 EndFunc Func ___CheckFilter() If $SpamFilter >= 5 Then GUISetState(@SW_DISABLE, $GUI) HotKeySet("{ENTER}", "Protect") GUICtrlSetData($Text, "Spam detected! You have been muted for 10 seconds.") $_Start = TimerInit() Do Until TimerDiff($_Start) > 10000 ResetStatus() EndIf EndFunc Func ResetStatus() GUISetState(@SW_ENABLE, $GUI) GUICtrlSetData($Text, "") HotKeySet("{ENTER}") ResetFilter() EndFunc Func Protect() EndFunc ;Func RandomName($nChar) ; $___Array = StringSplit("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789", "") ; ; $___Name = "" ; For $X = 1 to $nChar ; $___Name &= $___Array[Random (1, $___Array[0], 1)] ; Next ; Return $___Name ;EndFunc Edited November 13, 2009 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2009 Moderators Share Posted November 13, 2009 AlmarM,The Sleep is just there to show you the function working - by adjusting the values as I suggested you can simulate 5 Sends in more/less than 2 secs. In your script, $SpamFilter is only incremented when you click the $Send and $Action_Send buttons - so you do not need a simulation. The code I posted is just to show you how the new function works - I have not touched your While...WEnd loop where you actually do the Sending. MM23 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 Link to comment Share on other sites More sharing options...
AlmarM Posted November 13, 2009 Author Share Posted November 13, 2009 (edited) Aah ok, im getting a clear vision now. Thanks! EDIT: Grtz on your 2,000 posts Edited November 13, 2009 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. 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