<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp" -->

<%
'================================
'当前版本号：4.0
'程序作者：可见度零（Garn Wraly）
'WCBBS 版权所有
'Http://BBs.W3Sea.Net
'================================



If Not IsObject(Conn) Then ConnectionDatabase
dim sql,rs,founderr,i,errmsg
Dim wcdb,rswc,connwc,SQLM
Dim player,score,sqlwc,game,per,addmoney,RSWCC,gameid,game2,score2,highscore,award1,award2,winmsg,connwcc,execc,execcc,usern,highname,gameurl,gamename
Dim istop,newtop,messagebox
Dim scriptstr,isplayed,scriptheadstr


founderr=false


wcdb="data/wc_high-score.mdb"

connwc="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(wcdb)
set rswc=Server.CreateObject("ADODB.recordset")
set rswcc=Server.CreateObject("ADODB.recordset")
set connwcc=server.createobject("adodb.connection")
connwcc.open connwc



Dim plustitle,backasp
plustitle = "休闲室"
backasp   = "wc_rec-room.asp"

function checklog
	If dvbbs.userid=0 Then
		Dvbbs.AddErrCode(6)
		Dvbbs.Showerr()
	End If
end function

select case request("act")
case "games"
	checklog
	call games()
case "script"
	call script
case "showhigh"
	call showhigh()

case "submitscore"
	checklog
	call submitscore()
case else
	checklog
	call main()
end select

sub script
isplayed=0
	usern=request.querystring("username")
		rswc.Source = "SELECT * FROM gamedb"
		rswc.ActiveConnection = connwc
		rswc.Open()
		scriptheadstr="<a href=""wc_rec-room.asp""><font style=""font-weight:bold; color: #000000; font-family: 黑体;"">休闲室游戏得分</font></a>"
			do until rswc.eof
				gameid=rswc("gameid")
				gamename=rswc("gamename")
				highname=rswc("highname")
				gameurl=rswc("gameurl")
				rswcc.Source = "SELECT top 1 score FROM scores WHERE player = '"&usern&"' and game='"&gameid&"'"
				rswcc.ActiveConnection = connwc
				rswcc.Open()
					if not rswcc.eof then
						isplayed=1
						score=rswcc("score")
						scriptstr=scriptstr+"<tr><td>&nbsp;<a href="""&gameurl&"""><font style=""color: #2266ee; font-family: 宋体;"">"&gamename&"</font></a></td><td>&nbsp;&nbsp;<font style=""color: #2266ee; font-family: 宋体;"">"&score&"</font> <br></td></tr>"
					end if
				rswcc.close
				rswc.movenext
			loop
		rswc.close
		
		if isplayed=1 then
			response.write("document.write('<div align=center><table width=160 border=0 cellpadding=0 cellspacing=0><tr><th colspan=2 align=center>"&scriptheadstr&"</th></tr>"&scriptstr&"</table></div>')")
		end if
end sub


sub submitscore()
		score=Request.Form("score")
		game=Request.Form("game")
		messagebox=messagebox+"score="&score
		
		sqlwc =  "INSERT INTO scores (game,player,score) VALUES ('"&game&"','"&dvbbs.membername&"','"&score&"')"
		connwcc.execute sqlwc
		
		rswc.Source = "SELECT * FROM gamedb where gameid='" & game &"'"
		rswc.ActiveConnection = connwc
		rswc.Open()
			highscore=rswc("highscore")
			award1=rswc("award1")
			award2=rswc("award2")
			messagebox=messagebox+"&award1="&award1
			messagebox=messagebox+"&award2="&award2
			per=rswc("percentt")
		rswc.close
		
		if (score-highscore)>0 then 
			istop =1
			if highscore<>0 then
			messagebox=messagebox+"&istop=1"
			messagebox=messagebox+"&newtop=0"
					if award1<>0 then
						conn.execute("update Dv_user set userwealth=userwealth+"&award1&" where username='"&dvbbs.membername&"'")
					end if
					
					if award2<>0 then
						conn.execute("update Dv_user set usercp=usercp+"&award2&" where username='"&dvbbs.membername&"'")
					end if
				sqlwc="UPDATE gamedb SET highscore="&score&",highname='"&dvbbs.membername&"' WHERE gameid='"&game&"'"
				connwcc.execute sqlwc
			else
				messagebox=messagebox+"&istop=1"
				messagebox=messagebox+"&newtop=1"
				sqlwc="UPDATE gamedb SET highscore="&score&",highname='"&dvbbs.membername&"' WHERE gameid='"&game&"'"
				connwcc.execute sqlwc
			end if
		else
			messagebox=messagebox+"&istop=0"
			messagebox=messagebox+"&newtop=0"
		end if
		
		connwcc.close
		set connwcc=nothing
		
		addmoney=clng( per * score \ 1000 )
		SQLM = "UPDATE [Dv_user] SET userWealth=userWealth+"&ADDmoney&" WHERE username='"&dvbbs.membername&"'"
		conn.execute(SQLM)
				messagebox=messagebox+"&ADDmoney="&ADDmoney
		
		response.write(messagebox)
end sub



sub main()
Dvbbs.Loadtemplates("")

Dvbbs.Stats="休闲室首页"
dvbbs.nav()
Dvbbs.head_var 0,0,plustitle,backasp

%>
<table cellpadding=3 cellspacing=1 align=center class=tableborder1>
	<tr>
		<th valign=middle colspan=2 align=center height=25>
		<div id="divTitle">
		<b>休闲室</b>
<%
If Dvbbs.master then
response.write("&nbsp;<a href=""wc_admin_rec-room.asp"">管理休闲室</a>")
end if
%>
		</div>
		</th>
	</tr>
	<tr>
		<td valign=middle class=tablebody1 height=100><CENTER>
		<div id="divinner" width=100% align=center>
			<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0">
			<tr>
				<td valign=middle class=tablebody1 colspan='3' height=100>
					<p align='center'><b>欢迎使用论坛休闲室~</p>
				</td>
			</tr>
				<tr>
					<td width="33%" align="center">
					<a href="?act=games&gametype=1&zhname=%C3%B0%CF%D5%C0%E0%D3%CE%CF%B7">
					<img border="0" src="pics/action.gif" width="200" height="200">
					</a>
					</td>

					<td width="33%" align="center">
					<a href="?act=games&gametype=2&zhname=%D2%E6%D6%C7%C0%E0%D3%CE%CF%B7">
					<img border="0" src="pics/puzzles.gif" width="200" height="200">
					</a>
					</td>
					<td width="33%" align="center">
					<a href="?act=games&gametype=3&zhname=%B6%C4%B2%A9%C0%E0%D3%CE%CF%B7">
					<img border="0" src="pics/luck_chance.gif" width="200" height="200">
					</a>
					</td>
				</tr>

			</table>
		</div>
		</td>
	</tr>
</table>
<%
Dvbbs.ActiveOnline()
Dvbbs.Footer()
end sub


sub games()
Dvbbs.Loadtemplates("")
Dim zhname,gametype,iiii
zhname=request.querystring("zhname")
gametype=request.querystring("gametype")

Dvbbs.Stats=zhname
dvbbs.nav()
Dvbbs.head_var 0,0,plustitle,backasp

RSWc.CursorLocation=3 
RSWc.CursorType=3 
RSWc.PageSize="12"

rswc.Source = "SELECT * FROM gamedb where type=" & gametype & " ORDER BY id"
rswc.ActiveConnection = connwc
rswc.Open()

dim eoff
eoff=0

if rswc.eof then 
eoff = 1
end if

if eoff=0 then 
if Request.QueryString("pg")="" then
rswc.AbsolutePage=1
else
rswc.AbsolutePage=cint(Request.QueryString("pg"))
end if
end if
%>
<table cellpadding=3 cellspacing=1 align=center class=tableborder1>
	<tr>
		<th valign=middle colspan=2 align=center height=25>
		<div id="divTitle">
		<b><%=zhname%>--</b><a onclick="getMain();" style="text-decoration: none; color: #000000" href="wc_rec-room.asp"><b>回到休闲室首页</b></a>
<%
If Dvbbs.master then
response.write("&nbsp;<a href=""wc_admin_rec-room.asp"">管理休闲室</a>")
end if
%>
		</div>
		</th>
	</tr>
	<tr>
		<td valign=middle class=tablebody1 height=100><CENTER>
<table id="table3" cellspacing="1" bordercolorlight="#000000" bordercolordark="#000000">
<tr>
<%
dim eof
eof=0

if rswc.eof then 
eof = 1
response.write ("<table width=200><tr><td align=center>本分类暂时没有游戏</td></tr></table>")
end if

if eof=0 then
do until rswc.eof or iiii=12
if iiii=4 or iiii=8 then response.write "</tr><tr>"
%>
<td align='center' width='180' height='140' valign=center>
	<table cellpadding=0 cellspacing=0 style='border: 1px #444444 dotted;' width=150 height=125>
		<tr>
			<th valign=middle align=center height=25 style='BORDER-BOTTOM: 1px #444444 solid;'><%=rswc("gamename")%>
			</th>
		</tr>
		<tr>
			<td class=tablebody1 height=100><a onclick="window.open('<%=rswc("gameurl")%>','myWin','toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=yes, width=600, height=480');return false;"  onMouseOver="getScore('<%=rswc("gamename")%>','<%=rswc("gameid")%>');" title="游戏得分×<%=rswc("percentt")%>‰ = 奖金"><img border='0' src='<%=rswc("gameimg")%>' width='150' height='100'></a>
			</td>
		</tr>
	</table>
</td>
<%
iiii = iiii+1
rswc.movenext
loop
end if%>
</tr>
</table> 
</td>
</tr>
	<tr>
		<td bgcolor=#ffffff>
<%
if eof=0 then
Dim allpages,pageon,curpage,nowpage,iii
if Request.QueryString("pg")<>"" then pageon=rswc.AbsolutePage
if Request.QueryString("pg")="" then pageon=1

curpage = Request.QueryString("pg")
if curpage<>"" then nowpage = curpage
if curpage="" then nowpage = 1

allpages = rswc.PageCount
Response.Write "<table><tr>"
Response.Write "<td width='100%' align='right' style=''><div>"
Response.write  ("<font color=#ffff00 style='color: #333300; font-size: 13px; font-family: Arial,Helvetica,sans-serif'>" & nowpage & "</font><font style='color: #333333; font-size: 13px; font-family: Arial,Helvetica,sans-serif'>" & "/" & allpages &"</font><font style='color: #666611; font-size: 9px; font-family: Arial,Helvetica,sans-serif'>&nbsp;Page:&nbsp;</font>")

for iii=1 to rswc.PageCount
Response.Write "<a href=wc_rec-room.asp?act=games&gametype="&gametype&"&zhname="&zhname&"&pg=" & iii & "><font color=#555555 style='font-family: 黑体; font-color: #333333 ; font-size: 13px'>[" & iii & "]</a></font>"
next
Response.Write "</div></td></tr></table>"
end if

rswc.Close()
%>

		</td>
	</tr>
</table>

		</td>
	</tr>
</table>

<table cellpadding=0 cellspacing=0 align=center class=tableborder1>
	<tr>
	<th valign=middle colspan=0 align=center height=25>
	<div id="divTitle2" align=center>高分榜
	</div>
	</td>
	</tr>
	<tr>
	<td valign=middle align=center bgcolor=#ffffff>
	<div id="divBottem" align=center>
	</div>
	</td>
	</tr>
</table>
<script>
function getScore(name,address){
	document.getElementById("divBottem").innerHTML="<iframe name=I1 src=./wc_rec-room.asp?act=showhigh&game="+address+" width=100%' style='' height='210' align='middle'>浏览器不支持嵌入式框架，或被配置为不显示嵌入式框架。</iframe>"
	document.getElementById("divTitle2").innerHTML="<b>"+name+"--高分榜</b>"
}
</script>
<%
Dvbbs.ActiveOnline()
Dvbbs.Footer()
end sub

sub showhigh

	DIM game2,number
	conn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + Server.MapPath("DATA/wc_high-score.mdb")
	set rs=Server.CreateObject("ADODB.recordset")
	game2=Request.QueryString("game")
	rs.source = "SELECT * FROM scores where game='" + game2 + "' ORDER BY score DESC"
	rs.ActiveConnection = conn
	rs.Open()
	%>
	<html>
	<head>
	</head>
	<body topmargin="0" leftmargin="0" rightmargin="0">
	<table cellpadding=0 cellspacing=0 border="0" width="100%" id="table1">
		<tr valign="top">
			<td width="50%" valign="top">
	<div align="center">
	<table cellpadding=0 cellspacing=0 width="100%" id="table2">
		<tr>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=15% height=25></th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=5% height=25>	 </th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=left width=42% height=25>
			<font color="#FFFFFF">名字</font></th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=5% height=25>	 </th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=33% height=25>
			<font color="#FFFFFF">分数</font></th>
		</tr>
	
	<%
	Number=1
	Do until number = 11 or rs.eof
	response.write("<tr style='font-family: 黑体; font-size:11pt'>")
	response.write("<td width=15% align=right>")
	response.write("<img border=0 src=pics/num/" & number &".gif width=14 height=14>")
	response.write("</td>")
	response.write("<td width=5% align=right>")
	response.write("&nbsp;&nbsp;&nbsp;")
	response.write("</td>")
	response.write("<td width=42% align=left>")
	response.write(rs.Fields.Item("player").value)
	response.write("</td>")
	response.write("<td width=5% align=center></td>")
	response.write("<td width=33% align=center>")
	response.write(rs.Fields.Item("score").value)
	response.write("</td>")
	response.write("</tr>")
	number = number + 1
	rs.MoveNext
	loop
	%>
		
	</table>
	
	</div>
	</td>
			<td width="50%" valign="top">
	<div align="center">
	<table cellpadding=0 cellspacing=0 width="100%" id="table3">
		<tr>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=15% height=25></th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=5% height=25>	 </th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=left width=42% height=25>
			<font color="#FFFFFF">名字</font></th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=5% height=25>	 </th>
			<th style='background-color: #4477ff;font-size: 12px;font-weight:bold;' valign=middle colspan=0 align=center width=33% height=25>
			<font color="#FFFFFF">分数</font></th>
		</tr>
	
	<%
	Number=11
	Do until number = 21 or rs.eof
	response.write("<tr style='font-family: 黑体; font-size:11pt'>")
	response.write("<td width=15% align=right>")
	response.write("<img border=0 src=pics/num/" & number &".gif width=14 height=14>")
	response.write("</td>")
	response.write("<td width=5% align=right>")
	response.write("&nbsp;&nbsp;&nbsp;")
	response.write("</td>")
	response.write("<td width=42% align=left>")
	response.write(rs.Fields.Item("player").value)
	response.write("</td>")
	response.write("<td width=5% align=center></td>")
	response.write("<td width=33% align=center>")
	response.write(rs.Fields.Item("score").value)
	response.write("</td>")
	response.write("</tr>")
	number = number + 1
	rs.MoveNext
	loop
	%>
	
	
	</table>
	</div>
	</td>
		</tr>
	</table>
	
	</body>
	</html>
	<%
	rs.Close()
	Set conn = Nothing

end sub
%>