Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!allbery From: al@questar.questar.mn.org (Al Viall) Newsgroups: comp.sources.misc Subject: v10i069: MultiTalk1.2 - Multi-user Talk Parlour Message-ID: <78928@uunet.UU.NET> Date: 14 Feb 90 02:06:40 GMT Sender: allbery@uunet.UU.NET Reply-To: Al Viall Organization: Questar Data Systems, Inc., St. Paul, MN Lines: 1732 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Posting-number: Volume 10, Issue 69 Submitted-by: Al Viall Archive-name: multitalk Multitalk is a multi-user talk program which allows up to 20 users online at one time. For BSD and System V machines only. ----------------------- Cut here, then type sh 'file' -------------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh Readme.1st <<'END_OF_Readme.1st' X Helpfull hints from the Author XHello, if you are reading this right now, then obviously you have decided to Xtry out the enclosed program, Multitalk. Henceforth, the words Mtalk and XMultiTalk will conversely mean the same thing. XI'll try to keep this as brief as possible, since the purpose of me writing Xthis was only to point out certain things which may be helpfull in maintaining XMtalk, but most of the comments included with the source are pretty self- Xexplanatory. X XPURPOSE X The purpose behind writing Multitalk was actually two-fold. I needed Xa project to do in my spare time in order to understand and write in 'C', and XI thought that this type of a program would be rather usefull and entertaining Xon BSD systems which only had TALK or NTALK to interactively converse with Xothers on the system. Mtalk does not have the limitation of ONE to ONE chatting Xlike TALK or NTALK (These programs are ussually supplied with BSD systems), but Xcan have up to 20 users online at once. Mtalk also allows private conversation Xbetween individuals or groups(sitting at a table). Mtalk was very easy to Xwrite after the initial things were out of the way, so I decided to make it Xeasy for others to use. No object modules. No Makefile's. Just a simple script Xthat will compile and then if successful, will setuid the executable so that Xothers may use it. X XINSTALLATION X Installation requires a few steps, none of which should take very Xlong to accomplish. X X Step 1: Decide where you would like Mtalk to reside. Make that directory X read/write/execute for the person in charge of Mtalk. From this point on X we shall assume it is you. The reason for this, is that we wouldn't X want unwanted visitors into the directory since Mtalk has certain X security functions for users who abuse it. Those people would just end X up mucking things all to hell. X X Step 2: Put all of the enclosed files into that directory except for X the /bin/sh script file called 'mtalk'. This file should be put into X a default login directory like /usr/local/bin. Before you do that, X be sure to edit the script for the pathname to the Mtalk directory. X X Step 3: Edit the multitalk.h file to correspond with the filenames X that you wish things to be. Be sure to specify a HEADMOO <--Don't Ask. X Without a UID name for this definition, certain caretaker features can X not be used by you. These features include tasklock and user removal. X X Step 4: Now compile the multitalk.c file using the /bin/sh script X 'Makeit'. All this does is compile the source and then SETUID the X executable file so that others can use it without Permission errors. X X Step 5: Mtalk is now runnable. Too make sure, just type 'mtalk'. X X I have not run into any errors or major bugs while using Mtalk. The Xonly problem so far is when someone ungracefully exits the program while in Xauto_mode(/AUTO). In this case, which is worst-case scenario, all you need Xto do, once you are told about it, is just edit the 'loginfile' and remove Xthat persons entry from the file. Also, you will want to remove that persons XPID-unique commfile. X XHOW IT WORKS X As you may already know, when one runs a particular job or command Xin UNIX, the OS gives it a unique Process Identification Number(PID) so that Xit may be able to reference that number later. X When you logon, Mtalk gets that PID number and a global variable is set Xto correspond to that number. This is now your personal CommFile. Each user Xwho logs on will get their own CommFile, which will be unique to that particular Xprocess, and the corresponding PID number is then written to the loginfile Xalong with other information pertinent to that user(i.e. UID_name, tty, etc.). X When you input a line of text for others to see, the loginfile is loaded Xinto a structure array. Each entry is then taken, one by one, and your text is Xappended to that entry's CommFile. When the user/users that you sent the text Xto either hits C/R alone or uses a command AND there is text in their CommFile Xto display, then it is displayed. Mtalk is not a Parent Process dependent Xprogram. In other words, Mtalk does not start a parent process and spawn Xchildren whenever a new user executes the program. Doing it that way would Xhave been more work than it was worth!! Mtalk uses very little system resources, Xsince the SIZE and RES, as reported by TOP is 134K and 38K, Xrespectively. X XFINAL NOTES X I hope this pretty much explains the naughty bits of Mtalk. I am Xsure you will either have good things to say about the program, are maybe you Xmight tell me where to put the thing, either way, I would like to hear about Xit. One serious note, I realize that more portable version of this would Xbe usefull to others, but considering the time involved, I just could not do Xit at this time, but it will be forthcoming. Right now, we only have the Xversion for BSD and System V. If you have bug reports, and/or Xcriticisms and suggestions please read below. X X Albert Viall X 6881 MeadowBrook Blvd #317 X St. Louis Park, MN 55426 X X E-Mail: al@{questar,hobbes}.QUESTAR.MN.ORG X Voice : 1-612-688-0089 X42 (8:00am-5:00pm CST) X X X END_OF_Readme.1st if test 5104 -ne `wc -c cmds.txt <<'END_OF_cmds.txt' X XAvailable Commands as of: 1/11/90 X X Commands preceded by an '*' are for Caretaker use ONLY. X X /? .......... Displays this command help file. X /q .......... Quit. Logout of the Mtalk program. X /auto ....... Puts you in auto-mode. Constant 'returns' are not needed in this X mode because Mtalk will wait until there is output to display. X*/broadcast .. Sends a highlighted message to all users. X*/dayfile .... Displays a dayfile of activity and users in Mtalk. X /echo ....... Toggles echo mode on/off. X /look ....... Tells you what table or room you are located. X*/lock ....... Puts the Mtalk program into a locked/unlocked state. This will X prevent others from entering the Parlour. X /message .... Allows you to leave a short message for a user who is not logged X on at the time. When that person logs on, it can be displayed. X /news ....... Displays any important bulletins or news if there is any to X report. X /page ....... Allows you to PAGE a user to Mtalk. X /prompt ..... Will change your default 'Say?' prompt to whatever you choose. X*/purge ...... Effectively bans a user from further use of Mtalk. X /sit ........ Moves you to whatever table of your choosing. X /status ..... Shows who is currently logged into Mtalk. X /time ....... Displays the current time and date. X /whisper .... Send a private message to someone anywhere in the Parlour. X /yell ....... Sends a message to everyone in the Parlour. X*/logoff ..... Forcibly logs off a current user of Mtalk. X X X END_OF_cmds.txt if test 1506 -ne `wc -c mtalk.1 <<'END_OF_mtalk.1' X.TH MTALK 1-Questar X.SH NAME Xmtalk \- Multitalk multi-user Talk Parlour X.SH ORIGIN XQuestar Data Systems X.SH SYNOPSIS X.nf Xmtalk X.fi X.SH DESCRIPTION X.I mtalk Xis a multi-user conference program which can support up to 20 users at Xthe same time. When you run X.I mtalk X, you actually run a shell script which then runs the main program and Xis controlled in the X.I mtalk Xdirectory which is defined upon compilation. This program allows you to have Xeither public or private conversations with others who are logged into Xthe program at that particular time. For information on the many commands, Xand procedures for using X.I mtalk X, refer to you site administrator for copies of the manual. X.nf X.SH FILES X/usr/local/bin/mtalk - script that runs multitalk. X.SH BUGS X.I mtalk Xwill lose track of its loginfile if someone ctrl-C's out while in /auto. Other Xthan that, the program is bulletproof. X.SH AUTHOR XAlbert Viall X.\" @(#)multitalk.c 2.0 (Questar) 8/9/89 END_OF_mtalk.1 if test 953 -ne `wc -c mtalk.man <<'END_OF_mtalk.man' X X X XMTALK(1-Questar) Pyramid OSx Operating System MTALK(1-Questar) X X X XNAME X mtalk - Multitalk multi-user Talk Parlour X XORIGIN X Questar Data Systems X XSYNOPSIS X mtalk X XDESCRIPTION X _m_t_a_l_k is a multi-user conference program which can support X up to 20 users at the same time. When you run _m_t_a_l_k , you X actually run a shell script which then runs the main program X and is controlled in the _m_t_a_l_k directory which is defined X upon compilation. This program allows you to have either X public or private conversations with others who are logged X into the program at that particular time. For information on X the many commands, and procedures for using _m_t_a_l_k , refer to X you site administrator for copies of the manual. X XFILES X /usr/local/bin/mtalk - script that runs multitalk. X XBUGS X _m_t_a_l_k will lose track of its loginfile if someone ctrl-C's X out while in /auto. Other than that, the program is bullet- X proof. X XAUTHOR X Albert Viall X X X X X X X X X X X X X X X X X X X X X X X X X XPrinted 12/27/89 1 X X X END_OF_mtalk.man echo shar: 25 control characters may be missing from \"mtalk.man\" if test 1140 -ne `wc -c multitalk.c <<'END_OF_multitalk.c' X/*********************************************** X * X * MultiTalk - Talk Parlour X * Multi-user Conferencing Program. X * X * Written and Developed by Albert Viall X * WARNING: Do not remove this header or alter it X * in anyway. By releasing this source code into X * public domain, the author allows minor changes X * to the source code to suit the needs of the X * user. X * X * (C)1989 X * All Rights Reserved X **********************************************/ X X X#include X#include X#include X#include X#include X#include X#include X#include X#include "multitalk.h" X X#define BELL '\007' X#define WRITELOCAL "m_local" X#define WRITEALL "m_all" X#define SENDLOCAL "s_local" X#define SENDALL "s_all" X#define WHISPER "m_whisper" X#define SENDTO "s_to" X Xchar name[40],*myroom,myfile[35]; Xchar prompt[8]; Xint yellcnt,mypid,echo,master; X X/* Global structure used for loginfile X * If you add or delete any login parameters, it must be X * done here first X */ Xstruct logon { X char thetty[12]; /* tty filename, i.e. /dev/ttyi34 */ X char uid_name[8]; /* the system login name */ X char logon_name[40]; /* Mtalk login name */ X char room[11]; /* current room */ X int thepid; /* this structures pidnumber */ X } logon_info[MAXUSERS]; /* MAXUSERS is defined in multitalk.h */ Xint cleanup(); X Xmain() X{ X int x,z,y; X char str[256],junk[9],*myname,*getlogin(),*mytty,*ttyname(); X X /* Perform a tidy cleanup upon signal. X * Thank you for keeping your area clean. X */ X signal(SIGHUP,cleanup); X signal(SIGINT,cleanup); X security("compare",junk); /* Am I in the purgefile? */ X master=0; X mypid=getpid(); X myname=getlogin(); X mytty=ttyname(fileno(stdin)); X /* set global 'myfile' to search for my commfile */ X sprintf(myfile,"%s%d\0",PATH,mypid); X fopen(myfile,"a"); /* Open my commfile just to make sure its there */ X do_login(); X sprintf(str,"### %s was just escorted into the Talk Parlour on %s.",&name,mytty); X mwrite(SENDALL,"",str); X get_comfile(); X do_message(myname,"read"); X yellcnt=0; X echo=1; X sprintf(prompt,"Say? \0"); /* set default input prompt */ X X X /* main processing - things branch from here */ X for(;;) { X str[0]='\0'; X printf("%s",prompt); X gets(str); X X get_room(); X /* is str a command? */ X if (str[0]=='/') { X parse_cmd(str); X get_comfile(); X continue; X } X X /* did I input regular text? */ X if (strlen(str) != 0) { X mwrite(WRITELOCAL,"",str); X get_comfile(); X continue; X } X /* or did I hit a c/r */ X if (strlen(str) == 0) { X get_comfile(); X continue; X } X X X } /* end of main processing */ X} /* NOTREACHED */ X Xchar * Xdate() /* returns date and time in the 26 character format */ X{ X long t; X register char *s; X char *ctime(); X X time(&t); X s=ctime(&t); X return s; X} X Xvoid init_flds() X{ X int t; X X /* This should be the first function to be called whenever a new X * set of fields are incorporated into the array. It will X * Initialize the entire array. X */ X for (t=0; t 1) { X y=0; X sscanf(str,"%s %s",cmd,arg); X for(i=0;!isspace(str[i]);i++) { continue; } X for(i++;!isspace(str[i]);i++) { continue; } X for(i++;i= 0); X X /* If input pending, store it and read it. Mask is now hosed */ X if (n && (mask[fileno(stdin)/32] & (1 << (fileno(stdin)%32)))) { X char c; X assert(read(fileno(stdin),&c,sizeof(char)) > 0); X if (c=='\n') break; X } X /* if Myfile is there, read the thing */ X if ((accessible=access(myfile,0))==0) { X get_comfile(); X continue; X } X } X /* Reset the terminal. This should really be a signal call, in case X * someone hits control-C, but most people use TCSH, and the shell X * does all that for us. X */ X ttysettings.sg_flags |= ECHO; X ttysettings.sg_flags &= (~CBREAK); X assert(ioctl(fileno(stdin), TIOCSETP, &ttysettings)==0); X return; X} Xcleanup(sig) X{ X /* This routine provides a tidy exit from the program upon X * an ungracefull exit by the user. This routine is used only X * with the signal calls shown at the beginning of this X * source code. X */ X kill(mypid,SIGHUP); X do_logout(); X exit(0); X} Xvoid check_users() X{ X /* This function compares your name that you inputted with the X * logonnames which are in the parlour at your login. If we get X * a match, then we can't let you in. Must not have more than one X * person of the same name online. X */ X int z,y,i,max_i,accessible; X FILE *lgofd; X char shmoo[80],*myname,*getlogin(); X X if ((lgofd=fopen(LGNFILE,"r")) == NULL) { /* Open the loginfile */ X perror("Warning: Open Error reading loginfile, no big deal."); X return; X } X myname=getlogin(); X init_flds(); X /* Read a line from LGOFD until EOF. Each line in loginfile consists X * of info regarding each user logged into MTALK. X */ X max_i=0; X for (i=0; i ",lineno); X gets(text[i].line); X if (strlen(text[i].line)==0) break; X lineno++; X } X printf("Do you want to (s)end it, or (f)orget it? "); X ch=getchar(); X X switch(ch) { X case 's': X break; X case 'f': X printf("\n`Nothing sent..'"); X return; X default: X printf("\n`Nothing sent..'"); X return; X } X X X if ((msgfd=fopen(file,"a"))==NULL) { X perror("error on msgfd"); X return; X } X fprintf(msgfd,"-------------------------------------------------------------------\n"); X fprintf(msgfd,"%s\0",msg); X for (i=0; imultitalk.h <<'END_OF_multitalk.h' X/*************************************** X * Multitalk.h - Albert Viall X * (C) 1989 X * Global macros for certain file accesses X * This file may be changed to reflect any location changes for X * any/or all files associated with Multitalk. X **************************************/ X X#define LGNFILE "/u1/prg/al/C/TALK/loginfile" /* login records file */ X#define PATH "/u1/prg/al/C/TALK/" /* Path for CommFiles */ X#define GAME "/u1/prg/al/C/TALK/multitalk" /* actual game */ X#define NEWS "/u1/prg/al/C/TALK/news.txt" /* news file, if any */ X#define CMDS "/u1/prg/al/C/TALK/cmds.txt" /* list of commands */ X#define DAYFILE "/u1/prg/al/C/TALK/.dayfile" /* daily logon report */ X#define LOCKFIL "/u1/prg/al/C/TALK/.tasklock" /* is TASK Locked */ X#define PRGFILE "/u1/prg/al/C/TALK/.purgefile" /* Purged user file */ X#define HEADMOO "al" /* This is defined as the Caretaker */ X#define MAXUSERS 10 /* Please keep this reasonable, it should never be X * raised to more than 20, unless you KNOW that your X * system can hadle it. X */ X END_OF_multitalk.h if test 1088 -ne `wc -c news.txt <<'END_OF_news.txt' X XMultiTalk News: 1/25/90 X New Commands that have been installed since 1/14/90 are a new /message X and the /logoff command. /logoff allows the Caretaker to forcibly logoff a X obnoxious user. Mtalk is now up to Ver.1.2, after correcting messy displays X and fixing two bugs pertaining to the loginfile during 'login'. X X X END_OF_news.txt if test 319 -ne `wc -c -- -Bill Randle Tektronix, Inc. billr@saab.CNA.TEK.COM