<script language=vbscript runat=server>
const ConstStr="ffchat"
sub Application_OnStart
 
 Connstr="DRIVER={Microsoft Access Driver (*.mdb)};DBQ="+server.mappath("db/global.asa")+";DefaultDir='';DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=15;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
 Application(ConstStr & "_connstr") = ConnStr
 set cschat=server.createobject("ffcschat.cssbchat")
 cschat.ConstStr=ConstStr
 cschat.InitGlobal(application)
 set cschat=nothing
end sub

Sub Session_OnStart
 Session("myname")=""
 Session("mytemp")=""
End Sub

Sub Session_OnEnd

  myname=trim(Session("myname"))
  if Session("Leave")="true" and myname="" then exit sub

  application.lock
  if instr(Application(ConstStr & "_user_list"),"<$"&myname&"$>")=0 then
   application.unlock
   exit sub
  end if

  user_array=split(Application(ConstStr & "_user_list"),"<$"&myname&"$>")
  user_array2=split(user_array(1),"$>")

  if trim(user_array2(0))<>trim(Session("mytemp")) then
   application.unlock
   exit sub
  end if
  set cschat=server.createobject("ffcschat.cssbchat")
  room_id=user_array2(4)
  if instr(Application(ConstStr & "_room_list"),"<$"&room_id&"$>")<>0 then Application( ConstStr & "_room_list")=cschat.SetListValue(Application( ConstStr & "_room_list"), room_id,12,myname,-1)

  application(ConstStr & "_user_list")=user_array(0)&user_array(2)

  say_mess=split(application(ConstStr & "_userloseshow"),"::")
  say_mess(0)=say_mess(0) & "<\script>parent.parent.dell(\'" & myname & "\')</\script>"

  says=application(ConstStr & "_says")
  current=application(ConstStr & "_current")
  cschat.newsay myname,"",0,room_id,say_mess(0),say_mess(1),say_mess(2),-2,says,current
  application(ConstStr & "_current")=current
  application(ConstStr & "_says")=says
  
  Set Conn=Server.CreateObject("ADODB.Connection")
  conn.open Application(ConstStr & "_connstr")
  conn.Execute("UPDATE user SET out_time='"&now()&"',out_info=1,room_id=0 WHERE username='"&myname&"'")
  conn.close
  set conn=nothing

  set cschat=nothing
  application.unlock
End Sub
</script>