home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / hydrabbsa8 / source / src.lha / node / Node_Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  35.5 KB  |  1,232 lines

  1. /*
  2.  
  3.  
  4.    modify NodeGUI.C so that it has these two lines in the OpenNodeWndWindow()
  5.    function.
  6.  
  7.                 (WA_Left), N_ND->NodeX,
  8.                 (WA_Top), N_ND->NodeY,
  9.  
  10.    and so it has these includes and external definition right after "NodeGUI.H"
  11.  
  12.    #include "/common/types.h"
  13.    #include "/common/defines.h"
  14.    #include "/common/structures.h"
  15.  
  16.    extern struct NodeData *N_ND;
  17.  
  18.    todo:
  19.  
  20.    add a CheckNodePaths() sub routine..
  21.  
  22. */
  23.  
  24. #include <stdio.h>
  25. #include <exec/types.h>
  26. #include <libraries/locale.h>
  27. #include <exec/memory.h>
  28. #include <dos/dosextens.h>
  29. #include <intuition/screens.h>
  30. #include <intuition/intuition.h>
  31. #include <intuition/gadgetclass.h>
  32. #include <libraries/gadtools.h>
  33. #include <diskfont/diskfont.h>
  34. #include <utility/utility.h>
  35. #include <graphics/gfxbase.h>
  36. #include <devices/console.h>
  37. #include <devices/timer.h>
  38. #include <workbench/workbench.h>
  39. #include <graphics/scale.h>
  40. #include <clib/locale_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/wb_protos.h>
  43. #include <clib/intuition_protos.h>
  44. #include <clib/gadtools_protos.h>
  45. #include <clib/graphics_protos.h>
  46. #include <clib/utility_protos.h>
  47. #include <string.h>
  48. #include <clib/diskfont_protos.h>
  49.  
  50. #include <dos/dos.h>
  51. #include <dos/dostags.h>
  52. #include <stdlib.h>
  53. #include <stdio.h>
  54. #include <ctype.h>
  55. #include <time.h>
  56.  
  57. #include <libraries/reqtools.h>
  58.  
  59. #include <clib/alib_protos.h>
  60. #include <clib/dos_protos.h>
  61. #include <clib/reqtools_protos.h>
  62.  
  63. #include "NodeGUI.h"
  64.  
  65. #define MAIN
  66.  
  67. struct ReqToolsBase *ReqToolsBase;
  68.  
  69. #ifdef __SASC
  70. int CXBRK(void) { return(0); }
  71. int _CXBRK(void) { return(0); }
  72. void chkabort(void) {}
  73. #endif
  74.  
  75. #include "/common/types.h"
  76. #include "/common/errors.h"
  77. #include "/common/defines.h"
  78. #include "/common/structures.h"
  79. #include "/common/strings.h"
  80. #include "/common/files.h"
  81. #include "/common/options.h"
  82.  
  83. #include "Node_Options.h"
  84. #include "Node_Console_Protos.h"
  85. #include "Node_Serial_Protos.h"
  86. #include "Node_Input_Protos.h"
  87. #include "Node_Misc_Protos.h"
  88.  
  89. #include "/library/hbbscommon_protos.h"
  90. #include "/library/hbbscommon_pragmas.h"
  91. #include "nodelibrary/hbbsnode_protos.h"
  92. #include "nodelibrary/hbbsnode_pragmas.h"
  93.  
  94. long __stack=25000; // *C* how do we change this ??
  95.  
  96. struct Library *HBBSCommonBase=NULL;
  97. struct Library *HBBSNodeBase=NULL;
  98.  
  99. /*** global vars ***/
  100.  
  101.  
  102.  
  103. // ** ALWAYS define pointers as NULL **
  104.  
  105. struct MsgPort *N_ReplyPort=NULL; // only used in GetBBSGobal so far so might define locally in that..
  106.  
  107. int N_NodeNum=-1;
  108.  
  109. char WindowTitle[50];
  110. char InfoTitle[25];
  111. char SettingsTitle[25];
  112.  
  113. char WatchUserString[80];
  114.  
  115. struct BBSGlobalData *BBSGlobal=NULL;
  116. struct NodeData *N_ND=NULL;
  117. // *C* put in NodeData ?
  118. struct Screen *scr;
  119. struct TextFont *HBBSFont;
  120. UWORD offx;
  121. UWORD offy;
  122. ULONG InfoWinActive=0; // callers, uploads, downloads
  123.  
  124. struct List *HistoryList;  // for Get_Line()
  125. ULONG HistoryItems=0;
  126.  
  127. ULONG rttags[] =
  128. {
  129.   RTGS_Flags, GSREQF_CENTERTEXT,
  130.   RT_Underscore, '_',
  131.   RTEZ_ReqTitle, (ULONG)"Node Message",
  132.   RT_PubScrName, (ULONG)"CtrlScrn",
  133.   TAG_END
  134. };
  135.  
  136. extern struct ColorSpec ScreenColors[];
  137.  
  138. #include "/common/shared.c"
  139.  
  140. void WatchScreenToFront( void )
  141. {
  142.   if (!N_ND->ConOK)
  143.   {
  144.     OpenNodeConsoleWin();
  145.   }
  146.   if (N_ND->ConOK)
  147.   {
  148.     if (N_ND->NodeSettings.UseOwnScreen)
  149.     {
  150.       ScreenToFront(N_ND->ConScr);
  151.     }
  152.     else
  153.     {
  154.       WindowToFront(N_ND->ConWin);
  155.     }
  156.   }
  157. }
  158.  
  159. BOOL PickConScreen( void )
  160. {
  161.   BOOL retval=FALSE;
  162.   struct rtScreenModeRequester *scrmodereq;
  163.  
  164.   if (scrmodereq = rtAllocRequestA (RT_SCREENMODEREQ, NULL))
  165.   {
  166.     if (rtScreenModeRequest (scrmodereq, "Select Screen mode:",RTSC_Flags,SCREQF_GUIMODES | SCREQF_DEPTHGAD | SCREQF_SIZEGADS,
  167.                                                                RT_Window,NodeWnd,
  168.                                                                RTSC_MinHeight,200,
  169.                                                                RTSC_MinWidth,640,
  170.                                                                RTSC_MinDepth,1,
  171.                                                                RTSC_MaxDepth,3,
  172.                                                                TAG_END))
  173.     {
  174.       N_ND->NodeSettings.ScrModeID=scrmodereq->DisplayID;
  175.       N_ND->NodeSettings.ScrHeight=scrmodereq->DisplayHeight;
  176.       N_ND->NodeSettings.ScrWidth=scrmodereq->DisplayWidth;
  177.       N_ND->NodeSettings.ScrDepth=scrmodereq->DisplayDepth;
  178.       retval=TRUE;
  179.     }
  180.     rtFreeRequest(scrmodereq);
  181.   }
  182.   return(retval);
  183. }
  184.  
  185. BOOL CreateNodePorts( void )
  186. {
  187.   N_ND->ReplyPort=NULL; // set to null for FreeNodeData()...
  188.   N_ND->NodePort=NULL;
  189.   if (N_ND->OLMPort=CreateMsgPort())
  190.   {
  191.     if (N_ND->NodePort=CreatePort(N_ND->PortName,0))
  192.     {
  193.       if (N_ND->ReplyPort=CreatePort(0,0)) // don't need to be named..
  194.       {
  195.         return(TRUE);
  196.       }
  197.       else
  198.       {
  199.         DeletePort(N_ND->NodePort);
  200.         N_ND->NodePort=NULL; // set to null for FreeNodeData()...
  201.       }
  202.     }
  203.   }
  204.   return(FALSE);
  205. }
  206.  
  207. void CloseNodePorts( void )
  208. {
  209.   if (N_ND->OLMPort)
  210.   {
  211.     DeletePort(N_ND->OLMPort);
  212.     N_ND->OLMPort=NULL; // do we need ?
  213.   }
  214.   if (N_ND->NodePort)
  215.   {
  216.     DeletePort(N_ND->NodePort);
  217.     N_ND->NodePort=NULL; // do we need ?
  218.   }
  219.   if (N_ND->ReplyPort)
  220.   {
  221.     DeletePort(N_ND->ReplyPort);
  222.     N_ND->ReplyPort=NULL;
  223.   }
  224. }
  225.  
  226. void UpdateNodeWndGadgets( void )
  227. {
  228.   // must update stuff like the chat flag, user on-line, reserved etc.. etc..
  229.   GT_SetGadgetAttrs(NodeWndGadgets[NodeWnd_ChatFlag],NodeWnd,NULL,GTCY_Active,N_ND->NodeSettings.ChatFlag ? 0 : 1,TAG_DONE);
  230. }
  231.  
  232. void OpenNodeWin( struct Screen *scr )
  233. {
  234.   N_ND->NodeSettings.Iconified=TRUE; // just in case the window does not open..
  235.   if (OpenNodeWndWindow(scr)==0)
  236.   {
  237.     N_ND->NodeWnd=NodeWnd; // update node structure
  238.     offx = NodeWnd->BorderLeft;
  239.     offy = NodeWnd->BorderTop;
  240.     sprintf(WindowTitle,"HBBS Node %d Control Window! (C) Hydra/LSD",N_NodeNum);
  241.     SetWindowTitles(NodeWnd,WindowTitle,(UBYTE *) ~0);
  242.     UpdateNodeWndGadgets();
  243.     N_ND->NodeSettings.Iconified=FALSE;
  244.     DOOR_UpdateNodeStatus(UPD_NAME);
  245.     DOOR_UpdateNodeStatus(UPD_GROUP);
  246.     DOOR_UpdateNodeStatus(UPD_ACTION);
  247.     DOOR_UpdateNodeStatus(UPD_CPSBAUD);
  248.   }
  249. }
  250.  
  251. void CloseNodeWin(void)
  252. {
  253.   N_ND->NodeX=NodeWnd->LeftEdge;
  254.   N_ND->NodeY=NodeWnd->TopEdge;
  255.  
  256.   CloseNodeWndWindow();
  257.   N_ND->NodeSettings.Iconified=TRUE;
  258.   N_ND->NodeWnd=NULL; // update node structure
  259. }
  260.  
  261. /*** GUI ***/
  262.  
  263. void UpdateInfoWin( void )
  264. {
  265.   if (N_ND->InformationOpen)
  266.   {
  267.     sprintf(InfoTitle,"Info For Node %d",N_NodeNum);
  268.     SetWindowTitles(InfoWin,InfoTitle,(UBYTE *)~0);
  269.  
  270.     // update the list view..
  271.     // depending on what the user's looking at...
  272.  
  273.     switch(InfoWinActive)
  274.     {
  275.       case 0:
  276.         GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_LV1],InfoWin,NULL,GTLV_Labels,N_ND->Last_Callers,GTLV_Top,0,TAG_DONE);
  277.         break;
  278.       case 1:
  279.         GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_LV1],InfoWin,NULL,GTLV_Labels,N_ND->Last_Uploads,GTLV_Top,0,TAG_DONE);
  280.         break;
  281.       case 2:
  282.         GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_LV1],InfoWin,NULL,GTLV_Labels,N_ND->Last_Downloads,GTLV_Top,0,TAG_DONE);
  283.         break;
  284.       case 3:
  285.         GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_LV1],InfoWin,NULL,GTLV_Labels,N_ND->Last_Pagers,GTLV_Top,0,TAG_DONE);
  286.         break;
  287.       case 4:
  288.         GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_LV1],InfoWin,NULL,GTLV_Labels,N_ND->Last_PWFails,GTLV_Top,0,TAG_DONE);
  289.         break;
  290.       case 5:
  291.         GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_LV1],InfoWin,NULL,GTLV_Labels,N_ND->Last_Carrier,GTLV_Top,0,TAG_DONE);
  292.         break;
  293.     }
  294.  
  295.     // update the calls number..
  296.     GT_SetGadgetAttrs(InfoWinGadgets[InfoWin_Calls],InfoWin,NULL,GTNM_Number,N_ND->CallsToday,TAG_DONE);
  297.  
  298.  
  299.   }
  300. }
  301.  
  302. void ProcessWindowInfoWin( LONG Class, UWORD Code, APTR IAddress )
  303. {
  304. struct Gadget *gad;
  305. switch ( Class )
  306.   {
  307.   case IDCMP_GADGETUP :
  308.     /* Gadget message, gadget = gad. */
  309.     gad = (struct Gadget *)IAddress;
  310.     switch ( gad->GadgetID )
  311.       {
  312.       case InfoWin_LV1_Cycle1 :
  313.         /* Cycle changed   , Text of gadget :  */
  314.         InfoWinActive=Code;
  315.         UpdateInfoWin();
  316.         break;
  317.       case InfoWin_LV1 :
  318.         /* ListView pressed, Text of gadget :  */
  319.         break;
  320.       }
  321.     break;
  322.   case IDCMP_CLOSEWINDOW :
  323.     /* CloseWindow Now */
  324.     CloseInfoWinWindow();
  325.     N_ND->InformationOpen=FALSE;
  326.     break;
  327.   case IDCMP_REFRESHWINDOW :
  328.     GT_BeginRefresh( InfoWin);
  329.     /* Refresh window. */
  330.     RendWindowInfoWin( InfoWin, InfoWinVisualInfo );
  331.     GT_EndRefresh( InfoWin, TRUE);
  332.     GT_RefreshWindow( InfoWin, NULL);
  333.     RefreshGList( InfoWinGList, InfoWin, NULL, ~0);
  334.     DOOR_UpdateNodeStatus(UPD_NAME);
  335.     DOOR_UpdateNodeStatus(UPD_GROUP);
  336.     DOOR_UpdateNodeStatus(UPD_ACTION);
  337.     DOOR_UpdateNodeStatus(UPD_CPSBAUD);
  338.     break;
  339.   }
  340. }
  341.  
  342. void UpdateSettingsWindow( void )
  343. {
  344.   if (N_ND->SettingsOpen)
  345.   {
  346.     sprintf(SettingsTitle,"Settings For Node %d",N_NodeNum);
  347.     SetWindowTitles(SettingsWin,SettingsTitle,(UBYTE *)~0);
  348.  
  349.     GT_SetGadgetAttrs(SettingsWinGadgets[SettingsWin_ModemDebug],SettingsWin,NULL,GTCB_Checked,N_ND->NodeDevice.ModemDebug,TAG_DONE);
  350.     GT_SetGadgetAttrs(SettingsWinGadgets[SettingsWin_ModemLog],SettingsWin,NULL,GTCB_Checked,N_ND->NodeDevice.ModemLog,TAG_DONE);
  351.     GT_SetGadgetAttrs(SettingsWinGadgets[SettingsWin_WinOrScreen],SettingsWin,NULL,GTCY_Active,N_ND->NodeSettings.UseOwnScreen ? 0 : 1,TAG_DONE);
  352.     GT_SetGadgetAttrs(SettingsWinGadgets[SettingsWin_AllowLogins],SettingsWin,NULL,GTCY_Active,N_ND->AllowLogins ? 0 : 1,TAG_DONE);
  353.   }
  354. }
  355.  
  356. void LoadWindowSettings( void )
  357. {
  358.   struct CfgFileData *WindowCFG;
  359.   char tmpstr[BIG_STR],optionstr[10],*paramstr;
  360.   ULONG loop;
  361.   ULONG col1,col2,col3;
  362.   N_ND->ConX=0;
  363.   N_ND->ConY=11;
  364.   N_ND->ConW=640;
  365.   N_ND->ConH=200-11;
  366.  
  367.  
  368.   sprintf(tmpstr,"%sScreen.CFG",N_ND->NodeLocation);
  369.  
  370.   if (WindowCFG=HBBS_LoadConfig(tmpstr,LCFG_NONE))
  371.   {
  372.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->NodeX,VTYPE_BIGNUM,"NodeWnd_LeftEdge",OPT_SINGLE);
  373.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->NodeY,VTYPE_BIGNUM,"NodeWnd_TopEdge",OPT_SINGLE);
  374.  
  375.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->ConX,VTYPE_BIGNUM,"ConWin_LeftEdge",OPT_SINGLE);
  376.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->ConY,VTYPE_BIGNUM,"ConWin_TopEdge",OPT_SINGLE);
  377.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->ConW,VTYPE_BIGNUM,"ConWin_Width",OPT_SINGLE);
  378.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->ConH,VTYPE_BIGNUM,"ConWin_Height",OPT_SINGLE);
  379.  
  380.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->NodeSettings.ScrModeID,VTYPE_BIGNUM,OPT_NODE_ScrModeID,OPT_SINGLE);
  381.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->NodeSettings.ScrHeight,VTYPE_BIGNUM,OPT_NODE_ScrHeight,OPT_SINGLE);
  382.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->NodeSettings.ScrWidth,VTYPE_BIGNUM,OPT_NODE_ScrWidth,OPT_SINGLE);
  383.     HBBS_GetSetting(WindowCFG,(void *)&N_ND->NodeSettings.ScrDepth,VTYPE_BIGNUM,OPT_NODE_ScrDepth,OPT_SINGLE);
  384.  
  385.     for (loop=0;loop<8;loop++)
  386.     {
  387.       sprintf(optionstr,"Colour_%d",loop);
  388.       paramstr=NULL;
  389.       if (HBBS_GetSetting(WindowCFG,(void *)¶mstr,VTYPE_STRING,optionstr,OPT_SINGLE))
  390.       {
  391.         if (sscanf(paramstr,"%ld %ld %ld",&col1,&col2,&col3)==3)
  392.         {
  393.           ScreenColors[loop].Red=(UWORD)col1;
  394.           ScreenColors[loop].Green=(UWORD)col2;
  395.           ScreenColors[loop].Blue=(UWORD)col3;
  396.         }
  397.         FreeStr(paramstr);
  398.       }
  399.     }
  400.  
  401.     HBBS_FlushConfig(WindowCFG);
  402.   }
  403.  
  404. }
  405.  
  406. void SaveWindowSettings( void )
  407. {
  408.   struct CfgFileData *WindowCFG;
  409.   char tmpstr[BIG_STR],optionstr[BIG_STR];
  410.   ULONG loop;
  411.  
  412.   sprintf(tmpstr,"%sScreen.CFG",N_ND->NodeLocation);
  413. //  sprintf(tmpstr,"HBBS:System/Data/Node%d_Private.CFG",N_NodeNum);
  414.  
  415.   if (WindowCFG=HBBS_CreateConfig(tmpstr))
  416.   {
  417.     sprintf(tmpstr,"%d",NodeWnd->LeftEdge);
  418.     HBBS_AddCfgItemQuick(WindowCFG,"NodeWnd_LeftEdge",tmpstr);   // *C* make strings into variables!
  419.     sprintf(tmpstr,"%d",NodeWnd->TopEdge);
  420.     HBBS_AddCfgItemQuick(WindowCFG,"NodeWnd_TopEdge",tmpstr);
  421.  
  422.     sprintf(tmpstr,"%d",N_ND->ConWin->LeftEdge);
  423.     HBBS_AddCfgItemQuick(WindowCFG,"ConWin_LeftEdge",tmpstr);
  424.     sprintf(tmpstr,"%d",N_ND->ConWin->TopEdge);
  425.     HBBS_AddCfgItemQuick(WindowCFG,"ConWin_TopEdge",tmpstr);
  426.     sprintf(tmpstr,"%d",N_ND->ConWin->Width);
  427.     HBBS_AddCfgItemQuick(WindowCFG,"ConWin_Width",tmpstr);
  428.     sprintf(tmpstr,"%d",N_ND->ConWin->Height);
  429.     HBBS_AddCfgItemQuick(WindowCFG,"ConWin_Height",tmpstr);
  430.  
  431.     sprintf(tmpstr,"%d",N_ND->NodeSettings.ScrModeID);
  432.     HBBS_AddCfgItemQuick(WindowCFG,OPT_NODE_ScrModeID,tmpstr);
  433.     sprintf(tmpstr,"%d",N_ND->NodeSettings.ScrHeight);
  434.     HBBS_AddCfgItemQuick(WindowCFG,OPT_NODE_ScrHeight,tmpstr);
  435.     sprintf(tmpstr,"%d",N_ND->NodeSettings.ScrWidth);
  436.     HBBS_AddCfgItemQuick(WindowCFG,OPT_NODE_ScrWidth,tmpstr);
  437.     sprintf(tmpstr,"%d",N_ND->NodeSettings.ScrDepth);
  438.     HBBS_AddCfgItemQuick(WindowCFG,OPT_NODE_ScrDepth,tmpstr);
  439.  
  440.     for (loop=0;loop<8;loop++)
  441.     {
  442.       sprintf(tmpstr,"%ld %ld %ld",ScreenColors[loop].Red,ScreenColors[loop].Green,ScreenColors[loop].Blue);
  443.       sprintf(optionstr,"Colour_%d",loop);
  444.       HBBS_AddCfgItemQuick(WindowCFG,optionstr,tmpstr);
  445.     }
  446.  
  447.     HBBS_SaveConfig(WindowCFG); // *C* add errorchecking and error message
  448.     HBBS_FlushConfig(WindowCFG);
  449.   }
  450. }
  451.  
  452. void ProcessWindowSettingsWin( LONG Class, UWORD Code, APTR IAddress )
  453. {
  454. char tmpstr[1024],filename[1024];
  455. struct Gadget *gad;
  456. switch ( Class )
  457.   {
  458.   case IDCMP_GADGETUP :
  459.     /* Gadget message, gadget = gad. */
  460.     gad = (struct Gadget *)IAddress;
  461.     switch ( gad->GadgetID )
  462.       {
  463.       case SettingsWin_ScreenMode :
  464.         if (PickConScreen())
  465.         {
  466.           if (N_ND->NodeSettings.UseOwnScreen)
  467.           {
  468.             if (N_ND->ConOK) CleanupNodeConsoleWin();
  469.             OpenNodeConsoleWin();
  470.           }
  471.         }
  472.         break;
  473. /*
  474.       case SettingsWin_Save :
  475.         break;
  476. */
  477.       case SettingsWin_SaveWin:
  478.         SaveWindowSettings();
  479.         break;
  480.       case SettingsWin_WinOrScreen :
  481.         ChangeConsoleMode(Code); // 0 for screen or 1 for window,2 for reverse
  482.         break;
  483.       case SettingsWin_ModemDebug :
  484.         N_ND->NodeDevice.ModemDebug=!N_ND->NodeDevice.ModemDebug;
  485.         break;
  486.       case SettingsWin_ModemLog :
  487.         N_ND->NodeDevice.ModemLog=!N_ND->NodeDevice.ModemLog;
  488.         break;
  489.       case SettingsWin_AllowLogins :
  490.         N_ND->AllowLogins=!N_ND->AllowLogins;
  491.         break;
  492.       case SettingsWin_NodeConfig :
  493.         strcpy(tmpstr,BBSGlobal->EditorCMD);
  494.         sprintf(filename,"%sNodeLocal",N_ND->NodeLocation);
  495.         replace(tmpstr,tmpstr,"{FILE}",filename);
  496.         HBBS_RunDOSCMD(tmpstr,TRUE);
  497.         break;
  498.       case SettingsWin_CallersLog:
  499.         strcpy(tmpstr,BBSGlobal->EditorCMD);
  500.         replace(tmpstr,tmpstr,"{FILE}",N_ND->NodeSettings.CallersLogFile);
  501.         HBBS_RunDOSCMD(tmpstr,TRUE);
  502.         break;
  503.       case SettingsWin_DeviceConfig :
  504.         strcpy(tmpstr,BBSGlobal->EditorCMD);
  505.         sprintf(filename,"%sDevice",N_ND->NodeLocation);
  506.         replace(tmpstr,tmpstr,"{FILE}",filename);
  507.         HBBS_RunDOSCMD(tmpstr,TRUE);
  508.         break;
  509.       }
  510.     break;
  511.   case IDCMP_CLOSEWINDOW :
  512.     CloseSettingsWinWindow();
  513.     N_ND->SettingsOpen=FALSE;
  514.     // updatesettings();
  515.     break;
  516.   case IDCMP_REFRESHWINDOW :
  517.     GT_BeginRefresh( SettingsWin);
  518.     /* Refresh window. */
  519.   RendWindowSettingsWin( SettingsWin, SettingsWinVisualInfo );
  520.     GT_EndRefresh( SettingsWin, TRUE);
  521.   GT_RefreshWindow( SettingsWin, NULL);
  522.   RefreshGList( SettingsWinGList, SettingsWin, NULL, ~0);
  523.     break;
  524.   }
  525. }
  526.  
  527. void ProcessWindowNodeWnd( LONG Class, UWORD Code, APTR IAddress )
  528. {
  529. struct Gadget *gad;
  530. switch ( Class )
  531.   {
  532.   case IDCMP_GADGETUP :
  533.     /* Gadget message, gadget = gad. */
  534.     gad = (struct Gadget *)IAddress;
  535.     switch ( gad->GadgetID )
  536.       {
  537.       case NodeWnd_ChatFlag :
  538.         N_ND->NodeSettings.ChatFlag= Code == 0 ? TRUE : FALSE;
  539.         break;
  540.       case NodeWnd_OffHook :
  541.         /* Button pressed  , Text of gadget : OffHook */
  542.  
  543.         if (N_ND->OnlineStatus==OS_OFFLINE)
  544.         {
  545.           if (Code==0) // onhook...
  546.           {
  547.             InitModem();
  548.           }
  549.           if (Code==1) // off hook
  550.           {
  551.             OffHook();
  552.           }
  553.         }
  554.         else
  555.         {
  556.           if (Code==0) Code = 1; else Code=0;
  557.           // put the gadget back to what it was!
  558.           GT_SetGadgetAttrs(NodeWndGadgets[NodeWnd_OffHook],NodeWnd,NULL,GTCY_Active,Code,TAG_DONE);
  559.         }
  560.         break;
  561.       case NodeWnd_InitModem :
  562.         /* Button pressed  , Text of gadget : Init Modem */
  563.  
  564.         // only do it if no one's online..
  565.  
  566.         if (N_ND->OnlineStatus==OS_OFFLINE) InitModem();
  567.         break;
  568.       case NodeWnd_Reserve :
  569.         break;
  570.       case NodeWnd_Screen :
  571.         if (N_ND->ConOK)
  572.         {
  573.           CleanupNodeConsoleWin();
  574.         }
  575.         else
  576.         {
  577.           WatchScreenToFront();
  578.         }
  579.         break;
  580.       case NodeWnd_ChatNow :
  581.         /* Button pressed  , Text of gadget : Chat Now */
  582.  
  583.         if (N_ND->OnlineStatus==OS_ONLINE)
  584.         {
  585.           // open watch window if closed and/or bring it to the front.
  586.  
  587.           WatchScreenToFront();
  588.  
  589.           if (N_ND->ConOK) // check again as if we had to open the watch window it might not have actually opened...
  590.           {
  591.             if ((N_ND->ActiveDoor==NULL) || (N_ND->ActiveDoor) && (iposition("SYSOPCHAT",N_ND->ActiveDoor->node.ln_Name)<0))
  592.             {
  593.               // only start the door if it's not already started..
  594.  
  595.               GoSystemDoor("SYSOPCHAT",NULL);
  596.             }
  597.           }
  598.         }
  599.         else DisplayBeep(scr); // Doh! Can't chat to user if no-one's logged on m8! :-)
  600.  
  601.         break;
  602.       case NodeWnd_Settings :
  603.         if (N_ND->SettingsOpen==FALSE)
  604.         {
  605.           if (OpenSettingsWinWindow(scr)==0) // success!
  606.           {
  607.             N_ND->SettingsOpen=TRUE;
  608.             UpdateSettingsWindow();
  609.           }
  610.         }
  611.         /* Button pressed  , Text of gadget : Settings */
  612.         break;
  613.       case NodeWnd_Information :
  614.         /* Button pressed  , Text of gadget : Information */
  615.         if (N_ND->InformationOpen==FALSE)
  616.         {
  617.           if (OpenInfoWinWindow(scr)==0) // success!
  618.           {
  619.             N_ND->InformationOpen=TRUE;
  620.             UpdateInfoWin();
  621.           }
  622.         }
  623.         break;
  624.       }
  625.     break;
  626.   case IDCMP_CLOSEWINDOW :
  627.     /* CloseWindow Now */
  628.     if (N_ND->NodeSettings.Iconified==FALSE)
  629.     {
  630.       CloseNodeWin();
  631. // *R* moved to clodenodewin();
  632. //      N_ND->NodeX=N_ND->NodeWnd->LeftEdge;
  633. //      N_ND->NodeY=N_ND->NodeWnd->TopEdge;
  634.     }
  635.     break;
  636.   case IDCMP_REFRESHWINDOW :
  637.     GT_BeginRefresh( NodeWnd);
  638.     /* Refresh window. */
  639.   RendWindowNodeWnd( NodeWnd, NodeWndVisualInfo );
  640.     GT_EndRefresh( NodeWnd, TRUE);
  641.   GT_RefreshWindow( NodeWnd, NULL);
  642.   RefreshGList( NodeWndGList, NodeWnd, NULL, ~0);
  643.     break;
  644.   case IDCMP_VANILLAKEY :
  645.     /* Processed key press */
  646.     /* gadgets need processing perhaps. */
  647.     break;
  648.   }
  649. }
  650.  
  651. void ProcessConWindow( LONG Class, UWORD Code, APTR IAddress )
  652. {
  653. //  struct Gadget *gad;
  654.  
  655.   switch ( Class )
  656.   {
  657.     case IDCMP_CLOSEWINDOW :
  658.       /* CloseWindow Now */
  659.  
  660.       // get thesetings for the window position now so that it will open in the same place
  661.       CleanupNodeConsoleWin();
  662.       break;
  663.     case IDCMP_REFRESHWINDOW :
  664.       GT_BeginRefresh( NodeWnd);
  665.       /* Refresh window. */
  666.       RendWindowNodeWnd( NodeWnd, NodeWndVisualInfo );
  667.       GT_EndRefresh( NodeWnd, TRUE);
  668.       GT_RefreshWindow( NodeWnd, NULL);
  669.       RefreshGList( NodeWndGList, NodeWnd, NULL, ~0);
  670.       break;
  671.   }
  672. }
  673.  
  674. void SendStatus(V_BIGNUM status)
  675. {
  676.   struct StatusMsg *SMsg;
  677.  
  678.   if (SMsg=(struct StatusMsg *)AllocVec(sizeof(struct StatusMsg),MEMF_PUBLIC))
  679.   {
  680.     SMsg->message.mn_Node.ln_Type = NT_MESSAGE;
  681.     SMsg->message.mn_ReplyPort=NULL;//N_ND->ReplyPort;
  682.     SMsg->message.mn_Length=sizeof(struct StatusMsg);
  683.     SMsg->MsgType=mtype_STATUS;
  684.     SMsg->NodeNum=N_ND->NodeNum;
  685.     SMsg->Status=status;
  686.     SendMessage((struct Message*)SMsg,CtrlMainPortName);
  687.   }
  688. }
  689.  
  690. void SendRequest(V_BIGNUM requesttype)
  691. {
  692.   struct RequestMsg *RMsg;
  693.  
  694.   if (RMsg=(struct RequestMsg *)AllocVec(sizeof(struct RequestMsg),MEMF_PUBLIC))
  695.   {
  696.     RMsg->message.mn_Node.ln_Type = NT_MESSAGE;
  697.     RMsg->message.mn_ReplyPort=NULL;//N_ND->ReplyPort;
  698.     RMsg->message.mn_Length=sizeof(struct RequestMsg);
  699.     RMsg->MsgType=mtype_REQUEST;
  700.     RMsg->NodeNum=N_ND->NodeNum;
  701.     RMsg->Flags=requesttype;
  702.     SendMessage((struct Message*)RMsg,CtrlMainPortName);
  703.   }
  704. }
  705.  
  706.  
  707. void ClearDeviceData(struct DeviceData *DD)
  708. {
  709.   // small subroutine to set all the default values
  710.   // never call if you've allocated mem for strings!
  711.   DD->DeviceName=NULL;
  712.   DD->SerialDevice=NULL;
  713.   DD->SerialUnit=0;
  714.   DD->SerialBaud=0;
  715.   DD->NullModemCable=FALSE;
  716.   DD->ModemDebug=FALSE;
  717.   DD->ModemLog=FALSE;
  718.   DD->EchoRetries=0;
  719.   DD->ReOpenRetries=0;
  720.   DD->ReOpenDelay=0;
  721.   DD->LockUpScript=NULL;
  722.   DD->MaxCommandWait=0;
  723.   DD->CommandRetries=0;
  724.   DD->DelayBetweenCmds=0;
  725.   DD->TildeDelay=0;
  726.   DD->TurnOnEcho=NULL;
  727.   DD->TurnOnEchoDelay=0;
  728.   DD->ModemInit=NULL;
  729.   DD->StrictConnect=FALSE;
  730.   DD->StrictConnectStr=NULL;
  731.   DD->RelaxedConnectStr=NULL;
  732.   DD->CommandModeString=NULL;
  733.   DD->DropDTRHangup=FALSE;
  734.   DD->HangUpString=NULL;
  735.   DD->OffHookString=NULL;
  736.   DD->Incoming=NULL;
  737.   DD->ImmediateAnswer=NULL;
  738. }
  739.  
  740. void SetDeviceDataDefaults(struct DeviceData *DD)
  741. {
  742.   // small subroutine to set all the default values
  743.  
  744.   DD->EchoRetries=4;
  745.   DD->ReOpenRetries=2;
  746.   DD->ReOpenDelay=25;
  747.   DD->MaxCommandWait=10;
  748.   DD->CommandRetries=3;
  749.   DD->DelayBetweenCmds=1;
  750.   DD->TildeDelay=22;
  751.   DD->TurnOnEchoDelay=20;
  752.   DD->DropDTRHangup=TRUE;
  753. }
  754.  
  755. void FreeDeviceData(struct DeviceData *DD)
  756. {
  757.   FreeStr(DD->DeviceName);
  758.   FreeStr(DD->SerialDevice);
  759.   FreeStr(DD->LockUpScript);
  760.   FreeStr(DD->HangUpString);
  761.   FreeStr(DD->OffHookString);
  762.   FreeStr(DD->Incoming);
  763.   FreeStr(DD->ImmediateAnswer);
  764.   FreeStrList(DD->TurnOnEcho);
  765.   FreeStrList(DD->ModemInit);
  766.   FreeStrList(DD->StrictConnectStr);
  767.   FreeStrList(DD->CommandModeString);
  768.   FreeStrList(DD->RelaxedConnectStr);
  769. }
  770.  
  771. V_ERROR LoadDeviceData(ULONG NodeNum,struct DeviceData *DD )
  772. {
  773.   struct CfgFileData *DeviceCFG;
  774.   V_ERROR error=TYPE_NONE;
  775.   UBYTE *filename=NULL;
  776.   struct NodeData *ND;
  777.  
  778.   if (ND=HBBS_NodeDataPtr(NodeNum))
  779.   {
  780.     if (filename=AllocVec(strlen(ND->NodeLocation)+strlen(FILENAME_DEVICE)+1,MEMF_PUBLIC))
  781.     {
  782.       strcpy(filename,ND->NodeLocation);
  783.       strcat(filename,FILENAME_DEVICE);
  784.     }
  785.   }
  786.  
  787.   if (filename)
  788.   {
  789.     if (DeviceCFG=HBBS_LoadConfig(filename,LCFG_NONE))
  790.     {
  791.       // get settings!
  792.       HBBS_GetSetting(DeviceCFG,(void *)&DD->DeviceName       ,VTYPE_STRING,OPT_DEVICE_DeviceName       ,OPT_SINGLE);
  793.       HBBS_GetSetting(DeviceCFG,(void *)&DD->SerialDevice     ,VTYPE_STRING,OPT_DEVICE_SerialDevice     ,OPT_SINGLE);
  794.       HBBS_GetSetting(DeviceCFG,(void *)&DD->SerialUnit       ,VTYPE_BIGNUM,OPT_DEVICE_SerialUnit       ,OPT_SINGLE);
  795.       HBBS_GetSetting(DeviceCFG,(void *)&DD->SerialBaud       ,VTYPE_BIGNUM,OPT_DEVICE_SerialBaud       ,OPT_SINGLE);
  796.       HBBS_GetSetting(DeviceCFG,(void *)&DD->NullModemCable   ,VTYPE_BOOL,OPT_DEVICE_NullModemCable     ,OPT_SINGLE);
  797.       HBBS_GetSetting(DeviceCFG,(void *)&DD->ModemDebug       ,VTYPE_BOOL,OPT_DEVICE_ModemDebug         ,OPT_SINGLE);
  798.       HBBS_GetSetting(DeviceCFG,(void *)&DD->ModemLog         ,VTYPE_BOOL,OPT_DEVICE_ModemLog           ,OPT_SINGLE);
  799.       HBBS_GetSetting(DeviceCFG,(void *)&DD->EchoRetries      ,VTYPE_SMALLNUM,OPT_DEVICE_EchoRetries    ,OPT_SINGLE);
  800.       HBBS_GetSetting(DeviceCFG,(void *)&DD->ReOpenRetries    ,VTYPE_SMALLNUM,OPT_DEVICE_ReOpenRetries  ,OPT_SINGLE);
  801.       HBBS_GetSetting(DeviceCFG,(void *)&DD->ReOpenDelay      ,VTYPE_TIME,OPT_DEVICE_ReOpenDelay        ,OPT_SINGLE);
  802.       HBBS_GetSetting(DeviceCFG,(void *)&DD->LockUpScript     ,VTYPE_STRING,OPT_DEVICE_LockUpScript     ,OPT_SINGLE);
  803.       HBBS_GetSetting(DeviceCFG,(void *)&DD->MaxCommandWait   ,VTYPE_TIME,OPT_DEVICE_MaxCommandWait     ,OPT_SINGLE);
  804.       HBBS_GetSetting(DeviceCFG,(void *)&DD->CommandRetries   ,VTYPE_SMALLNUM,OPT_DEVICE_CommandRetries ,OPT_SINGLE);
  805.       HBBS_GetSetting(DeviceCFG,(void *)&DD->DelayBetweenCmds ,VTYPE_TIME,OPT_DEVICE_DelayBetweenCmds   ,OPT_SINGLE);
  806.       HBBS_GetSetting(DeviceCFG,(void *)&DD->TildeDelay       ,VTYPE_TIME,OPT_DEVICE_TildeDelay         ,OPT_SINGLE);
  807.       HBBS_GetSetting(DeviceCFG,(void *)&DD->TurnOnEcho       ,VTYPE_STRINGLIST,OPT_DEVICE_TurnOnEcho   ,OPT_MULTI);
  808.       HBBS_GetSetting(DeviceCFG,(void *)&DD->TurnOnEchoDelay  ,VTYPE_BIGNUM,OPT_DEVICE_TurnOnEcho       ,OPT_SINGLE);
  809.       HBBS_GetSetting(DeviceCFG,(void *)&DD->ModemInit        ,VTYPE_STRINGLIST,OPT_DEVICE_ModemInit    ,OPT_MULTI);
  810.       HBBS_GetSetting(DeviceCFG,(void *)&DD->StrictConnect    ,VTYPE_BOOL,OPT_DEVICE_StrictConnect      ,OPT_SINGLE);
  811.       HBBS_GetSetting(DeviceCFG,(void *)&DD->StrictConnectStr ,VTYPE_STRINGLIST,OPT_DEVICE_StrictConnectStr ,OPT_MULTI);
  812.       HBBS_GetSetting(DeviceCFG,(void *)&DD->RelaxedConnectStr,VTYPE_STRINGLIST,OPT_DEVICE_RelaxedConnectStr,OPT_MULTI);
  813.       HBBS_GetSetting(DeviceCFG,(void *)&DD->DropDTRHangup    ,VTYPE_BOOL,OPT_DEVICE_DropDTRHangup      ,OPT_SINGLE);
  814.       HBBS_GetSetting(DeviceCFG,(void *)&DD->CommandModeString,VTYPE_STRINGLIST,OPT_DEVICE_CommandModeString,OPT_MULTI);
  815.       HBBS_GetSetting(DeviceCFG,(void *)&DD->HangUpString     ,VTYPE_STRING,OPT_DEVICE_HangUpString     ,OPT_SINGLE);
  816.       HBBS_GetSetting(DeviceCFG,(void *)&DD->OffHookString    ,VTYPE_STRING,OPT_DEVICE_OffHookString    ,OPT_SINGLE);
  817.       HBBS_GetSetting(DeviceCFG,(void *)&DD->Incoming         ,VTYPE_STRING,OPT_DEVICE_Incoming         ,OPT_SINGLE);
  818.       HBBS_GetSetting(DeviceCFG,(void *)&DD->ImmediateAnswer  ,VTYPE_STRING,OPT_DEVICE_ImmediateAnswer  ,OPT_SINGLE);
  819.  
  820.       HBBS_FlushConfig(DeviceCFG);
  821.       DD->SysopNode=FALSE;
  822.     }
  823.     else
  824.     {
  825.       DD->SysopNode=TRUE;
  826.     }
  827.     FreeVec(filename);
  828.   }
  829.   return(error);
  830. }
  831.  
  832.  
  833. static VOID cleanup(ULONG num)
  834. {
  835.   if (HBBSNodeBase)
  836.   {
  837.     HBBS_CleanUpNode();
  838.     CloseLibrary (HBBSNodeBase);
  839.   }
  840.  
  841.   if (HBBSCommonBase)
  842.   {
  843.     HBBS_CleanUpCommon();
  844.     CloseLibrary (HBBSCommonBase);
  845.   }
  846.  
  847.   if (N_ReplyPort)
  848.     DeleteMsgPort(N_ReplyPort);
  849.  
  850.   if (num)
  851.   {
  852.     HBBS_DoErrorMessage(num,N_NodeNum,NULL);
  853.   }
  854.  
  855.   if (ReqToolsBase)
  856.     CloseLibrary ((struct Library *)ReqToolsBase);
  857.  
  858.   exit(0);
  859. }
  860.  
  861. static VOID init(VOID)
  862. {
  863.   if (!(ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION)))
  864.   {
  865.     cleanup(EMSG_NOREQTOOLS);
  866.   }
  867.  
  868.   if (!(N_ReplyPort=CreateMsgPort()))
  869.   {
  870.     cleanup(EMSG_NOMEM);
  871.   }
  872.  
  873.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  874.   {
  875.     cleanup(EMSG_NOCOMMON);
  876.   }
  877.  
  878.   if (!(HBBS_InitCommon()))
  879.   {
  880.     cleanup(EMSG_COMMONERR);
  881.   }
  882.  
  883.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  884.   {
  885.     cleanup(EMSG_NONODE);
  886.   }
  887.  
  888.   if (!(HBBS_InitNode(N_NodeNum)))
  889.   {
  890.     cleanup(EMSG_NODEERR);
  891.   }
  892. }
  893.  
  894. V_ERROR GetBBSGlobal(void)
  895. {
  896.   struct AskMsg *AMsg,*Reply;
  897.   V_ERROR error=TYPE_CRITICAL;
  898.  
  899.   if (AMsg=(struct AskMsg *)AllocVec(sizeof(struct AskMsg),MEMF_PUBLIC))
  900.   {
  901.     // create the message
  902.     AMsg->message.mn_Node.ln_Type = NT_MESSAGE;
  903.     AMsg->message.mn_ReplyPort=N_ReplyPort;
  904.     AMsg->message.mn_Length=sizeof(struct AskMsg);
  905.     AMsg->MsgType=mtype_ASK; // so CONTROL knows what type of message structe to typecast to..
  906.     AMsg->NodeNum=N_NodeNum; // can't use N_ND->NodeNum yet.. as we don't know N_ND
  907.     AMsg->Flags=ASK_BBSGLOBAL;
  908.  
  909.     // now send it to ctrlmain, note we can't use N_ND->ReplyPort as we don't know N_ND yet!!
  910.  
  911.     if (SafePutToPort((struct Message *)AMsg,CtrlMainPortName))
  912.     {
  913.       if (1L << N_ReplyPort->mp_SigBit==Wait(1L << N_ReplyPort->mp_SigBit))
  914.       {
  915.         Reply=(struct AskMsg*)GetMsg(N_ReplyPort);
  916.         if (Reply)
  917.         {
  918.           BBSGlobal=(struct BBSGlobalData *)Reply->Pointer;
  919.           error=TYPE_NONE;
  920.         }
  921.       }
  922.     }
  923.     FreeVec(AMsg);
  924.   }
  925.   return(error);
  926. }
  927.  
  928. V_BOOL InitNode(void)
  929. {
  930.   // *C* add error messages and return codes here ?
  931.   if (CreateNodePorts())
  932.   {
  933.     // ports must be created before sendstatus will work..
  934.     SendStatus(STAT_INITIALIZING);
  935.  
  936.     if (N_ND->BBSCols=(struct BBSColsData*)AllocVec(sizeof(struct BBSColsData),MEMF_CLEAR|MEMF_PUBLIC))
  937.     {
  938.       if (N_ND->OLMList=HBBS_CreateList())
  939.       {
  940.         N_ND->OLMCount=0;
  941.         if (N_ND->Last_Callers=HBBS_CreateList())
  942.         {
  943.           if (N_ND->Last_Uploads=HBBS_CreateList())
  944.           {
  945.             if (N_ND->Last_Downloads=HBBS_CreateList())
  946.             {
  947.               if (N_ND->Last_PWFails=HBBS_CreateList())
  948.               {
  949.                 if (N_ND->Last_Carrier=HBBS_CreateList())
  950.                 {
  951.                   if (N_ND->Last_Pagers=HBBS_CreateList())
  952.                   {
  953.                     ClearNodeData(&N_ND->NodeSettings);
  954.                     ClearDeviceData(&N_ND->NodeDevice);
  955.                     SetDeviceDataDefaults(&N_ND->NodeDevice);
  956.                     CopyNodeSettings(&N_ND->NodeSettings,&BBSGlobal->NodeGlobalData->NodeSettings);
  957.                     N_ND->NodeFlags=NFLG_NONE;
  958.                     if (LoadNodeSettingsData(N_NodeNum,&N_ND->NodeSettings)==TYPE_NONE)
  959.                     {
  960.                       HBBS_SetBBSCols();
  961.                       if (N_ND->NodeTimer=InitTimer())
  962.                       {
  963.                         if (N_ND->NodeSettings.UseDevice)
  964.                         {
  965.                           if (LoadDeviceData(N_NodeNum,&N_ND->NodeDevice)==TYPE_NONE)
  966.                           {
  967.                             if (OpenSerial())
  968.                             {
  969.                               SendStatus(STAT_READY);
  970.                               return(TRUE);
  971.                             }
  972.                           } else HBBS_DoErrorMessage(EMSG_DEVICEFILEERR,N_ND->NodeNum,NULL);
  973.                         }
  974.                         else
  975.                         {
  976.                           return(TRUE);
  977.                         }
  978.                       } else HBBS_DoErrorMessage(EMSG_NOTIMER,N_ND->NodeNum,NULL);
  979.                     } else HBBS_LogError(FILE_ERRORLOG,ERR_NODESETTINGS,NULL,TYPE_FATAL); // *C* add error message too ?
  980.                   }
  981.                 }
  982.               }
  983.             }
  984.           }
  985.         }
  986.       }
  987.     }
  988.     SendStatus(STAT_CLOSED);
  989.   }
  990.   return(FALSE);
  991. }
  992.  
  993. void FreeNode( void )
  994. {
  995.   SendStatus(STAT_CLOSING);
  996.   if (N_ND->NodeTimer) CleanupTimer(N_ND->NodeTimer);
  997.   FreeStrList(N_ND->Last_Callers);
  998.   FreeStrList(N_ND->Last_Uploads);
  999.   FreeStrList(N_ND->Last_Downloads);
  1000.   FreeStrList(N_ND->Last_Pagers);
  1001.   FreeStrList(N_ND->Last_PWFails);
  1002.   FreeStrList(N_ND->Last_Carrier);
  1003.   FreeStrList(N_ND->OLMList);
  1004.   N_ND->OLMList=NULL; //must be done!!
  1005.  
  1006.   if (N_ND->BBSCols)
  1007.   {
  1008.     FreeVec(N_ND->BBSCols->MenuTextANSI);
  1009.     FreeVec(N_ND->BBSCols->MenuOpenBracket);
  1010.     FreeVec(N_ND->BBSCols->MenuCloseBracket);
  1011.     FreeVec(N_ND->BBSCols->MenuHighlightANSI);
  1012.     FreeVec(N_ND->BBSCols->MenuDefaultOptANSI);
  1013.     FreeVec(N_ND->BBSCols->MenuPromptANSI);
  1014.     FreeVec(N_ND->BBSCols);
  1015.   }
  1016.   FreeDeviceData(&N_ND->NodeDevice);
  1017.   FreeNodeSettingsData(&N_ND->NodeSettings);
  1018.   SendStatus(STAT_CLOSED);
  1019.   // must be done last cos status won't work otherwise..
  1020.   CloseNodePorts();
  1021.   HBBS_ResetNodeData(N_ND);
  1022. }
  1023.  
  1024. void HandleAsk(struct AskMsg *AMsg)
  1025. {
  1026.   switch(AMsg->Flags)
  1027.   {
  1028.     case ASK_STATUS:
  1029.       AMsg->Value=N_ND->Status;
  1030.       break;
  1031.   }
  1032.   ReplyMsg((struct Message *)AMsg);
  1033. }
  1034.  
  1035. // returns 1 if quit..
  1036. void HandleStatus(struct StatusMsg *SMsg)
  1037. {
  1038.   switch(SMsg->Status)
  1039.   {
  1040.     case STAT_REQUESTCLOSE:
  1041.       // node must NOT be doing anything if we want to shut it down
  1042.       if (N_ND->Status==STAT_READY) N_ND->RequestShutdown=TRUE;
  1043.       break;
  1044.  
  1045.     case STAT_OPENWINDOW:
  1046.       if (N_ND->NodeSettings.Iconified==TRUE)
  1047.       {
  1048.         OpenNodeWin(scr);
  1049.       }
  1050.       break;
  1051.     case STAT_CLOSEWINDOW:
  1052.       // *C* change to abort con if window closed pressed as we can't actually
  1053.       // care about the console coming in if we're closing the window!
  1054.       // ah, but what if a door does care ??? Umm.. fuck it.. who cares it's staying
  1055.       if (N_ND->NodeSettings.Iconified==FALSE && N_ND->ConWaiting==FALSE)
  1056.       {
  1057.         CloseNodeWin();
  1058.       }
  1059.       break;
  1060.     case STAT_OPENSCREEN:
  1061.       WatchScreenToFront();
  1062.       break;
  1063.     case STAT_CLOSESCREEN:
  1064.       if (N_ND->ConOK==TRUE)
  1065.       {
  1066.         CleanupNodeConsoleWin();
  1067.       }
  1068.       break;
  1069.   }
  1070.  
  1071.   // a status message MAY be sent to the node without the control or other program wanting to be told
  1072.   // that the NODE has recived the message, all messages sent that DONT want a reply WILL be freed..
  1073.  
  1074.   if (SMsg->message.mn_ReplyPort)
  1075.   {
  1076.     ReplyMsg((struct Message *)SMsg);
  1077.   }
  1078.   else
  1079.   {
  1080.     FreeVec(SMsg);
  1081.   }
  1082. }
  1083.  
  1084. void HandleDoorActivityMsg(struct DoorActivityMsg *DMsg)
  1085. {
  1086.   switch(DMsg->Status)
  1087.   {
  1088.     case DMSG_DOORSTARTED:
  1089. //      printf("Door Started! (%s)\n",N_ND->ActiveDoor->node.ln_Name);
  1090.       break;
  1091.     case DMSG_DOORFINISHED:
  1092. //      printf("Door Finished!\n");
  1093.       break;
  1094.   }
  1095.   // a door message MAY be sent to the node without the control or other program wanting to be told
  1096.   // that the NODE has recived the message, all messages sent that DONT want a reply WILL be freed..
  1097.  
  1098.   if (DMsg->message.mn_ReplyPort)
  1099.   {
  1100.     ReplyMsg((struct Message *)DMsg);
  1101.   }
  1102.   else
  1103.   {
  1104.     FreeVec(DMsg);
  1105.   }
  1106. }
  1107.  
  1108. void HandleCheckMsg(struct NodeMsg *NMsg)  // *R* needed ?
  1109. {
  1110.   if (NMsg->message.mn_ReplyPort)
  1111.   {
  1112.     ReplyMsg((struct Message *)NMsg);
  1113.   }
  1114.   else
  1115.   {
  1116.     FreeVec(NMsg);
  1117.   }
  1118. }
  1119.  
  1120. void HandleMsg( void )
  1121. {
  1122.   struct NodeMsg *NMsg;
  1123.  
  1124.  
  1125.   while (NMsg=(struct NodeMsg*)GetMsg(N_ND->NodePort))
  1126.   {
  1127.     switch(NMsg->MsgType)
  1128.     {
  1129.       case mtype_ASK:
  1130.         HandleAsk((struct AskMsg *)NMsg);
  1131.         break;
  1132.       case mtype_STATUS:
  1133.         HandleStatus((struct StatusMsg *)NMsg);
  1134.         break;
  1135.       case mtype_DOORACTIVITY:
  1136.         HandleDoorActivityMsg((struct DoorActivityMsg *)NMsg);
  1137.         break;
  1138.       case mtype_DOORIO:
  1139.         HandleDoorIOMsg((struct DoorIOMsg *)NMsg);
  1140.         break;
  1141.       case mtype_CHECK:   // all we want to do is get the node to check some stuff
  1142.         HandleCheckMsg(NMsg); // depending on what it's doing...
  1143.         break;
  1144.     }
  1145.     // we might get a message that does not want a reply.. (like a request shutdown message..)
  1146.   }
  1147. }
  1148.  
  1149. // copied and modified from NodeGUI.c as the version in there does NOT free the fonts!!!!
  1150.  
  1151. int OpenTheDiskFonts( void )
  1152. {
  1153.   int OKSoFar = 1; // reveresed numbers
  1154.   if ((HBBSFont = OpenDiskFont( &HBBS8066 ))==NULL )
  1155.   OKSoFar = 0;
  1156. return ( OKSoFar );
  1157. }
  1158.  
  1159. void NodeMain(void)
  1160. {
  1161.   if (OpenLibs()==0)
  1162.   {
  1163.     if (OpenTheDiskFonts())
  1164.     {
  1165.       if (scr=LockPubScreen(str_CtrlScrnName))
  1166.       {
  1167.         if (InitNode())
  1168.         {
  1169.           HBBS_LoadCallsData();
  1170.           LoadWindowSettings();
  1171.           if (N_ND->NodeSettings.Iconified==FALSE) OpenNodeWin(scr);
  1172.           if (N_ND->NodeSettings.StartScreen) OpenNodeConsoleWin();
  1173.  
  1174.           AwaitConnect();
  1175.           if (N_ND->NodeSettings.Iconified==FALSE) CloseNodeWin();
  1176.           if (N_ND->SettingsOpen) CloseSettingsWinWindow();
  1177.           if (N_ND->InformationOpen) CloseInfoWinWindow();
  1178.           if (N_ND->ConOK) CleanupNodeConsoleWin();
  1179.           if (N_ND->SerOK) CleanupSerial();
  1180.         }
  1181.         FreeNode();
  1182.         UnlockPubScreen(NULL, scr);
  1183.       } else HBBS_DoErrorMessage(EMSG_NOSCREEN,0,NULL);
  1184.       CloseFont( HBBSFont ) ;
  1185.     }
  1186.     else  HBBS_DoErrorMessage(EMSG_NOFONT,0,NULL);
  1187.     CloseLibs();
  1188.   } else HBBS_DoErrorMessage(EMSG_NOLIBS,0,NULL);
  1189. }
  1190.  
  1191. int main(int argc,char *argv[])
  1192. {
  1193.   struct MsgPort *tmpport;
  1194.   char tmpstr[20];
  1195.  
  1196.   if ((argc!=2) || (sscanf(argv[1],"%d",&N_NodeNum)==0))
  1197.   {
  1198.     printf("Invalid/No Paramaters for node!\n");
  1199.     exit (20);
  1200.   }
  1201.   sprintf(tmpstr,"HBBS_Node %d",N_NodeNum);
  1202.   SetProgramName(tmpstr);
  1203.   init();
  1204.   if (BBSGlobal=HBBS_GimmeBBS())
  1205.   {
  1206.     if (N_NodeNum >= BBSGlobal->BBSNodes)
  1207.     {
  1208.       HBBS_DoErrorMessage(EMSG_NODEINVALID,N_NodeNum,NULL);
  1209.     }
  1210.     else
  1211.     {
  1212.       if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  1213.       {
  1214.         Forbid();
  1215.         tmpport=FindPort(N_ND->PortName);
  1216.         Permit();
  1217.         if (tmpport)
  1218.         {
  1219.           HBBS_DoErrorMessage(EMSG_NODEALREADYUP,N_NodeNum,NULL);
  1220.         }
  1221.         else
  1222.         {
  1223.           // actually already set by control..
  1224.           //N_ND->NodeNum=N_NodeNum; // set the node number (as gained from command line parms)
  1225.           NodeMain();
  1226.         }
  1227.       }
  1228.     }
  1229.   } else HBBS_DoErrorMessage(EMSG_NOCTRL,0,NULL);
  1230.   cleanup(0);
  1231. }
  1232.