Using Telnet character mode

 
Post new topic   Reply to topic    mudlab.org Forum Index -> Coding
View previous topic :: View next topic  
Author Message
locke



Joined: 05 Feb 2006
Posts: 4
Location: Pittsburgh, PA

PostPosted: Mon Feb 20, 2006 9:41 pm    Post subject: Using Telnet character mode Reply with quote

Give your mud VT100/102 + ANSI Keyboard Command Support
A Snippet for Any Old Mud by Locke

The snippet is written for Diku/Merc


In your read_from_descriptor() from comm.c:
Code:

#if defined(MSDOS) || defined(unix)
    for ( ; ; )
    {
        int nRead;  /* # of bytes read */

        /*
         * use read() to read from the connection into the inbuf,
         * writing onto the end of inbuf.
         */

        nRead = read( d->connection, d->inbuf + iStart,
            sizeof(d->inbuf) - 10 - iStart );

        if ( nRead > 0 )   /* a buffer is found */
        {
            iStart += nRead;   /* advance iStart to "new inbuf length" */

            if ( d->inbuf[iStart-1] == '\n' || d->inbuf[iStart-1] == '\r' )
                break;

//--------------> INSERT CODE BELOW HERE
            /*
             * VT100/102+ANSI keyboard code support - by Locke of NiMUD
             * Requires 'character mode' telnet option to be set on
             */
            if ( d->inbuf[(iStart-nRead)]=='\e'
              && d->inbuf[(iStart-nRead)+1]=='[' && nRead>2 )
             {
                int i=iStart-nRead;

                char akey[5];
                akey[0] = '\e';
                akey[1] = '[';
                akey[2] = d->inbuf[i+2];
                akey[3] = d->inbuf[i+3] != '~' ? '\0' : '~';
                akey[4] = '\0';
                if ( d->inbuf[i+3] == '~' ) i+=4;
                   else i+=3;

                if ( d->character ) interpret( d->character, akey );

                   /*
                    * Insert spaces in place of code
                    */
                for ( i=iStart-nRead; i<iStart+nRead; i++ ) d->inbuf[i] = ' ';
             }
//----------------------> INSERT SNIPPET COMPLETE

        }


Then, in your interpret() add the keyboard mappings, right after
implementing the Freeze command in interp.c:

Code:

    /* Active telnet mode numeric keypad support.
     * by Locke; must 'set active' to use, otherwise
     * user must hit return between each keypress.
     */
    if ( !str_cmp( argument, "[A" ) /* UP arrow */
      || !str_cmp( argument, "\e[A" ) ) { cmd_north( ch, "" ); return; }
    if ( !str_cmp( argument, "[B" ) /* DOWN arrow */
      || !str_cmp( argument, "\e[B" ) ) { cmd_south( ch, "" ); return; }
    if ( !str_cmp( argument, "[C" ) /* RIGHT arrow */
      || !str_cmp( argument, "\e[C" ) ) { cmd_east ( ch, "" ); return; }
    if ( !str_cmp( argument, "[D" ) /* LEFT arrow */
      || !str_cmp( argument, "\e[D" ) ) { cmd_west ( ch, "" ); return; }
    if ( !str_cmp( argument, "[G" ) /* Numpad Center or 5 */
      || !str_cmp( argument, "\e[G" ) ) { if ( ch->position != POS_SLEEPING )
                                          cmd_sleep( ch, "" ); else
                                          cmd_stand( ch, "" ); return; }
    if ( !str_cmp( argument, "[1~" ) /* HOME */
      || !str_cmp( argument, "\e[1~" ) ) { cmd_nw( ch, "" ); return; }
    if ( !str_cmp( argument, "[2~" ) /* INSERT */
      || !str_cmp( argument, "\e[2~" ) ){ cmd_home( ch, "" ); return; }
    if ( !str_cmp( argument, "[3~" ) /* DELETE */
      || !str_cmp( argument, "\e[3~" ) ){
              PROP_DATA *prop1 = get_eq_char( ch, WEAR_HOLD_1 );
              PROP_DATA *prop2 = get_eq_char( ch, WEAR_HOLD_2 );
              prop1 = prop1 ? prop1 : get_eq_char( ch, WEAR_WIELD_1 );
              prop2 = prop2 ? prop2 : get_eq_char( ch, WEAR_WIELD_2 );
              if ( (prop1 && IS_SET(prop1->wear_flags, ITEM_WEAR_BELT))
                || (prop2 && IS_SET(prop2->wear_flags, ITEM_WEAR_BELT)) )
              cmd_sheath( ch, "" );
              else cmd_draw( ch, "" ); return;
            }
    if ( !str_cmp( argument, "[4~" ) /* END */
      || !str_cmp( argument, "\e[4~" ) ){ cmd_sw( ch, "" ); return; }
    if ( !str_cmp( argument, "[5~" ) /* Page Up */
      || !str_cmp( argument, "\e[5~" ) ){ cmd_ne( ch, "" ); return; }
    if ( !str_cmp( argument, "[6~" ) /* Page Down */
      || !str_cmp( argument, "\e[6~" ) ){ cmd_se( ch, "" ); return; }

/*
 * You must step ahead of "buffered" keystrokes in active telnet mode.
 */
while ( *argument == '\e' ) {
 argument++;
 if ( *argument == 'A'    || *argument == 'B'
   || *argument == 'C'    || *argument == 'D'
   || *argument == 'E'    || *argument == 'F'
   || *argument == 'G'    || *argument == '0'
   || *argument == '1'    || *argument == '2'
   || *argument == '3'    || *argument == '4'
   || *argument == '5'    || *argument == '6'
   || *argument == '7'    || *argument == '8'
   || *argument == '9'  ) argument++;
 if ( *argument == '~'  ) argument++;
 }


 while ( *argument == '[' ) {
  argument++;
  if ( *argument == 'A'    || *argument == 'B'
    || *argument == 'C'    || *argument == 'D'
    || *argument == 'E'    || *argument == 'F'
    || *argument == 'G'    || *argument == '0'
    || *argument == '1'    || *argument == '2'
    || *argument == '3'    || *argument == '4'
    || *argument == '5'    || *argument == '6'
    || *argument == '7'    || *argument == '8'
    || *argument == '9'  ) argument++;
  if ( *argument == '~'  ) argument++;
  }



---------
To activate character mode,
You will have to set your telnet with Ctrl-] and then (for windows)
type "mode character", unless you employ this code, which requests
character mode from the client:

?

You should turn on local echo to go along with this feature,
or add these lines:

Code:

#define ECHO_ON_STR '\'   
#define CHARACTER_MODE_STRING '\'

if ( IS_SET(d->character->act2, PLR_CHARACTER) ) {
write_to_buffer( ECHO_ON_STR, d );
write_to_buffer( CHARACTER_MODE_STRING, d );
}

To new_descriptor():


It's good not to add that support, but instead instruct the user to
do so to allow connections from the widest number of possible
telnet applications. You should have the user toggle this option
so that the code for automatically switching to CHARACTER_MODE and
activating echo are handled during login after the MOTD in nanny.c

Then have them type 'set active' or 'config +active' or whatever to
activate this feature.

---> note this snippet is incomplete
source: http://www.mudolc.org/snippets

-Locke


Last edited by locke on Tue Feb 21, 2006 12:19 am; edited 12 times in total
Back to top
View user's profile Send private message Visit poster's website
Author Message
locke



Joined: 05 Feb 2006
Posts: 4
Location: Pittsburgh, PA

PostPosted: Mon Feb 20, 2006 9:43 pm    Post subject: Corresponding help doc Reply with quote

Code:

KEYBOARD (General)

Keyboard controls.  For most telnet applications, hitting an arrow
key, or numeric keypad key, will generate an ANSI terminal code.
This works in both VT100/102 and ANSI telnet applications.

Here are the mud's default keyboard mappings:


  _________________________
 | HOME |  UP | PGUP | INS |
 |  nw  |north|  ne  |home |
 |______|_____|______|_____|
 |  <-  |    5| ->   | DEL |
 | west |sleep| east |draw |
 |______|_____|______|_____|
 |  END | DOWN| PGDN |
 |  sw  |south|  se  |
 |______|_____|______|

It is of note that on most telnet applications, you must set the
mode to character, but in doing so, remember that these commands
can be tried by just hitting "enter" between keystrokes before
switching to Character telnet mode.

The INSERT and DELETE keys are mapped "recall" and "draw/sheath"
respectively.

Hitting "CENTER" or "Numpad-5" results in "stand/sleep"

Example:
Line-mode:
Try <home>+<enter> in your favorite telnet application

Character-mode:
Just press a key.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    mudlab.org Forum Index -> Coding All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
BBTech Template by © 2003-04 MDesign