<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
  <!ENTITY prefix "#" > 
]>

<!-- Saved on Sunday, April 13, 2003, 2:37 PM -->
<!-- MuClient version 3.37 -->

<!-- Plugin "Chat" generated by Plugin Wizard -->

<!-- Change the "prefix" entity above to change the chat alias prefix.
     The default is "#", so you would enter "#chat Nick Hi", but you 
     could make it "-" for instance. -->

<muclient>
<plugin
   name="Chat"
   author="Nick Gammon"
   id="753ba7e011f3c8943a885f18"
   language="VBscript"
   purpose="Support for chat feature"
   date_written="2003-04-13 14:32:22"
   date_modified="2003-04-24 16:56"
   requires="3.37"
   version="1.2"
   >
<!--
Version 1 - initial release.
Version 1.1 - minor fixes.
Version 1.2 - added more examples, added "is snooping" flag.
              took "echo_alias" off the basic chatting commands
-->

<description trim="y">
Provides an interface to the chat functions.

Commands
========

chat:help     &lt;-- show this help screen

For commands affecting a chat connection you can either use their name
(eg. Nick) or their connection number (eg. 5). Both appear when you type
&quot;&prefix;chats&quot;.

General
-------

&prefix;chats        &lt;-- get connected chat list (note chat ID on left)
&prefix;chatdetails [who]  &lt;-- shows full details for one or all connections
&prefix;info         &lt;-- shows chat status and chat list

Accept calls
------------

&prefix;accept       &lt;-- accept connections on current port
&prefix;accept port  &lt;-- accept connections on 'port' eg. &prefix;accept 4052
&prefix;nocalls      &lt;-- stop accepting incoming calls

Calling someone
---------------

&prefix;call ip port &lt;-- attempts to call user on at IP address and port
&prefix;call ip      &lt;-- attempts to call user on at IP address, port 4050
&prefix;hangup who   &lt;-- hangs up a call
&prefix;hangupall    &lt;-- hangs up all calls


Chatting
--------

&prefix;chat who xxx  &lt;-- sends message to person, eg. &prefix;chat Nick Hi there
&prefix;chatall xxxx  &lt;-- sends message to all connections
&prefix;cg group xxxx &lt;-- sends message to everyone in group 'group'
&prefix;emote who xx  &lt;-- emotes to one person, eg. &prefix;emote Nick laughs
&prefix;emoteall xxx  &lt;-- emotes to all, eg. &prefix;emoteall sighs
&prefix;eg group xxxx &lt;-- emotes to everyone in group 'group'

Other
-----

&prefix;command who xxx    &lt;-- send command "xxx" to that person
&prefix;group who xxx      &lt;-- places this person into group &quot;xxx&quot;
&prefix;name newname       &lt;-- change your chat name, eg. &prefix;name Nick
&prefix;peek  who          &lt;-- peek this person's connections
&prefix;paste who          &lt;-- paste clipboard to this connection
&prefix;pasteall           &lt;-- paste clipboard to everybody
&prefix;ping  who          &lt;-- ping this connection
&prefix;request who        &lt;-- try to connect to this person's connections
&prefix;sendfile who       &lt;-- send a file to this connection
&prefix;stopfile who       &lt;-- stop sending a file to this connection
&prefix;snoop who          &lt;-- start/stop snooping this connection

Flags
-----

&prefix;allowcommands   who      &lt;-- allow them to send me commands
&prefix;allowfiles      who      &lt;-- allow them to send me files
&prefix;allowsnoop      who      &lt;-- allow them to snoop me
&prefix;ignore          who      &lt;-- ignore them
&prefix;private         who      &lt;-- mark connection private
&prefix;served          who      &lt;-- mark them as incoming

&prefix;noallowcommands who      &lt;-- turn off above options
&prefix;noallowfiles    who    
&prefix;noallowsnoop    who    
&prefix;noignore        who     
&prefix;noprivate       who     
&prefix;noserved        who      

</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   match="&prefix;snoop *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatMessage ChatGetID (&quot;%1&quot;), 30, &quot;&quot;</send>
  </alias>

  <alias
   match="&prefix;command * *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatMessage ChatGetID (&quot;%1&quot;), 105, &quot;%2&quot;</send>
  </alias>

  <alias
   match="&prefix;allowsnoop *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;can_snoop&quot;, 1) = 0 then
  Note &quot;Snooping for %1 enabled&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;group * *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;group&quot;, "%2") = 0 then
  Note &quot;%1 is now in group '%2'&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;noallowsnoop *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
   >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;can_snoop&quot;, 0) = 0 then
  Note &quot;Snooping for %1 disabled&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;allowfiles *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;can_send_files&quot;, 1) = 0 then
  Note &quot;File sending for %1 enabled&quot;
end if</send>
  </alias>
  <alias
   match="&prefix;noallowfiles *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;can_send_files&quot;, 0) = 0 then
  Note &quot;File sending for %1 disabled&quot;
end if</send>
  </alias> 

  <alias
   match="&prefix;allowcommands *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;can_send_commands&quot;, 1) = 0 then
  Note &quot;Command sending for %1 enabled&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;noallowcommands *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;can_send_commands&quot;, 0) = 0 then
  Note &quot;Command sending for %1 disabled&quot;
end if</send>
  </alias> 

  <alias
   match="&prefix;ignore *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;ignore&quot;, 1) = 0 then
  Note &quot;Now ignoring %1&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;noignore *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;ignore&quot;, 0) = 0 then
  Note &quot;Not ignoring %1&quot;
end if</send>
  </alias> 

  <alias
   match="&prefix;private *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;private&quot;, 1) = 0 then
  Note &quot;%1 is now marked private&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;noprivate *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;private&quot;, 0) = 0 then
  Note &quot;%1 is now NOT private&quot;
end if</send>
  </alias> 

 <alias
   match="&prefix;served *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;served&quot;, 1) = 0 then
  Note &quot;%1 is now marked as served (incoming)&quot;
end if</send>
  </alias>

  <alias
   match="&prefix;noserved *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>if SetChatOption (ChatGetID (&quot;%1&quot;), &quot;served&quot;, 0) = 0 then
  Note &quot;%1 is now NOT marked as served (ie. now outgoing)&quot;
end if</send>
  </alias> 

 <alias
   match="&prefix;paste *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatPasteText ChatGetID (&quot;%1&quot;)</send>
  </alias>

 <alias
   match="&prefix;pasteall"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatPasteEverybody</send>
  </alias>

  <alias
   match="&prefix;ping *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatPing ChatGetID (&quot;%1&quot;)</send>
  </alias>

  <alias
   match="&prefix;sendfile *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatSendFile ChatGetID (&quot;%1&quot;), ""</send>
  </alias>

 <alias
   match="&prefix;stopfile *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatStopFileTransfer ChatGetID (&quot;%1&quot;)</send>
  </alias>

  <alias
   match="&prefix;peek *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatPeekConnections ChatGetID (&quot;%1&quot;)</send>
  </alias>
  <alias
   match="&prefix;request *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatRequestConnections ChatGetID (&quot;%1&quot;)</send>
  </alias>
  <alias
   match="&prefix;accept *"
   enabled="y"
   send_to="12"
   sequence="90"
   echo_alias="y"
  >
  <send>ChatAcceptCalls %1</send>
  </alias>
  <alias
   match="&prefix;accept"
   enabled="y"
   send_to="12"
   sequence="90"
   echo_alias="y"
  >
  <send>ChatAcceptCalls 0</send>
  </alias>
  <alias
   match="&prefix;name *"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatNameChange &quot;%1&quot;</send>
  </alias>
  <alias
   match="&prefix;nocalls"
   enabled="y"
   send_to="12"
   sequence="90"
   echo_alias="y"
  >
  <send>ChatStopAcceptingCalls</send>
  </alias>

  <alias
   match="&prefix;chat * *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatPersonal &quot;%1&quot;, &quot;%2&quot;, 0</send>
  </alias>

  <alias
   match="&prefix;cg * *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatGroup &quot;%1&quot;, &quot;%2&quot;, 0</send>
  </alias>

  <alias
   match="&prefix;eg * *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatGroup &quot;%1&quot;, &quot;%2&quot;, 1</send>
  </alias>

  <alias
   match="&prefix;chatall *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatEverybody &quot;%1&quot;, 0</send>
  </alias>
  <alias
   match="&prefix;chats"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatList</send>
  </alias>
  <alias
   match="&prefix;emoteall *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatEverybody &quot;%1&quot;, 1</send>
  </alias>
  <alias
   match="&prefix;hangup *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatDisconnect ChatGetID (&quot;%1&quot;)</send>
  </alias>
  <alias
   match="&prefix;hangupall"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ChatDisconnectAll</send>
  </alias>
  <alias
   match="&prefix;info"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>call ChatInfo</send>
  </alias>
  <alias
   match="&prefix;emote * *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatPersonal &quot;%1&quot;, &quot;%2&quot;, 1</send>
  </alias>
  <alias
   match="&prefix;call *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ChatCall &quot;%1&quot;, 0</send>
  </alias>
  <alias
   match="&prefix;call * *"
   enabled="y"
   send_to="12"
   sequence="90"
   echo_alias="y"
  >
  <send>ChatCall &quot;%1&quot;, %2</send>
  </alias>
  <alias
   match="&prefix;chatdetails *"
   enabled="y"
   send_to="12"
   sequence="90"
   echo_alias="y"
  >
  <send>ChatDetails ChatGetID (&quot;%1&quot;)</send>
  </alias>
  <alias
   match="&prefix;chatdetails"
   enabled="y"
   send_to="12"
   sequence="100"
   echo_alias="y"
  >
  <send>ShowChats</send>
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[

sub chatdetails (id)
dim sType

'
' no id - give up
'

  if id = 0 then  exit sub

  if GetChatInfo (id, 10) = 0 then
    sType = "MudMaster"
  else
    sType = "zChat"
  end if
 
  Note "----------------------------------------"
  Note "Server         : " & GetChatInfo (id, 1)
  Note "User           : " & GetChatInfo (id, 2)
  Note "Group          : " & GetChatInfo (id, 3)
  Note "Version        : " & GetChatInfo (id, 4)
  Note "Call IP        : " & GetChatInfo (id, 5)
  Note "Address        : " & GetChatInfo (id, 6)
  Note "Port           : " & GetChatInfo (id, 7)
  Note "Call port      : " & GetChatInfo (id, 8)
  Note "Status         : " & GetChatInfo (id, 9)
  Note "Type           : " & sType
  Note "ID             : " & GetChatInfo (id, 11) 
  Note "Incoming       : " & GetChatInfo (id, 12) 
  Note "Can snoop      : " & GetChatInfo (id, 13) 
  Note "Snooping       : " & GetChatInfo (id, 14) 
  Note "They snoop     : " & GetChatInfo (id, 15) 
  Note "Send commands  : " & GetChatInfo (id, 16) 
  Note "Private        : " & GetChatInfo (id, 17) 
  Note "Can send files : " & GetChatInfo (id, 18) 
  Note "Ignore them    : " & GetChatInfo (id, 19) 
  Note "Recent ping    : " & GetChatInfo (id, 20) 
  Note "Started at     : " & GetChatInfo (id, 21) 
  Note "Last in        : " & GetChatInfo (id, 22) 
  Note "Last out       : " & GetChatInfo (id, 23) 
  Note "Started file   : " & GetChatInfo (id, 24) 
  Note "Xfer file      : " & GetChatInfo (id, 25) 
  Note "Xfer is send   : " & GetChatInfo (id, 26) 
  Note "File name      : " & GetChatInfo (id, 27) 
  Note "Full file path : " & GetChatInfo (id, 28) 
  Note "File size bytes: " & GetChatInfo (id, 29) 
  Note "File blocks    : " & GetChatInfo (id, 30) 
  Note "Blocks xferred : " & GetChatInfo (id, 31)
  Note "Block size     : " & GetChatInfo (id, 32)
  Note "Count of incoming:" & _
       " Personal : " & GetChatInfo (id, 33) & _
       ", All : " & GetChatInfo (id, 34) & _
       ", Group : " & GetChatInfo (id, 35) & _
       ", Messages : " & GetChatInfo (id, 39)

 Note "Count of outgoing:" & _
       " Personal : " & GetChatInfo (id, 36) & _
       ", All : " & GetChatInfo (id, 37) & _
       ", Group : " & GetChatInfo (id, 38)
  Note ""

end sub

sub showchats 

dim mylist

mylist = GetChatList

if not IsEmpty (mylist) then

  Note ""
  ColourNote "white", "blue", "---- Chat List ----"
  Note ""
 
  For Each id In myList 
    chatdetails (id)
  Next

else
  ColourNote "white", "red", "No chat sessions"
End If

End Sub

sub chatlist

dim mylist, flags

mylist = GetChatList

if not IsEmpty (mylist) then

  Note ""
  ColourNote "white", "blue", "---- Chats ----"
  Note ""
 
  For Each id In myList 

    flags = ""

    ' look for flags
    if GetChatInfo (id, 17) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "private"
    end if

    if GetChatInfo (id, 12) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "served"
    end if

    if GetChatInfo (id, 13) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "can snoop"
    end if

    if GetChatInfo (id, 14) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "snooping"
    end if

    if GetChatInfo (id, 16) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "can send commands"
    end if

    if GetChatInfo (id, 18) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "can send files"
    end if

    if GetChatInfo (id, 19) then
      if flags <> "" then flags = flags & ", "
      flags = flags & "ignore"
    end if

    if flags <> "" then
       flags = " (" & flags & ")"
    end if

	Note id & ": " & _
               GetChatInfo (id, 2) & " (" & _
               GetChatInfo (id, 5) & ", " & _
               GetChatInfo (id, 8) & ")" & _
               flags

  Next

else
  ColourNote "white", "red", "No chat sessions"
End If

Note ""

end sub

sub ChatInfo

  Note ""
  ColourNote "white", "blue", "---- Chat Configuration ----"
  Note ""

  Note "Accepting incoming connections: " & _
       CBool (GetOption ("accept_chat_connections"))
  Note "Incoming connections port: " & _
       	GetOption ("chat_port")
  Note "Our chat name: " & _
       GetAlphaOption ("chat_name")

  call chatlist

end sub

'
'  Chat callbacks
'  --------------
'

' OnPluginChatAccept 
' ------------------
'
'  MUSHclient has received a connection from IP,name
'  Return TRUE to accept it, FALSE to reject it
'
Function OnPluginChatAccept (sText)
dim theList
dim username, ip, domain

  theList = split (sText, ",")
  ip = theList (0)
  username = theList (1)

'
'  Example of looking up their domain name:
'

'  domain = GetHostName (ip)


'
'  Example user notifications:
'
'  Note "** Received chat call from " & username & " at address " & ip
'
'  Note "** Received chat call from " & username & " at domain " & domain


  OnPluginChatAccept = vbTrue  ' accept it

'
'  Example of rejecting someone (uncomment and change address):
'
'  if ip = "111.222.10.3" then OnPluginChatAccept = vbFalse
'

End Function
 
' OnPluginChatMessage
' ------------------
'
'  MUSHclient has received chat message: id, type, text
'  Return TRUE to use the default processing, FALSE to ignore it
'
'
'  The "id" argument supplies the chat id of the connection which sent the
'  message.
'
'  The message code indicating the chat message, where these are likely
'         to be received:
'

'   1    Name_change				  
'   2    Request_connections 
'   3    Connection_list	 		
'   4    Text_everybody			
'   5    Text_personal			  
'   6    Text_group				  
'   7    Message					    
'   8    Do_not_disturb			
'   9    Send_action				  
'  10    Send_alias				  
'  11    Send_macro				  
'  12    Send_variable				
'  13    Send_event			    
'  14    Send_gag				    
'  15    Send_highlight			
'  16    Send_list				    
'  17    Send_array				  
'  18    Send_baritem			  
'  19    Version					    
'  20    File_start				  
'  21    File_deny				    
'  22    File_block_request	
'  23    File_block			    
'  24    File_end				    
'  25    File_cancel				  
'  26    Ping_request				
'  27    Ping_response				
'  28    Peek_connections		
'  29    Peek_list			    	
'  30    Snoop					      
'  31    Snoop_data		
' 105    Send_command		  

Function OnPluginChatMessage (id, message, sText)

  OnPluginChatMessage = vbTrue  ' process it

'
'  Example of rejecting a message:
'
'  if message = 26 then OnPluginChatMessage = vbFalse ' ignore pings
'

End Function


' OnPluginChatDisplay
' ------------------
'
'  MUSHclient is about to display message: type, text
'  Return TRUE to use the default display, FALSE to not display
'
'  Note - the message type number, which groups types
'         of messages, as follows:
'

'   0 Connection attempt    
'   1 Session start, end          
'   2 Name Change        
'   3 Message           
'   4 Incoming Personal  
'   5 Incoming Everybody 
'   6 Incoming Group     
'   7 Outgoing Personal  
'   8 Outgoing Everybody 
'   9 Outgoing Group     
'  10 Peek List          
'  11 Connection List    
'  12 Ping              
'  13 Information       
'  14 File              
'  15 Snoop Data         
'  16 Command

Function OnPluginChatDisplay (message, sText)

  OnPluginChatDisplay = vbTrue  ' display it

'
'  Example of rejecting a message:
'
'  if message = 10 then OnPluginChatDisplay = vbFalse ' ignore peek lists
'

'
'  Example of doing something different with it.
'
'  We will take normal incoming and outgoing chats and emotes, and
'  display them in a notepad window, and omit them from the main window
'

'   if message >= 4 and message <= 9 then
'     AppendToNotepad "Chats", Replace (StripAnsi (sText), chr (10), vbCrLf)
'     OnPluginChatDisplay = vbFalse
'   end if 

'
'  Example of timestamping messages
'
'  If an incoming message type is not 1000 we prepend the date and re-display it
'  If it is 1000 (our user-assigned type) we simply let MUSHclient display it.
'

'  If message <> 1000 Then
'    ChatNote 1000,  FormatDateTime (Now, vbShortTime) & ": " & sText
'    OnPluginChatDisplay = vbFalse
'  End If  
  
End Function


' OnPluginChatNewUser
' -------------------
'
' A new plugin user has been accepted on: id, name
'
'
' This script callback has been provided so you can take action if
' you want (such as allowing file transfers).
'

sub OnPluginChatNewUser (id, name)

'
'  Example of notifying yourself of a new chat user.
'
' Note "New chat user: " & name
'

'
' Example of taking special action
'
'  If Bruce connects let him send files, and mark as private
'

'  if LCase (name) = "bruce" then
'     SetChatOption id, "can_send_files", 1
'     SetChatOption id, "private", 1
'  end if

end sub


' OnPluginChatUserDisconnect
' --------------------------
'
' This chat user has disconnected for one reason or another.
'
' This callback lets you take action (eg. notify others) however
' you cannot send messages to this connection or change any options
' once they have disconnected. The chat id is supplied so you can 
' match the id to the one that connected.
'
' For each call to OnPluginChatNewUser there should eventually be a
' corresponding call to OnPluginChatUserDisconnect.
'
sub OnPluginChatUserDisconnect (id, name)

'  Example of notifying yourself someone has left ...
'
'  Note "Chat user: " & name & " has left the chat system."
'

end sub


]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="Chat:help"
   enabled="y"
   ignore_case = "y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
  World.Note World.GetPluginInfo (World.GetPluginID, 3)
End Sub
]]>
</script> 

</muclient>
