|
|
1.1 ! root 1: /* logout.cpp */ ! 2: ! 3: /* Synchronet user logout routines */ ! 4: ! 5: /* $Id: logout.cpp,v 1.22 2005/09/20 03:39:51 deuce 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; ! 52: ! 53: now=time(NULL); ! 54: if(localtime_r(&now,&tm)==NULL) ! 55: return; ! 56: ! 57: if(!useron.number) { /* Not logged in, so do nothing */ ! 58: if(!online) { ! 59: sprintf(str,"%s T:%3u sec\r\n" ! 60: ,hhmmtostr(&cfg,&tm,tmp) ! 61: ,(uint)(now-answertime)); ! 62: logline("@-",str); } ! 63: return; ! 64: } ! 65: strcpy(lastuseron,useron.alias); /* for use with WFC status display */ ! 66: ! 67: if(useron.rest&FLAG('G')) { /* Reset guest's msg scan cfg */ ! 68: putuserrec(&cfg,useron.number,U_NAME,LEN_NAME,nulstr); ! 69: batdn_total=0; ! 70: } ! 71: ! 72: batch_create_list(); ! 73: ! 74: if(sys_status&SS_USERON && thisnode.status!=NODE_QUIET && !(useron.rest&FLAG('Q'))) ! 75: for(i=1;i<=cfg.sys_nodes;i++) ! 76: if(i!=cfg.node_num) { ! 77: getnodedat(i,&node,0); ! 78: if((node.status==NODE_INUSE || node.status==NODE_QUIET) ! 79: && !(node.misc&NODE_AOFF) && node.useron!=useron.number) { ! 80: sprintf(str,text[NodeLoggedOff],cfg.node_num ! 81: ,thisnode.misc&NODE_ANON ! 82: ? text[UNKNOWN_USER] : useron.alias); ! 83: putnmsg(&cfg,i,str); } } ! 84: ! 85: if(!online) { /* NOT re-login */ ! 86: ! 87: #if 0 /* too soon, handled in node_thread */ ! 88: getnodedat(cfg.node_num,&thisnode,1); ! 89: thisnode.status=NODE_WFC; ! 90: thisnode.misc&=~(NODE_INTR|NODE_MSGW|NODE_NMSG ! 91: |NODE_UDAT|NODE_POFF|NODE_AOFF|NODE_EXT); ! 92: putnodedat(cfg.node_num,&thisnode); ! 93: #endif ! 94: ! 95: #if 0 /* beep? */ ! 96: if(sys_status&SS_SYSALERT) { ! 97: mswait(500); ! 98: offhook(); ! 99: CLS; ! 100: lputs("\r\n\r\nAlerting Sysop..."); ! 101: while(!lkbrd(1)) { ! 102: sbbs_beep(1000,200); ! 103: nosound(); ! 104: mswait(200); } ! 105: lkbrd(0); } ! 106: #endif ! 107: sys_status&=~SS_SYSALERT; ! 108: if(cfg.sys_logout[0]) /* execute system logout event */ ! 109: external(cmdstr(cfg.sys_logout,nulstr,nulstr,NULL),EX_OUTL|EX_OFFLINE); ! 110: } ! 111: ! 112: if(cfg.logout_mod[0]) ! 113: exec_bin(cfg.logout_mod,&main_csi); ! 114: backout(); ! 115: sprintf(str,"%smsgs/%4.4u.msg",cfg.data_dir,useron.number); ! 116: if(!flength(str)) /* remove any 0 byte message files */ ! 117: remove(str); ! 118: ! 119: delfiles(cfg.temp_dir,ALLFILES); ! 120: putmsgptrs(); ! 121: if(!REALSYSOP) ! 122: logofflist(); ! 123: useron.laston=now; ! 124: ! 125: ttoday=useron.ttoday-useron.textra; /* billable time used prev calls */ ! 126: if(ttoday>=cfg.level_timeperday[useron.level]) ! 127: i=0; ! 128: else ! 129: i=cfg.level_timeperday[useron.level]-ttoday; ! 130: if(i>cfg.level_timepercall[useron.level]) /* i=amount of time without min */ ! 131: i=cfg.level_timepercall[useron.level]; ! 132: j=(now-starttime)/60; /* j=billable time online in min */ ! 133: if(i<0) i=0; ! 134: if(j<0) j=0; ! 135: ! 136: if(useron.min && j>i) { ! 137: j-=i; /* j=time to deduct from min */ ! 138: sprintf(str,"Minute Adjustment: %d",-j); ! 139: logline(">>",str); ! 140: if(useron.min>(ulong)j) ! 141: useron.min-=j; ! 142: else ! 143: useron.min=0L; ! 144: putuserrec(&cfg,useron.number,U_MIN,10,ultoa(useron.min,str,10)); } ! 145: ! 146: if(timeleft>0 && starttime-logontime>0) /* extra time */ ! 147: useron.textra+=(ushort)((starttime-logontime)/60); ! 148: ! 149: putuserrec(&cfg,useron.number,U_TEXTRA,5,ultoa(useron.textra,str,10)); ! 150: putuserrec(&cfg,useron.number,U_NS_TIME,8,ultoa(last_ns_time,str,16)); ! 151: ! 152: logoutuserdat(&cfg, &useron, now, logontime); ! 153: ! 154: getusrsubs(); ! 155: getusrdirs(); ! 156: if(usrgrps>0) ! 157: putuserrec(&cfg,useron.number,U_CURSUB,0,cfg.sub[usrsub[curgrp][cursub[curgrp]]]->code); ! 158: if(usrlibs>0) ! 159: putuserrec(&cfg,useron.number,U_CURDIR,0,cfg.dir[usrdir[curlib][curdir[curlib]]]->code); ! 160: hhmmtostr(&cfg,&tm,str); ! 161: strcat(str," "); ! 162: if(sys_status&SS_USERON) ! 163: sprintf(tmp,"T:%3u R:%3lu P:%3lu E:%3lu F:%3lu " ! 164: "U:%3luk %lu D:%3luk %lu" ! 165: ,(uint)(now-logontime)/60,posts_read,logon_posts ! 166: ,logon_emails,logon_fbacks,logon_ulb/1024UL,logon_uls ! 167: ,logon_dlb/1024UL,logon_dls); ! 168: else ! 169: sprintf(tmp,"T:%3u sec",(uint)(now-answertime)); ! 170: strcat(str,tmp); ! 171: strcat(str,"\r\n"); ! 172: logline("@-",str); ! 173: sys_status&=~SS_USERON; ! 174: answertime=now; // Incase we're relogging on ! 175: } ! 176: ! 177: /****************************************************************************/ ! 178: /* Backout of transactions and statuses for this node */ ! 179: /****************************************************************************/ ! 180: void sbbs_t::backout() ! 181: { ! 182: char str[256],code[128],*buf; ! 183: int i,file; ! 184: long length,l; ! 185: file_t f; ! 186: ! 187: sprintf(str,"%sbackout.dab",cfg.node_dir); ! 188: if(flength(str)<1L) { ! 189: remove(str); ! 190: return; } ! 191: if((file=nopen(str,O_RDONLY))==-1) { ! 192: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 193: return; } ! 194: length=filelength(file); ! 195: if((buf=(char *)malloc(length))==NULL) { ! 196: close(file); ! 197: errormsg(WHERE,ERR_ALLOC,str,length); ! 198: return; } ! 199: if(read(file,buf,length)!=length) { ! 200: close(file); ! 201: free(buf); ! 202: errormsg(WHERE,ERR_READ,str,length); ! 203: return; } ! 204: close(file); ! 205: for(l=0;l<length;l+=BO_LEN) { ! 206: switch(buf[l]) { ! 207: case BO_OPENFILE: /* file left open */ ! 208: memcpy(code,buf+l+1,8); ! 209: code[8]=0; ! 210: for(i=0;i<cfg.total_dirs;i++) /* search by code */ ! 211: if(!stricmp(cfg.dir[i]->code,code)) ! 212: break; ! 213: if(i<cfg.total_dirs) { /* found internal code */ ! 214: f.dir=i; ! 215: memcpy(&f.datoffset,buf+l+9,4); ! 216: closefile(&f); } ! 217: break; ! 218: default: ! 219: errormsg(WHERE,ERR_CHK,str,buf[l]); } } ! 220: free(buf); ! 221: remove(str); /* always remove the backout file */ ! 222: } ! 223: ! 224: /****************************************************************************/ ! 225: /* Detailed usage stats for each logon */ ! 226: /****************************************************************************/ ! 227: void sbbs_t::logofflist() ! 228: { ! 229: char str[256]; ! 230: int file; ! 231: struct tm tm, tm_now; ! 232: ! 233: if(localtime_r(&now,&tm_now)==NULL) ! 234: return; ! 235: if(localtime_r(&logontime,&tm)==NULL) ! 236: return; ! 237: sprintf(str,"%slogs/%2.2d%2.2d%2.2d.lol",cfg.logs_dir,tm.tm_mon+1,tm.tm_mday ! 238: ,TM_YEAR(tm.tm_year)); ! 239: if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) { ! 240: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND); ! 241: return; } ! 242: sprintf(str,"%-*.*s %-2d %-8.8s %2.2d:%2.2d %2.2d:%2.2d %3d%3ld%3ld%3ld%3ld" ! 243: "%3ld%3ld\r\n",LEN_ALIAS,LEN_ALIAS,useron.alias,cfg.node_num,connection ! 244: ,tm.tm_hour,tm.tm_min,tm_now.tm_hour,tm_now.tm_min ! 245: ,(int)(now-logontime)/60,posts_read,logon_posts,logon_emails ! 246: ,logon_fbacks,logon_uls,logon_dls); ! 247: write(file,str,strlen(str)); ! 248: close(file); ! 249: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.