Annotation of sbbs/sbbs3/ctrl/mainformunit.cpp, revision 1.1.1.1

1.1       root        1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
                      2: 
                      3: /* $Id: MainFormUnit.cpp,v 1.15 2000/12/06 03:10:08 rswindell Exp $ */
                      4: 
                      5: /****************************************************************************
                      6:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      7:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                      8:  *                                                                                                                                                     *
                      9:  * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html         *
                     10:  *                                                                                                                                                     *
                     11:  * This program is free software; you can redistribute it and/or                       *
                     12:  * modify it under the terms of the GNU General Public License                         *
                     13:  * as published by the Free Software Foundation; either version 2                      *
                     14:  * of the License, or (at your option) any later version.                                      *
                     15:  * See the GNU General Public License for more details: gpl.txt or                     *
                     16:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     17:  *                                                                                                                                                     *
                     18:  * Anonymous FTP access to the most recent released source is available at     *
                     19:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     20:  *                                                                                                                                                     *
                     21:  * Anonymous CVS access to the development source and modification history     *
                     22:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     23:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     24:  *     (just hit return, no password is necessary)                                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     26:  *                                                                                                                                                     *
                     27:  * For Synchronet coding style and modification guidelines, see                                *
                     28:  * http://www.synchro.net/source.html                                                                          *
                     29:  *                                                                                                                                                     *
                     30:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     31:  * format) via e-mail to [email protected]                                                                      *
                     32:  *                                                                                                                                                     *
                     33:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     34:  ****************************************************************************/
                     35: 
                     36: //---------------------------------------------------------------------------
                     37: #include <vcl.h>
                     38: #include <vcl\Registry.hpp>    /* TRegistry */
                     39: #pragma hdrstop
                     40: #include <winsock.h>           // IPPORT_TELNET, INADDR_ANY
                     41: #include <process.h>           // _beginthread()
                     42: #include <io.h>
                     43: #include <stdio.h>
                     44: #include <sys\stat.h>
                     45: #include <sys\locking.h>
                     46: #include <fcntl.h>
                     47: #include <share.h>
                     48: 
                     49: #include "MainFormUnit.h"
                     50: #include "TelnetFormUnit.h"
                     51: #include "FtpFormUnit.h"
                     52: #include "MailFormUnit.h"
                     53: #include "NodeFormUnit.h"
                     54: #include "StatsFormUnit.h"
                     55: #include "ClientFormUnit.h"
                     56: #include "CtrlPathDialogUnit.h"
                     57: #include "TelnetCfgDlgUnit.h"
                     58: #include "MailCfgDlgUnit.h"
                     59: #include "FtpCfgDlgUnit.h"
                     60: #include "AboutBoxFormUnit.h"
                     61: #include "CodeInputFormUnit.h"
                     62: #include "TextFileEditUnit.h"
                     63: #include "UserListFormUnit.h"
                     64: 
                     65: #include "sbbs.h"           // unixtodstr()
                     66: #include "userdat.h"           // lastuser()
                     67: 
                     68: //---------------------------------------------------------------------------
                     69: #pragma package(smart_init)
                     70: #pragma resource "*.dfm"
                     71: TMainForm *MainForm;
                     72: 
                     73: extern "C" __declspec(dllimport) BOOL __stdcall load_cfg(scfg_t* cfg, char* text[]);
                     74: extern "C" __declspec(dllimport) BOOL __stdcall getstats(scfg_t* cfg, char node, stats_t* stats);
                     75: extern "C" __declspec(dllimport) int  __stdcall getmail(scfg_t* cfg, int usernumber, BOOL sent);
                     76: #define MAX_LOGLEN 20000
                     77: 
                     78: #define LOG_TIME_FMT "  m/d  hh:mm:ssa/p"
                     79: 
                     80: int threads=1;
                     81: 
                     82: static void thread_up(BOOL up)
                     83: {
                     84:        char str[128];
                     85:        static HANDLE mutex;
                     86: 
                     87:     if(!mutex)
                     88:        mutex=CreateMutex(NULL,false,NULL);
                     89:        WaitForSingleObject(mutex,INFINITE);
                     90:     if(up)
                     91:            threads++;
                     92:     else if(threads>0)
                     93:        threads--;
                     94:     sprintf(str,"Threads: %d",threads);
                     95:     AnsiString Str=AnsiString(str);
                     96:     if(MainForm->StatusBar->Panels->Items[0]->Text!=Str)
                     97:                MainForm->StatusBar->Panels->Items[0]->Text=Str;
                     98:     ReleaseMutex(mutex);
                     99: }
                    100: 
                    101: int sockets=0;
                    102: 
                    103: void socket_open(BOOL open)
                    104: {
                    105:        char    str[128];
                    106:        static HANDLE mutex;
                    107: 
                    108:     if(!mutex)
                    109:        mutex=CreateMutex(NULL,false,NULL);
                    110:        WaitForSingleObject(mutex,INFINITE);
                    111:     if(open)
                    112:            sockets++;
                    113:     else if(sockets>0)
                    114:        sockets--;
                    115:     sprintf(str,"Sockets: %d",sockets);
                    116:     AnsiString Str=AnsiString(str);
                    117:     if(MainForm->StatusBar->Panels->Items[1]->Text!=Str)
                    118:                MainForm->StatusBar->Panels->Items[1]->Text=Str;
                    119:     ReleaseMutex(mutex);
                    120: }
                    121: 
                    122: int clients=0;
                    123: int total_clients=0;
                    124: 
                    125: static void client_add(BOOL add)
                    126: {
                    127:        char    str[128];
                    128:        static  HANDLE mutex;
                    129: 
                    130:     if(!mutex)
                    131:        mutex=CreateMutex(NULL,false,NULL);
                    132:        WaitForSingleObject(mutex,INFINITE);
                    133:     if(add) {
                    134:            clients++;
                    135:         total_clients++;
                    136:     } else if(clients>0)
                    137:        clients--;
                    138:     sprintf(str,"Clients: %d",clients);
                    139:     AnsiString Str=AnsiString(str);
                    140:     if(MainForm->StatusBar->Panels->Items[2]->Text!=Str)
                    141:                MainForm->StatusBar->Panels->Items[2]->Text=Str;
                    142: 
                    143:     sprintf(str,"Served: %d",total_clients);
                    144:     Str=AnsiString(str);
                    145:     if(MainForm->StatusBar->Panels->Items[3]->Text!=Str)
                    146:                MainForm->StatusBar->Panels->Items[3]->Text=Str;
                    147:     ReleaseMutex(mutex);
                    148: }
                    149: 
                    150: static void client_on(BOOL on, int sock, client_t* client)
                    151: {
                    152:     char    str[128];
                    153:     int     i,j;
                    154:     time_t  t;
                    155:        static  HANDLE mutex;
                    156:     TListItem*  Item;
                    157: 
                    158:     if(!mutex)
                    159:        mutex=CreateMutex(NULL,false,NULL);
                    160:        WaitForSingleObject(mutex,INFINITE);
                    161:     WaitForSingleObject(ClientForm->ListMutex,INFINITE);
                    162: 
                    163:     /* Search for exising entry for this socket */
                    164:     for(i=0;i<ClientForm->ListView->Items->Count;i++) {
                    165:         if(ClientForm->ListView->Items->Item[i]->Caption.ToIntDef(0)==sock)
                    166:             break;
                    167:     }
                    168:     if(i>=ClientForm->ListView->Items->Count)
                    169:         i=-1;
                    170: 
                    171:     if(on==FALSE) { // Off
                    172:         if(i>=0)
                    173:             ClientForm->ListView->Items->Delete(i);
                    174:         ReleaseMutex(mutex);
                    175:         ReleaseMutex(ClientForm->ListMutex);
                    176:         return;
                    177:     }
                    178:     if(client!=NULL && client->size==sizeof(client_t)) {
                    179:         if(i>=0) {
                    180:             Item=ClientForm->ListView->Items->Item[i];
                    181:         } else {
                    182:             Item=ClientForm->ListView->Items->Add();
                    183:             Item->Data=(void*)client->time;
                    184:             Item->Caption=sock;
                    185:         }
                    186:         Item->SubItems->Clear();
                    187:         Item->SubItems->Add(client->protocol);
                    188:         Item->SubItems->Add(client->user);
                    189:         Item->SubItems->Add(client->addr);
                    190:         Item->SubItems->Add(client->host);
                    191:         Item->SubItems->Add(client->port);
                    192:         t=time(NULL)-(time_t)Item->Data;
                    193:         sprintf(str,"%d:%02d",t/60,t%60);
                    194:         Item->SubItems->Add(str);
                    195:     }
                    196:     ReleaseMutex(mutex);
                    197:     ReleaseMutex(ClientForm->ListMutex);
                    198: }
                    199: 
                    200: static int bbs_lputs(char *str)
                    201: {
                    202:        static HANDLE mutex;
                    203: 
                    204:     if(!mutex)
                    205:        mutex=CreateMutex(NULL,false,NULL);
                    206:        WaitForSingleObject(mutex,INFINITE);
                    207: 
                    208:     while(TelnetForm->Log->Text.Length()>=MAX_LOGLEN)
                    209:         TelnetForm->Log->Lines->Delete(0);
                    210: 
                    211:     AnsiString Line=Now().FormatString(LOG_TIME_FMT)+"  ";
                    212:     Line+=AnsiString(str).Trim();
                    213:        TelnetForm->Log->Lines->Add(Line);
                    214:     ReleaseMutex(mutex);
                    215:     return(Line.Length());
                    216: }
                    217: 
                    218: static void bbs_status(char *str)
                    219: {
                    220:        static HANDLE mutex;
                    221: 
                    222:     if(!mutex)
                    223:        mutex=CreateMutex(NULL,false,NULL);
                    224:        WaitForSingleObject(mutex,INFINITE);
                    225: 
                    226:        TelnetForm->Status->Caption=AnsiString(str);
                    227: 
                    228:     ReleaseMutex(mutex);
                    229: }
                    230: 
                    231: static void bbs_clients(int clients)
                    232: {
                    233:        static HANDLE mutex;
                    234:     static save_clients;
                    235: 
                    236:     if(clients>save_clients)
                    237:         client_add(TRUE);
                    238:     else if(clients<save_clients)
                    239:         client_add(FALSE);
                    240:     save_clients=clients;
                    241: 
                    242:     if(!mutex)
                    243:        mutex=CreateMutex(NULL,false,NULL);
                    244:        WaitForSingleObject(mutex,INFINITE);
                    245: 
                    246:     TelnetForm->ProgressBar->Max
                    247:        =(MainForm->bbs_startup.last_node
                    248:            -MainForm->bbs_startup.first_node)+1;
                    249:        TelnetForm->ProgressBar->Position=clients;
                    250: 
                    251:     ReleaseMutex(mutex);
                    252: }
                    253: 
                    254: static void bbs_terminated(int code)
                    255: {
                    256:        Screen->Cursor=crDefault;
                    257:        MainForm->TelnetStart->Enabled=true;
                    258:        MainForm->TelnetStop->Enabled=false;
                    259: }
                    260: static void bbs_started(void)
                    261: {
                    262:        Screen->Cursor=crDefault;
                    263:        MainForm->TelnetStart->Enabled=false;
                    264:     MainForm->TelnetStop->Enabled=true;
                    265: }
                    266: static void bbs_start(void)
                    267: {
                    268:        Screen->Cursor=crAppStart;
                    269:     bbs_status("Starting");
                    270:     strcpy(MainForm->bbs_startup.ctrl_dir,MainForm->CtrlDirectory.c_str());
                    271:        _beginthread((void(*)(void*))bbs_thread,0,&MainForm->bbs_startup);
                    272: }
                    273: 
                    274: static int mail_lputs(char *str)
                    275: {
                    276:        static HANDLE mutex;
                    277:        static FILE* LogStream;
                    278: 
                    279:     if(!mutex)
                    280:        mutex=CreateMutex(NULL,false,NULL);
                    281:        WaitForSingleObject(mutex,INFINITE);
                    282: 
                    283:     if(str==NULL) {
                    284:         if(LogStream!=NULL)
                    285:             fclose(LogStream);
                    286:         LogStream=NULL;
                    287:         ReleaseMutex(mutex);
                    288:         return(0);
                    289:     }
                    290: 
                    291:     while(MailForm->Log->Text.Length()>=MAX_LOGLEN)
                    292:         MailForm->Log->Lines->Delete(0);
                    293: 
                    294:     AnsiString Line=Now().FormatString(LOG_TIME_FMT)+"  ";
                    295:     Line+=AnsiString(str).Trim();
                    296:        MailForm->Log->Lines->Add(Line);
                    297: 
                    298:     if(MainForm->MailLogFile && MainForm->MailStop->Enabled) {
                    299:         AnsiString LogFileName
                    300:             =AnsiString(MainForm->cfg.data_dir)
                    301:             +"LOGS\\MS"
                    302:             +Now().FormatString("mmddyy")
                    303:             +".LOG";
                    304: 
                    305:         if(!FileExists(LogFileName)) {
                    306:             if(LogStream!=NULL) {
                    307:                fclose(LogStream);
                    308:                 LogStream=NULL;
                    309:             }
                    310:         }
                    311:         if(LogStream==NULL)
                    312:             LogStream=fopen(LogFileName.c_str(),"a");
                    313: 
                    314:         if(LogStream!=NULL) {
                    315:                        Line=Now().FormatString("hh:mm:ss")+"  ";
                    316:                    Line+=AnsiString(str).Trim();
                    317:                Line+="\n";
                    318:                fwrite(AnsiString(Line).c_str(),1,Line.Length(),LogStream);
                    319:         }
                    320:        }
                    321: 
                    322:     ReleaseMutex(mutex);
                    323:     return(Line.Length());
                    324: }
                    325: 
                    326: static void mail_status(char *str)
                    327: {
                    328:        static HANDLE mutex;
                    329: 
                    330:     if(!mutex)
                    331:        mutex=CreateMutex(NULL,false,NULL);
                    332:        WaitForSingleObject(mutex,INFINITE);
                    333: 
                    334:        MailForm->Status->Caption=AnsiString(str);
                    335: 
                    336:     ReleaseMutex(mutex);
                    337: }
                    338: 
                    339: static void mail_clients(int clients)
                    340: {
                    341:        static HANDLE mutex;
                    342:     static save_clients;
                    343: 
                    344:     if(clients>save_clients)
                    345:         client_add(TRUE);
                    346:     else if(clients<save_clients)
                    347:         client_add(FALSE);
                    348:     save_clients=clients;
                    349: 
                    350:     if(!mutex)
                    351:        mutex=CreateMutex(NULL,false,NULL);
                    352:        WaitForSingleObject(mutex,INFINITE);
                    353: 
                    354:     MailForm->ProgressBar->Max=MainForm->mail_startup.max_clients;
                    355:        MailForm->ProgressBar->Position=clients;
                    356: 
                    357:     ReleaseMutex(mutex);
                    358: }
                    359: 
                    360: static void mail_terminated(int code)
                    361: {
                    362:        Screen->Cursor=crDefault;
                    363:        MainForm->MailStart->Enabled=true;
                    364:        MainForm->MailStop->Enabled=false;
                    365: }
                    366: static void mail_started(void)
                    367: {
                    368:        Screen->Cursor=crDefault;
                    369:        MainForm->MailStart->Enabled=false;
                    370:     MainForm->MailStop->Enabled=true;
                    371: }
                    372: static void mail_start(void)
                    373: {
                    374:        Screen->Cursor=crAppStart;
                    375:     mail_status("Starting");
                    376:     strcpy(MainForm->mail_startup.ctrl_dir,MainForm->CtrlDirectory.c_str());
                    377:        _beginthread((void(*)(void*))mail_server,0,&MainForm->mail_startup);
                    378: }
                    379: 
                    380: static int ftp_lputs(char *str)
                    381: {
                    382:        static HANDLE mutex;
                    383:        static FILE* LogStream;
                    384: 
                    385:     if(!mutex)
                    386:        mutex=CreateMutex(NULL,false,NULL);
                    387:        WaitForSingleObject(mutex,INFINITE);
                    388: 
                    389:     if(str==NULL) {
                    390:         if(LogStream!=NULL)
                    391:             fclose(LogStream);
                    392:         LogStream=NULL;
                    393:         ReleaseMutex(mutex);
                    394:         return(0);
                    395:     }
                    396: 
                    397:     while(FtpForm->Log->Text.Length()>=MAX_LOGLEN)
                    398:         FtpForm->Log->Lines->Delete(0);
                    399: 
                    400:     AnsiString Line=Now().FormatString(LOG_TIME_FMT)+"  ";
                    401:     Line+=AnsiString(str).Trim();
                    402:        FtpForm->Log->Lines->Add(Line);
                    403: 
                    404:     if(MainForm->FtpLogFile && MainForm->FtpStop->Enabled) {
                    405:         AnsiString LogFileName
                    406:             =AnsiString(MainForm->cfg.data_dir)
                    407:             +"LOGS\\FS"
                    408:             +Now().FormatString("mmddyy")
                    409:             +".LOG";
                    410: 
                    411:         if(!FileExists(LogFileName)) {
                    412:             FileClose(FileCreate(LogFileName));
                    413:             if(LogStream!=NULL) {
                    414:                 fclose(LogStream);
                    415:                 LogStream=NULL;
                    416:             }
                    417:         }
                    418:         if(LogStream==NULL)
                    419:             LogStream=fopen(LogFileName.c_str(),"a");
                    420: 
                    421:         if(LogStream!=NULL) {
                    422:             Line=Now().FormatString("hh:mm:ss")+"  ";
                    423:             Line+=AnsiString(str).Trim();
                    424:             Line+="\n";
                    425:                fwrite(AnsiString(Line).c_str(),1,Line.Length(),LogStream);
                    426:         }
                    427:        }
                    428: 
                    429:     ReleaseMutex(mutex);
                    430:     return(Line.Length());
                    431: }
                    432: 
                    433: static void ftp_status(char *str)
                    434: {
                    435:        static HANDLE mutex;
                    436: 
                    437:     if(!mutex)
                    438:        mutex=CreateMutex(NULL,false,NULL);
                    439:        WaitForSingleObject(mutex,INFINITE);
                    440: 
                    441:        FtpForm->Status->Caption=AnsiString(str);
                    442: 
                    443:     ReleaseMutex(mutex);
                    444: }
                    445: 
                    446: static void ftp_clients(int clients)
                    447: {
                    448:        static HANDLE mutex;
                    449:     static save_clients;
                    450: 
                    451:     if(clients>save_clients)
                    452:         client_add(TRUE);
                    453:     else if(clients<save_clients)
                    454:         client_add(FALSE);
                    455:     save_clients=clients;
                    456: 
                    457:     if(!mutex)
                    458:        mutex=CreateMutex(NULL,false,NULL);
                    459:        WaitForSingleObject(mutex,INFINITE);
                    460: 
                    461:     FtpForm->ProgressBar->Max=MainForm->ftp_startup.max_clients;
                    462:        FtpForm->ProgressBar->Position=clients;
                    463: 
                    464:     ReleaseMutex(mutex);
                    465: }
                    466: 
                    467: static void ftp_terminated(int code)
                    468: {
                    469:        Screen->Cursor=crDefault;
                    470:        MainForm->FtpStart->Enabled=true;
                    471:        MainForm->FtpStop->Enabled=false;
                    472: }
                    473: static void ftp_started(void)
                    474: {
                    475:        Screen->Cursor=crDefault;
                    476:        MainForm->FtpStart->Enabled=false;
                    477:     MainForm->FtpStop->Enabled=true;
                    478: }
                    479: static void ftp_start(void)
                    480: {
                    481:        Screen->Cursor=crAppStart;
                    482:     ftp_status("Starting");
                    483:     strcpy(MainForm->ftp_startup.ctrl_dir,MainForm->CtrlDirectory.c_str());
                    484:        _beginthread((void(*)(void*))ftp_server,0,&MainForm->ftp_startup);
                    485: }
                    486: //---------------------------------------------------------------------------
                    487: 
                    488: #define REG_KEY "\\Software\\Swindell\\Synchronet Control Panel\\"
                    489: 
                    490: //---------------------------------------------------------------------------
                    491: __fastcall TMainForm::TMainForm(TComponent* Owner)
                    492:         : TForm(Owner)
                    493: {
                    494:     CtrlDirectory="c:\\sbbs\\ctrl\\";
                    495:     LoginCommand="start telnet://localhost";
                    496:     ConfigCommand="%sSCFG %s /T2";
                    497: 
                    498:     memset(&bbs_startup,0,sizeof(bbs_startup));
                    499:     bbs_startup.size=sizeof(bbs_startup);
                    500:     bbs_startup.first_node=1;
                    501:     bbs_startup.last_node=4;
                    502:     bbs_startup.telnet_port=IPPORT_TELNET;
                    503:     bbs_startup.telnet_interface=INADDR_ANY;
                    504:     bbs_startup.rlogin_port=513;
                    505:     bbs_startup.rlogin_interface=INADDR_ANY;
                    506:        bbs_startup.lputs=bbs_lputs;
                    507:     bbs_startup.status=bbs_status;
                    508:     bbs_startup.clients=bbs_clients;
                    509:     bbs_startup.started=bbs_started;
                    510:     bbs_startup.terminated=bbs_terminated;
                    511:     bbs_startup.thread_up=thread_up;
                    512:     bbs_startup.client_on=client_on;
                    513:     bbs_startup.socket_open=socket_open;
                    514: 
                    515:     memset(&mail_startup,0,sizeof(mail_startup));
                    516:     mail_startup.size=sizeof(mail_startup);
                    517:     mail_startup.smtp_port=IPPORT_SMTP;
                    518:     mail_startup.relay_port=IPPORT_SMTP;
                    519:     mail_startup.pop3_port=110;
                    520:     mail_startup.interface_addr=INADDR_ANY;
                    521:        mail_startup.lputs=mail_lputs;
                    522:     mail_startup.status=mail_status;
                    523:     mail_startup.clients=mail_clients;
                    524:     mail_startup.started=mail_started;
                    525:     mail_startup.terminated=mail_terminated;
                    526:     mail_startup.options=MAIL_OPT_ALLOW_POP3;
                    527:     mail_startup.thread_up=thread_up;
                    528:     mail_startup.client_on=client_on;
                    529:     mail_startup.socket_open=socket_open;
                    530:     mail_startup.max_delivery_attempts=10;
                    531:     mail_startup.rescan_frequency=300;  /* 5 minutes */
                    532: 
                    533:     memset(&ftp_startup,0,sizeof(ftp_startup));
                    534:     ftp_startup.size=sizeof(ftp_startup);
                    535:     ftp_startup.port=IPPORT_FTP;
                    536:     ftp_startup.interface_addr=INADDR_ANY;
                    537:        ftp_startup.lputs=ftp_lputs;
                    538:     ftp_startup.status=ftp_status;
                    539:     ftp_startup.clients=ftp_clients;
                    540:     ftp_startup.started=ftp_started;
                    541:     ftp_startup.terminated=ftp_terminated;
                    542:     ftp_startup.thread_up=thread_up;
                    543:     ftp_startup.client_on=client_on;
                    544:     ftp_startup.socket_open=socket_open;
                    545:        ftp_startup.options=FTP_OPT_INDEX_FILE|FTP_OPT_ALLOW_QWK;
                    546:     strcpy(ftp_startup.index_file_name,"00index");
                    547: 
                    548:     /* Default local "Spy Terminal" settings */
                    549:     SpyTerminalFont=new TFont;
                    550:     SpyTerminalFont->Name="Terminal";
                    551:     SpyTerminalFont->Size=9;
                    552:     SpyTerminalFont->Pitch=fpFixed;
                    553:     SpyTerminalWidth=434;
                    554:     SpyTerminalHeight=365;
                    555:     SpyTerminalKeyboardActive=true;
                    556: }
                    557: //---------------------------------------------------------------------------
                    558: void __fastcall TMainForm::FileExitMenuItemClick(TObject *Sender)
                    559: {
                    560:         Close();
                    561: }
                    562: void __fastcall TMainForm::FormCreate(TObject *Sender)
                    563: {
                    564:        Height=400;     // Just incase we mess it up in the IDE
                    565:     Width=700;
                    566: 
                    567:        if(putenv("TZ=UCT0")) {
                    568:        Application->MessageBox("Error settings timezone"
                    569:                ,"ERROR",MB_OK|MB_ICONEXCLAMATION);
                    570:         Application->Terminate();
                    571:     }
                    572:        tzset();
                    573: 
                    574:     // Read Registry keys
                    575:        TRegistry* Registry=new TRegistry;
                    576:     if(!Registry->OpenKey(REG_KEY,true)) {
                    577:        Application->MessageBox("Error opening registry key"
                    578:                ,REG_KEY,MB_OK|MB_ICONEXCLAMATION);
                    579:         Application->Terminate();
                    580:     }
                    581:        if(Registry->ValueExists("MainFormTop"))
                    582:                Top=Registry->ReadInteger("MainFormTop");
                    583:        if(Registry->ValueExists("MainFormLeft"))
                    584:                Left=Registry->ReadInteger("MainFormLeft");
                    585:        if(Registry->ValueExists("MainFormHeight"))
                    586:                Height=Registry->ReadInteger("MainFormHeight");
                    587:        if(Registry->ValueExists("MainFormWidth"))
                    588:                Width=Registry->ReadInteger("MainFormWidth");
                    589:     else
                    590:         WindowState=wsMaximized;    // Default to fullscreen
                    591: 
                    592:        if(Registry->ValueExists("SpyTerminalWidth"))
                    593:                SpyTerminalWidth=Registry->ReadInteger("SpyTerminalWidth");
                    594:        if(Registry->ValueExists("SpyTerminalHeight"))
                    595:                SpyTerminalHeight=Registry->ReadInteger("SpyTerminalHeight");
                    596:        if(Registry->ValueExists("SpyTerminalFontName"))
                    597:                SpyTerminalFont->Name=Registry->ReadString("SpyTerminalFontName");
                    598:        if(Registry->ValueExists("SpyTerminalFontSize"))
                    599:                SpyTerminalFont->Size=Registry->ReadInteger("SpyTerminalFontSize");
                    600:        if(Registry->ValueExists("SpyTerminalKeyboardActive"))
                    601:                SpyTerminalKeyboardActive
                    602:             =Registry->ReadBool("SpyTerminalKeyboardActive");
                    603: 
                    604:     Registry->CloseKey();
                    605:     delete Registry;
                    606: }
                    607: //---------------------------------------------------------------------------
                    608: void __fastcall TMainForm::FormShow(TObject *Sender)
                    609: {
                    610:        StartupTimer->Enabled=true;
                    611: }
                    612: //---------------------------------------------------------------------------
                    613: 
                    614: void __fastcall TMainForm::ViewToolbarMenuItemClick(TObject *Sender)
                    615: {
                    616:        Toolbar->Visible=!ViewToolbarMenuItem->Checked;
                    617:     ViewToolbarMenuItem->Checked=Toolbar->Visible;
                    618: }
                    619: //---------------------------------------------------------------------------
                    620: void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
                    621: {
                    622:     SaveSettings(Sender);
                    623: }
                    624: //---------------------------------------------------------------------------
                    625: void __fastcall TMainForm::SaveSettings(TObject* Sender)
                    626: {
                    627:     // Write Registry keys
                    628:        TRegistry* Registry=new TRegistry;
                    629:     if(!Registry->OpenKey(REG_KEY,true)) {
                    630:        Application->MessageBox("Error creating registry key"
                    631:                ,REG_KEY,MB_OK|MB_ICONEXCLAMATION);
                    632:         Application->Terminate();
                    633:     }
                    634: 
                    635:     Registry->WriteInteger("MainFormTop",Top);
                    636:     Registry->WriteInteger("MainFormLeft",Left);
                    637:     Registry->WriteInteger("MainFormHeight",Height);
                    638:     Registry->WriteInteger("MainFormWidth",Width);
                    639: 
                    640:     Registry->WriteInteger("NodeFormTop",NodeForm->Top);
                    641:     Registry->WriteInteger("NodeFormLeft",NodeForm->Left);
                    642:     Registry->WriteInteger("NodeFormHeight",NodeForm->Height);
                    643:     Registry->WriteInteger("NodeFormWidth",NodeForm->Width);
                    644: 
                    645:     Registry->WriteInteger("StatsFormTop",StatsForm->Top);
                    646:     Registry->WriteInteger("StatsFormLeft",StatsForm->Left);
                    647:     Registry->WriteInteger("StatsFormHeight",StatsForm->Height);
                    648:     Registry->WriteInteger("StatsFormWidth",StatsForm->Width);
                    649: 
                    650:     Registry->WriteInteger("ClientFormTop",ClientForm->Top);
                    651:     Registry->WriteInteger("ClientFormLeft",ClientForm->Left);
                    652:     Registry->WriteInteger("ClientFormHeight",ClientForm->Height);
                    653:     Registry->WriteInteger("ClientFormWidth",ClientForm->Width);
                    654: 
                    655:     Registry->WriteInteger("TelnetFormTop",TelnetForm->Top);
                    656:     Registry->WriteInteger("TelnetFormLeft",TelnetForm->Left);
                    657:     Registry->WriteInteger("TelnetFormHeight",TelnetForm->Height);
                    658:     Registry->WriteInteger("TelnetFormWidth",TelnetForm->Width);
                    659: 
                    660:     Registry->WriteInteger("FtpFormTop",FtpForm->Top);
                    661:     Registry->WriteInteger("FtpFormLeft",FtpForm->Left);
                    662:     Registry->WriteInteger("FtpFormHeight",FtpForm->Height);
                    663:     Registry->WriteInteger("FtpFormWidth",FtpForm->Width);
                    664: 
                    665:     Registry->WriteInteger("MailFormTop",MailForm->Top);
                    666:     Registry->WriteInteger("MailFormLeft",MailForm->Left);
                    667:     Registry->WriteInteger("MailFormHeight",MailForm->Height);
                    668:     Registry->WriteInteger("MailFormWidth",MailForm->Width);
                    669: 
                    670:     Registry->WriteInteger("TopPanelHeight",TopPanel->Height);
                    671:        Registry->WriteInteger("UpperLeftPageControlWidth"
                    672:        ,UpperLeftPageControl->Width);
                    673:     Registry->WriteInteger("LowerLeftPageControlWidth"
                    674:        ,LowerLeftPageControl->Width);
                    675: 
                    676:     Registry->WriteBool("TelnetFormFloating",TelnetForm->Floating);
                    677:     Registry->WriteBool("NodeFormFloating",NodeForm->Floating);
                    678:     Registry->WriteBool("StatsFormFloating",StatsForm->Floating);
                    679:     Registry->WriteBool("ClientFormFloating",ClientForm->Floating);
                    680:     Registry->WriteBool("FtpFormFloating",FtpForm->Floating);
                    681:     Registry->WriteBool("MailFormFloating",MailForm->Floating);
                    682: 
                    683:     Registry->WriteInteger("TelnetFormPage"
                    684:            ,PageNum((TPageControl*)TelnetForm->HostDockSite));
                    685:     Registry->WriteInteger("NodeFormPage"
                    686:        ,PageNum((TPageControl*)NodeForm->HostDockSite));
                    687:     Registry->WriteInteger("MailFormPage"
                    688:        ,PageNum((TPageControl*)MailForm->HostDockSite));
                    689:     Registry->WriteInteger("FtpFormPage"
                    690:        ,PageNum((TPageControl*)FtpForm->HostDockSite));
                    691:     Registry->WriteInteger("StatsFormPage"
                    692:        ,PageNum((TPageControl*)StatsForm->HostDockSite));
                    693:     Registry->WriteInteger("ClientFormPage"
                    694:        ,PageNum((TPageControl*)ClientForm->HostDockSite));
                    695: 
                    696:     Registry->WriteBool("ToolBarVisible",Toolbar->Visible);
                    697:     Registry->WriteBool("StatusBarVisible",StatusBar->Visible);
                    698: 
                    699:     Registry->WriteString("CtrlDirectory",CtrlDirectory);
                    700:     Registry->WriteString("LoginCommand",LoginCommand);
                    701:     Registry->WriteString("ConfigCommand",ConfigCommand);
                    702: 
                    703:     Registry->WriteInteger("SysAutoStart",SysAutoStart);
                    704:     Registry->WriteInteger("MailAutoStart",MailAutoStart);
                    705:     Registry->WriteInteger("FtpAutoStart",FtpAutoStart);
                    706:     Registry->WriteInteger("MailLogFile",MailLogFile);
                    707:     Registry->WriteInteger("FtpLogFile",FtpLogFile);
                    708: 
                    709:     Registry->WriteInteger("TelnetInterface",bbs_startup.telnet_interface);
                    710:     Registry->WriteInteger("RLoginInterface",bbs_startup.rlogin_interface);
                    711: 
                    712:        Registry->WriteInteger("TelnetPort",bbs_startup.telnet_port);
                    713:        Registry->WriteInteger("RLoginPort",bbs_startup.rlogin_port);
                    714:     Registry->WriteInteger("FirstNode",bbs_startup.first_node);
                    715:     Registry->WriteInteger("LastNode",bbs_startup.last_node);
                    716: 
                    717:     Registry->WriteString("AnswerSound",AnsiString(bbs_startup.answer_sound));
                    718:     Registry->WriteString("HangupSound",AnsiString(bbs_startup.hangup_sound));
                    719: 
                    720:     Registry->WriteInteger("StartupOptions",bbs_startup.options);
                    721: 
                    722:     Registry->WriteInteger("MailMaxClients",mail_startup.max_clients);
                    723:     Registry->WriteInteger("MailMaxInactivity",mail_startup.max_inactivity);
                    724:     Registry->WriteInteger("MailInterface",mail_startup.interface_addr);
                    725:     Registry->WriteInteger("MailMaxDeliveryAttempts"
                    726:         ,mail_startup.max_delivery_attempts);
                    727:     Registry->WriteInteger("MailRescanFrequency"
                    728:         ,mail_startup.rescan_frequency);
                    729: 
                    730:     Registry->WriteInteger("MailSMTPPort",mail_startup.smtp_port);
                    731:     Registry->WriteInteger("MailPOP3Port",mail_startup.pop3_port);
                    732: 
                    733:     Registry->WriteString("MailRelayServer",mail_startup.relay_server);
                    734:     Registry->WriteString("MailDNSServer",mail_startup.dns_server);
                    735: 
                    736:     Registry->WriteString("MailInboundSound",AnsiString(mail_startup.inbound_sound));
                    737:     Registry->WriteString("MailOutboundSound",AnsiString(mail_startup.outbound_sound));
                    738:     Registry->WriteInteger("MailOptions",mail_startup.options);
                    739: 
                    740:     Registry->WriteString("MailPOP3Sound",AnsiString(mail_startup.pop3_sound));
                    741: 
                    742:        Registry->WriteInteger("FtpPort",ftp_startup.port);
                    743:     Registry->WriteInteger("FtpMaxClients",ftp_startup.max_clients);
                    744:     Registry->WriteInteger("FtpMaxInactivity",ftp_startup.max_inactivity);
                    745:     Registry->WriteInteger("FtpInterface",ftp_startup.interface_addr);
                    746:     Registry->WriteString("FtpAnswerSound",AnsiString(ftp_startup.answer_sound));
                    747:     Registry->WriteString("FtpHangupSound",AnsiString(ftp_startup.hangup_sound));
                    748:     Registry->WriteString("FtpIndexFileName"
                    749:        ,AnsiString(ftp_startup.index_file_name));
                    750:     Registry->WriteInteger("FtpOptions",ftp_startup.options);
                    751: 
                    752:        Registry->WriteInteger( "SpyTerminalWidth"
                    753:                             ,SpyTerminalWidth);
                    754:        Registry->WriteInteger( "SpyTerminalHeight"
                    755:                             ,SpyTerminalHeight);
                    756:        Registry->WriteString(  "SpyTerminalFontName"
                    757:                             ,SpyTerminalFont->Name);
                    758:        Registry->WriteInteger( "SpyTerminalFontSize"
                    759:                             ,SpyTerminalFont->Size);
                    760:        Registry->WriteBool(    "SpyTerminalKeyboardActive"
                    761:                             ,SpyTerminalKeyboardActive);
                    762: 
                    763:     Registry->CloseKey();
                    764:     delete Registry;
                    765: 
                    766: }
                    767: //---------------------------------------------------------------------------
                    768: 
                    769: void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
                    770: {
                    771:        CanClose=true;
                    772: 
                    773:     if(TelnetStop->Enabled) {
                    774:                CanClose=false;
                    775:        if(TelnetForm->ProgressBar->Position
                    776:                && Application->MessageBox("Shut down the Telnet Server?"
                    777:                ,"Telnet Server In Use", MB_OKCANCEL)!=IDOK)
                    778:             return;
                    779:         TelnetStopExecute(Sender);
                    780:        }
                    781: 
                    782:     if(MailStop->Enabled) {
                    783:         CanClose=false;
                    784:        if(MailForm->ProgressBar->Position
                    785:                && Application->MessageBox("Shut down the Mail Server?"
                    786:                ,"Mail Server In Use", MB_OKCANCEL)!=IDOK)
                    787:             return;
                    788:         MailStopExecute(Sender);
                    789:     }
                    790: 
                    791:     if(FtpStop->Enabled) {
                    792:         CanClose=false;
                    793:        if(FtpForm->ProgressBar->Position
                    794:                && Application->MessageBox("Shut down the FTP Server?"
                    795:                ,"FTP Server In Use", MB_OKCANCEL)!=IDOK)
                    796:             return;
                    797:         FtpStopExecute(Sender);
                    798:     }
                    799: 
                    800:     if(CanClose==false)
                    801:            CloseTimer->Enabled=true;
                    802: }
                    803: //---------------------------------------------------------------------------
                    804: 
                    805: void __fastcall TMainForm::TelnetStartExecute(TObject *Sender)
                    806: {
                    807:        bbs_start();
                    808: }
                    809: //---------------------------------------------------------------------------
                    810: 
                    811: void __fastcall TMainForm::TelnetStopExecute(TObject *Sender)
                    812: {
                    813:        Screen->Cursor=crAppStart;
                    814:     bbs_status("Terminating");
                    815:        bbs_terminate();
                    816: }
                    817: //---------------------------------------------------------------------------
                    818: 
                    819: void __fastcall TMainForm::TelnetConfigureExecute(TObject *Sender)
                    820: {
                    821:        Application->CreateForm(__classid(TTelnetCfgDlg), &TelnetCfgDlg);
                    822:        TelnetCfgDlg->ShowModal();
                    823:     delete TelnetCfgDlg;
                    824: }
                    825: //---------------------------------------------------------------------------
                    826: 
                    827: 
                    828: void __fastcall TMainForm::NodeListStartExecute(TObject *Sender)
                    829: {
                    830:        NodeForm->Timer->Enabled=true;
                    831:     NodeListStart->Enabled=false;
                    832:     NodeListStop->Enabled=true;
                    833: }
                    834: //---------------------------------------------------------------------------
                    835: 
                    836: void __fastcall TMainForm::NodeListStopExecute(TObject *Sender)
                    837: {
                    838:     NodeForm->Timer->Enabled=false;
                    839:     NodeListStart->Enabled=true;
                    840:     NodeListStop->Enabled=false;
                    841: }
                    842: //---------------------------------------------------------------------------
                    843: 
                    844: 
                    845: void __fastcall TMainForm::MailConfigureExecute(TObject *Sender)
                    846: {
                    847:        Application->CreateForm(__classid(TMailCfgDlg), &MailCfgDlg);
                    848:        MailCfgDlg->ShowModal();
                    849:     delete MailCfgDlg;
                    850: }
                    851: //---------------------------------------------------------------------------
                    852: 
                    853: void __fastcall TMainForm::MailStartExecute(TObject *Sender)
                    854: {
                    855:     mail_start();
                    856: }
                    857: //---------------------------------------------------------------------------
                    858: 
                    859: void __fastcall TMainForm::MailStopExecute(TObject *Sender)
                    860: {
                    861:        Screen->Cursor=crAppStart;
                    862:     mail_status("Terminating");
                    863:        mail_terminate();
                    864: }
                    865: //---------------------------------------------------------------------------
                    866: 
                    867: void __fastcall TMainForm::ViewTelnetExecute(TObject *Sender)
                    868: {
                    869:        TelnetForm->Visible=!TelnetForm->Visible;
                    870:     ViewTelnet->Checked=TelnetForm->Visible;
                    871: }
                    872: //---------------------------------------------------------------------------
                    873: 
                    874: void __fastcall TMainForm::ViewNodesExecute(TObject *Sender)
                    875: {
                    876:        NodeForm->Visible=!NodeForm->Visible;
                    877:     ViewNodes->Checked=NodeForm->Visible;
                    878: }
                    879: //---------------------------------------------------------------------------
                    880: 
                    881: void __fastcall TMainForm::ViewMailServerExecute(TObject *Sender)
                    882: {
                    883:        MailForm->Visible=!MailForm->Visible;
                    884:     ViewMailServer->Checked=MailForm->Visible;
                    885: }
                    886: //---------------------------------------------------------------------------
                    887: 
                    888: void __fastcall TMainForm::ViewFtpServerExecute(TObject *Sender)
                    889: {
                    890:        FtpForm->Visible=!FtpForm->Visible;
                    891:     ViewFtpServer->Checked=FtpForm->Visible;
                    892: }
                    893: //---------------------------------------------------------------------------
                    894: 
                    895: void __fastcall TMainForm::FtpStartExecute(TObject *Sender)
                    896: {
                    897:        ftp_start();
                    898: }
                    899: //---------------------------------------------------------------------------
                    900: 
                    901: void __fastcall TMainForm::FtpStopExecute(TObject *Sender)
                    902: {
                    903:        Screen->Cursor=crAppStart;
                    904:     ftp_status("Terminating");
                    905:        ftp_terminate();
                    906: }
                    907: //---------------------------------------------------------------------------
                    908: 
                    909: void __fastcall TMainForm::FtpConfigureExecute(TObject *Sender)
                    910: {
                    911:        Application->CreateForm(__classid(TFtpCfgDlg), &FtpCfgDlg);
                    912:        FtpCfgDlg->ShowModal();
                    913:     delete FtpCfgDlg;
                    914: }
                    915: //---------------------------------------------------------------------------
                    916: 
                    917: void __fastcall TMainForm::CloseTimerTimer(TObject *Sender)
                    918: {
                    919:        if(!TelnetStop->Enabled && !MailStop->Enabled && !FtpStop->Enabled)
                    920:            Close();
                    921: }
                    922: //---------------------------------------------------------------------------
                    923: 
                    924: void __fastcall TMainForm::BBSConfigureMenuItemClick(TObject *Sender)
                    925: {
                    926:        char str[256];
                    927: 
                    928:     sprintf(str,ConfigCommand.c_str()
                    929:        ,cfg.exec_dir, cfg.ctrl_dir);
                    930:     STARTUPINFO startup_info={0};
                    931:     PROCESS_INFORMATION process_info;
                    932:     startup_info.cb=sizeof(startup_info);
                    933:        CreateProcess(
                    934:                NULL,                   // pointer to name of executable module
                    935:                str,                    // pointer to command line string
                    936:                NULL,                   // process security attributes
                    937:                NULL,                   // thread security attributes
                    938:                TRUE,                   // handle inheritance flag
                    939:                CREATE_NEW_CONSOLE|CREATE_SEPARATE_WOW_VDM, // creation flags
                    940:         NULL,                          // pointer to new environment block
                    941:                cfg.ctrl_dir,   // pointer to current directory name
                    942:                &startup_info,  // pointer to STARTUPINFO
                    943:                &process_info   // pointer to PROCESS_INFORMATION
                    944:                );
                    945: }
                    946: //---------------------------------------------------------------------------
                    947: 
                    948: 
                    949: 
                    950: 
                    951: void __fastcall TMainForm::NodeCloseButtonClick(TObject *Sender)
                    952: {
                    953:        ViewNodesExecute(Sender);
                    954: }
                    955: //---------------------------------------------------------------------------
                    956: 
                    957: void __fastcall TMainForm::TelnetCloseButtonClick(TObject *Sender)
                    958: {
                    959:        ViewTelnetExecute(Sender);
                    960: }
                    961: //---------------------------------------------------------------------------
                    962: 
                    963: void __fastcall TMainForm::MailCloseButtonClick(TObject *Sender)
                    964: {
                    965:        ViewMailServerExecute(Sender);
                    966: }
                    967: //---------------------------------------------------------------------------
                    968: 
                    969: void __fastcall TMainForm::FtpCloseButtonClick(TObject *Sender)
                    970: {
                    971:        ViewFtpServerExecute(Sender);
                    972: }
                    973: //---------------------------------------------------------------------------
                    974: 
                    975: 
                    976: #define STAT_DESC_LEN 23
                    977: 
                    978: void __fastcall TMainForm::StatsTimerTick(TObject *Sender)
                    979: {
                    980:        char    str[128];
                    981:        int     i;
                    982:        static stats_t stats;
                    983: 
                    984:     getstats(&cfg,0,&stats);
                    985: 
                    986: #if 0
                    987:     for(i=0;i<8;i++) {
                    988:        str[0];
                    989:        switch(i) {
                    990:                        case 0:
                    991:                sprintf(str,"%*s %lu Total: %lu"
                    992:                        ,STAT_DESC_LEN,"Logons Today:"
                    993:                        ,stats.ltoday,stats.logons);
                    994:                 break;
                    995:             case 1:
                    996:                sprintf(str,"%*s %lu Total: %lu"
                    997:                        ,STAT_DESC_LEN,"Time Used Today:"
                    998:                        ,stats.ttoday,stats.timeon);
                    999:                 break;
                   1000:             case 2:
                   1001:                sprintf(str,"%*s %lu bytes in %lu files"
                   1002:                        ,STAT_DESC_LEN,"Uploads Today:"
                   1003:                        ,stats.ulb,stats.uls);
                   1004:                 break;
                   1005:             case 3:
                   1006:                sprintf(str,"%*s %lu bytes in %lu files"
                   1007:                        ,STAT_DESC_LEN,"Downloads Today:"
                   1008:                        ,stats.dlb,stats.dls);
                   1009:                 break;
                   1010:             case 4:
                   1011:                sprintf(str,"%*s %lu"
                   1012:                        ,STAT_DESC_LEN,"Messages Posted Today:"
                   1013:                        ,stats.ptoday);
                   1014:                 break;
                   1015:             case 5:
                   1016:                sprintf(str,"%*s %lu Total: %lu"
                   1017:                        ,STAT_DESC_LEN,"E-mail Sent Today:"
                   1018:                        ,stats.etoday,getmail(&cfg,0,0));
                   1019:                 break;
                   1020:             case 6:
                   1021:                sprintf(str,"%*s %lu Total: %lu"
                   1022:                        ,STAT_DESC_LEN,"Feedback Sent Today:"
                   1023:                        ,stats.ftoday,getmail(&cfg,1,0));
                   1024:                 break;
                   1025:                        case 7:
                   1026:                sprintf(str,"%*s %hu Total: %lu"
                   1027:                        ,STAT_DESC_LEN,"New Users Today:"
                   1028:                        ,stats.nusers,lastuser(&cfg));
                   1029:                 break;
                   1030:         }
                   1031:         if(!str[0])
                   1032:                break;
                   1033: 
                   1034:         AnsiString Str=AnsiString(str);
                   1035: 
                   1036:         if(StatsForm->ListBox->Items->Count<i+1)
                   1037:             StatsForm->ListBox->Items->Add(Str);
                   1038:         else if(StatsForm->ListBox->Items->Strings[i]!=Str)
                   1039:             StatsForm->ListBox->Items->Strings[i]=str;
                   1040:        }
                   1041: #else
                   1042: 
                   1043:        StatsForm->TotalLogons->Caption=AnsiString(stats.logons);
                   1044:     StatsForm->LogonsToday->Caption=AnsiString(stats.ltoday);
                   1045:     StatsForm->TotalTimeOn->Caption=AnsiString(stats.timeon);
                   1046:     StatsForm->TimeToday->Caption=AnsiString(stats.ttoday);
                   1047:     StatsForm->TotalEMail->Caption=AnsiString(getmail(&cfg,0,0));
                   1048:        StatsForm->EMailToday->Caption=AnsiString(stats.etoday);
                   1049:        StatsForm->TotalFeedback->Caption=AnsiString(getmail(&cfg,1,0));
                   1050:        StatsForm->FeedbackToday->Caption=AnsiString(stats.ftoday);
                   1051:     StatsForm->TotalUsers->Caption=AnsiString(lastuser(&cfg));
                   1052:     StatsForm->NewUsersToday->Caption=AnsiString(stats.nusers);
                   1053:     StatsForm->PostsToday->Caption=AnsiString(stats.ptoday);
                   1054:     StatsForm->UploadedFiles->Caption=AnsiString(stats.uls);
                   1055:        if(stats.ulb>=1024*1024)
                   1056:        sprintf(str,"%.1fM",stats.ulb/(1024.0*1024.0));
                   1057:     else if(stats.ulb>=1024)
                   1058:        sprintf(str,"%luK",stats.ulb/1024);
                   1059:     else
                   1060:        sprintf(str,"%lu",stats.ulb);
                   1061:     StatsForm->UploadedBytes->Caption=AnsiString(str);
                   1062:     StatsForm->DownloadedFiles->Caption=AnsiString(stats.dls);
                   1063:        if(stats.dlb>=1024*1024)
                   1064:        sprintf(str,"%.1fM",stats.dlb/(1024.0*1024.0));
                   1065:     else if(stats.dlb>=1024)
                   1066:        sprintf(str,"%luK",stats.dlb/1024);
                   1067:     else
                   1068:        sprintf(str,"%lu",stats.dlb);
                   1069:     StatsForm->DownloadedBytes->Caption=AnsiString(str);
                   1070: 
                   1071: #endif
                   1072: }
                   1073: //---------------------------------------------------------------------------
                   1074: 
                   1075: void __fastcall TMainForm::ViewStatsExecute(TObject *Sender)
                   1076: {
                   1077:        StatsForm->Visible=!StatsForm->Visible;
                   1078:     ViewStats->Checked=StatsForm->Visible;
                   1079: }
                   1080: //---------------------------------------------------------------------------
                   1081: 
                   1082: void __fastcall TMainForm::StatsCloseButtonClick(TObject *Sender)
                   1083: {
                   1084:        ViewStatsExecute(Sender);
                   1085: }
                   1086: //---------------------------------------------------------------------------
                   1087: enum {
                   1088:         PAGE_UPPERLEFT
                   1089:     ,PAGE_UPPERRIGHT
                   1090:     ,PAGE_LOWERRIGHT
                   1091:     ,PAGE_LOWERLEFT
                   1092:     };
                   1093: TPageControl* __fastcall TMainForm::PageControl(int num)
                   1094: {
                   1095:        switch(num)
                   1096:     {
                   1097:        case PAGE_UPPERLEFT:
                   1098:                return(UpperLeftPageControl);
                   1099:         case PAGE_UPPERRIGHT:
                   1100:                return(UpperRightPageControl);
                   1101:         case PAGE_LOWERRIGHT:
                   1102:                return(LowerRightPageControl);
                   1103:         case PAGE_LOWERLEFT:
                   1104:                return(LowerLeftPageControl);
                   1105:     }
                   1106:     return(NULL);
                   1107: }
                   1108: int __fastcall TMainForm::PageNum(TPageControl* obj)
                   1109: {
                   1110:     if(obj==UpperLeftPageControl)
                   1111:                return(PAGE_UPPERLEFT);
                   1112:     if(obj==UpperRightPageControl)
                   1113:                return(PAGE_UPPERRIGHT);
                   1114:     if(obj==LowerRightPageControl)
                   1115:                return(PAGE_LOWERRIGHT);
                   1116:     if(obj==LowerLeftPageControl)
                   1117:                return(PAGE_LOWERLEFT);
                   1118:        return(PAGE_LOWERRIGHT);
                   1119: }
                   1120: void __fastcall TMainForm::StartupTimerTick(TObject *Sender)
                   1121: {
                   1122:     bool       TelnetFormFloating=false;
                   1123:     bool       NodeFormFloating=false;
                   1124:     bool       StatsFormFloating=false;
                   1125:     bool       ClientFormFloating=false;
                   1126:     bool       MailFormFloating=false;
                   1127:     bool       FtpFormFloating=false;
                   1128:     int                NodeFormPage=PAGE_UPPERLEFT;
                   1129:     int                StatsFormPage=PAGE_UPPERLEFT;
                   1130:     int                ClientFormPage=PAGE_UPPERLEFT;
                   1131:     int                TelnetFormPage=PAGE_LOWERLEFT;
                   1132:     int                MailFormPage=PAGE_UPPERRIGHT;
                   1133:     int                FtpFormPage=PAGE_LOWERRIGHT;
                   1134: 
                   1135:     AnsiString Str;
                   1136: 
                   1137:     delete StartupTimer;
                   1138: 
                   1139:     // Read Registry keys
                   1140:        TRegistry* Registry=new TRegistry;
                   1141:     if(!Registry->OpenKey(REG_KEY,true)) {
                   1142:        Application->MessageBox("Error opening registry key"
                   1143:                ,REG_KEY,MB_OK|MB_ICONEXCLAMATION);
                   1144:         Application->Terminate();
                   1145:     }
                   1146: 
                   1147:     TopPanel->Height=Height/3;
                   1148:     UpperLeftPageControl->Width=Width/2;
                   1149:     LowerLeftPageControl->Width=Width/2;
                   1150: 
                   1151:     if(Registry->ValueExists("TopPanelHeight"))
                   1152:        TopPanel->Height=Registry->ReadInteger("TopPanelHeight");
                   1153:     if(Registry->ValueExists("UpperLeftPageControlWidth"))
                   1154:        UpperLeftPageControl->Width
                   1155:                =Registry->ReadInteger("UpperLeftPageControlWidth");
                   1156:     if(Registry->ValueExists("LowerLeftPageControlWidth"))
                   1157:        LowerLeftPageControl->Width
                   1158:                =Registry->ReadInteger("LowerLeftPageControlWidth");
                   1159: 
                   1160:     if(Registry->ValueExists("TelnetFormFloating"))
                   1161:        TelnetFormFloating=Registry->ReadBool("TelnetFormFloating");
                   1162:     if(Registry->ValueExists("NodeFormFloating"))
                   1163:        NodeFormFloating=Registry->ReadBool("NodeFormFloating");
                   1164:     if(Registry->ValueExists("StatsFormFloating"))
                   1165:        StatsFormFloating=Registry->ReadBool("StatsFormFloating");
                   1166:     if(Registry->ValueExists("ClientFormFloating"))
                   1167:        ClientFormFloating=Registry->ReadBool("ClientFormFloating");
                   1168:     if(Registry->ValueExists("MailFormFloating"))
                   1169:        MailFormFloating=Registry->ReadBool("MailFormFloating");
                   1170:     if(Registry->ValueExists("FtpFormFloating"))
                   1171:        FtpFormFloating=Registry->ReadBool("FtpFormFloating");
                   1172: 
                   1173:     if(Registry->ValueExists("TelnetFormPage"))
                   1174:        TelnetFormPage=Registry->ReadInteger("TelnetFormPage");
                   1175:     if(Registry->ValueExists("NodeFormPage"))
                   1176:        NodeFormPage=Registry->ReadInteger("NodeFormPage");
                   1177:     if(Registry->ValueExists("StatsFormPage"))
                   1178:        StatsFormPage=Registry->ReadInteger("StatsFormPage");
                   1179:     if(Registry->ValueExists("ClientFormPage"))
                   1180:        ClientFormPage=Registry->ReadInteger("ClientFormPage");
                   1181:     if(Registry->ValueExists("MailFormPage"))
                   1182:        MailFormPage=Registry->ReadInteger("MailFormPage");
                   1183:     if(Registry->ValueExists("FtpFormPage"))
                   1184:        FtpFormPage=Registry->ReadInteger("FtpFormPage");
                   1185: 
                   1186:        if(Registry->ValueExists("TelnetFormTop"))
                   1187:        TelnetForm->Top=Registry->ReadInteger("TelnetFormTop");
                   1188:        if(Registry->ValueExists("TelnetFormLeft"))
                   1189:        TelnetForm->Left=Registry->ReadInteger("TelnetFormLeft");
                   1190:        if(Registry->ValueExists("TelnetFormWidth"))
                   1191:        TelnetForm->Width=Registry->ReadInteger("TelnetFormWidth");
                   1192:        if(Registry->ValueExists("TelnetFormHeight"))
                   1193:        TelnetForm->Height=Registry->ReadInteger("TelnetFormHeight");
                   1194: 
                   1195:        if(Registry->ValueExists("FtpFormTop"))
                   1196:        FtpForm->Top=Registry->ReadInteger("FtpFormTop");
                   1197:        if(Registry->ValueExists("FtpFormLeft"))
                   1198:        FtpForm->Left=Registry->ReadInteger("FtpFormLeft");
                   1199:        if(Registry->ValueExists("FtpFormWidth"))
                   1200:        FtpForm->Width=Registry->ReadInteger("FtpFormWidth");
                   1201:        if(Registry->ValueExists("FtpFormHeight"))
                   1202:        FtpForm->Height=Registry->ReadInteger("FtpFormHeight");
                   1203: 
                   1204:        if(Registry->ValueExists("MailFormTop"))
                   1205:        MailForm->Top=Registry->ReadInteger("MailFormTop");
                   1206:        if(Registry->ValueExists("MailFormLeft"))
                   1207:        MailForm->Left=Registry->ReadInteger("MailFormLeft");
                   1208:        if(Registry->ValueExists("MailFormWidth"))
                   1209:        MailForm->Width=Registry->ReadInteger("MailFormWidth");
                   1210:        if(Registry->ValueExists("MailFormHeight"))
                   1211:        MailForm->Height=Registry->ReadInteger("MailFormHeight");
                   1212: 
                   1213:        if(Registry->ValueExists("NodeFormTop"))
                   1214:        NodeForm->Top=Registry->ReadInteger("NodeFormTop");
                   1215:        if(Registry->ValueExists("NodeFormLeft"))
                   1216:        NodeForm->Left=Registry->ReadInteger("NodeFormLeft");
                   1217:        if(Registry->ValueExists("NodeFormWidth"))
                   1218:        NodeForm->Width=Registry->ReadInteger("NodeFormWidth");
                   1219:        if(Registry->ValueExists("NodeFormHeight"))
                   1220:        NodeForm->Height=Registry->ReadInteger("NodeFormHeight");
                   1221: 
                   1222:        if(Registry->ValueExists("StatsFormTop"))
                   1223:        StatsForm->Top=Registry->ReadInteger("StatsFormTop");
                   1224:        if(Registry->ValueExists("StatsFormLeft"))
                   1225:        StatsForm->Left=Registry->ReadInteger("StatsFormLeft");
                   1226:        if(Registry->ValueExists("StatsFormWidth"))
                   1227:        StatsForm->Width=Registry->ReadInteger("StatsFormWidth");
                   1228:        if(Registry->ValueExists("StatsFormHeight"))
                   1229:        StatsForm->Height=Registry->ReadInteger("StatsFormHeight");
                   1230: 
                   1231:        if(Registry->ValueExists("ClientFormTop"))
                   1232:        ClientForm->Top=Registry->ReadInteger("ClientFormTop");
                   1233:        if(Registry->ValueExists("ClientFormLeft"))
                   1234:        ClientForm->Left=Registry->ReadInteger("ClientFormLeft");
                   1235:        if(Registry->ValueExists("ClientFormWidth"))
                   1236:        ClientForm->Width=Registry->ReadInteger("ClientFormWidth");
                   1237:        if(Registry->ValueExists("ClientFormHeight"))
                   1238:        ClientForm->Height=Registry->ReadInteger("ClientFormHeight");
                   1239: 
                   1240:     if(Registry->ValueExists("ToolbarVisible"))
                   1241:        Toolbar->Visible=Registry->ReadBool("ToolbarVisible");
                   1242: 
                   1243:     if(Registry->ValueExists("SysAutoStart"))
                   1244:        SysAutoStart=Registry->ReadInteger("SysAutoStart");
                   1245:     else
                   1246:        SysAutoStart=true;
                   1247: 
                   1248:     if(Registry->ValueExists("MailAutoStart"))
                   1249:        MailAutoStart=Registry->ReadInteger("MailAutoStart");
                   1250:     else
                   1251:        MailAutoStart=true;
                   1252: 
                   1253:     if(Registry->ValueExists("FtpAutoStart"))
                   1254:        FtpAutoStart=Registry->ReadInteger("FtpAutoStart");
                   1255:     else
                   1256:        FtpAutoStart=true;
                   1257: 
                   1258:     ViewToolbarMenuItem->Checked=Toolbar->Visible;
                   1259:     ViewStatusBarMenuItem->Checked=StatusBar->Visible;
                   1260: 
                   1261:     if(Registry->ValueExists("CtrlDirectory"))
                   1262:        CtrlDirectory=Registry->ReadString("CtrlDirectory");
                   1263:     if(Registry->ValueExists("LoginCommand"))
                   1264:        LoginCommand=Registry->ReadString("LoginCommand");
                   1265:     if(Registry->ValueExists("ConfigCommand"))
                   1266:        ConfigCommand=Registry->ReadString("ConfigCommand");
                   1267: 
                   1268:     if(Registry->ValueExists("MailLogFile"))
                   1269:        MailLogFile=Registry->ReadInteger("MailLogFile");
                   1270:     else
                   1271:        MailLogFile=true;
                   1272: 
                   1273:     if(Registry->ValueExists("FtpLogFile"))
                   1274:        FtpLogFile=Registry->ReadInteger("FtpLogFile");
                   1275:     else
                   1276:        FtpLogFile=true;
                   1277: 
                   1278:     if(Registry->ValueExists("TelnetInterface"))
                   1279:        bbs_startup.telnet_interface=Registry->ReadInteger("TelnetInterface");
                   1280:     if(Registry->ValueExists("RLoginInterface"))
                   1281:        bbs_startup.rlogin_interface=Registry->ReadInteger("RLoginInterface");
                   1282: 
                   1283:        if(Registry->ValueExists("TelnetPort"))
                   1284:        bbs_startup.telnet_port=Registry->ReadInteger("TelnetPort");
                   1285:        if(Registry->ValueExists("RLoginPort"))
                   1286:        bbs_startup.rlogin_port=Registry->ReadInteger("RLoginPort");
                   1287: 
                   1288:     if(Registry->ValueExists("FirstNode"))
                   1289:        bbs_startup.first_node=Registry->ReadInteger("FirstNode");
                   1290: 
                   1291:     if(Registry->ValueExists("LastNode"))
                   1292:        bbs_startup.last_node=Registry->ReadInteger("LastNode");
                   1293: 
                   1294:     if(Registry->ValueExists("AnswerSound"))
                   1295:        sprintf(bbs_startup.answer_sound,"%.*s"
                   1296:                ,sizeof(bbs_startup.answer_sound)-1
                   1297:                ,Registry->ReadString("AnswerSound").c_str());
                   1298: 
                   1299:     if(Registry->ValueExists("HangupSound"))
                   1300:        sprintf(bbs_startup.hangup_sound,"%.*s"
                   1301:                ,sizeof(bbs_startup.hangup_sound)-1
                   1302:                ,Registry->ReadString("HangupSound").c_str());
                   1303: 
                   1304:     if(Registry->ValueExists("StartupOptions"))
                   1305:        bbs_startup.options=Registry->ReadInteger("StartupOptions");
                   1306: 
                   1307:     if(Registry->ValueExists("MailMaxClients"))
                   1308:        mail_startup.max_clients=Registry->ReadInteger("MailMaxClients");
                   1309: 
                   1310:     if(Registry->ValueExists("MailMaxInactivity"))
                   1311:        mail_startup.max_inactivity=Registry->ReadInteger("MailMaxInactivity");
                   1312: 
                   1313:     if(Registry->ValueExists("MailInterface"))
                   1314:        mail_startup.interface_addr=Registry->ReadInteger("MailInterface");
                   1315: 
                   1316:     if(Registry->ValueExists("MailMaxDeliveryAttempts"))
                   1317:        mail_startup.max_delivery_attempts
                   1318:             =Registry->ReadInteger("MailMaxDeliveryAttempts");
                   1319: 
                   1320:     if(Registry->ValueExists("MailRescanFrequency"))
                   1321:        mail_startup.rescan_frequency
                   1322:             =Registry->ReadInteger("MailRescanFrequency");
                   1323: 
                   1324:     if(Registry->ValueExists("MailSMTPPort"))
                   1325:        mail_startup.smtp_port=Registry->ReadInteger("MailSMTPPort");
                   1326: 
                   1327:     if(Registry->ValueExists("MailPOP3Port"))
                   1328:        mail_startup.pop3_port=Registry->ReadInteger("MailPOP3Port");
                   1329: 
                   1330:     if(Registry->ValueExists("MailRelayServer"))
                   1331:         sprintf(mail_startup.relay_server,"%.*s"
                   1332:             ,sizeof(mail_startup.relay_server)-1
                   1333:             ,Registry->ReadString("MailRelayServer").c_str());
                   1334: 
                   1335:     if(Registry->ValueExists("MailDNSServer"))
                   1336:         sprintf(mail_startup.dns_server,"%.*s"
                   1337:             ,sizeof(mail_startup.dns_server)-1
                   1338:             ,Registry->ReadString("MailDNSServer").c_str());
                   1339: 
                   1340:     if(Registry->ValueExists("MailInboundSound"))
                   1341:        sprintf(mail_startup.inbound_sound,"%.*s"
                   1342:                ,sizeof(mail_startup.inbound_sound)-1
                   1343:                ,Registry->ReadString("MailInboundSound").c_str());
                   1344: 
                   1345:     if(Registry->ValueExists("MailOutboundSound"))
                   1346:        sprintf(mail_startup.outbound_sound,"%.*s"
                   1347:                ,sizeof(mail_startup.outbound_sound)-1
                   1348:                ,Registry->ReadString("MailOutboundSound").c_str());
                   1349: 
                   1350:     if(Registry->ValueExists("MailPOP3Sound"))
                   1351:        sprintf(mail_startup.pop3_sound,"%.*s"
                   1352:                ,sizeof(mail_startup.pop3_sound)-1
                   1353:                ,Registry->ReadString("MailPOP3Sound").c_str());
                   1354: 
                   1355:     if(Registry->ValueExists("MailOptions"))
                   1356:        mail_startup.options=Registry->ReadInteger("MailOptions");
                   1357: 
                   1358:     if(Registry->ValueExists("FtpMaxClients"))
                   1359:        ftp_startup.max_clients=Registry->ReadInteger("FtpMaxClients");
                   1360: 
                   1361:     if(Registry->ValueExists("FtpMaxInactivity"))
                   1362:        ftp_startup.max_inactivity=Registry->ReadInteger("FtpMaxInactivity");
                   1363: 
                   1364:     if(Registry->ValueExists("FtpInterface"))
                   1365:        ftp_startup.interface_addr=Registry->ReadInteger("FtpInterface");
                   1366: 
                   1367:     if(Registry->ValueExists("FtpPort"))
                   1368:        ftp_startup.port=Registry->ReadInteger("FtpPort");
                   1369: 
                   1370:     if(Registry->ValueExists("FtpAnswerSound"))
                   1371:        sprintf(ftp_startup.answer_sound,"%.*s"
                   1372:                ,sizeof(ftp_startup.answer_sound)-1
                   1373:                ,Registry->ReadString("FtpAnswerSound").c_str());
                   1374: 
                   1375:     if(Registry->ValueExists("FtpHangupSound"))
                   1376:        sprintf(ftp_startup.hangup_sound,"%.*s"
                   1377:                ,sizeof(ftp_startup.hangup_sound)-1
                   1378:                ,Registry->ReadString("FtpHangupSound").c_str());
                   1379: 
                   1380:     if(Registry->ValueExists("FtpIndexFileName"))
                   1381:        sprintf(ftp_startup.index_file_name,"%.*s"
                   1382:                ,sizeof(ftp_startup.index_file_name)-1
                   1383:                ,Registry->ReadString("FtpIndexFileName").c_str());
                   1384: 
                   1385:     if(Registry->ValueExists("FtpOptions"))
                   1386:        ftp_startup.options=Registry->ReadInteger("FtpOptions");
                   1387: 
                   1388:     Registry->CloseKey();
                   1389:     delete Registry;
                   1390: 
                   1391:     if(!FileExists(CtrlDirectory+"MAIN.CNF")) {
                   1392:        Sleep(3000);    // Let 'em see the logo for a bit
                   1393:                Application->CreateForm(__classid(TCtrlPathDialog), &CtrlPathDialog);
                   1394:        if(CtrlPathDialog->ShowModal()!=mrOk) {
                   1395:                Application->Terminate();
                   1396:             return;
                   1397:         }
                   1398:         CtrlDirectory=CtrlPathDialog->Edit->Text;
                   1399:         delete CtrlPathDialog;
                   1400:     }
                   1401:     if(CtrlDirectory.UpperCase().AnsiPos("MAIN.CNF"))
                   1402:                CtrlDirectory.SetLength(CtrlDirectory.Length()-8);
                   1403:     strcpy(cfg.ctrl_dir,CtrlDirectory.c_str());
                   1404:        if(!load_cfg(&cfg, NULL)) {
                   1405:        Application->MessageBox("Failed to load configuration files.","ERROR"
                   1406:                ,MB_OK|MB_ICONEXCLAMATION);
                   1407:         Application->Terminate();
                   1408:         return;
                   1409:     }
                   1410: 
                   1411:     if(bbs_startup.options&BBS_OPT_MUTE)
                   1412:        SoundToggle->Checked=false;
                   1413:     else
                   1414:        SoundToggle->Checked=true;
                   1415: 
                   1416:     if(bbs_startup.options&BBS_OPT_SYSOP_AVAILABLE)
                   1417:        ChatToggle->Checked=true;
                   1418:     else
                   1419:        ChatToggle->Checked=false;
                   1420: 
                   1421:        if(!NodeFormFloating)
                   1422:        NodeForm->ManualDock(PageControl(NodeFormPage),NULL,alClient);
                   1423:        if(!ClientFormFloating)
                   1424:        ClientForm->ManualDock(PageControl(ClientFormPage),NULL,alClient);
                   1425:        if(!StatsFormFloating)
                   1426:        StatsForm->ManualDock(PageControl(StatsFormPage),NULL,alClient);
                   1427:        if(!MailFormFloating)
                   1428:        MailForm->ManualDock(PageControl(MailFormPage),NULL,alClient);
                   1429:        if(!TelnetFormFloating)
                   1430:        TelnetForm->ManualDock(PageControl(TelnetFormPage),NULL,alClient);
                   1431:        if(!FtpFormFloating)
                   1432:        FtpForm->ManualDock(PageControl(FtpFormPage),NULL,alClient);
                   1433: 
                   1434:     NodeForm->Show();
                   1435:     ClientForm->Show();
                   1436:     StatsForm->Show();
                   1437:     TelnetForm->Show();
                   1438:     FtpForm->Show();
                   1439:     MailForm->Show();
                   1440: 
                   1441:        UpperLeftPageControl->Visible=true;
                   1442:        UpperRightPageControl->Visible=true;
                   1443:        LowerLeftPageControl->Visible=true;
                   1444:        LowerRightPageControl->Visible=true;
                   1445:        HorizontalSplitter->Visible=true;
                   1446:     BottomPanel->Visible=true;
                   1447:        TopPanel->Visible=true;
                   1448: 
                   1449:     // Work-around for CB5 PageControl anomaly
                   1450:     int i;
                   1451: 
                   1452:     for(i=1;i<UpperLeftPageControl->PageCount;i++)
                   1453:         UpperLeftPageControl->ActivePageIndex=i;
                   1454:     UpperLeftPageControl->ActivePageIndex=0;
                   1455: 
                   1456:     for(i=1;i<UpperRightPageControl->PageCount;i++)
                   1457:         UpperRightPageControl->ActivePageIndex=i;
                   1458:     UpperRightPageControl->ActivePageIndex=0;
                   1459: 
                   1460:     for(i=1;i<LowerRightPageControl->PageCount;i++)
                   1461:         LowerRightPageControl->ActivePageIndex=i;
                   1462:     LowerRightPageControl->ActivePageIndex=0;
                   1463: 
                   1464:     for(i=1;i<LowerLeftPageControl->PageCount;i++)
                   1465:         LowerLeftPageControl->ActivePageIndex=i;
                   1466:     LowerLeftPageControl->ActivePageIndex=0;
                   1467: 
                   1468:     if(SysAutoStart) {
                   1469:         bbs_start();
                   1470:     }
                   1471:     if(MailAutoStart) {
                   1472:         mail_start();
                   1473:     }
                   1474:     if(FtpAutoStart) {
                   1475:         ftp_start();
                   1476:     }
                   1477:     NodeForm->Timer->Enabled=true;
                   1478:        StatsTimer->Enabled=true;
                   1479: }
                   1480: //---------------------------------------------------------------------------
                   1481: 
                   1482: void __fastcall TMainForm::ViewStatusBarMenuItemClick(TObject *Sender)
                   1483: {
                   1484:        StatusBar->Visible=!StatusBar->Visible;
                   1485:     ViewStatusBarMenuItem->Checked=StatusBar->Visible;
                   1486: }
                   1487: //---------------------------------------------------------------------------
                   1488: 
                   1489: 
                   1490: void __fastcall TMainForm::HelpAboutMenuItemClick(TObject *Sender)
                   1491: {
                   1492:        Application->CreateForm(__classid(TAboutBoxForm), &AboutBoxForm);
                   1493:     AboutBoxForm->ShowModal();
                   1494:     delete AboutBoxForm;
                   1495: }
                   1496: //---------------------------------------------------------------------------
                   1497: 
                   1498: 
                   1499: 
                   1500: void __fastcall TMainForm::SoundToggleExecute(TObject *Sender)
                   1501: {
                   1502:     SoundToggle->Checked=!SoundToggle->Checked;
                   1503:     if(!SoundToggle->Checked) {
                   1504:            bbs_startup.options|=BBS_OPT_MUTE;
                   1505:            ftp_startup.options|=FTP_OPT_MUTE;
                   1506:            mail_startup.options|=MAIL_OPT_MUTE;
                   1507:        } else {
                   1508:            bbs_startup.options&=~BBS_OPT_MUTE;
                   1509:            ftp_startup.options&=~FTP_OPT_MUTE;
                   1510:            mail_startup.options&=~MAIL_OPT_MUTE;
                   1511:     }
                   1512: }
                   1513: //---------------------------------------------------------------------------
                   1514: 
                   1515: 
                   1516: 
                   1517: void __fastcall TMainForm::BBSStatisticsLogMenuItemClick(TObject *Sender)
                   1518: {
                   1519:        StatsForm->LogButtonClick(Sender);
                   1520: }
                   1521: //---------------------------------------------------------------------------
                   1522: 
                   1523: void __fastcall TMainForm::ForceTimedEventMenuItemClick(TObject *Sender)
                   1524: {
                   1525:        int i,file;
                   1526:        char str[MAX_PATH+1];
                   1527: 
                   1528:        Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
                   1529:        CodeInputForm->Label->Caption="Event Internal Code";
                   1530:     if(cfg.total_events)
                   1531:        CodeInputForm->Edit->Text=AnsiString(cfg.event[0]->code);
                   1532:     if(CodeInputForm->ShowModal()==mrOk
                   1533:                && CodeInputForm->Edit->Text.Length()) {
                   1534:         for(i=0;i<cfg.total_events;i++) {
                   1535:                        if(!stricmp(CodeInputForm->Edit->Text.c_str(),cfg.event[i]->code)) {
                   1536:                                sprintf(str,"%s%s.now",cfg.data_dir,cfg.event[i]->code);
                   1537:                if((file=_sopen(str,O_CREAT|O_TRUNC|O_WRONLY
                   1538:                        ,SH_DENYRW,S_IREAD|S_IWRITE))!=-1)
                   1539:                        close(file);
                   1540:                 break;
                   1541:                        }
                   1542:         }
                   1543:         if(i>=cfg.total_events)
                   1544:                Application->MessageBox("Event Code Not Found"
                   1545:                        ,CodeInputForm->Edit->Text.c_str(),MB_OK|MB_ICONEXCLAMATION);
                   1546:     }
                   1547:     delete CodeInputForm;
                   1548: }
                   1549: //---------------------------------------------------------------------------
                   1550: 
                   1551: void __fastcall TMainForm::ForceNetworkCalloutMenuItemClick(
                   1552:       TObject *Sender)
                   1553: {
                   1554:        int i,file;
                   1555:        char str[MAX_PATH+1];
                   1556: 
                   1557:        Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
                   1558:        CodeInputForm->Label->Caption="Hub QWK-ID";
                   1559:     if(cfg.total_qhubs)
                   1560:        CodeInputForm->Edit->Text=AnsiString(cfg.qhub[0]->id);
                   1561:     if(CodeInputForm->ShowModal()==mrOk
                   1562:        && CodeInputForm->Edit->Text.Length()) {
                   1563:         for(i=0;i<cfg.total_qhubs;i++) {
                   1564:                        if(!stricmp(CodeInputForm->Edit->Text.c_str(),cfg.qhub[i]->id)) {
                   1565:                                sprintf(str,"%sqnet/%s.now",cfg.data_dir,cfg.qhub[i]->id);
                   1566:                if((file=_sopen(str,O_CREAT|O_TRUNC|O_WRONLY
                   1567:                        ,SH_DENYRW,S_IREAD|S_IWRITE))!=-1)
                   1568:                        close(file);
                   1569:                 break;
                   1570:                        }
                   1571:         }
                   1572:         if(i>=cfg.total_qhubs)
                   1573:                Application->MessageBox("QWKnet Hub ID Not Found"
                   1574:                        ,CodeInputForm->Edit->Text.c_str(),MB_OK|MB_ICONEXCLAMATION);
                   1575:     }
                   1576:     delete CodeInputForm;
                   1577: }
                   1578: //---------------------------------------------------------------------------
                   1579: 
                   1580: void __fastcall TMainForm::TextMenuItemEditClick(TObject *Sender)
                   1581: {
                   1582:        char filename[MAX_PATH+1];
                   1583: 
                   1584:     sprintf(filename,"%s%s"
                   1585:        ,MainForm->cfg.text_dir
                   1586:         ,((TMenuItem*)Sender)->Hint.c_str());
                   1587:        Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
                   1588:        TextFileEditForm->Filename=AnsiString(filename);
                   1589:     TextFileEditForm->Caption=((TMenuItem*)Sender)->Caption;
                   1590:        TextFileEditForm->ShowModal();
                   1591:     delete TextFileEditForm;
                   1592: 
                   1593: }
                   1594: //---------------------------------------------------------------------------
                   1595: 
                   1596: void __fastcall TMainForm::CtrlMenuItemEditClick(TObject *Sender)
                   1597: {
                   1598:        char filename[MAX_PATH+1];
                   1599: 
                   1600:     sprintf(filename,"%s%s"
                   1601:        ,MainForm->cfg.ctrl_dir
                   1602:         ,((TMenuItem*)Sender)->Hint.c_str());
                   1603:        Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
                   1604:        TextFileEditForm->Filename=AnsiString(filename);
                   1605:     TextFileEditForm->Caption=((TMenuItem*)Sender)->Caption;
                   1606:        TextFileEditForm->ShowModal();
                   1607:     delete TextFileEditForm;
                   1608: 
                   1609: }
                   1610: 
                   1611: //---------------------------------------------------------------------------
                   1612: 
                   1613: void __fastcall TMainForm::UpTimerTick(TObject *Sender)
                   1614: {
                   1615:        char    str[128];
                   1616:     char    days[64];
                   1617:     static  time_t start;
                   1618:     ulong   up;
                   1619: 
                   1620:     if(!start)
                   1621:         start=time(NULL);
                   1622:     up=time(NULL)-start;
                   1623: 
                   1624:     days[0]=0;
                   1625:     if((up/(24*60*60))>=2) {
                   1626:         sprintf(days,"%u days ",up/(24*60*60));
                   1627:         up%=(24*60*60);
                   1628:     }
                   1629:     sprintf(str,"Up: %s%u:%02u"
                   1630:         ,days
                   1631:         ,up/(60*60)
                   1632:         ,(up/60)%60
                   1633:         );
                   1634:     AnsiString Str=AnsiString(str);
                   1635:     if(MainForm->StatusBar->Panels->Items[4]->Text!=Str)
                   1636:                MainForm->StatusBar->Panels->Items[4]->Text=Str;
                   1637: }
                   1638: //---------------------------------------------------------------------------
                   1639: 
                   1640: void __fastcall TMainForm::BBSViewErrorLogMenuItemClick(TObject *Sender)
                   1641: {
                   1642:        char filename[MAX_PATH+1];
                   1643: 
                   1644:     sprintf(filename,"%sERROR.LOG"
                   1645:        ,MainForm->cfg.data_dir);
                   1646:        Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
                   1647:        TextFileEditForm->Filename=AnsiString(filename);
                   1648:     TextFileEditForm->Caption="Error Log (See SYSOP.DOC for help)";
                   1649:     TextFileEditForm->Memo->ReadOnly=true;
                   1650:        TextFileEditForm->ShowModal();
                   1651:     delete TextFileEditForm;
                   1652: }
                   1653: //---------------------------------------------------------------------------
                   1654: 
                   1655: void __fastcall TMainForm::ChatToggleExecute(TObject *Sender)
                   1656: {
                   1657:     ChatToggle->Checked=!ChatToggle->Checked;
                   1658:     if(ChatToggle->Checked)
                   1659:            bbs_startup.options|=BBS_OPT_SYSOP_AVAILABLE;
                   1660:     else
                   1661:         bbs_startup.options&=~BBS_OPT_SYSOP_AVAILABLE;
                   1662: 
                   1663: }
                   1664: //---------------------------------------------------------------------------
                   1665: 
                   1666: void __fastcall TMainForm::ViewClientsExecute(TObject *Sender)
                   1667: {
                   1668:        ClientForm->Visible=!ClientForm->Visible;
                   1669:     ViewClients->Checked=ClientForm->Visible;
                   1670: }
                   1671: //---------------------------------------------------------------------------
                   1672: 
                   1673: 
                   1674: void __fastcall TMainForm::UserEditExecute(TObject *Sender)
                   1675: {
                   1676:     char str[256];
                   1677: 
                   1678:     sprintf(str,"%sUSEREDIT %s",cfg.exec_dir,cfg.data_dir);
                   1679:     WinExec(str,SW_SHOWNORMAL);
                   1680: }
                   1681: //---------------------------------------------------------------------------
                   1682: 
                   1683: void __fastcall TMainForm::FileOpenMenuItemClick(TObject *Sender)
                   1684: {
                   1685:     TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
                   1686: 
                   1687:     dlg->Filter = "Text files (*.txt)|*.TXT"
                   1688:                 "|Log files (*.log)|*.LOG"
                   1689:                 "|Config files (*.cfg)|*.CFG"
                   1690:                 "|Message files (*.msg; *.asc)|*.MSG;*.ASC"
                   1691:                 "|Baja Source (*.src)|*.SRC"
                   1692:                 "|All files|*.*";
                   1693:     dlg->InitialDir=cfg.text_dir;
                   1694:     if(dlg->Execute()==true) {
                   1695:         Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
                   1696:         TextFileEditForm->Filename=AnsiString(dlg->FileName);
                   1697:         TextFileEditForm->Caption="Edit";
                   1698:         TextFileEditForm->ShowModal();
                   1699:         delete TextFileEditForm;
                   1700:     }
                   1701:     delete dlg;
                   1702: }
                   1703: //---------------------------------------------------------------------------
                   1704: 
                   1705: 
                   1706: void __fastcall TMainForm::BBSLoginMenuItemClick(TObject *Sender)
                   1707: {
                   1708:     if(!strnicmp(LoginCommand.c_str(),"start ",6))
                   1709:         WinExec(LoginCommand.c_str(),SW_SHOWMINNOACTIVE);
                   1710:     else
                   1711:         WinExec(LoginCommand.c_str(),SW_SHOWNORMAL);
                   1712: 
                   1713: }
                   1714: //---------------------------------------------------------------------------
                   1715: 
                   1716: 
                   1717: void __fastcall TMainForm::ViewLogClick(TObject *Sender)
                   1718: {
                   1719:     char    str[128];
                   1720:        char    filename[MAX_PATH+1];
                   1721:     struct  tm* tm;
                   1722:     time_t  t;
                   1723:     TModalResult mr;
                   1724: 
                   1725:     if(((TMenuItem*)Sender)->Tag==-1) {
                   1726:        Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
                   1727:        CodeInputForm->Label->Caption="Date";
                   1728:                CodeInputForm->Edit->Text=AnsiString(unixtodstr(&cfg,time(NULL),str));
                   1729:         mr=CodeInputForm->ShowModal();
                   1730:         t=dstrtounix(&cfg,CodeInputForm->Edit->Text.c_str());
                   1731:         delete CodeInputForm;
                   1732:         if(mr!=mrOk)
                   1733:             return;
                   1734:     } else {
                   1735:         t=time(NULL);
                   1736:         t-=((TMenuItem*)Sender)->Tag*24*60*60;
                   1737:     }
                   1738:     tm=gmtime(&t);
                   1739:     if(tm==NULL)
                   1740:         return;
                   1741: 
                   1742:     /* Close Mail/FTP logs */
                   1743:     mail_lputs(NULL);
                   1744:     ftp_lputs(NULL);
                   1745: 
                   1746:     sprintf(filename,"%sLOGS\\%s%02d%02d%02d.LOG"
                   1747:        ,MainForm->cfg.data_dir
                   1748:         ,((TMenuItem*)Sender)->Hint.c_str()
                   1749:         ,tm->tm_mon+1
                   1750:         ,tm->tm_mday
                   1751:         ,tm->tm_year%100
                   1752:         );
                   1753:        Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
                   1754:        TextFileEditForm->Filename=AnsiString(filename);
                   1755:     TextFileEditForm->Caption=((TMenuItem*)Sender)->Caption;
                   1756:     TextFileEditForm->Memo->ReadOnly=true;
                   1757:        TextFileEditForm->ShowModal();
                   1758:     delete TextFileEditForm;
                   1759: }
                   1760: //---------------------------------------------------------------------------
                   1761: 
                   1762: 
                   1763: void __fastcall TMainForm::UserListExecute(TObject *Sender)
                   1764: {
                   1765:     UserListForm->Show();
                   1766: }
                   1767: //---------------------------------------------------------------------------
                   1768: 

unix.superglobalmegacorp.com

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