VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmRemote 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Remote Controller"
   ClientHeight    =   6180
   ClientLeft      =   4215
   ClientTop       =   2130
   ClientWidth     =   7200
   Icon            =   "frmRemote.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   6180
   ScaleWidth      =   7200
   Begin VB.Timer PauseTimer 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   1560
      Top             =   5880
   End
   Begin VB.CommandButton Command20 
      Caption         =   "Save Log"
      Height          =   375
      Left            =   3720
      TabIndex        =   16
      ToolTipText     =   "Save client status log to a file"
      Top             =   5640
      Width           =   1215
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   0
      Top             =   5400
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Command7 
      Caption         =   "Help"
      Height          =   375
      Left            =   5040
      TabIndex        =   17
      ToolTipText     =   "Get help on how to run a remote session"
      Top             =   5640
      Width           =   975
   End
   Begin VB.Frame Frame5 
      Caption         =   "Interactive Mode"
      Height          =   3975
      Left            =   1680
      TabIndex        =   22
      Top             =   1560
      Width           =   5415
      Begin VB.CommandButton Command11 
         Caption         =   "Insert Speech Modifier"
         Enabled         =   0   'False
         Height          =   255
         Left            =   480
         TabIndex        =   30
         Top             =   3360
         Width           =   2055
      End
      Begin VB.CommandButton Command9 
         Caption         =   "Insert Variable"
         Enabled         =   0   'False
         Height          =   255
         Left            =   480
         TabIndex        =   29
         Top             =   3000
         Width           =   2055
      End
      Begin VB.CommandButton Command8 
         Caption         =   "Send command..."
         Enabled         =   0   'False
         Height          =   375
         Left            =   3600
         TabIndex        =   28
         Top             =   1080
         Width           =   1695
      End
      Begin VB.CommandButton Command19 
         Caption         =   "Cancel Current Script"
         Enabled         =   0   'False
         Height          =   375
         Left            =   3600
         TabIndex        =   13
         ToolTipText     =   "Cancel the currently running script on the remote machine"
         Top             =   600
         Width           =   1695
      End
      Begin VB.CommandButton Command10 
         Caption         =   "Speak Text"
         Enabled         =   0   'False
         Height          =   285
         Left            =   2880
         TabIndex        =   12
         ToolTipText     =   "Speak a line of text on the remote machine"
         Top             =   3000
         Width           =   2055
      End
      Begin VB.TextBox Text2 
         Height          =   405
         Left            =   240
         TabIndex        =   10
         ToolTipText     =   "Caption of Yes/No dialog"
         Top             =   2400
         Width           =   4935
      End
      Begin VB.CommandButton Command6 
         Caption         =   "Send Yes/No Box"
         Enabled         =   0   'False
         Height          =   285
         Left            =   2880
         TabIndex        =   11
         ToolTipText     =   "Have a yes/no dialog pop up on the remote machine"
         Top             =   3360
         Width           =   2055
      End
      Begin VB.TextBox Text1 
         Height          =   735
         Left            =   120
         ScrollBars      =   1  'Horizontal
         TabIndex        =   8
         Top             =   600
         Width           =   3015
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Send Script Command(s)"
         Enabled         =   0   'False
         Height          =   285
         Left            =   600
         TabIndex        =   9
         ToolTipText     =   "Send script command to the remote machine"
         Top             =   1440
         Width           =   2055
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         Caption         =   "Remote Commands"
         Height          =   255
         Left            =   3600
         TabIndex        =   27
         Top             =   240
         Width           =   1695
      End
      Begin VB.Line Line3 
         X1              =   3480
         X2              =   3480
         Y1              =   240
         Y2              =   1920
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         Caption         =   "Text"
         ForeColor       =   &H80000006&
         Height          =   255
         Left            =   240
         TabIndex        =   24
         Top             =   2040
         Width           =   4935
      End
      Begin VB.Line Line1 
         X1              =   120
         X2              =   5280
         Y1              =   1920
         Y2              =   1920
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         Caption         =   "Send Raw Script Command(s):"
         ForeColor       =   &H80000007&
         Height          =   255
         Left            =   120
         TabIndex        =   23
         Top             =   240
         Width           =   3255
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "Custom Script"
      Height          =   1935
      Left            =   120
      TabIndex        =   21
      Top             =   1920
      Width           =   1455
      Begin MSComctlLib.ProgressBar ProgBar 
         Height          =   255
         Left            =   120
         TabIndex        =   25
         Top             =   1320
         Width           =   1215
         _ExtentX        =   2143
         _ExtentY        =   450
         _Version        =   393216
         Appearance      =   1
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Send Script..."
         Enabled         =   0   'False
         Height          =   375
         Left            =   120
         TabIndex        =   7
         ToolTipText     =   "Send a script to the remote machine, into the ""custom"" session position"
         Top             =   480
         Width           =   1215
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Caption         =   "Status"
         Height          =   255
         Left            =   120
         TabIndex        =   26
         Top             =   1080
         Width           =   1215
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Session Position"
      Height          =   1815
      Left            =   120
      TabIndex        =   20
      Top             =   0
      Width           =   1455
      Begin VB.OptionButton Option6 
         Caption         =   "Interactive"
         Enabled         =   0   'False
         Height          =   255
         Left            =   120
         MaskColor       =   &H00000000&
         TabIndex        =   5
         ToolTipText     =   "Switch to Interactive Mode, which lets you send single commands one by one"
         Top             =   1440
         Value           =   -1  'True
         Width           =   1215
      End
      Begin VB.OptionButton Option5 
         Caption         =   "Custom"
         Enabled         =   0   'False
         Height          =   255
         Left            =   120
         MaskColor       =   &H00000000&
         TabIndex        =   4
         ToolTipText     =   "Run a custom script sent using the ""Send Script"" button"
         Top             =   1200
         Width           =   1215
      End
      Begin VB.OptionButton Option4 
         Caption         =   "Wakening"
         Enabled         =   0   'False
         Height          =   255
         Left            =   120
         MaskColor       =   &H00000000&
         TabIndex        =   3
         ToolTipText     =   "Run the user's Wakening script"
         Top             =   960
         Width           =   1215
      End
      Begin VB.OptionButton Option3 
         Caption         =   "Suggestions"
         Enabled         =   0   'False
         Height          =   255
         Left            =   120
         MaskColor       =   &H00000000&
         TabIndex        =   2
         ToolTipText     =   "Run the user's Suggestions script"
         Top             =   720
         Width           =   1215
      End
      Begin VB.OptionButton Option2 
         Caption         =   "Deepener"
         Enabled         =   0   'False
         Height          =   255
         Left            =   120
         MaskColor       =   &H00000000&
         TabIndex        =   1
         ToolTipText     =   "Run the user's Deepener script"
         Top             =   480
         Width           =   1095
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Induction"
         Enabled         =   0   'False
         Height          =   255
         Left            =   120
         MaskColor       =   &H00000000&
         TabIndex        =   0
         ToolTipText     =   "Run the user's Induction script"
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Status Log (double-click for full view)"
      Height          =   1455
      Left            =   1680
      TabIndex        =   19
      Top             =   0
      Width           =   5415
      Begin VB.TextBox ClientStatus 
         Height          =   1095
         Left            =   240
         Locked          =   -1  'True
         MultiLine       =   -1  'True
         ScrollBars      =   3  'Both
         TabIndex        =   6
         Top             =   240
         Width           =   5055
      End
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Stop Remote Session"
      Enabled         =   0   'False
      Height          =   375
      Left            =   1920
      TabIndex        =   15
      ToolTipText     =   "Stop the running remote session"
      Top             =   5640
      Width           =   1695
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Start Remote Session"
      Height          =   375
      Left            =   120
      TabIndex        =   14
      ToolTipText     =   "Start up a remote session by contacting other machine"
      Top             =   5640
      Width           =   1695
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Exit"
      Height          =   375
      Left            =   6120
      TabIndex        =   18
      ToolTipText     =   "Stop remote session and exit the Remote Controller"
      Top             =   5640
      Width           =   975
   End
   Begin VB.Image Image1 
      Height          =   1575
      Left            =   120
      Picture         =   "frmRemote.frx":08CA
      Stretch         =   -1  'True
      Top             =   3960
      Width           =   1455
   End
End
Attribute VB_Name = "frmRemote"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Virtual Hypnotist
'©2003-2008 FollowTheWatch Software
'http://vhypno.sourceforge.net
'http://sourceforge.net/projects/vhypno
'Contact - followthewatch55@yahoo.com

'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.

'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Option Explicit
Public Connected As Boolean
Public AckResponse As String
Public Proceed As Boolean

Private Sub ClientStatus_Change()
ClientStatus.SelStart = Len(ClientStatus)
ClientStatus.SelLength = 1
End Sub

Private Sub ClientStatus_DblClick()
Call frmViewer.View(1, "Client Status Log", 0, ClientStatus.Text)
End Sub

Private Sub Command1_Click()
Command1.Enabled = False
SendCommand Text1.Text, ClientSN
Command1.Enabled = True
End Sub

Private Sub Command10_Click()
Command10.Enabled = False
SendCommand "<speak> " + Text2.Text, ClientSN
Command10.Enabled = True
End Sub

Private Sub Command11_Click()
ScriptMaker.AppendOnly = True
Set ScriptMaker.DestObject = Me.Text2
Me.PopupMenu ScriptMaker.mnuInsertSpeech, , Command11.Left + Frame5.Left + 100, Command11.top
End Sub

Private Sub Command19_Click()
Command19.Enabled = False
SendCommand "<cancel>", ClientSN
Command19.Enabled = True
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Command20_Click()
On Error GoTo 20
CommonDialog1.InitDir = App.path
CommonDialog1.CancelError = True
CommonDialog1.DefaultExt = ".txt"
CommonDialog1.Filter = "Text File (*.txt)|*.txt|"
CommonDialog1.DialogTitle = "Save Log File"
CommonDialog1.action = 2
If ExceptionHandlers = True Then On Error GoTo ErrorHandler
StartSaving:
Dim FileExists As Boolean
Dim i As Integer
i = Len(Dir$(CommonDialog1.FileName))
If err Or i = 0 Then
    FileExists = False
    Else
        FileExists = True
End If

If FileExists = True Then
    If MsgBox("Overwrite existing file?", vbYesNo + vbQuestion + vbDefaultButton2, "Virtual Hypnotist") = vbNo Then Exit Sub
    
    'erase contents of old file
    Open CommonDialog1.FileName For Output As #1
        Print #1, ""
    Close #1
End If

'Save File
Open CommonDialog1.FileName For Binary Access Write As #1
    Put #1, , ClientStatus.Text
Close #1
     
20 Exit Sub
ErrorHandler:
err.Source = "Remote Controller"
Call ErrorReport("An error occurred while saving the log file.", vbCritical)
Exit Sub
End Sub

Private Sub Command3_Click()
Dim NewTickCount As Long

'send start command to client
SendCommand "<start>", ClientSN

'wait for acknowledgement
OldTickCount = GetTickCount
While Connected = False
    DoEvents
    NewTickCount = GetTickCount
    If NewTickCount - OldTickCount > 10000 Then
        If ChatRoom = False Then MsgBox "Remote machine is not responding", vbOKOnly + vbExclamation, "Virtual Hypnotist"
        If ChatRoom = True Then MsgBox "Remote group is not responding", vbOKOnly + vbExclamation, "Virtual Hypnotist"
        Exit Sub
    End If
Wend

'Enable controls
Option1.Enabled = True
Option2.Enabled = True
Option3.Enabled = True
Option4.Enabled = True
Option5.Enabled = False
Option6.Enabled = True
Command1.Enabled = True
Command3.Enabled = False
Command4.Enabled = True
If ChatRoom = False Then Command5.Enabled = True Else Command5.Enabled = False
Command6.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command11.Enabled = True
Command19.Enabled = True
Option6.value = True
End Sub

Private Sub Command4_Click()

SendCommand "<stop>", ClientSN
Connected = False
frmRemoteList.ConnectCount = 0

'Disable controls
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
Option4.Enabled = False
Option5.Enabled = False
Option6.Enabled = False
Command1.Enabled = False
Command3.Enabled = True
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command10.Enabled = False
Command11.Enabled = False
Command19.Enabled = False
End Sub

Private Sub Command5_Click()
On Error GoTo 10
CommonDialog1.InitDir = App.path
CommonDialog1.CancelError = True
CommonDialog1.DefaultExt = ".txt"
CommonDialog1.Filter = "Text File (*.txt)|*.txt|"
CommonDialog1.DialogTitle = "Send Script"
CommonDialog1.action = 1
If ExceptionHandlers = True Then On Error GoTo ErrorHandler
StartLoading:
Dim FileExists As Boolean
Dim i As Integer
Dim j As Integer 'retry counter
Dim k As Integer 'transmission error counter

i = Len(Dir$(CommonDialog1.FileName))
If err Or i = 0 Then
    FileExists = False
    Else
        FileExists = True
End If

If ExceptionHandlers = True Then On Error GoTo ErrorHandler
If FileExists = False Then Error 53

Dim TempScript As String
Dim NumLines As Integer
Dim RetryNum As Integer

'Get number of lines in the file
NumLines = GetLines(CommonDialog1.FileName, True)

If NumLines = 0 Then Exit Sub

'send transmit command to client
SendCommand "<transmit> " + LTrim$(Str$(NumLines)), ClientSN

'Clear response
AckResponse = ""

'wait until client is ready
Do Until AckResponse = "Ready to receive"
    DoEvents
Loop

Call UpdateStatus("Transmitting file...")

i = 0

'load file, and send to remote machine
Open CommonDialog1.FileName For Input As #1
    TempScript = ""
    Do While Not EOF(1)
        DoEvents
SkipLine:
        Line Input #1, TempScript
        If Left$(Trim2(TempScript), 1) <> "#" And Trim2(TempScript) <> "" Then
            i = i + 1
        Else
            GoTo SkipLine
        End If
        'Clear response
        AckResponse = ""
        k = 15000
        RetryNum = 2000
Retry:
        j = 0
        'send line to client
        SendCommand TempScript, ClientSN
        'wait for client
        Do Until Left(AckResponse, 7) = "Proceed" Or AckResponse = "Script received"
            j = j + 1
            Sleep2 (1)
            If j = RetryNum Then
                Call UpdateStatus("Transmission error. Waiting...")
            End If
            If j = k Then
                Call UpdateStatus("Cannot send script - giving up")
                ProgBar.value = 0
                Close #1
                Exit Sub
            End If
        Loop
        If j >= RetryNum Then Call UpdateStatus("Continuing...")
        'show status
        ProgBar.value = Int((i / NumLines) * 100)
    Loop
Close #1

'Enable Custom session position option
Option5.Enabled = True

10 Exit Sub
ErrorHandler:
err.Source = "Remote Controller"
Call ErrorReport("An error occurred while loading the script file.", vbCritical)
End Sub

Private Sub Command6_Click()
Command6.Enabled = False
SendCommand "<yesno> " + Text2.Text, ClientSN
Command6.Enabled = True
End Sub

Private Sub Command7_Click()
If ExceptionHandlers = True Then On Error GoTo ErrorHandler

Shell "hh " + App.path + "\vh.chm::/hypnochat.html#RC", vbNormalFocus
Exit Sub

ErrorHandler:
err.Source = "Remote Controller"
   Call ErrorReport("An error occurred while loading Windows HTML Help.", vbExclamation)
   
End Sub

Private Sub Command8_Click()
ScriptMaker.RemoteSend = True
ScriptMaker.cmdEnd.Enabled = False
ScriptMaker.cmdGoto.Enabled = False
ScriptMaker.cmdGotoLabel.Enabled = False
ScriptMaker.cmdLoadVars.Enabled = False
ScriptMaker.cmdSaveVars.Enabled = False
ScriptMaker.cmdIf.Enabled = False

Me.PopupMenu ScriptMaker.mnuInsertCmd, , Command8.Left + Frame5.Left + 100, Command8.top + Frame5.top
End Sub

Private Sub Command9_Click()
ScriptMaker.AppendOnly = True
Set ScriptMaker.DestObject = Me.Text2
Me.PopupMenu ScriptMaker.mnuInsertVariable, , Command9.Left + Frame5.Left + 100, Command9.top
End Sub

Private Sub Form_Activate()
If aimSignOn.wskAIM.State <> sckConnected Then
    MsgBox "You must log in with HypnoChat to use the Remote Controller", vbOKOnly + vbCritical, "Virtual Hypnotist"
    Unload Me
    Exit Sub
End If
End Sub

Public Sub UpdateStatus(Txt As String, Optional NoNewline As Boolean)
Dim TimeStamp As String
TimeStamp = "[" + Format(time, "hh:mm") + "]"
ClientStatus.Text = ClientStatus.Text + TimeStamp + " " + Txt
If NoNewline = False Then ClientStatus.Text = ClientStatus.Text + vbCrLf
End Sub

Private Sub Form_Load()
Me.Left = (ScreenX / 2) - (Me.Width / 2)
Me.top = (ScreenY / 2) - (Me.Height / 2)
UpdateStatus ("--- Virtual Hypnotist " + LTrim$(Str$(App.Major)) + "." + LTrim$(Str$(App.Minor)) + " build " + LTrim$(Str$(App.Revision)) + " ---")
If ChatRoom = False Then
    UpdateStatus ("Subject SN: " + ClientSN)
Else
    UpdateStatus ("Chat Room: " + ChatName)
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Connected = True Then SendCommand "<stop>", ClientSN
ClientSN = ""
ChatRoom = False
Connected = False
frmRemoteList.ConnectCount = 0
End Sub

Private Sub Option1_Click()
SendCommand "<cancel>", ClientSN
SendCommand "<run> 1", ClientSN
End Sub

Private Sub Option2_Click()
SendCommand "<cancel>", ClientSN
SendCommand "<run> 2", ClientSN
End Sub

Private Sub Option3_Click()
SendCommand "<cancel>", ClientSN
SendCommand "<run> 3", ClientSN
End Sub

Private Sub Option4_Click()
SendCommand "<cancel>", ClientSN
SendCommand "<run> 4", ClientSN
End Sub

Private Sub Option5_Click()
SendCommand "<cancel>", ClientSN
SendCommand "<run> 6", ClientSN
End Sub

Private Sub Option6_Click()
SendCommand "<cancel>", ClientSN
End Sub

Private Sub PauseTimer_Timer()
Proceed = True
End Sub

