[ScryMUD] SVN Commit Info r888 - trunk/mud/grrmud/server
scrymud at wanfear.com
scrymud at wanfear.com
Fri Feb 23 01:27:57 PST 2007
Author: eroper
Date: 2007-02-23 01:27:57 -0800 (Fri, 23 Feb 2007)
New Revision: 888
Added:
trunk/mud/grrmud/server/hegemon_handler.h
trunk/mud/grrmud/server/protocol_handler.h
trunk/mud/grrmud/server/telnet_handler.cc
trunk/mud/grrmud/server/telnet_handler.h
Log:
Start of work on a generalized ProtocolHandler interface.
Added: trunk/mud/grrmud/server/hegemon_handler.h
===================================================================
--- trunk/mud/grrmud/server/hegemon_handler.h (rev 0)
+++ trunk/mud/grrmud/server/hegemon_handler.h 2007-02-23 09:27:57 UTC (rev 888)
@@ -0,0 +1,49 @@
+// $Id$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 2007 Edward Roper
+//
+//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.
+//
+// To contact the Author, Edward Roper: edro <- at -> wanfear.net
+//
+
+#ifndef GRRMUD_HEGEMON_HANDLER
+#define GRRMUD_HEGEMON_HANDLER
+
+#include "protocol_handler.h"
+
+class HegemonHandler : public ProtocolHandler {
+
+ protected:
+ static int _cnt;
+
+ critter* my_critter;
+
+ public:
+
+ static int getInstanceCount() { return HegemonHandler::_cnt; }
+
+ HegemonHandler(critter *c_ptr) : my_critter(c_ptr) { HegemonHandler::_cnt++; };
+ ~HegemonHandler() { HegemonHandler::_cnt--; };
+
+ void parse(const char* input_buf) { my_critter->pc->input += input_buf; }
+ void toggle_echo() { }
+ const char* end_of_record() const { return(""); }
+};
+
+
+#endif
Property changes on: trunk/mud/grrmud/server/hegemon_handler.h
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Added: trunk/mud/grrmud/server/protocol_handler.h
===================================================================
--- trunk/mud/grrmud/server/protocol_handler.h (rev 0)
+++ trunk/mud/grrmud/server/protocol_handler.h 2007-02-23 09:27:57 UTC (rev 888)
@@ -0,0 +1,75 @@
+// $Id$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 2007 Edward Roper
+//
+//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.
+//
+// To contact the Author, Edward Roper: edro <- at -> wanfear.net
+
+// --------------------------------------------------------------------------
+// The general idea here is that every connection starts with a NullHandler.
+// This handler essentially implements the ProtocolHandler interface but
+// passes things along as they are. Once a client type is determined during
+// the login process the NullHandler is delete'd and replaced with a new
+// handler of the more specific and appropriate type.
+//
+// Also worth mentioning is that the interface is currently only designed to
+// provide input (to the server) filtering. The lack of an output filter is
+// the result of having not yet finalized a replacement socket class and
+// therefore not being certain what said interface should look like. This is
+// obviously important to implement at a later date. In particular both
+// Hegemon and Telnet expect certain characters/sequences to be escaped.
+// --------------------------------------------------------------------------
+
+#ifndef GRRMUD_PROTOCOL_HANDLER
+#define GRRMUD_PROTOCOL_HANDLER
+
+class ProtocolHandler {
+ public:
+
+ virtual ~ProtocolHandler() { };
+
+ // do any necessary parsing, stick the resulting data (if any) in the pc's
+ // input buffer.
+ virtual void parse(const char* input_buf);
+
+ // toggle server-side echoing of input
+ virtual void toggle_echo();
+
+ // return a string used to mark end-of-record (player prompt)
+ virtual const char* end_of_record();
+};//class ProtocolHandler
+
+class NullHandler : public ProtocolHandler {
+ protected:
+ static int _cnt;
+
+ critter* my_critter;
+
+ public:
+
+ static int getInstanceCount() { return NullHandler::_cnt; }
+
+ NullHandler(critter *c_ptr) : my_critter(c_ptr) { NullHandler::_cnt++; };
+ ~NullHandler() { NullHandler::_cnt--; };
+
+ void parse(const char* input_buf) { my_critter->pc->input += input_buf; }
+ void toggle_echo() { return; }
+ const char* end_of_record() const { return(""); }
+};//class NullHandler
+
+#endif
Property changes on: trunk/mud/grrmud/server/protocol_handler.h
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Added: trunk/mud/grrmud/server/telnet_handler.cc
===================================================================
--- trunk/mud/grrmud/server/telnet_handler.cc (rev 0)
+++ trunk/mud/grrmud/server/telnet_handler.cc 2007-02-23 09:27:57 UTC (rev 888)
@@ -0,0 +1,188 @@
+// $Id$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 2007 Edward Roper
+//
+//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.
+//
+// To contact the Author, Edward Roper: edro <- at -> wanfear.net
+//
+
+#include "telnet_handler.h"
+
+TelnetHandler::TelnetHandler(critter* c_ptr) {
+
+ TelnetHandler::_cnt++;
+
+ my_critter = c_ptr;
+ current_state = ST_TEXT;
+
+ //memset is probably faster, but oh well.
+ for(int i=0;i<sizeof(my_want_states);my_want_states[i++]=false);
+ for(int i=0;i<sizeof(my_option_states);my_option_states[i++]=false);
+
+}//Constructor: TelnetHandler
+
+//handle DOs
+void TelnetHandler::rcv_do(const int opt) {
+
+ if ( my_want_states[opt] ) {
+
+ }
+
+ switch ( opt ) {
+
+ case TELOPT_ECHO:
+ break;
+
+ case TELOPT_EOR:
+ break;
+
+ default:
+ break;
+
+ };
+
+}//TelnetHandler::rcv_do()
+
+//handle DONTs
+void TelnetHandler::rcv_dont(const int opt) {
+}//TelnetHandler::rcv_dont()
+
+//handle WILLs
+void TelnetHandler::rcv_will(const int opt) {
+}//TelnetHandler::rcv_will()
+
+//handle WONTs
+void TelnetHandler::rcv_wont(const int opt) {
+ // The only thing that might come back to us here is NAWS
+ // as I don't plan on asking the client to do much more than
+ // that.
+}//TelnetHandler::rcv_wont()
+
+void TelnetHandler::parse(const char* input_buf) {
+ using namespace telnet;
+
+ const char* p = input_buf;
+
+ while ( *p ) {
+
+ switch ( current_state ) {
+
+ case ST_TEXT:
+ switch (*p) {
+
+ case IAC:
+ current_state = ST_IAC;
+ break;
+
+ default:
+ my_critter->pc->input += *p;
+ break;
+ };
+ break;
+
+ case ST_IAC:
+ switch (*p) {
+
+ case IAC://escaped IAC
+ my_critter->pc->input += *p;
+ break;
+
+ case DO:
+ current_state = ST_DO;
+ break;
+
+ case DONT:
+ current_state = ST_DONT;
+ break;
+
+ case WILL:
+ current_state = ST_WILL;
+ break;
+
+ case WONT:
+ current_state = ST_WONT;
+ break;
+
+ case SB://start option sub-negotiation
+ current_state = ST_SB;
+ break;
+
+ default:
+ break;
+ };
+ break;
+
+ case ST_DO:
+ rcv_do(*p);
+ break;
+
+ case ST_DONT:
+ rcv_dont(*p);
+ break;
+
+ case ST_WILL:
+ rcv_will(*p);
+ break;
+
+ case ST_WONT:
+ rcv_wont(*p);
+ break;
+
+ case ST_SB://processing a sub-option datastream
+ switch (*p) {
+
+ case IAC:
+ current_state = ST_SB_IAC;
+ break;
+
+ default://default here is to append to sb_buf
+ // sanity check this to prevent resource exhaustion from a
+ // rogue client
+ sb_buf += *p;
+ if ( sb_buf.Strlen() > 256 ) {
+ current_state = ST_TEXT;
+ sb_buf.clear();
+ }
+ break;
+ };
+ break;
+
+ case ST_SB_IAC:
+ switch (*p) {
+
+ case IAC:
+ sb_buf += *p;
+ break;
+
+ case SE://end of sub-option data
+ sb_buf.clear();
+ break;
+
+ default:
+ //this state transistion is not valid
+ break;
+
+ };
+ break;
+
+ };//switch ( telnet_state )
+
+ p++;
+ }//while there's more input
+
+}//TelnetHandler::parse()
Property changes on: trunk/mud/grrmud/server/telnet_handler.cc
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Added: trunk/mud/grrmud/server/telnet_handler.h
===================================================================
--- trunk/mud/grrmud/server/telnet_handler.h (rev 0)
+++ trunk/mud/grrmud/server/telnet_handler.h 2007-02-23 09:27:57 UTC (rev 888)
@@ -0,0 +1,68 @@
+// $Id$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 2007 Edward Roper
+//
+//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.
+//
+// To contact the Author, Edward Roper: edro <- at -> wanfear.net
+//
+
+#ifndef GRRMUD_TELNET_HANDLER
+#define GRRMUD_TELNET_HANDLER
+
+#include "string2.h"
+#include "critter.h"
+#include "protocol_handler.h"
+
+namespace telnet {
+
+#include "telnet.h"
+
+};
+
+class TelnetHandler : public ProtocolHandler {
+
+ protected:
+ static int _cnt;
+
+ enum state { ST_TEXT, ST_IAC, ST_DO, ST_DONT, ST_WILL, ST_WONT, ST_SB, ST_SB_IAC };
+
+ state current_state;
+ String sb_buf;
+ String eor_str;
+ critter* my_critter;
+
+ bool my_want_states[256]; //things I've requested or offered.
+ bool my_option_states[256];//the current state of things.
+
+ public:
+ TelnetHandler(critter* c_ptr);
+ ~TelnetHandler() { TelnetHandler::_cnt--; };
+
+ void parse(const char* input_buf);
+
+ void toggle_echo() { }
+ const char* end_of_record() const { return( (const char*)eor_str ); }
+
+ void rcv_do(int opt);
+ void rcv_dont(int opt);
+ void rcv_will(int opt);
+ void rcv_wont(int opt);
+
+};
+
+#endif
Property changes on: trunk/mud/grrmud/server/telnet_handler.h
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
More information about the ScryMUD
mailing list