|
|
1.1 ! root 1: /* data_ovl.cpp */ ! 2: ! 3: /* Synchronet hi-level data access routines */ ! 4: ! 5: /* $Id: data_ovl.cpp,v 1.5 2000/11/14 22:16:58 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: ! 40: /****************************************************************************/ ! 41: /* Puts 'name' into slot 'number' in user/name.dat */ ! 42: /****************************************************************************/ ! 43: void sbbs_t::putusername(int number, char *name) ! 44: { ! 45: char str[256]; ! 46: int file; ! 47: long length; ! 48: ! 49: if (number<1) { ! 50: errormsg(WHERE,ERR_CHK,"user number",number); ! 51: return; } ! 52: ! 53: sprintf(str,"%suser/name.dat", cfg.data_dir); ! 54: if((file=nopen(str,O_RDWR|O_CREAT))==-1) { ! 55: errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_CREAT); ! 56: return; } ! 57: length=filelength(file); ! 58: if(length && length%(LEN_ALIAS+2)) { ! 59: close(file); ! 60: errormsg(WHERE,ERR_LEN,str,length); ! 61: return; } ! 62: if(length<(((long)number-1)*(LEN_ALIAS+2))) { ! 63: sprintf(str,"%*s",LEN_ALIAS,nulstr); ! 64: memset(str,ETX,LEN_ALIAS); ! 65: strcat(str,crlf); ! 66: lseek(file,0L,SEEK_END); ! 67: while(filelength(file)<((long)number*(LEN_ALIAS+2))) ! 68: write(file,str,(LEN_ALIAS+2)); } ! 69: lseek(file,(long)(((long)number-1)*(LEN_ALIAS+2)),SEEK_SET); ! 70: putrec(str,0,LEN_ALIAS,name); ! 71: putrec(str,LEN_ALIAS,2,crlf); ! 72: write(file,str,LEN_ALIAS+2); ! 73: close(file); ! 74: } ! 75: ! 76: /****************************************************************************/ ! 77: /* Fills the 'ptr' element of the each element of the cfg.sub[] array of sub_t */ ! 78: /* and the sub_cfg and sub_ptr global variables */ ! 79: /* Called from function main */ ! 80: /****************************************************************************/ ! 81: void sbbs_t::getmsgptrs() ! 82: { ! 83: char str[256]; ! 84: uint i; ! 85: int file; ! 86: long length; ! 87: FILE *stream; ! 88: ! 89: now=time(NULL); ! 90: if(!useron.number) ! 91: return; ! 92: bputs(text[LoadingMsgPtrs]); ! 93: sprintf(str,"%suser/ptrs/%4.4u.ixb", cfg.data_dir,useron.number); ! 94: if((stream=fnopen(&file,str,O_RDONLY))==NULL) { ! 95: for(i=0;i<cfg.total_subs;i++) { ! 96: sub_ptr[i]=sav_sub_ptr[i]=0; ! 97: sub_last[i]=sav_sub_last[i]=0; ! 98: sub_cfg[i]=0; ! 99: if(cfg.sub[i]->misc&SUB_NSDEF) ! 100: sub_cfg[i]|=SUB_CFG_NSCAN; ! 101: if(cfg.sub[i]->misc&SUB_SSDEF) ! 102: sub_cfg[i]|=SUB_CFG_SSCAN; ! 103: sav_sub_cfg[i]=sub_cfg[i]; ! 104: } ! 105: bputs(text[LoadedMsgPtrs]); ! 106: return; } ! 107: length=filelength(file); ! 108: for(i=0;i<cfg.total_subs;i++) { ! 109: if(length<(cfg.sub[i]->ptridx+1)*10L) { ! 110: sub_ptr[i]=sub_last[i]=0L; ! 111: sub_cfg[i]=0; ! 112: if(cfg.sub[i]->misc&SUB_NSDEF) ! 113: sub_cfg[i]|=SUB_CFG_NSCAN; ! 114: if(cfg.sub[i]->misc&SUB_SSDEF) ! 115: sub_cfg[i]|=SUB_CFG_SSCAN; ! 116: } ! 117: else { ! 118: fseek(stream,(long)cfg.sub[i]->ptridx*10L,SEEK_SET); ! 119: fread(&sub_ptr[i],4,1,stream); ! 120: fread(&sub_last[i],4,1,stream); ! 121: fread(&sub_cfg[i],2,1,stream); ! 122: } ! 123: sav_sub_ptr[i]=sub_ptr[i]; ! 124: sav_sub_last[i]=sub_last[i]; ! 125: sav_sub_cfg[i]=sub_cfg[i]; ! 126: } ! 127: fclose(stream); ! 128: bputs(text[LoadedMsgPtrs]); ! 129: } ! 130: ! 131: /****************************************************************************/ ! 132: /* Writes to DATA\USER\PTRS\xxxx.DAB the msgptr array for the current user */ ! 133: /* Called from functions main and newuser */ ! 134: /****************************************************************************/ ! 135: void sbbs_t::putmsgptrs() ! 136: { ! 137: char str[256]; ! 138: ushort idx,ch; ! 139: uint i,j; ! 140: int file; ! 141: ulong l=0L,length; ! 142: ! 143: if(!useron.number) ! 144: return; ! 145: sprintf(str,"%suser/ptrs/%4.4u.ixb", cfg.data_dir,useron.number); ! 146: if((file=nopen(str,O_WRONLY|O_CREAT))==-1) { ! 147: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT); ! 148: return; } ! 149: length=filelength(file); ! 150: for(i=0;i<cfg.total_subs;i++) { ! 151: if(sav_sub_ptr[i]==sub_ptr[i] && sav_sub_last[i]==sub_last[i] ! 152: && length>=((cfg.sub[i]->ptridx+1)*10UL) ! 153: && sav_sub_cfg[i]==sub_cfg[i]) ! 154: continue; ! 155: while(filelength(file)<(long)(cfg.sub[i]->ptridx)*10) { ! 156: lseek(file,0L,SEEK_END); ! 157: idx=tell(file)/10; ! 158: for(j=0;j<cfg.total_subs;j++) ! 159: if(cfg.sub[j]->ptridx==idx) ! 160: break; ! 161: write(file,&l,4); ! 162: write(file,&l,4); ! 163: ch=0xff; /* default to scan ON for new sub */ ! 164: if(j<cfg.total_subs) { ! 165: if(!(cfg.sub[j]->misc&SUB_NSDEF)) ! 166: ch&=~SUB_CFG_NSCAN; ! 167: if(!(cfg.sub[j]->misc&SUB_SSDEF)) ! 168: ch&=~SUB_CFG_SSCAN; ! 169: } ! 170: write(file,&ch,2); ! 171: } ! 172: lseek(file,(long)((long)(cfg.sub[i]->ptridx)*10),SEEK_SET); ! 173: write(file,&(sub_ptr[i]),4); ! 174: write(file,&(sub_last[i]),4); ! 175: write(file,&(sub_cfg[i]),2); ! 176: } ! 177: close(file); ! 178: if(!flength(str)) /* Don't leave 0 byte files */ ! 179: remove(str); ! 180: } ! 181: ! 182: /****************************************************************************/ ! 183: /* Checks for a duplicate user field starting at user record offset */ ! 184: /* 'offset', reading in 'datlen' chars, comparing to 'str' for each user */ ! 185: /* except 'usernumber' if it is non-zero. Comparison is NOT case sensitive. */ ! 186: /* 'del' is true if the search is to include deleted/inactive users */ ! 187: /* Returns the usernumber of the dupe if found, 0 if not */ ! 188: /****************************************************************************/ ! 189: uint sbbs_t::userdatdupe(uint usernumber, uint offset, uint datlen, char *dat ! 190: ,bool del) ! 191: { ! 192: bputs(text[SearchingForDupes]); ! 193: uint i=::userdatdupe(&cfg, usernumber, offset, datlen, dat, del); ! 194: bputs(text[SearchedForDupes]); ! 195: return(i); ! 196: } ! 197: ! 198:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.