<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">

'----------------------------------------------------------------------------------------
rem 数据库的连接字符 (可根据需要进行修改）
'ConnStr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password='';Initial Catalog=chinasdjy;Data Source=M"
'ConnStr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=blueyrr;Password='gannima123';Initial Catalog=hiseshipingjiaoyou;Data Source=(local)"

ConnStr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=blueyrr;Password=gannima123;Initial Catalog=hiseshipingjiaoyou;Data Source=(local)"

		 
Sub Application_onStart

	rem 取得系统保存的相关数据
	Set conn=Server.CreateObject("ADODB.CONNECTION")
	conn.open connstr
	set rs=conn.execute("SELECT * FROM system")'这里需要填加为空的判定处理吗？
	application("c_sysmaxonline")=rs("maxonline")
	application("c_sysmaxonlinetime")=rs("maxonlinetime")
	rs.close
	rem 读取各房间的信息(RS'ID',名称,描述,公告用$分隔）(0维未使用,）
	set rs=conn.execute("select * from room")
	dim roominfo()
	while not rs.eof
		j=j+1
	    redim preserve roominfo(j)
		roominfo(j)="$"+cstr(rs("id"))+"$"+rs("room_name")+"$"+rs("room_ref")+"$"+cstr(rs("max_user"))+"$"+rs("room_notice")+"$"+cstr(rs("notice_high"))
		Application("c_roommanager"+cstr(rs("id")))=rs("room_owner")
		rs.movenext()
	wend
	Application("c_roominfo")=roominfo
	rs.close
	set rs=conn.execute("select * from param")
	Application("c_clientset")="$"+rs("fall_time")+"$"+rs("leave_time")+"$"+rs("leave_answer")+"$"+rs("out_time")
	Application("c_managerset")="$"+rs("ip_lock")+"$"+rs("user_del")
	
	rem 总在线人数，会员在线预置为0
	Application("c_useronline")=0
	Application("c_usermember")=0

	rs.close
	conn.close
	set conn=nothing

	rem 标识本页已运行
	application("initialized")=true
End sub

Sub Application_onEnd

    rem 专业版或以后加强版本中，将在这里保存各房间在线记录

End sub

Sub Session_onStart

End sub

Sub Session_onEnd
   rem 如果是本系统使用的sess结束,做相应的处理
   if session("c_username")<>"" then
      application.lock
	  roomuserlist=application("c_roomuserlist"&session("c_userroomid"))
	  roomuserlist=replace(roomuserlist,"$"+session("c_userlistinfo"),"")
	  application("c_roomuserlist"&session("c_userroomid"))=roomuserlist
	  roomusernum=application("c_roomusernum"&session("c_userroomid"))
	  if roomusernum>0 then roomusernum=roomusernum-1
	  application("c_roomusernum"&session("c_userroomid"))=roomusernum
	  if cstr(right(session("c_userlistinfo"),5))="#true" then 
	     if Application("c_usermember")>0 then Application("c_usermember")=Application("c_usermember")-1
	  end if
	  rem 将原房间的talkinfo数组缩小,并将你的退出信息通知大家
		s_talkinfo=Application("c_roomtalkinfo"&cstr(session("c_userroomid")))
		if isarray(s_talkinfo) then
			if ubound(s_talkinfo)<=24 then'如果只有一个人在原来
				Application("c_roomtalkinfo"&session("c_userroomid"))=""
				application("c_roomusernum"&session("c_userroomid"))=0
				Application("c_roomLid"&session("c_userroomid"))=0
			else'如果原来有多人在,需要将你退出的信息告诉大家
				position=s_talkinfo(0)'标识当前指针在循环队列中的位置
				sumitem=ubound(s_talkinfo)'标识当前队列的上标
				s_lid=Application("c_roomLid"&session("c_userroomid"))+1
				thisnum=sumitem-24
				redim result(thisnum)
				j=0
				if position+3+24=sumitem then'直接去了后24项
				   for i=0 to thisnum
					   result(i)=s_talkinfo(i)
				   next
				elseif position+3+24>sumitem then
					for i=position+3-thisnum+1 to position+3
						j=j+1
						result(j)=s_talkinfo(i)
					next
				 else
					for i=position+24+4 to sumitem
					   j=j+1
					   result(j)=s_talkinfo(i)
					next
					for i=1 to position+3
						j=j+1
						result(j)=s_talkinfo(i)
					next
				end if
				result(0)=1
				result(1)=s_lid
				result(2)=session("c_username")
				result(3)="大家"
				result(4)="<F>"&session("c_username")&"</F><T>大家</T><E>0</E><sC>$F一声不吭地离开了聊天室！</sC><cL>#cc3366</cL><nC>#ff0000</nC>"
				Application("c_roomtalkinfo"&session("c_userroomid"))=result'获得最终的缩小的数组
				Application("c_roomLid"&session("c_userroomid"))=s_lid
			end if'if ubound(s_talkinfo)<=24的结束
		end if'if isarray的结束
        application("c_userinfo"+session("c_username"))=null
	application.unlock
   end if
End sub
</Script>
