Annotation of sbbs/sbbs3/answer.cpp, revision 1.1.1.1

1.1       root        1: /* answer.cpp */
                      2: 
                      3: /* Synchronet answer "caller" function */
                      4: 
                      5: /* $Id: answer.cpp,v 1.7 2000/12/11 23:21:11 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: #include "telnet.h"
                     40: 
                     41: bool sbbs_t::answer()
                     42: {
                     43:        char    str[256],str2[256],c;
                     44:        char    tmp[512];
                     45:        int             i,l,in;
                     46:        struct tm * tm;
                     47:        struct in_addr addr;
                     48: 
                     49:        useron.number=0;
                     50:        answertime=logontime=starttime=now=time(NULL);
                     51:        /* Caller ID is IP address */
                     52:        addr.s_addr=client_addr;
                     53:        strcpy(cid,inet_ntoa(addr)); 
                     54:        
                     55:     tm=localtime(&now); 
                     56:        if(tm==NULL)
                     57:                return(false);
                     58: 
                     59:        sprintf(str,"%02d:%02d%c  %s %s %02d %u            Node %3u"
                     60:         ,tm->tm_hour>12 ? tm->tm_hour-12 : tm->tm_hour==0 ? 12 : tm->tm_hour
                     61:                ,tm->tm_min,tm->tm_hour>=12 ? 'p' : 'a',wday[tm->tm_wday]
                     62:         ,mon[tm->tm_mon],tm->tm_mday,tm->tm_year+1900,cfg.node_num);
                     63:        logline("@ ",str);
                     64: 
                     65:        sprintf(str,"%s  %s [%s]", connection, client_name, cid);
                     66:        logline("@+:",str);
                     67: 
                     68:        online=ON_REMOTE;
                     69: 
                     70:        rlogin_name[0]=0;
                     71:        if(sys_status&SS_RLOGIN) {
                     72:                mswait(1000);   /* Give input_thread time to start */
                     73:                if(incom()==0) {
                     74:                        for(i=0;i<LEN_ALIAS;i++) {
                     75:                                in=incom();
                     76:                                if(in==0 || in==NOINP)
                     77:                                        break;
                     78:                                str[i]=in;
                     79:                        }
                     80:                        str[i]=0;
                     81:                        for(i=0;i<LEN_ALIAS;i++) {
                     82:                                in=incom();
                     83:                                if(in==0 || in==NOINP)
                     84:                                        break;
                     85:                                str2[i]=in;
                     86:                        }
                     87:                        str2[i]=0;
                     88:                        lprintf("Node %d RLogin: '%s' / '%s'",cfg.node_num,str,str2);
                     89:                        strcpy(rlogin_name
                     90:                                ,cfg.startup->options&BBS_OPT_USE_2ND_RLOGIN ? str2 : str);
                     91:                        useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0);
                     92:                        if(useron.number)
                     93:                                getuserdat(&cfg,&useron);
                     94:                }
                     95:        }
                     96:        if(rlogin_name[0]==0)
                     97:                sys_status&=~SS_RLOGIN;
                     98: 
                     99:        /* Detect terminal type */
                    100:     mswait(200);
                    101:        rioctl(IOFI);           /* flush input buffer */
                    102:        putcom( "\r\n"          /* locate cursor at column 1 */
                    103:                "\x1b[99B"      /* locate cursor as far down as possible */
                    104:                        "\x1b[6n"       /* Get cursor position */
                    105:                        "\x1b[!_"       /* RIP? */
                    106:                        "\x1b[0t_"      /* WIP? */
                    107:                        "\x1b[0m_"      /* "Normal" colors */
                    108:                        "\x1b[2J"       /* clear screen */
                    109:                        "\x1b[H"        /* home cursor */
                    110:                        "\xC"           /* clear screen (in case not ANSI) */
                    111:                        "\r"            /* Move cursor left (in case previous char printed) */
                    112:                        );
                    113:        i=l=0;
                    114:        tos=1;
                    115:        strcpy(str,VERSION_NOTICE);
                    116:        strcat(str,COPYRIGHT_NOTICE);
                    117:        center(str);
                    118:        while(i++<50 && l<sizeof(str)-1) {      /* wait up to 5 seconds for response */
                    119:                c=(incom()&0x7f);
                    120:                if(!c) {
                    121:                        mswait(100);
                    122:                        continue;
                    123:                }
                    124:                i=0;
                    125:                if(l==0 && c!=ESC)      // response must begin with escape char
                    126:                        continue;
                    127:                str[l++]=c;
                    128:                if(c=='R') {   /* break immediately if response */
                    129:                        mswait(100);
                    130:                        break; 
                    131:                }
                    132:        }
                    133: 
                    134:        if(rioctl(RXBC))        /* wait a bit for extra RIP reply chars */
                    135:                mswait(500);
                    136:  
                    137:        while((c=(incom()&0x7f))!=0 && l<sizeof(str)-1)
                    138:                str[l++]=c;
                    139:        str[l]=0;
                    140: 
                    141:     if(l) {
                    142:         if(str[0]==ESC && str[1]=='[') {
                    143:                        autoterm|=(ANSI|COLOR);
                    144:             rows=((str[2]&0xf)*10)+(str[3]&0xf);
                    145:                        if(rows<10 || rows>99) rows=24; }
                    146:                truncsp(str);
                    147:                if(strstr(str,"RIPSCRIP")) {
                    148:                        logline("@R",strstr(str,"RIPSCRIP"));
                    149:                        autoterm|=(RIP|COLOR|ANSI); }
                    150:                else if(strstr(str,"DC-TERM")
                    151:                        && toupper(*(strstr(str,"DC-TERM")+12))=='W') {
                    152:                        logline("@W",strstr(str,"DC-TERM"));
                    153:                        autoterm|=(WIP|COLOR|ANSI); } }
                    154:        rioctl(IOFI); /* flush left-over or late response chars */
                    155: 
                    156:        if(!autoterm && str[0]) {
                    157:                lputs("Terminal Auto-detect failed, Response: ");
                    158:         str2[0]=0;
                    159:                for(i=0;str[i];i++) {
                    160:                if(str[i]>=' ' && str[i]<='~')
                    161:                sprintf(tmp,"%c", str[i]);
                    162:             else
                    163:                                sprintf(tmp,"<%02X>", (uchar)str[i]);
                    164:             strcat(str2,tmp);
                    165:         }
                    166:         lputs(str2);
                    167:        }
                    168: 
                    169:        if(!(sys_status&SS_RLOGIN)) {
                    170:                /* Disable Telnet Terminal Echo */
                    171:                sprintf(str,"%c%c%c",TELNET_IAC,TELNET_WILL,TELNET_ECHO);
                    172:                putcom(str,3);
                    173:                /* Will supress Go Ahead */
                    174:                sprintf(str,"%c%c%c",TELNET_IAC,TELNET_WILL,TELNET_SUP_GA);
                    175:                putcom(str,3);
                    176:        }
                    177: 
                    178:        /* AutoLogon via IP or Caller ID here */
                    179:        if(!useron.number && !(sys_status&SS_RLOGIN)
                    180:                && cfg.startup->options&BBS_OPT_AUTO_LOGON && cid[0]) {
                    181:                useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid, 0);
                    182:                if(useron.number) {
                    183:                        getuserdat(&cfg, &useron);
                    184:                        if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V')))
                    185:                                useron.number=0;
                    186:                }
                    187:        }
                    188: 
                    189:        if(!online) 
                    190:                return(false); 
                    191: 
                    192:        useron.misc&=~(ANSI|COLOR|RIP|WIP);
                    193:        useron.misc|=autoterm;
                    194:        sprintf(useron.comp, "%.*s", sizeof(useron.comp)-1, client_name);
                    195: 
                    196:        if(!useron.number && sys_status&SS_RLOGIN) {
                    197:                CRLF;
                    198:                newuser();
                    199:        }
                    200: 
                    201:        if(!useron.number) {    /* manual/regular logon */
                    202: 
                    203:                /* Display ANSWER screen */
                    204:                sprintf(str,"%sanswer",cfg.text_dir);
                    205:                sprintf(tmp,"%s.%s",str,autoterm&WIP ? "wip":"rip");
                    206:                sprintf(str2,"%s.ans",str);
                    207:                if(autoterm&(RIP|WIP) && fexist(tmp))
                    208:                        strcat(str,autoterm&WIP ? ".wip":".rip");
                    209:                else if(autoterm&ANSI && fexist(str2))
                    210:                        strcat(str,".ans");
                    211:                else
                    212:                        strcat(str,".asc");
                    213:                rioctl(IOSM|PAUSE);
                    214:                sys_status|=SS_PAUSEON;
                    215:                printfile(str,P_NOABORT);
                    216:                sys_status&=~SS_PAUSEON;
                    217:                exec_bin(cfg.login_mod,&main_csi);
                    218:        } else  /* auto logon here */
                    219:                if(logon()==false)
                    220:                        return(false);
                    221: 
                    222: 
                    223:        if(!useron.number)
                    224:                hangup();
                    225:        if(!online) 
                    226:                return(false); 
                    227: 
                    228:        /* Save the IP to the user's note */
                    229:        if(cid[0]) {
                    230:                sprintf(useron.note, "%.*s", sizeof(useron.note)-1, cid);
                    231:                putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note);
                    232:        }
                    233: 
                    234:        /* Save host name to the user's computer description */
                    235:        if(client_name[0]) {
                    236:                sprintf(useron.comp, "%.*s", sizeof(useron.comp)-1, client_name);
                    237:                putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp);
                    238:        }
                    239: 
                    240:        if(!(sys_status&SS_USERON)) {
                    241:                errormsg(WHERE,ERR_CHK,"User not logged on",0);
                    242:                hangup();
                    243:                return(false); }
                    244: 
                    245:        return(true);
                    246: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.