Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Disabling specific input with Chat plugin

Disabling specific input with Chat plugin

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Karl_Newbie   USA  (23 posts)  Bio
Date Thu 01 Jul 2004 09:01 PM (UTC)
Message
I occassionally allow #allowcommands and #allowsnoop with other MC users.
I would use the feature more frequently, but in the #allowcommands option worries me. Because it allows ANY command to be sent. Trust issues I need to work on with a shrink I guess....
Meanwhile, is there any way I could modify the chat plugin so that I can #allowcommands but so that I could set it up to not allow certain commands? Possibly using regular expression. Nothing fancy.
I just don't want a user sending anything like 'change password' or 'read mail' 'delete character' etc.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #1 on Thu 01 Jul 2004 09:36 PM (UTC)
Message

OnPluginChatMessage

' MUSHclient has received chat message: id, type, text
' Return TRUE to use the default processing, FALSE to ignore it
'
' See the Chat.xml plugin for the exact message numbers that might be received.

Function OnPluginChatMessage (id, message, sText)
OnPluginChatMessage = vbTrue ' process it
End Function

You can use that callback, whenever you get a command (105 I believe) you can check the text. This has to be done from within the plugin, so you'll have to use the regexps of the script engine, or other string commands.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 02 Jul 2004 03:02 AM (UTC)
Message
Good idea. You might want to start by removing leading spaces, checking for the script prefix, and checking for command stacking. Otherwise someone might do this:

/world.send "change password blah"

or

say hi there; change password blah


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #3 on Fri 02 Jul 2004 03:25 AM (UTC)
Message
Also, if your mud supports serverside aliasing, you can alias the real sensetive stuff (that you wouldnt normally use) such as, delete, or password, to something else. like a tell to yourself. then you can also disallow the alias command.
Then when you get the tell (that means someone has gotten around your other precautions) you can disallow commands from people, or whatnot. Alert yourself, things of that nature.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Karl_Newbie   USA  (23 posts)  Bio
Date Reply #4 on Fri 02 Jul 2004 08:02 PM (UTC)
Message
Thanks, I'm not sure how I go about implementing the basic part. Flannel, do I place the callback in the chat.xml? Sorry I haven't used Mushclient beyond triggers with short scripts but am trying to learn.
That's true about the serverside aliasing. In addition to commands to change a password etc I will need to block the serverside alias command.
If you have time, saw that message 105 is for the send command, but how/where do I place your callback script. Do I need to use a script file for it? And where in that script do I place the text I want to block?


Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 02 Jul 2004 11:55 PM (UTC)

Amended on Sat 03 Jul 2004 12:01 AM (UTC) by Nick Gammon

Message
Edit your chat.xml plugin file (or better still, make a copy and edit the copy).

In the middle where there is a function OnPluginChatMessage, replace the existing function with the code below ...


Function OnPluginChatMessage (id, message, sText)
Dim regEx, Matches, Match, FixedText
Dim ScriptPrefix, ScriptEnabled
Dim CommandStackCharacter, CommandStackEnabled

  OnPluginChatMessage = vbTrue  ' process it


'
'  Example of rejecting a message:
'
'  if message = 26 then OnPluginChatMessage = vbFalse ' ignore pings
'

'
'  Example of filtering commands
'
   if message = 105 then  ' command from chat connection

'
'  Find their script prefix and command stack character
'
   ScriptPrefix  = world.GetAlphaOption ("script_prefix")
   ScriptEnabled = world.GetOption ("enable_scripts")
   CommandStackCharacter = world.GetAlphaOption ("command_stack_character")
   CommandStackEnabled = world.GetOption ("enable_command_stack")

   FixedText = Trim (sText)   ' remove spaces

'
'  Disable command stacking
'
   If CommandStackEnabled And _
      InStr (FixedText, CommandStackCharacter) > 0 Then
     ColourNote "white", "red", _
        "Command stacking received via chat - discarded"
     ColourNote "white", "red", _
        "Line was: " & FixedText 
     OnPluginChatMessage = vbFalse
     Exit Function
   End If
     
'
'  Disable script commands
'
   If ScriptEnabled And ScriptPrefix <> "" And _
      Left (FixedText, Len (ScriptPrefix)) = ScriptPrefix Then
     ColourNote "white", "red", _
        "Script command received via chat - discarded"
     ColourNote "white", "red", _
        "Line was: " & FixedText 
     OnPluginChatMessage = vbFalse
     Exit Function
   End If

   Set regEx = New RegExp

'
'  Disallow:  change password
'             read mail
'             delete character
'
'  You can add others of your own. The \s+ means "one or more spaces"
'    This stops people typing "read   mail" and getting through the filter
'
   regEx.Pattern = "^(change\s+password)|(read\s+mail)|(delete\s+character)"

'
'  Execute regular expression
'

   Set Matches = regEx.Execute (lcase (FixedText))

'
'  Exit if no match
'
   if Matches.Count = 0 then  
     Set regEx = Nothing
     Set Matches = Nothing
     Exit Function
   end if

   Set Match = Matches.Item (0)
 
'
'  wildcards in the regexp can be accessed here, eg.
'    Match.SubMatches (0) is the first wildcard
'    Match.SubMatches (1) is the second wildcard, and so on
'
   Set regEx = Nothing
   Set Matches = Nothing

'
'  Matched - ignore this command
'
   ColourNote "white", "red", _
      "Illegal command received via chat - discarded"
   ColourNote "white", "red", _
      "Line was: " & FixedText 
   OnPluginChatMessage = vbFalse
   Exit Function

   end if  ' type 105 (command)

End Function



The example above disables command stacking, and script commands via the chat command (the first two tests).

Then it sets up a regular expression to test for the other commands (or you could test them one-by-one). The "|" in the regular expression means "or". The "^" means "at the start of the line.

The script first does a trim to get rid of leading spaces (so they don't feed through space-space-space something). It also converts the text to lower case to make sure the regular expression matches.

If anything fails the test you see a display on the screen, eg.


Illegal command received via chat - discarded
Line was: change password xxx


Save the plugin file and re-install it (or if you have saved under a different name, uninstall the original one, and install your modified version).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Fri 02 Jul 2004 11:59 PM (UTC)

Amended on Sat 03 Jul 2004 12:00 AM (UTC) by Nick Gammon

Message
An alternative would be to modify the sense of the test. Make a regular expression that only *allows* certain command through, and discards the rest. This is probably safer.

eg. You might allow:

^(north|south|east|west|take|drop)

That way you specify what you want them to do rather than what you don't want them to do. Then you can always expand the list later on.

Then you accept the line if the regular expression *matches* and discard it if it doesn't.

For more flexibility you could keep the allowed (or disallowed) commands in a variable and get the script to use that variable rather than hard-coding in the regular expression.

For example, change the line with the regular expression to:

regEx.Pattern = GetPluginVariable ("", "chat_regexp")

This gets the global variable "chat_regexp" (not the one in the plugin) which you can then just change in the variable configuration screen whenever you want to modify the regular expression.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,864 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.