Re: [Telnet] Altering input modes

From: Daniel Koepke (dkoepke@CALIFORNIA.COM)
Date: 09/08/98


>    Thanks for your response; I did try this, and although it didn't work
> for me, while trying to figure out why I found out something sort of
> interesting: process_input( ) isn't being called each time a key is
> pushed.  It's only being called when I press that big one above my right
> shift key.  Damn.
>    Any other suggestions?

Okay, I admit it: I did this a while ago and have been too lazy to send it
along to the list.  I wrote it in order to autodetect ANSI support (the
code to do this isn't included here) before falling back on the QANSI
state (so, in essence, it was an extension of my QANSI patch), but you can
use it for whatever you want.  Note: this is ugly.  It's not clean by a
long-shot.  The actual char-by-char mode is inefficient and probably only
supported by 'telnet'.  Even further, 'telnet' will send you some stuff
back in an effort to negotiate with you.  It's "safe" to ignore it.

In structs.h, at the top,

  #define READFUN(name) int (name)(struct descriptor_data * t)

and then add to descriptor_data,

  READFUN(*read);

In comm.c,

  READFUN(process_input);
  void char_mode(struct descriptor_data * d, READFUN(r));
  void line_mode(struct descriptor_data * d);

change "if (process_input(d) < 0) close_socket(d);" to,

    if ((*d->read)(d) < 0)
      close_socket(d);

add,

  void char_mode(struct descriptor_data * d, READFUN(r))
  {
    char on_string[] = {
      (char) IAC,
      (char) WILL,
      (char) TELOPT_SGA,
      (char) 0,
    }, off_string[] = {
      (char) IAC,
      (char) WONT,
      (char) TELOPT_LINEMODE,
      (char) 0,
    };

    d->read = r;
    SEND_TO_Q(on_string, d);
    SEND_TO_Q(off_string, d);
    echo_off(d);
  }

  void line_mode(struct descriptor_data * d)
  {
    char off_string[] = {
      (char) IAC,
      (char) WONT,
      (char) TELOPT_SGA,
      (char) 0,
    }, on_string[] = {
      (char) IAC,
      (char) WILL,
      (char) TELOPT_LINEMODE,
      (char) 0,
    };

    d->read = process_input;
    SEND_TO_Q(off_string, d);
    SEND_TO_Q(on_string, d);
    echo_on(d);
  }

Your read function will look like this,

  READFUN(char_input)
  {
    char in[2];
    int bytes_read;

    /* read one character */
    bytes_read = perform_socket_read(t->descriptor, in, 1);
    if (bytes_read <= 0) return bytes_read;

    .
    .
    .
  }

That should be all.  I might have missed something of vital importance.
Bah, hope it helps.

-dak : Go McGwire!  62 and counting...


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST