|
|
1.1 ! root 1: /* logout.cpp */ ! 2: ! 3: /* Synchronet user logout routines */ ! 4: ! 5: /* $Id: logout.cpp,v 1.7 2000/12/11 23:21:12 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include "sbbs.h" ! 39: #include "cmdshell.h" ! 40: ! 41: /****************************************************************************/ ! 42: /* Function that is called after a user hangs up or logs off */ ! 43: /****************************************************************************/ ! 44: void sbbs_t::logout() ! 45: { ! 46: char str[256]; ! 47: char tmp[512]; ! 48: int i,j; ! 49: ushort ttoday; ! 50: node_t node; ! 51: struct tm * tm, tm_now; ! 52: FILE *stream; ! 53: ! 54: now=time(NULL); ! 55: tm=gmtime(&now); ! 56: if(tm==NULL) ! 57: return; ! 58: tm_now=*tm; ! 59: ! 60: if(!useron.number) { /* Not logged in, so do nothing */ ! 61: #if 1 ! 62: if(!online) { ! 63: sprintf(str,"%02d:%02d%c T:%3u sec\r\n" ! 64: ,tm->tm_hour>12 ? tm->tm_hour-12 ! 65: : tm->tm_hour==0 ? 12 : tm->tm_hour, tm->tm_min ! 66: , tm->tm_hour>=12 ? 'p' : 'a' ! 67: ,(uint)(now-answertime)); ! 68: logline("@-",str); } ! 69: #endif ! 70: return; ! 71: } ! 72: strcpy(lastuseron,useron.alias); /* for use with WFC status display */ ! 73: ! 74: if(useron.rest&FLAG('G')) { /* Reset guest's msg scan cfg */ ! 75: putuserrec(&cfg,useron.number,U_NAME,LEN_NAME,nulstr); ! 76: #if 0 // no longer necessary ! 77: for(i=0;i<cfg.total_subs;i++) { ! 78: if(cfg.sub[i]->misc&SUB_NSDEF) ! 79: sub_cfg[i]|=SUB_CFG_NSCAN; ! 80: else ! 81: sub_cfg[i]&=~SUB_CFG_NSCAN; ! 82: if(cfg.sub[i]->misc&SUB_SSDEF) ! 83: sub_cfg[i]|=SUB_CFG_SSCAN; ! 84: else ! 85: sub_cfg[i]&=~SUB_CFG_SSCAN; } ! 86: #endif ! 87: batdn_total=0; } ! 88: ! 89: if(batdn_total) { ! 90: sprintf(str,"%sfile/%04u.dwn",cfg.data_dir,useron.number); ! 91: if((stream=fnopen(NULL,str,O_WRONLY|O_TRUNC|O_CREAT))!=NULL) { ! 92: for(i=0;i<(int)batdn_total;i++) ! 93: fprintf(stream,"%s\r\n",batdn_name[i]); ! 94: fclose(stream); } } ! 95: ! 96: if(sys_status&SS_USERON && thisnode.status!=NODE_QUIET && !(useron.rest&FLAG('Q'))) ! 97: for(i=1;i<=cfg.sys_nodes;i++) ! 98: if(i!=cfg.node_num) { ! 99: getnodedat(i,&node,0); ! 100: if((node.status==NODE_INUSE || node.status==NODE_QUIET) ! 101: && !(node.misc&NODE_AOFF) && node.useron!=useron.number) { ! 102: sprintf(str,text[NodeLoggedOff],cfg.node_num ! 103: ,thisnode.misc&NODE_ANON ! 104: ? text[UNKNOWN_USER] : useron.alias); ! 105: putnmsg(i,str); } } ! 106: ! 107: if(!online) { /* NOT re-login */ ! 108: ! 109: getnodedat(cfg.node_num,&thisnode,1); ! 110: thisnode.status=NODE_WFC; ! 111: thisnode.misc&=~(NODE_INTR|NODE_MSGW|NODE_NMSG ! 112: |NODE_UDAT|NODE_POFF|NODE_AOFF|NODE_EXT); ! 113: putnodedat(cfg.node_num,&thisnode); ! 114: #if 0 /* beep? */ ! 115: if(sys_status&SS_SYSALERT) { ! 116: mswait(500); ! 117: offhook(); ! 118: CLS; ! 119: lputs("\r\n\r\nAlerting Sysop..."); ! 120: while(!lkbrd(1)) { ! 121: sbbs_beep(1000,200); ! 122: nosound(); ! 123: mswait(200); } ! 124: lkbrd(0); } ! 125: #endif ! 126: sys_status&=~SS_SYSALERT; ! 127: if(cfg.sys_logout[0]) /* execute system logoff event */ ! 128: external(cmdstr(cfg.sys_logout,nulstr,nulstr,NULL),EX_OUTL); /* EX_CC */ ! 129: } ! 130: ! 131: if(cfg.logout_mod[0]) ! 132: exec_bin(cfg.logout_mod,&main_csi); ! 133: backout(); ! 134: sprintf(str,"%smsgs/%4.4u.msg",cfg.data_dir,useron.number); ! 135: if(!flength(str)) /* remove any 0 byte message files */ ! 136: remove(str); ! 137: ! 138: delfiles(cfg.temp_dir,ALLFILES); ! 139: putmsgptrs(); ! 140: if(!REALSYSOP) ! 141: logofflist(); ! 142: useron.laston=now; ! 143: ! 144: ttoday=useron.ttoday-useron.textra; /* billable time used prev calls */ ! 145: if(ttoday>=cfg.level_timeperday[useron.level]) ! 146: i=0; ! 147: else ! 148: i=cfg.level_timeperday[useron.level]-ttoday; ! 149: if(i>cfg.level_timepercall[useron.level]) /* i=amount of time without min */ ! 150: i=cfg.level_timepercall[useron.level]; ! 151: j=(now-starttime)/60; /* j=billable time online in min */ ! 152: if(i<0) i=0; ! 153: if(j<0) j=0; ! 154: ! 155: if(useron.min && j>i) { ! 156: j-=i; /* j=time to deduct from min */ ! 157: sprintf(str,"Minute Adjustment: %d",-j); ! 158: logline(">>",str); ! 159: if(useron.min>(ulong)j) ! 160: useron.min-=j; ! 161: else ! 162: useron.min=0L; ! 163: putuserrec(&cfg,useron.number,U_MIN,10,ultoa(useron.min,str,10)); } ! 164: ! 165: useron.tlast=(now-logontime)/60; ! 166: useron.timeon+=useron.tlast; ! 167: useron.ttoday+=useron.tlast; ! 168: ! 169: if(timeleft>0 && starttime-logontime>0) /* extra time */ ! 170: useron.textra+=(starttime-logontime)/60; ! 171: ! 172: tm=gmtime(&logontime); ! 173: if(tm==NULL) ! 174: return; ! 175: if(tm->tm_mday!=tm_now.tm_mday) { /* date has changed while online */ ! 176: putuserrec(&cfg,useron.number,U_LTODAY,5,"0"); ! 177: useron.ttoday=0; /* so zero logons today and time on today */ ! 178: useron.textra=0; } /* and extra time */ ! 179: ! 180: putuserrec(&cfg,useron.number,U_NS_TIME,8,ultoa(last_ns_time,str,16)); ! 181: putuserrec(&cfg,useron.number,U_LASTON,8,ultoa(useron.laston,str,16)); ! 182: putuserrec(&cfg,useron.number,U_TIMEON,5,ultoa(useron.timeon,str,10)); ! 183: putuserrec(&cfg,useron.number,U_TTODAY,5,ultoa(useron.ttoday,str,10)); ! 184: putuserrec(&cfg,useron.number,U_TEXTRA,5,ultoa(useron.textra,str,10)); ! 185: putuserrec(&cfg,useron.number,U_TLAST,5,ultoa(useron.tlast,str,10)); ! 186: ! 187: getusrsubs(); ! 188: getusrdirs(); ! 189: if(usrgrps>0) ! 190: putuserrec(&cfg,useron.number,U_CURSUB,8,cfg.sub[usrsub[curgrp][cursub[curgrp]]]->code); ! 191: if(usrlibs>0) ! 192: putuserrec(&cfg,useron.number,U_CURDIR,8,cfg.dir[usrdir[curlib][curdir[curlib]]]->code); ! 193: sprintf(str,"%02d:%02d%c ",tm_now.tm_hour>12 ? tm_now.tm_hour-12 ! 194: : tm_now.tm_hour==0 ? 12 : tm_now.tm_hour, tm_now.tm_min ! 195: , tm_now.tm_hour>=12 ? 'p' : 'a'); ! 196: if(sys_status&SS_USERON) ! 197: sprintf(tmp,"T:%3u R:%3lu P:%3lu E:%3lu F:%3lu " ! 198: "U:%3luk %lu D:%3luk %lu" ! 199: ,(uint)(now-logontime)/60,posts_read,logon_posts ! 200: ,logon_emails,logon_fbacks,logon_ulb/1024UL,logon_uls ! 201: ,logon_dlb/1024UL,logon_dls); ! 202: else ! 203: sprintf(tmp,"T:%3u sec",(uint)(now-answertime)); ! 204: strcat(str,tmp); ! 205: strcat(str,"\r\n"); ! 206: logline("@-",str); ! 207: sys_status&=~SS_USERON; ! 208: answertime=now; // Incase we're relogging on ! 209: } ! 210: ! 211: /****************************************************************************/ ! 212: /* Backout of transactions and statuses for this node */ ! 213: /****************************************************************************/ ! 214: void sbbs_t::backout() ! 215: { ! 216: char str[256],code[128],*buf; ! 217: int i,file; ! 218: long length,l; ! 219: file_t f; ! 220: ! 221: sprintf(str,"%sbackout.dab",cfg.node_dir); ! 222: if(flength(str)<1L) { ! 223: remove(str); ! 224: return; } ! 225: if((file=nopen(str,O_RDONLY))==-1) { ! 226: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 227: return; } ! 228: length=filelength(file); ! 229: if((buf=(char *)MALLOC(length))==NULL) { ! 230: close(file); ! 231: errormsg(WHERE,ERR_ALLOC,str,length); ! 232: return; } ! 233: if(read(file,buf,length)!=length) { ! 234: close(file); ! 235: FREE(buf); ! 236: errormsg(WHERE,ERR_READ,str,length); ! 237: return; } ! 238: close(file); ! 239: for(l=0;l<length;l+=BO_LEN) { ! 240: switch(buf[l]) { ! 241: case BO_OPENFILE: /* file left open */ ! 242: memcpy(code,buf+l+1,8); ! 243: code[8]=0; ! 244: for(i=0;i<cfg.total_dirs;i++) /* search by code */ ! 245: if(!stricmp(cfg.dir[i]->code,code)) ! 246: break; ! 247: if(i<cfg.total_dirs) { /* found internal code */ ! 248: f.dir=i; ! 249: memcpy(&f.datoffset,buf+l+9,4); ! 250: closefile(&f); } ! 251: break; ! 252: default: ! 253: errormsg(WHERE,ERR_CHK,str,buf[l]); } } ! 254: FREE(buf); ! 255: remove(str); /* always remove the backout file */ ! 256: } ! 257: ! 258: /****************************************************************************/ ! 259: /* Detailed usage stats for each logon */ ! 260: /****************************************************************************/ ! 261: void sbbs_t::logofflist() ! 262: { ! 263: char str[256]; ! 264: int file; ! 265: struct tm * tm, tm_now; ! 266: ! 267: tm=gmtime(&now); ! 268: if(tm==NULL) ! 269: return; ! 270: tm_now=*tm; ! 271: tm=gmtime(&logontime); ! 272: if(tm==NULL) ! 273: return; ! 274: sprintf(str,"%slogs/%2.2d%2.2d%2.2d.LOL",cfg.data_dir,tm->tm_mon+1,tm->tm_mday ! 275: ,TM_YEAR(tm->tm_year)); ! 276: if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) { ! 277: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND); ! 278: return; } ! 279: sprintf(str,"%-*.*s %-2d %-8.8s %2.2d:%2.2d %2.2d:%2.2d %3d%3ld%3ld%3ld%3ld" ! 280: "%3ld%3ld\r\n",LEN_ALIAS,LEN_ALIAS,useron.alias,cfg.node_num,connection ! 281: ,tm->tm_hour,tm->tm_min,tm_now.tm_hour,tm_now.tm_min ! 282: ,(int)(now-logontime)/60,posts_read,logon_posts,logon_emails ! 283: ,logon_fbacks,logon_uls,logon_dls); ! 284: write(file,str,strlen(str)); ! 285: close(file); ! 286: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.