<%option explicit%>
<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock
dim cschat,my_level
set cschat=server.createobject("ffcschat.cssbchat")
my_level=cschat.getLevel(Session,Application(ConstStr & "_user_list"),Application(ConstStr & "_room_list"))
if my_level=0 then
  set cschat=nothing
  application.unlock
  response.end
end if
dim myname,room_id,add_exp_num,errText,conn,sql,rs,exp_num,saymess,says,current
myname=cschat.myname
room_id=cschat.room_id
my_level=cint(cschat.getListvalue(Application( ConstStr & "_user_list"),myname,3))

add_exp_num=datediff("n",cschat.getListvalue(Application( ConstStr & "_user_list"),myname,11),now())

if add_exp_num<5 then
  errText="【系统】您的经验值增长不足5点，不能存点！" 
else
  Set Conn=Server.CreateObject("ADODB.Connection")
  conn.open Application( ConstStr & "_connstr")
  sql="SELECT * FROM user WHERE username='" & myname & "'"
  set Rs=conn.Execute(sql)
  if not (Rs.eof or Rs.bof) then
    exp_num=Rs("exp_num")+add_exp_num
    if my_level-10<0 and Application( ConstStr & "_autoupgrade")=1 and rs("auto_update")=1 then
      if exp_num-Application( ConstStr & "_expupto"&( my_level+1 ))>0 then my_level=my_level+1
    end if
    if (Rs("user_level")-my_level)>0 then my_level=Rs("user_level")
    conn.Execute("UPDATE user SET user_level="&my_level&",exp_num="&exp_num&" WHERE username='"&myname&"'")
    conn.Execute("UPDATE room SET room_exp=room_exp+"&add_exp_num&",room_time='"&now()&"' WHERE ID="&room_id)
    Application( ConstStr & "_room_list")=cschat.SetListValue(Application( ConstStr & "_room_list"), room_id, 10, add_exp_num, 2, 7, now(), 0)
    Application( ConstStr & "_user_list")=cschat.SetListValue(Application( ConstStr & "_user_list"),myname,3,my_level,0,11,now(),0)
    errText="【存点】您的最新情况：级别("&my_level&")；经验增长("&add_exp_num&")；累积经验("&exp_num&")。努力哦！<\script>parent.roomlife="&cschat.getListvalue(Application( ConstStr & "_room_list"),room_id,10)&"</\script>"
  else
    Application( ConstStr & "_user_list")=cschat.DelList(Application( ConstStr & "_user_list"), myname)
    Application( ConstStr & "_room_list")=cschat.SetListValue(Application( ConstStr & "_room_list"), room_id, 12, myname, -1)
    
    say_mess=split(Application( ConstStr & "_userloseshow"),"::")
    say_mess(0)=say_mess(0) & "<\script>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 & "_says") = says
    Application(ConstStr & "_current") = current
  end if
  rs.close
  set rs=nothing
  conn.close
  set conn=nothing
end if
application.unlock
errText="-1,'"&errText&"','大家','"&myname&"',0,'996633','990099',-2,'"&cschat.gettimestr()&"'"
set cschat=nothing
%>
<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><SCRIPT language=JavaScript>parent.input.nosavetime=0;parent.addsay(<%=errText%>);</script>


