|
|
1.1 ! root 1: #line 1 "GETUSER.C" ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: #include "sbbs.h" ! 6: #include "cmdshell.h" ! 7: ! 8: /****************************************************************************/ ! 9: /* Fills the structure 'user' with info for user.number from USER.DAT */ ! 10: /* Called from functions useredit, waitforcall and main_sec */ ! 11: /****************************************************************************/ ! 12: void getuserdat(user_t *user) ! 13: { ! 14: uchar userdat[U_LEN+1],str[U_LEN+1]; ! 15: int i,file; ! 16: ! 17: if(!user->number || user->number>lastuser()) { ! 18: memset(user,0L,sizeof(user_t)); ! 19: user->number=0; ! 20: return; } ! 21: sprintf(userdat,"%sUSER\\USER.DAT",data_dir); ! 22: if((file=nopen(userdat,O_RDONLY|O_DENYNONE))==-1) { ! 23: close(file); ! 24: memset(user,0L,sizeof(user_t)); ! 25: user->number=0; ! 26: return; } ! 27: lseek(file,(long)((long)(user->number-1)*U_LEN),SEEK_SET); ! 28: i=0; ! 29: while(i<LOOP_NODEDAB ! 30: && lock(file,(long)((long)(user->number-1)*U_LEN),U_LEN)==-1) { ! 31: if(i>10) ! 32: mswait(55); ! 33: i++; } ! 34: ! 35: if(i>=LOOP_NODEDAB) { ! 36: close(file); ! 37: errormsg(WHERE,ERR_LOCK,"USER.DAT",user->number); ! 38: memset(user,0L,sizeof(user_t)); ! 39: user->number=0; ! 40: return; } ! 41: ! 42: if(read(file,userdat,U_LEN)!=U_LEN) { ! 43: unlock(file,(long)((long)(user->number-1)*U_LEN),U_LEN); ! 44: close(file); ! 45: errormsg(WHERE,ERR_READ,"USER.DAT",U_LEN); ! 46: memset(user,0L,sizeof(user_t)); ! 47: user->number=0; ! 48: return; } ! 49: ! 50: unlock(file,(long)((long)(user->number-1)*U_LEN),U_LEN); ! 51: close(file); ! 52: getrec(userdat,U_ALIAS,LEN_ALIAS,user->alias); ! 53: /* order of these function */ ! 54: getrec(userdat,U_NAME,LEN_NAME,user->name); ! 55: /* calls is irrelevant */ ! 56: getrec(userdat,U_HANDLE,LEN_HANDLE,user->handle); ! 57: getrec(userdat,U_NOTE,LEN_NOTE,user->note); ! 58: getrec(userdat,U_COMP,LEN_COMP,user->comp); ! 59: getrec(userdat,U_COMMENT,LEN_COMMENT,user->comment); ! 60: getrec(userdat,U_NETMAIL,LEN_NETMAIL,user->netmail); ! 61: getrec(userdat,U_ADDRESS,LEN_ADDRESS,user->address); ! 62: getrec(userdat,U_LOCATION,LEN_LOCATION,user->location); ! 63: getrec(userdat,U_ZIPCODE,LEN_ZIPCODE,user->zipcode); ! 64: getrec(userdat,U_PASS,LEN_PASS,user->pass); ! 65: getrec(userdat,U_PHONE,LEN_PHONE,user->phone); ! 66: getrec(userdat,U_BIRTH,LEN_BIRTH,user->birth); ! 67: getrec(userdat,U_MODEM,LEN_MODEM,user->modem); ! 68: getrec(userdat,U_LASTON,8,str); user->laston=ahtoul(str); ! 69: getrec(userdat,U_FIRSTON,8,str); user->firston=ahtoul(str); ! 70: getrec(userdat,U_EXPIRE,8,str); user->expire=ahtoul(str); ! 71: getrec(userdat,U_PWMOD,8,str); user->pwmod=ahtoul(str); ! 72: getrec(userdat,U_NS_TIME,8,str); ! 73: user->ns_time=ahtoul(str); ! 74: if(user->ns_time<0x20000000L) ! 75: user->ns_time=user->laston; /* Fix for v2.00->v2.10 */ ! 76: ! 77: getrec(userdat,U_LOGONS,5,str); user->logons=atoi(str); ! 78: getrec(userdat,U_LTODAY,5,str); user->ltoday=atoi(str); ! 79: getrec(userdat,U_TIMEON,5,str); user->timeon=atoi(str); ! 80: getrec(userdat,U_TEXTRA,5,str); user->textra=atoi(str); ! 81: getrec(userdat,U_TTODAY,5,str); user->ttoday=atoi(str); ! 82: getrec(userdat,U_TLAST,5,str); user->tlast=atoi(str); ! 83: getrec(userdat,U_POSTS,5,str); user->posts=atoi(str); ! 84: getrec(userdat,U_EMAILS,5,str); user->emails=atoi(str); ! 85: getrec(userdat,U_FBACKS,5,str); user->fbacks=atoi(str); ! 86: getrec(userdat,U_ETODAY,5,str); user->etoday=atoi(str); ! 87: getrec(userdat,U_PTODAY,5,str); user->ptoday=atoi(str); ! 88: getrec(userdat,U_ULB,10,str); user->ulb=atol(str); ! 89: getrec(userdat,U_ULS,5,str); user->uls=atoi(str); ! 90: getrec(userdat,U_DLB,10,str); user->dlb=atol(str); ! 91: getrec(userdat,U_DLS,5,str); user->dls=atoi(str); ! 92: getrec(userdat,U_CDT,10,str); user->cdt=atol(str); ! 93: getrec(userdat,U_MIN,10,str); user->min=atol(str); ! 94: getrec(userdat,U_LEVEL,2,str); user->level=atoi(str); ! 95: getrec(userdat,U_FLAGS1,8,str); user->flags1=ahtoul(str); /*** ! 96: getrec(userdat,U_TL,2,str); user->tl=atoi(str); ***/ ! 97: getrec(userdat,U_FLAGS2,8,str); user->flags2=ahtoul(str); ! 98: getrec(userdat,U_FLAGS3,8,str); user->flags3=ahtoul(str); ! 99: getrec(userdat,U_FLAGS4,8,str); user->flags4=ahtoul(str); ! 100: getrec(userdat,U_EXEMPT,8,str); user->exempt=ahtoul(str); ! 101: getrec(userdat,U_REST,8,str); user->rest=ahtoul(str); ! 102: getrec(userdat,U_ROWS,2,str); user->rows=atoi(str); ! 103: if(user->rows && user->rows<10) ! 104: user->rows=10; ! 105: user->sex=userdat[U_SEX]; ! 106: if(!user->sex) ! 107: user->sex=SP; /* fix for v1b04 that could save as 0 */ ! 108: user->prot=userdat[U_PROT]; ! 109: if(user->prot<SP) ! 110: user->prot=SP; ! 111: getrec(userdat,U_MISC,8,str); user->misc=ahtoul(str); ! 112: if(user->rest&FLAG('Q')) ! 113: user->misc&=~SPIN; ! 114: ! 115: getrec(userdat,U_LEECH,2,str); ! 116: user->leech=(uchar)ahtoul(str); ! 117: getrec(userdat,U_CURSUB,8,useron.cursub); ! 118: getrec(userdat,U_CURDIR,8,useron.curdir); ! 119: ! 120: getrec(userdat,U_FREECDT,10,str); ! 121: user->freecdt=atol(str); ! 122: ! 123: getrec(userdat,U_XEDIT,8,str); ! 124: for(i=0;i<total_xedits;i++) ! 125: if(!stricmp(str,xedit[i]->code) && chk_ar(xedit[i]->ar,*user)) ! 126: break; ! 127: user->xedit=i+1; ! 128: if(user->xedit>total_xedits) ! 129: user->xedit=0; ! 130: ! 131: getrec(userdat,U_SHELL,8,str); ! 132: for(i=0;i<total_shells;i++) ! 133: if(!stricmp(str,shell[i]->code)) ! 134: break; ! 135: if(i==total_shells) ! 136: i=0; ! 137: user->shell=i; ! 138: ! 139: getrec(userdat,U_QWK,8,str); ! 140: if(str[0]<SP) { /* v1c, so set defaults */ ! 141: if(user->rest&FLAG('Q')) ! 142: user->qwk=(QWK_RETCTLA); ! 143: else ! 144: user->qwk=(QWK_FILES|QWK_ATTACH|QWK_EMAIL|QWK_DELMAIL); } ! 145: else ! 146: user->qwk=ahtoul(str); ! 147: ! 148: getrec(userdat,U_TMPEXT,3,user->tmpext); ! 149: if((!user->tmpext[0] || !strcmp(user->tmpext,"0")) && total_fcomps) ! 150: strcpy(user->tmpext,fcomp[0]->ext); /* For v1x to v2x conversion */ ! 151: ! 152: getrec(userdat,U_CHAT,8,str); ! 153: user->chat=ahtoul(str); ! 154: ! 155: if(useron.number==user->number) { ! 156: useron=*user; ! 157: ! 158: if(online) { ! 159: ! 160: #if 0 ! 161: getusrdirs(); ! 162: getusrsubs(); ! 163: #endif ! 164: if(useron.misc&AUTOTERM) { ! 165: useron.misc&=~(ANSI|RIP|WIP); ! 166: useron.misc|=autoterm; } ! 167: statusline(); } } ! 168: } ! 169: ! 170: ! 171: /****************************************************************************/ ! 172: /* Returns the username in 'str' that corresponds to the 'usernumber' */ ! 173: /* Called from functions everywhere */ ! 174: /****************************************************************************/ ! 175: char *username(int usernumber,char *strin) ! 176: { ! 177: char str[256]; ! 178: char c; ! 179: int file; ! 180: ! 181: if(usernumber<1) { ! 182: strin[0]=0; ! 183: return(strin); } ! 184: sprintf(str,"%sUSER\\NAME.DAT",data_dir); ! 185: if(flength(str)<1L) { ! 186: strin[0]=0; ! 187: return(strin); } ! 188: if((file=nopen(str,O_RDONLY))==-1) { ! 189: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 190: strin[0]=0; ! 191: return(strin); } ! 192: if(filelength(file)<(long)((long)usernumber*(LEN_ALIAS+2))) { ! 193: close(file); ! 194: strin[0]=0; ! 195: return(strin); } ! 196: lseek(file,(long)((long)(usernumber-1)*(LEN_ALIAS+2)),SEEK_SET); ! 197: read(file,strin,LEN_ALIAS); ! 198: close(file); ! 199: for(c=0;c<LEN_ALIAS;c++) ! 200: if(strin[c]==ETX) break; ! 201: strin[c]=0; ! 202: if(!c) ! 203: strcpy(strin,"DELETED USER"); ! 204: return(strin); ! 205: } ! 206: ! 207: /****************************************************************************/ ! 208: /* Fills the timeleft variable with the correct value. Hangs up on the */ ! 209: /* user if their time is up. */ ! 210: /* Called from functions main_sec and xfer_sec */ ! 211: /****************************************************************************/ ! 212: void gettimeleft(void) ! 213: { ! 214: static inside; ! 215: char str[128]; ! 216: int i; ! 217: time_t eventtime=0,thisevent; ! 218: long tleft; ! 219: struct date lastdate; ! 220: struct tm *gm; ! 221: ! 222: now=time(NULL); ! 223: ! 224: gm=localtime(&now); ! 225: if(useron.exempt&FLAG('T')) { /* Time online exemption */ ! 226: timeleft=level_timepercall[useron.level]*60; ! 227: if(timeleft<10) /* never get below 10 for exempt users */ ! 228: timeleft=10; } ! 229: else { ! 230: tleft=(((long)level_timeperday[useron.level]-useron.ttoday) ! 231: +useron.textra)*60L; ! 232: if(tleft<0) tleft=0; ! 233: if(tleft>level_timepercall[useron.level]*60) ! 234: tleft=level_timepercall[useron.level]*60; ! 235: tleft+=useron.min*60L; ! 236: tleft-=now-starttime; ! 237: if(tleft>0x7fffL) ! 238: timeleft=0x7fff; ! 239: else ! 240: timeleft=tleft; } ! 241: ! 242: /* Timed event time reduction handler */ ! 243: ! 244: for(i=0;i<total_events;i++) { ! 245: if(!event[i]->node || event[i]->node>sys_nodes) ! 246: continue; ! 247: if(!(event[i]->misc&EVENT_FORCE) ! 248: || (!(event[i]->misc&EVENT_EXCL) && event[i]->node!=node_num) ! 249: || !(event[i]->days&(1<<gm->tm_wday))) ! 250: continue; ! 251: unixtodos(event[i]->last,&lastdate,&curtime); ! 252: unixtodos(now,&date,&curtime); ! 253: curtime.ti_hour=event[i]->time/60; /* hasn't run yet today */ ! 254: curtime.ti_min=event[i]->time-(curtime.ti_hour*60); ! 255: curtime.ti_sec=0; ! 256: thisevent=dostounix(&date,&curtime); ! 257: if(date.da_day==lastdate.da_day && date.da_mon==lastdate.da_mon) ! 258: thisevent+=24L*60L*60L; /* already ran today, so add 24hrs */ ! 259: if(!eventtime || thisevent<eventtime) ! 260: eventtime=thisevent; } ! 261: if(eventtime && now+timeleft>eventtime) { /* less time, set flag */ ! 262: sys_status|=SS_EVENT; ! 263: timeleft=eventtime-now; } ! 264: ! 265: /* Event time passed by front-end */ ! 266: if(next_event && (next_event<now || next_event-now<timeleft)) { ! 267: timeleft=next_event-now; ! 268: sys_status|=SS_EVENT; } ! 269: ! 270: if(timeleft<0) /* timeleft can't go negative */ ! 271: timeleft=0; ! 272: if(thisnode.status==NODE_NEWUSER) { ! 273: timeleft=level_timepercall[new_level]; ! 274: if(timeleft<10*60L) ! 275: timeleft=10*60L; } ! 276: ! 277: if(inside) /* The following code is not recursive */ ! 278: return; ! 279: inside=1; ! 280: ! 281: if(!timeleft && !SYSOP && !(sys_status&SS_LCHAT)) { ! 282: logline(nulstr,"Ran out of time"); ! 283: SAVELINE; ! 284: bputs(text[TimesUp]); ! 285: if(!(sys_status&(SS_EVENT|SS_USERON)) && useron.cdt>=100L*1024L ! 286: && !(sys_misc&SM_NOCDTCVT)) { ! 287: sprintf(tmp,text[Convert100ktoNminQ],cdt_min_value); ! 288: if(yesno(tmp)) { ! 289: logline(" ","Credit to Minute Conversion"); ! 290: useron.min=adjustuserrec(useron.number,U_MIN,10,cdt_min_value); ! 291: useron.cdt=adjustuserrec(useron.number,U_CDT,10,-(102400L)); ! 292: sprintf(str,"Credit Adjustment: %ld",-(102400L)); ! 293: logline("$-",str); ! 294: sprintf(str,"Minute Adjustment: %u",cdt_min_value); ! 295: logline("*+",str); ! 296: RESTORELINE; ! 297: gettimeleft(); ! 298: inside=0; ! 299: return; } } ! 300: if(sys_misc&SM_TIME_EXP && !(sys_status&SS_EVENT) ! 301: && !(useron.exempt&FLAG('E'))) { ! 302: /* set to expired values */ ! 303: bputs(text[AccountHasExpired]); ! 304: sprintf(str,"%s Expired",useron.alias); ! 305: logentry("!%",str); ! 306: if(level_misc[useron.level]&LEVEL_EXPTOVAL ! 307: && level_expireto[useron.level]<10) { ! 308: useron.flags1=val_flags1[level_expireto[useron.level]]; ! 309: useron.flags2=val_flags2[level_expireto[useron.level]]; ! 310: useron.flags3=val_flags3[level_expireto[useron.level]]; ! 311: useron.flags4=val_flags4[level_expireto[useron.level]]; ! 312: useron.exempt=val_exempt[level_expireto[useron.level]]; ! 313: useron.rest=val_rest[level_expireto[useron.level]]; ! 314: if(val_expire[level_expireto[useron.level]]) ! 315: useron.expire=now ! 316: +(val_expire[level_expireto[useron.level]]*24*60*60); ! 317: else ! 318: useron.expire=0; ! 319: useron.level=val_level[level_expireto[useron.level]]; } ! 320: else { ! 321: if(level_misc[useron.level]&LEVEL_EXPTOLVL) ! 322: useron.level=level_expireto[useron.level]; ! 323: else ! 324: useron.level=expired_level; ! 325: useron.flags1&=~expired_flags1; /* expired status */ ! 326: useron.flags2&=~expired_flags2; /* expired status */ ! 327: useron.flags3&=~expired_flags3; /* expired status */ ! 328: useron.flags4&=~expired_flags4; /* expired status */ ! 329: useron.exempt&=~expired_exempt; ! 330: useron.rest|=expired_rest; ! 331: useron.expire=0; } ! 332: putuserrec(useron.number,U_LEVEL,2,itoa(useron.level,str,10)); ! 333: putuserrec(useron.number,U_FLAGS1,8,ultoa(useron.flags1,str,16)); ! 334: putuserrec(useron.number,U_FLAGS2,8,ultoa(useron.flags2,str,16)); ! 335: putuserrec(useron.number,U_FLAGS3,8,ultoa(useron.flags3,str,16)); ! 336: putuserrec(useron.number,U_FLAGS4,8,ultoa(useron.flags4,str,16)); ! 337: putuserrec(useron.number,U_EXPIRE,8,ultoa(useron.expire,str,16)); ! 338: putuserrec(useron.number,U_EXEMPT,8,ultoa(useron.exempt,str,16)); ! 339: putuserrec(useron.number,U_REST,8,ultoa(useron.rest,str,16)); ! 340: if(expire_mod[0]) ! 341: exec_bin(expire_mod,&main_csi); ! 342: RESTORELINE; ! 343: gettimeleft(); ! 344: inside=0; ! 345: return; } ! 346: SYNC; ! 347: hangup(); } ! 348: inside=0; ! 349: } ! 350: ! 351: /****************************************************************************/ ! 352: /* Places into 'strout' CR or ETX terminated string starting at */ ! 353: /* 'start' and ending at 'start'+'length' or terminator from 'strin' */ ! 354: /****************************************************************************/ ! 355: void getrec(char *strin,int start,int length,char *strout) ! 356: { ! 357: int i=0,stop; ! 358: ! 359: stop=start+length; ! 360: while(start<stop) { ! 361: if(strin[start]==ETX || strin[start]==CR || strin[start]==LF) ! 362: break; ! 363: strout[i++]=strin[start++]; } ! 364: strout[i]=0; ! 365: } ! 366: ! 367: /****************************************************************************/ ! 368: /* Places into 'strout', 'strin' starting at 'start' and ending at */ ! 369: /* 'start'+'length' */ ! 370: /****************************************************************************/ ! 371: void putrec(char *strout,int start,int length,char *strin) ! 372: { ! 373: int i=0,j; ! 374: ! 375: j=strlen(strin); ! 376: while(i<j && i<length) ! 377: strout[start++]=strin[i++]; ! 378: while(i++<length) ! 379: strout[start++]=ETX; ! 380: } ! 381: ! 382: ! 383: /****************************************************************************/ ! 384: /* Returns the age derived from the string 'birth' in the format MM/DD/YY */ ! 385: /* Called from functions statusline, main_sec, xfer_sec, useredit and */ ! 386: /* text files */ ! 387: /****************************************************************************/ ! 388: char getage(char *birth) ! 389: { ! 390: char age; ! 391: ! 392: if(!atoi(birth) || !atoi(birth+3)) /* Invalid */ ! 393: return(0); ! 394: getdate(&date); ! 395: age=(date.da_year-1900)-(((birth[6]&0xf)*10)+(birth[7]&0xf)); ! 396: if(sys_misc&SM_EURODATE) { /* DD/MM/YY format */ ! 397: if(atoi(birth)>31 || atoi(birth+3)>12) ! 398: return(0); ! 399: if(((birth[3]&0xf)*10)+(birth[4]&0xf)>date.da_mon || ! 400: (((birth[3]&0xf)*10)+(birth[4]&0xf)==date.da_mon && ! 401: ((birth[0]&0xf)*10)+(birth[1]&0xf)>date.da_day)) ! 402: age--; } ! 403: else { /* MM/DD/YY format */ ! 404: if(atoi(birth)>12 || atoi(birth+3)>31) ! 405: return(0); ! 406: if(((birth[0]&0xf)*10)+(birth[1]&0xf)>date.da_mon || ! 407: (((birth[0]&0xf)*10)+(birth[1]&0xf)==date.da_mon && ! 408: ((birth[3]&0xf)*10)+(birth[4]&0xf)>date.da_day)) ! 409: age--; } ! 410: if(age<0) ! 411: return(0); ! 412: return(age); ! 413: } ! 414: ! 415: ! 416: /****************************************************************************/ ! 417: /* Converts an ASCII Hex string into an ulong */ ! 418: /****************************************************************************/ ! 419: ulong ahtoul(char *str) ! 420: { ! 421: ulong l,val=0; ! 422: ! 423: while((l=(*str++)|0x20)!=0x20) ! 424: val=(l&0xf)+(l>>6&1)*9+val*16; ! 425: return(val); ! 426: } ! 427:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.