Index: constants.h =================================================================== RCS file: /cvs/muds/tinymudserver/constants.h,v retrieving revision 1.22 retrieving revision 1.23 diff -c -r1.22 -r1.23 *** constants.h 15 Aug 2004 01:12:29 -0000 1.22 --- constants.h 15 Aug 2004 06:13:09 -0000 1.23 *************** *** 4,10 **** // configuration constants static const string MUDNAME = "BabbleMUD"; // server name ! static const string VERSION = "2.7"; // server version static const int MESSAGE_INTERVAL = 300; // seconds between tick messages // This is the time the "select" waits before timing out. --- 4,10 ---- // configuration constants static const string MUDNAME = "BabbleMUD"; // server name ! static const string VERSION = "2.8"; // server version static const int MESSAGE_INTERVAL = 300; // seconds between tick messages // This is the time the "select" waits before timing out. Index: webclient.cpp =================================================================== RCS file: /cvs/muds/tinymudserver/webclient.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** webclient.cpp 15 Aug 2004 03:12:54 -0000 1.6 --- webclient.cpp 15 Aug 2004 06:13:09 -0000 1.7 *************** *** 49,54 **** --- 49,60 ---- } }; + void DoFooter (WebClient & w) + { + w << control ().gets ("html_footer") << "\n"; + w.connstate_ = eAwaitingFinish; + } // end of DoFooter + const string SendMessage (WebClient & w, int iWhich) { string sMessage; *************** *** 188,243 **** data [URLDecode (sItem.substr (0, i))] = URLDecode (sItem.substr (i + 1, string::npos)); } // end of AssembleValue - - // process data (eg. POST data) - void ProcessData (WebClient & w) - { - string::size_type i; - - do - { - i = w.inbuf_.find ('&'); - if (i != string::npos) - { - AssembleValue (w.inbuf_.substr (0, i), w.postData_); - w.inbuf_.erase (0, i + 1); - } - } while (i != string::npos); - - AssembleValue (w.inbuf_, w.postData_); - - w.inbuf_.clear (); - - DoHeader (w, 200, "Post data"); - - w << "

" << w.URL_ << "

\n"; - w << "

Post data ...

\n"; - w << "\n"; - - if (w.postData_ ["action"] == "send_to_all" && - !w.postData_ ["message"].empty ()) - { - SendToAll ("\n`^** `WMessage from web client: `R" + w.postData_ ["message"] + "`v\n"); - w << "

Message " << FixHTML (w.postData_ ["message"]) - << " sent to everybody.

"; - } - - DoFooter (w); - - } // end of ProcessData - void ShowError (WebClient & w, const string & what) { w << "

" --- 194,199 ---- *************** *** 248,254 **** DoFooter (w); } // end of ShowError ! void ProcessGet (WebClient & w, const bool headonly) { static WebHandlerMap & webhandlermap = getWebHandlerMap (); --- 204,210 ---- DoFooter (w); } // end of ShowError ! void ProcessPage (WebClient & w) { static WebHandlerMap & webhandlermap = getWebHandlerMap (); *************** *** 314,319 **** --- 270,276 ---- try { handlerIter->second (w); // call appropriate handler + DoFooter (w); // make sure we output a footer return; } catch (runtime_error & e) *************** *** 372,381 **** w << "Last-Modified: " << modifiedDateString << "\n"; w << "\n"; ! if (headonly) { w.CloseFile (); ! w.connstate_ = eAwaitingFinish; } size_t iRead = fread (fbuf, 1, sizeof fbuf, w.file_); --- 329,340 ---- w << "Last-Modified: " << modifiedDateString << "\n"; w << "\n"; ! // header only wanted, all done ! if (w.command_ == "HEAD") { w.CloseFile (); ! w.connstate_ = eAwaitingFinish; ! return; } size_t iRead = fread (fbuf, 1, sizeof fbuf, w.file_); *************** *** 398,412 **** } // end of WebClient::ProcessGet void ProcessCompleteRequest (WebClient & w) { cout << "Processing request ... " << w.command_ << " " << w.URL_ << endl; ! if (w.command_ == "GET") ! ProcessGet (w, false); ! else if (w.command_ == "HEAD") ! ProcessGet (w, true); else SendError (w, 501); // not implemented --- 357,392 ---- } // end of WebClient::ProcessGet + // process data (eg. POST data) + void ProcessData (WebClient & w) + { + string::size_type i; + + do + { + i = w.inbuf_.find ('&'); + if (i != string::npos) + { + AssembleValue (w.inbuf_.substr (0, i), w.postData_); + w.inbuf_.erase (0, i + 1); + } + } while (i != string::npos); + + AssembleValue (w.inbuf_, w.postData_); + + w.inbuf_.clear (); + + ProcessPage (w); + + } // end of ProcessData + void ProcessCompleteRequest (WebClient & w) { cout << "Processing request ... " << w.command_ << " " << w.URL_ << endl; ! if (w.command_ == "GET" || w.command_ == "HEAD") ! ProcessPage (w); else SendError (w, 501); // not implemented Index: webclient.h =================================================================== RCS file: /cvs/muds/tinymudserver/webclient.h,v retrieving revision 1.4 retrieving revision 1.5 diff -c -r1.4 -r1.5 *** webclient.h 15 Aug 2004 01:12:29 -0000 1.4 --- webclient.h 15 Aug 2004 06:13:09 -0000 1.5 *************** *** 186,191 **** const int messageType = 200, // type, eg, 200, 404 const string & title = "", // what to put into title const bool sendBody = true); // if true, start a message body - void DoFooter (WebClient & w); #endif // BABBLEMUD_WEBCLIENT_H --- 186,190 ---- Index: webpages.cpp =================================================================== RCS file: /cvs/muds/tinymudserver/webpages.cpp,v retrieving revision 1.3 retrieving revision 1.5 diff -c -r1.3 -r1.5 *** webpages.cpp 15 Aug 2004 01:12:29 -0000 1.3 --- webpages.cpp 15 Aug 2004 07:10:54 -0000 1.5 *************** *** 54,65 **** return message; } // end of DoHeader - void DoFooter (WebClient & w) - { - w << control ().gets ("html_footer") << "\n"; - w.connstate_ = eAwaitingFinish; - } // end of DoFooter - // show things template struct showWebAttribute --- 54,59 ---- *************** *** 68,81 **** // ctor showWebAttribute (WebClient & w, const string & name) : w_ (w) { ! w_ << "" << ! "\n"; } void operator() (const pair & data) { ! w_ << "" << ! "\n"; } }; // end of showWebAttribute --- 62,75 ---- // ctor showWebAttribute (WebClient & w, const string & name) : w_ (w) { ! w_ << "" << ! "\n"; } void operator() (const pair & data) { ! w_ << "" << ! "\n"; } }; // end of showWebAttribute *************** *** 83,89 **** static void ShowWebThing (WebClient & w, const thing & o) { ! w << "

" << FixHTML (name) << "
" << FixHTML (data.first) << "" << FixHTML (MAKE_STRING (data.second)) << "
" << FixHTML (name) << "
" << FixHTML (data.first) << "" << FixHTML (MAKE_STRING (data.second)) << "
\n"; // string data if (!o.get_sdata ().empty ()) for_each_noreturn (ISEQ (o.get_sdata ()), showWebAttribute (w, "Strings")); --- 77,83 ---- static void ShowWebThing (WebClient & w, const thing & o) { ! w << "

\n"; // string data if (!o.get_sdata ().empty ()) for_each_noreturn (ISEQ (o.get_sdata ()), showWebAttribute (w, "Strings")); *************** *** 104,111 **** --- 98,161 ---- } // end of ShowWebThing + struct fWebShowThing + { + WebClient & w_; + int count_; + const string & name_; + + // ctor + fWebShowThing (WebClient & w, const string & name) : w_ (w), count_ (0), name_ (name) {} + + void operator() (const Object & thing) + { + w_ << "
  • " << name_ << " " << ++count_ << "\n"; + ShowWebThing (w_, thing); + w_ << "


    \n"; + + if (!thing.contents_.empty ()) + { + w_ << "

    Contents

    \n"; + } + + } + }; // end of fWebShowThing + + void WebShowOnePlayer (WebClient & w) + { + string name = w.getData_ ["name"]; + + DoHeader (w, 200, "Player " + name); + + Character * p = FindPlayer (name); + + if (!p) + throw runtime_error (name + " is not playing."); + + ShowWebThing (w, *p); + + w << "

    Inventory

    \n"; + + w << "

    "; + w << "Show who list\n"; + + } + void WebWhoList (WebClient & w) { + + if (!w.getData_ ["name"].empty ()) + { + WebShowOnePlayer (w); + return; + } + DoHeader (w, 200, "Who List"); w << "

    Who list

    \n"; *************** *** 119,126 **** Player * pTarget = *iter; // the player if (pTarget->IsPlaying ()) { ! w << "
  • " << FixHTML (pTarget->gets (NAME)) << ! " in room " << pTarget->geti (ROOM) << "\n"; ++count; } // end of if playing } // end of doing each player --- 169,177 ---- Player * pTarget = *iter; // the player if (pTarget->IsPlaying ()) { ! w << "
  • gets (NAME) << "\">" ! << FixHTML (pTarget->gets (NAME)) << ! " in room " << pTarget->geti (ROOM) << "\n"; ++count; } // end of if playing } // end of doing each player *************** *** 129,154 **** w << "

    " << count << " player(s)

    \n"; - DoFooter (w); } // end of WebWhoList - struct fWebShowThing - { - WebClient & w_; - int count_; - const string & name_; - - // ctor - fWebShowThing (WebClient & w, const string & name) : w_ (w), count_ (0), name_ (name) {} - - void operator() (const Object & thing) - { - w_ << "
  • " << name_ << " " << ++count_ << "\n"; - ShowWebThing (w_, thing); - w_ << "


    \n"; - } - }; // end of fWebShowThing - void WebShowOneRoom (WebClient & w) { DoHeader (w, 200, "Room"); --- 180,187 ---- *************** *** 160,170 **** RoomMap::const_iterator iter = rooms ().find (vnum); if (iter == rooms ().end ()) ! { ! w << "

    Room " << vnum << " does not exist.

    \n"; ! DoFooter (w); ! return; ! } Room * r = iter->second; --- 193,199 ---- RoomMap::const_iterator iter = rooms ().find (vnum); if (iter == rooms ().end ()) ! throw runtime_error ("Room " + w.getData_ ["room"] + " does not exist."); Room * r = iter->second; *************** *** 178,186 **** w << "

    "; w << "Show rooms list\n"; ! ! DoFooter (w); ! } // end of WebShowOneRoom struct fWebShowOneRoom --- 207,213 ---- w << "

    "; w << "Show rooms list\n"; ! } // end of WebShowOneRoom struct fWebShowOneRoom *************** *** 218,231 **** int count = for_each (ISEQ (rooms ()), fWebShowOneRoom (w)).GetCount (); w << "\n"; w << "

    " << count << " room(s)

    \n"; - DoFooter (w); } // end of WebRoomList void WebControlList (WebClient & w) { DoHeader (w, 200, "Control data"); ShowWebThing (w, control ()); - DoFooter (w); } // end of WebControlList void WebShowOneSpell (WebClient & w) --- 245,256 ---- *************** *** 249,257 **** w << "

    "; w << "Show spells list\n"; ! ! DoFooter (w); ! } // end of WebShowOneSpell struct fWebShowOneSpell --- 274,280 ---- w << "

    "; w << "Show spells list\n"; ! } // end of WebShowOneSpell struct fWebShowOneSpell *************** *** 292,300 **** int count = for_each (ISEQ (spells), fWebShowOneSpell (w)).GetCount (); w << "\n"; w << "

    " << count << " spell(s)

    \n"; - DoFooter (w); } // end of WebSpellList static int LoadWebMap () { static WebHandlerMap & webmap = getWebHandlerMap (); --- 315,340 ---- int count = for_each (ISEQ (spells), fWebShowOneSpell (w)).GetCount (); w << "\n"; w << "

    " << count << " spell(s)

    \n"; } // end of WebSpellList + void WebSend (WebClient & w) + { + + DoHeader (w, 200, "Send message"); + w << "

    Send message

    \n"; + + if (w.postData_ ["action"] == "send_to_all" && + !w.postData_ ["message"].empty ()) + { + SendToAll ("\n`^** `WMessage from web client: `R" + w.postData_ ["message"] + "`v\n"); + w << "

    Message " << FixHTML (w.postData_ ["message"]) + << " sent to everybody.

    "; + } + else + throw runtime_error ("No message"); + + } // end of WebSend + static int LoadWebMap () { static WebHandlerMap & webmap = getWebHandlerMap (); *************** *** 305,310 **** --- 345,351 ---- WEBPAGE (WebRoomList); // list of rooms WEBPAGE (WebControlList); // control data WEBPAGE (WebSpellList); // list of spells + WEBPAGE (WebSend); // send a message return 0; } // end of LoadWebMap Index: html/index.htm =================================================================== RCS file: /cvs/muds/tinymudserver/html/index.htm,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** html/index.htm 15 Aug 2004 03:12:54 -0000 1.2 --- html/index.htm 15 Aug 2004 06:13:09 -0000 1.3 *************** *** 17,23 **** !

    Example of sending data

    --- 17,23 ---- !

    Example of sending data

    Index: players/Nick.player.xml =================================================================== RCS file: /cvs/muds/tinymudserver/players/Nick.player.xml,v retrieving revision 1.43 retrieving revision 1.45 diff -c -r1.43 -r1.45 *** players/Nick.player.xml 15 Aug 2004 03:12:54 -0000 1.43 --- players/Nick.player.xml 15 Aug 2004 07:10:54 -0000 1.45 *************** *** 1,15 **** ! ! ! ! --- 99,109 ---- password_length_minimum="6" password_length_unique="4" port="4000" ! webport="4080" /> *************** *** 147,178 **** ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! --- 195,233 ---- ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !