<!-- #include file="setup.asp" -->
<%
top
if Request.Cookies("username")=empty then
response.redirect "login.asp"
end if

if instr(Request.Cookies("username")," ")>0 then:error("<li>非法操作"):end if

sql="select * from [user] where username='"&Request.Cookies("username")&"'"
rs.Open sql,Conn,1,3

if Request.Cookies("userpass")<>rs("userpass") then
error2("密码错误！")
end if
rs.close
username=Request.Cookies("username")
bwname=Request("bwname")

Set rs1 = Server.CreateObject("ADODB.Recordset")
rs.Open "select * from [mytools] where username='"&username&"' and use = 2",Conn,1,3
     if not rs.eof then
     mywuqi=rs("toolname")
     end if
rs1.Open "select * from [tools] where toolname='"&mywuqi&"' and exp <> 0",Conn,1,3
     if rs.eof then
     mygongji=0
     else
     mygongji=rs1("exp")
     end if
rs1.close
rs.close

rs.Open "select * from [mytools] where username='"&bwname&"' and use = 2",Conn,1,3
     if not rs.eof then
     bwwuqi=rs("toolname")
     end if
rs1.Open "select * from [tools] where toolname='"&bwwuqi&"' and exp <> 0",Conn,1,3
     if rs.eof then
     bwgongji=0
     else
     bwgongji=rs1("exp")
     end if
rs1.close
rs.close

rs.Open "select * from [mytools] where username='"&username&"' and use = 3",Conn,1,3
     if not rs.eof then
     myanqi=rs("toolname")
     end if
rs1.Open "select * from [tools] where toolname='"&myanqi&"' and exp <> 0",Conn,1,3
     if rs.eof then
     mygongjis=0
     else
     mygongjis=rs1("exp")
     end if
rs1.close
rs.close

rs.Open "select * from [mytools] where username='"&bwname&"' and use = 3",Conn,1,3
     if not rs.eof then
     bwanqi=rs("toolname")
     end if
rs1.Open "select * from [tools] where toolname='"&bwanqi&"' and exp <> 0",Conn,1,3
     if rs.eof then
     bwgongjis=0
     else
     bwgongjis=rs1("exp")
     end if
rs1.close
rs.close

rs.Open "select * from [mytools] where username='"&username&"' and use = 4",Conn,1,3
     if not rs.eof then
     myfangju=rs("toolname")
     end if
rs1.Open "select * from [tools] where toolname='"&myfangju&"' and magicpower <> 0",Conn,1,3
     if rs.eof then
     myfangyu=0
     else
     myfangyu=rs1("exp")
     end if
rs1.close
rs.close

rs.Open "select * from [mytools] where username='"&bwname&"' and use = 4",Conn,1,3
     if not rs.eof then
     bwfangju=rs("toolname")
     end if
rs1.Open "select * from [tools] where toolname='"&bwfangju&"' and magicpower <> 0",Conn,1,3
     if rs.eof then
     bwfangyu=0
     else
     bwfangyu=rs1("magicpower")
     end if
rs1.close
rs.close

rs.Open "select * from [leitai] where bwname='"&username&"'",Conn,1,3
rs1.Open "select * from [leitai] where bwname='"&bwname&"'",Conn,1,3
Set rs2 = Server.CreateObject("ADODB.Recordset")
if now-rs("bwnow")>=1 then rs("bwtime")=0
if now-rs1("bwnow")>=1 then rs1("bwtime")=0
if rs("bwbeizhan")=0 then error("<li>您尚未报名打擂<meta http-equiv=refresh content=3;url=leitai.asp>")
if rs1("bwbeizhan")=0 then error("<li>对方尚未报名打擂<meta http-equiv=refresh content=3;url=leitai.asp>")
if rs("bwtime")>9 then error("<li>您今天已经打了10次，明天再来挑战对方吧！<meta http-equiv=refresh content=3;url=leitai.asp>")
if rs1("bwtime")>9 then error("<li><font color=#0000FF>『"&bwname&"』</font>今天已经打了10次，明天在挑战<font color=#0000FF>『"&bwname&"』</font>吧！<meta http-equiv=refresh content=3;url=leitai.asp>")

Randomize
userindex=fix(rnd*100)+1+mygongji+mygongjis+myfangyu
bwindex=fix(rnd*100)+1+bwgongji+bwgongjis+bwfangyu

if userindex - bwindex >= 0 then
rs("bwtopic")=rs("bwtopic")+1
rs1("bwtopic")=rs1("bwtopic")+1
rs("zhstopic")=rs("zhstopic")+1
rs("bwtime")=rs("bwtime")+1
rs1("bwtime")=rs1("bwtime")+1
rs("bwbeizhan")=2
rs1("bwbeizhan")=2
rs("bwnow")=now()
rs1("bwnow")=now()
rs("bwjieguo")="<font color=#0000FF>『"&username&"』</font>挑战<font color=#0000FF>『"&bwname&"』</font> <font color=#FF0000>战胜</font>"
rs2.Open "select * from [user] where username='"&username&"'",Conn,1,3
rs2("magicpower")=rs2("magicpower")+10
rs2("money")=rs2("money")+500
rs2.update
rs2.close
rs2.Open "select * from [user] where username='"&bwname&"'",Conn,1,3
if rs2("magicpower")>9 then
rs2("magicpower")=rs2("magicpower")-10
else
rs2("magicpower")=0
end if
if rs2("money")>499 then
rs2("money")=rs2("money")-500
else
rs2("money")=0
end if
if rs2("userlife")>9 then
rs2("userlife")=rs2("userlife")-10
else
rs2("userlife")=0
end if
rs2.update
rs2.close
else
rs("bwtopic")=rs("bwtopic")+1
rs1("bwtopic")=rs1("bwtopic")+1
rs1("zhstopic")=rs1("zhstopic")+1
rs("bwbeizhan")=2
rs1("bwbeizhan")=2
rs("bwtime")=rs("bwtime")+1
rs1("bwtime")=rs1("bwtime")+1
rs("bwnow")=now()
rs1("bwnow")=now()
rs("bwjieguo")="<font color=#0000FF>『"&username&"』</font>挑战<font color=#0000FF>『"&bwname&"』</font> <font color=#00FF00>败北</font>"
rs2.Open "select * from [user] where username='"&bwname&"'",Conn,1,3
rs2("magicpower")=rs2("magicpower")+10
rs2("money")=rs2("money")+500
rs2.update
rs2.close
rs2.Open "select * from [user] where username='"&username&"'",Conn,1,3
if rs2("magicpower")>9 then
rs2("magicpower")=rs2("magicpower")-10
else
rs2("magicpower")=0
end if
if rs2("money")>499 then
rs2("money")=rs2("money")-500
else
rs2("money")=0
end if
if rs2("userlife")>9 then
rs2("userlife")=rs2("userlife")-10
else
rs2("userlife")=0
end if
rs2.update
rs2.close

end if
rs.update
rs1.update
rs.close
rs1.close
if userindex - bwindex >= 0 then
succeed("经过一番激烈战斗之后<font color=#0000FF>『"&username&"』</font>挑战<font color=#0000FF>『"&bwname&"』</font><font color=#FF0000>成功</font>!!<meta http-equiv=refresh content=3;url=leitai.asp>")
else
succeed("经过一番激烈战斗之后<font color=#0000FF>『"&username&"』</font>挑战<font color=#0000FF>『"&bwname&"』</font><font color=#FF0000>失败</font>!!<meta http-equiv=refresh content=3;url=leitai.asp>")
end if
%>
