#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <dos.h>
#include <exec/types.h>
#include <libraries/dos.h>

#include <dlg/dlg.h>
#include <dlg/user.h>
#include <dlg/msg.h>
#include <dlg/misc.h>
#include <dlg/portconfig.h>
#include <dlg/menu.h>
#include <dlg/resman.h>
#include <dlg/cron.h>

#include <Link/Area.h>
#include <Link/io.h>
#include <Link/Msg.h>
#include <Link/user.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/dlg.h>

#include <pragmas/dlg.h>

#include <private/Version.h>
#define  ObjRev "1"
const UBYTE version[]="\0$VER: Forward " BUILDVER "." ObjRev " ©" COPYRIGHT " by Digerati Dreams "__AMIGADATE__;

void   AskQuestions(void);
void   Usage(char *);
SHORT  ForwardMessage(void);
void   Aborted(char *);
int    CleanUp(void);
void  _CXBRK(void);
SHORT  CheckNode(SHORT, SHORT, SHORT);

unsigned char *dbody = NULL;
char Online          = TRUE;
char Forward         = FALSE;
char Hurl            = FALSE;
char HurlDelete      = FALSE;
char MsgType         = FALSE;
char Freq            = FALSE;
char Fattach         = FALSE;
char CrashMail       = FALSE;
char PrivNet         = FALSE;
char callstring[255];
int Zone=0,Net=0,Node=0,point=0,Cost;
long sarea, darea, Area,Message;
char FromName[37],duser[37],LPswd[24],To[37],UUTo[129],EnterFlag=FALSE;
char *transarray=NULL,origsender=FALSE;
char   crash;

#define IGNORE_CM        1024
#define UUCPMESSAGE      -2
#define NETMAILMESSAGE   -3

#define INSTACK RStruct.Command_Stack[0]
#define STK     RStruct.Command_Stack
#define HOT     UserDat.Hot_Keys
#define LEVEL   UserDat.User_Level
#define LAST    UserDat.Last_Area
#define NAME    RStruct.Name

int PvtSendLevel;

char                   Ext[4];
struct USER_DATA       UserDat = {"", 24, 80, 0, 1, 0, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
struct Ram_File        RStruct;
struct Msg_Log         SLog;
struct Msg_Log         DLog;
struct Msg_Area        SArea;
struct Msg_Area        DArea;
struct Msg_Header      header;
struct MsgStruct       ms;
struct fido            FidoNet;
struct Global_Settings Globals;

struct ShortMenu Menu[4]  = {{'A',"Public Msg",1},
                             {'P',"Private Msg",1},
                             {'U',"UUCP Mail",1},
                             {'N',"NetMail Msg",1}
                            };

struct ShortMenu Menu1[3] = {{'F',"Forward Msg",1},
                             {'C',"Copy Msg",1},
                             {'M',"Move Msg",1}
                            };

BPTR               sout;
struct Library    *NodelistBase = NULL;
struct Library    *DLGBase      = NULL;
struct LangStruct *ls;
char             **SA;

/// Main
void main(int argc,char *argv[])
{char *s;

 sout = Output();
 if (!(DLGBase = OpenLibrary(DLGNAME, DLGVERSION)))  exit(5);

 if (GetDevName(Ext)==-1)
    {Online = FALSE;
     strcpy(Ext, "NOL");
    _CXBRK();
    }

 if (!(ls=(struct LangStruct *)GetLang(Ext)))  _CXBRK();
 SA = ls->strings;

 ASPrintf(NULL, LPswd, "%s-Forward", Ext);

 if (Online)
    {if (!ReadUser(&RStruct, &UserDat, Ext))
        {AFPrintf(&UserDat, sout, SA[596]);
        _CXBRK();
        }
    }

 if (GetFirstStruct("DLGConfig:Port/FidoNet.Settings",(char *)&FidoNet,sizeof(FidoNet))==-1)
     FidoNet.net=0;

 while(--argc > 0)
      {s = *++argv;

       if (*s++=='-')
          {while(*s)
                {switch(*s++)
                       {case 'a': if (!--argc)  break;
                                  argv++;
                                  sarea = atol(*argv);
                                  if (!sarea)
                                     {sarea = PVTAREA;
                                      strcpy(FromName, *argv);
                                      DeScore(FromName);
                                     }
                                  break;
      
                        case 'm': if (!--argc)  break;
                                  Message = atoi(*++argv);
                                  break;
      
                        case 'p': if (!--argc)  break;
                                  PvtSendLevel = atoi(*++argv);
                                  break;
                       }
                }
          }
        else
           Usage(SA[597]);
      }

 if (Online)  AskQuestions();
 ForwardMessage();
_CXBRK();
}
//-

/// AskQuestions
void AskQuestions(void)
{char inp[2],filename[80],smessage[80],tempname[80];
 int retval,fp;
  
 /* Load in user data for current message area of fill structure for PVT */
 if (sarea!=PVTAREA)
    {ReadArea(sarea,&SArea,0);
     if (SArea.savecharset)
        {struct CharSet set;
         char           setname[46];

         set.number=SArea.savecharset;
         if (GetStruct("DLGConfig:CharSets/CharSets.bbs",(char *)&set,sizeof(set),1)!=-1)
            {ASPrintf(NULL, setname, "DLGConfig:CharSets/%s.set",set.name);

             if (transarray = malloc(256))
                {if (GetFirstStruct(setname,(char *)transarray,256)==-1)
                    {free(transarray);
                     transarray=NULL;
                    }
                }
            }
        }

     ASPrintf(NULL, filename, "MSG:%ld/User.msg",sarea);
     strcpy(SLog.Name,RStruct.Name);
     GetStruct(filename,(char *)&SLog,sizeof(SLog),36);
     BuildPrivFlag(&SArea,&SLog,UserDat.User_Level);
    }
  else
    SLog.Priv_Flag=255;
  
 /* Calculate message name */
 if (sarea==PVTAREA)
    {ASPrintf(NULL,smessage,"USER:%s/%d.msg",FromName,Message);
     UnderScore(smessage);
    }
  else
     ASPrintf(NULL,smessage,"MSG:%d/%d.msg",sarea,Message);
  
 /* Load message header */
 if (GetFirstStruct(smessage,(char *)&header,sizeof(header))==-1)
    {AFPrintf(&UserDat, sout, SA[598],smessage);
    _CXBRK();
    }

 /* Disable proper menu items */
 if (!(SLog.Priv_Flag&Sysop_Access))
       if (!(SLog.Priv_Flag&Forward_Priv))
             Menu1[0].status=0;
  
 if (!(SLog.Priv_Flag&Sysop_Access))
    {if (!(SLog.Priv_Flag&Hurl_Priv))  Menu1[1].status=Menu1[2].status=0;
      
     if (Stricmp(header.From,NAME) && Stricmp(header.To,NAME))
         Menu1[1].status=Menu1[2].status=0;
      
     if (!(Stricmp(header.From,NAME) && Stricmp(header.To,NAME)) && !(SLog.Priv_Flag&Kill_Priv))
         Menu1[2].status=0;
    }

 if (!Menu1[0].status && !Menu1[1].status && !Menu1[2].status)
    {
     AFPrintf(&UserDat, sout, SA[599]);
    _CXBRK();
    }

 if (!INSTACK && !Menu1[1].status)  strcpy(STK,"F");
  
 /* Display Forward, Copy, Move menu and get selection */
 if (!INSTACK)
    {menu(Menu1,3,0);
     AFPrintf(NULL, sout, "\n");
    }
  
 DLGInput(NULL,inp,NULL,1,255,1, SA[600]);
 if (!INSTACK)  AFPrintf(NULL, sout, "\n\n");
  
 switch(inp[0])
       {case 'F': if (!Menu1[0].status)  Aborted(NULL);
                  Forward=TRUE;
                  break;
      
        case 'C': if (!Menu1[1].status)  Aborted(NULL);
                  Hurl=TRUE;
                  break;
      
        case 'M': if (!Menu1[2].status)  Aborted(NULL);
                  HurlDelete=TRUE;
                  break;
      
         default: Aborted(NULL);
                  break;
       }
    
 /* Calculate the menu and display it */
 if (!(UserDat.UUCP&USENET_ACCESS))   Menu[2].status=0;
 if (!(UserDat.NetMail))              Menu[3].status=0;
  
 if (!INSTACK)
    {menu(Menu,4,0);
     AFPrintf(NULL, sout, "\n");
    }
  
 DLGInput(NULL,inp,NULL,1,255,1, SA[601]);
 if (!INSTACK)  AFPrintf(NULL, sout, "\n\n");
  
 switch(inp[0])
 {
  case 'A':       /* Public message */

    darea=iinput(1,999999,0, SA[602]);

    AFPrintf(NULL, sout, "\n\n");
    if(!darea)
      Aborted(NULL);
      
    if(_EnterArea(darea,MSGLOCK,1)==-1)
      Aborted(NULL);
    else
      EnterFlag++;

    if(!ReadArea(darea,&DArea,0)) /* Check for area */
      Aborted(NULL);
      
    if(DArea.Flag&NETMAIL_AREA) /* Check if Netmail area */
      Aborted(SA[603]);
      
    if(!(DArea.Flag&NEWSGROUP_AREA) && !Hurl && !HurlDelete)
    {
      DLGInput(NULL,To,NULL,36,255,3, SA[604]);
      AFPrintf(NULL, sout, "\n\n");
      if(To[0]=='\0')
         Aborted(NULL);
    }
    ASPrintf(NULL,filename,"MSG:%d/User.msg",darea); /* Get user structure */
    strcpy(DLog.Name,RStruct.Name);
    retval=GetStruct(filename,(char *)&DLog,sizeof(DLog),36);
    BuildPrivFlag(&DArea,&DLog,UserDat.User_Level);
    if(retval==-1)
      if(retval==-1 && (UserDat.User_Level<DArea.llevel ||
         UserDat.User_Level>DArea.llevel)) /* Check auto level */
   Aborted(SA[605]);
    if(!(DLog.Priv_Flag&Enter_Priv)) /* Check write access */
      Aborted(SA[606]);
    Area=darea;
    break;
      
  case 'P':
    darea=PVTAREA;
    DLGInput(NULL,duser,NULL,36,255,3, SA[604]);
    AFPrintf(NULL, sout, "\n\n");
    if(duser[0]=='\0')
      Aborted(NULL);
      
    if (PvtSendLevel > UserDat.User_Level)
        if (GetLevel(duser) < PvtSendLevel)
            Aborted(SA[607]);

    Area=PVTAREA;
    break;
      
  case 'U':
    if(!UserDat.UUCP&USENET_ACCESS)
      Aborted(NULL);
    Area=UUCPMESSAGE;
      
    DLGInput(NULL,UUTo,NULL,128,255,0, SA[600]);
    AFPrintf(NULL, sout, "\n\n");
    if(UUTo[0]=='\0')
      Aborted(NULL);
    break;
      
  case 'N':
      
    if(!UserDat.NetMail)
      Aborted(NULL);
      
    /* Scan to find netmail area */
      
    if((fp=open("MSG:Area.bbs",O_RDONLY))==EOF)
      Aborted(SA[609]);
      
    retval=FALSE;
    while(read(fp,&DArea,sizeof(DArea))==sizeof(DArea))
      if(DArea.Flag&NETMAIL_AREA) {
   retval=TRUE;
   break;
      }
    close(fp);
    if(!retval)
      Aborted(SA[610]);
      
    darea=DArea.Number;
      
    if(_EnterArea(darea,MSGLOCK,1)==-1)
      Aborted(NULL);
    else
      EnterFlag++;
      
    /* Load user data for area */
    DLGInput(NULL,To,NULL,36,255,3, SA[604]);
    AFPrintf(NULL, sout, "\n\n");
    if (To[0]=='\0')  Aborted(NULL);
      
    ASPrintf(NULL, filename,"MSG:%d/User.msg",DArea.Number); /* Get user structure */
    strcpy(DLog.Name,NAME);
    retval=GetStruct(filename,(char *)&DLog,sizeof(DLog),36);
    BuildPrivFlag(&DArea,&DLog,UserDat.User_Level);
    if (retval==-1)  DLog.Priv_Flag=0;
      
    /* Get net,node,zone and point information */
   {char *node_s;

    while(TRUE)
         {Zone  = 0;
          Net   = 0;
          Node  = 0;
          point = 0;
          DLGInput(NULL,tempname,NULL,32,255,0, SA[611]);

          if (!strchr(tempname, ':') && !strchr(tempname, '/') && !strchr(tempname, '.'))
             {Zone = atoi(tempname);
              tempname[0] = 0;
             }

          if ((node_s = strchr(tempname, ':')))
             {Zone = atoi(tempname);
              strcpy(tempname, ++node_s);
              Net = -1;
             }

          if ((node_s = strchr(tempname, '/')) || Net < 0)
             {Net = atoi(tempname);
              if (node_s)
                  strcpy(tempname, ++node_s);
                else
                  tempname[0] = 0;
             }

          Node   = atoi(tempname);
          node_s = strchr(tempname, '.');
          if (node_s)  point = atoi(++node_s);

          if (!Zone)
             {DLGInput(NULL,tempname,NULL,6,255,0, "   Zone=> ");
              Zone = atoi(tempname);
             }

          if (!Net)
             {DLGInput(NULL,tempname,NULL,6,255,0, SA[612]);
              Net = atoi(tempname);
             }

          if (!Node)
             {DLGInput(NULL,tempname,NULL,12,255,0, SA[613]);
              Node = atoi(tempname);
              if ((node_s = strchr(tempname, '.')))  point = atoi(++node_s);
             }

          AFPrintf(NULL, sout, "\n\n");
          Cost = CheckNode(Zone,Net,Node);
          if (Cost == -1)
             {
              if (finput(0, SA[614]))
                 {AFPrintf(NULL, sout, "\n\n");
                  continue;
                 }

              AFPrintf(NULL, sout, "\n\n");;
              if (!(finput(0, SA[615])))
                 {AFPrintf(NULL, sout, "\n\n");
                  Aborted(SA[616]);
                 }
               else
                 {AFPrintf(NULL, sout, "\n\n");
                  Cost = 0;
                 }
             }

          break;
         }
   }
      
    if(Cost>UserDat.credit)
      Aborted(SA[617]);
      
    if(DLog.Priv_Flag&Sysop_Access) {
      Freq=finput(0, SA[618]);
      AFPrintf(NULL, sout, "\n");
     
      if(!Freq) {
   Fattach=finput(0, SA[619]);
   AFPrintf(NULL, sout, "\n");
      }

     CrashMail = FALSE;   
     if (crash  ||  (FidoNet.flags & IGNORE_CM))
         CrashMail = finput(FidoNet.flags & Crash, SA[620]);

      AFPrintf(NULL, sout, "\n");
    }
      
    PrivNet=finput(1, SA[621]);
    if(!Forward)
      origsender=finput(0, SA[622]);
    AFPrintf(NULL, sout, "\n\n");
      
    Area=NETMAILMESSAGE;
      
      
    break;
      
  default:        /* User aborted */
    Aborted(NULL);
    break;
  }
}
//-

/// Usage
void Usage(char *string)

{AFPrintf(&UserDat, sout, SA[623],string);
 AFPrintf(&UserDat, sout, SA[624]);
 AFPrintf(&UserDat, sout, SA[625]);
 AFPrintf(&UserDat, sout, SA[626]);
 AFPrintf(&UserDat, sout, SA[627]);
 AFPrintf(&UserDat, sout, SA[628]);
  
_CXBRK();
}
//-

/// ForwardMessage
SHORT ForwardMessage(void)
{
  char filename[80],bodyfile[80],prebuff[255];
  int fp;
  char success=0;
  struct Msg_Area msgarea;
  char SendSuccess=FALSE;
  
  
  AFPrintf(&UserDat, sout, SA[629],(Forward)?SA[630]:SA[631]);
  
  prebuff[0]='\0';
  
  header.Attribute|=Local; /* Set local bit in header */
  header.Attribute&=~Sent;
  
  
  if(Area==NETMAILMESSAGE) {
    if(Zone!=FidoNet.zone) {  /* Insert the kludge lines as first thing */
      char tempstring[255];
      ASPrintf(NULL, tempstring,"%cINTL %d:%d/%d %d:%d/%d%c",1,Zone,Net,Node,FidoNet.zone,FidoNet.net,FidoNet.node,13);
      strcat(tempstring,prebuff);
      strcpy(prebuff,tempstring);
      header.DestNet=FidoNet.zone;
      header.DestNode=Zone;
    }
    if(point) {
      char tempstring[80];
      ASPrintf(NULL,tempstring,"%cTOPT %d%c",1,point,13);
      strcat(prebuff,tempstring);
    }
      
    if(FidoNet.point) {
      char tempstring[80];
      ASPrintf(NULL,tempstring,"%cFMPT %d%c",1,FidoNet.point,13);
      strcat(prebuff,tempstring);
    }
  }
  
  if(Forward) {
    if(DArea.Flag&NEWSGROUP_AREA || DArea.Flag&ECHO_AREA)
      ASPrintf(NULL, SA[632],Globals.BBSName);
      
    if(sarea>0)
      ASPrintf(NULL,prebuff+strlen(prebuff),SA[633],SArea.Number,SArea.Name,header.Date,header.From); 
      
    if(sarea==PVTAREA)
      ASPrintf(NULL, prebuff+strlen(prebuff),SA[634],NAME,header.Date,header.From);
      
    strcpy(header.From,RStruct.Name);
      
    MDate(header.Date);
      
    if(Area!=PVTAREA)
      if(header.To[0]=='\0') {
   AFPrintf(NULL, sout, "\n\n");
   Aborted(NULL);
      }
  }
  
 if (sarea!=PVTAREA)
     ASPrintf(NULL, filename,"MSG:%ld/%ld.msg",sarea,Message);
   else
    {ASPrintf(NULL, filename,"USER:%s/%ld.msg",NAME,Message);
     UnderScore(filename);
    }
  
  ASPrintf(NULL, bodyfile,"T:%s.body",Ext);
  
  /* Forward to a netmail area */
  
  switch(Area) {

  case NETMAILMESSAGE:
      
    if(!UserDat.NetMail) {
      AFPrintf(&UserDat, sout, SA[635]);
      return(-1);
    }
      
    strcpy(header.To,To);
    header.Attribute &= ~Sent;
      
    header.TimesRead=PrivNet?PRINET_MSG:PUBNET_MSG;
      
    if(PrivNet)
      header.Attribute|=Private;
    else
      header.Attribute&=~Private;
      
    header.DestNet=Net;
    header.DestNode=Node;
      
    if(!origsender) {
      header.OrigNet=FidoNet.net;
      header.OrigNode=FidoNet.node;
    }
      
    if(Freq)
      header.Attribute|=FFileRequest;
    else
      header.Attribute&=~FFileRequest;
      
    if(Fattach)
      header.Attribute|=FileAttached;
    else
      header.Attribute&=~FileAttached;
      
    if(CrashMail)
      header.Attribute|=Crash;
    else
      header.Attribute&=~Crash;
      
    MakeBody(filename,NULL,prebuff,transarray,&dbody);
      
    if((fp=open("MSG:Area.bbs",O_RDONLY))==EOF)
      return(-1);
    while(read(fp,&msgarea,sizeof(msgarea))==sizeof(msgarea))
      if(msgarea.Flag&NETMAIL_AREA) {
   success++;
   break;
      }
    close(fp);
      
    header.Attribute &= ~Received;
      
    if(success) {
      ms.header=&header;
      ms.repheader=NULL;
      ms.body=dbody;
      ms.replyto=0;
      ms.areainfo=&msgarea;
      ms.flags=0L;  
     
      SendSuccess=SendPublicMsg(&ms,&FidoNet,LPswd,Ext);
    }
    else {
      AFPrintf(&UserDat, sout, SA[636]);
      SendSuccess=FALSE;
    }
    if(SendSuccess) { 
      UserDat.credit-=Cost;
      if(header.Attribute&Crash)
   CronEvent(ADDEVENT,0L,"Execute dlgconfig:batch/CrashMail.batch");
    }
      
    break;
      
  case PVTAREA:
    if(!CheckUser(duser)) {
      AFPrintf(&UserDat, sout, SA[637]);
      return(FALSE);
    }
    Capitalize(duser);
    strcpy(header.To,duser);
      
    MsgType=PRI_MSG;
    header.TimesRead=PRI_MSG;
    header.Attribute &= ~Received;
      
    MakeBody(filename,NULL,prebuff,transarray,&dbody);
      
    SendSuccess=SendPrivateMsg(&header,dbody,MsgType,LPswd,Ext);
      
    if(SendSuccess && ReadArea(Globals.PrivateArea,&DArea,0)) {
      ms.header=&header;
      ms.repheader=NULL;
      ms.body=dbody;
      ms.replyto=0;
      ms.areainfo=&DArea;
      ms.flags=0L;
     
      SendRawMsg(&ms,NULL,LPswd);
    }
      
    break;
      
  case UUCPMESSAGE: {
    char titlestring[78];
    MakeBody(filename,bodyfile,prebuff,transarray,&dbody);
   
    ASPrintf(NULL, titlestring,"\042%s\042",header.Title);
    ASPrintf(NULL, callstring,"DLG:DLGUuSend -m -t %s -r %s -s %s -a",UUTo,bodyfile,titlestring);
    if(OverlayProgram(callstring))
      SendSuccess=FALSE;
    else
      SendSuccess=-10;
  }
      
    break;
      
  default:
      
    if(!Hurl && !HurlDelete)
      strcpy(header.To,To);
      
    if(DArea.Flag&NEWSGROUP_AREA) {
      char titlestring[78];
     
      MakeBody(filename,bodyfile,prebuff,transarray,&dbody);
     
      if(!Exists(bodyfile)) {
   AFPrintf(&UserDat, sout, SA[638],bodyfile);
   _CXBRK();
      }
      ASPrintf(NULL,titlestring,"\042%s\042",header.Title);
      ASPrintf(NULL,callstring,"DLG:DLGUuSend -n -r %s -s %s -g %d -a",bodyfile,titlestring,DArea.origin);
      if(OverlayProgram(callstring))
   SendSuccess=FALSE;
      else {
   CronEvent(ADDEVENT,0L,"DLG:UNet2DLG -k");
   SendSuccess=-10;
      }
      break;
    }
      
    MakeBody(filename,NULL,prebuff,transarray,&dbody);
      
    if(DArea.Flag&ECHO_AREA)
      MsgType=ECHO_MSG;
      
    header.Attribute &= ~Received;
    header.Attribute &= ~Private;
      
    ms.header=&header;
    ms.repheader=NULL;
    ms.body=dbody;
    ms.replyto=0;
    ms.areainfo=&DArea;
    ms.flags=0L;
      
    SendSuccess=SendPublicMsg(&ms,&FidoNet,LPswd,Ext);
    break;
  }
  
  if(SendSuccess) {
    if(HurlDelete)
      if(!KillMsg((long)Message,sarea,FromName,LPswd))
   AFPrintf(&UserDat, sout, SA[639]);
    if(SendSuccess==-10)
      AFPrintf(&UserDat, sout, SA[640]);
    else
      AFPrintf(&UserDat, sout, SA[641]);
  }
  else
    AFPrintf(&UserDat, sout, SA[642]);
  
  DeleteFile(bodyfile);
  free(dbody);
  return(0);
}
//-

void Aborted(char *string)
{if (string)
     AFPrintf(&UserDat, sout, SA[643], string);

 AFPrintf(&UserDat, sout, SA[644]);
_CXBRK();
}


int CleanUp(void)

{if (EnterFlag)  LeaveArea(darea,MSGLOCK);
  
 WriteRam(&RStruct,Ext);
 CloseLibrary(DLGBase);
 return(TRUE);
}


void _CXBRK(void )

{CleanUp();
 exit(0);
}

/// CheckNode
SHORT CheckNode(SHORT zone, SHORT net, SHORT node)

{NodeList *the_nodelist = NULL;
 NodeDesc *node_desc    = NULL;
 Addr      find_me;
 SHORT     cost;

  if (!(NodelistBase = OpenLibrary("traplist.library", 3L)))
     {AFPrintf(&UserDat, sout, SA[645]);
      return(-1);
     }

 if (!(the_nodelist = NLOpen("Nodelist:", 0)))
    {CloseLibrary(NodelistBase);
     return(-1);
    }

 find_me.Zone  = zone;
 find_me.Net   = net;
 find_me.Node  = node;
 find_me.Point =  0;

 if (node_desc = NLFind(the_nodelist, &find_me, 0))
    {
     AFPrintf(&UserDat, sout, SA[646], node_desc->Node.Zone, node_desc->Node.Net,
               node_desc->Node.Node, node_desc->Node.Point, node_desc->System,
               node_desc->City);
     AFPrintf(&UserDat, sout, SA[647], node_desc->Sysop);
     AFPrintf(&UserDat, sout, SA[648], node_desc->Region, node_desc->Hub);
     AFPrintf(&UserDat, sout, SA[649], node_desc->BaudRate);
     AFPrintf(&UserDat, sout, SA[650],node_desc->Phone);

     cost = node_desc->Cost;
     if (cost != -1)
         AFPrintf(&UserDat, sout, SA[651], cost/100, cost%100);
       else
         AFPrintf(&UserDat, sout, SA[652]);

     AFPrintf(&UserDat, sout, SA[653], node_desc->Flags);

     if (strstr(node_desc->Flags, "CM"))
         crash = TRUE;
       else
        {crash = FALSE;
         AFPrintf(&UserDat, sout, SA[654]);
        }

     AFPrintf(NULL, sout, "\n\n");
    }
  else
    {AFPrintf(&UserDat, sout, SA[655]);
     cost = -1;
    }

 if (node_desc)     NLFreeNode(node_desc);
 if (the_nodelist)  NLClose(the_nodelist);
 CloseLibrary(NodelistBase);

 return(cost);
}
//-
