|
|
1.1 root 1: #line 1 "MAIN.C"
2:
3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
4:
5: /*********************************************************/
6: /* Entry point to the BBS and the waitforcall() function */
7: /*********************************************************/
8:
9: #include "sbbs.h"
10: #include "cmdshell.h"
11:
12: csi_t main_csi;
13: uint curshell=0;
14:
15: char onquiet=0,qwklogon;
16: char term_ret=0;
17: ulong connect_rate=0; /* already connected at xbps */
18:
19: #if __OS2__
20: void cbreakh(int sig) /* Ctrl-C */
21: {
22: sys_status|=SS_ABORT;
23: signal(sig,cbreakh);
24: }
25:
26: #else
27:
28: int cbreakh() /* ctrl-break handler */
29: {
30: sys_status|=SS_ABORT;
31: return(1); /* 1 to continue, 0 to abort */
32: }
33: #endif
34:
35: /****************************************************************************/
36: /* This is the entry point to the BBS from dos */
37: /* No arguments are defined as of yet. */
38: /****************************************************************************/
39: main(int argc, char *argv[])
40: {
41: char str[256];
42: int i,j,file,twenty;
43: node_t node;
44:
45: startup(argc,argv); /* startup code overlaid */
46:
47: while(1) {
48:
49: while(1) {
50: qwklogon=0;
51: twenty=0;
52:
53: /* Reset TEXT.DAT */
54:
55: for(i=0;i<TOTAL_TEXT;i++)
56: if(text[i]!=text_sav[i]) {
57: if(text[i]!=nulstr)
58: FREE(text[i]);
59: text[i]=text_sav[i]; }
60:
61: /* Reset COMMAND SHELL */
62:
63: if(main_csi.cs)
64: FREE(main_csi.cs);
65: if(main_csi.str)
66: FREE(main_csi.str);
67: freevars(&main_csi);
68: memset(&main_csi,0,sizeof(csi_t));
69: main_csi.str=MALLOC(1024);
70: if(!main_csi.str) {
71: errormsg(WHERE,ERR_ALLOC,"command shell",1024);
72: bail(1); }
73: memset(main_csi.str,0,1024);
74: menu_dir[0]=0;
75: twenty+=10;
76:
77: /* Reset Global Variables */
78:
79: if(global_str_var)
80: for(i=0;i<global_str_vars;i++)
81: if(global_str_var[i]) {
82: FREE(global_str_var[i]);
83: global_str_var[i]=0; }
84: if(global_str_var) {
85: FREE(global_str_var);
86: global_str_var=0; }
87: if(global_str_var_name) {
88: FREE(global_str_var_name);
89: global_str_var_name=0; }
90: global_str_vars=0;
91: if(global_int_var) {
92: FREE(global_int_var);
93: global_int_var=0; }
94: if(global_int_var_name) {
95: FREE(global_int_var_name);
96: global_int_var_name=0; }
97: global_int_vars=0;
98: twenty*=2;
99:
100: if(waitforcall()) /* Got caller/logon */
101: break; }
102:
103: if(qwklogon) {
104: getsmsg(useron.number);
105: qwk_sec();
106: hangup();
107: logout();
108: continue; }
109:
110: while(useron.number && (main_csi.misc&CS_OFFLINE_EXEC || online)) {
111:
112: if(!main_csi.cs || curshell!=useron.shell) {
113: if(useron.shell>=total_shells)
114: useron.shell=0;
115: sprintf(str,"%s%s.BIN",exec_dir,shell[useron.shell]->code);
116: if((file=nopen(str,O_RDONLY|O_BINARY))==-1) {
117: errormsg(WHERE,ERR_OPEN,str,O_RDONLY|O_BINARY);
118: hangup();
119: break; }
120: if(main_csi.cs)
121: FREE(main_csi.cs);
122: freevars(&main_csi);
123: clearvars(&main_csi);
124:
125: main_csi.length=filelength(file);
126: if((main_csi.cs=(uchar *)MALLOC(main_csi.length))==NULL) {
127: close(file);
128: errormsg(WHERE,ERR_ALLOC,str,main_csi.length);
129: hangup();
130: break; }
131:
132: if(lread(file,main_csi.cs,main_csi.length)!=main_csi.length) {
133: errormsg(WHERE,ERR_READ,str,main_csi.length);
134: close(file);
135: FREE(main_csi.cs);
136: main_csi.cs=NULL;
137: hangup();
138: break; }
139: close(file);
140:
141: main_csi.ip=main_csi.cs;
142: curshell=useron.shell;
143: menu_dir[0]=0;
144: menu_file[0]=0;
145: #ifdef __MSDOS__
146: freedosmem=farcoreleft();
147: #endif
148: }
149: if(exec(&main_csi))
150: break;
151:
152: if(!(main_csi.misc&CS_OFFLINE_EXEC))
153: checkline();
154:
155: #if 0
156: if(freedosmem!=farcoreleft()) {
157: if(freedosmem>farcoreleft())
158: errormsg(WHERE,ERR_CHK,"memory",freedosmem-farcoreleft());
159: freedosmem=farcoreleft(); }
160: #endif
161: }
162: logout();
163: catsyslog(0);
164: if(!REALSYSOP || sys_misc&SM_SYSSTAT)
165: logoffstats(); /* Updates both system and node dsts.dab files */
166: if(qoc) {
167: while(!wfc_events(time(NULL)))
168: ;
169: catsyslog(0);
170: if(qoc==1)
171: offhook();
172: lclini(node_scrnlen);
173: lputc(FF);
174: bail(0); }
175: }
176: }
177:
178: /************************************/
179: /* encrypted string output function */
180: /************************************/
181: char *decrypt(ulong l[], char *instr)
182: {
183: static char str[128];
184: uchar ch,bits,len;
185: ushort i,j,lc=0;
186:
187: len=(uchar)(l[0]&0x7f)^0x49;
188: bits=7;
189: for(i=0,j=0;i<len;i++) {
190: ch=(char)((l[j]>>bits)&0x7fL);
191: ch^=(i^0x2c);
192: str[lc++]=ch;
193: bits+=7;
194: if(bits>=26 && i+1<len) {
195: if(bits==32)
196: ch=0;
197: else
198: ch=(char)((l[j]>>bits)&0x7fL);
199: bits=(32-bits);
200: j++;
201: ch|=((l[j]&0x7f)<<(bits))&0x7f;
202: i++;
203: ch^=(i^0x2c);
204: bits=7-bits;
205: str[lc++]=ch; } }
206: str[lc]=0;
207: if(instr) {
208: strcpy(instr,str);
209: return(instr); }
210: else
211: return(str);
212: }
213:
214: /****************************************************************************/
215: /* Writes NODE.LOG at end of SYSTEM.LOG */
216: /****************************************************************************/
217: void catsyslog(int crash)
218: {
219: char str[256];
220: char HUGE16 *buf;
221: int i,file;
222: ulong length;
223:
224: if(sys_status&SS_LOGOPEN) {
225: if(close(logfile)) {
226: errormsg(WHERE,ERR_CLOSE,"logfile",0);
227: return; }
228: sys_status&=~SS_LOGOPEN; }
229: sprintf(str,"%sNODE.LOG",node_dir);
230: if((file=nopen(str,O_RDONLY))==-1) {
231: errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
232: return; }
233: length=filelength(file);
234: if(length) {
235: if((buf=(char HUGE16 *)LMALLOC(length))==NULL) {
236: close(file);
237: errormsg(WHERE,ERR_ALLOC,str,length);
238: return; }
239: if(lread(file,buf,length)!=length) {
240: close(file);
241: errormsg(WHERE,ERR_READ,str,length);
242: FREE((char *)buf);
243: return; }
244: close(file);
245: now=time(NULL);
246: unixtodos(now,&date,&curtime);
247: sprintf(str,"%sLOGS\\%2.2d%2.2d%2.2d.LOG",data_dir,date.da_mon,date.da_day
1.1.1.2 ! root 248: ,TM_YEAR(date.da_year-1900));
1.1 root 249: if((file=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
250: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
251: FREE((char *)buf);
252: return; }
253: if(lwrite(file,buf,length)!=length) {
254: close(file);
255: errormsg(WHERE,ERR_WRITE,str,length);
256: FREE((char *)buf);
257: return; }
258: close(file);
259: if(crash) {
260: for(i=0;i<2;i++) {
261: sprintf(str,"%sCRASH.LOG",i ? data_dir : node_dir);
262: if((file=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
263: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
264: FREE((char *)buf);
265: return; }
266: if(lwrite(file,buf,length)!=length) {
267: close(file);
268: errormsg(WHERE,ERR_WRITE,str,length);
269: FREE((char *)buf);
270: return; }
271: close(file); } }
272: FREE((char *)buf); }
273: else
274: close(file);
275: sprintf(str,"%sNODE.LOG",node_dir);
276: if((logfile=nopen(str,O_WRONLY|O_TRUNC))==-1) /* Truncate NODE.LOG */
277: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_TRUNC);
278: else sys_status|=SS_LOGOPEN;
279: }
280:
281: void quicklogonstuff()
282: {
283: int i;
284: node_t node;
285:
286: reset_logon_vars();
287:
288: lclini(node_scrnlen-1);
289: if(com_port && !DCDHIGH) /* don't take phone offhook if */
290: offhook(); /* connected */
291: useron.number=1;
292: getuserdat(&useron);
293: autoterm=ANSI;
294: if(!useron.number)
295: useron.level=99;
296: console=CON_L_ECHO|CON_L_INPUT;
297: online=ON_LOCAL;
298: statline=sys_def_stat;
299: statusline();
300: answertime=logontime=time(NULL);
301: sprintf(connection,"%.*s",LEN_MODEM,text[Locally]);
302: cur_rate=14400;
303: cur_cps=1750;
304: sys_status|=SS_USERON;
305: }
306:
307:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.