#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#include "extern.h"

logoff()
       { int i,j; 
		 unsigned long  cntt;
         char cntz[4],exp_ch[2];
         
         remove(temp_fil);
	 	 remove(seek_hdr);
         *(ssent) = NULL;
 
         /* CLOSEING MESSAGE */
                  

         nwdate();
         sprintf(fbuff,"\nThis is %s-BBS  %s %s  Thank you\n",rbbscall,nowdate,nowtime);
         strcpy(ssent,fbuff);
         rsout();
         
         fpw = fopen(LOG_FIL,"r+");

		 if ( fpw == NULL ) { printf("logoff err 1\n"); exit(1); }
         fseek(fpw,logptr,0);
         fputs(nowtime,fpw);
         fclose(fpw);

        /* LOG Æ ¼­³Ø®³ ¼Þº¸ ¶·ºÐ */
         
	
         /* USER FILE º³¼Ý */
  if ( strcmp(hiscall,guestid) )
	{
		 strcpy(exp_ch," ");
		 if ( exp_flg )  *(exp_ch) = '*';
         if ( userptr == -1 )     /* ÊÂ ±¸¾½ ·®¸ Ê Â²¶ */
            {  fpw = fopen(USER_FIL,"a");
         
			 if ( fpw == NULL ) { printf("logoff err 2\n"); exit(1); }
               fprintf(fpw,"%s %s %s %s     1 %s     \n",hiscall,nowdate,statdate,stattime,exp_ch);
               fclose(fpw);  }
         
          else
         
            {  fpw = fopen(USER_FIL,"r+");
               
			 if ( fpw == NULL ) { printf("logoff err 3\n"); exit(1); }
               fseek(fpw,userptr,0);     /* ±¸¾½ ¶²½³ Ê±¸ */         
               fgets(fbuff,255,fpw);    
               
               substr(fbuff,33,5,cntz);
               cntt = atol(cntz);
               if ( cntt != 99999 ) cntt++;
               if ( strcmp(hiscall,sysop) == 0 ) cntt = 0;
        
               userptr += 18;
               fseek(fpw,userptr,0);    /* LOGIN ¼Þº¸¤ ±¸¾½ ¶²½³ º³¼Ý */
               fprintf(fpw,"%s %s %5ld %s",statdate,stattime,cntt,exp_ch);
               fclose(fpw);
            }  
	}

		if ( resv )  { mlchk(1);
					   rsans(wait_time);
					 }
		rsans(5);
        chgjyo("WAIT");
        
        return(0);
        }
