|
|
1.1 root 1: /* con_hi.cpp */
2:
3: /* Synchronet hi-level console routines */
4:
5: /* $Id: con_hi.cpp,v 1.1.1.1 2000/10/10 11:23:57 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: /* Returns 1 if a is a valid ctrl-a code, 0 if it isn't. */
42: /****************************************************************************/
43: bool sbbs_t::validattr(char a)
44: {
45:
46: switch(toupper(a)) {
47: case '-': /* clear */
48: case '_': /* clear */
49: case 'B': /* blue fg */
50: case 'C': /* cyan fg */
51: case 'G': /* green fg */
52: case 'H': /* high fg */
53: case 'I': /* blink */
54: case 'K': /* black fg */
55: case 'L': /* cls */
56: case 'M': /* magenta fg */
57: case 'N': /* normal */
58: case 'P': /* pause */
59: case 'R': /* red fg */
60: case 'W': /* white fg */
61: case 'Y': /* yellow fg */
62: case '0': /* black bg */
63: case '1': /* red bg */
64: case '2': /* green bg */
65: case '3': /* brown bg */
66: case '4': /* blue bg */
67: case '5': /* magenta bg */
68: case '6': /* cyan bg */
69: case '7': /* white bg */
70: return(true); }
71: return(false);
72: }
73:
74: /****************************************************************************/
75: /* Strips invalid Ctrl-Ax sequences from str */
76: /* Returns number of ^A's in line */
77: /****************************************************************************/
78: int sbbs_t::stripattr(char *strin)
79: {
80: char str[256];
81: uint a,c,d,e;
82:
83: e=strlen(strin);
84: for(a=c=d=0;c<e && d<sizeof(str)-1;c++) {
85: if(strin[c]==1) {
86: a++;
87: if(!validattr(strin[c+1])) {
88: c++;
89: continue; } }
90: str[d++]=strin[c]; }
91: str[d]=0;
92: strcpy(strin,str);
93: return(a);
94: }
95:
96: /****************************************************************************/
97: /* Redraws str using i as current cursor position and l as length */
98: /****************************************************************************/
99: void sbbs_t::redrwstr(char *strin, int i, int l, long mode)
100: {
101: char str[256],c;
102:
103: sprintf(str,"%-*.*s",l,l,strin);
104: c=i;
105: while(c--)
106: outchar(BS);
107: if(mode&K_MSG)
108: bputs(str);
109: else
110: rputs(str);
111: if(useron.misc&ANSI) {
112: bputs("\x1b[K");
113: if(i<l)
114: bprintf("\x1b[%dD",l-i); }
115: else {
116: while(c<79) { /* clear to end of line */
117: outchar(SP);
118: c++; }
119: while(c>l) { /* back space to end of string */
120: outchar(BS);
121: c--; } }
122: }
123:
124:
125: int sbbs_t::uselect(int add, uint n, char *title, char *item, uchar *ar)
126: {
127: char str[128];
128: int i;
129: uint t,u;
130:
131: if(uselect_total>=sizeof(uselect_num)/sizeof(uselect_num[0])) /* out of bounds */
132: uselect_total=0;
133:
134: if(add) {
135: if(ar && !chk_ar(ar,&useron))
136: return(0);
137: if(!uselect_total)
138: bprintf(text[SelectItemHdr],title);
139: uselect_num[uselect_total++]=n;
140: bprintf(text[SelectItemFmt],uselect_total,item);
141: return(0); }
142:
143: if(!uselect_total)
144: return(-1);
145:
146: for(u=0;u<uselect_total;u++)
147: if(uselect_num[u]==n)
148: break;
149: if(u==uselect_total)
150: u=0;
151: sprintf(str,text[SelectItemWhich],u+1);
152: mnemonics(str);
153: i=getnum(uselect_total);
154: t=uselect_total;
155: uselect_total=0;
156: if(i<0)
157: return(-1);
158: if(!i) { /* User hit ENTER, use default */
159: for(u=0;u<t;u++)
160: if(uselect_num[u]==n)
161: return(uselect_num[u]);
162: if(n<t)
163: return(uselect_num[n]);
164: return(-1); }
165: return(uselect_num[i-1]);
166: }
167:
168: /****************************************************************************/
169: /* Prompts user for System Password. Returns 1 if user entered correct PW */
170: /****************************************************************************/
171: bool sbbs_t::chksyspass(int local)
172: {
173: char str[256],str2[256] /*,x,y,atr */;
174: int orgcon=console;
175:
176: if(online==ON_REMOTE && !(cfg.sys_misc&SM_R_SYSOP))
177: return(false);
178: if(online==ON_LOCAL) {
179: if(!(cfg.sys_misc&SM_L_SYSOP))
180: return(false);
181: if(!(cfg.node_misc&NM_SYSPW) && !(cfg.sys_misc&SM_REQ_PW))
182: return(false); }
183: bputs("SY: ");
184: console&=~(CON_R_ECHO|CON_L_ECHO);
185: getstr(str,40,K_UPPER);
186: console=orgcon;
187: if(!local)
188: CRLF;
189: if(strcmp(cfg.sys_pass,str)) {
190: sprintf(str2,"%s #%u System password attempt: '%s'"
191: ,useron.alias,useron.number,str);
192: logline("S!",str2);
193: return(false); }
194: return(true);
195: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.