/*
  QSilver-ICQ.rexx - A simple example of how to use STRICQ as a file server
  $VER: QSilver-ICQ.rexx v1.0 12.05.99 Copyright (C) 1999 Douglas F. McLaughlin & Roger Clark
  Based on original script written by: Douglas F. McLaughlin
  Note: Permission is granted to use this script in any form or make any modifications as necessary.
*/

Config:
UserName = 'Roger Clark'
MyUIN = '13648880'
Path = 'Work:NetUtilities/STRICQ/FileServer/'
MaxFiles = 5

ReadFile:
In = 'In'
Parse Arg UIN Type File .
Address STRICQ.1
GetContact 'UIN='UIN 'VAR=USER'
If ~Open(In,File,'R') Then Exit(10)
  Line = Strip(ReadLn(In),"T","0d"x)
Call Close(In)
Call Delete(File)
If Type ~= 1 Then Exit(0)

CheckOnline:
If Upper(Word(Line,1)) = '!LIST' | Upper(Word(Line,1)) = '!GET' Then Do
  If User.IP = '0.0.0.0' Then Do
    SendMessage 'UIN='UIN 'MSG="Sorry, you are either not in my Contact List, have your IP address hidden, or are currently offline.  Your filerequest has been cancelled."'
    Call Delete("Env:QSilver-ICQ")
    Exit(0)
  End
End

Serve:
If Upper(Word(Line,1)) = '!LIST' Then Do
  If Exists("Env:QSilver-ICQ") then Do
    SendMessage 'UIN='UIN 'MSG="Sorry, the file server is busy.  Please try again in a few minutes."'
    Exit(0)
  End
  Else Do
    Call Open("E","ENV:QSilver-ICQ","W")
      Call WriteLn("E","UIN "UIN)
    Call Close("E")
  End
  Call Open('Out','T:FileList.'||MyUIN,'W')
    Call WriteLn('Out','Files available from 'UserName' ('MyUIN')')
    Call WriteLn('Out',' ')
  Call Close('Out')
  Address Command 'List >>T:FileList.'MyUIN' 'Path' FILES LFORMAT="%-24N %7L %C"'
  AddFile 'FILE=T:FileList.'||MyUIN
  FileDirect 'UIN='UIN 'SPEED=100' 'DESC="Current Files Available"'
  Call Delete("Env:QSilver-ICQ")
  Exit(0)
End
If Upper(Word(Line,1)) = '!GET' Then Do
  If Exists("Env:QSilver-ICQ") then Do
    SendMessage 'UIN='UIN 'MSG="Sorry, the file server is busy.  Please try again in a few minutes."'
    Exit(0)
  End
  Else Do
    Call Open("E","ENV:QSilver-ICQ","W")
      Call WriteLn("E","UIN "UIN)
    Call Close("E")
  End
  AddFile CLEAR
  Sending = ""
  If Words(Line) - 1 > MaxFiles Then Line = SubWord(Line,1,MaxFiles + 1)
  Do Loop = 2 to Words(Line)
    File = Path || Word(Line,Loop)
    If Exists(File) Then Do
      Sending = Sending||" "||Word(Line,Loop)||";"
      AddFile 'FILE='File
    End
  End
  Sending = Strip(Sending,"T",";")
  If Words(Line) > 2 then Desc = 'Here are the files you requested:'Sending
  Else Desc = 'Here is the file you requested: 'Sending
  FileDirect 'UIN='UIN 'SPEED=100' 'DESC="'Desc'"'
  Call Delete("Env:QSilver-ICQ")
  Exit(0)
End
Exit(0)
