Microsoft Chat Server Development Guide |
---|
' It is always good VB coding to explicitly check your variable declarations
Option Explicit
' #if control over whether to support a property page
#Const SUPPORT_PPAGE = 1
' This extension implements these two extensibility interfaces
Implements CHATSVCLib.IChatExtensionCallBack
Implements CHATSVCLib.IChatServerCallBack
' Name of the chat audit log file, This extension will write an entry to this
' file whenever a user logs out from the chat server
Const LOGFILE = "C:\CHAT.LOG"
' Keep a reference to the registrar component to allow ad-hoc binding for events
Dim gRegistrar As CHATSVCLib.IChatRegistrar
' Remember a user's login time
Dim gLoginTimes As Collection
' Declare a object class public property (set by a property page)
' to enable/disable logging
#If SUPPORT_PPAGE Then
Public EnableLogging As Boolean
#End If
' Define a short friendly name for this extension
Private Property Get IChatExtensionCallBack_Name() As String
IChatExtensionCallBack_Name = "LogMonitor"
End Property
' The Init method is called by the server to allow the extension to initialize
Private Function IChatExtensionCallBack_Init(ByVal Server As CHATSVCLib.IChatServer, ByVal Registrar As CHATSVCLib.IChatRegistrar) As Long
Set gLoginTimes = New Collection ' Hold a collection of times users logged in
Set gRegistrar = Registrar ' Keep a copy of the interface to the registrar object
' Bind to the New and Close user notifications
If Not gRegistrar Is Nothing Then
gRegistrar.AddServerEvent ("OnNewUser")
gRegistrar.AddServerEvent ("OnCloseUser")
End If
#If SUPPORT_PPAGE Then
EnableLogging = True ' Enable logging by default
#End If
' An extension must return zero to indicate it initialize correctly
IChatExtensionCallBack_Init = 0
End Function
' Confirm it is the PostUpdate (confirmation call) for a new user
' and take a note of what time this user logs in
Private Function IChatServerCallBack_OnNewUser(ByVal User As CHATSVCLib.IChatUser, ByVal PostUpdate As Boolean) As Long
If PostUpdate Then
gLoginTimes.Add Time, User.Nick
End If
End Function
' When the user logs out, write the logout entry
Private Sub IChatServerCallBack_OnCloseUser(ByVal User As CHATSVCLib.IChatUser)
Dim fNum As Integer
Dim loggedIn As Variant
' look up when this user logged in
loggedIn = gLoginTimes(User.Nick)
#If SUPPORT_PPAGE Then
' only log if the property page has not disabled logging
If EnableLogging Then
#End If
' Write an entry to the logfile: <User's Nick> <Logged In> < Logged Out>
fNum = FreeFile
Open LOGFILE For Append As #fNum
Print #fNum, User.Nick, loggedIn, Time
Close #fNum
#If SUPPORT_PPAGE Then
End If
#End If
' and remove this users start time from the collection
gLoginTimes.Remove User.Nick
End Sub
' This callback method is called by the Chat snap-in MMC administration pages
' to facilitate an extension's property pages
Private Function IChatExtensionCallBack_OnGetPropertyPageClass(ByVal Class As CHATSVCLib.PROPERTY_PAGE) As String
#If SUPPORT_PPAGE Then
If Class = PPAGE_SERVER Then ' We only have a global (server) property page
' return the ProgID for an ActiveX Control that has our property pages attached
IChatExtensionCallBack_OnGetPropertyPageClass = "LogMonitorPP.DummyCtrl"
End If
#End If
End Function
' The following methods contain no implementation, and are required solely
' for VB to correctly implement the extensibility interfaces
Private Sub IChatExtensionCallBack_OnConfigureExtension(ByVal User As CHATSVCLib.IChatUser, ByVal Command As String)
End Sub
Private Function IChatExtensionCallBack_Term() As Long
End Function
Private Sub IChatExtensionCallBack_OnInstall()
End Sub
Private Sub IChatExtensionCallBack_OnUninstall()
End Sub
Private Sub IChatServerCallBack_OnCloseChannel(ByVal Channel As CHATSVCLib.IChatChannel)
End Sub
Private Function IChatServerCallBack_OnNewChannel(ByVal Channel As CHATSVCLib.IChatChannel, ByVal PostUpdate As Boolean) As Long
End Function
Private Sub IChatServerCallBack_OnRemoveAccess(ByVal Server As CHATSVCLib.IChatServer, ByVal AccessEntry As CHATSVCLib.IChatAccessEntry)
End Sub
Private Function IChatServerCallBack_OnAddAccess(ByVal Server As CHATSVCLib.IChatServer, ByVal AccessEntry As CHATSVCLib.IChatAccessEntry, ByVal PostUpdate As Boolean) As Long
End Function
© 1998 Microsoft Corporation. All rights reserved.