|
|
1.1 ! root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */ ! 2: ! 3: /* $Id: NodeFormUnit.cpp,v 1.9 2000/12/01 18:46:06 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: #pragma hdrstop ! 39: #include <io.h> ! 40: #include <stdio.h> ! 41: #include <sys\stat.h> ! 42: #include <sys\locking.h> ! 43: #include <fcntl.h> ! 44: #include <share.h> ! 45: #include "NodeFormUnit.h" ! 46: #include "UserMsgFormUnit.h" ! 47: #include "SpyFormUnit.h" ! 48: #include "sbbs.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: // OutputDebugString("NodeForm constructor\n"); ! 61: MainForm=(TMainForm*)Application->MainForm; ! 62: MainForm->bbs_startup.node_spybuf ! 63: =(RingBuf**)calloc(1,sizeof(RingBuf*)*MAX_NODES); ! 64: } ! 65: //--------------------------------------------------------------------------- ! 66: ! 67: ! 68: void __fastcall TNodeForm::FormHide(TObject *Sender) ! 69: { ! 70: MainForm->ViewNodesMenuItem->Checked=false; ! 71: MainForm->ViewNodesButton->Down=false; ! 72: } ! 73: //--------------------------------------------------------------------------- ! 74: ! 75: ! 76: ! 77: ! 78: void __fastcall TNodeForm::FormShow(TObject *Sender) ! 79: { ! 80: // OutputDebugString("NodeForm::FormShow\n"); ! 81: ! 82: MainForm->ViewNodesMenuItem->Checked=true; ! 83: MainForm->ViewNodesButton->Down=true; ! 84: } ! 85: //--------------------------------------------------------------------------- ! 86: ! 87: char* username(int usernumber,char *strin) ! 88: { ! 89: char str[256]; ! 90: char c; ! 91: int file; ! 92: ! 93: if(usernumber<1) { ! 94: strcpy(strin,"UNKNOWN USER"); ! 95: return(strin); ! 96: } ! 97: sprintf(str,"%suser/name.dat",MainForm->cfg.data_dir); ! 98: if((file=_sopen(str,O_RDONLY,SH_DENYWR,S_IWRITE))==-1) { ! 99: return("<!ERROR opening name.dat>"); ! 100: } ! 101: if(filelength(file)<(long)((long)usernumber*(LEN_ALIAS+2))) { ! 102: close(file); ! 103: strcpy(strin,"UNKNOWN USER"); ! 104: return(strin); ! 105: } ! 106: lseek(file,(long)((long)(usernumber-1)*(LEN_ALIAS+2)),SEEK_SET); ! 107: read(file,strin,LEN_ALIAS); ! 108: close(file); ! 109: for(c=0;c<LEN_ALIAS;c++) ! 110: if(strin[c]==ETX) break; ! 111: strin[c]=0; ! 112: if(!c) ! 113: strcpy(strin,"DELETED USER"); ! 114: return(strin); ! 115: } ! 116: ! 117: void __fastcall TNodeForm::TimerTick(TObject *Sender) ! 118: { ! 119: static int nodedab; ! 120: char str[128],tmp[128],mer[10]; ! 121: int i,n,hour; ! 122: node_t node; ! 123: ! 124: if(nodedab<1) { ! 125: nodedab=_sopen(AnsiString(MainForm->CtrlDirectory+"NODE.DAB").c_str() ! 126: ,O_RDWR|O_BINARY|O_CREAT, SH_DENYNONE, S_IREAD|S_IWRITE); ! 127: if(nodedab==-1) { ! 128: ListBox->Items->Clear(); ! 129: ListBox->Items->Add("Error opening NODE.DAB"); ! 130: return; ! 131: } ! 132: } ! 133: for(n=0;n<MainForm->cfg.sys_nodes;n++) { ! 134: lseek(nodedab, n*sizeof(node_t), SEEK_SET); ! 135: if(eof(nodedab)) ! 136: break; ! 137: i=locking(nodedab, LK_LOCK, sizeof(node_t)); ! 138: if(i) { ! 139: ListBox->Items->Add("Error "+AnsiString(i)+" reading record for" ! 140: " node "+AnsiString(n+1)); ! 141: continue; ! 142: } ! 143: read(nodedab,&node, sizeof(node_t)); ! 144: lseek(nodedab, n*sizeof(node_t), SEEK_SET); ! 145: locking(nodedab, LK_UNLCK, sizeof(node_t)); ! 146: sprintf(str,"%3d ",n+1); ! 147: switch(node.status) { ! 148: case NODE_WFC: ! 149: strcat(str,"Waiting for call"); ! 150: break; ! 151: case NODE_OFFLINE: ! 152: strcat(str,"Offline"); ! 153: break; ! 154: case NODE_NETTING: ! 155: strcat(str,"Networking"); ! 156: break; ! 157: case NODE_LOGON: ! 158: strcat(str,"At logon prompt"); ! 159: break; ! 160: case NODE_EVENT_WAITING: ! 161: strcat(str,"Waiting for all nodes to become inactive"); ! 162: break; ! 163: case NODE_EVENT_LIMBO: ! 164: sprintf(str,"Waiting for node %d to finish external event" ! 165: ,node.aux); ! 166: break; ! 167: case NODE_EVENT_RUNNING: ! 168: strcat(str,"Running external event"); ! 169: break; ! 170: case NODE_NEWUSER: ! 171: strcat(str,"New user"); ! 172: strcat(str," applying for access "); ! 173: if(!node.connection) ! 174: strcat(str,"Locally"); ! 175: else if(node.connection==0xffff) { ! 176: strcat(str,"via telnet"); ! 177: } else { ! 178: sprintf(tmp,"at %ubps",node.connection); ! 179: strcat(str,tmp); ! 180: } ! 181: break; ! 182: case NODE_QUIET: ! 183: case NODE_INUSE: ! 184: // sprintf(tmp, "User #%d ",node.useron); ! 185: username(node.useron,tmp); ! 186: strcat(str,tmp); ! 187: strcat(str," "); ! 188: switch(node.action) { ! 189: case NODE_MAIN: ! 190: strcat(str,"at main menu"); ! 191: break; ! 192: case NODE_RMSG: ! 193: strcat(str,"reading messages"); ! 194: break; ! 195: case NODE_RMAL: ! 196: strcat(str,"reading mail"); ! 197: break; ! 198: case NODE_RSML: ! 199: strcat(str,"reading sent mail"); ! 200: break; ! 201: case NODE_RTXT: ! 202: strcat(str,"reading text files"); ! 203: break; ! 204: case NODE_PMSG: ! 205: strcat(str,"posting message"); ! 206: break; ! 207: case NODE_SMAL: ! 208: strcat(str,"sending mail"); ! 209: break; ! 210: case NODE_AMSG: ! 211: strcat(str,"posting auto-message"); ! 212: break; ! 213: case NODE_XTRN: ! 214: if(!node.aux) ! 215: strcat(str,"at external program menu"); ! 216: else if(node.aux<=MainForm->cfg.total_xtrns) { ! 217: sprintf(tmp,"running %s" ! 218: ,MainForm->cfg.xtrn[node.aux-1]->name); ! 219: strcat(str,tmp); ! 220: } else { ! 221: sprintf(tmp,"running external program #%d" ! 222: ,node.aux); ! 223: strcat(str,tmp); ! 224: } ! 225: break; ! 226: case NODE_DFLT: ! 227: strcat(str,"changing defaults"); ! 228: break; ! 229: case NODE_XFER: ! 230: strcat(str,"at transfer menu"); ! 231: break; ! 232: case NODE_RFSD: ! 233: sprintf(tmp,"retrieving from device #%d",node.aux); ! 234: strcat(str,tmp); ! 235: break; ! 236: case NODE_DLNG: ! 237: strcat(str,"downloading"); ! 238: break; ! 239: case NODE_ULNG: ! 240: strcat(str,"uploading"); ! 241: break; ! 242: case NODE_BXFR: ! 243: strcat(str,"transferring bidirectional"); ! 244: break; ! 245: case NODE_LFIL: ! 246: strcat(str,"listing files"); ! 247: break; ! 248: case NODE_LOGN: ! 249: strcat(str,"logging on"); ! 250: break; ! 251: case NODE_LCHT: ! 252: strcat(str,"in local chat with sysop"); ! 253: break; ! 254: case NODE_MCHT: ! 255: if(node.aux) { ! 256: sprintf(tmp,"in multinode chat channel %d" ! 257: ,node.aux&0xff); ! 258: if(node.aux&0x1f00) { /* password */ ! 259: strcat(tmp,"* "); ! 260: // strcat(tmp, unpackchatpass(tmp,node)); ! 261: } ! 262: strcat(str,tmp); ! 263: } ! 264: else ! 265: strcat(str,"in multinode global chat channel"); ! 266: break; ! 267: case NODE_PAGE: ! 268: sprintf(tmp,"paging node %u for private chat",node.aux); ! 269: strcat(str,tmp); ! 270: break; ! 271: case NODE_PCHT: ! 272: if(!node.aux) ! 273: strcat(str,"in local chat with sysop"); ! 274: else { ! 275: sprintf(tmp,"in private chat with node %u" ! 276: ,node.aux); ! 277: strcat(str,tmp); ! 278: } ! 279: break; ! 280: case NODE_GCHT: ! 281: strcat(str,"chatting with The Guru"); ! 282: break; ! 283: case NODE_CHAT: ! 284: strcat(str,"in chat section"); ! 285: break; ! 286: case NODE_TQWK: ! 287: strcat(str,"transferring QWK packet"); ! 288: break; ! 289: case NODE_SYSP: ! 290: strcat(str,"performing sysop activities"); ! 291: break; ! 292: default: ! 293: strcat(str,itoa(node.action,tmp,10)); ! 294: break; } ! 295: if(!node.connection) ! 296: strcat(str," locally"); ! 297: if(node.connection==0xffff) { ! 298: strcat(str," via telnet"); ! 299: } else { ! 300: sprintf(tmp," at %ubps",node.connection); ! 301: strcat(str,tmp); ! 302: } ! 303: if(node.action==NODE_DLNG) { ! 304: if((node.aux/60)>=12) { ! 305: if(node.aux/60==12) ! 306: hour=12; ! 307: else ! 308: hour=(node.aux/60)-12; ! 309: strcpy(mer,"pm"); } ! 310: else { ! 311: if((node.aux/60)==0) /* 12 midnite */ ! 312: hour=12; ! 313: else hour=node.aux/60; ! 314: strcpy(mer,"am"); } ! 315: sprintf(tmp, " ETA %02d:%02d %s" ! 316: ,hour,node.aux-((node.aux/60)*60),mer); ! 317: strcat(str, tmp); } ! 318: break; } ! 319: if(node.misc&(NODE_LOCK|NODE_POFF|NODE_AOFF|NODE_MSGW|NODE_NMSG)) { ! 320: strcat(str," ("); ! 321: if(node.misc&NODE_AOFF) ! 322: strcat(str,"A"); ! 323: if(node.misc&NODE_LOCK) ! 324: strcat(str,"L"); ! 325: if(node.misc&(NODE_MSGW|NODE_NMSG)) ! 326: strcat(str,"M"); ! 327: if(node.misc&NODE_POFF) ! 328: strcat(str,"P"); ! 329: strcat(str,")"); } ! 330: if(((node.misc ! 331: &(NODE_ANON|NODE_UDAT|NODE_INTR|NODE_RRUN|NODE_EVENT|NODE_DOWN)) ! 332: || node.status==NODE_QUIET)) { ! 333: strcat(str," ["); ! 334: if(node.misc&NODE_ANON) ! 335: strcat(str,"A"); ! 336: if(node.misc&NODE_INTR) ! 337: strcat(str,"I"); ! 338: if(node.misc&NODE_RRUN) ! 339: strcat(str,"R"); ! 340: if(node.misc&NODE_UDAT) ! 341: strcat(str,"U"); ! 342: if(node.status==NODE_QUIET) ! 343: strcat(str,"Q"); ! 344: if(node.misc&NODE_EVENT) ! 345: strcat(str,"E"); ! 346: if(node.misc&NODE_DOWN) ! 347: strcat(str,"D"); ! 348: if(node.misc&NODE_LCHAT) ! 349: strcat(str,"C"); ! 350: strcat(str,"]"); } ! 351: if(node.errors) { ! 352: sprintf(tmp, " %d error%c",node.errors, node.errors>1 ? 's' : '\0' ); ! 353: strcat(str,tmp); ! 354: } ! 355: AnsiString Str=AnsiString(str); ! 356: if(ListBox->Items->Count<n+1) ! 357: ListBox->Items->Add(Str); ! 358: else if(ListBox->Items->Strings[n]!=Str) ! 359: ListBox->Items->Strings[n]=str; ! 360: } ! 361: Timer->Enabled=true; ! 362: } ! 363: //--------------------------------------------------------------------------- ! 364: ! 365: ! 366: ! 367: void __fastcall TNodeForm::InterruptNodeButtonClick(TObject *Sender) ! 368: { ! 369: int i; ! 370: node_t node; ! 371: ! 372: for(i=0;i<ListBox->Items->Count;i++) ! 373: if(ListBox->Selected[i]==true) { ! 374: getnodedat(&MainForm->cfg,i+1,&node,1); ! 375: node.misc^=NODE_INTR; ! 376: putnodedat(&MainForm->cfg,i+1,&node); ! 377: } ! 378: } ! 379: //--------------------------------------------------------------------------- ! 380: ! 381: void __fastcall TNodeForm::LockNodeButtonClick(TObject *Sender) ! 382: { ! 383: int i; ! 384: node_t node; ! 385: ! 386: for(i=0;i<ListBox->Items->Count;i++) ! 387: if(ListBox->Selected[i]==true) { ! 388: getnodedat(&MainForm->cfg,i+1,&node,1); ! 389: node.misc^=NODE_LOCK; ! 390: putnodedat(&MainForm->cfg,i+1,&node); ! 391: } ! 392: } ! 393: //--------------------------------------------------------------------------- ! 394: ! 395: void __fastcall TNodeForm::RerunNodeButtonClick(TObject *Sender) ! 396: { ! 397: int i; ! 398: node_t node; ! 399: ! 400: for(i=0;i<ListBox->Items->Count;i++) ! 401: if(ListBox->Selected[i]==true) { ! 402: getnodedat(&MainForm->cfg,i+1,&node,1); ! 403: node.misc^=NODE_RRUN; ! 404: putnodedat(&MainForm->cfg,i+1,&node); ! 405: } ! 406: } ! 407: ! 408: //--------------------------------------------------------------------------- ! 409: ! 410: void __fastcall TNodeForm::ListBoxKeyPress(TObject *Sender, char &Key) ! 411: { ! 412: if(Key==1) // ctrl-a ! 413: SelectAllMenuItemClick(Sender); ! 414: } ! 415: //--------------------------------------------------------------------------- ! 416: ! 417: void __fastcall TNodeForm::SelectAllMenuItemClick(TObject *Sender) ! 418: { ! 419: int i; ! 420: ! 421: for(i=0;i<ListBox->Items->Count;i++) ! 422: ListBox->Selected[i]=true; ! 423: ! 424: } ! 425: //--------------------------------------------------------------------------- ! 426: ! 427: void __fastcall TNodeForm::DownButtonClick(TObject *Sender) ! 428: { ! 429: int i; ! 430: node_t node; ! 431: ! 432: for(i=0;i<ListBox->Items->Count;i++) ! 433: if(ListBox->Selected[i]==true) { ! 434: getnodedat(&MainForm->cfg,i+1,&node,1); ! 435: if(node.status==NODE_WFC) ! 436: node.status=NODE_OFFLINE; ! 437: else if(node.status==NODE_OFFLINE) ! 438: node.status=NODE_WFC; ! 439: else ! 440: node.misc^=NODE_DOWN; ! 441: putnodedat(&MainForm->cfg,i+1,&node); ! 442: } ! 443: } ! 444: //--------------------------------------------------------------------------- ! 445: ! 446: void __fastcall TNodeForm::ClearErrorButtonClick(TObject *Sender) ! 447: { ! 448: int i; ! 449: node_t node; ! 450: ! 451: for(i=0;i<ListBox->Items->Count;i++) ! 452: if(ListBox->Selected[i]==true) { ! 453: getnodedat(&MainForm->cfg,i+1,&node,1); ! 454: node.errors=0; ! 455: putnodedat(&MainForm->cfg,i+1,&node); ! 456: } ! 457: } ! 458: //--------------------------------------------------------------------------- ! 459: ! 460: void __fastcall TNodeForm::ChatButtonClick(TObject *Sender) ! 461: { ! 462: char str[512]; ! 463: char name[128]; ! 464: int i; ! 465: node_t node; ! 466: ! 467: for(i=0;i<ListBox->Items->Count;i++) ! 468: if(ListBox->Selected[i]==true) { ! 469: getnodedat(&MainForm->cfg,i+1,&node,0); ! 470: if(node.status==NODE_WFC || node.status>NODE_QUIET) ! 471: continue; ! 472: sprintf(str,"%sCHAT %s %s %d %s" ! 473: ,MainForm->cfg.exec_dir ! 474: ,MainForm->cfg.ctrl_dir ! 475: ,MainForm->cfg.node_path[i] ! 476: ,i+1 ! 477: ,username(node.useron,name) ! 478: ); ! 479: WinExec(str,SW_SHOWNORMAL); ! 480: } ! 481: } ! 482: //--------------------------------------------------------------------------- ! 483: ! 484: void __fastcall TNodeForm::SpyButtonClick(TObject *Sender) ! 485: { ! 486: int i; ! 487: ! 488: for(i=0;i<ListBox->Items->Count;i++) ! 489: if(ListBox->Selected[i]==true) { ! 490: if(SpyForms[i]==NULL) { ! 491: Application->CreateForm(__classid(TSpyForm), &SpyForms[i]); ! 492: SpyForms[i]->inbuf=&MainForm->bbs_startup.node_inbuf[i]; ! 493: SpyForms[i]->outbuf=&MainForm->bbs_startup.node_spybuf[i]; ! 494: SpyForms[i]->Caption="Node "+AnsiString(i+1); ! 495: } ! 496: SpyForms[i]->Show(); ! 497: } ! 498: } ! 499: //--------------------------------------------------------------------------- ! 500: ! 501: void __fastcall TNodeForm::UserEditButtonClick(TObject *Sender) ! 502: { ! 503: int i; ! 504: char str[128]; ! 505: node_t node; ! 506: ! 507: for(i=0;i<ListBox->Items->Count;i++) ! 508: if(ListBox->Selected[i]==true) { ! 509: getnodedat(&MainForm->cfg,i+1,&node,0); ! 510: if(node.useron==0) ! 511: continue; ! 512: sprintf(str,"%sUSEREDIT %s %d" ! 513: ,MainForm->cfg.exec_dir ! 514: ,MainForm->cfg.data_dir ! 515: ,node.useron); ! 516: WinExec(str,SW_SHOWNORMAL); ! 517: } ! 518: } ! 519: //--------------------------------------------------------------------------- ! 520: ! 521: void __fastcall TNodeForm::UserMsgButtonClick(TObject *Sender) ! 522: { ! 523: int i; ! 524: node_t node; ! 525: ! 526: Application->CreateForm(__classid(TUserMsgForm), &UserMsgForm); ! 527: UserMsgForm->Memo->Text="\1n\1y\1hMessage From Sysop:\1w "; ! 528: UserMsgForm->Memo->SelStart=UserMsgForm->Memo->Text.Length(); ! 529: if(UserMsgForm->ShowModal()==mrOk) { ! 530: UserMsgForm->Memo->Lines->Add(""); ! 531: for(i=0;i<ListBox->Items->Count;i++) ! 532: if(ListBox->Selected[i]==true) { ! 533: getnodedat(&MainForm->cfg,i+1,&node,0); ! 534: if(node.useron==0) ! 535: continue; ! 536: putsmsg(&MainForm->cfg,node.useron ! 537: ,UserMsgForm->Memo->Text.c_str()); ! 538: } ! 539: } ! 540: delete UserMsgForm; ! 541: } ! 542: //--------------------------------------------------------------------------- ! 543:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.