<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart()'初始化聊天室
	'g_SiteName是站点的名称
	Const g_SiteName = "IceSoft"
	'g_SiteDomain是站点的域名
	Const g_SiteDomain = "IceSoft.com.cn"
	'g_BodyTag是<body>的属性
	Const g_BodyTag = "bgcolor=""#DEE5FA"" leftmargin=""10"" topmargin=""10"" marginleft=""0"" margintop=""0"""
	Dim g_DBString
	'g_DBString是连接数据库的字符串，请确保其无语法错误。
	'连接SQLServer写法：
	'g_DBString = "Provider=SQLOLEDB;Persist Security Info=False;UID=sa;PWD=;Initial Catalog=Chatroom;Data Source=127.0.0.1"
	'DSN写法：
	'g_DBString = "DSN=<数据库名>;UID=<DSN账号>;PWD=<密码>"
	'使用物理路径连接Access数据库写法：
	g_DBString = "DBQ=" & Server.MapPath("database/chatroom.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

	
	Dim g_ErrFile
	g_ErrFile = Server.MapPath("err.txt")
	
	Application("SiteName") = g_SiteName
	Application("SiteDomain") = g_SiteDomain
	Application("BodyTag") = g_BodyTag
	Application("DBString") = g_DBString
	Application("ErrFile") = g_ErrFile
	
	Dim oChat
	Set oChat = Server.CreateObject("LSChat.ChatRooms")
	oChat.Configure g_SiteName, g_SiteDomain, g_DBString, g_ErrFile, "global.asa"
	oChat.Initialize
	Set oChat = Nothing
End Sub

Sub Application_OnEnd()
	Dim oChat
	Set oChat = Server.CreateObject("LSChat.ChatRooms")
	oChat.Configure Application("SiteName"), Application("SiteDomain"), Application("DBString"), Application("ErrFile"), "global.asa"
	Call oChat.saveChatRooms(Application("ChatRoom"))
	Set oChat = Nothing
End Sub

Sub Session_OnStart()
	Session.TimeOut = 1
End Sub

Sub Session_OnEnd()
	Dim oChat
	Set oChat = Server.CreateObject("LSChat.Users")
	oChat.Configure Application("SiteName"), Application("SiteDomain"), Application("DBString"), Application("ErrFile"), "global.asa"

	Dim iGUID, sNickName
    Dim bUserExist
    Dim aUserList, aChatRoom
    iGUID = Session("GUID")
    iRoom = Session("Room")
    sNickName = Session("NickName")
    
    If iGUID <> Empty Then
		Application.Lock
			aUserList = Application("UserList")
			aChatRoom = Application("ChatRoom")
            aUserList(iRoom) = oChat.logoutUser(aUserList(iRoom), iGUID, bUserExist)'从UserList.XML中删除该用户节点
            aChatRoom(iRoom) = oChat.logoutRoom(aChatRoom(iRoom), sNickName, iGUID)'插入一条用户退出的记录
			Application("UserList") = aUserList
			Application("ChatRoom") = aChatRoom
		Application.UnLock
		'保存用户的聊天数据
        oChat.saveChatUser iGUID, Session("LastLogin"), Session("ChatWords"), Session("ChatMessages")
    End If
End Sub
</SCRIPT>