|
|
1.1 ! root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */ ! 2: ! 3: /* $Id: NodeFormUnit.cpp,v 1.28 2006/09/24 19:56:04 deuce 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 2004 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 "sbbs.h" ! 38: #include <vcl.h> ! 39: #pragma hdrstop ! 40: #include <io.h> ! 41: #include <stdio.h> ! 42: #include <sys/stat.h> ! 43: #include <sys/locking.h> ! 44: #include <fcntl.h> ! 45: #include <share.h> ! 46: #include "NodeFormUnit.h" ! 47: #include "UserMsgFormUnit.h" ! 48: #include "SpyFormUnit.h" ! 49: #include "nodedefs.h" ! 50: #include "userdat.h" ! 51: #include "ringbuf.h" ! 52: //--------------------------------------------------------------------------- ! 53: #pragma package(smart_init) ! 54: #pragma resource "*.dfm" ! 55: TNodeForm *NodeForm; ! 56: //--------------------------------------------------------------------------- ! 57: __fastcall TNodeForm::TNodeForm(TComponent* Owner) ! 58: : TForm(Owner) ! 59: { ! 60: MainForm->bbs_startup.node_spybuf ! 61: =(RingBuf**)calloc(1,sizeof(RingBuf*)*MAX_NODES); ! 62: } ! 63: //--------------------------------------------------------------------------- ! 64: void __fastcall TNodeForm::FormHide(TObject *Sender) ! 65: { ! 66: MainForm->ViewNodes->Checked=false; ! 67: } ! 68: //--------------------------------------------------------------------------- ! 69: int __fastcall TNodeForm::getnodedat(int node_num, node_t* node, int* file) ! 70: { ! 71: char errmsg[128]; ! 72: int err; ! 73: ! 74: if((err=::getnodedat(&MainForm->cfg,node_num,node,file))!=0) { ! 75: sprintf(errmsg,"getnodedat returned %d",err); ! 76: Application->MessageBox(errmsg ! 77: ,"ERROR",MB_OK|MB_ICONEXCLAMATION); ! 78: } ! 79: ! 80: return(err); ! 81: } ! 82: //--------------------------------------------------------------------------- ! 83: int __fastcall TNodeForm::putnodedat(int node_num, node_t* node, int file) ! 84: { ! 85: char errmsg[128]; ! 86: int err; ! 87: ! 88: if((err=::putnodedat(&MainForm->cfg,node_num,node, file))!=0) { ! 89: sprintf(errmsg,"putnodedat(%d) returned %d",file,err); ! 90: Application->MessageBox(errmsg ! 91: ,"ERROR",MB_OK|MB_ICONEXCLAMATION); ! 92: } ! 93: ! 94: return(err); ! 95: } ! 96: //--------------------------------------------------------------------------- ! 97: ! 98: char* username(int usernumber,char *strin) ! 99: { ! 100: char str[256]; ! 101: char c; ! 102: int file; ! 103: ! 104: if(usernumber<1) { ! 105: strcpy(strin,"UNKNOWN USER"); ! 106: return(strin); ! 107: } ! 108: sprintf(str,"%suser/name.dat",MainForm->cfg.data_dir); ! 109: if((file=_sopen(str,O_RDONLY,SH_DENYWR,S_IWRITE))==-1) { ! 110: return("<!ERROR opening name.dat>"); ! 111: } ! 112: if(filelength(file)<(long)((long)usernumber*(LEN_ALIAS+2))) { ! 113: close(file); ! 114: strcpy(strin,"UNKNOWN USER"); ! 115: return(strin); ! 116: } ! 117: lseek(file,(long)((long)(usernumber-1)*(LEN_ALIAS+2)),SEEK_SET); ! 118: read(file,strin,LEN_ALIAS); ! 119: close(file); ! 120: for(c=0;c<LEN_ALIAS;c++) ! 121: if(strin[c]==ETX) break; ! 122: strin[c]=0; ! 123: if(!c) ! 124: strcpy(strin,"DELETED USER"); ! 125: return(strin); ! 126: } ! 127: ! 128: void __fastcall TNodeForm::TimerTick(TObject *Sender) ! 129: { ! 130: static int nodedab; ! 131: char str[256]; ! 132: char status[128]; ! 133: int i,n,rd,digits=1; ! 134: node_t node; ! 135: ! 136: if(!Visible) ! 137: return; ! 138: ! 139: if(nodedab<1) { ! 140: char path[MAX_PATH+1]; ! 141: sprintf(path,"%sNODE.DAB",MainForm->global.ctrl_dir); ! 142: nodedab=_sopen(path,O_RDONLY|O_BINARY|O_CREAT, SH_DENYNONE, S_IREAD|S_IWRITE); ! 143: if(nodedab==-1) { ! 144: ListBox->Items->Clear(); ! 145: ListBox->Items->Add("Error "+AnsiString(errno)+" opening NODE.DAB"); ! 146: return; ! 147: } ! 148: } ! 149: if(MainForm->cfg.sys_nodes>9) ! 150: digits++; ! 151: if(MainForm->cfg.sys_nodes>99) ! 152: digits++; ! 153: if(MainForm->cfg.sys_nodes>999) ! 154: digits++; ! 155: for(n=0;n<MainForm->cfg.sys_nodes;n++) { ! 156: lseek(nodedab, n*sizeof(node_t), SEEK_SET); ! 157: if(eof(nodedab)) ! 158: break; ! 159: #ifdef USE_LOCKING ! 160: if(locking(nodedab, LK_NBLCK, sizeof(node_t))!=0) ! 161: continue; ! 162: #endif ! 163: memset(&node,0,sizeof(node_t)); ! 164: rd=read(nodedab,&node, sizeof(node_t)); ! 165: #ifdef USE_LOCKING ! 166: lseek(nodedab, n*sizeof(node_t), SEEK_SET); ! 167: locking(nodedab, LK_UNLCK, sizeof(node_t)); ! 168: #endif ! 169: ! 170: if(rd!=sizeof(node_t)) ! 171: continue; ! 172: ! 173: sprintf(str,"%*d %s" ! 174: ,digits ! 175: ,n+1 ! 176: ,nodestatus(&MainForm->cfg,&node,status,sizeof(status))); ! 177: AnsiString Str=AnsiString(str); ! 178: if(ListBox->Items->Count<n+1) ! 179: ListBox->Items->Add(Str); ! 180: else if(ListBox->Items->Strings[n]!=Str) { ! 181: bool selected=ListBox->Selected[n]; // save selected state ! 182: ListBox->Items->Strings[n]=str; ! 183: ListBox->Selected[n]=selected; // restore ! 184: } ! 185: } ! 186: if(n!=MainForm->cfg.sys_nodes) { /* read error or something */ ! 187: close(nodedab); ! 188: nodedab=-1; ! 189: } ! 190: Timer->Enabled=true; ! 191: } ! 192: //--------------------------------------------------------------------------- ! 193: ! 194: ! 195: ! 196: void __fastcall TNodeForm::InterruptNodeButtonClick(TObject *Sender) ! 197: { ! 198: int i; ! 199: int file; ! 200: node_t node; ! 201: ! 202: for(i=0;i<ListBox->Items->Count;i++) ! 203: if(ListBox->Selected[i]==true) { ! 204: if(getnodedat(i+1,&node,&file)) ! 205: break; ! 206: node.misc^=NODE_INTR; ! 207: if(putnodedat(i+1,&node,file)) ! 208: break; ! 209: } ! 210: TimerTick(Sender); ! 211: } ! 212: //--------------------------------------------------------------------------- ! 213: ! 214: void __fastcall TNodeForm::LockNodeButtonClick(TObject *Sender) ! 215: { ! 216: int i; ! 217: int file; ! 218: node_t node; ! 219: ! 220: for(i=0;i<ListBox->Items->Count;i++) ! 221: if(ListBox->Selected[i]==true) { ! 222: if(getnodedat(i+1,&node,&file)) ! 223: break; ! 224: node.misc^=NODE_LOCK; ! 225: if(putnodedat(i+1,&node,file)) ! 226: break; ! 227: } ! 228: TimerTick(Sender); ! 229: } ! 230: //--------------------------------------------------------------------------- ! 231: ! 232: void __fastcall TNodeForm::RerunNodeButtonClick(TObject *Sender) ! 233: { ! 234: int i; ! 235: int file; ! 236: node_t node; ! 237: ! 238: for(i=0;i<ListBox->Items->Count;i++) ! 239: if(ListBox->Selected[i]==true) { ! 240: if(getnodedat(i+1,&node,&file)) ! 241: break; ! 242: node.misc^=NODE_RRUN; ! 243: if(putnodedat(i+1,&node,file)) ! 244: break; ! 245: } ! 246: TimerTick(Sender); ! 247: } ! 248: ! 249: //--------------------------------------------------------------------------- ! 250: ! 251: ! 252: void __fastcall TNodeForm::SelectAllMenuItemClick(TObject *Sender) ! 253: { ! 254: int i; ! 255: ! 256: for(i=0;i<ListBox->Items->Count;i++) ! 257: ListBox->Selected[i]=true; ! 258: ! 259: } ! 260: //--------------------------------------------------------------------------- ! 261: ! 262: void __fastcall TNodeForm::DownButtonClick(TObject *Sender) ! 263: { ! 264: int i; ! 265: int file; ! 266: node_t node; ! 267: ! 268: for(i=0;i<ListBox->Items->Count;i++) ! 269: if(ListBox->Selected[i]==true) { ! 270: if(getnodedat(i+1,&node,&file)) ! 271: break; ! 272: if(node.status==NODE_WFC) ! 273: node.status=NODE_OFFLINE; ! 274: else if(node.status==NODE_OFFLINE) ! 275: node.status=NODE_WFC; ! 276: else ! 277: node.misc^=NODE_DOWN; ! 278: if(putnodedat(i+1,&node,file)) ! 279: break; ! 280: } ! 281: TimerTick(Sender); ! 282: } ! 283: //--------------------------------------------------------------------------- ! 284: ! 285: void __fastcall TNodeForm::ClearErrorButtonClick(TObject *Sender) ! 286: { ! 287: int i; ! 288: int file; ! 289: node_t node; ! 290: ! 291: for(i=0;i<ListBox->Items->Count;i++) ! 292: if(ListBox->Selected[i]==true) { ! 293: if(getnodedat(i+1,&node,&file)) ! 294: break; ! 295: node.errors=0; ! 296: if(putnodedat(i+1,&node,file)) ! 297: break; ! 298: } ! 299: TimerTick(Sender); ! 300: } ! 301: //--------------------------------------------------------------------------- ! 302: ! 303: void __fastcall TNodeForm::ChatButtonClick(TObject *Sender) ! 304: { ! 305: char str[512]; ! 306: char name[128]; ! 307: int i; ! 308: node_t node; ! 309: ! 310: for(i=0;i<ListBox->Items->Count;i++) ! 311: if(ListBox->Selected[i]==true) { ! 312: if(getnodedat(i+1,&node,NULL)) ! 313: break; ! 314: if(node.status==NODE_WFC || node.status>NODE_QUIET) ! 315: continue; ! 316: sprintf(str,"%sCHAT %s %s %d %s" ! 317: ,MainForm->cfg.exec_dir ! 318: ,MainForm->cfg.ctrl_dir ! 319: ,MainForm->cfg.node_path[i] ! 320: ,i+1 ! 321: ,username(node.useron,name) ! 322: ); ! 323: WinExec(str,SW_SHOWNORMAL); ! 324: } ! 325: TimerTick(Sender); ! 326: } ! 327: //--------------------------------------------------------------------------- ! 328: ! 329: void __fastcall TNodeForm::SpyButtonClick(TObject *Sender) ! 330: { ! 331: int i; ! 332: ! 333: for(i=0;i<ListBox->Items->Count;i++) ! 334: if(ListBox->Selected[i]==true) { ! 335: if(SpyForms[i]==NULL) { ! 336: Application->CreateForm(__classid(TSpyForm), &SpyForms[i]); ! 337: SpyForms[i]->inbuf=&MainForm->bbs_startup.node_inbuf[i]; ! 338: SpyForms[i]->outbuf=&MainForm->bbs_startup.node_spybuf[i]; ! 339: SpyForms[i]->Caption="Node "+AnsiString(i+1); ! 340: } ! 341: SpyForms[i]->Show(); ! 342: } ! 343: TimerTick(Sender); ! 344: } ! 345: //--------------------------------------------------------------------------- ! 346: ! 347: void __fastcall TNodeForm::UserEditButtonClick(TObject *Sender) ! 348: { ! 349: int i; ! 350: char str[128]; ! 351: node_t node; ! 352: ! 353: for(i=0;i<ListBox->Items->Count;i++) ! 354: if(ListBox->Selected[i]==true) { ! 355: if(getnodedat(i+1,&node,NULL)) ! 356: break; ! 357: if(node.useron==0) ! 358: continue; ! 359: sprintf(str,"%sUSEREDIT %s %d" ! 360: ,MainForm->cfg.exec_dir ! 361: ,MainForm->cfg.data_dir ! 362: ,node.useron); ! 363: WinExec(str,SW_SHOWNORMAL); ! 364: } ! 365: TimerTick(Sender); ! 366: } ! 367: //--------------------------------------------------------------------------- ! 368: ! 369: void __fastcall TNodeForm::UserMsgButtonClick(TObject *Sender) ! 370: { ! 371: int i; ! 372: node_t node; ! 373: ! 374: Application->CreateForm(__classid(TUserMsgForm), &UserMsgForm); ! 375: UserMsgForm->Memo->Text="\1n\1y\1hMessage From Sysop:\1w "; ! 376: UserMsgForm->Memo->SelStart=UserMsgForm->Memo->Text.Length(); ! 377: if(UserMsgForm->ShowModal()==mrOk) { ! 378: UserMsgForm->Memo->Lines->Add(""); ! 379: for(i=0;i<ListBox->Items->Count;i++) ! 380: if(ListBox->Selected[i]==true) { ! 381: if(getnodedat(i+1,&node,NULL)) ! 382: break; ! 383: if(node.useron==0) ! 384: continue; ! 385: putsmsg(&MainForm->cfg,node.useron ! 386: ,UserMsgForm->Memo->Text.c_str()); ! 387: } ! 388: } ! 389: delete UserMsgForm; ! 390: TimerTick(Sender); ! 391: } ! 392: //--------------------------------------------------------------------------- ! 393: ! 394: void __fastcall TNodeForm::RefreshMenuItemClick(TObject *Sender) ! 395: { ! 396: ListBox->Clear(); ! 397: TimerTick(Sender); ! 398: } ! 399: //--------------------------------------------------------------------------- ! 400:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.