#  A mud client for
#  Dawn of the Ages  http://www.rplay.net
#
#  Copyright (C) 2001,2002 Peter Herth <p.herth@uni-koeln.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

* The DMC-Package
=================
The following files are part of the DMC, the Dawn Mud Client.
 - .clientrc
   The default config-file. Please create your own config file by copying
   this default file to your homedirectory and modifying the copy. Do NOT
   modify the default, it is needed in case your own copy gets corrupted.
 - Applets.py
   The file where most of the applets and functions are defined in.
 - DOCS
   The Documentation of DMC, this file.
 - README
   The README including a short documentation
 - COPYING
   The GNU General Public License
 - TODO
   A todo-list with listed improvements wanted by the users, main source 
   of idea for further improvements.
 - client.py
   The main program-file.
 - gui.py
   The graphical user interface for the DMC (optional)
 - speedwalk.py
   Speedwalk module
 - spells.py
   The definition of the diplayable spell-affects.

* Features
==============
* Aliases and Triggers with parameters
* Speedwalks
* Highlights
* statusbar showing yours/opponent's hp, mana and mv as bars
* affect-display in the status-bar
* Input history and Tab-Completion
* unlimited, search- and writeable scrollback
* buttons that track affects automatically
* Talker, displaying conversations in a different window
* all colors and fonts customizable
* fully programmable by python-extensions

* Client Usage
==============
The starting of the client is different for Windows and Linux. Skip to the 
appropriate section for your operating system. If you have another OS, 
please let us know so we can add instructions for it.

In order to use language specific characters, such as the german umlaute, 
please either link or copy the provided file "sitecustomize.py" to your 
python directory, which would look like this "/usr/lib/python2.3/".

Linux specifics:
----------------

The client is either started via an executable character startfile or 
called directly, either with the command "DMC.py" in case the client 
file is set as executable or via "python DMC.py" in case you prefer not 
to have the client.py as executable. If you prefer to use the client 
withing a terminal emulation, without the gui, please add the commandline 
option --term to your command/character file. Upon start, the client will 
read the specified files and load necessary parts to function properly. In 
case that your python installation did not put a link into /usr/bin you 
can do so yourself:
 - First, find out where the python interpreter was stored. 
   To do this, simply type: 'whereis python'
 - change to the /usr/bin directory and create a link to the location
   of the python interpreter:
   'ln <path fo the interpreter> <link-name>'
   So in case you have an interpreter named Python2.0 in the /sbin
   directory the link command would be: 'ln /sbin/Python2.0 python'
   and everthing works fine.   
For convenience either the client file (client.py) or the 
character startfiles should be set as executables. To do that, use the chmod 
command:

chmod 700 <file>

This will allow you to execute the file by simply entering its name and 
pressing enter afterwards. Putting client.py and its support files in the 
searchpath of $PATH and using the command_dir option of the config file 
will allow you to start your client from anywhere on your system.

Windows specifics:
------------------
After installing python and unzipping the client into any directory,
simply start the client by double-clicking on the file DMC.py 
in the Windows explorer.
Character startfiles should work if stored as batch-files, using the .BAT 
termination. This feature is not tested yet.

* Client (built-in) commands
============================
A short helpfile can be accessed for each of the commands by using: #help 
<command> To use a command, put a # directly in front of the command, 
without the #, the client assumes your input to be directed to the mud you 
might be connected to and will pass it through without further processing 
your input.
In all cases commands and expressions are case sensitive. Multiple mud 
commands can be used by putting a ';' between the individual commands, 
which is of special interest for triggers and aliases.
I will list the available commands, give the syntax for each command and 
add a short help to the command in question. As joker to represent any 
number of characters, from 1 to oo, please use '.*'.

- alias
	Syntax:
		#alias 
		#alias <shortcut> <command(s)>
	Synopsis:
		alias will list the defined aliases or define a new one
- closeaffects
	Syntax:
		#closeaffects
	Synopsis:
		closes an open affects window
- closelog
	Syntax:
		#closelog
	Synopsis:
		stops a currently running logging
- connect
	Syntax:
		#connect
		#connect <ip/address> <port>
	Synopsis:
		connects the client to a mud. if no parameter is given, a
		connection with dawn of the ages will be opened, for which
		this client was originally written.
- echo
	Syntax:
		#echo <text>
	Synopsis:
		will diplay the given text on the clientside. useful 
		within makros
- echoinput
	Syntax:
		#echoinput
	Synopsis:
		toggles the input for echo
- eval
	Syntax:
		#eval <expression>
	Synopsis:
		sends the <expression> to python for evaluation
- exit
	Syntax:
		#exit
	Synopsis:
		will exit the mudclient. additional windows opened by the 
		mud client, like affects windows are NOT closed yet.
- help
	Syntax:
		#help <command>
	Synopsis:
		displays a short online help with syntax for the 
		respective command
- highlight
	Syntax:
		#highlight <color> <expression to be highlighted>
	Synopsis:
		highlights the given expression by using the given color. 
		the 8 ansi colors are used, available both as bright and 
		dim versions. bright colors are used if the color name is 
		written with a capital starting letter. the available 
		colors are:
		red, blue, green, yellow, magenta, cyan, white and black
- ignore
	Syntax:
		#ignore
                #ignore [on|off]
	Synopsis:
		switches/sets triggering on/off globally
- load
	Syntax:
		#load <file>
	Synopsis:
		load a file with python code which is then interpreted as 
		if being part of the client.py file
- log
	Syntax:
		#log
		#log <file>
	Synopsis:
		starts logging to the given file in append-modus, else 
		logging is stopped
- more
	Syntax:
		#more
	Synopsis:
		uses a buffer to display the output screenwise. the next 
		portion of text is fetched from the buffer by using the 
		TAB-key
- prefix
	Syntax:
		#prefix
	Synopsis:
		sets the prefix command
- prompt
	Syntax:
		#prompt <dawn-promptstring>
	Synopsis:
		enables the correct function of the display-applets. adds
		a string to the dawn-prompt which is used in game so that
		the client can evaluate the string displayed by the mud.
		the added part of the prompt is visible only when using 
		telnet or another client when connecting to dawn without
		this client. Please note that there will not be a 
		different battleprompt available.
- read
	Syntax:
		#read <file>
	Synopsis:
		read a file and interpret the contents as if typed from 
		within the client. this allows to re-read files created 
		with the #writeXXX commands
- recall
	Syntax:
		#recall <expression>
	Synopsis:
		output all lines that match the given expression within 
		the recall buffer.
- recallsize
	Syntax:
		#recallsize <size>
	Synopsis:
		sets the size in lines of the recall buffer, standard size 
		is 10,000.
- send
	Syntax:
		#send
	Synopsis:
		pass input directly to the mud without processing it for 
		triggers, highlights or aliases
- setvar
	Syntax:
		#setvar <variable> <value>
	Synopsis:
		sets a value to a variable. the value of the variable can 
		be retrieved with #eval or with $[variable]
- shell
	Syntax:
		#shell <commands>
	Synopsis:
		executes commands in a shell
- showaffects
	Syntax:
		#showaffects
	Synopsis:
		opens a window to display the affects in. the contents of 
		the affects window will be updated automatically whenever
 		the mud-command affects is executed.
- showlog
	Syntax:
		#showlog
	Synopsis:
		???
- sleep
	Syntax:
		#sleep <seconds>
	Synopsis:
		will let the client sleep for the given amount of 
		seconds, which can also be given as a fraction.
- split
	Syntax:
		#split
	Synopsis:
		splits the client display into an input and an output 
		section. the size of the input section, part of which can 
		be used to display exits and gauges, can be defined in the
		config file.
- sw
	Syntax:
		#sw
		#sw add <name> <directions/commands>
		#sw del <name>
	Synopsis:
		lists all defined speedwalks, adds a new speedwalk with 
		the given name and the given directions and commands or 
		removes a speedwalk by the given name.
- trigger
	Syntax:
		#trigger <expressopm>~<commands to be executed>
	Synopsis:
		defines a trigger to be executed upon appearance of an 
		expression or text.
- unalias
	Syntax:
		#unalias <aliasname>
	Synopsis:
		removes an alias from the alias list
- unhighlight
	Syntax:
		#unhighlight <text>
	Synopsis:
		remove a highlight from the highlight list
- unsplit
	Syntax:
		#unsplit
	Synopsis:
		presents the client with a single, unsplit window
- untrigger
	Syntax:
		#untrigger <trigger text>|<number>
	Synopsis:
		removes a trigger from the list matching the given text 
		or number
- write
	Syntax:
		#write <file>
	Synopsis:
		writes all defines into a single file. the file can be 
		re-read with the #read command.
- writealiases
	Syntax:
		#writealiases <file>
	Synopsis:
		writes all aliases into a file. the file can be re-read 
		with the #read command.
- writehighlites
	Syntax:
		#writehighlites <file>
	Synopsis:
		writes all highlights into a file. the file can be 
		re-read with the #read command.
- writerecall
	Syntax:
		#writerecall <file>
	Synopsis:
		writes the recall buffer into a file. useful to augment 
		logs or for bugtracing.
- writesw
	Syntax:
		#writesw <file>
	Synopsis:
		writes all speedwalks into a file. the file can be 
		re-read with the #read command.
- writetriggers
	Syntax:
		#writetriggers <file>
	Synopsis:
		writes all triggers into a file. the file can be re-read 
		with the #read command.
		
		
* The client's configfile ".clientrc"
=====================================
Comments start with a # in the first row of a line. Keywords and their 
options are separated by an equals (=) wich itself is separated from the 
keyword and the option by spaces on either side. Which gives the following 
look:

keyword = option

Apart from keywords, the client also can get an individual setup by 
defining where certain display elements will be located. This happens via 
the displayers object. To add a certain feature, simply use:

displayers.append(([row],[line],[value/object]))

If you want to draw a line composed of dashes to separate the two parts 
of the display, simply add the following:

displayers.append((1,1,lambda: "-"*80))	

This will draw a line composed of 80 dashes in line one, starting at row 
one. 
A clock display on the right end of the separation will be done by the 
following displayers object:

displayers.append((width-7,1,clock_disp))

To emulate a tf-alike display, the special display features of the client 
are ignored should the tf-commandline option be given at the client 
startup.

The configfile is always read from the home directory of the user, thus 
you can always keep a copy of the config file in your installation 
directory for backup purposes.
The configfile will define how your client basically looks in two ways, 
a) it defines how the xterm is defined which is used for the output of 
the client, and b) how the statusbar is handled.
The following keywords are recognized by the client:

 - xterm_opts
 - command_dir
 - status_size

xterm_opts:
The options used for the xterm are the same as for a standard xterm 
window. Please refer to the corresponding man pages for further detail. 
The options of your choice are to be given in single quotes (') after the 
keyword xterm_opts.

command_dir:
This option allows you to set a path to the directory where your client is 
located. Namely the files 'speedwalk.py' and 'spells.py' are loaded from 
the given directory. If no path is given, the following paths are checked 
when trying to load the above mentioned files:
 - the directory in which the client.py file is located
 - the current directory 
If the loading fails, a message will be displayed.

status_resize:
This gives the number of lines used for the status part of the client. We 
recomment at least 3 lines, 4 if you use a line of separation, so that you 
can enjoy the full benefit of the possibilites to display the exits and 
the hp/mv/mana gauges as well as the currently effective affects.

An exemplary configfile might look like this:

------->

# options for the xterms used to display the affects list
xterm_opts = '-bg black -fg grey -sb -rightbar -sl 10000'
command_dir = '/usr/bin/dmc'

# statusbar configuration

displayers.append((1,1,lambda: "-"*80))
displayers.append((width-7,1,clock_disp))

status_size = 4
ter_resize("")

if tf_look:
    pass
else:
    displayers.append((4,2,hp_gauge))
    displayers.append((24,2,mana_gauge))
    displayers.append((42,2,move_gauge))
    displayers.append((1,2,draw_exits))
    displayers.append((4,3,tank_gauge))
    displayers.append((4,4,foe_gauge))
    displayers.append((30,3,draw_spells))       

<--------

* Character startfiles
======================
The individual character startfiles are scriptfiles that start the client 
and load a number of individual files, such as trigger files, and perform 
client commands. In order for this to work, the first line of such a 
startfile has the following built:

#! /[path if needed]/python [path to the DMC client]/DMC.py [--term]

Client commands are used just like the manual usage, starting with the 
obligatory #, thus files containing triggers, highlights or speedwalks are 
read with #read and python files loaded with #load.

An exemplary startfile for a gui-setup might look like this:

------->

#! /usr/bin/python [path]/DMC.py 
#read [path]/[char]_trigger
#read [path]/[char]_sw
#connect

<-------

An exemplary startfile for a terminal-setup might look like this:

------->

#! /usr/bin/python [path]/DMC.py --term
#read [path]/[char]_trigger
#read [path]/[char]_sw
#split
#connect

<-------

* Auxiliary files
=================
Highlights or Speedwalks can be saved from within the client to external 
files. Since the format chosen for these files is plain ascii, they can 
also be manually be written and modified. Each line in these files 
represents a commandline for the client. The structure of the commands is 
the same as used in the client. Speedwalks therefore take the form of the 
command that adds a speedwalk to the client, highlights the same as within 
the client, same goes for triggers, options and aliases.

* The Statusbar Affects
=======================
The active affects that are displayed in the statusbar use the spells.py 
file. At the start of the file, the Affects class is defined followed by a 
basic list of affects that you can encounter while playing dawn of the 
ages. Since most of you surely have their own idea on how their favorite 
affects should look like, be it namewise, colorwise or in respect to the 
framing, here a short guide on how to personalize the file.
As with the other python files, you can add comments by using a #. The 
affects are listed below the line stating: affects = []
In order to keep the cleaned-up look, please keep to 5 letters per affect. 
We use 2 letters to frame the affect and 3 letters for the affect itself. 
If you use more or less than those 5 letters, the linebreak will not work 
correctly anymore. 

Affects are built up as follows:

affects.append(Affect(	[affect name],
			[5 letter display string including color codes],
			[name in the affect list], 
			[mud message that starts the affect], 
			[mud message that cancels the affect], 
			[timeout warning for the affect by the mud]))

or 

affects.append(Affect(	[affect name],
			[5 letter display string including color codes],
			[name in the affect list], 
			[mud message that starts the affect], 
			[mud message that cancels the affect]))

in case there is no timeout warning. The display string is built like in 
java, by putting the parts of it together by using +. Characters that are 
meant to be displayed have to be enclosed in double quotes ("). The color 
code takes the form "fcolor(COLOR,bold=x)", where valid values for COLOR 
are BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW and x can take 
the values of 0 for dim colors and 1 for bright colors. Please note that 
the capitalization of the color names is required for the client to work 
properly. The bold entry can be omitted, however, since it is a switch, 
the previous value will be assumed to be true until changed for each 
affect. Thus:

fcolor(BLUE,bold=1)+"A"+fcolor(RED)+"B"+fcolor(MAGENTA)+"C"

used as color code will result in the letters ABC being printed in the 
designated colors but all of them in bold ! Since the default value of
bold is 0, the color command CLR resets the bold entry to 0. Which would 
give us the following:

fcolor(BLUE,bold=1)+"A"+CLR+fcolor(RED)+"B"+fcolor(MAGENTA)+"C"

where only the letter A is printed bold, the other letters normally. Of 
course using:

fcolor(BLUE,bold=1)+"A"+fcolor(RED,bold=0)+"B"+fcolor(MAGENTA,bold=0)+"C"

would result in exactly the same output as before. So it is mainly a 
matter of clarity and personal preference which way you write your 
colorcodes.

* Number of Statusbar Affects per Line
======================================
Decide first how many affects you want to use in a line that is not 
preceded with the 'Aff: '. On a 80 character display you can easily 
display 10 affects. If you want to reduce or increase that number, just 
modify the Applets.py file, in the draw_spells() section. Go to the 
if/else part. The "if" checks against "counter vs MaxNumber-1", the else 
checks against "(counter - MaxNumber-1)%MaxNumber vs 0". In both cases an 
Escapesequence is added which looks like this: "\33[1B\33[xxD". xx is 5 
times MaxNumber. For the modification, just enter your new MaxNumber and 
don't forget to fix the escape sequence as well. Save and you are done.


* Alias usage
=============

Introduction

You can use aliases to let a single command that you type into the
client send several lines of text to the mud. Aliases are created with
the #alias command and also accept parameters.

A simple alias

Let's say that any time you drink, you get a flask from your backpack,
drink a couple of times, and put it back in. Typing these commands in
time and time again can quickly become tiresome, so why not create an
alias "drink" which does just that for you:

     #alias drink get flask backpack\;drink flask\;drink flask\;put
      flask backpack
(type all of this as a single line!)

Be cautious to always type a \ before the ; separating the commands
within the alias. If you forget it, the client will deem the alias
finished and just execute the things after it as a new command. Typing

    #alias drink get flask backpack\;drink flask\;drink flask;put
     flask backpack

will make drink an alias for "get flask backpack;drink flask;drink
flask" and then send "put flask backpack" to the mud!

An alias with a parameter

Typing "open backpack;get thingy backpack;close backpack" each time
you want to get something from there is a lot of typing, too. How much
easier would it be to just type "gb thingy". The trick to do this is
with a parametrized alias:

    #alias gc open backpack\;get $1 backpack\;close backpack

$1 is the first parameter, $2 the second, and so on. $0 are all
parameters, so if you want to be able to get the 'brown potion' instead
of the 'blue potion', you'ld rather make the following alias:

   #alias gc open backpack\;get '$0' backpack\;close backpack

This allows you to just type "gc brown potion".


* Trigger usage
===============

Introduction

Triggers are used to let your client react automatically to text sent
from the MUD. Please, be aware that many MUDs restrict or totally
forbid the usage of triggers. Dawn disallows any triggers that might
give your character an advantage!
For didactic purposes, we'll separate the trigger-explanation into a
part on easy triggers, and one on regex-triggers, although the former
are just a simple case of the latter.

Easy triggers

Well, in easy triggers the text you want to trigger on is fixed, it is
always the same line. If you, for example, want to drink every time
you get the message "You are thirsty.", the trigger command would be:

    #trigger You are thirsty.~drink flask\;drink flask\;drink flask

As with aliases, you see that you have to put a '\' before the
separating ';' which will be stripped by the client when executing the
trigger.
Triggers are not case-sensitive.

Regex triggers

A "regex" or "regular expression" is a pattern with which varying text
can be matched. A regular expression can contain normal letters as
well as certain special symbols. These are:

.   Matches any character besides newline
^   Matches the start of a line
$   Matches the end of a line
*   Matches the preceding item zero or more times
+   Matches the preceding item one or more times
?   Matches the preceding item zero times or once
[]  Matches one of the characters within the braces
()  Everything enclosed in the braces is treated as a single item
    and put into the variables $x by the client.
|   Matches the item to the left or the item to the right.

So, if you want to bonk anyone whenever he says something, you'ld
type:
     
    #trigger (.*) says~bonk $1

This, though, will also trigger on a part of a room-description, eg.
There is a sign hanging over the door. The sign says "Don't smoke!"
So, we will have to further specify what common parts a "say" has.
First off, the name of a character is a single word, there are no
spaces in it. Also, it is the first thing on the line, and whatever
the character says is enclosed in "'"s:
Enrico says 'Be quiet.'

So, a better trigger would be:
     
     #trigger ^([a-zA-Z]*) says '.*'$~bonk $1

If you only want to bonk Enrico or Matthias, that'ld look like this:
     
     #trigger ^(Enrico)|(Matthias) says '.*'$~bon $1

As you can see, you don't have to type in each character for the
braces, but can use ranges instead: [a-z] means all lower-case letters.
In contrast to the rest of the patterns, these "bracketted
expressions" are case-sensitive!

Bracketted expressions also include classes of characters defined,
which can be used as follows:

    [[:alnum:]]

The classes defined are:
alnum       digit       punct
alpha       graph       space
blank       lower       upper
cntrl       print       xdigit

So, instead of [a-zA-Z] one can write: [[:alpha:]]. 
If ^ is the first character after the opening bracket, everything is
matched but the characters within the bracket.

There is much more you can do with regular expressions. For a complete
reference see the man-page on regex (type "man 7 regex" at your
command-line if you're on unix, or search for it on the web), or look
into the python documentation.


* Connecting aliases and triggers
=================================

Let's assume there are a few characters whose name you just find
ridiculous and you want to laugh at them and bonk them every time they
arrive. You can, of course, define a trigger for each of them and just
delete the triggers by hand. But if you use the same kind of trigger
often, why not define two aliases that do that work for us. We'll call
them ridic and unridic. The ridic alias looks like this:

#alias ridic #trigger ($1) has arrived~laugh $1\\;bonk $1\;echo "$1 is
 now ridiculous"

See how you have to use two '\'s in the trigger definition: The first
one, so that the client does not start a new command, the second one
so that bonk $1 belongs to the trigger definition and not to the
alias. The echo will display a message to you, so you know everything
has run smoothly.

Unridic looks almost the same:
#alias unridic #untrigger ($1) has arrived\;echo "$1 is no longer ridiculous"

* Variables
===========

Variables can be used with the #setvar command, and accessed by
putting them into braces preceded by a '$' (eg.: $[container]). 
Taking up the backpack command, let's say you switch containers
frequently. Redefining the alias each time is a bit of a hassle, and a
quick #setvar command will be a lot briefer. So, the alias command
needs to be changed to include the variable "container":

    #setvar container backpack
    #alias gb open $[container]\;get '$1' $[container]\;close $[container]

Now, each time you set the variable container to a different name, the
gb-alias will use this new value, and you do not have to redefine it.









