server.c

ncohafmuta-1.4.2/srcfiles/server.c · 526.0 KB

From the archive ncoh142-dist-full.tar.gz

Download the archive   « Back to the archive contents

/*----------------------------------------------------------------------*/
/* Now Come on Over Here And Fuck Me Up The Ass - Ncohafmuta V 1.4.x    */
/*----------------------------------------------------------------------*/
/*  This code is a collection of software that originally started       */
/*  as a system called:                                                 */
/*                       IFORMS V 1.0                                   */
/*            Interactive FORum Multiplexor Software - (C) Deep         */
/*                 Last update 25/9/94                                  */
/*                                                                      */
/* As a result of extensive changes, it can no longer be considered     */
/* the same code                                                        */
/*                     -Cygnus (Anthony J. Biacco - Ncohafmuta Ent.)    */
/*                                                                      */
/* Legal note:  This code may NOT be freely distributed.  Doing so may  */
/*              be in violation of the US Munitions laws which cover    */
/*              exportation of encoding technology.                     */
/*----------------------------------------------------------------------*/

 /* SPECIAL PINWHEELS USER EXCEPTIONS IN THE CODE */
 /* llo doesn't get blinking */
	
 /* Major things to do:
                intertalker connectivity
                investigate using a database
                investigate using threads or async IO for connections
                investigate creating an email gateway
                multiline mail, board writes
                add command initialization from a file
                create standards for diffent term type 
                allocate structure dynamically
                break code up into multiple C files (in progress)
                port code to Win95 and WinNT (in progress)
 */
 
/*--------------------------------------------------------------*/
/* NOTE: For AIX users the getrlimit is not supported by the OS */
/*                                                              */
/*   For sun users the cpp is not ansi standard so preprocessor */
/*   strings are not supported properly                         */
/*                                                              */
/*--------------------------------------------------------------*/

#if defined(HAVE_CONFIG_H)
#include "../hdrfiles/config.h"
#endif

#include "../hdrfiles/includes.h"

/*--------------------------------------------------------*/
/* Talker-related include files                           */
/*--------------------------------------------------------*/
#include "../hdrfiles/osdefs.h"
#include "../hdrfiles/authuser.h"
#define _DEFINING_TEXT
#include "../hdrfiles/text.h"
#include "../hdrfiles/constants.h"

/*--------------------------------------------------------*/
/* Initialize functions we need too			  */
/* Almost all, including all command functions		  */
/*--------------------------------------------------------*/
#include "../hdrfiles/protos.h"
#include "../hdrfiles/resolver_clipon.h"

extern int resolver_toclient_pipes[2];
extern int resolver_toserver_pipes[2];
extern int resolver_clipon_pid;
extern char *our_delimiters;

/** Variables declared somewhere else **/

extern int PORT;                  /* main login port for incoming   */

extern int listen_sock[4];        /* 32 bit listening sockets       */
extern fd_set readmask;           /* bitmap read set                */
extern fd_set writemask;          /* bitmap write set               */
extern int inter;                 /* inter talker connections       */
extern int cypher;                /* caller id port                 */

extern int last_user;
extern int restarting;

/* Big Letter array map */
extern int biglet[26][5][5];
extern char *syserror;

extern char area_nochange[MAX_AREAS]; 
extern char mess[ARR_SIZE+25];    /* functions use mess to send output   */ 
extern char t_mess[ARR_SIZE+25];  /* functions use t_mess as a buffer    */ 
extern char t_inpstr[ARR_SIZE];   /* functions use t_mess as a buffer    */ 
extern char datadir[255];	  /* config directory                    */
extern char thishost[101];	  /* FQDN were running on                */
extern char thisos[101];          /* operating system were running on    */
extern char thisprog[255];	  /* the binary the program is run as	 */
extern int noprompt;		  /* talker waiting for user input?      */
extern int signl;
extern int tells;		  /* tells in defined time period        */
extern int commands;		  /* total commands in defined time period  */
extern int says;		  /* says in defined time period         */
extern int says_running;
extern int tells_running;
extern int commands_running;
extern int shutd;		/* talker waiting for confirm on a shutdown? */
extern int delete_sent;
extern int sys_access;	/* is the system open for user connections?      */
extern int wiz_access;	/* is the system open for wizard connections?    */
extern int who_access;	/* is the system open for external who listings? */
extern int www_access;	/* is the system open for external web requests? */
extern int checked;	/* see if messages have been checked at midnight */
extern int debug;

extern struct command_struct sys[];          /* the user command structure */
extern struct botcommand_struct botsys[];    /* the bot command structure  */
extern char sh_conv[NUM_LINES][MAX_LINE_LEN+1];     /* store review shouts */
extern int sh_count;			      /* shout count in the buffer */
extern char mailgateway_ip[16];		     	   /* SMTP gateway address */
extern unsigned int mailgateway_port;		      /* SMTP gateway port */

/*** GLOBAL DECLARATIONS ***/

/* Definitions for authuser info from a remote identd */
struct timeval timeout={10, 0};
char l_mess[ARR_SIZE+25];  /* log functions use l_mess as buffer  */ 
char bt_conv[NUM_LINES][MAX_LINE_LEN+1]; /* stores lines of conversation in wiztell buffer */
char web_opts[11][64];	/* web configuration options from file    */
time_t start_time;	/* startup time                           */
int NUM_AREAS;		/* number of areas defined in config file */
int num_of_users=0;	/* total number of users online           */
int MESS_LIFE=0;	/* message lifetime in days               */
int atmos_on;		/* all room atmospherics on?              */
int syslog_on;		/* are we logging system stuff to a file  */
int allow_new;		/* can new users be created?              */
int dobackups;		/* are we archiving log files @ midnight? */
int average_tells;	/* average tells                          */
int down_time=0;	/* countdown to an auto shutdown or auto reboot */
int bt_count;		/* wiztell count in the buffer                  */
int treboot=0;		/* is an auto-reboot started?                   */

int autopromote = AUTO_PROMOTE; /* allowing users to promote themselves? */
int autonuke    = NUKE_NOSET;	/* nuking users on quit without a desc.? */
int autoexpire  = AUTO_EXPIRE;	/* expiring users at midnight on auto?   */
int bot         = -5;           /* this will hold the bots user number   */
int new_room;			/* room new users log into               */

/*** END OF GLOBAL DELCARATIONS ***/

/*** START OF FUNCTIONS ***/

/* list global revoke (mode 0) or grant (mode 1) permissions */
void listall_gravokes(int user, int mode)
{
int aa=0,ii=0,found2=0,t=0;
char name2[ARR_SIZE];
char small_buff2[64];
char filerid2[FILE_NAME_LEN];
struct dirent *dp2;
DIR  *dirp2;

if (mode==0)
write_str(user," Global revoke list");
else if (mode==1)
write_str(user," Global grant list");

write_str(user,"+-------------------------------------------------+");

  sprintf(t_mess,"%s",USERDIR);
        
  strncpy(filerid2,t_mess,FILE_NAME_LEN);
    
  dirp2=opendir((char *)filerid2);
       
 if (dirp2 == NULL)
   {write_str(user,"Directory information not found.");
    write_str(user,"+-------------------------------------------------+");
    write_log(ERRLOG,YESTIME,"Directory information not found for directory \"%s\" in listall_gravokes %s\n",
    filerid2,get_error());
    return;
   }

 while ((dp2 = readdir(dirp2)) != NULL)   
   {
    sprintf(small_buff2,"%s",dp2->d_name);
       if (small_buff2[0]=='.') continue;

	found2=0; aa=0; ii=0;
        read_user(small_buff2);

		/* first see if user has at least 1 to print their name */
                for (aa=0; aa < MAX_GRAVOKES; ++aa) {
		if (mode==0) {
                  if (!is_revoke(t_ustr.revokes[aa])) continue;
		  }
		else if (mode==1) {
                  if (!is_grant(t_ustr.revokes[aa])) continue;
		  }
                  found2=1; break;
                } /* end of for */
		if (!found2) continue;

sprintf(name2,"%-*s",NAME_LEN+count_color(t_ustr.say_name,0),t_ustr.say_name);
		/* print out all permissions */
                for (aa=0; aa < MAX_GRAVOKES; ++aa) {
		if (mode==0) {
                  if (!is_revoke(t_ustr.revokes[aa])) continue;
		  }
		else if (mode==1) {
                  if (!is_grant(t_ustr.revokes[aa])) continue;
		  }
		  if (ii>0) strcat(name2,",");
		  for (t=0;sys[t].jump_vector != -1;++t) {
			if (strip_com(t_ustr.revokes[aa]) == sys[t].jump_vector) {
				  strcat(name2,sys[t].command);
				break;
				}
		     }
			t=0;
		  ii=1;
                } /* end of for */
write_str(user,name2);
continue;
} /* end of while */
(void) closedir(dirp2);
write_str(user,"+-------------------------------------------------+");

}


/*------------------------------------------------------*/
/* write time system went up or down to syslog file     */
/*------------------------------------------------------*/
void sysud(int ud, int user)
{
char filename[FILE_NAME_LEN];
FILE *tfp;

/* if ud=1 system is coming up, else if 0, going down */

if (!syslog_on) return;

if (ud) puts("Logging startup...");

/* write to file */
if (ud)  {
  time(&start_time);
  write_log(BOOTLOG,NOTIME,"%s: BOOT on port %d using datadir: %s with pid %u\n",get_time(start_time,0),PORT,datadir,(unsigned int)getpid());
  }
else {
      if (user==-1) {
      if (treboot==1)
       write_log(BOOTLOG,YESTIME,"SOFT-REBOOT by the talker\n");
      else if (treboot==2)
       write_log(BOOTLOG,YESTIME,"HARD-REBOOT by the talker\n");
      else
       write_log(BOOTLOG,YESTIME,"SHUTDOWN by the talker complete\n");
      }
      else {
      if (treboot==1)
       write_log(BOOTLOG,YESTIME,"SOFT-REBOOT by %s\n",ustr[user].say_name);
      else if (treboot==2)
       write_log(BOOTLOG,YESTIME,"HARD-REBOOT by %s\n",ustr[user].say_name);
      else
       write_log(BOOTLOG,YESTIME,"SHUTDOWN by %s complete\n",ustr[user].say_name);
      }
     }

sprintf(filename,"%s.pid",thisprog);

if (ud) {
  if (!(tfp=fopen(filename,"w"))) return;

  fprintf(tfp,"%u",(unsigned int)getpid());
  fclose(tfp);
  }
else {
  remove(filename);
  }

}


/*** Handle macros... if any ***/
/* returning 0 is an error, but the command will continue through the */
/* main loop, returning -1 is an error and the command is discarded   */
int check_macro(int user, char *inpstr)
{
int a=0;
int arg1=0;
int arg2=0;
int arg3=0;
int i=0;
int j=0;
int found=0;
int noarg=0;
char line[ARR_SIZE];
char outstr[ARR_SIZE];
char tp[3];
char argu[3][ARR_SIZE];
MacroPtr tmpMacros = ustr[user].Macros;

tp[0]=0;

if (!tmpMacros) return 0;

sscanf(inpstr,"%s ",line);
for (i=0;i<NUM_MACROS;++i) {
   if (!strcmp(tmpMacros->name[i],line)) {
     found=1;
     break;
    }
  }
if (!found) return 0;
found=0;

outstr[0]=0;
/* strcpy(outstr,line); */
remove_first(inpstr);
if (!strlen(inpstr)) noarg=1;
else {
 argu[0][0]=0;
 argu[1][0]=0;
 argu[2][0]=0;
 argu[3][0]=0;  /* last input */

 /* scan arguments into seperate arrays */
 while (strlen(inpstr)) {
   if (a<3) {
    sscanf(inpstr,"%s ",argu[a]);
    argu[a][80]=0;
    }
   else {
    strcpy(line,inpstr);
    break;
    }
   if (a<3) line[0]=0;
   remove_first(inpstr); 
   a++;
  } /* end of while */
 a=0;
} /* end of else */


/* go through the input string character by character */
for (j=0;j<strlen(tmpMacros->body[i]);++j) {
  if (tmpMacros->body[i][j]=='$') {
     j++;
     if (tmpMacros->body[i][j]=='1') {
        if (noarg) {
          write_str(user,"Macro was made to accept an argument. None was given.");
          return -1;
          }
        /* only set if coming from a lower argument substition */
        if (a<1 && strlen(argu[0])) a=1;
        arg1++;
         /* only can use same substitution 3 times in same macro */
        if (arg1<=3)
         strcat(outstr,argu[0]);
        else { }
        continue;
       }
     else if (tmpMacros->body[i][j]=='2') {
        if (noarg) {
          write_str(user,"Macro was made to accept an argument. None was given.");
          return -1;
          }
        /* only set if coming from a lower argument substition */
        if (a<2 && strlen(argu[1])) a=2;
        arg2++;
         /* only can use same substitution 3 times in same macro */
        if (arg2<=3)
         strcat(outstr,argu[1]);
        else { }
        continue;     
       }
     else if (tmpMacros->body[i][j]=='3') {
        if (noarg) {
          write_str(user,"Macro was made to accept an argument. None was given.");
          return -1;
          }
        /* only set if coming from a lower argument substition */
        if (a<3 && strlen(argu[2])) a=3;
        arg3++;
         /* only can use same substitution 3 times in same macro */
        if (arg3<=3)
         strcat(outstr,argu[2]);
        else { }
        continue;     
       }
     else {
        /* $ is not a substitution, just a $ */
        j--;
        tp[0]=tmpMacros->body[i][j];
        tp[1]=0;
        strcat(outstr,tp);
        continue;
       }
    } /* end of if $ */
  else {
   /* just a normal character */
   tp[0]=tmpMacros->body[i][j];
   tp[1]=0;
   strcat(outstr,tp);
   tp[0]=0;
   continue;
  } /* end of else */
 } /* end of for */
j=0;

/* copy extra arguments onto end depending  */
/* on how many substitions were given       */
if (!a && !noarg) {
  /* none given to match macro, copy whole inpstr to end */
  strcat(outstr," ");
  strcat(outstr,argu[0]);
  if (strlen(argu[1])) strcat(outstr," ");
  strcat(outstr,argu[1]);
  if (strlen(argu[2])) strcat(outstr," ");
  strcat(outstr,argu[2]);
  if (strlen(line)) strcat(outstr," ");
  j = ARR_SIZE - (strlen(outstr) + 1);
  line[j]=0;
  strcat(outstr,line);
  }
else if (a==1 && !noarg) {
  /* 1 given to match macro, copy last 3 to end */
  if (strlen(argu[1])) strcat(outstr," ");
  strcat(outstr,argu[1]);
  if (strlen(argu[2])) strcat(outstr," ");
  strcat(outstr,argu[2]);
  if (strlen(line)) strcat(outstr," ");
  j = ARR_SIZE - (strlen(outstr) + 1);
  line[j]=0;
  strcat(outstr,line);
  }
else if (a==2 && !noarg) {
  /* 2 given to match macro, copy last 2 to end */
  if (strlen(argu[2])) strcat(outstr," ");
  strcat(outstr,argu[2]);
  if (strlen(line)) strcat(outstr," ");
  j = ARR_SIZE - (strlen(outstr) + 1);
  line[j]=0;
  strcat(outstr,line);
  }
else if (a==3 && !noarg) {
  /* 3 given to match macro, copy last 1 to end */
  if (strlen(line)) strcat(outstr," ");
  j = ARR_SIZE - (strlen(outstr) + 1);
  line[j]=0;
  strcat(outstr,line);
  }

/* copy final processed string back to main input string */
strcpy(inpstr,outstr);

 argu[0][0]=0;
 argu[1][0]=0;
 argu[2][0]=0;
 argu[3][0]=0;  /* last input */
 line[0]=0; outstr[0]=0; tp[0]=0;
 arg1=0; arg2=0; arg3=0; a=0; i=0; j=0; found=0; noarg=0;

return 1;
}


/*---------------------------------------------------------*/
/* keep an audit trail of user logins and logoffs          */
/* in the system log file                                  */
/*---------------------------------------------------------*/
void syssign(int user, int onoff)
{
char stm[30];
char filename[FILE_NAME_LEN];
FILE *fp;

/* write to file */
write_log(LOGINLOG,YESTIME,"%s:%s:%s:%s:sck#%d:slt#%d\n",onoff == 1 ? "IN " : "OUT",ustr[user].name,ustr[user].site,ustr[user].net_name,ustr[user].sock,user);

 if (onoff==1) {

   /* the name does not get the color stripped out of it here */
   /* because this is the first time the bot will get the user name */
   /* to put in its list */
    sprintf(mess,"+++++ logon:%s %s %d", ustr[user].say_name,
		astr[ustr[user].area].name, ustr[user].vis);
    write_bot(mess);

  /* If user coming in in bot room, tell bot that user is here */
  if (ustr[user].area == ustr[bot].area) {
    sprintf(mess,"+++++ came in:%s", strip_color(ustr[user].say_name));
    write_bot(mess);
    }

  sprintf(filename,"%s/%s",LOGDIR,LASTLOGS);
  if (!(fp=fopen(filename,"a"))) {
       /* write_str(user,BAD_FILEIO); */
       /* writeall_str(mess, WIZ_ONLY, -1, 0, -1, BOLD, NONE, 0); */
       write_log(ERRLOG,YESTIME,"Couldn't open file(a) \"%s\" in syssign! %s\n",filename,get_error()); 
       return;
       }

strcpy(stm,get_time(0,0));
fprintf(fp,"%s  %s ",stm,strip_color(ustr[user].say_name));
fprintf(fp,"%s\n",strip_color(ustr[user].desc));
fclose(fp);

midcpy(stm,stm,11,12);
  if (!strcmp(stm,"00"))
   logstat[0].logins++;
  else if (!strcmp(stm,"01"))
   logstat[1].logins++;
  else if (!strcmp(stm,"02"))
   logstat[2].logins++;
  else if (!strcmp(stm,"03"))
   logstat[3].logins++;
  else if (!strcmp(stm,"04"))
   logstat[4].logins++;
  else if (!strcmp(stm,"05"))
   logstat[5].logins++;
  else if (!strcmp(stm,"06"))
   logstat[6].logins++;
  else if (!strcmp(stm,"07"))
   logstat[7].logins++;
  else if (!strcmp(stm,"08"))
   logstat[8].logins++;
  else if (!strcmp(stm,"09"))
   logstat[9].logins++;
  else if (!strcmp(stm,"10"))
   logstat[10].logins++;
  else if (!strcmp(stm,"11"))
   logstat[11].logins++;
  else if (!strcmp(stm,"12"))
   logstat[12].logins++;
  else if (!strcmp(stm,"13"))
   logstat[13].logins++;
  else if (!strcmp(stm,"14"))
   logstat[14].logins++;
  else if (!strcmp(stm,"15"))
   logstat[15].logins++;
  else if (!strcmp(stm,"16"))
   logstat[16].logins++;
  else if (!strcmp(stm,"17"))
   logstat[17].logins++;
  else if (!strcmp(stm,"18"))
   logstat[18].logins++;
  else if (!strcmp(stm,"19"))
   logstat[19].logins++;
  else if (!strcmp(stm,"20"))
   logstat[20].logins++;
  else if (!strcmp(stm,"21"))
   logstat[21].logins++;
  else if (!strcmp(stm,"22"))
   logstat[22].logins++;
  else if (!strcmp(stm,"23"))
   logstat[23].logins++;

 }
 else {
  /* If user leaving from bot room, tell bot that user left */
  if (ustr[user].area == ustr[bot].area) {
    sprintf(mess,"+++++ left:%s", strip_color(ustr[user].say_name));
    write_bot(mess);
    }
 }

}


/*---------------------------------------------------------*/
/* keep an audit trail of user logins to the who and www   */
/* ports in the system log file                            */
/*---------------------------------------------------------*/
int log_misc_connect(int user, unsigned long addr, int type)
{
char stm[30];
static char buf[256];
static char namebuf[256];
struct hostent *he;
time_t tm;

/* write to file */
time(&tm);
strcpy(stm,ctime(&tm));
stm[strlen(stm)-6]=0; /* get rid of nl at end */

/* Resolve sock address to hostname, if cant copy failed message */
 if (type != 3 && type != 4) {
 he = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
 if (he && he->h_name)
    strcpy(namebuf, he->h_name);
 else
    strcpy(namebuf, SYS_LOOK_FAILED);
 }

/* Resolve to ip */
addr = ntohl(addr);
sprintf(buf,"%ld.%ld.%ld.%ld", (addr >> 24) & 0xff, (addr >> 16) & 0xff,
         (addr >> 8) & 0xff, addr & 0xff);

if (type==1) {
  write_log(LOGINLOG,YESTIME,"WHO: Connection %s:%s:sck#%d:slt#%d\n",buf,namebuf,whoport[user].sock,user);
  strcpy(whoport[user].site,buf);
  strcpy(whoport[user].net_name,namebuf);
  }
else if (type==2) {
  write_log(LOGINLOG,YESTIME,"WWW: Connection %s:%s:sck#%d:slt#%d\n",buf,namebuf,wwwport[user].sock,user);
  strcpy(wwwport[user].site,buf);
  strcpy(wwwport[user].net_name,namebuf);
  }
else if (type==3) {
  strcpy(namebuf,buf);
  write_log(LOGINLOG,YESTIME,"RWHO: Connection %s:%s:sck#%d:slt#%d:%s\n",buf,namebuf,miscconn[user].sock,user,ustr[miscconn[user].user].name);
  strcpy(miscconn[user].site,buf);
  }
else if (type==4) {
  strcpy(namebuf,buf);
  write_log(LOGINLOG,YESTIME,"SMTP: Connection %s:%s:sck#%d:slt#%d\n",buf,namebuf,miscconn[user].sock,user);
  strcpy(miscconn[user].site,buf);
  }

if (type==1) {
  if (check_misc_restrict(whoport[user].sock,buf,namebuf) == 1) {
   write_log(BANLOG,YESTIME,"WHO : Connection attempt, RESTRICTed site %s:%s:sck#%d:slt#%d\n",buf,namebuf,whoport[user].sock,user);
   return -1;
   }
  else
   return 0;
  }
else if (type==2) {
  if (check_misc_restrict(wwwport[user].sock,buf,namebuf) == 1) {
   write_log(BANLOG,YESTIME,"WWW : Connection attempt, RESTRICTed site %s:%s:sck#%d:slt#%d\n",buf,namebuf,wwwport[user].sock,user);
   return -1;
   }
  else
   return 0;
  }

return 1;
}


/*** closes socket & does relevant output to other users & files ***/
void user_hot_quit(int user)
{
time_t tm;

time(&tm);
strcpy(ustr[user].last_date,  ctime(&tm));
  ustr[user].last_date[24]=0;
strcpy(ustr[user].last_site, ustr[user].site);
strcpy(ustr[user].last_name, ustr[user].net_name);
ustr[user].rawtime = tm;

/* Fix a user that has quit or has been killed while stuck in editing */
if (ustr[user].pro_enter) {
  free(ustr[user].pro_start);
  ustr[user].pro_end='\0';
  strcpy(ustr[user].flags,ustr[user].mutter);
  }
else if (ustr[user].vote_enter) {
  free(ustr[user].vote_start);
  ustr[user].vote_end='\0';
  strcpy(ustr[user].flags,ustr[user].mutter);
  }
else if (ustr[user].roomd_enter) {
  free(ustr[user].roomd_start);
  ustr[user].roomd_end='\0';
  strcpy(ustr[user].flags,ustr[user].mutter);
  }

queue_flush(user);
if (ustr[user].logging_in) {
        /* Close socket and clear from readmask */
	SHUTDOWN(ustr[user].sock, 2);
        while (CLOSE(ustr[user].sock) == -1 && errno == EINTR)
                ; /* empty while */
}
else {
copy_from_user(user);
write_user(ustr[user].name);
write_rebootdb(user);
}

        FD_CLR(ustr[user].sock,&readmask);
        FD_CLR(ustr[user].sock,&writemask);
	reset_user_struct(user,1);
}

/*** closes socket & does relevant output to other users & files ***/
/*** If mode is 0 we run silent and dont output/flush anything   ***/
void user_quit(int user, int mode)
{
int area=ustr[user].area;
int min;
time_t tm;

/* see is user has quit before he logged in */
if (ustr[user].logging_in) {
       min=(int)((time(0) - ustr[user].last_input)/60);
       if (min >= LOGIN_TIMEOUT)
        sprintf(mess," [LOGIN TIMED OUT from %s (%s)]",ustr[user].net_name,ustr[user].site);
       else
        sprintf(mess," [LOGIN ABORTED from %s (%s)]",ustr[user].net_name,ustr[user].site);
        writeall_str(mess, -2, user, 0, user, BOLD, NONE, 0);
        mess[0]=0;
        min=0;
   if (!strcmp(ustr[user].desc,DEF_DESC) && (ustr[user].super==0)) {
	if (mode) {
         write_str(user,"");
         write_str(user,"Description not set. GONNA HAFTA NUKE YOU. Sorry.");
         write_str(user,"");
	}
        remove_exem_data(ustr[user].login_name);
        remove_user(ustr[user].login_name);
        write_log(SYSTEMLOG,YESTIME,"AUTO-NUKE of %s\n",ustr[user].login_name);
        }

	/* Flush data to socket */
	if (mode) queue_flush(user);

	/* Close socket and clear from readmask */
	SHUTDOWN(ustr[user].sock, 2);
        while (CLOSE(ustr[user].sock) == -1 && errno == EINTR)
		; /* empty while */
        FD_CLR(ustr[user].sock,&readmask);
        FD_CLR(ustr[user].sock,&writemask);

	/* reset user structure */
	reset_user_struct(user,1);
	return;
	}

if (mode) write_str(user,BYE_MESS); 

time(&tm);
strcpy(ustr[user].last_date,  ctime(&tm));
  ustr[user].last_date[24]=0;
strcpy(ustr[user].last_site, ustr[user].site);
strcpy(ustr[user].last_name, ustr[user].net_name);
ustr[user].rawtime = tm;

min=(tm-ustr[user].time)/60;
if (min<0) min=0;

if (mode) {
sprintf(mess,"%s %s",
             ustr[user].say_name,  ustr[user].desc);
write_str(user,mess);

sprintf(mess,"From site %s - %s",
             ustr[user].last_site, ustr[user].last_name);
write_str(user,mess);
                                      
sprintf(mess,USE_MESS,ustr[user].last_date,converttime((long)min));
write_str(user,mess);
} /* end of mode */

/* kind of a fudge factor always have at least one */
if (ustr[user].aver==0) ustr[user].aver = 1;  

ustr[user].times_on++;

ustr[user].totl += (long)min;

ustr[user].aver = (int)(ustr[user].totl / (long)ustr[user].times_on);

/* Fix a user that has quit or has been killed while stuck in editing */
if (ustr[user].pro_enter) {
  free(ustr[user].pro_start);
  ustr[user].pro_end='\0';
  strcpy(ustr[user].flags,ustr[user].mutter);
  }
else if (ustr[user].vote_enter) {
  free(ustr[user].vote_start);
  ustr[user].vote_end='\0';
  strcpy(ustr[user].flags,ustr[user].mutter);
  }
else if (ustr[user].roomd_enter) {
  free(ustr[user].roomd_start);
  ustr[user].roomd_end='\0';
  strcpy(ustr[user].flags,ustr[user].mutter);
  }

copy_from_user(user);
write_user(ustr[user].name);

/* send message to other users & conv file */
if (ustr[user].super >= WIZ_LEVEL) 
  {
   sprintf(mess,SYS_DEPART_HI,ustr[user].say_name,ustr[user].desc);
   writeall_str(mess, 0, user, 0, user, NORM, LOGIO, 0);
  }
else 
  {
   sprintf(mess,SYS_DEPART_LO,ustr[user].say_name,ustr[user].desc);
   writeall_str(mess, 0, user, 0, user, NORM, LOGIO, 0);
  }

if (astr[area].private && (find_num_in_area(area) <= PRINUM) && (mode!=2))
   {
    strcpy(mess,NOW_PUBLIC);
    writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
    astr[area].private=0;
    cbuff(user);
   }


/* store signoff in log file & set some vars. */
num_of_users--;
syssign(user,0);

sprintf(mess,"+++++ logoff:%s",strip_color(ustr[user].say_name));
write_bot(mess);

if (ustr[user].ttt_opponent != -3)
        ttt_abort(user); 

if (user == fight.first_user || user == fight.second_user) reset_chal(0,"");

 if (autonuke) {
   if (!strcmp(ustr[user].desc,DEF_DESC) && (ustr[user].super==0)) {
	if (mode) {
        write_str(user,"");
        write_str(user,"Description not set. GONNA HAFTA NUKE YOU. Sorry.");
        write_str(user,"");
	}
        remove_exem_data(ustr[user].login_name);
        remove_user(ustr[user].login_name);
	write_log(SYSTEMLOG,YESTIME,"AUTO-NUKE of %s\n",ustr[user].say_name);

        sprintf(mess,"%s %s has been AUTO-NUKED",STAFF_PREFIX,strip_color(ustr[user].say_name));
        writeall_str(mess, WIZ_ONLY, user, 0, user, BOLD, WIZT, 0);
      }
   }

/* If bot logging off, clear bot id */
if (user==bot) {
  write_bot("+++++ QUIT");
  bot=-5;
  }

if (ustr[user].rwho > 1) {
/*
        write_str(user,"");
        write_str(user,"You're in the middle of a remote who. Your connection will not close until the task is done. Please wait.");
*/
for (min=0;min<MAX_MISC_CONNECTS;++min) {
        if (miscconn[min].user==user) {
        free_sock(min,'5');
	break;
	} /* if */
} /* for */
	write_log(SYSTEMLOG,YESTIME,"RWHO: Cancelled remote who for %s\n",strip_color(ustr[user].say_name));
	ustr[user].rwho=1;
}

 /* Flush data to socket */
if (mode) queue_flush(user);

 /* Close user's connection socket */
  SHUTDOWN(ustr[user].sock, 2);
  while (CLOSE(ustr[user].sock) == -1 && errno == EINTR)
	; /* empty while */
  FD_CLR(ustr[user].sock,&readmask);
  FD_CLR(ustr[user].sock,&writemask);

 /* reset user structure */
  reset_user_struct(user,1);

}


/*** prints who is on the system to requesting user ***/
void t_who(int user, char *inpstr, int mode)
{
FILE   *fp=NULL;
int    s,u,v,min,idl,invis=0,count=0,ranklen=0;
int    z=0;
int    vi=' ';
int    with,num=0;
char   ud[100],un[SAYNAME_LEN+5],an[ROOM_LEN+5],und[SAYNAME_LEN*2],rank[50];
char   temp[256];
char   check[NAME_LEN+1];
char   i_buff[5];
char   filename[FILE_NAME_LEN];
time_t tm;

/*------------------------------------------------------------*/
/* Check if inpstr length is greater than the max name length */
/*------------------------------------------------------------*/
if (strlen(inpstr) > NAME_LEN) {
   write_str(user,"Name too long.");
   return;
   }

if (check_rwho(user,inpstr) == 1) return;

if (mode==3) {
  if (ustr[user].friend_num==0) {
     write_str(user,"You have no friends!");
     return;
     }
  }  

/*-------------------------------------------------------*/
/* process the with command                              */
/*-------------------------------------------------------*/
with = user;
if (mode == 2)
  {
    if(strlen(inpstr) == 0) 
      {
       with = ustr[user].area;
      }
     else
      {
       sscanf(inpstr,"%s ",temp);
       strtolower(temp);

       if ((u=get_user_num(temp,user))== -1) 
         {
           not_signed_on(user,temp);  
           return;
         }
       with = ustr[u].area;
      }
  }

if (ustr[user].pbreak) {
   strcpy(filename,get_temp_file());
   if (!(fp=fopen(filename,"w"))) {
     write_str(user,BAD_FILEIO);
     return;
     }
   }

time(&tm);
/* display current time */
if (mode==1)
 sprintf(mess,WWHO_COLOR,get_time(0,1));
else if (mode==3)
 sprintf(mess,FWHO_COLOR,get_time(0,1));
else
 sprintf(mess,WHO_COLOR,get_time(0,1));

if (ustr[user].pbreak) {
   strcat(mess,"\n\r\n\r");
   fputs(mess,fp);
   }
else {
write_str(user,mess);
write_str(user,"");
}

/* Give Display format */
if (ustr[user].who==0) { /* OURS */
/* sprintf(mess,"^LCRoom^             "); */
sprintf(mess,"%-*s",ROOM_LEN+6,"^LCRoom^");
strcat(mess,"^HGTime^ "); 
strcat(mess,"^HRStat^ "); 
strcat(mess,"^Idl^   ");
strcat(mess,"^HMName^/^HBDescription^");
if (ustr[user].pbreak) {
   strcat(mess,"\n");
   fputs(mess,fp);
   }
else write_str(user,mess);
} /* end of if */
else if (ustr[user].who==2) { /* IFORMS */
/* sprintf(mess,"^LCRoom^              "); */
sprintf(mess,"%-*s",ROOM_LEN+7,"^LCRoom^");
strcat(mess,"^HMName^/^HBDescription^                           ");
strcat(mess,"^HGTime^-"); 
strcat(mess,"^HRStat^-"); 
strcat(mess,"^Idle^");
if (ustr[user].pbreak) {
   strcat(mess,"\n");
   fputs(mess,fp);
   }
else write_str(user,mess);
} /* end of if */
else if (ustr[user].who==3) { /* NEW */
sprintf(mess,"%-*s %-*s ",NAME_LEN,"Name",ROOM_LEN,"Room");
strcat(mess,"    On For Idle");
if (ustr[user].pbreak) {
   strcat(mess,"\n");
   fputs(mess,fp);
   }
else write_str(user,mess);
} /* end of if */


if (mode!=3) {
for (v=0;v<NUM_AREAS;++v) {
  for (u=0;u<MAX_USERS;++u) {
	if ((ustr[u].area!= -1) && (ustr[u].area == v) && (!ustr[u].logging_in))
	  {
		if (!ustr[u].vis && ustr[user].tempsuper < MIN_HIDE_LEVEL)
	          {
	            invis++;
	            continue; 
	          }
	   
       	        min=(int)((time(0)-ustr[u].time)/60);
		idl=(int)((time(0)-ustr[u].last_input)/60);
		if (min<0) min=0;
		if (idl<0) idl=0;

		if (ustr[user].who==1)
		sprintf(un," %s",ustr[u].say_name);
		else
		strcpy(un,ustr[u].say_name);

                if (ustr[u].afk==0)
		 strcpy(ud,ustr[u].desc);
		else if ((strlen(ustr[u].afkmsg) > 1) && (ustr[u].afk>=1))
		 strcpy(ud,ustr[u].afkmsg);
                else if (!strlen(ustr[u].afkmsg) && (ustr[u].afk>=1))
                 strcpy(ud,ustr[u].desc);

		strcpy(und,un);
		strcat(und," ");
		strcat(und,ud);
		
		if (!astr[ustr[u].area].hidden)
		  {
		    strcpy(an,astr[ustr[u].area].name);
		  }
		 else
		  { 
		    if ((ustr[user].tempsuper >= ROOMVIS_LEVEL) && SHOW_HIDDEN)
		      {
		        strcpy(an, "<");
		        strcat(an, astr[ustr[u].area].name);
		        strcat(an, ">");
		      }
		     else
		      {
		       strcpy(an, "        ");
		      }
		  }
		  
		
		if (ustr[user].tempsuper >= WHO_LEVEL) 
		   { 
		    s=ranks[ustr[u].super].abbrev;
		   }
		  else
		   s=' ';
		   
		if (ustr[u].afk == 1) {
		   if (ustr[u].lockafk)
		    strcpy(i_buff,"^HYLAFK^");
		   else
		    strcpy(i_buff,"^HYAFK^ ");
                  }
		 else if (ustr[u].afk == 2) {
		      strcpy(i_buff,"^HRBAFK^");
                     }
                 else if (ustr[u].pro_enter) {
		      strcpy(i_buff,"^HGPROF^");
                     }
                 else if (ustr[u].vote_enter) {
		      strcpy(i_buff,"^HGVOTE^");
                     }
                 else if (ustr[u].roomd_enter) {
		      strcpy(i_buff,"^HGDESC^");
                     }
		 else {
		if ((ustr[user].who==1) && (ustr[user].tempsuper >= WHO_LEVEL))
		 strcpy(i_buff,"");
		else {
                  if (idl < 3)
                    strcpy(i_buff,"Actv");
                  else if (idl >= 3 && idl < 60)
                    strcpy(i_buff,"Awke");
                  else if (idl >= 60 && idl < 180)
		    strcpy(i_buff,"Idle"); 
                  else if (idl >= 180)
                    strcpy(i_buff,"Coma");
		  }
                    } 

	if (ustr[user].who==1) {
	if (ustr[user].tempsuper >= WHO_LEVEL) {
	strcpy(rank,ranks[ustr[u].super].sname);
	ranklen=RANK_LEN;
	}
	else {
	strcpy(rank,"  ");
	strcat(rank,i_buff);
	strcat(rank,"  ");
	strcpy(i_buff,"");
	ranklen=strlen(rank);
	}
	}

	if (ustr[user].who==1) {
		if (!ustr[u].vis)
		 und[0]='*';
	}
	else {
                if (!ustr[u].vis) vi='_';
                else vi=' ';
	}

count=DESC_LEN+count_color(und,0);
/*
sprintf(mess,"len without mod        : %d\nlen of colors          : %d\nlen of replacing colors: %d\ncount                  : %d\n",strlen(und),count_color(und,0),count_color(und,1),count);
write_str(user,mess);
*/
if (ustr[user].who==1)
        sprintf(mess,"%-*s :%-*s:%-*s:%-3.3d m %s",count,und,ranklen,rank,ROOM_LEN,an,min,i_buff);
else if (ustr[user].who==2)
        sprintf(mess,"%-*s %c%c%-*s %-5.5d %s %3.3d",ROOM_LEN,an,s,vi,count,und,min,i_buff,idl);
else if (ustr[user].who==3) {
        sprintf(mess,"%-*s %-*s %s %s",NAME_LEN+count_color(ustr[u].say_name,0),
ustr[u].say_name,ROOM_LEN,an,time_format_1((time_t)time(0)-ustr[u].time),
time_format_2((time_t)time(0)-ustr[u].last_input));
}
else
        sprintf(mess,"%-*s %-5.5d %s %3.3d %c%c%s",ROOM_LEN,an,min,i_buff,idl,s,vi,und);

count=0;
		
		strncpy(temp,strip_color(mess),256);
		strtolower(temp);
		
		if (!strlen(inpstr) ||
		     instr2(0,mess,inpstr,0)!= -1 ||
		     instr2(0,temp,inpstr,0)!= -1 ||
		     mode > 0) 
		 {
		   if ((mode == 1 && ustr[u].tempsuper >= WIZ_LEVEL) || 
		        mode == 0 ||
		       (mode == 2 && ustr[u].area == with))
		     {
		      mess[0]=toupper((int)mess[0]);
			if (ustr[user].pbreak) {
			   strcat(mess,"\n");
  			   fputs(mess,fp);
  			 }
		      else write_str(user,mess);
                      num++;
		     }  /* inpstr check */
                 }  /* mode check */
	   }  /* if user in area check */
	}  /* user for */
 }  /* area for */
}  /* end of mode if */

/* Friends check */
if (mode==3) {
for (z=0; z<MAX_ALERT; ++z) {
  strcpy(check,ustr[user].friends[z]);
  strtolower(check);
for (v=0;v<NUM_AREAS;++v) {
  for (u=0;u<MAX_USERS;++u) {
	if ((ustr[u].area!= -1) && (ustr[u].area == v) && (!ustr[u].logging_in))
	  {
            if (!strcmp(ustr[u].name,check)) {
		if (!ustr[u].vis && ustr[user].tempsuper < MIN_HIDE_LEVEL)
	          {
	            invis++;
	            continue; 
	          }
	   
       	        min=(int)((time(0)-ustr[u].time)/60);
		idl=(int)((time(0)-ustr[u].last_input)/60);
		if (min<0) min=0;
		if (idl<0) idl=0;

		if (ustr[user].who==1)
		sprintf(un," %s",ustr[u].say_name);
		else
		strcpy(un,ustr[u].say_name);

                if (ustr[u].afk==0)
		 strcpy(ud,ustr[u].desc);
		else if ((strlen(ustr[u].afkmsg) > 1) && (ustr[u].afk>=1))
		 strcpy(ud,ustr[u].afkmsg);
                else if (!strlen(ustr[u].afkmsg) && (ustr[u].afk>=1))
                 strcpy(ud,ustr[u].desc);

		strcpy(und,un);
		strcat(und," ");
		strcat(und,ud);
		
		if (!astr[ustr[u].area].hidden)
		  {
		    strcpy(an,astr[ustr[u].area].name);
		  }
		 else
		  { 
		    if ((ustr[user].tempsuper >= ROOMVIS_LEVEL) && SHOW_HIDDEN)
		      {
		        strcpy(an, "<");
		        strcat(an, astr[ustr[u].area].name);
		        strcat(an, ">");
		      }
		     else
		      {
		       strcpy(an, "        ");
		      }
		  }
		  
		
		if (ustr[user].tempsuper >= WHO_LEVEL) 
		   { 
		    s=ranks[ustr[u].super].abbrev;
		   }
		  else
		   s=' ';
		   
		if (ustr[u].afk == 1) {
		   if (ustr[u].lockafk)
		    strcpy(i_buff,"^HYLAFK^");
		   else
		    strcpy(i_buff,"^HYAFK^ ");
                  }
		 else if (ustr[u].afk == 2) {
		      strcpy(i_buff,"^HRBAFK^");
                     }
                 else if (ustr[u].pro_enter) {
		      strcpy(i_buff,"^HGPROF^");
                     }
                 else if (ustr[u].vote_enter) {
		      strcpy(i_buff,"^HGVOTE^");
                     }
                 else if (ustr[u].roomd_enter) {
		      strcpy(i_buff,"^HGDESC^");
                     }
		 else {
		if ((ustr[user].who==1) && (ustr[user].tempsuper >= WHO_LEVEL))
		  strcpy(i_buff,"");
		else {
                  if (idl < 3)
                    strcpy(i_buff,"Actv");
                  else if (idl >= 3 && idl < 60)
                    strcpy(i_buff,"Awke");
                  else if (idl >= 60 && idl < 180)
		    strcpy(i_buff,"Idle"); 
                  else if (idl >= 180)
                    strcpy(i_buff,"Coma");
		  }
                    } 

	if (ustr[user].who==1) {
	if (ustr[user].tempsuper >= WHO_LEVEL) {
	strcpy(rank,ranks[ustr[u].super].sname);
	ranklen=RANK_LEN;
	}
	else {
	strcpy(rank,"  ");
	strcat(rank,i_buff);
	strcat(rank,"  ");
	strcpy(i_buff,"");
	ranklen=strlen(rank);
	}
	}

	if (ustr[user].who==1) {
		if (!ustr[u].vis)
		 und[0]='*';
	}
	else {
                if (!ustr[u].vis) vi='_';
                else vi=' ';
	}

count=DESC_LEN+count_color(und,0);
if (ustr[user].who==1)
        sprintf(mess,"%-*s :%-*s:%-*s:%-3.3d min %s",count,und,ranklen,rank,ROOM_LEN,an,min,i_buff);
else if (ustr[user].who==2)
        sprintf(mess,"%-*s %c%c%-*s %-5.5d %s %3.3d",ROOM_LEN,an,s,vi,count,und,min,i_buff,idl);
else if (ustr[user].who==3) {
        sprintf(mess,"%-*s %-*s %s %s",NAME_LEN+count_color(ustr[u].say_name,0),
ustr[u].say_name,ROOM_LEN,an,time_format_1((time_t)time(0)-ustr[u].time),
time_format_2((time_t)time(0)-ustr[u].last_input));
}
else
        sprintf(mess,"%-*s %-5.5d %s %3.3d %c%c%s",ROOM_LEN,an,min,i_buff,idl,s,vi,und);

count=0;
                 
		      mess[0]=toupper((int)mess[0]);
			if (ustr[user].pbreak) {
			   strcat(mess,"\n");
  			   fputs(mess,fp);
  			 }
		      else write_str(user,mess);
                      num++;
              }  /* end of if found */
	   }  /* if user in area check */
	}  /* user for */
  }  /* area for */
 }  /* end of friends list for */
}  /* end of mode if */


if (invis) {
sprintf(mess,SHADOW_COLOR,invis == 1 ? "is" : "are",invis,invis == 1 ? " " : "s");

	if (ustr[user].pbreak) {
	   strcat(mess,"\n");
	   fputs(mess,fp);
  	 }
	else write_str(user,mess);

	}

if (ustr[user].pbreak) {
   fputs("\n",fp);
   }	
else write_str(user," ");

 if (mode==1)
  sprintf(mess,WUSERCNT_COLOR,num,num == 1 ? "" : "s");
 else if (mode==3)
  sprintf(mess,FUSERCNT_COLOR,num,num == 1 ? "" : "s");
 else
  sprintf(mess,USERCNT_COLOR,num_of_users,num_of_users == 1 ? "" : "s");

	if (ustr[user].pbreak) {
	   strcat(mess,"\n");
	   fputs(mess,fp);
           fputs("\n",fp);
  	 }
  else {
  write_str(user,mess);
  write_str(user," ");
  }

	if (ustr[user].pbreak) {
	   fclose(fp);
           cat(filename,user,0);
  	 }

}


/*** prints who is on the system to requesting user ***/
void swho(int user, char *inpstr)
{
int u;
int found = 0;

/* Give Display format */
if ( !strlen(inpstr) )
  {
   write_str(user,"----------------------------------------------------------------");
   write_str(user,"User          IP address    User#:Sock  Hostname");
   write_str(user,"----------------------------------------------------------------");
  }
else strtolower(inpstr);

/* display who port connections */
for (u=0; u<MAX_WHO_CONNECTS; ++u) 
  {
   if (strlen(whoport[u].site) > 1) {
	   sprintf(mess, SYS_SITE_LINE, " [who port] ", 
	                                whoport[u].site, 
	                                u, whoport[u].sock,
		                        whoport[u].net_name );

	   if (!strlen(inpstr) || instr2(0,mess,inpstr,0) != -1) 
	     {
	       mess[0]=toupper((int)mess[0]);
	       write_str(user,mess);
               found=1;
             }
     } /* end of if */
  } /* end of for */
u=0;

/* display www port connections */
for (u=0; u<MAX_WWW_CONNECTS; ++u) 
  {
   if (strlen(wwwport[u].site) > 1) {
	   sprintf(mess, SYS_SITE_LINE, " [www port] ", 
	                                wwwport[u].site, 
	                                u, wwwport[u].sock,
		                        wwwport[u].net_name );

	   if (!strlen(inpstr) || instr2(0,mess,inpstr,0) != -1) 
	     {
	       mess[0]=toupper((int)mess[0]);
	       write_str(user,mess);
               found=1;
             }
     } /* end of if */
  } /* end of for */
u=0;
/* display misc connections */
for (u=0; u<MAX_MISC_CONNECTS; ++u) 
  {
   if (miscconn[u].sock != -1) {
	if (miscconn[u].type==1) {
	   sprintf(mess, SYS_SITE_LINE, " [ rwho ] ", 
	                                miscconn[u].site, 
	                                u, miscconn[u].sock,
		                        itoa(miscconn[u].port) );
	}
	else if (miscconn[u].type==2) {
	   sprintf(t_mess, "Stage: %d Queue: %s",miscconn[u].stage,miscconn[u].queuename);
	   sprintf(mess, SYS_SITE_LINE, " [ smtp ] ", 
	                                miscconn[u].site, 
	                                u, miscconn[u].sock,
		                        t_mess );
	}

	   if (!strlen(inpstr) || instr2(0,mess,inpstr,0) != -1) 
	     {
	       mess[0]=toupper((int)mess[0]);
	       write_str(user,mess);
               found=1;
             }
     } /* end of if */
  } /* end of for */
u=0;
/* display user list */
for (u=0; u<MAX_USERS; ++u) 
  {
    if (!strcmp(ustr[u].name,inpstr)) found = 2;

    if (ustr[u].area != -1)  
      {
	sprintf(mess, SYS_SITE_LINE, ustr[u].name,
	                             ustr[u].site,
	                             u, ustr[u].sock,
		                     ustr[u].net_name );

        if (strlen(inpstr) && (found==2)) {
	   mess[0]=toupper((int)mess[0]);
	   write_str(user,mess);
           write_str(user," ");
           return;
           }
	else if (!strlen(inpstr) || instr2(0,mess,inpstr,0) != -1) 
	  {
	   mess[0]=toupper((int)mess[0]);
	   write_str(user,mess);
           found=1;
          }
       } /* end of area if */
      else if (ustr[u].logging_in) 
         {
	   sprintf(mess, SYS_SITE_LINE, " [login] ", 
	                                ustr[u].site, 
	                                u, ustr[u].sock,
		                        ustr[u].net_name );

	   if (!strlen(inpstr) || instr2(0,mess,inpstr,0) != -1) 
	     {
	       mess[0]=toupper((int)mess[0]);
	       write_str(user,mess);
               found=1;
             }
	  } /* end of else if */
  } /* end of for */
/*
for (u=0;u<MAX_CONNLIST_ENTRIES;++u) {
	sprintf(mess,"%14s %2d %ld\n",connlist[u].site,connlist[u].connections,
	connlist[u].starttime);
	write_str(user,mess);
}
*/

if (!found) {
/* plug security hole */
if (check_fname(inpstr,user))
  {                                     
   write_str(user,"Illegal name.");
   return;
  }

   if (!check_for_user(inpstr)) {
     write_str(user,NO_USER_STR);
     return;
     }
   read_user(inpstr);
   sprintf(mess,"%s, in from %s %s",t_ustr.say_name,t_ustr.last_site,t_ustr.last_name);
   write_str(user,mess);
   }

write_str(user," ");
}


/*** not signed on - subsid func ***/
void not_signed_on(int user, char *name)
{
sprintf(mess,"%s is not signed on",name);
mess[0]=toupper((int)mess[0]);
write_str(user,mess);
return;
}


/*** go moves user into different room ***/
void go(int user, char *inpstr, int user_knock)
{
int f;
int new_area=0;
int teleport=0;
int beep=0;
int area=ustr[user].area;
int found = 0;
char room_char;
char room_name[ARR_SIZE];
char entmess[80];
char exitmess[80];

if (ustr[user].anchor) {
  write_str(user,ANCHORED_DOWN);
  return;
  }

if (!strlen(inpstr)) 
  {
   if (user_knock==1) 
     {
      write_str(user,"Knock where?");
      return;
     }
    else if (!user_knock)
     {
      if ((ustr[user].tempsuper==0) && (!strcmp(ustr[user].desc,DEF_DESC))
          && (area==new_room)) {
          write_str(user,"You can't leave this room until you set a description with .desc");
          return;
         }
      write_str(user,"*** warp to main room ***");
      new_area = INIT_ROOM;
      teleport = 1;
     }
  }
 else
  {
   sscanf(inpstr,"%s ",room_name);

      if ((ustr[user].tempsuper==0) && (!strcmp(ustr[user].desc,DEF_DESC))
          && (area==new_room)) {
          write_str(user,"You can't leave this room until you set a description with .desc");
          return;
         }

   /*--------------------*/
   /* see if area exists */
   /*--------------------*/

   found = FALSE;
   for (new_area=0; new_area < NUM_AREAS; ++new_area)
    { 
     if (! instr2(0, astr[new_area].name, room_name, 0) )
       { 
         found = TRUE;
         break;
       }
    }
 
   if (!found)
     {
      write_str(user, NO_ROOM);
      return;
     }
  }
  
/*----------------------------------------------*/
/* check to see if the user is in that room     */
/*----------------------------------------------*/

if (ustr[user].area == new_area) 
  {
    write_str(user,"You are in that room now!");  
    return;
  }

/*----------------------------------------------*/
/* check for secure room                        */
/*----------------------------------------------*/

if (ustr[user].security[new_area] == 'X' && user_knock!=1) 
  {
   /* don't let in unless invited */
   if (ustr[user].invite != new_area ) {
   write_str(user,"Your security clearance does not let you enter there");
   return;
   }
  }
  
/*-----------------------------------------------*/
/* see if user can get to area from current area */
/*-----------------------------------------------*/

room_char = new_area + 'A';                /* get char. repr. of room to move to */

  strcpy(entmess,ustr[user].entermsg);
  strcpy(exitmess,ustr[user].exitmsg);

/*------------------------------------------*/
/* see if new room is joined to current one */
/*------------------------------------------*/

found = FALSE;
for (f=0; f<strlen(astr[area].move); ++f) 
 {
  if ( astr[area].move[f] == room_char )  
    {
     found = TRUE;
     break;
    }
 }

/*--------------------------------------------------------------*/
/* anyone equal to the TELEP_LEVEL or higher can teleport to    */
/* non-connected rooms                                          */
/*--------------------------------------------------------------*/

if (!found)
  {
    if ((ustr[user].tempsuper >= TELEP_LEVEL) || (ustr[user].security[new_area] == 'Y')) 
      {
        strcpy(entmess,COME_TELEMESS);  
        beep=1;
        teleport=1;  
        found = TRUE;
      }
  }
  
if (!strlen(inpstr) && strcmp(astr[ustr[user].area].name,ARREST_ROOM)) {
     found = TRUE;
     }

if ((user_knock==2)
    && strcmp(astr[ustr[user].area].name,ARREST_ROOM)
    && FOLLOWIS_JOIN) {
    found = TRUE;
    }

if (!found)
  { 
   write_str(user,"That room is not adjoined to here");
   return;
  }

/*-----------------------------------------------------------*/
/* check for a user knock                                    */
/*-----------------------------------------------------------*/
if (user_knock==1) 
  {
   knock(user,new_area);  
   return;
  }
  
/*-----------------------------------------------------------*/
/* if the room is private abort move...inform user           */
/*-----------------------------------------------------------*/

if (astr[new_area].private && ustr[user].invite != new_area ) 
  {
   write_str(user,"Sorry - that room is currently private");
   return;
  }

/* record movement */
if (teleport || astr[new_area].hidden)
  sprintf(mess,GO_TELEMESS,ustr[user].say_name);
 else {
  if (!strcmp(exitmess,DEF_EXIT))
   sprintf(mess,"%s %s %s",ustr[user].say_name,exitmess,astr[new_area].name);
  else  
   sprintf(mess,"%s %s",ustr[user].say_name,exitmess);
  }

/* send output to old room & to conv file */
if (!ustr[user].vis) {
   if (area == ustr[bot].area) {
    sprintf(mess,"+++++ left:%s", strip_color(ustr[user].say_name));
    write_bot(mess);
    }
   strcpy(mess,INVIS_MOVES);
   }
	
writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);

if (ustr[user].vis) {
   sprintf(mess,"%s has left the room.",ustr[user].say_name);
   writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
   if (area == ustr[bot].area) {
    sprintf(mess,"+++++ left:%s", strip_color(ustr[user].say_name));
    write_bot(mess);
    }
   }

/*-----------------------------------------------------------*/
/* return room to public     (if needed)                     */
/*-----------------------------------------------------------*/

if (astr[area].private && (find_num_in_area(area) <= PRINUM))
  {
   strcpy(mess,NOW_PUBLIC);
   writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
   cbuff(user); 
   astr[area].private=0;
  }

/* record movement to new room */ 
sprintf(mess,"%s %s",ustr[user].say_name,entmess);

/* send output to new room */
if (!ustr[user].vis) 
	strcpy(mess,INVIS_MOVES);

if (!strcmp(astr[new_area].name,HEAD_ROOM)) {
   write_str(user,"A portal appears from nowhere as you step in it.");
   write_str_nr(user,"Identify for retina scan.");
	telnet_write_eor(user);
      if (!strcmp(ustr[user].name,ROOT_ID) || !strcmp(ustr[user].name,"matrix")
          || !strcmp(ustr[user].name,"sirkrake") || !strcmp(ustr[user].name,"pixie")
          || !strcmp(ustr[user].name,"shadowlord") || !strcmp(ustr[user].name,"sauron") 
          || !strcmp(ustr[user].name,"shadowscragger") || !strcmp(ustr[user].name,"stauf")
          || !strcmp(ustr[user].name,"wil") || !strcmp(ustr[user].name,"ladybug")
          || !strcmp(ustr[user].name,"damia") || !strcmp(ustr[user].name,"lazarus")
          || !strcmp(ustr[user].name,"krystal") || !strcmp(ustr[user].name,"dagny")
          || !strcmp(ustr[user].name,"weasal") || !strcmp(ustr[user].name,"scupper")
          || !strcmp(ustr[user].name,"necros") || !strcmp(ustr[user].name,"hecubus")
          || !strcmp(ustr[user].name,"cygnus"))
        {
         if (user_wants_message(user,BEEPS)) {
          write_str_nr(user,".\07");
	telnet_write_eor(user);
          write_str_nr(user,".\07");
	telnet_write_eor(user);
          write_str_nr(user,".\07\07");
	telnet_write_eor(user);
          }
         else {
          write_str_nr(user,".");
	telnet_write_eor(user);
          write_str_nr(user,".");
	telnet_write_eor(user);
          write_str_nr(user,".");
	telnet_write_eor(user);
          }
         write_str(user,"Access granted!");
         write_str(user,"\nThe portal closes behind you...\n");
        }
      else { 
       if (user_wants_message(user,BEEPS)) {
        write_str_nr(user,".\07");
	telnet_write_eor(user);
        write_str_nr(user,".\07");
	telnet_write_eor(user);
        }
       else {
        write_str_nr(user,".");
	telnet_write_eor(user);
        write_str_nr(user,".");
	telnet_write_eor(user);
        }
       write_str(user,"Identification not recognized..sorry.");
       return;
       }
  }
    
ustr[user].area = new_area;

if (beep==1)
 writeall_str(mess, 1, user, 0, user, BEEPS, NONE, 0);
else
 writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
beep=0;

   if (new_area == ustr[bot].area) {
    sprintf(mess,"+++++ came in:%s", strip_color(ustr[user].say_name));
    write_bot(mess);
    }

/* deal with user */
if (ustr[user].invite == new_area)  
  ustr[user].invite= -1;
  
look(user,"");
}



/*** knock - subsid func of go ***/
void knock(int user, int new_area)
{
int temp;

if (!astr[new_area].private) 
  {
   write_str(user,"That room is public anyway");
   return;
  }
  
write_str(user,"You knock on the door");
sprintf(mess,"%s knocks on the door",ustr[user].say_name);
if (!ustr[user].vis)
 sprintf(mess,"%s knocks on the door",INVIS_ACTION_LABEL);

/* swap user area 'cos of way output func. works */
temp=ustr[user].area;
ustr[user].area=new_area;
writeall_str(mess, 1, user, 0, user, NORM, KNOCK, 0);
ustr[user].area=temp;

/* send message to users in current room */
sprintf(mess,"%s knocks on the %s door",ustr[user].say_name,astr[new_area].name);
writeall_str(mess, 1, user, 0, user, NORM, KNOCK, 0);
}


/* Edit a user profile from the command line */
/* op_mode = 0       Straight editing of a line               */
/* op_mode = 1       Clearing of a line                       */
/* op_mode = 2       Blanking of a line                       */
/* op_mode = 3       Inserting a line at end of file          */
/* op_mode = 4       Inserting a blank line at end of file    */
/* op_mode = 5       Inserting a line in middle of file       */
/* op_mode = 6       Inserting a blank line in middle of file */

void inedit_file(int user, char *inpstr, int line_num, int mode)
{
int a=0;
int lines=0;
int diff=0;
char buffer[ARR_SIZE];
char filename[FILE_NAME_LEN];
char filename2[FILE_NAME_LEN];
FILE *fp;
FILE *fp2;

sprintf(filename,"%s/%s",PRO_DIR,ustr[user].name);
lines = file_count_lines(filename);
fp=fopen(filename,"r");

/* Put these mode checks in first so we know if we can insert anymore */
/* lines in the users profile.                                        */
if ((mode==3) || (mode==4) || (mode==5) || (mode==6)) {
   if (lines==PRO_LINES) {
     write_str(user,"You cant insert anymore lines to an already full profile.");
     FCLOSE(fp);
     return;
    }
  }

/* Put these modes first since we know they contain an input string */
/* and only need to append to the end of the original file          */
if ((mode==3) || (mode==4)) {
FCLOSE(fp);
if (!(fp=fopen(filename,"a"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open file(a) \"%s\" in inedit_file! %s\n",filename,get_error());
	return;
        }
   if (mode==3) { fputs(inpstr,fp); }
   else if (mode==4) { }

   fputs("\n",fp);
   if (mode==3)
    write_str(user,"Inserted text to end.");
   else if (mode==4)
    write_str(user,"Inserted blank line to end.");
   FCLOSE(fp);
   if (mode==3) {
        if (autopromote == 1)
         check_promote(user,9);
     }
   return;
  }

if (!strlen(inpstr)) {
  if (line_num > lines) {
    write_str(user,"You dont have anything in that line.");
    FCLOSE(fp);
    return;
    }
   for (a=1;a<PRO_LINES+1;++a) {
      fgets(buffer,1000,fp);
      buffer[strlen(buffer)-1]=0;
      if (a==line_num) {
         if (strlen(buffer) > 1)
          sprintf(mess,"Line ^%d^ is: %s",line_num,buffer);
         else
          sprintf(mess,"Line ^%d^ is blank.",line_num);
         write_str(user,mess);
         FCLOSE(fp);
         return;
        }
      strcpy(buffer,"");
     } /* end of for */
  } /* end of no input string */
else {
strcpy(filename2,get_temp_file());
if (!(fp2=fopen(filename2,"a"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open tempfile(a) for %s to append to in inedit_file()! %s\n",ustr[user].name,get_error());
        FCLOSE(fp); return;
        }
 if (mode==1) {
   if (line_num > lines) {
     write_str(user,"That line doesnt exist to clear.");
     FCLOSE(fp);
     FCLOSE(fp2);
     return;
    }
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) { }
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   sprintf(mess,"Line ^%d^ cleared!",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
  } /* end of clear line mode */
 else if (mode==2) {
   if (line_num > lines) {
     write_str(user,"That line doesnt exist to blank.");
     FCLOSE(fp);
     FCLOSE(fp2);
     return;
    }
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) fputs("\n",fp2);
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   sprintf(mess,"Line ^%d^ blanked!",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
  } /* end of blank line mode */

 else if (mode==5 || mode==6) {
   if (line_num > lines) {
     write_str(user,"That line doesnt exist to insert after.");
     FCLOSE(fp);
     FCLOSE(fp2);
     return;
    }
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) {
        fputs(buffer,fp2);
        if (mode==5) {
         fputs(inpstr,fp2);
         fputs("\n",fp2);
         }
        else if (mode==6) fputs("\n",fp2);
        }
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   if (mode==5)
    sprintf(mess,"Inserted your text after line ^%d^",line_num);
   else if (mode==6)
    sprintf(mess,"Inserted a blank line after line ^%d^",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   if (mode==5) {
        if (autopromote == 1)
         check_promote(user,9);
     }
   return;
  } /* end of insert line in middle mode */

 if (line_num > lines) {
   diff = line_num - lines;

   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   a=0;
   if (diff!=1) {
     for (a=0;a<diff-1;++a) {
      fputs("\n",fp2);
       }
     } /* end of if diff */
   fputs(inpstr,fp2);
   fputs("\n",fp2);
   sprintf(mess,"Added line ^%d^",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);

        if (autopromote == 1)
         check_promote(user,9);

   return;
   } /* end of greater than if */
 else {
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) {
        fputs(inpstr,fp2);
        fputs("\n",fp2);
        }
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   sprintf(mess,"Modified line ^%d^",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);

        if (autopromote == 1)
         check_promote(user,9);

   return;
  } /* end of other line edit else */
 } /* end of main else */

}

/** Write profile in buffer to file **/
int write_pro(int user)
{
char *c,filename[FILE_NAME_LEN];
FILE *fp;

sprintf(filename,"%s/%s",PRO_DIR,ustr[user].name);
if (!(fp=fopen(filename,"w"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open file(w) \"%s\" in write_pro! %s\n",filename,get_error());
	return 0;
        }
for (c=ustr[user].pro_start;c<ustr[user].pro_end;++c) putc(*c,fp);
fclose(fp);
return 1;
}


/** Enter room description ***/
void descroom(int user, char *inpstr)
{
char *c;
int ret_val;
int redo=0;
int i=0; /*******/
int op_mode=0; /******/
char option[ARR_SIZE]; /******/
char filename[FILE_NAME_LEN];
char filename2[FILE_NAME_LEN];
FILE *fp;

if ((!strcmp(astr[ustr[user].area].name,HEAD_ROOM)) ||
    (!strcmp(astr[ustr[user].area].name,"sky_palace"))) {
    write_str(user,"Can't make a description for this room, sorry.");
    return;
    }

/* get memory */
STARTROOMD:

if (!ustr[user].roomd_enter) {
       option[0]=0;
       sscanf(inpstr,"%s ",option);
       if (!strcmp(option,"-c") || !strcmp(option,"clear")) {
       sprintf(filename,"%s/%s",datadir,astr[ustr[user].area].name);
       remove(filename);
       write_str(user,"Room description deleted.");
       return;
       }
        if (!(ustr[user].roomd_start=(char *)malloc(82*ROOM_DESC_LINES))) {
        write_str(user,BAD_MALLOC);
	write_log(ERRLOG,YESTIME,"MALLOC: Can't malloc memory in descroom! %s\n",get_error());
        return;
        }

       if (strlen(inpstr) && (!redo)) {
         if (!strncmp(option,"-i",2)) {
          if (strlen(option)==2) op_mode=3;
          else {
           for (i=2;i<strlen(option);++i) {
              if (!isdigit((int)option[i])) {
                write_str(user,"Line number given was not a number!");
                return;
                }
             } /* end of for */
           i=0;
           midcpy(option,option,2,7);
           i=atoi(option);
           if (i == 0) {
             write_str(user,"Description lines start at 1. Not 0. Try again.");
             return;
             }
           op_mode=5;
          } /* end of else */

          remove_first(inpstr);
          if (op_mode==3) {
            if (!strlen(inpstr)) {
              write_str(user,"You must have text or a -b after this option");
              return;
              }
            if (!strcmp(inpstr,"-b")) op_mode=4;
            inedit_file2(user,inpstr,1,op_mode);
            return;
           }
          else if (op_mode==5) {
            if (!strlen(inpstr)) {
              write_str(user,"You must have text or a -b after this option");
              return;
              }
            if (!strcmp(inpstr,"-b")) op_mode=6;
            inedit_file2(user,inpstr,i,op_mode);
            return;
           }
         } /* end of IF INSERT OPTION */

       for (i=0;i<strlen(option);++i) {
          if (!isdigit((int)option[i])) {
            write_str(user,"Line number given was not a number!");
            return;
            }
         }
       i=0;
       i=atoi(option);
       if (i == 0) {
         write_str(user,"Description lines start at 1. Not 0. Try again.");
         return;
         }
       if (i > PRO_LINES) {
         sprintf(mess,"The line number can't be higher than the max desc. lines allowed, which is currently %d",PRO_LINES);
         write_str(user,mess);
         return;
         }
       remove_first(inpstr);
       if (!strcmp(inpstr,"-c")) op_mode=1;
       else if (!strcmp(inpstr,"-b")) op_mode=2;
       else op_mode=0;
       inedit_file2(user,inpstr,i,op_mode);
       return;
      } /* end of inedit */         
    ustr[user].roomd_enter=1;
    ustr[user].roomd_end=ustr[user].roomd_start;
    if (!redo) {
    sprintf(mess,"%s is writing a room description..",ustr[user].say_name);
    writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
    }
    if (!redo) strcpy(ustr[user].mutter,ustr[user].flags);
    user_ignore(user,"all");
    write_str(user,"");
    write_str(user,"** Decorating the room, finish with a '.' on a line by itself **");
    sprintf(mess,"** Max lines you can write is %d",ROOM_DESC_LINES);
    write_str(user,mess);
    write_str(user,"");
    write_str_nr(user,"1: ");
	 telnet_write_eor(user);
    noprompt=1;
    return;
    }
inpstr[80]=0;  c=inpstr;

/* check for dot terminator */
ret_val=0;

if (ustr[user].roomd_enter > ROOM_DESC_LINES) {
   if (*c=='s' && *(c+1)==0) {
     ret_val=write_room(user);
        if (ret_val) {
	write_str(user,"");
	write_str(user,"Room description stored");
	}
        else {
	write_str(user,"");
	write_str(user,"Room description not stored");
	}
        free(ustr[user].roomd_start);  ustr[user].roomd_enter=0;
        ustr[user].roomd_end='\0';
        noprompt=0;
        sprintf(mess,"%s finishes the room description.",ustr[user].say_name);
        writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
        strcpy(ustr[user].flags,ustr[user].mutter);
        ustr[user].mutter[0]=0;
        return;
     }
   else if (*c=='v' && *(c+1)==0) {
write_str(user,"+-----------------------------------------------------------------------------+");
c='\0';
strcpy(filename2,get_temp_file());
fp=fopen(filename2,"w");
for (c=ustr[user].roomd_start;c<ustr[user].roomd_end;++c) { 
    putc(*c,fp);
    }
    fclose(fp);
    cat(filename2,user,0);
    remove(filename2);
c='\0';
write_str(user,"+-----------------------------------------------------------------------------+");
            write_str_nr(user,PROFILE_PROMPT);
		 telnet_write_eor(user);
            noprompt=1;  return;
        }
   else if (*c=='r' && *(c+1)==0) {
        free(ustr[user].roomd_start); ustr[user].roomd_enter=0;
        ustr[user].roomd_end='\0';
        redo=1;
        goto STARTROOMD;
        }             
   else if (*c=='a' && *(c+1)==0) {
        free(ustr[user].roomd_start); ustr[user].roomd_enter=0;
        ustr[user].roomd_end='\0';
	write_str(user,"");
        write_str(user,"Room description not stored");
        noprompt=0;
        sprintf(mess,"%s finishes the room description.",ustr[user].say_name);
        writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
        strcpy(ustr[user].flags,ustr[user].mutter);
        ustr[user].mutter[0]=0;
        return;
        }             
   else {
    write_str_nr(user,PROFILE_PROMPT);
	 telnet_write_eor(user);
    return;
   } 
  }

if (*c=='.' && *(c+1)==0) {
        if (ustr[user].roomd_enter!=1)   {
            ustr[user].roomd_enter= ROOM_DESC_LINES + 1;
            write_str_nr(user,PROFILE_PROMPT);
		 telnet_write_eor(user);
            noprompt=1;  return;
            }
        else {
	write_str(user,"");
	write_str(user,"Room description not stored");
	}
        free(ustr[user].roomd_start);  ustr[user].roomd_enter=0;
        noprompt=0;
        sprintf(mess,"%s finishes the room description.",ustr[user].say_name);
        writeall_str(mess, 1, user, 0, user, NORM, NONE, 0);
        strcpy(ustr[user].flags,ustr[user].mutter);
        ustr[user].mutter[0]=0;
        return;
        }

/* write string to memory */
while(*c) *ustr[user].roomd_end++=*c++;
*ustr[user].roomd_end++='\n';

/* end of lines */
if (ustr[user].roomd_enter==ROOM_DESC_LINES) {
            ustr[user].roomd_enter= ROOM_DESC_LINES + 1;
            write_str_nr(user,PROFILE_PROMPT);
		 telnet_write_eor(user);
            noprompt=1;  return;
        }
sprintf(mess,"%d: ",++ustr[user].roomd_enter);
write_str_nr(user,mess);
telnet_write_eor(user);
}


/* Edit a room description from the command line */
/* op_mode = 0       Straight editing of a line               */
/* op_mode = 1       Clearing of a line                       */
/* op_mode = 2       Blanking of a line                       */
/* op_mode = 3       Inserting a line at end of file          */
/* op_mode = 4       Inserting a blank line at end of file    */
/* op_mode = 5       Inserting a line in middle of file       */
/* op_mode = 6       Inserting a blank line in middle of file */

void inedit_file2(int user, char *inpstr, int line_num, int mode)
{
int a=0;
int lines=0;
int diff=0;
char buffer[ARR_SIZE];
char filename[FILE_NAME_LEN];
char filename2[FILE_NAME_LEN];
FILE *fp;
FILE *fp2;

sprintf(filename,"%s/%s",datadir,astr[ustr[user].area].name);
lines = file_count_lines(filename);
fp=fopen(filename,"r");

/* Put these mode checks in first so we know if we can insert anymore */
/* lines in the users profile.                                        */
if ((mode==3) || (mode==4) || (mode==5) || (mode==6)) {
   if (lines==PRO_LINES) {
     write_str(user,"You cant insert anymore lines to an already full room description.");
     FCLOSE(fp);
     return;
    }
  }

/* Put these modes first since we know they contain an input string */
/* and only need to append to the end of the original file          */
if ((mode==3) || (mode==4)) {
FCLOSE(fp);
if (!(fp=fopen(filename,"a"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open file(a) \"%s\" in inedit_file2! %s\n",filename,get_error());
	return;
        }
   if (mode==3) { fputs(inpstr,fp); }
   else if (mode==4) { }

   fputs("\n",fp);
   if (mode==3)
    write_str(user,"Inserted text to end.");
   else if (mode==4)
    write_str(user,"Inserted blank line to end.");
   FCLOSE(fp);
   return;
  }

if (!strlen(inpstr)) {
  if (line_num > lines) {
    write_str(user,"You dont have anything in that line.");
    FCLOSE(fp);
    return;
    }
   for (a=1;a<PRO_LINES+1;++a) {
      fgets(buffer,1000,fp);
      buffer[strlen(buffer)-1]=0;
      if (a==line_num) {
         if (strlen(buffer) > 1)
          sprintf(mess,"Line ^%d^ is: %s",line_num,buffer);
         else
          sprintf(mess,"Line ^%d^ is blank.",line_num);
         write_str(user,mess);
         FCLOSE(fp);
         return;
        }
      strcpy(buffer,"");
     } /* end of for */
  } /* end of no input string */
else {
strcpy(filename2,get_temp_file());
if (!(fp2=fopen(filename2,"a"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open tempfile(a) for %s to append to in inedit_file2! %s\n",ustr[user].name,get_error());
        FCLOSE(fp); return;
        }
 if (mode==1) {
   if (line_num > lines) {
     write_str(user,"That line doesnt exist to clear.");
     FCLOSE(fp);
     FCLOSE(fp2);
     return;
    }
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) { }
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   sprintf(mess,"Line ^%d^ cleared!",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
  } /* end of clear line mode */
 else if (mode==2) {
   if (line_num > lines) {
     write_str(user,"That line doesnt exist to blank.");
     FCLOSE(fp);
     FCLOSE(fp2);
     return;
    }
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) fputs("\n",fp2);
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   sprintf(mess,"Line ^%d^ blanked!",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
  } /* end of blank line mode */

 else if (mode==5 || mode==6) {
   if (line_num > lines) {
     write_str(user,"That line doesnt exist to insert after.");
     FCLOSE(fp);
     FCLOSE(fp2);
     return;
    }
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) {
        fputs(buffer,fp2);
        if (mode==5) {
         fputs(inpstr,fp2);
         fputs("\n",fp2);
         }
        else if (mode==6) fputs("\n",fp2);
        }
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   if (mode==5)
    sprintf(mess,"Inserted your text after line ^%d^",line_num);
   else if (mode==6)
    sprintf(mess,"Inserted a blank line after line ^%d^",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
  } /* end of insert line in middle mode */

 if (line_num > lines) {
   diff = line_num - lines;

   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   a=0;
   if (diff!=1) {
     for (a=0;a<diff-1;++a) {
      fputs("\n",fp2);
       }
     } /* end of if diff */
   fputs(inpstr,fp2);
   fputs("\n",fp2);
   sprintf(mess,"Added line ^%d^",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
   } /* end of greater than if */
 else {
   for (a=1;a<lines+1;++a) {
      fgets(buffer,1000,fp);
      if (a==line_num) {
        fputs(inpstr,fp2);
        fputs("\n",fp2);
        }
      else fputs(buffer,fp2);
      strcpy(buffer,"");
     } /* end of for */
   sprintf(mess,"Modified line ^%d^",line_num);
   write_str(user,mess);
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   return;
  } /* end of other line edit else */
 } /* end of main else */

}


/** Write room description in buffer to file **/
int write_room(int user)
{
char *c,filename[FILE_NAME_LEN];
FILE *fp;

sprintf(filename,"%s/%s",datadir,astr[ustr[user].area].name);
if (!(fp=fopen(filename,"w"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open file(w) \"%s\" in write_room! %s\n",filename,get_error());
	return 0;
        }
for (c=ustr[user].roomd_start;c<ustr[user].roomd_end;++c) putc(*c,fp);
fclose(fp);
return 1;
}

/** Write vote topic in buffer to file **/
int write_vote(int user)
{
char *c,filename[FILE_NAME_LEN];
FILE *fp;

sprintf(filename,"%s/%s",LIBDIR,"votefile");
if (!(fp=fopen(filename,"w"))) {
        write_str(user,BAD_FILEIO);
        write_log(ERRLOG,YESTIME,"Couldn't open file(w) \"%s\" in write_vote! %s\n",filename,get_error());
	return 0;
        }
for (c=ustr[user].vote_start;c<ustr[user].vote_end;++c) putc(*c,fp);
fclose(fp);
return 1;
}

/** show a newbie how to type a command **/
void show(int user, char *inpstr)
{
  if (!strlen(inpstr)) {
    write_str(user,"Show what?");  return;
    }

if (ustr[user].frog) strcpy(inpstr,FROG_TALK);

sprintf(mess,"Type ---> ^%s^\n",inpstr);
write_str(user,mess);
writeall_str(mess, 1, user, 0, user, NORM, ECHOM, 0);
}

/** clears a socket for use **/
void cline(int user, char *inpstr)
{
int u=0,uu,found=0;

if (!strlen(inpstr)) {
        write_str(user,"Clear which line?\n");
        return;
        }

/* plug security hole */
if (check_fname(inpstr,user)) 
  {
   write_str(user,"Illegal name.");
   return;
  }

u=atoi(inpstr);

for (uu=0;uu<MAX_WWW_CONNECTS;++uu) {
        if (wwwport[uu].sock==u) {
          free_sock(uu,'4');
          sprintf(mess,"Web line %d cleared\n",uu);
          write_str(user,mess);
          found=1;
          break;
          }
   }
   
uu=0;
if (found) return;

for (uu=0;uu<MAX_WHO_CONNECTS;++uu) {
        if (whoport[uu].sock==u) {
          free_sock(uu,'3');
          sprintf(mess,"Who line %d cleared\n",uu);
          write_str(user,mess);
          found=1;
          break;
          }
   }
           
uu=0;
if (found) return;

for (uu=0;uu<MAX_MISC_CONNECTS;++uu) {
        if (miscconn[uu].sock==u) {
          free_sock(uu,'5');
          sprintf(mess,"Rwho line %d cleared\n",uu);
          write_str(user,mess);
          found=1;
          break;
          }
   }
   
uu=0;
if (found) return;

for (uu=0;uu<MAX_USERS;++uu) {
	if (ustr[uu].sock==u && ustr[uu].logging_in) {
        user_quit(uu,1);
        sprintf(mess,"Line %d cleared\n",uu);
        write_str(user,mess);
	found=1; break;
        }
	else if (ustr[uu].sock==u && !ustr[uu].logging_in) {
        sprintf(mess,"Line %d is in use\n",uu);
        write_str(user,mess);
	found=1; break;
	}
   } /* end of for */
if (!found) {
	write_str(user,"Line not found!");
  }

}

/** blinking broadcast **/
void bbcast(int user, char *inpstr)
{
if (!strlen(inpstr)) {
  write_str(user,"Broadcast what?");
  return;
  }
sprintf(mess,"^BL *** [ %s ] ***^",inpstr);
writeall_str(mess, 0, user, 1, user, BEEPS, BCAST, 0);
write_log(SYSTEMLOG,YESTIME,"BBCAST: by %s\n",ustr[user].say_name);
}

/** version command **/
void version(int user)
{
int i=0;
struct stat fileinfo2;
time_t lastmod;

write_str(user,VERSION);

/* See when the program was last updated */
stat(thisprog, &fileinfo2);
lastmod = fileinfo2.st_ctime;
sprintf(mess,"Updated: %s",ctime(&lastmod));
mess[strlen(mess)-1]=0;
write_str(user,mess);

sprintf(mess,"Hostname & OS: %s (%s)",thishost,thisos);
write_str(user,mess);

if ((TELEP_LEVEL==0) && (FOLLOWIS_JOIN==1))
 write_str(user,"Teleportation is NOT restricted.");
else if ((TELEP_LEVEL==0) && (FOLLOWIS_JOIN==0))
 write_str(user,"Teleportation is loosely restricted.");
else if ((TELEP_LEVEL > 0) && (FOLLOWIS_JOIN==0)) {
 sprintf(mess,"Teleportation is reserved for ranks >= %d",TELEP_LEVEL);
 write_str(user,mess);
 }
else if ((TELEP_LEVEL > 0) && (FOLLOWIS_JOIN==1)) {
 sprintf(mess,"Teleportation is reserved for ranks >= %d (except .follow)",TELEP_LEVEL);
 write_str(user,mess);
 }

if (allow_new > 1)
 write_str(user,"Registration is NOT needed for new players.");
else if (allow_new==1)
 write_str(user,"Email verification IS required for new players.");
else
 write_str(user,"New players are not allowed at this time.");

i=DAYS_OFF;
if ((i < 1) || (i > 1))
 sprintf(mess,"Expiration grace period for users is %d days.",i);
else
 sprintf(mess,"Expiration grace period for users is %d day.",i);
write_str(user,mess);

if ((autoexpire==1) || (autoexpire==2)) {
i=TIME_TO_GO;
if (i > 1)
 sprintf(mess,"Expiration warning period for users is %d days.",i);
else if (i==1)
 sprintf(mess,"Expiration warning period for users is %d day.",i);
else
 strcpy(mess,"Expiration warning period for users is DISABLED");
write_str(user,mess);
}
else {
 write_str(user,"Expiration warning period for users is DISABLED");
}

write_str(user,"An administrative hierarchy exists.");
if (resolve_names==1)
 write_str(user,"Resolver is                 configured for cache and gethostbyaddr");
else if (resolve_names==2)
 write_str(user,"Resolver is                 configured for cache and resolver clip-on");
else if (resolve_names==3)
 write_str(user,"Resolver is                 configured for just resolver clip-on");
else if (resolve_names==4)
 write_str(user,"Resolver is                 configured for just gethostbyaddr");
else
 write_str(user,"Resolver is                 disabled.");
write_str(user,"The robot interface is      enabled.");
if (down_time == 1)
 sprintf(mess,"Auto-Shutdown/Reboot is     enabled.  (%d min. left)",down_time);
else if (down_time > 0)
 sprintf(mess,"Auto-Shutdown/Reboot is     enabled.  (%d mins. left)",down_time);
else
 sprintf(mess,"Auto-Shutdown/Reboot is     disabled.");
write_str(user,mess);
sprintf(mess,"Max users                   : %3d       Max atmospheres p/room : %-3d",MAX_USERS,MAX_ATMOS);
write_str(user,mess);
sprintf(mess,"Max areas                   : %3d       Max length of atmoses  : %-3d",MAX_AREAS,ATMOS_LEN);
write_str(user,mess);
sprintf(mess,"Max name length for players : %3d       Max mail forwards a day: %-3d",NAME_LEN,MAX_AUTOFORS);
write_str(user,mess);
sprintf(mess,"Max description length      : %3d       Max mailfile size      : %-6d",DESC_LEN,MAX_MAILSIZE);
write_str(user,mess);
sprintf(mess,"Max macro length            : %3d       Max sent-mailfile size : %-6d",MACRO_LEN,MAX_SMAILSIZE);
write_str(user,mess);
sprintf(mess,"Max profile lines           : %3d",PRO_LINES);
write_str(user,mess);
sprintf(mess,"Max room description lines  : %3d",ROOM_DESC_LINES);
write_str(user,mess);
sprintf(mess,"Max entermessage length     : %3d",MAX_ENTERM-2);
write_str(user,mess);
sprintf(mess,"Max exitmessage length      : %3d",MAX_EXITM-2);
write_str(user,mess);
sprintf(mess,"Max success and fail lengths: %3d",MAX_ENTERM-2);
write_str(user,mess);
sprintf(mess,"Max topic length            : %3d",TOPIC_LEN);
write_str(user,mess);
}


/** superusers changing user_name **/
void suname(int user, char *inpstr)
{
int f,u;
char other_user[ARR_SIZE],newname[ARR_SIZE],lowername[NAME_LEN+1];
char filename[80];
char filename2[80];


if (!strlen(inpstr)) {
   write_str(user,"Whose name do you want to change?");
   return;
   }

sscanf(inpstr,"%s ",other_user);

/* plug security hole */
if (check_fname(other_user,user)) 
  {
   write_str(user,"Illegal name.");
   return;
  }

strtolower(other_user);
CHECK_NAME(other_user);

if (!read_user(other_user))
  {
   write_str(user,NO_USER_STR);
   return;
  }

 if ((t_ustr.super >= ustr[user].tempsuper) && strcmp(ustr[user].name,ROOT_ID))
  {
    strcpy(t_mess,"You cannot rename a user of same or higher rank.");
    write_str(user,t_mess);
    return;
  }
  
remove_first(inpstr);  
   
sscanf(inpstr,"%s",newname);

 if (newname[0]<32 || strlen(newname)< 3) 
    {
     write_str(user,"Invalid name given [must be at least 3 letters].");  
     return;
    }

 if (strstr(newname,"^")) {
    write_str(user,"Name cannot have color or hilites in it.");
    return;
    }

  if (strlen(newname)>NAME_LEN-1) 
    {
     write_str(user,"Name too long");  
     return;
    }

	/* see if only letters in login */
     for (f=0; f<strlen(newname); ++f) 
       {
         if (!isalpha((int)newname[f]) || newname[f]<'A' || newname[f] >'z') 
           {
	     write_str(user,"Name can only contain letters.");
	     return;
	   }
       }
        

  /*----------------------------------------------------------------*/
  /* copy capitalized name to a temp array and convert to lowercase */
  /*----------------------------------------------------------------*/
  
  strcpy(lowername,newname);
  strtolower(lowername);
 
 if (!strcmp(other_user, lowername))
    {
        write_str(user,"\nNew name cannot be the login name. \nName not changed."); 
        return;  
    }

if (check_for_user(lowername))
    {
      write_str(user,"Sorry, that name is already used.");
      return;
    }
  
  sprintf(mess,"changed %s\'s name to %s",other_user,newname);
  btell(user,mess); 
  strcpy(t_ustr.name,lowername);   
  strcpy(t_ustr.login_name,lowername);   
  strcpy(t_ustr.say_name,newname);   
  write_user(lowername);
  if ((u=get_user_num_exact(other_user,user)) != -1) 
    {
     strcpy(ustr[u].name,lowername);
     strcpy(ustr[u].login_name,lowername);
     sprintf(mess,"^*^ ^HY%s^ has had their name changed to ^HY%s^ ^*^",strip_color(ustr[u].say_name),newname);
     writeall_str(mess, 0, user, 1, user, NORM, BCAST, 0);
     strcpy(ustr[u].say_name,newname);
    }

/* change exempt file */
/* first arguement is to check against names in file for user */
/* second is the new name we're changing to */
change_exem_data(other_user,newname);

   /* move user's INBOX mail file to new name */
  sprintf(filename,"%s/%s",MAILDIR,other_user);
  sprintf(filename2,"%s/%s",MAILDIR,lowername);
  rename(filename,filename2);

   /* move user's SENT mail file to new name */
  sprintf(filename,"%s/%s.sent",MAILDIR,other_user);
  sprintf(filename2,"%s/%s.sent",MAILDIR,lowername);
  rename(filename,filename2);

   /* move user's EMAIL file to new name */
  sprintf(filename,"%s/%s.email",MAILDIR,other_user);
  sprintf(filename2,"%s/%s.email",MAILDIR,lowername);
  rename(filename,filename2);

   /* move user's PROFILE file to new name */
  sprintf(filename,"%s/%s",PRO_DIR,other_user);
  sprintf(filename2,"%s/%s",PRO_DIR,lowername);
  rename(filename,filename2);

   /* move user's WARNING file to new name */
  sprintf(filename,"%s/%s",WLOGDIR,other_user);
  sprintf(filename2,"%s/%s",WLOGDIR,lowername);
  rename(filename,filename2);

  nuke(user,other_user,0);
  sprintf(mess,"%s Had the name ^%s^, but is renamed now to ^%s^ by ^HR%s^"
              ,lowername,other_user,newname,ustr[user].say_name);
  warning(user,mess,0);
  newname[0]=0;
  lowername[0]=0;
}

/** superusers changing user's passwords **/
void supass(int user, char *inpstr)
{
int u;
char other_user[ARR_SIZE],newpass[ARR_SIZE];


if (!strlen(inpstr)) {
   write_str(user,"Whose password do you want to change?");
   return;
   }

sscanf(inpstr,"%s ",other_user);

/* plug security hole */
if (check_fname(other_user,user)) 
  {
   write_str(user,"Illegal name.");
   return;
  }

strtolower(other_user);
CHECK_NAME(other_user);

if (!read_user(other_user))
  {
   write_str(user,NO_USER_STR);
   return;
  }

 if ((t_ustr.super >= ustr[user].tempsuper) && strcmp(ustr[user].name,ROOT_ID))
  {
    strcpy(t_mess,"You cannot repassword a user of same or higher rank.");
    write_str(user,t_mess);
    return;
  }
  
remove_first(inpstr);  
   
sscanf(inpstr,"%s",newpass);

 if (newpass[0]<32 || strlen(newpass)< 3) 
    {
     write_str(user,SYS_PASSWD_INVA);  
     return;
    }

 if (strstr(newpass,"^")) {
    write_str(user,"Password cannot have color or hilites in it.");
    return;
    }
        
  if (strlen(newpass)>NAME_LEN-1) 
    {
     write_str(user,SYS_PASSWD_LONG);  
     return;
    }

  /*-------------------------------------------------------------*/
  /* convert password to lowercase and encrypt the password      */
  /*-------------------------------------------------------------*/
  
  strtolower(newpass);  
 
 if (!strcmp(other_user, newpass))
    {
        write_str(user,"\nPassword cannot be the login name. \nPassword not changed."); 
        return;  
    }
  
  sprintf(mess,"Password for %s changed to %s",t_ustr.say_name,newpass);
  write_str(user,mess); 
  
  st_crypt(newpass);                                   
  strcpy(t_ustr.password,newpass);   
  strcpy(t_ustr.login_pass,newpass);   
  write_user(other_user);
  if ((u=get_user_num_exact(other_user,user)) != -1) 
    {
     strcpy(ustr[u].password,newpass);
     strcpy(ustr[u].login_pass,newpass);
    }
  newpass[0]=0; 
} 


/** list abbreviations **/
void abbrev(int user, char *inpstr)
{
int i=0;
int c=0;
int num=0;
int found=0;
char abbrcom[ARR_SIZE];

if (!strlen(inpstr)) {
 write_str(user,"Command           Yours  Default");
 write_str(user,"-------------     -----  -------");

  for (i=0;i<NUM_ABBRS;++i) {

     for (c=0; sys[c].su_com != -1; ++c) {
      if (!strcmp(sys[c].command,ustr[user].custAbbrs[i].com)) {
     sprintf(mess,"%-12s <-->   %s      %s", ustr[user].custAbbrs[i].com,
	ustr[user].custAbbrs[i].abbr,sys[c].cabbr);
     write_str(user,mess);
     break;
     }
    } /* end of c for */

   } /* end of i for */

  write_str(user,"Ok.");
  return;
 }

/* User wants the defaults back */
if (!strcmp(inpstr,"-d")) {
    write_str(user,"Resetting abbreviations to defaults..");
    initabbrs(user);
    write_str(user,"Ok.");
    return;
    }

sscanf(inpstr,"%s ",abbrcom);
strtolower(abbrcom);
i=0;

/* Make sure command name is one that is available for abbreviation */
 for (i=0;i<NUM_ABBRS;++i) {
  if (!strcmp(abbrcom,ustr[user].custAbbrs[i].com)) {
     found=1;
     num=i;
     break;
     }
  }

 if (!found) {
   write_str(user,"That command is not available for abbreviation.");
   return;
   }

 remove_first(inpstr);

 if (!strlen(inpstr)) {
    sprintf(mess,"Your abbreviation for %s is %s",ustr[user].custAbbrs[num].com,ustr[user].custAbbrs[num].abbr);
    write_str(user,mess);
    return;
    }

 if (strlen(inpstr) > 1) {
   write_str(user,"Abbreviation too long.");
   return;
   }

/* Check for letters, numbers, and a period */
 if (inpstr[0] == '.' || isalnum((int)inpstr[0])) {
   write_str(user,"You can't use that key for a abbreviation.");
   return;
   }

i=0;
found=0;

/* Check if abbreviation is being used by another command already */
 for (i=0;i<NUM_ABBRS;++i) {
       if (!strcmp(ustr[user].custAbbrs[i].abbr,inpstr)) {
        found=1;
        break;
       }
     }

 if (found) {
    write_str(user,"That abbreviation is already being used by another command.");
    return;
    }
       
 if (inpstr[0]=='\\')
     strcpy(ustr[user].custAbbrs[num].abbr,"\\");
 else if (inpstr[0]=='\'')
     strcpy(ustr[user].custAbbrs[num].abbr,"\'");
 else if (inpstr[0]=='\"')
     strcpy(ustr[user].custAbbrs[num].abbr,"\"");
 else if (inpstr[0]=='\?')
     strcpy(ustr[user].custAbbrs[num].abbr,"\?");
 else
     strcpy(ustr[user].custAbbrs[num].abbr,inpstr);
 
/*
 strcpy(ustr[user].custAbbrs[num].abbr,inpstr);
*/

 copy_from_user(user);
 write_user(ustr[user].name);
 write_str(user,"Abbreviation changed.");
}


/** short who with new mud form **/
void newwho(int user)
{
int u,v,idl,invis=0;
char un[SAYNAME_LEN+10];
char amess[5000];
char bmess[5000];
char cmess[5000];
char dmess[5000];
char emess[500];
char fmess[100];

strcpy(amess,"");
strcpy(bmess,"");
strcpy(cmess,"");
strcpy(dmess,"");
strcpy(emess,"");
strcpy(fmess,"");

for (v=0;v<NUM_AREAS;++v) 
     {
       for (u=0;u<MAX_USERS;++u) {
	if ((ustr[u].area!= -1) && (ustr[u].area == v) && (!ustr[u].logging_in))
	        {
	   	  if (!ustr[u].vis && ustr[user].tempsuper < MIN_HIDE_LEVEL)
	             { 
	              invis++;  
	              continue; 
	              }
			 
		 idl=(int)((time(0)-ustr[u].last_input)/60);
		
		 strcpy(un,ustr[u].say_name);
                 strcat(un," ");

                 if (idl < 3) {  
                    strcat(amess,un);
                    } 
                 if (idl >= 3 && idl < 60) {
                    strcat(bmess,un);
                    }
                 if (idl >= 60 && idl < 180) {
                    strcat(cmess,un);
                    }
                 if (idl >= 180) {
                    strcat(dmess,un);
                    }
                 }
        }
     }
 if (strlen(amess) >= 3) {
    amess[strlen(amess)]=0;
    sprintf(mess,"  Active: %s",amess);
    write_str(user,mess);
    }
 if (strlen(bmess) >= 3) {
    bmess[strlen(bmess)]=0;
    sprintf(mess,"   Awake: %s",bmess);
    write_str(user,mess);
    }
 if (strlen(cmess) >= 3) {
    cmess[strlen(cmess)]=0;
    sprintf(mess,"    Idle: %s",cmess);
    write_str(user,mess);
    }
 if (strlen(dmess) >= 3) {
    dmess[strlen(dmess)]=0;
    sprintf(mess,"Comatose: %s",dmess);
    write_str(user,mess);
    }

sprintf(emess,SHORT_WHO,num_of_users,num_of_users == 1 ? "" : "s",num_of_users == 1 ? "is" : "are");

if (invis) {
   sprintf(fmess," (%d invis)",invis);
   strcat(emess,fmess);
   } 
write_str(user,emess);

}


/** check last login for specified user **/
void last_u(int user, char *inpstr)
{
int on_now=0;
int u;
char other_user[ARR_SIZE],ldate[20];
time_t tm_then;

if (!strlen(inpstr)) {
   write_str(user,"Who do you want to see the lastlog of?");
   return;
   } 

sscanf(inpstr,"%s",other_user);

strtolower(other_user);
CHECK_NAME(other_user);

   if ((u = get_user_num(other_user,user)) != -1) {
      if (!strcmp(ustr[u].name,other_user))
       on_now = 1;
      }

if (!on_now) {
if (!read_user(other_user))
   {
    write_str(user,NO_USER_STR);
    return;
   }
midcpy(t_ustr.last_date,ldate,0,15);
write_str(user,"");
sprintf(mess,"^LR-->^    %s was last here on %s",t_ustr.say_name,ldate);
write_str(user,mess);
tm_then=((time_t) t_ustr.rawtime);
sprintf(mess,"^LR-->^    That was %s ago.",converttime((long)((time(0)-tm_then)/60)));
write_str(user,mess);
write_str(user,"");
}
else { 
  write_str(user,"");
  if (!ustr[u].vis) {
	if (ustr[user].tempsuper >= MIN_HIDE_LEVEL)
	 sprintf(mess,"^LR-->^    %s is online right now!! (*)   ^LR<--^",ustr[u].say_name);
	else {
	 /* target user is invisible and doing user does not have the */
	 /* power to see them */
	 midcpy(ustr[u].last_date,ldate,0,15);
	 sprintf(mess,"^LR-->^    %s was last here on %s",ustr[u].say_name,ldate);
	 write_str(user,mess);
	 tm_then=((time_t) ustr[u].rawtime);
	 sprintf(mess,"^LR-->^    That was %s ago.",converttime((long)((time(0)-tm_then)/60)));
	}
  } /* !vis */
  else {
  sprintf(mess,"^LR-->^    %s is online right now!!    ^LR<--^",ustr[u].say_name);
  } /* vis */
  write_str(user,mess);
  write_str(user,"");
 } /* online */
}

/*** search for specific talker in the talker list, add a talker ***/
/*** modify a talker, or delete a talker                         ***/
void talker(int user, char *inpstr)
{
int occured=0;
int i=0;
int num=0;
int num2=0;
int alpha=0;
int lasthost=0;
char filename[FILE_NAME_LEN],filename2[FILE_NAME_LEN];
char line[ARR_SIZE],line2[ARR_SIZE];
FILE *fp;
FILE *fp2;

if (!ustr[user].t_ent) {
 ustr[user].t_num        = 0;
 ustr[user].t_name[0]    = 0;
 ustr[user].t_host[0]    = 0;
 ustr[user].t_ip[0]      = 0;
 ustr[user].t_port[0]    = 0;

 if (!strlen(inpstr)) 
   {
	sprintf(t_mess,"%s",TALKERLIST);
	strncpy(filename,t_mess,FILE_NAME_LEN);
        if (!check_for_file(filename)) {
           write_str(user,NO_TLIST);
           return;
          }
        write_str(user,"    Name                    Hostname                       Number Address  Port");
        write_str(user,"    ----------------------- ------------------------------ --------------- ----");
        cat(filename,user,1);
   }
 else {
	sprintf(t_mess,"%s",TALKERLIST);
	strncpy(filename,t_mess,FILE_NAME_LEN);

 if (!strcmp(inpstr,"-a")) {
   START:
    ustr[user].t_ent=1;
    write_str(user,"Enter a \"q\" by itself on any line to abort");
    write_str(user,"");
    write_str_nr(user,"Enter the name of the talker: ");
	 telnet_write_eor(user);
    noprompt=1; return;
   } /* end of -a if */
 else if (!strncmp(inpstr,"-d",2)) {
   if (ustr[user].tempsuper < WIZ_LEVEL) {
     write_str(user,NOT_WORTHY);
     return;
     }
    remove_first(inpstr);
   if (!strlen(inpstr) || (strlen(inpstr)>3)) {
     write_str(user,"You must enter the number of the talker you wish to delete.");
     return;
    }
   num=atoi(inpstr);
   num2=file_count_lines(filename);
   if ((num==0) || (num>num2)) {
     write_str(user,"That is not a valid number.");
     return;
    }
   if (!(fp=fopen(filename,"r"))) { 
     write_str(user,"Can't open talker list! May not exist");
     return;
    }
   strcpy(filename2,get_temp_file());
   if (!(fp2=fopen(filename2,"a"))) { 
        write_str(user,BAD_FILEIO);
	write_log(ERRLOG,YESTIME,"Couldn't open tempfile(a) in talker! %s\n",get_error());
     return;
    }
   strcpy(line,"");
   line[0]=0;
   while (fgets(line,80,fp)!=NULL) {
    line[strlen(line)-1]=0;
    i++;
    if (i==num) { strcpy(line,""); line[0]=0; continue; }
    else {
     fputs(line,fp2); fputs("\n",fp2);
     strcpy(line,""); line[0]=0;
     }
   }
   i=0;
   write_str(user,"Talker entry deleted.");
   FCLOSE(fp);
   FCLOSE(fp2);
   remove(filename);
   rename(filename2,filename);
   ustr[user].t_num        = 0;
   ustr[user].t_name[0]    = 0;
   ustr[user].t_host[0]    = 0;
   ustr[user].t_ip[0]      = 0;
   ustr[user].t_port[0]    = 0;
   return;
  } /* end of -d if */
 else if (isdigit((int)inpstr[0]) && (strlen(inpstr)<4)) {
   if (ustr[user].tempsuper < WIZ_LEVEL) {
     write_str(user,NOT_WORTHY);
     return;
     }
   num=atoi(inpstr);
   num2=file_count_lines(filename);
   if ((num==0) || (num>num2)) {
     write_str(user,"That is not a valid number.");
     return;
    }
   write_str(user,"Modifying talker info..");
   ustr[user].t_num=num;
   goto START;
   } /* end of modify if */
 else {
	strtolower(inpstr);
        /* look through list */
	if (!(fp=fopen(filename,"r"))) { 
           write_str(user,"Can't open talker list! May not exist");
           return;
           }
        strcpy(line,""); line[0]=0;
	while(fgets(line,80,fp)!=NULL) {
                num++;
	        line[strlen(line)-1]=0;
                strcpy(line2,line);
                strtolower(line2);
		if (instr2(0,line2,inpstr,0)== -1) goto NEXT;
                if (!occured) {
        write_str(user,"    Name                    Hostname                       Number Address  Port");
        write_str(user,"    ----------------------- ------------------------------ --------------- ----");
                 }
                 if (ustr[user].tempsuper >= LINENUM_LEVEL) {
		  sprintf(mess,"%-3d ",num);
		  write_str_nr(user,mess);
                  }
		  write_str(user,line);	
		  ++occured;
		NEXT:
                strcpy(line,""); line[0]=0;
		continue;
		}
	FCLOSE(fp);

   if (!occured) write_str(user,"No occurences found");
   else {
        write_str(user," ");
	sprintf(mess,"%d occurence%s found",occured,occured == 1 ? "" : "s");
	write_str(user,mess);
	}
   num=0;
   } /* end of search else */
  } /* end of strlen inpstr else */
 } /* end of if t_ent */
else {
    if ((strlen(inpstr) < 5) && ustr[user].t_ent>0 && ustr[user].t_ent<4) {
	if (is_quit(user,inpstr)) return;
      if (ustr[user].t_ent==1) {
       write_str(user,"Name too short.");
       write_str_nr(user,"Enter the name of the talker: ");
	telnet_write_eor(user);
       noprompt=1; return;
       }
      else if (ustr[user].t_ent==2) {
       write_str(user,"Hostname too short.");
       write_str(user,"Use \"unknown\" if you dont know the name address");
       write_str_nr(user,"Enter the hostname address (w/o port): ");
	telnet_write_eor(user);
       noprompt=1; return;
       }
      else if (ustr[user].t_ent==3) {
        write_str(user,"Address too short.");
        write_str(user,"Use \"unknown\" if you dont know the numeric address");
        write_str_nr(user,"Enter the talker numeric address (w/o port): ");
	telnet_write_eor(user);
        noprompt=1; return;
       }
     } /* end of if strlen inpstr */
   if (ustr[user].t_ent==1) {
      inpstr[23]=0;
      strcpy(ustr[user].t_name,inpstr);
      if (isalpha((int)ustr[user].t_name[0])) ustr[user].t_name[0]=toupper((int)ustr[user].t_name[0]);
      write_str_nr(user,"Enter hostname address (w/o port): ");
	telnet_write_eor(user);
      ustr[user].t_ent=2;
      noprompt=1; return;
     }
   else if (ustr[user].t_ent==2) {
      inpstr[30]=0;
      strcpy(ustr[user].t_host,inpstr);
      write_str_nr(user,"Enter the talker numeric address (w/o port): ");
	telnet_write_eor(user);
      ustr[user].t_ent=3;
      noprompt=1; return;
     }
   else if (ustr[user].t_ent==3) {
      inpstr[15]=0;
      strcpy(ustr[user].t_ip,inpstr);
      write_str_nr(user,"Enter the talker port number: ");
	telnet_write_eor(user);
      ustr[user].t_ent=4;
      noprompt=1; return;
     }
   else if (ustr[user].t_ent==4) {
      inpstr[5]=0;
      strcpy(ustr[user].t_port,inpstr);
      sprintf(t_mess,"%s",TALKERLIST);
      strncpy(filename,t_mess,FILE_NAME_LEN);
      if (!(fp=fopen(filename,"r"))) {
        fp=fopen(filename,"a");
        sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
        ustr[user].t_ent=0;
        write_str(user,"Talker added.");
        ustr[user].t_num        = 0;
        ustr[user].t_name[0]    = 0;
        ustr[user].t_host[0]    = 0;
        ustr[user].t_ip[0]      = 0;
        ustr[user].t_port[0]    = 0;
        fputs(mess,fp);
        FCLOSE(fp);
        return;
       }
      else {
       if (isalpha((int)ustr[user].t_name[0]) ||
           isdigit((int)ustr[user].t_name[0])) alpha=1;
       else alpha=2;

       strcpy(filename2,get_temp_file());
   if (!(fp2=fopen(filename2,"a"))) { 
        write_str(user,BAD_FILEIO);
	write_log(ERRLOG,YESTIME,"Couldn't open tempfile(a) in talker! %s\n",get_error());
        alpha=0;
        ustr[user].t_ent        = 0;
        ustr[user].t_num        = 0;
        ustr[user].t_name[0]    = 0;
        ustr[user].t_host[0]    = 0;
        ustr[user].t_ip[0]      = 0;
        ustr[user].t_port[0]    = 0;
     FCLOSE(fp);
     return;
    }
   if (ustr[user].t_num) {
    strcpy(line,""); line[0]=0;
    while (fgets(line,80,fp)!=NULL) {
     line[strlen(line)-1]=0;
     i++;
     if (i==ustr[user].t_num) {
       if (alpha!=3) lasthost=1;
       continue;
      }
     else {
      if (alpha==3) {
         fputs(line,fp2); fputs("\n",fp2);
         lasthost=0;
         }
      else if ((alpha==2) || (alpha==1)) {
        if (line[0]<ustr[user].t_name[0]) {
         fputs(line,fp2); fputs("\n",fp2);
         lasthost=1;
         }
        else if (line[0]==ustr[user].t_name[0]) {
         if (line[1]<ustr[user].t_name[1]) {
          fputs(line,fp2); fputs("\n",fp2);
          lasthost=1;
          }
         else if (line[1]==ustr[user].t_name[1]) {
          fputs(line,fp2); fputs("\n",fp2);
          sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
          fputs(mess,fp2);
          alpha=3;
          lasthost=0;
          }
         else if (line[1]>ustr[user].t_name[1]) {
          sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
          fputs(mess,fp2);
          fputs(line,fp2); fputs("\n",fp2);
          alpha=3;
          lasthost=0;
          }
         } /* end of else if line equals */
        else if (line[0]>ustr[user].t_name[0]) {
         sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
         fputs(mess,fp2);
         fputs(line,fp2); fputs("\n",fp2);
         lasthost=0;
         alpha=3;
         }
       } /* end of else if alpha */
      } /* end of else */
     strcpy(line,""); line[0]=0;
     } /* end of while */
     if (lasthost) {
          sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
          fputs(mess,fp2);
          lasthost=0;
       }
     i=0;
     alpha=0;
     ustr[user].t_ent=0;
     ustr[user].t_num        = 0;
     ustr[user].t_name[0]    = 0;
     ustr[user].t_host[0]    = 0;
     ustr[user].t_ip[0]      = 0;
     ustr[user].t_port[0]    = 0;
     write_str(user,"Talker entry modified.");
     FCLOSE(fp);
     FCLOSE(fp2);
     remove(filename);
     rename(filename2,filename);
     return;
    } /* end of if t_num */
    strcpy(line,""); line[0]=0;
   while (fgets(line,80,fp)!=NULL) {
    line[strlen(line)-1]=0;
      if (alpha==3) {
         fputs(line,fp2); fputs("\n",fp2);
         lasthost=0;
         }
      else if ((alpha==2) || (alpha==1)) {
        if (line[0]<ustr[user].t_name[0]) {
         fputs(line,fp2); fputs("\n",fp2);
         lasthost=1;
         }
        else if (line[0]==ustr[user].t_name[0]) {
         if (line[1]<ustr[user].t_name[1]) {
          fputs(line,fp2); fputs("\n",fp2);
          lasthost=1;
          }
         else if (line[1]==ustr[user].t_name[1]) {
          fputs(line,fp2); fputs("\n",fp2);
          sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
          fputs(mess,fp2);
          alpha=3;
          lasthost=0;
          }
         else if (line[1]>ustr[user].t_name[1]) {
          sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
          fputs(mess,fp2);
          fputs(line,fp2); fputs("\n",fp2);
          alpha=3;
          lasthost=0;
          }
         } /* end of else if line equals */
        else if (line[0]>ustr[user].t_name[0]) {
         sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
         fputs(mess,fp2);
         fputs(line,fp2); fputs("\n",fp2);
         lasthost=0;
         alpha=3;
         }
       } /* end of else if alpha */
     strcpy(line,""); line[0]=0;
    } /* end of while */
    if (lasthost) {
          sprintf(mess,"%-23s %-30s %-15s %s\n",ustr[user].t_name,
                ustr[user].t_host,ustr[user].t_ip,ustr[user].t_port);      
          fputs(mess,fp2);
          lasthost=0;
      }
    ustr[user].t_ent=0;
    ustr[user].t_num        = 0;
    ustr[user].t_name[0]    = 0;
    ustr[user].t_host[0]    = 0;
    ustr[user].t_ip[0]      = 0;
    ustr[user].t_port[0]    = 0;
    alpha=0;
    write_str(user,"Talker added.");
    FCLOSE(fp);
    FCLOSE(fp2);
    remove(filename);
    rename(filename2,filename);
  } /* end of filename else */
 } /* end of else if */
 } /* end of t_ent else */
strcpy(line,""); line[0]=0; i=0;
}

/** bbbbbbbuuubbles for eve **/
void bubble(int user)
{
sprintf(mess,"OoOoo Ooo oOOo oOo oOooOOo OooOOooo oOoOooO ooo Ooo");
write_str(

Showing the first 100 KB of 526.0 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571