Author Topic: Fserve Script - IceServe 1.0  (Read 3893 times)

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Fserve Script - IceServe 1.0
« on: June 23, 2007, 11:12:54 AM »
Please, follow the instructions, that I have made. If you do not, the script may not work.

Do not add these scripts directly into the IceChat Editor initially, use a program like Notepad the create the files.
Place these files into the Scripts Folder.
To easily get to the IceChat Scripts folder, in IceChat, go to the Help Menu, Debug items, and Explore IceChat Data Folder.
The go to the Scripts folder.

Create all three (3) files there, and once completed, Open the IceChat Editor, go to the Scripts Tab, and load "fserve.ics", and only fserve.ics.
There is no need to load fserve.ice, the script will do that automatically.

Ok, I have been saying I was going to post an fserve script, for a VERY long time.
My work here is "in progress" which means, it is not finished. But so far, its working rather well.


The script consists of 2 script files, and then a welcome file, and the settings file.

This is the first script file, we can call it "fserve.ics"
This will start the FServe Script on IceChat load, and add the values for the triggers, that people will type to do the commands and such. It also adds a couple of menu items to the Script Menu, on the main menu bar.
It will also automatically load the fserve.ice script file.

Code: [Select]
on *:START:{
/load -s fserve.ice

if ( $exists($scriptdir $+ fserve.ini) == $false ) /! SetupFserve

/set %trigger /! Trigger
/set %qtrigger /! QTrigger
/set %maxqueue /! MaxQueue
/set %maxsends /! MaxSends
/set %filecount /! FserveFileCount
/set %totalsends /! TotalSends
/set %advertmsg /! AdvertMsg
/set %queuemsg /! QueueMsg
/set %totalsessions /! TotalSessions
/set %totalqueue /! TotalQueue
}

menu script {
IceServe
.Setup:/! SetupFserve
.Restart:/! RestartFserve
}

The 2nd script file, which is the main script, written in VBScript style scripting. It is the guts and core of the IceServe Script.
Save this file, as fserve.ice.

Code: [Select]
Option Explicit

Class QueueItem
    Public FileName
    Public NickName
    Public Key
End Class

Class Session
    Public NickName
    Public Folder
End Class

'Simple File Server Script
Const FserveIni ="fserve.ini"
Const WelcomeMsg = "welcome.txt"

Dim ScriptStatus
ScriptStatus = GetIniFile(FserveIni,"Main","Status","Off")

Dim SetupDialog

Dim FserveTrigger
FserveTrigger = GetIniFile(FserveIni,"Main","Trigger","!Fserve")

'array of all files, and total count
Dim DownloadFiles(), FileCount

Dim FserveFolder
FserveFolder = GetIniFile(FserveIni,"Main","DefaultFolder","n/a")

Dim TriggerDelay
'holds how many seconds between advertisements
TriggerDelay = GetIniFile(FserveIni,"Main","TriggerDelay","300")

Dim AdvertiseMessage
AdvertiseMessage =  GetIniFile(FserveIni,"Main", "AdvertiseMessage", "Serving %filecount files. Type %trigger to access this FServe. %qtrigger for Queue Info")

Dim QueueMessage
QueueMessage =  GetIniFile(FserveIni,"Main", "QueueMessage", "Total Files in Queue %totalqueue / %maxqueue - %totalsends / %maxsends Total Sends")

Dim QueueTrigger
QueueTrigger = GetIniFile(FserveIni,"Main","QueueTrigger","!Queue")

Dim ServerChannel
ServerChannel = GetIniFile(FserveIni,"Main","Channel","#scriptchannel")

Dim MaxQueueItems
'total allowable items for the Download Queue
MaxQueueItems =  GetIniFile(FserveIni,"Main", "MaxQueueItems", 25)

Dim MaxSendItems
'maximum number of simultaneous dcc sends
MaxSendItems =  GetIniFile(FserveIni,"Main", "MaxSendItems", 2)

Dim TotalSendItems
TotalSendItems = 0

Dim DownloadQueue
Set DownloadQueue = CreateObject("Scripting.Dictionary")

Dim DCCSessions
Set DCCSessions = CreateObject("Scripting.Dictionary")

If FserveFolder = "n/a" then
 'run default setup
  SetupFserve
End if

Sub SetupFserve()
'show dialog for fserve settings
SetupDialog = CreateDialog ("IceServe 1.0 Setup",200,100,650,370)

AddLabel SetupDialog, "Default Fserve Folder",10,12,150,20,1
AddButton SetupDialog, "Choose Folder",170,10,125,25,7,0,"PickFolder"

If FserveFolder = "n/a" then
     AddEditBox SetupDialog, GetIceChatFolder & "download\", 10,40,480,25,2
else
     AddEditBox SetupDialog, FserveFolder, 10,40,480,25,2
End if

AddLabel SetupDialog, "Script Status",350,12,100,20,4
AddComboBox SetupDialog,470,10,50,100,3
AddItem 3, 5,"On"
AddItem 3, 5,"Off"
If ScriptStatus = "Off" then
  SetListItem 3,1,5
Else
  SetListItem 3,0,5
End if

AddLabel SetupDialog, "Fserve Trigger",10,72,100,20,5
AddEditBox SetupDialog, FserveTrigger, 120,70,100,25,6

AddLabel SetupDialog, "Queue Trigger",300,72,100,20,13
AddEditBox SetupDialog, QueueTrigger, 410,70,100,25,14

AddLabel SetupDialog, "Advertise Delay Seconds",10,102,170,20,7
AddEditBox SetupDialog, TriggerDelay, 200,100,50,25,8

AddLabel SetupDialog, "Max Queue Items",10,132,120,20,15
AddEditBox SetupDialog, MaxQueueItems, 140,130,50,25,16

AddLabel SetupDialog, "Max Send Items",300,132,120,20,17
AddEditBox SetupDialog, MaxSendItems, 430,130,50,25,18

AddLabel SetupDialog, "Advertise Message",10,165,140,20,9
AddEditBox SetupDialog, AdvertiseMessage, 10,190,630,25,10

AddLabel SetupDialog, "Queue Message",10,225,140,20,11
AddEditBox SetupDialog, QueueMessage, 10,250,630,25,12

AddLabel SetupDialog, "Channel",10,280,140,20,13
AddEditBox SetupDialog, ServerChannel, 10,305,300,25,19


AddButton SetupDialog, "Save",550,340,75,25,20,0,"SaveButton"

ShowDialog SetupDialog
End Sub

Sub SaveButton_Clicked()
FserveFolder = GetText(2)
If Right(FserveFolder,1) <> "\" then FserveFolder=FserveFolder & "\"
ScriptStatus = GetListitem(3,5)
FserveTrigger = GetText(6)
TriggerDelay = GetText(8)
AdvertiseMessage = GetText(10)
QueueMessage = GetText(12)
QueueTrigger = GetText(14)
MaxQueueItems = GetText(16)
MaxSendItems = GetText(18)
ServerChannel = GetText(19)

CloseDialog SetupDialog
WriteIniFile FserveIni,"Main","DefaultFolder",FserveFolder
WriteIniFile FserveIni,"Main","Status",ScriptStatus
WriteIniFile FserveIni,"Main","Trigger",FserveTrigger
WriteIniFile FserveIni,"Main","TriggerDelay",TriggerDelay
WriteIniFile FserveIni,"Main","AdvertiseMessage",AdvertiseMessage
WriteIniFile FserveIni,"Main","QueueMessage",QueueMessage
WriteIniFile FserveIni,"Main","Channel",ServerChannel
WriteIniFile FserveIni,"Main","Status",ScriptStatus
WriteIniFile FserveIni,"Main","MaxQueueItems",MaxQueueItems
WriteIniFile FserveIni,"Main","MaxSendItems",MaxSendItems
WriteIniFile FserveIni,"Main","QueueTrigger",QueueTrigger

End Sub

Sub PickFolder_Clicked()
Dim folder
folder = ShowFolderPIcker("Pick Fserve Folder")
if folder <> "" then
  AddItem 2,2,folder
end if
End Sub

Sub RestartFserve()

 SendCommand "/timer fserve off"

 DccSessions.RemoveAll()
 DownloadQueue.RemoveAll() 

 StartFserve CurrentServerNumber

End Sub

Sub StartFserve(ServerNumber)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'check if Fserve Folder Exists
If not fso.folderexists(FserveFolder) then
  SendCommand "/echo -s ERROR: FServe Folder does not exist (" & FserveFolder & ")",ServerNumber
  SendCommand "/echo -s ERROR: Re-start FServe Setup and change default folder [ /! SetupFserve ]",ServerNumber
  set fso = nothing
  Exit sub
End if

'do a recursive file search of folder
Dim objFolder, objFiles, File, objFile,colFiles
Set objFolder = fso.GetFolder(FserveFolder)
Set colFiles = objFolder.Files
FileCount=0
For Each File in colFiles
  FileCount=FileCount+1
  Redim Preserve DownloadFiles(FileCount)
  DownloadFiles(FileCount) = File.Name
Next

SendCommand "/echo -s Fserve Loaded:Total Files (" & FileCount & ")",ServerNumber
SendCommand "/echo -s Starting Fserve",ServerNumber
SendCommand "//timer fserve " & 0 & " " & TriggerDelay & " //msg " & ServerChannel & " " & AdvertiseMessage,ServerNumber
SendCommand "//msg " & ServerChannel & " " & AdvertiseMessage,ServerNumber
End Sub


Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
'SendCommand "/echo -s join " & nickname & " " & scriptstatus
if lcase(Channel) = lcase(ServerChannel) and ScriptStatus = "On" then
  if NickName = MyNickName(ServerNumber) then
     StartFServe ServerNumber
  end if
end if
End Sub

Sub ONPART(Nickname,Host,Channel,Reason,ServerNumber)
if lcase(Channel) = lcase(ServerChannel) then
 if NickName = MyNickName(ServerNumber) then
    SendCommand "/timer fserve off",ServerNumber
    SendCommand "/echo -s Stopped FServe",ServerNumber
 end if
end if
End Sub

Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
'check if its in the right Channel(s)
if lcase(Channel) = lcase(ServerChannel) then
  if lcase(Message) = lcase(FServeTrigger) then
    'check for the fserve trigger
    'start a dcc chat with the person  (check if one is already established)
    if DccSessions.Exists(NickName) = false then   
       'SendCommand "/notice " & NickName & " starting DCC FServe Session",ServerNumber       
       SendCommand "/dcc chat " & NickName, ServerNumber
    else
       SendCommand "/notice " & NickName & " you already have a DCC Fserve Session Open",ServerNumber
    end if
  End If
  if lcase(Message) = lcase(QueueTrigger) then
     SendCommand "//msg " & ServerChannel & " " & QueueMessage,ServerNumber
  end if
End if
End Sub


Sub ONCHATCONNECT(ChatType,Nickname,ServerNumber)
SendCommand "/echo -s DCC Chat Connection Established with " & NickName, ServerNumber
Dim fso,objFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.OpenTextFile(GetIceChatFolder & "scripts\welcome.txt") 
'send the welcome message
While not objFile.AtEndOfStream
 SendCommand "//msg =" & NickName & " " & objFile.readline,ServerNumber
Wend

'create session variable
Dim DCCSession
Set DCCSession = new Session
DCCSession.NickName = NickName
DCCSession.Folder = FServeFolder
DCCSessions.Add NickName, DccSession
End Sub


Sub ONCHATCLOSE(ChatType,Nickname,ServerNumber)
SendCommand "/echo -s Spiffy DCC Chat Connection Closed with " & NickName, ServerNumber

'close the chat window
SendCommand "/closechat " & NickName, ServerNumber

'remove the Session from the Collection
dim i, a
a=DCCSessions.Items
for i = DCCSessions.Count -1 to 0 step -1
 if lcase(a(i).NickName) = lcase(NickName) then
  DCCSessions.Remove(a(i).NickName)
 end if
next
SendCommand "/echo -s Total Sessions = " & TotalSessions,ServerNumber 
End Sub


Sub ONFILECLOSE(FileType,Nickname,FileName,Completed,ServerNumber)
'check the queue for another send
TotalSendItems = TotalSendItems - 1
SendCommand "/echo -s Spiffy DCC File Session closed from " & NickName & ":" & Completed, ServerNumber

CheckNextSend ServerNumber

End Sub

Sub ONCHATTEXT(Nickname, Message,ServerNumber)
'check for any commands here
CheckCommands Message,NickName,ServerNumber
End Sub

Sub ShowFiles(Folder,NickName,ServerNumber)
Dim objFso,objFolder,colFiles,objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Folder)
SendCommand "/msg =" & NickName & " Folder Listing for " & objFolder.Path,ServerNumber
Set colFiles = objFolder.Files
For Each objFile In colFiles
  SendCommand "/msg =" & NickName & " " & objFile.Name,ServerNumber
Next

'Show SubFolders
Dim colFolders,objSubFolder
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
  SendCommand "/msg =" & NickName & " < " & objSubFolder.Name & " >",ServerNumber
Next

SendCommand "/msg =" & NickName & " End of File List" ,ServerNumber

End sub

Sub ChangeFolder(Folder,NickName,ServerNumber)
SendCommand "/msg =" & NickName & " Wanting to Change to " & Folder,ServerNumber
'check for a valid folder name and change
if Folder = ".." then
  if DccSessions.Item(NickName).Folder <> FserveFolder then
     DccSessions.Item(NickName).Folder = Left(DccSessions.Item(NickName).Folder, instrrev(DccSessions.Item(NickName).Folder,"\")-1)
     SendCommand "/msg =" & NickName & " Successfully Changed to " & DccSessions.Item(NickName).Folder,ServerNumber   
     Exit Sub
  else
     SendCommand "/msg =" & NickName & " Can not change, at root folder",ServerNumber
  end if
end if

Dim objFso,objFolder,colFiles,objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(DccSessions.Item(NickName).Folder)
Dim colFolders,objSubFolder
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
  if lcase(objSubFolder.Name) = lcase(Folder) then
     DccSessions.Item(NickName).Folder=DccSessions.Item(NickName).Folder & "\" & objSubFolder.Name
     SendCommand "/msg =" & NickName & " Successfully Changed to " & DccSessions.Item(NickName).Folder,ServerNumber   
  End if
Next

End Sub

Sub CheckCommands(Message,NickName,ServerNumber)
dim i, command ,file
Dim fso
if Instr(Message," ") then
   Command = Left(Message,Instr(Message," ")-1)
else
   Command = Message
end if

Select Case Command
  case "get"
     if DCCSessions.Exists(NickName) then
      if instr(Message," ") Then       
       file = DccSessions.Item(NickName).Folder & Mid(Message,instr(Message," ")+1)
       Set fso = CreateObject("Scripting.FileSystemObject")
       'check if File Exists, if so, add it to the Queue
       If fso.fileexists(file) then
         'add it to the queue       
         AddToQueue File,NickName,ServerNumber
       end if     
      end if
     end if
     exit sub
  case "dir","ls"
     if DCCSessions.Exists(NickName) then
       ShowFiles DccSessions.Item(NickName).Folder,NickName,ServerNumber
     end if
     exit sub
  case "cd"
     if DCCSessions.Exists(NickName) then
       if instr(Message," ") Then
         ChangeFolder mid(Message,instr(Message," ")+1),NickName,ServerNumber
       end if
     end if
     exit sub
  case "queue" 'get queue for user, and show all as well
    SendCommand "//msg =" & NickName & " Total Files in your queue = " & TotalQueueItems(NickName) & " - Total Files in Queue %totalqueue / %maxqueue" ,ServerNumber
    exit sub
  case "sends"
    SendCommand "//msg =" & NickName & " Total DCC Sends %totalsends / %maxsends" ,ServerNumber
  case "clearqueue"
    SendCommand "//msg =" & NickName & " Clearing your file queue",ServerNumber
    ClearQueue NickName
  case "quit"
    SendCommand "/closechat " & NickName, ServerNumber
 
End select

End Sub

Sub ClearQueue(NickName)
Dim a,c,i
c=0
a = DownloadQueue.Items 
for i = DownloadQueue.Count -1 to 0 step -1
    if a(i).NickName = NickName then
      DownloadQueue.Remove(a(i).Key)
    end if
next

End Sub

Sub AddToQueue(File,NickName,ServerNumber)
Dim qi
set qi = new QueueItem
qi.FileName = file
qi.NickName = NickName
qi.Key = RandomKey
DownloadQueue.Add qi.Key, qi
SendCommand "/msg =" & NickName & " Added " & File & " to queue" ,ServerNumber
'check total sends, if not , fire the queue
CheckNextSend ServerNumber
End Sub

Function TotalQueueItems(NickName)
Dim a,c,i
c=0
  a = DownloadQueue.Items 
  'SendCommand "/echo -s Total Items "  & DownloadQueue.Count
  for i = 0 to DownloadQueue.Count -1
    'SendCommand "/echo -s Item " & a(i).NickName & ":" & NickName
    if a(i).NickName = NickName then c = c + 1
  next
TotalQueueItems=c
End Function

Sub CheckNextSend(ServerNumber)
Dim a
if TotalQueue > 0 then
 if Int(TotalSendItems) < Int(MaxSendItems) then
   TotalSendItems = TotalSendItems+1
   a=DownloadQueue.Items
   SendCommand "/dcc send " & a(0).NickName & " " & a(0).Filename,ServerNumber
   DownloadQueue.Remove(a(0).Key)
 end if
end if
End Sub

Function TotalQueue()
TotalQueue = DownloadQueue.Count
End Function

Function MaxQueue()
MaxQueue = MaxQueueItems
End Function

Function MaxSends()
MaxSends = MaxSendItems
End Function

Function TotalSends()
TotalSends=TotalSendItems
End Function

Function FserveFileCount()
FServeFileCount = FileCount
End Function

Function Trigger()
Trigger=FServeTrigger
End Function

Function QTrigger()
QTrigger = QueueTrigger
End Function

Function AdvertMsg()
AdvertMsg = AdvertiseMessage
End Function

Function QueueMsg()
QueueMsg = QueueMessage
End Function

Function TotalSessions()
TotalSessions=DCCSessions.Count
End Function

Function RandomKey
RandomKey = GetIdentifier("$rnd(100000,999999)")
End Function


Now.. the script does come with a Dialog Setup, so you can set the Script up in a Window, which is MUCH easier to do.
The script does come with default values, so I would change these to suite your needs, especially the channel it serves in, which by default is #scriptchannel. You can run the Setup from the Script Menu,  or type /! SetupFserve. It will initially run the setup, if the fserve.ini file does not exist.

Finally, add the welcome file. Here is the basic contents of it, and this is displayed everytime someone logs onto the IceServe Script.
Call the file welcome.txt.

Code: [Select]
Welcome to IceServe 1.0
We are currently serving %filecount total files
Valid Commands are 4dir, cd, get, queue, sends, clearqueue
.
.
.
Please enjoy your stay


Feel free to make adjustments, fixes, additions, to this script. I would hope with a bit of community effort, we can build this script up, and make it a lot better, this is just a good start, for the time being.
« Last Edit: June 23, 2007, 11:18:45 AM by Snerf »
The IceChat God

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Fserve Script - IceServe 1.0
« Reply #1 on: June 23, 2007, 11:22:10 AM »
One last thing. Please do not post a whole bunch of "it does not work" messages, because you need to have some knowledge of what an fserve script is, and how they work, in order to use this.
This is a very advanced script, and requires a bit of know-how to make it work.
As long as you set the proper default settings, it should work.
So, if I see a message that says "it doesnt work", and no proper and valid explanation, I will just delete the post.

Thanks
The IceChat God

wlfpck

  • Newbie
  • *
  • Posts: 9
Re: Fserve Script - IceServe 1.0
« Reply #2 on: July 06, 2007, 11:57:01 PM »
Hey.  Great to see this script up.  I will be testing it as soon as I get back.  Love icechat btw