/* Copyright (C) 1991, Marcus J. Ranum. All rights reserved. */ /* code to interface client MUDs with rwho server this is a standalone library. */ #include #include #include #include #include #include #include #include #include "defs.h" #include "params.h" #include "strings.h" #include "externs.h" #include "syscalls.h" #include "interface.h" #define DGRAMPORT 6888 /* extern char *malloc(); */ /* WOZ */ static int dgramfd = -1; static char *password; static char *localnam; static char *lcomment; static struct sockaddr_in addr; time_t senttime; /* enable RWHO and send the server a "we are up" message */ void rwhocli_setup(server,serverpw,myname,comment) char *server; char *serverpw; char *myname; char *comment; { #ifndef NO_HUGE_RESOLVER_CODE struct hostent *hp; #endif char pbuf[512]; char *p; if(dgramfd != -1) return; password = (char *)malloc(strlen(serverpw) + 1); localnam = (char *)malloc(strlen(myname) + 1); lcomment = (char *)malloc(strlen(comment) + 1); if(password == (char *)0 || localnam == (char *)0 || lcomment == (char *)0) return; strcpy(password,serverpw); strcpy(localnam,myname); strcpy(lcomment,comment); p = server; while(*p != '\0' && (*p == '.' || isdigit(*p))) p++; if(*p != '\0') { #ifndef NO_HUGE_RESOLVER_CODE if((hp = gethostbyname(server)) == (struct hostent *)0) return; bcopy(hp->h_addr, &addr.sin_addr, hp->h_length); #else return(1); #endif } else { unsigned long f; if((f = inet_addr(server)) == -1L) return; bcopy(&f, &addr.sin_addr, sizeof(f)); } addr.sin_port = htons(DGRAMPORT); addr.sin_family = AF_INET; if((dgramfd = socket(AF_INET,SOCK_DGRAM,0)) < 0) return; senttime = curtm(); sprintf(pbuf,"U\t%.20s\t%.20s\t%.20s\t%.10d\t0\t%.25s", localnam,password,localnam,senttime,comment); sendto(dgramfd,pbuf,strlen(pbuf),0,(struct sockaddr *)&addr,sizeof(addr)); } /* disable RWHO */ void rwhocli_shutdown() { char pbuf[512]; if(dgramfd != -1) { sprintf(pbuf,"D\t%.20s\t%.20s\t%.20s",localnam,password,localnam); sendto(dgramfd,pbuf,strlen(pbuf),0,(struct sockaddr *)&addr,sizeof(addr)); close(dgramfd); dgramfd = -1; free(password); free(localnam); } } /* send an update ping that we're alive */ void rwhocli_pingalive() { char pbuf[512]; if(dgramfd != -1) { sprintf(pbuf,"M\t%.20s\t%.20s\t%.20s\t%.10d\t0\t%.25s", localnam,password,localnam,senttime,lcomment); sendto(dgramfd,pbuf,strlen(pbuf),0,(struct sockaddr *)&addr,sizeof(addr)); } } /* send a "so-and-so-logged in" message */ void rwhocli_userlogin(char *uid, char *name, time_t tim) { char pbuf[512]; if(dgramfd != -1) { sprintf(pbuf,"A\t%.20s\t%.20s\t%.20s\t%.20s\t%.10d\t0\t%.20s", localnam,password,localnam,uid,tim,name); sendto(dgramfd,pbuf,strlen(pbuf),0,(struct sockaddr *)&addr,sizeof(addr)); } } /* send a "so-and-so-logged out" message */ void rwhocli_userlogout(uid) char *uid; { char pbuf[512]; if(dgramfd != -1) { sprintf(pbuf,"Z\t%.20s\t%.20s\t%.20s\t%.20s", localnam,password,localnam,uid); sendto(dgramfd,pbuf,strlen(pbuf),0,(struct sockaddr *)&addr,sizeof(addr)); } }