-
Notifications
You must be signed in to change notification settings - Fork 2
/
AutoReconnect.txt
78 lines (67 loc) · 2.28 KB
/
AutoReconnect.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'Description:
' This script will automatically reconnect or connect your bot when it is not online.
'
'Settings: Name Default Description
' ReconnectTime 60 The amount of seconds until it will
' retry connecting.
' ForceReconnect False When enabled, forces a reconnect even
' if the bot is already online.
Option Explicit
Private Connected
Script("Name") = "AutoReconnect"
Script("Major") = 1
Script("Minor") = 3
Script("Revision") = 0
Script("Author") = "Ribose"
Sub Event_Load()
CreateObj "LongTimer", "Reconnect"
Connected = IsOnline()
CheckStartTimer
End Sub
Sub Event_PacketSent(Protocol, ID, Length, Data)
Connected = True
End Sub
Sub Event_ServerError(Message)
If Message = "All connections closed." Then
Reconnect.Enabled = False
Connected = False
CheckStartTimer
End If
End Sub
Sub CheckStartTimer()
If Reconnect.Enabled = Connected Then
Reconnect.Interval = GetNumericSettingsEntry("ReconnectTime", 60)
Reconnect.Enabled = CheckCanReconnect()
End If
End Sub
Sub Reconnect_Timer()
If CheckCanReconnect() Then
AddChat vbYellow, "The Auto-Reconnect script is connecting your bot..."
If GetBooleanSettingsEntry("ForceReconnect", False) Then
AddChat vbYellow, "You are being reconnected while online because the setting is " & _
"set in scripts.ini. Set it to false to disable this behavior."
Disconnect
End If
Connect
End If
End Sub
Function CheckCanReconnect()
CheckCanReconnect = GetBooleanSettingsEntry("ForceReconnect", False) Or Not Connected
End Function
Function GetNumericSettingsEntry(SettingName, DefaultValue)
Dim Value
Value = GetSettingsEntry(SettingName)
If IsNumeric(Value) Then
GetNumericSettingsEntry = CInt(Value)
Else
GetNumericSettingsEntry = DefaultValue
End If
End Function
Function GetBooleanSettingsEntry(SettingName, DefaultValue)
Dim Value
Value = GetSettingsEntry(SettingName)
Select Case LCase(Value)
Case "true", "y", "yes" : GetBooleanSettingsEntry = True
Case Else : GetBooleanSettingsEntry = False
End Select
End Function