MOO-cows Mailing List Archive


Re: Inter-moo communications?

>You know I keep hearing about adding web to this moo and adding FUP to 
>this one.. internetworking moo on this one..

FUP is available from the usual place: in the
/pub/software/MOOsupport/FUP directory.  It allows access to the local (that
is, wherever the MOO is) filesystem.  Various people have written in-db
gopher, ftp, nntp, http, etc. clients; no doubt they will also respond.

In any case, making your MOO handle web requests is no big deal.  It needs
to handle connections which send an initial login command of GET or POST, like
   GET somedocumentpath someversionnumber
In the case of POST commands (for forms), you will also need to read and
decode the additional lines of text (which contain the forms data).  Finally,
you'll need to perform boot_player() on the connection, so that the Web client
knows you're done.

Similarly, enable your MOO to make web requests by opening a
network connection to the desired URL (remembering many web servers are at
port 80), sending a line of text like that above, and then receiving and
deciphering the results.  A simple example to access a hypertext dictionary:

@verb me:@webster any none none
@program me:@webster
"Usage: @webster <word>";
"Looks up the definition, etc. of the word using an online dictionary.";
"(the site should be in a separate property, not explicitly in the verb)";
site = {"", 5103};
"this routine should also be updated to take advantage of 1.8.0's new";
" connection-handling features...";
{word} = args;
"attempt to connect";
  conn = open_network_connection(@site);
except e (@errs)
  e = {"network error", "outbound connections disabled", "connection refused",
 "resource limit exceeded"}[(e in errs) + 1];
  player:tell(tostr("Unable to lookup a definition for ", word, " (", e, ")."));
"request the definition of the word";
notify(conn, "GET /prog/webster?"+word);
  add = 0;
  while(typeof(line = read(conn)) == STR)
  "site-specific code to decode the results; you may want to separate this";
  "into a separate routine";
    if (index(line, "Webster Definition"))
      add = 1;
    elseif (index(line, "Additional Lookup"))
      add = 0;
      "similarly, the following code is a very simplistic version of a";
      " separate routine to strip HTML tags from text:";
      if(line in {"<P>","<p>","<br>","<BR>"})
        line = "";
      elseif (line in {"<HR>","<hr>"})
        line = $string_utils:space(60,"-");
        while(m = match(line, "%(.*%)<%([^<>]*%)>%(.*%)"))
          line = substitute("%1%3", m);
except e (ANY)
  "nothing more to read from the connection";


Follow-Ups: References:

Home | Subject Index | Thread Index