/*    /www/gateways/mudlist.c
 *    from Nightmare IV
 *    a gateway to produce a mudlist for connecting to muds
 *    created by Descartes of Borg 940524
 *    Tweaked a little to work with DNS by Leto@Earth
 */

#include <mudlib.h>
#include <net/daemons.h>
#include <net/dns.h>

inherit DAEMON;

string gateway(string unused) {
    mapping borg;
    string *muds;
    string str;
    int i, maxi;

    maxi = sizeof(muds=sort_array(keys(borg=(mapping)DNS_MASTER->query_muds()),
      "alphabetize_muds", this_object()));
    str = sprintf("<TITLE>%s Mudlist Gateway</TITLE><h1>"
      "%s is aware of the following %d muds.</h1><OL>",
         capitalize(mud_name()),
     capitalize(mud_name()),maxi);
    for(i=0; i<maxi; i++)
      str += sprintf("<LI><a href=telnet://%s:%s>%s</a> (%s %s), Driver: %s, "
        "Mudlib: %s %s\n", borg[muds[i]]["HOSTADDRESS"], borg[muds[i]]["PORT"],
        borg[muds[i]]["NAME"], borg[muds[i]]["HOSTADDRESS"],
        (borg[muds[i]]["PORT"]), 
        (borg[muds[i]]["DRIVER"] ? borg[muds[i]]["DRIVER"] : "Unknown"),
        (borg[muds[i]]["MUDLIB"] ? borg[muds[i]]["MUDLIB"] : "Unknown"),
        (borg[muds[i]]["VERSION"] ? borg[muds[i]]["VERSION"] : ""));
str += "</OL>This mudlist is maintained dynamically through the Intermud network system";
    return str;
}

int alphabetize_muds(string a, string b) { return strcmp(a, b); }
