Elf programming example #6

automatically reconnect upon disconnection

Task: automatically reconnect to the MUD when disconnection happens before renting.
View the source code now.

To achieve this task requires very few and simple steps:

First of all we need to create a global numeric variable named @DoRecon that will hold 0 or 1. 0 means that reconnection is not enabled because last disconnection happened after renting.

Next, we need to define a trigger that recognises any simple message received from the MUD when we rent.

Let's trap the message "Rosetta the receptionist stores your stuff in the safe".

The trigger will be
*Rosetta the receptionist stores your stuff in the safe*

The commands related to this trigger are the following:
@DoRecon=0

Now, let's define the aliases that actually handle connection and disconnection. From version 4.02, ELF calls two aliases when connection and disconnection happen. Such aliases are OnConnect and OnDisconnect.

The alias OnConnect will be activated by the pattern
OnConnect

The commands related to this alias are the following:
@OutStr @FGCyan+"Connection established..."
@DoRecon=1

The first command is simply informational :-)

The second one signals that a connection has been established.

The alias OnDisconnect will be activated by the pattern
OnDisconnect

The commands related to this alias are the following:
@OutStr @FGCyan+"Connection closed."
@If @DoRecon
@OutStr @FGLightRed+"Resuming connection to "+@FGLightGreen+@LastMud+@FGLightRed+"..."
@Connect @LastMud

The first @OutStr is simply informational.

The @IF checks if we rent or not. If we rent then reconnection is not wanted (@DoRecon=0).

The second @OutStr informs that reconnection is enabled.

@Connect tries to reconnect to the last mud we connected to.

Here is the necessary programming for this task:
 
variable DoRecon
type numeric
 
trigger Recognise renting
trigger *Rosetta the receptionist stores your stuff in the safe*
flags none
commands @DoRecon=0
 
alias OnConnect
pattern OnConnect
flags none
commands @OutStr @FGCyan+"Connection established..."
@DoRecon=1
 
alias OnDisconnect
pattern OnDisconnect
flags none
commands @OutStr @FGCyan+"Connection closed."
@If @DoRecon
@OutStr @FGLightRed+"Resuming connection to "+@FGLightGreen+@LastMud+@FGLightRed+"..."
@Connect @LastMud
 

These pages were developed with Netscape Composer 4.03 by Alfredo Milani-Comparetti  
Last modified on 8 nov 1997