Skip to content
Permalink
Browse files

Overhaul all handling of losing connection to improve AutoReconnect.

- The bot now has three settings for AutoReconnect:
  [Features]
  ReconnectType=0, 1, or 2  [default 2]
  ReconnectDelay=SECONDS    [default 300  -- 5 minutes]
  ReconnectDelayMax=SECONDS [default 3600 -- 1 hour]

  When Type=0, no auto-reconnection is done.
  When Type=1, the bot waits (ReconnectDelay) seconds any time it loses
               connection for a "non-client reason".
  When Type=2, the bot waits (ReconnectDelay * NUMBER OF TRIES) seconds
               any time it loses connection for a "non-client reason".
               The wait cannot exceed ReconnectDelayMax.

- In any case, AutoReconnect will first try a "0-wait" reconnect if a
  connection was previously active (in most cases). That way, network
  errors on the client end can be quickly overcome.

- Since ReconnectDelay is now in seconds, previous settings will
  probably be unusual under this system.
  Fortunately, 1000 seconds (old ReconnectDelay default) is
  16 minutes 40 seconds and not too different magnitude from
  300 seconds (5 minutes). New installations will be set to 300 seconds.
  AutoReconnect will always wait at least 1 second.

- Changed the way DoDisconnect() works across the bot so that it is the
  only place resources are cleaned up, and it is called consistently.
  DoDisconnect() now has a notion of "client-initiated" disconnects and
  the opposite, "non-client reason", can then be followed up with a call
  to the AutoReconnect process.

- Any disconnect that is unrecoverable, such as version check errors
  (not done by BNLS with BNLS finder active), will go through
  AutoReconnect now.

- The default DoDisconnect() is unrecoverable and most of the calls to
  it are unchanged.

- BNLS closing connection prematurely and a different case of
  BNLS version check failing now go through BNLS finder
  (but not AutoReconnect).

- MCP, BNCS, and BNLS now handle losing connection from the proxy
  handshake better and should try AutoReconnect.

- The bot now handles "[BNCS] Disconnected." without a socket error
  as a reason to try AutoReconnect (possible IP ban).

- Getting a "CD-Key in use" error with the owner equal to the one the
  bot should have sent results in the bot trying AutoReconnect.
  This is anti-ghosting support. No "0-wait" reconnect will occur.

- Changed and standardized the appearance of connection errors.
  Since many of the specific features of the old error messages have
  changed or become obsolete, most custom errors have been removed.
  (IP bans now result in a connection close with no socket error;
   there are no server IPs listed under gateway addresses;
   etc.)
  Instead, with the more functional AutoReconnect system, it should be
  possible to return online with varying client, network, and server
  issues of any kind.

- AutoReconnect displays the time until reconnect with the same interval
  display function as uptime, meaning that it will be in a sane
  human-readable format.

- Refactoring:
    Removed clsErrorHandler, CloseAllConnections(), and some other
    functionality that is no longer used.
    HandleBnlsError() still calls into the BNLS finder before
    trying AutoReconnect [to the same server].
    The ReconnectTimer timer is now like the ExReconnectTimer and is a
    1000-millisecond timer using a Long "ticks" counter until the
    reconnect, supporting longer time frames. There is also only one
    such timer in the bot, simplifying the code.
  • Loading branch information...
nmbook committed Nov 20, 2017
1 parent f65063b commit f22dd106a3a4070639a9119ec7e53b1d986f5617
@@ -46,7 +46,6 @@ Private m_bWhisperGreet As Boolean
Private m_bUseRealm As Boolean
Private m_bNoTray As Boolean
Private m_bShowOfflineFriends As Boolean
Private m_lReconnectDelay As Long
Private m_lAutofilterMS As Long
Private m_bNoAutocompletion As Boolean
Private m_bNoColoring As Boolean
@@ -360,14 +359,6 @@ Public Property Let ShowOfflineFriends(ByVal bShowOfflineFriends As Boolean)
m_bShowOfflineFriends = bShowOfflineFriends
End Property

Public Property Get ReconnectDelay() As Long
ReconnectDelay = m_lReconnectDelay
End Property

Public Property Let ReconnectDelay(ByVal lReconnectDelay As Long)
m_lReconnectDelay = lReconnectDelay
End Property

Public Property Get UsingDirectFList() As Boolean
UsingDirectFList = Config.FriendsListTab
End Property
@@ -376,6 +367,14 @@ Public Property Let UsingDirectFList(ByVal bUsingDirectFList As Boolean)
Config.FriendsListTab = bUsingDirectFList
End Property

Public Property Get ReconnectDelay() As Long
ReconnectDelay = Config.ReconnectDelay * 1000
End Property

Public Property Let ReconnectDelay(ByVal lReconnectDelay As Long)
Config.ReconnectDelay = lReconnectDelay \ 1000
End Property

Public Property Get AutofilterMS() As Long
AutofilterMS = m_lAutofilterMS
End Property
@@ -79,7 +79,9 @@ Private m_NewPassword As String
'[FEATURES]
Private m_UseBackupChannel As Boolean
Private m_BackupChannel As String
Private m_ReconnectType As Byte
Private m_ReconnectDelay As Long
Private m_ReconnectDelayMax As Long
Private m_BotMail As Boolean
Private m_ProfileAmp As Boolean
Private m_VoidView As Boolean
@@ -480,6 +482,14 @@ Public Property Let BackupChannel(ByVal sValue As String)
m_BackupChannel = sValue
End Property

Public Property Get ReconnectType() As Byte
ReconnectType = m_ReconnectType
End Property

Public Property Let ReconnectType(ByVal sValue As Byte)
m_ReconnectType = sValue
End Property

Public Property Get ReconnectDelay() As Long
ReconnectDelay = m_ReconnectDelay
End Property
@@ -488,6 +498,14 @@ Public Property Let ReconnectDelay(ByVal sValue As Long)
m_ReconnectDelay = sValue
End Property

Public Property Get ReconnectDelayMax() As Long
ReconnectDelayMax = m_ReconnectDelayMax
End Property

Public Property Let ReconnectDelayMax(ByVal sValue As Long)
m_ReconnectDelayMax = sValue
End Property

Public Property Get BotMail() As Boolean
BotMail = m_BotMail
End Property
@@ -1757,7 +1775,9 @@ Public Sub Save(Optional ByVal sFilePath As String = vbNullString)

WriteSetting SECTION_FEATURES, "UseBackupChannel", m_UseBackupChannel
WriteSetting SECTION_FEATURES, "BackupChannel", m_BackupChannel
WriteSetting SECTION_FEATURES, "ReconnectType", m_ReconnectType
WriteSetting SECTION_FEATURES, "ReconnectDelay", m_ReconnectDelay
WriteSetting SECTION_FEATURES, "ReconnectDelayMax", m_ReconnectDelayMax
WriteSetting SECTION_FEATURES, "BotMail", m_BotMail
WriteSetting SECTION_FEATURES, "ProfileAmp", m_ProfileAmp
WriteSetting SECTION_FEATURES, "VoidView", m_VoidView
@@ -1954,7 +1974,9 @@ Private Sub LoadDefaults()
'[Features]
m_UseBackupChannel = False
m_BackupChannel = vbNullString
m_ReconnectDelay = 1000
m_ReconnectType = 2
m_ReconnectDelay = 300
m_ReconnectDelayMax = 3600
m_BotMail = True
m_ProfileAmp = False
m_VoidView = False
@@ -2305,7 +2327,9 @@ Private Sub LoadVersion6Config()

m_UseBackupChannel = ReadSettingB(SECTION_FEATURES, "UseBackupChannel", m_UseBackupChannel)
m_BackupChannel = ReadSetting(SECTION_FEATURES, "BackupChannel", m_BackupChannel)
m_ReconnectType = ReadSettingL(SECTION_FEATURES, "ReconnectType", m_ReconnectType)
m_ReconnectDelay = ReadSettingL(SECTION_FEATURES, "ReconnectDelay", m_ReconnectDelay)
m_ReconnectDelayMax = ReadSettingL(SECTION_FEATURES, "ReconnectDelayMax", m_ReconnectDelayMax)
m_BotMail = ReadSettingB(SECTION_FEATURES, "BotMail", m_BotMail)
m_ProfileAmp = ReadSettingB(SECTION_FEATURES, "ProfileAmp", m_ProfileAmp)
m_VoidView = ReadSettingB(SECTION_FEATURES, "VoidView", m_VoidView)
@@ -2481,8 +2505,11 @@ Private Sub ConformValues()
If m_MaxBacklogSize < 0 Then m_MaxBacklogSize = 10000
If m_MaxLogFileSize < 0 Then m_MaxLogFileSize = 50000000

If m_ReconnectDelay < 0 Then m_ReconnectDelay = 1000
If m_ReconnectDelay > 60000 Then m_ReconnectDelay = 60000
If m_ReconnectType < 0 Or m_ReconnectType > 2 Then m_ReconnectType = 2
If m_ReconnectDelay < 0 Then m_ReconnectDelay = 5
If m_ReconnectDelay > 86400 Then m_ReconnectDelay = 86400
If m_ReconnectDelayMax < m_ReconnectDelay Then m_ReconnectDelayMax = m_ReconnectDelay
If m_ReconnectDelayMax > 86400 Then m_ReconnectDelayMax = 86400

If m_PingSpoofing < 0 Or m_PingSpoofing > 2 Then m_PingSpoofing = 0
If m_ProxyPort < 0 Or m_ProxyPort > 65535 Then m_ProxyPort = 1080

This file was deleted.

1 comment on commit f22dd10

@Davnit

This comment has been minimized.

Copy link
Collaborator

commented on f22dd10 Nov 20, 2017

Looks like this completes #43

Please sign in to comment.
You can’t perform that action at this time.