--- sbbs/sbbs3/ctrl/nodeformunit.cpp 2018/04/24 16:39:34 1.1.1.1 +++ sbbs/sbbs3/ctrl/nodeformunit.cpp 2018/04/24 16:40:53 1.1.1.2 @@ -1,12 +1,12 @@ /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */ -/* $Id: nodeformunit.cpp,v 1.1.1.1 2018/04/24 16:39:34 root Exp $ */ +/* $Id: nodeformunit.cpp,v 1.1.1.2 2018/04/24 16:40:53 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -38,8 +38,8 @@ #pragma hdrstop #include #include -#include -#include +#include +#include #include #include #include "NodeFormUnit.h" @@ -57,30 +57,41 @@ TNodeForm *NodeForm; __fastcall TNodeForm::TNodeForm(TComponent* Owner) : TForm(Owner) { -// OutputDebugString("NodeForm constructor\n"); - MainForm=(TMainForm*)Application->MainForm; MainForm->bbs_startup.node_spybuf =(RingBuf**)calloc(1,sizeof(RingBuf*)*MAX_NODES); } //--------------------------------------------------------------------------- - - void __fastcall TNodeForm::FormHide(TObject *Sender) { - MainForm->ViewNodesMenuItem->Checked=false; - MainForm->ViewNodesButton->Down=false; + MainForm->ViewNodes->Checked=false; } //--------------------------------------------------------------------------- +int __fastcall TNodeForm::getnodedat(int node_num, node_t* node, int* file) +{ + char errmsg[128]; + int err; + if((err=::getnodedat(&MainForm->cfg,node_num,node,file))!=0) { + sprintf(errmsg,"getnodedat returned %d",err); + Application->MessageBox(errmsg + ,"ERROR",MB_OK|MB_ICONEXCLAMATION); + } - - -void __fastcall TNodeForm::FormShow(TObject *Sender) + return(err); +} +//--------------------------------------------------------------------------- +int __fastcall TNodeForm::putnodedat(int node_num, node_t* node, int file) { -// OutputDebugString("NodeForm::FormShow\n"); + char errmsg[128]; + int err; + + if((err=::putnodedat(&MainForm->cfg,node_num,node, file))!=0) { + sprintf(errmsg,"putnodedat(%d) returned %d",file,err); + Application->MessageBox(errmsg + ,"ERROR",MB_OK|MB_ICONEXCLAMATION); + } - MainForm->ViewNodesMenuItem->Checked=true; - MainForm->ViewNodesButton->Down=true; + return(err); } //--------------------------------------------------------------------------- @@ -117,246 +128,64 @@ char* username(int usernumber,char *stri void __fastcall TNodeForm::TimerTick(TObject *Sender) { static int nodedab; - char str[128],tmp[128],mer[10]; - int i,n,hour; + char str[256]; + char status[128]; + int i,n,rd,digits=1; node_t node; + if(!Visible) + return; + if(nodedab<1) { - nodedab=_sopen(AnsiString(MainForm->CtrlDirectory+"NODE.DAB").c_str() - ,O_RDWR|O_BINARY|O_CREAT, SH_DENYNONE, S_IREAD|S_IWRITE); + char path[MAX_PATH+1]; + sprintf(path,"%sNODE.DAB",MainForm->global.ctrl_dir); + nodedab=_sopen(path,O_RDONLY|O_BINARY|O_CREAT, SH_DENYNONE, S_IREAD|S_IWRITE); if(nodedab==-1) { ListBox->Items->Clear(); - ListBox->Items->Add("Error opening NODE.DAB"); + ListBox->Items->Add("Error "+AnsiString(errno)+" opening NODE.DAB"); return; } } + if(MainForm->cfg.sys_nodes>9) + digits++; + if(MainForm->cfg.sys_nodes>99) + digits++; + if(MainForm->cfg.sys_nodes>999) + digits++; for(n=0;ncfg.sys_nodes;n++) { lseek(nodedab, n*sizeof(node_t), SEEK_SET); if(eof(nodedab)) break; - i=locking(nodedab, LK_LOCK, sizeof(node_t)); - if(i) { - ListBox->Items->Add("Error "+AnsiString(i)+" reading record for" - " node "+AnsiString(n+1)); - continue; - } - read(nodedab,&node, sizeof(node_t)); +#ifdef USE_LOCKING + if(locking(nodedab, LK_NBLCK, sizeof(node_t))!=0) + continue; +#endif + memset(&node,0,sizeof(node_t)); + rd=read(nodedab,&node, sizeof(node_t)); +#ifdef USE_LOCKING lseek(nodedab, n*sizeof(node_t), SEEK_SET); locking(nodedab, LK_UNLCK, sizeof(node_t)); - sprintf(str,"%3d ",n+1); - switch(node.status) { - case NODE_WFC: - strcat(str,"Waiting for call"); - break; - case NODE_OFFLINE: - strcat(str,"Offline"); - break; - case NODE_NETTING: - strcat(str,"Networking"); - break; - case NODE_LOGON: - strcat(str,"At logon prompt"); - break; - case NODE_EVENT_WAITING: - strcat(str,"Waiting for all nodes to become inactive"); - break; - case NODE_EVENT_LIMBO: - sprintf(str,"Waiting for node %d to finish external event" - ,node.aux); - break; - case NODE_EVENT_RUNNING: - strcat(str,"Running external event"); - break; - case NODE_NEWUSER: - strcat(str,"New user"); - strcat(str," applying for access "); - if(!node.connection) - strcat(str,"Locally"); - else if(node.connection==0xffff) { - strcat(str,"via telnet"); - } else { - sprintf(tmp,"at %ubps",node.connection); - strcat(str,tmp); - } - break; - case NODE_QUIET: - case NODE_INUSE: -// sprintf(tmp, "User #%d ",node.useron); - username(node.useron,tmp); - strcat(str,tmp); - strcat(str," "); - switch(node.action) { - case NODE_MAIN: - strcat(str,"at main menu"); - break; - case NODE_RMSG: - strcat(str,"reading messages"); - break; - case NODE_RMAL: - strcat(str,"reading mail"); - break; - case NODE_RSML: - strcat(str,"reading sent mail"); - break; - case NODE_RTXT: - strcat(str,"reading text files"); - break; - case NODE_PMSG: - strcat(str,"posting message"); - break; - case NODE_SMAL: - strcat(str,"sending mail"); - break; - case NODE_AMSG: - strcat(str,"posting auto-message"); - break; - case NODE_XTRN: - if(!node.aux) - strcat(str,"at external program menu"); - else if(node.aux<=MainForm->cfg.total_xtrns) { - sprintf(tmp,"running %s" - ,MainForm->cfg.xtrn[node.aux-1]->name); - strcat(str,tmp); - } else { - sprintf(tmp,"running external program #%d" - ,node.aux); - strcat(str,tmp); - } - break; - case NODE_DFLT: - strcat(str,"changing defaults"); - break; - case NODE_XFER: - strcat(str,"at transfer menu"); - break; - case NODE_RFSD: - sprintf(tmp,"retrieving from device #%d",node.aux); - strcat(str,tmp); - break; - case NODE_DLNG: - strcat(str,"downloading"); - break; - case NODE_ULNG: - strcat(str,"uploading"); - break; - case NODE_BXFR: - strcat(str,"transferring bidirectional"); - break; - case NODE_LFIL: - strcat(str,"listing files"); - break; - case NODE_LOGN: - strcat(str,"logging on"); - break; - case NODE_LCHT: - strcat(str,"in local chat with sysop"); - break; - case NODE_MCHT: - if(node.aux) { - sprintf(tmp,"in multinode chat channel %d" - ,node.aux&0xff); - if(node.aux&0x1f00) { /* password */ - strcat(tmp,"* "); -// strcat(tmp, unpackchatpass(tmp,node)); - } - strcat(str,tmp); - } - else - strcat(str,"in multinode global chat channel"); - break; - case NODE_PAGE: - sprintf(tmp,"paging node %u for private chat",node.aux); - strcat(str,tmp); - break; - case NODE_PCHT: - if(!node.aux) - strcat(str,"in local chat with sysop"); - else { - sprintf(tmp,"in private chat with node %u" - ,node.aux); - strcat(str,tmp); - } - break; - case NODE_GCHT: - strcat(str,"chatting with The Guru"); - break; - case NODE_CHAT: - strcat(str,"in chat section"); - break; - case NODE_TQWK: - strcat(str,"transferring QWK packet"); - break; - case NODE_SYSP: - strcat(str,"performing sysop activities"); - break; - default: - strcat(str,itoa(node.action,tmp,10)); - break; } - if(!node.connection) - strcat(str," locally"); - if(node.connection==0xffff) { - strcat(str," via telnet"); - } else { - sprintf(tmp," at %ubps",node.connection); - strcat(str,tmp); - } - if(node.action==NODE_DLNG) { - if((node.aux/60)>=12) { - if(node.aux/60==12) - hour=12; - else - hour=(node.aux/60)-12; - strcpy(mer,"pm"); } - else { - if((node.aux/60)==0) /* 12 midnite */ - hour=12; - else hour=node.aux/60; - strcpy(mer,"am"); } - sprintf(tmp, " ETA %02d:%02d %s" - ,hour,node.aux-((node.aux/60)*60),mer); - strcat(str, tmp); } - break; } - if(node.misc&(NODE_LOCK|NODE_POFF|NODE_AOFF|NODE_MSGW|NODE_NMSG)) { - strcat(str," ("); - if(node.misc&NODE_AOFF) - strcat(str,"A"); - if(node.misc&NODE_LOCK) - strcat(str,"L"); - if(node.misc&(NODE_MSGW|NODE_NMSG)) - strcat(str,"M"); - if(node.misc&NODE_POFF) - strcat(str,"P"); - strcat(str,")"); } - if(((node.misc - &(NODE_ANON|NODE_UDAT|NODE_INTR|NODE_RRUN|NODE_EVENT|NODE_DOWN)) - || node.status==NODE_QUIET)) { - strcat(str," ["); - if(node.misc&NODE_ANON) - strcat(str,"A"); - if(node.misc&NODE_INTR) - strcat(str,"I"); - if(node.misc&NODE_RRUN) - strcat(str,"R"); - if(node.misc&NODE_UDAT) - strcat(str,"U"); - if(node.status==NODE_QUIET) - strcat(str,"Q"); - if(node.misc&NODE_EVENT) - strcat(str,"E"); - if(node.misc&NODE_DOWN) - strcat(str,"D"); - if(node.misc&NODE_LCHAT) - strcat(str,"C"); - strcat(str,"]"); } - if(node.errors) { - sprintf(tmp, " %d error%c",node.errors, node.errors>1 ? 's' : '\0' ); - strcat(str,tmp); - } +#endif + + if(rd!=sizeof(node_t)) + continue; + + sprintf(str,"%*d %s" + ,digits + ,n+1 + ,nodestatus(&MainForm->cfg,&node,status,sizeof(status))); AnsiString Str=AnsiString(str); if(ListBox->Items->CountItems->Add(Str); - else if(ListBox->Items->Strings[n]!=Str) + else if(ListBox->Items->Strings[n]!=Str) { + bool selected=ListBox->Selected[n]; // save selected state ListBox->Items->Strings[n]=str; + ListBox->Selected[n]=selected; // restore + } + } + if(n!=MainForm->cfg.sys_nodes) { /* read error or something */ + close(nodedab); + nodedab=-1; } Timer->Enabled=true; } @@ -367,52 +196,58 @@ void __fastcall TNodeForm::TimerTick(TOb void __fastcall TNodeForm::InterruptNodeButtonClick(TObject *Sender) { int i; + int file; node_t node; for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,1); + if(getnodedat(i+1,&node,&file)) + break; node.misc^=NODE_INTR; - putnodedat(&MainForm->cfg,i+1,&node); + if(putnodedat(i+1,&node,file)) + break; } + TimerTick(Sender); } //--------------------------------------------------------------------------- void __fastcall TNodeForm::LockNodeButtonClick(TObject *Sender) { int i; + int file; node_t node; for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,1); + if(getnodedat(i+1,&node,&file)) + break; node.misc^=NODE_LOCK; - putnodedat(&MainForm->cfg,i+1,&node); + if(putnodedat(i+1,&node,file)) + break; } + TimerTick(Sender); } //--------------------------------------------------------------------------- void __fastcall TNodeForm::RerunNodeButtonClick(TObject *Sender) { int i; + int file; node_t node; for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,1); + if(getnodedat(i+1,&node,&file)) + break; node.misc^=NODE_RRUN; - putnodedat(&MainForm->cfg,i+1,&node); + if(putnodedat(i+1,&node,file)) + break; } + TimerTick(Sender); } //--------------------------------------------------------------------------- -void __fastcall TNodeForm::ListBoxKeyPress(TObject *Sender, char &Key) -{ - if(Key==1) // ctrl-a - SelectAllMenuItemClick(Sender); -} -//--------------------------------------------------------------------------- void __fastcall TNodeForm::SelectAllMenuItemClick(TObject *Sender) { @@ -427,33 +262,41 @@ void __fastcall TNodeForm::SelectAllMenu void __fastcall TNodeForm::DownButtonClick(TObject *Sender) { int i; + int file; node_t node; for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,1); + if(getnodedat(i+1,&node,&file)) + break; if(node.status==NODE_WFC) node.status=NODE_OFFLINE; else if(node.status==NODE_OFFLINE) node.status=NODE_WFC; else node.misc^=NODE_DOWN; - putnodedat(&MainForm->cfg,i+1,&node); + if(putnodedat(i+1,&node,file)) + break; } + TimerTick(Sender); } //--------------------------------------------------------------------------- void __fastcall TNodeForm::ClearErrorButtonClick(TObject *Sender) { int i; + int file; node_t node; for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,1); + if(getnodedat(i+1,&node,&file)) + break; node.errors=0; - putnodedat(&MainForm->cfg,i+1,&node); + if(putnodedat(i+1,&node,file)) + break; } + TimerTick(Sender); } //--------------------------------------------------------------------------- @@ -466,7 +309,8 @@ void __fastcall TNodeForm::ChatButtonCli for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,0); + if(getnodedat(i+1,&node,NULL)) + break; if(node.status==NODE_WFC || node.status>NODE_QUIET) continue; sprintf(str,"%sCHAT %s %s %d %s" @@ -478,6 +322,7 @@ void __fastcall TNodeForm::ChatButtonCli ); WinExec(str,SW_SHOWNORMAL); } + TimerTick(Sender); } //--------------------------------------------------------------------------- @@ -495,6 +340,7 @@ void __fastcall TNodeForm::SpyButtonClic } SpyForms[i]->Show(); } + TimerTick(Sender); } //--------------------------------------------------------------------------- @@ -506,7 +352,8 @@ void __fastcall TNodeForm::UserEditButto for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,0); + if(getnodedat(i+1,&node,NULL)) + break; if(node.useron==0) continue; sprintf(str,"%sUSEREDIT %s %d" @@ -515,6 +362,7 @@ void __fastcall TNodeForm::UserEditButto ,node.useron); WinExec(str,SW_SHOWNORMAL); } + TimerTick(Sender); } //--------------------------------------------------------------------------- @@ -530,7 +378,8 @@ void __fastcall TNodeForm::UserMsgButton UserMsgForm->Memo->Lines->Add(""); for(i=0;iItems->Count;i++) if(ListBox->Selected[i]==true) { - getnodedat(&MainForm->cfg,i+1,&node,0); + if(getnodedat(i+1,&node,NULL)) + break; if(node.useron==0) continue; putsmsg(&MainForm->cfg,node.useron @@ -538,6 +387,14 @@ void __fastcall TNodeForm::UserMsgButton } } delete UserMsgForm; + TimerTick(Sender); +} +//--------------------------------------------------------------------------- + +void __fastcall TNodeForm::RefreshMenuItemClick(TObject *Sender) +{ + ListBox->Clear(); + TimerTick(Sender); } //---------------------------------------------------------------------------