home *** CD-ROM | disk | FTP | other *** search
- /***********************************************
- *
- * MultiTalk - Talk Parlour
- * Multi-user Conferencing Program.
- *
- * Written and Developed by Albert Viall
- * WARNING: Do not remove this header or alter it
- * in anyway. By releasing this source code into
- * public domain, the author allows minor changes
- * to the source code to suit the needs of the
- * user.
- *
- * (C)1989
- * All Rights Reserved
- **********************************************/
-
-
- #include <stdio.h>
- #include <ctype.h>
- #include <errno.h>
- #include <signal.h>
- #include <sgtty.h>
- #include <assert.h>
- #include <sys/file.h>
- #include <sys/time.h>
- #include "multitalk.h"
-
- #define BELL '\007'
- #define WRITELOCAL "m_local"
- #define WRITEALL "m_all"
- #define SENDLOCAL "s_local"
- #define SENDALL "s_all"
- #define WHISPER "m_whisper"
- #define SENDTO "s_to"
-
- char name[40],*myroom,myfile[35];
- char prompt[8];
- int yellcnt,mypid,echo,master;
-
- /* Global structure used for loginfile
- * If you add or delete any login parameters, it must be
- * done here first
- */
- struct logon {
- char thetty[12]; /* tty filename, i.e. /dev/ttyi34 */
- char uid_name[8]; /* the system login name */
- char logon_name[40]; /* Mtalk login name */
- char room[11]; /* current room */
- int thepid; /* this structures pidnumber */
- } logon_info[MAXUSERS]; /* MAXUSERS is defined in multitalk.h */
- int cleanup();
-
- main()
- {
- int x,z,y;
- char str[256],junk[9],*myname,*getlogin(),*mytty,*ttyname();
-
- /* Perform a tidy cleanup upon signal.
- * Thank you for keeping your area clean.
- */
- signal(SIGHUP,cleanup);
- signal(SIGINT,cleanup);
- security("compare",junk); /* Am I in the purgefile? */
- master=0;
- mypid=getpid();
- myname=getlogin();
- mytty=ttyname(fileno(stdin));
- /* set global 'myfile' to search for my commfile */
- sprintf(myfile,"%s%d\0",PATH,mypid);
- fopen(myfile,"a"); /* Open my commfile just to make sure its there */
- do_login();
- sprintf(str,"### %s was just escorted into the Talk Parlour on %s.",&name,mytty);
- mwrite(SENDALL,"",str);
- get_comfile();
- do_message(myname,"read");
- yellcnt=0;
- echo=1;
- sprintf(prompt,"Say? \0"); /* set default input prompt */
-
-
- /* main processing - things branch from here */
- for(;;) {
- str[0]='\0';
- printf("%s",prompt);
- gets(str);
-
- get_room();
- /* is str a command? */
- if (str[0]=='/') {
- parse_cmd(str);
- get_comfile();
- continue;
- }
-
- /* did I input regular text? */
- if (strlen(str) != 0) {
- mwrite(WRITELOCAL,"",str);
- get_comfile();
- continue;
- }
- /* or did I hit a c/r */
- if (strlen(str) == 0) {
- get_comfile();
- continue;
- }
-
-
- } /* end of main processing */
- } /* NOTREACHED */
-
- char *
- date() /* returns date and time in the 26 character format */
- {
- long t;
- register char *s;
- char *ctime();
-
- time(&t);
- s=ctime(&t);
- return s;
- }
-
- void init_flds()
- {
- int t;
-
- /* This should be the first function to be called whenever a new
- * set of fields are incorporated into the array. It will
- * Initialize the entire array.
- */
- for (t=0; t<MAXUSERS; t++) {
- logon_info[t].thetty[0]='\0';
- logon_info[t].uid_name[0]='\0';
- logon_info[t].logon_name[0]='\0';
- logon_info[t].room[0]='\0';
- }
- }
-
-
- do_login()
- {
- /* This function performs all entry duties into the parlour
- * such as name input, status_display, and adding this entry
- * to the loginfile.
- */
- int z;
- FILE *lgnfd;
- char *ttyname(), *getlogin(), *mytty, *myname,*room;
- char byname[40],text[230];
- int accessible;
-
- mytty=ttyname(fileno(stdin));
- myname=getlogin();
- check_max(); /* check on how many slots are being used */
- /* Test access of lockfile and exit if found after user notify */
- if ((strcmp(myname,HEADMOO)==0)) goto bypass; /* Icck! I hate goto's */
- if ((accessible=access(LOCKFIL, 0))== 0) {
- putchar(BELL);
- printf("\n\nThe Task has been locked from further entry by the Caretaker.");
- printf("\nFor further information, contact the Caretaker(%s)\n\n",HEADMOO);
- exit(0);
- }
- bypass: /* like I said above, I hate goto's, but there was no choice here
- * this is written here to allow noone into Mtalk when it has been
- * LOCKED except for the Caretaker.
- */
- printf("\n___________________________________________________________");
- printf("\n Multi*Talk Talk Parlour Ver1.2 ");
- printf("\n Multi-user Conferencing Program by Albert Viall");
- printf("\n-----------------------------------------------------------\n");
- printf("\n'Please sign-in at the Register' (%s): ", myname);
- gets(byname);
-
- if (strlen(byname) ==0) {
- strcpy(byname,myname);
- strcpy(name,myname);
- } else {
- strcpy(name,byname);
- }
- room="Reception";
- myroom="Reception";
- check_users(); /* Check the uniqueness of your name. */
-
- if ((lgnfd=fopen(LGNFILE,"a")) == NULL) {
- perror("do_login/lgnfd open error");
- exit(-1);
- }
-
- fprintf(lgnfd,"%s %s %s %s %d\n",mytty,myname,&byname,room,mypid);
- fflush(lgnfd); fclose(lgnfd);
- status_display();
-
- printf("\nAll commands must be preceded by '/'. Type '/q' to Quit.\n");
- printf("Type '/?' for commands. Type '/news' for current news.\n");
- printf("\n'Greeves, the butler, escorts you into the Reception Hall.'\n");
- /* show a login entry in the dayfile for this person. */
- security("dayfile","Login ");
- return;
- }
-
- parse_cmd(str)
- char *str;
- {
- /* This function parses an Mtalk commandline which is always
- * preceded by a '/'.
- */
- FILE *lckfd,*pgfd;
- int i;
- int j=0;
- int b,y,accessible;
- char cmd[15],tty[8],ch;
- char arg[15],ttybuf[13];
- char obj[230],yell[230];
- char bro[230],t_lock[35],m_togl[35];
- char *myname,*getlogin(),*mytty,*ttyname();
-
- myname=getlogin();
- mytty=ttyname(fileno(stdin));
- obj[0]='\0';
- /* This FOR loop spans the string looking for how many spaces it can
- * find. We are only worried about the first two which would incorporate
- * a complete command I.e. CMD ARG OBJ
- */
- y=0;
- for(i=0;i<strlen(str);i++) {
- if (isspace(str[i])) y++;
- /* If there is only one command argument. Null out ARG and OBJ */
- }
- if (y==0) {
- sscanf(str,"%s",cmd);
- arg[0]='\0';
- obj[0]='\0';
- }
- /* If there are two arguments ONLY. Null out the OBJ */
- if (y==1) {
- sscanf(str,"%s %s",cmd,arg);
- obj[0]='\0';
- }
- /* More than than 2 args? Scan for CMD and ARG, then construct
- * OBJ character by character ending with a NULL.
- */
- if (y > 1) {
- y=0;
- sscanf(str,"%s %s",cmd,arg);
- for(i=0;!isspace(str[i]);i++) { continue; }
- for(i++;!isspace(str[i]);i++) { continue; }
- for(i++;i<strlen(str);i++) {
- obj[y]=str[i];
- y++;
- }
- obj[y]='\0';
- y=0;
- }
- /* printf("\nCMD:%s\nARG:%s\nOBJ:%s\n",cmd,arg,obj); */
- /* These string compares do the matching of the 'cmd' to whatever
- * command you are defining. All new commands MUST be defined in this
- * area.
- */
- if (b=strcmp(cmd, "/q") == 0) {
- do_logout();
- exit(0);
- }
- if (b=strcmp(cmd, "/?") == 0) {
- read_text(CMDS,"pause");
- return;
- }
- if (b=strcmp(cmd, "/auto") == 0) {
- auto_mode();
- return;
- }
- if (b=strcmp(cmd, "/echo") == 0) {
- if (echo==1) {
- echo=0;
- printf("Echo Mode is OFF.\n");
- return;
- }
- if (echo==0) {
- echo=1;
- printf("Echo Mode is ON.\n");
- return;
- }
- return;
- }
- if (b=strcmp(cmd, "/news") == 0) {
- read_text(NEWS,"pause");
- return;
- }
- if (b=strcmp(cmd, "/prompt") == 0) {
- if (strlen(arg)==0) {
- sprintf(prompt,"Say? \0");
- return;
- }
- sprintf(prompt,"%s \0",arg);
- return;
- }
- if (b=strcmp(cmd, "/whisper") == 0) {
- if (strlen(arg)==0) {
- printf("Usage is: /whisper [logon name] [mesg]\n");
- return;
- }
- mwrite(WHISPER,arg,obj);
- return;
- }
- /* by some of the following undocumented commands, you can see that
- * I intended for Mtalk to be somewhat humorous
- */
- if (b=strcmp(cmd, "/wear") == 0) {
- if (strlen(arg)==0) {
- sprintf(bro,"`%s just put on a lampshade.'",&name);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- sprintf(bro,"`%s just put on %s %s'",&name,arg,obj);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- if (b=strcmp(cmd, "/drink") == 0) {
- if (strlen(arg)==0) {
- sprintf(bro,"`%s just drank some Coke.'",&name);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- sprintf(bro,"`%s just drank %s %s'",&name,arg,obj);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- if (b=strcmp(cmd, "/eat") == 0) {
- if (strlen(arg)==0) {
- sprintf(bro,"`%s just ate some potato chips.'",&name);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- sprintf(bro,"`%s just ate %s %s.'",&name,arg,obj);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- if (b=strcmp(cmd, "/throwup") == 0) {
- if (strlen(arg)==0) {
- sprintf(bro,"`%s just threw up.'",&name);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- sprintf(bro,"`%s just threw up %s %s.'",&name,arg,obj);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- if (b=strcmp(cmd, "/fart") == 0) {
- sprintf(bro,"`%s just broke wind.'",&name);
- mwrite(SENDLOCAL,"",bro);
- return;
- }
- /* OKAY, Let's get back to serious */
- if (b=strcmp(cmd, "/time") == 0) {
- printf("The Time is: %s",date());
- return;
- }
- if (b=strcmp(cmd, "/status") == 0) {
- status_display();
- return;
- }
- if (b=strcmp(cmd, "/moderator") == 0) {
- if (strcmp(myroom,"Reception")!=0) {
- if (master==1) {
- moderator("unmaster","moo");
- return;
- } else {
- moderator("master","moo");
- return;
- }
- } else {
- printf("You may not Moderate the Reception Hall.\n");
- return;
- }
- }
- if (b=strcmp(cmd, "/remove") == 0) {
- if (strcmp(myroom,"Reception")!=0) {
- if (master==1) {
- moderator("remove",arg);
- return;
- }
- printf("You are not the Moderator of this table.\n");
- return;
- } else {
- printf("You may not Remove anyone from the Reception Hall.\n");
- return;
- }
- }
- if (b=strcmp(cmd, "/open") == 0) {
- if (strcmp(myroom,"Reception")!=0) {
- if (master==1) {
- moderator("open","moo");
- return;
- }
- printf("You are not the Moderator of this table.\n");
- return;
- } else {
- printf("You may not Open/Close the Reception Hall.\n");
- return;
- }
- }
- if (b=strcmp(cmd, "/close") == 0) {
- if (strcmp(myroom,"Reception")!=0) {
- if (master==1) {
- moderator("close","moo");
- return;
- }
- printf("You are not the Moderator of this table.\n");
- return;
- } else {
- printf("You may not Open/Close the Reception Hall.\n");
- return;
- }
- }
- if (b=strcmp(cmd, "/message") == 0) {
- if (strlen(arg)==0) {
- printf("You must specify someone to send it to.\n");
- return;
- }
- do_message(arg,"write");
- return;
- }
- if (b=strcmp(cmd, "/lock") == 0) {
- if (y=strcmp(myname,HEADMOO)!=0) {
- putchar(BELL);
- printf("This Command reserved for Caretaker.\n");
- return;
- }
- if ((accessible=access(LOCKFIL,0)) ==0) {
- unlink(LOCKFIL);
- security("dayfile","UNLOCK");
- mwrite(SENDALL,"","`Greeves just opened the doors to the Parlour.'");
- return;
- } else {
- fopen(LOCKFIL,"a");
- }
- mwrite(SENDALL,"","`Greeves has just bolted the doors shut. No further entry is permitted.'");
- security("dayfile","LOCK ");
- return;
- }
- if (b=strcmp(cmd, "/logoff") == 0) {
- if (y=strcmp(myname,HEADMOO)!=0) {
- putchar(BELL);
- printf("\nThis Command reserved for Caretaker.\n");
- return;
- }
- if (strlen(arg)==0) {
- printf("You must specify someone to 'logoff'.\n");
- return;
- }
- sprintf(bro,"### %s was just forcibly logged off by a Caretaker.",arg);
- logoff(arg);
- mwrite(SENDALL,"",bro);
- return;
- }
- if (b=strcmp(cmd, "/dayfile") == 0) {
- if (y=strcmp(myname,HEADMOO)!=0) {
- putchar(BELL);
- printf("\nThis Command reserved for Caretaker.\n");
- return;
- }
- printf("\nSTATUS - UID - LOGINAME - TIME DESCRIPTION\n");
- printf("=============================================\n\n");
- read_text(DAYFILE,"pause"); /* show dayfile and pause */
- return;
- }
- if (b=strcmp(cmd, "/broadcast") == 0) {
- if (y=strcmp(myname,HEADMOO)!=0) {
- putchar(BELL);
- printf("This Command reserved for Caretaker.\n");
- return;
- }
- sprintf(bro,"### BROADCAST(%s): %s %s",&name,arg,obj);
- mwrite(SENDALL,"",bro);
- return;
- }
- if (b=strcmp(cmd, "/purge") == 0) {
- if (y=strcmp(myname,HEADMOO)!=0) {
- putchar(BELL);
- printf("This Command reserved for Caretaker.\n");
- return;
- }
- security("purge",arg);
- return;
- }
- if (b=strcmp(cmd, "/page") == 0) {
- system("who | more");
- printf("\nPage which TTY(i.e. ttyi19)?");
- gets(tty);
- sprintf(ttybuf,"/dev/%s",tty);
- if ((pgfd=fopen(ttybuf,"w"))==NULL) {
- perror("PAGE Device not found");
- return;
- }
- fputc(BELL,pgfd);
- fprintf(pgfd,"\n** %s(%s) Paged you to the Talk Parlour **\n respond with 'mtalk' , %s",myname,mytty,date());
- fflush(pgfd); fclose(pgfd);
- return;
- }
- if (b=strcmp(cmd, "/yell") == 0) {
- sprintf(yell,"%s %s",arg,obj);
- mwrite(WRITEALL,"",yell);
- return;
- }
- if (b=strcmp(cmd, "/sit") == 0) {
- if (strlen(arg)==0) {
- moderator("cleanup","moo");
- moderator("unmaster","moo");
- sit("Reception");
- printf("You get up and walk back to the Reception Hall.\n");
- return;
- }
- sprintf(t_lock,"%s%s.LCK\0",PATH,arg);
- if ((accessible=access(t_lock,0))==0) {
- printf("The `%s' table has been closed from further entry.\n",arg);
- return;
- }
- sit(arg);
- printf("You sit down at the `%s' table.\n",arg);
- return;
- }
- if (b=strcmp(cmd, "/look") == 0) {
- if (strcmp(myroom,"Reception")==0) {
- printf("You are in the Reception Hall.\n");
- return;
- }
- printf("You are sitting at the `%s' table.\n",myroom);
- sprintf(t_lock,"%s%s.LCK\0",PATH,myroom);
- sprintf(m_togl,"%s%s.MAS\0",PATH,myroom);
- if ((accessible=access(m_togl,0))==0) {
- printf("This table is Moderated.\n");
- }
- if (master==1) {
- printf("You are the Moderator.\n");
- }
- if ((accessible=access(t_lock,0))==0) {
- printf("The table is Closed from further entry.\n");
- }
- return;
- }
- /* Stupid? or what?? */
- printf("Huh? I don't understand.\nType '/?' for commands.\n");
- return;
- }
- void status_display()
- {
- /* This will display the user status of Mtalk. It also tests
- * to see if you are HEADMOO, and displays usefull information
- * for Caretakers eye's only.
- */
- int z,y,i,max_i,accessible;
- FILE *lgofd;
- char shmoo[80],*myname,*getlogin();
-
- if ((lgofd=fopen(LGNFILE,"r")) == NULL) { /* Open the loginfile */
- perror("Open Error reading LGNFILE");
- exit(-1);
- }
- myname=getlogin();
- init_flds();
- /* Read a line from LGOFD until EOF. Each line in loginfile consists
- * of info regarding each user logged into MTALK.
- */
- max_i=0;
- for (i=0; i<MAXUSERS; i++) {
- if (feof(lgofd)) break;
- fscanf(lgofd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1;
- fclose(lgofd);
-
- /* Okay, now format the header */
- printf("\nThe following are currently in the Talk Parlour:");
- printf("\n==================================================================");
- printf("\n Name Terminal Uid Room ");
- printf("\n------------------------------------------------------------------");
-
- /* Now print out status, all fields are left justified */
- for (i=0; i<max_i; i++) {
- if ((strcmp(logon_info[i].room,"Reception")==0)) {
- printf("\n%-17.17s %-11.11s %-8.8s %-10.10s",logon_info[i].logon_name,logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].room);
- continue;
- }
- if ((strcmp(logon_info[i].room,"Casino")==0)) {
- printf("\n%-17.17s %-11.11s %-8.8s %-10.10s",logon_info[i].logon_name,logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].room);
- continue;
- }
-
- printf("\n%-17.17s %-11.11s %-8.8s *********",logon_info[i].logon_name,logon_info[i].thetty,logon_info[i].uid_name);
- }
- /* Print the trailer */
- printf("\n==================================================================\n");
- /* If I am HEADMOO, tell me if the task is locked */
- if (y=strcmp(myname,HEADMOO)==0) {
- if ((accessible=access(LOCKFIL,0))==0){
- printf("\t\t\tThe Task is LOCKED.\n");
- }
- }
- }
- void do_logout()
- {
- /* This function performs a gracefull logout. What is done, is that
- * the loginfile is loaded into the logon_info array. Then, the
- * program matches you with your corresponding login entry and
- * NULLS it out. Lastly, the loginfile is unlinked and the remaining
- * entries are written to a new loginfile minus your's.
- */
- int z,y,i,max_i;
- FILE *lgofd;
- char *ttyname(), *getlogin(), *mytty, *myname,junk[230];
-
- /* Initialize the array fields */
- init_flds();
- mytty=ttyname(fileno(stdin));
- myname=getlogin();
- sprintf(junk,"### %s just left the Talk Parlour on %s.",&name,mytty);
- mwrite(SENDALL,"",junk);
-
- /* Open this blasted file */
- if ((lgofd=fopen(LGNFILE,"r+"))==NULL) {
- perror("Open error on do_logout()");
- exit(-1);
- }
- /* Read in the loginfile */
- for (i=0; i<MAXUSERS; i++) {
- if (feof(lgofd)) break;
- fscanf(lgofd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1;
- fclose(lgofd);
-
- /* Compare Array 'thetty' to mine to get a match */
- for (i=0; i<max_i; i++) {
- if (strcmp(mytty,logon_info[i].thetty)==0) {
- /* A match to my tty is found */
- logon_info[i].thetty[0]='\0'; /* NULL it out */
- break;
- }
- }
- unlink(LGNFILE); /* We don't need it now, erase it */
- /* Open the new loginfile */
- if ((lgofd=fopen(LGNFILE,"a"))==NULL) {
- perror("Open error on do_logout()2");
- exit(-1);
- }
-
- /* Put the array into the new file except for mine */
- for (i=0; i<max_i; i++) {
- if (strlen(logon_info[i].thetty)!=0) {
- fprintf(lgofd,"%s %s %s %s %d\n",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,logon_info[i].thepid);
- }
- continue;
- }
- fclose(lgofd);
- get_comfile();
- moderator("cleanup","moo"); /* Do this on the possibility that someone
- * logs out while at a table.
- */
- /* put entry into dayfile that I logged out */
- security("dayfile","Logout");
- printf("\nThanks for using M*Talk...\n");
- }
-
- read_text(news,pause)
- char *news;
- char *pause;
- {
- /* This function will read a text file in one of two ways depending
- * upon the parameters it has been given. If "pause" is passed
- * it will display the file and pause every 23 lines and wait for
- * a c/r. Otherwise, "nopause" should be passed.
- */
- FILE *rn;
- int c,y,cnt;
- char ch;
-
- if ((rn=fopen(news,"r"))==NULL) {
- return;
- }
-
- if (y=strcmp(pause,"nopause") == 0) {
- while ((c=getc(rn))!=EOF)
- putc(c,stdout);
-
- fclose(rn);
- return;
- }
-
- if (y=strcmp(pause,"pause") == 0) {
- while ((c=getc(rn))!=EOF) {
- if (c=='\n') cnt++;
- if (cnt==23) {
- printf("\n- 'Return' for more or 'q' to Quit -");
- ch=getchar();
- if (strcmp(ch,'q')==0) {
- break;
- } else {
- printf("\013\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
- cnt=0;
- continue;
- }
- }
- putc(c,stdout);
- }
- fclose(rn);
- return;
- }
-
- }
-
- sit(where)
- char *where;
- {
- /* function is self-explanatory. It corresponds to the /SIT
- * command.
- */
-
- FILE *lgnfd,*outfd;
- int max_i,i,y,accessible;
- char *ttyname(),*getlogin(),*mytty,*myname,stuff[230],pid[5],t_lock[35];
-
- sprintf(t_lock,"%s%s.LCK\0",PATH,where);
-
- if ((lgnfd=fopen(LGNFILE,"r"))== NULL) {
- perror("Open error on sit()/LGNFD");
- return;
- }
- strcpy(myroom,where);
- mytty=ttyname(fileno(stdin));
- myname=getlogin();
- init_flds(); /* Initialize the array */
- max_i=0;
-
- /* Get the info */
- for(i=0;i<MAXUSERS;i++) {
- if (feof(lgnfd)) break;
- fscanf(lgnfd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1;
-
- /* Set my array table equal to my physical table */
- for(i=0; i<max_i; i++) {
- if (strcmp(mytty,logon_info[i].thetty)==0) {
- strcpy(logon_info[i].room, myroom);
- break;
- }
- continue;
- }
- /* Now tell everyone but me, that I sat down at their table */
- for(i=0; i<max_i; i++) {
- if (strlen(where)==0) break;
- if (strcmp(mytty,logon_info[i].thetty)==0) {
- continue;
- }
- sprintf(pid,"%s%d",PATH,logon_info[i].thepid);
- if (strcmp(logon_info[i].room,myroom) ==0) {
- if ((outfd=fopen(pid,"a"))==NULL) {
- perror("open error commfile/sit");
- continue;
- }
- sprintf(stuff,"`%s' just sat down at your table.\n\0",&name);
- fwrite(stuff,sizeof(char),strlen(stuff),outfd);
- fflush(outfd); fclose(outfd);
- continue;
- }
- continue;
- }
-
-
- unlink(LGNFILE);
- if ((outfd=fopen(LGNFILE,"a")) ==NULL) {
- perror("sit()/outfd");
- exit(-1);
- }
- for(i=0; i<max_i; i++) {
- fprintf(outfd,"%s %s %s %s %d\n",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,logon_info[i].thepid);
- }
- fclose(outfd);
- }
-
- security(which,who)
- char *which;
- char *who;
- {
- /* This function deals with security specific operations.
- * Most notably, the /PURGE command. But also, handles the
- * dayfile entry.
- */
- FILE *prgfd;
- char *getlogin(),*myname,junk[9];
-
- myname=getlogin();
-
- if (strcmp(which,"purge")==0) {
- if ((prgfd=fopen(PRGFILE,"a"))==NULL) {
- perror("security/purge open error");
- return;
- }
- fprintf(prgfd,"%s\n",who);
- fflush(prgfd); fclose(prgfd);
- printf("\n`%s' has now been purged from Mtalk.\n",who);
- return;
- }
- if (strcmp(which,"dayfile")==0) {
- if ((prgfd=fopen(DAYFILE,"a"))==NULL) {
- perror("security/dayfile open error");
- return;
- }
- fprintf(prgfd,"%s-%s-%s-%s",who,myname,&name,date());
- fflush(prgfd); fclose(prgfd);
- return;
- }
- if (strcmp(which,"compare")==0) {
- if ((prgfd=fopen(PRGFILE,"r"))==NULL) {
- return;
- }
- for(;;) {
- if (feof(prgfd)) break;
- fscanf(prgfd,"%s",junk);
- if (strcmp(myname,junk)==0) {
- putchar(BELL);
- printf("\n**** Your access to M*talk has been removed indefinately.\n**** Please see the Caretaker for further info.\n");
- exit(1);
- }
- continue;
- }
- return;
- }
- } /* NOTREACHED End of Security function */
-
- get_comfile()
- {
- /* This function will read your corresponding commfile and then
- * unlink it to ready it for further appendages.
- */
- read_text(myfile,"nopause");
- unlink(myfile);
- }
-
- void check_max()
- {
- /* This function checks to make sure there arent MAXUSERS on Mtalk
- * and is called before anything else.
- */
- int z,y,i,max_i;
- FILE *lgofd;
- char *ttyname(), *getlogin(), *mytty, *myname;
-
- /* Initialize the array fields */
- init_flds();
- mytty=ttyname(fileno(stdin));
- myname=getlogin();
-
- /* Open this blasted file */
- if ((lgofd=fopen(LGNFILE,"r+"))==NULL) {
- perror("Warning: Open error on loginfile, no big deal.");
- return;
- }
- for (i=0; i<MAXUSERS; i++) {
- if (feof(lgofd)) break;
- fscanf(lgofd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1;
- fclose(lgofd);
- if (max_i < MAXUSERS) {
- return;
- }
- putchar(BELL);
- printf("\n\n*** Sorry, M*Talk is full right Now. Try again later. ***\n\n");
- exit(0);
- }
- auto_mode()
- {
- /* The function for /AUTO. Here, we must change the term.
- * characteristics, and then build a bitmap of the file descriptors
- * we are interested in looking at. In this case, stdin does just fine.
- * Then, we delay one second, so as not to tie anything up, and
- * constantly check for our commfile. If it's there, display it.
- */
- int accessible, mypid, template[2], mask[2], st;
- struct sgttyb ttysettings;
- struct timeval delay;
-
- /* set the terminal characteristics */
- assert(ioctl(fileno(stdin), TIOCGETP, &ttysettings) ==0);
- ttysettings.sg_flags &= (~ECHO); /* no echo */
- ttysettings.sg_flags |= CBREAK; /* half raw, still allows signals */
- template[fileno(stdin)/32] = 1 << (fileno(stdin)%32);
-
- delay.tv_sec=1;
- delay.tv_usec=0;
-
- printf("\nAuto Mode - Press `ENTER' to abort.\n");
- for(;;) {
- int n;
- /* We must do this copy because select smashes the mask all
- * to hell each time it is called.
- */
- (void) bcopy(template,mask,2 * sizeof(int));
- assert(n=select(1,mask,0L,0L,&delay) >= 0);
-
- /* If input pending, store it and read it. Mask is now hosed */
- if (n && (mask[fileno(stdin)/32] & (1 << (fileno(stdin)%32)))) {
- char c;
- assert(read(fileno(stdin),&c,sizeof(char)) > 0);
- if (c=='\n') break;
- }
- /* if Myfile is there, read the thing */
- if ((accessible=access(myfile,0))==0) {
- get_comfile();
- continue;
- }
- }
- /* Reset the terminal. This should really be a signal call, in case
- * someone hits control-C, but most people use TCSH, and the shell
- * does all that for us.
- */
- ttysettings.sg_flags |= ECHO;
- ttysettings.sg_flags &= (~CBREAK);
- assert(ioctl(fileno(stdin), TIOCSETP, &ttysettings)==0);
- return;
- }
- cleanup(sig)
- {
- /* This routine provides a tidy exit from the program upon
- * an ungracefull exit by the user. This routine is used only
- * with the signal calls shown at the beginning of this
- * source code.
- */
- kill(mypid,SIGHUP);
- do_logout();
- exit(0);
- }
- void check_users()
- {
- /* This function compares your name that you inputted with the
- * logonnames which are in the parlour at your login. If we get
- * a match, then we can't let you in. Must not have more than one
- * person of the same name online.
- */
- int z,y,i,max_i,accessible;
- FILE *lgofd;
- char shmoo[80],*myname,*getlogin();
-
- if ((lgofd=fopen(LGNFILE,"r")) == NULL) { /* Open the loginfile */
- perror("Warning: Open Error reading loginfile, no big deal.");
- return;
- }
- myname=getlogin();
- init_flds();
- /* Read a line from LGOFD until EOF. Each line in loginfile consists
- * of info regarding each user logged into MTALK.
- */
- max_i=0;
- for (i=0; i<MAXUSERS; i++) {
- if (feof(lgofd)) break;
- fscanf(lgofd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1;
- fclose(lgofd);
-
- /* Now compare all the logonnames. */
- for (i=0; i<max_i; i++) {
- if (strcmp(&name,logon_info[i].logon_name)==0) {
- putchar(BELL);
- printf("\n\nThat Name is already in use. Try another name.\n\n");
- exit(-1);
- }
- continue;
- }
- }
- do_message(who,what)
- char *who;
- char *what;
- {
- FILE *msgfd;
- int y,accessible,i,lineno;
- char *myname, *getlogin(), stuff[20], msg[80], file[35],ch;
- struct message {
- char line[80];
- } text[20];
-
- myname=getlogin();
- sprintf(file,"%s%s\0",PATH,who);
-
- if (strcmp(what,"write")==0) {
- printf("\nGreeves says,`You wish to write a small message to (%s)?'\n`First, make sure that is the correct logon for this person.'\n",who);
- printf("\nContinue(yes or no)?");
- gets(stuff);
- if (strcmp(stuff,"no")==0) { return; }
- if (strlen(stuff)==0) return;
-
- sprintf(msg,"********* A message from (%s), sent on %s\n",myname,date());
- lineno=1;
- printf("\nMessage to (%s) on %sYou may write up to 20 lines. End the message with a 'blank' line.\n\n",who,date());
- for (i=0; i<20; i++) {
- printf("%d> ",lineno);
- gets(text[i].line);
- if (strlen(text[i].line)==0) break;
- lineno++;
- }
- printf("Do you want to (s)end it, or (f)orget it? ");
- ch=getchar();
-
- switch(ch) {
- case 's':
- break;
- case 'f':
- printf("\n`Nothing sent..'");
- return;
- default:
- printf("\n`Nothing sent..'");
- return;
- }
-
-
- if ((msgfd=fopen(file,"a"))==NULL) {
- perror("error on msgfd");
- return;
- }
- fprintf(msgfd,"-------------------------------------------------------------------\n");
- fprintf(msgfd,"%s\0",msg);
- for (i=0; i<lineno; i++) {
- fprintf(msgfd,"%s\n\0",text[i].line);
- }
- fprintf(msgfd,"-------------------------------------------------------------------\n");
- fflush(msgfd); fclose(msgfd);
- printf("\nGreeves says,`Allright %s, when I see %s, I shall givehim/her the message.'\n",&name,who);
- sprintf(file,"Wmsg (%s)\0",who);
- security("dayfile",file);
- return;
- }
-
- if (strcmp(what,"read")==0) {
- if ((accessible=access(file,0))==0) {
- putchar(BELL);
- printf("\nGreeves says,`Excuse me, I believe you have a message.'\n Would you like it now(yes or no)?");
- gets(stuff);
- if (strlen(stuff)==0) return;
- if (strcmp(stuff,"no")==0) {
- printf("\nGreeves says,`Allright %s, I shall save it for you until later.'\n\n",&name);
- return;
- }
-
- printf("\n`Greeves hands you a piece of paper and then leaves.'\n");
- read_text(file,"pause");
- unlink(file);
- return;
- }
- return;
- }
- }
-
- moderator(what,who)
- char *what;
- char *who;
- {
- FILE *lgnfd,*outfd;
- int max_i,i,accessible;
- char stuff[80],*myname,*getlogin(),m_togl[35],t_lock[35];
-
- sprintf(t_lock,"%s%s.LCK\0",PATH,myroom);
- sprintf(m_togl,"%s%s.MAS\0",PATH,myroom);
-
- myname=getlogin();
-
- if (strcmp(what,"master")==0) {
- if (((accessible=access(m_togl,0))==0)&&(master==1)) {
- printf("You are already Moderator of this table.\n");
- return;
- }
- if (((accessible=access(m_togl,0))==0)&&(master==0)) {
- printf("Someone is already Moderator of this table.\n");
- return;
- }
- master=1;
- sprintf(stuff,"`%s' is now Moderator of this table.",&name);
- mwrite(SENDLOCAL,"",stuff);
- fopen(m_togl,"a");
- return;
- }
- if (strcmp(what,"unmaster")==0) {
- if (((accessible=access(m_togl,0))==0)&&(master==1)) {
- unlink(m_togl);
- master=0;
- return;
- }
- return;
- }
-
- if (strcmp(what,"close")==0) {
- if (((accessible=access(t_lock,0))==0)&&(master==1)) {
- printf("This table is already Closed.\n");
- return;
- }
- fopen(t_lock,"a");
- sprintf(stuff,"`%s' has just Closed this table from further entry.",&name);
- mwrite(SENDLOCAL,"",stuff);
- return;
- }
- if (strcmp(what,"open")==0) {
- if (((accessible=access(t_lock,0))!=0)&&(master==1)) {
- printf("This table is already Open.\n");
- return;
- }
- unlink(t_lock);
- sprintf(stuff,"`%s' has just Opened this table.",&name);
- mwrite(SENDLOCAL,"",stuff);
- return;
- }
- if (strcmp(what,"cleanup")==0) {
- if (((accessible=access(m_togl,0))==0)&&(master==1)) {
- unlink(m_togl);
- }
- if (((accessible=access(t_lock,0))==0)&&(master==1)) {
- unlink(t_lock);
- }
- return;
- }
- if (strcmp(what,"remove")==0) {
- if (strcmp(who,&name)==0) {
- printf("You can't 'remove' yourself from a table.\n");
- return;
- }
- if ((lgnfd=fopen(LGNFILE,"r"))== NULL) {
- perror("Open error on sit()/LGNFD");
- return;
- }
- init_flds(); /* Initialize the array */
- max_i=0;
-
- /* Get the info */
- for(i=0;i<MAXUSERS;i++) {
- if (feof(lgnfd)) break;
- fscanf(lgnfd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- fclose(lgnfd);
- max_i=i-1;
- for(i=0;i<max_i;i++) {
- if ((strcmp(logon_info[i].logon_name,who)==0)&&(strcmp(logon_info[i].room,myroom)==0)) {
- sprintf(stuff,"*** `%s' was just removed from the table by the Moderator.",who);
- mwrite(SENDLOCAL,"",stuff);
- strcpy(logon_info[i].room,"Reception");
- break;
- }
- continue;
- }
- unlink(LGNFILE);
- if ((outfd=fopen(LGNFILE,"a"))==NULL) {
- perror("/master - remove");
- return;
- }
- for(i=0; i<max_i; i++) {
- fprintf(outfd,"%s %s %s %s %d\n",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,logon_info[i].thepid);
- }
- fclose(outfd);
- }
-
- }
- get_room()
- {
- FILE *lgnfd;
- int i,y,max_i;
- char *mytty,*ttyname();
-
- if ((lgnfd=fopen(LGNFILE,"r"))== NULL) {
- perror("Open error on sit()/LGNFD");
- return;
- }
- init_flds(); /* Initialize the array */
- max_i=0;
- mytty=ttyname(fileno(stdin));
-
- /* Get the info */
- for(i=0;i<MAXUSERS;i++) {
- if (feof(lgnfd)) break;
- fscanf(lgnfd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- fclose(lgnfd);
- max_i=i-1;
- for(i=0;i<max_i;i++) {
- if (strcmp(mytty,logon_info[i].thetty)==0) {
- strcpy(myroom,logon_info[i].room);
- break;
- }
- continue;
- }
- return;
- }
-
- mwrite(attr,who,msg)
- char *attr;
- char *who;
- char *msg;
- {
- /* Mwrite() is the core of the whole Mtalk program. Given the
- * different attributes as parameters, this function controls all
- * of the input/output to the other users in Mtalk.
- */
- FILE *lgnfd,*outfd;
- int max_i,i,accessible,y;
- char *ttyname(),*getlogin(),*mytty,*myname,pid[5],stuff[230];
-
-
- if ((lgnfd=fopen(LGNFILE,"r"))== NULL) {
- perror("Open error on Mwrite/LGNFD");
- return;
- }
-
- mytty=ttyname(fileno(stdin));
- myname=getlogin();
- init_flds(); /* Initialize the array */
- max_i=0;
-
- /* Get the info & fill the structure */
- for(i=0;i<MAXUSERS;i++) {
- if (feof(lgnfd)) break;
- fscanf(lgnfd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1; /* max_i is physical number of users. I have to do this */
- fclose(lgnfd);
-
-
- if (strcmp(attr,"m_local")==0) {
- for(i=0;i<max_i;i++) {
- if ((y=strcmp(logon_info[i].logon_name,&name)==0)&&(echo==0)) {
- continue; }
- sprintf(pid,"%s%d",PATH,logon_info[i].thepid);
- if (y=strcmp(logon_info[i].room, myroom) == 0) {
- if ((outfd=fopen(pid,"a"))==NULL) {
- perror("Open error to %s",logon_info[i].thetty);
- continue;
- }
- fprintf(outfd,"%s says,`%s'\n",&name,msg);
- if (max_i==1) {
- fprintf(outfd,"Greeves says,`Talking to yourself again, %s? I see.'\n",&name);
- }
- fflush(outfd);fclose(outfd);
- }
- }
- }
-
- if (strcmp(attr,"m_all")==0) {
- for(i=0;i<max_i;i++) {
- if ((y=strcmp(logon_info[i].logon_name,&name)==0)&&(echo==0)) {
- continue; }
- sprintf(pid,"%s%d",PATH,logon_info[i].thepid);
- if ((outfd=fopen(pid,"a"))==NULL) {
- perror("Open error to %s",logon_info[i].thetty);
- continue;
- }
- sprintf(stuff,"%s yells,`%s'\n",&name,msg);
- fwrite(stuff, sizeof(char), strlen(stuff), outfd);
- fflush(outfd);fclose(outfd);
- }
- /* So as not to abuse the /YELL command and have people ticked off
- * at you for disturbing their conversation with rash yells, I built
- * in this humorous yell counter. Feel free to change the counts
- * and/or the printf's
- */
- yellcnt=yellcnt+1;
- if (yellcnt==3) {
- printf("Greeves says,`Could you please keep it down. You are disturbing others.\n");
- }
- if (yellcnt==4) {
- printf("Greeves says,`One more outburst like that, and you will have to leave.\n");
- }
- if (yellcnt==5) {
- printf("Greeves says,`Allright buster, you've had it!!\n");
- printf("`Greeves takes you by the scruff of the neck and boots you out the door.'\n");
- sprintf(stuff,"### %s was just forcibly removed by the butler for yelling too much.\n\0",&name);
- mwrite(SENDALL,"",stuff);
- do_logout();
- exit(0);
- }
- }
- if (strcmp(attr,"s_local")==0) {
-
- for(i=0;i<max_i;i++) {
- sprintf(pid,"%s%d",PATH,logon_info[i].thepid);
- if (y=strcmp(logon_info[i].room, myroom) == 0) {
- if ((outfd=fopen(pid,"a"))==NULL) {
- perror("Open error to %s",logon_info[i].thetty);
- continue;
- }
- sprintf(stuff,"%s\n\0",msg);
- fwrite(stuff,sizeof(char),strlen(stuff),outfd);
- fflush(outfd);fclose(outfd);
- }
- }
- }
- if (strcmp(attr,"s_all")==0) {
-
- for(i=0;i<max_i;i++) {
- sprintf(pid,"%s%d",PATH,logon_info[i].thepid);
- if ((outfd=fopen(pid,"a"))==NULL) {
- perror("Open error to %s",logon_info[i].thetty);
- continue;
- }
- sprintf(stuff,"%s\n\0",msg);
- fwrite(stuff, sizeof(char), strlen(stuff), outfd);
- fflush(outfd);fclose(outfd);
- }
- }
- if (strcmp(attr,"m_whisper")==0) {
-
- for(i=0;i<max_i;i++) {
- sprintf(pid,"%s%d",PATH,logon_info[i].thepid);
- if (strcmp(logon_info[i].logon_name,who)==0) {
- if ((outfd=fopen(pid,"a"))==NULL) {
- perror("Open error to %s",logon_info[i].thetty);
- return;
- }
- sprintf(stuff,"%s whispers, `%s'\n",&name,msg);
- fwrite(stuff, sizeof(char), strlen(stuff), outfd);
- fflush(outfd); fclose(outfd);
- return;
- }
- continue;
- }
- printf("`%s' is not logged into Mtalk.\n",who);
- }
- } /** End of Mwrite function **/
- logoff(who)
- char *who;
- {
-
- FILE *lgnfd,*outfd;
- int max_i,i,accessible,y;
- char *ttyname(),*getlogin(),*mytty,*myname,pid[5],stuff[80];
-
-
- if ((lgnfd=fopen(LGNFILE,"r"))== NULL) {
- perror("Open error on Mwrite/LGNFD");
- return;
- }
-
- mytty=ttyname(fileno(stdin));
- myname=getlogin();
- init_flds(); /* Initialize the array */
- max_i=0;
-
- /* Get the info & fill the structure */
- for(i=0;i<MAXUSERS;i++) {
- if (feof(lgnfd)) break;
- fscanf(lgnfd,"%s %s %s %s %d",logon_info[i].thetty,logon_info[i].uid_name,logon_info[i].logon_name,logon_info[i].room,&logon_info[i].thepid);
- }
- max_i=i-1; /* max_i is physical number of users. I have to do this */
- fclose(lgnfd);
-
- for(i=0;i<max_i;i++) {
- if (strcmp(who,logon_info[i].logon_name)==0) {
- kill(logon_info[i].thepid,SIGINT);
- return;
- }
- continue;
- } /* Reached if Unsuccessful */
- printf("That person is not logged on.");
- return;
- } /* Notreached */
-
-
-