[ScryMUD] SVN Commit Info r903 - trunk/mud/grrmud/server

scrymud at wanfear.com scrymud at wanfear.com
Fri Mar 2 00:04:19 PST 2007


Author: eroper
Date: 2007-03-02 00:04:18 -0800 (Fri, 02 Mar 2007)
New Revision: 903

Modified:
   trunk/mud/grrmud/server/telnet_handler.cc
   trunk/mud/grrmud/server/telnet_handler.h
Log:
Small functional changes to the telnet handler.

Null bytes received in text streams (not telnet options / negotiations are now
ignored. 

Added a ST_CR state; used when we receive a carriage-return in a text stream.
The rfc says we may get CR-NULL or CR-LF. CR-LF is to be treated as a single
unit (we now do so) and CR-NULL (for us) means the same thing. At least Linux
telnet uses CR-NULL's by default when SGA (suppress go ahead) is negotiated.

0x7F (delete) and 0x08 (backspace) are both treated as backspace now.

Added support for the following telnet commands:
 NOP: do nothing / no operation
 EC: erase character (untested)
 EL: erase line (untested)

Most of this is being done so that we can support non-linemode based
functionality in the future. (single-key menu options, etc)


Modified: trunk/mud/grrmud/server/telnet_handler.cc
===================================================================
--- trunk/mud/grrmud/server/telnet_handler.cc	2007-02-27 10:19:30 UTC (rev 902)
+++ trunk/mud/grrmud/server/telnet_handler.cc	2007-03-02 08:04:18 UTC (rev 903)
@@ -50,7 +50,6 @@
    for(unsigned int i=0;i<sizeof(my_request_states);my_request_states[i++]=false);
    for(unsigned int i=0;i<sizeof(my_option_states);my_option_states[i++]=false);
 
-
    my_request_states[TELOPT_NAWS] = true;
    send(DO,TELOPT_NAWS);
 
@@ -59,7 +58,6 @@
 
    my_offer_states[TELOPT_EOR] = true;
    send(WILL,TELOPT_EOR);
-   send(WONT,TELOPT_ECHO);
 
 }//Constructor: TelnetHandler
 
@@ -126,6 +124,12 @@
             my_critter->pc->output += end_of_record();
          break;
 
+         /* We're not allowing this yet.
+         case TELOPT_SGA:
+            my_option_states[opt] = will = true;
+         break;
+         */
+
          default:
             need_to_respond = true;
             will = false;
@@ -278,23 +282,26 @@
                      case ST_NORM:
                         switch ( *p ) {
 
+                           case 0x00://null
+                              //these should only ever be received in text
+                              //mode after a carriage-return. Because our
+                              //text parsing later on relies on \0 terminated
+                              //strings, we make sure this isn't ever allowed
+                              //beyond this point. I'm pretty sure that the
+                              //RFC doesn't require this, but ScryMUD does ;)
+                           break;
+
                            case 0x08://backspace
                               if ( out_buf.size() > 0 ) {
+                                 cout << "Doing backspace!" << endl;
                                  out_buf.resize(out_buf.size()-1);
                               }
                            break;
 
-                           case 0x0D://carriage return
-                              //do nothing, we don't like \r's around here.
+                           case 0x0D://carriage-return aka \r
+                              current_text_state = ST_CR;
                            break;
 
-                           case 0x0A://newline
-                              out_buf += *p;
-                              my_critter->pc->input += out_buf.c_str();
-                              out_buf.clear();
-                              parsed_full_command = true;
-                           break;
-
                            case ';':
                               current_text_state = ST_SEMICOLON;
                            break;
@@ -313,6 +320,7 @@
                            break;
 
                            case 0x08://backspace
+                           case 0x7F://delete
                               if ( out_buf.size() > 0 ) {
                                  out_buf.resize(out_buf.size()-1);
                               }
@@ -328,6 +336,27 @@
                         current_text_state = ST_NORM;
                      break;
 
+                     case ST_CR:
+                     //rfc-854 says we can end a line with cr-lf or cr-null.
+                     //Technically they mean different things, but we'll
+                     //pretend for a moment that they don't.
+                     switch ( *p ) {
+
+                        case 0x00://null
+                        case 0x0A://linefeed aka \n
+                           out_buf += '\n';
+                           my_critter->pc->input += out_buf.c_str();
+                           out_buf.clear();
+                           parsed_full_command = true;
+                           current_text_state = ST_NORM;
+                        break;
+
+                        default://if we're here, I have no idea why
+                           current_text_state = ST_NORM;
+                        break;
+
+                     }
+
                   }//switch(current_text_state)
                break;
             };//ST_TEXT: switch(*p)
@@ -360,6 +389,22 @@
                   current_state = ST_SB;
                break;
 
+               case NOP://null operation
+                  current_state = ST_TEXT;
+               break;
+
+               case EC://erase character
+                  if ( out_buf.size() > 0 ) {
+                     out_buf.resize(out_buf.size()-1);
+                  }
+                  current_state = ST_TEXT;
+               break;
+
+               case EL://erase line
+                  out_buf.clear();
+                  current_state = ST_TEXT;
+               break;
+
                default:
                   //invalid transistion
                   current_state = ST_TEXT;
@@ -406,7 +451,7 @@
             };
          break;
 
-         case ST_SB_IAC:
+         case ST_SB_IAC://got an IAC in a sub-option
             switch (*p) {
 
                case IAC://escaped IAC character.

Modified: trunk/mud/grrmud/server/telnet_handler.h
===================================================================
--- trunk/mud/grrmud/server/telnet_handler.h	2007-02-27 10:19:30 UTC (rev 902)
+++ trunk/mud/grrmud/server/telnet_handler.h	2007-03-02 08:04:18 UTC (rev 903)
@@ -37,7 +37,7 @@
       static const char ttype_req_str[];
 
       enum state { ST_TEXT, ST_IAC, ST_DO, ST_DONT, ST_WILL, ST_WONT, ST_SB, ST_SB_IAC };
-      enum text_state { ST_NORM, ST_SEMICOLON };
+      enum text_state { ST_NORM, ST_SEMICOLON, ST_CR };
 
       state current_state;
       text_state current_text_state;




More information about the ScryMUD mailing list