Re: [CODE] Metaserver client-side functions

From: Mike Stilson (
Date: 09/20/02

On Fri, Sep 20, 2002 at 03:26:05PM +0200, Torgny Bjers wrote:
>From: "Mike Stilson" <mike@VELGARIAN.SYTES.NET>
>> On Fri, Sep 20, 2002 at 12:36:06AM -0700, Mathew Earle Reuther wrote:
>> >On Thu, 19 Sep 2002, Mike Stilson wrote:
>> >> Just wondered if there's any interest in this.
>> >
>> >If this is something used by other muds, I'd certainly place it on
>> >once I'm in production. :)  (Which, according to the latest chickens
>> >have my spiritual advisor slaughter will be sometime in 2005.)
>> It can still be considered a work in progress, and I do need some
>> testers.  (There's only so much you can test locally).
>What do we need to help you test this?  I wouldn't mind giving you a
>hand with it.

All I need it people to add the following code to comm.c, and add a line
in heartbeat() to call it.   I recommend putting them at the bottom of
the file, makes it lots easier to change them for upgrades, which I'm
not gonna probably do in patch format.

I'm posting them to the list because I don't consider them anywhere even
remotely close to being done enough to go to the ftp site.  Until it's
done, anyone wanting updates can ask me offlist and I'll be happy to
send them.

[--- cut here ---]
struct report_data {
        int ok;    /* Is everything set up properly? */
        int socket; /* persistent udp socket */
        struct sockaddr_in addr; /* Store this stuff for the sendto() call */
        struct hostent *serv_data;
} report;

#define MUDNAME "Define your mudname here"
#define SERVER ""

void setup_report(void)
        bzero(&report.addr, sizeof(report.addr));

        /* unless we make it to the end, don't report anything */
        report.ok = FALSE;

        /* create the socket */
        if((report.socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
                log("SYSERR: Can't open status socket: %m");

        /* get hostent info for the server */
        if(!(report.serv_data = gethostbyname(SERVER))) {
                log("SYSERR: Can't get address of status server: %m");

        /* and connect to it. */
        if(connect(report.socket, (struct sockaddr *)&report.addr, sizeof(report.addr)) < 0) {
                log("SYSERR: Can't connect: %m");

        /* make sure it's non-blocking */

        /* set up report.addr with all the info */
        report.addr.sin_family = AF_INET;
        report.addr.sin_port = htons(5000);
        memcpy(&report.addr.sin_addr, report.serv_data->h_addr, report.serv_data->h_length);

        /* if we got this far, then everything is (hopefully) set up ok */
        report.ok = TRUE;

void report_status(void)
        char stats[128];
        extern time_t boot_time;
        struct descriptor_data *d;
        int users = 0;

        /* if everything isn't set up ok, report.ok is false, so just return */
        if(!report.ok) return;

        /* count the connected users */
        for(d = descriptor_list; d; d = d->next, users++);

        /* make the status string to send */
        snprintf(stats, 128, "%s*%d*%d", MUDNAME, boot_time, users);

        /* send the packet.  make sure we aren't blocking, etc. */
        if(sendto(report.socket, stats, sizeof(stats), MSG_DONTWAIT, (struct sockaddr *)&report.addr, sizeof(report.addr)) < 0) {
                log("SYSERR: sendto() %m");
[--- end cut ---]

in heartbeat.c, add the call to report_status().
Put it where you want, but nothing longer than 15 minutes (15 * 60 * PASSES_PER_SEC)
as that's how long w/o receiving any data that I expire muds.

I've been testing it with one minute and it's been working fine.  3 to 5
minutes would probably be just fine.  If you REALLY want to keep stuff
accurate, you could also add calls to it when someone logs in/out, but I
don't really recommend it.

This code should be barely considered alpha.  It works, and that's about
all that can be said about it.  Thanks in advance to anyone helping me
test it, I'll try not to hammer you with updates and the like.
And just to avoid spamming the list, send flames, comments, suggestions,
etc to me offlist and I'll post some summary information once in a


oh yeah.  To check the list, just telnet to 5000.
type "list" to see the currently registered muds, type "quit" to leave
nicely, and if you feel the need to talk to anyone else (I didn't write
an irc server here, so there isn't even a "who" list so you ain't gonna
know if there even IS anyone else) just type whatever you want.. it'll
get sent to everyone.  Again, the server, too, is barely alpha, so it
might display some wierd things.  And trying to crash it will probably
work by faking the udp packet.  I won't be exceptionally mad about it,
but if people want to take some wierd pleasure in doing it I'll just
quit running it.  Report bugs though :)


   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT