⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 content.asp

📁 一个网站聊天室的模型
💻 ASP
📖 第 1 页 / 共 2 页
字号:
					end if
				end if
			end if
			'锁住本房间,只有房间创建者才可以给房间上锁
		case "/l"    
		'判断执行该命令的用户是否是该房间的创建者,如果是,才可以锁住这个房间;否则不能给该房间上锁
			newsql="select WhoCreate from RoomInfo where WhoCreate='" & UserID & "' and RoomName='" & session("myroom") & "'"
			set newrecordset=newconn.Execute (newsql)
			if newrecordset.bof then
				application(UserID)="您不是本房间的创建者,您无权给这个房间上锁!<br><br>" & application(UserID)
			else
				newsql="update RoomInfo set IfLocked=true where RoomName='" & session("myroom") & "'"
				newconn.Execute (newsql)

				application(UserID)="您已经给这个房间上锁了!<br><br>" & application(UserID)
			end if
			
		'打开房间,只有房间创建者才可以给房间解锁
		case "/u" 
				'判断执行该命令的用户是否是该房间的创建者,如果是,才可以给这个房间解锁,否则不能
			newsql="select WhoCreate from RoomInfo where WhoCreate='" & UserID & "' and RoomName='" & session("myroom") & "'"
			set newrecordset=newconn.Execute (newsql)
			if newrecordset.bof then
				application(UserID)="您不是本房间的创建者,您无权把这个房间解锁!<br><br>" & application(UserID)
			else
				newsql="update RoomInfo set IfLocked=false where RoomName='" & session("myroom") & "'"
				newconn.Execute (newsql)
				application(UserID)="您已经解开了这个房间的锁!<br><br>" & application(UserID)
			end if
			'清除聊天内容
		case "/c" 
			application(session("myname"))=""	
		'退出聊天室
		case "/b"    
%>
<script language="javascript">//声明这段代码的脚本语言是jscript
<!--
//转到byebye.asp页面
	top.location.href ="byebye.asp"
//-->
</script>
<%
'session对象的Abandon方法用来消除用户的Session对象并释放其所占用的资源
		session.Abandon 
		Response.End 
		
		'出现帮助系统内容
		case "/h"  
			
			info="/h---出现帮助提示<br>"
			info=info & "/j:roomname---加入新的房间<br>"
			info=info & "/r---查看当前房间信息<br>"
			info=info & "/w:roomname---查看当前用户信息<br>"
			info=info & "/l--锁住当前房间,只有创建者才能锁住<br>"
			info=info & "/b--退出聊天室<br>"
			info=info & "/u--解开某个房间<br>"
			info=info & "/t:newtopic--修改话题,只有创建者才能修改<br>"
			info=info & "/c--清除聊天内容<br>"
			'输出帮助信息
			application(UserID)= "<br>" & info & "<br>" & application(UserID)
			
		'更改聊天室话题,只有房间创建者才可以更改房间话题
		case "/t" 
			if right(left(command,3),1)<>":" then
				application(UserID)="<br>命令输入错误!需要有冒号“:”!<br><br>" & application(UserID)
			else
			'判断执行该命令的用户是否是该房间的创建者,如果是,才可以更改这个房间的话题,否则不能
				newsql="select WhoCreate from RoomInfo where WhoCreate='" & UserID & "' and RoomName='" & session("myroom") & "'"
				set newrecordset=newconn.Execute (newsql)
				if newrecordset.bof then
					application(UserID)="您不是本房间的室主,您无权修改这个房间的话题!<br><br>" & application(UserID)
				else
				'更新房间信息表的房间话题
					newsql="update RoomInfo set Topic='" & mid(command,4) & "' where RoomName='" & session("myroom") & "'"
					newconn.Execute (newsql)
					'通知本房间的所有聊天成员新修改的话题
					newsql="select OnLineUserID from UserOnLine where RoomName='" & session("myroom") & "'"
					'创建记录集对象
					set t_newrecordset=newconn.Execute (newsql)
						do while not t_newrecordset.eof
							application(t_newrecordset(0))="房间话题被修改为<font color=vbpurplea>" & mid(command,4) & "</font>!<br><br>" & application(t_newrecordset(0))
							t_newrecordset.movenext
						loop
						'关闭记录集对象
					t_newrecordset.close
					set t_newrecordset=nothing
						
				end if
			end if
			
		case else
			
			application(UserID)= "<br>没有这个命令,请用/h命令查看帮助<br>" &  application(UserID)
	end select
	
'如果T1提交信息的第一个字符不是"/",即表示T1提交的信息不是命令,而是聊天内容,就判断是对谁说的
'这个else是与if left(Request.Form ("T1"),1)="/" then语句相对应的
else
'如果聊天对象不是所有人,就从在线用户表中查找出聊天对象的昵称
if request.form("D1")<>"all" then
	yourid=Request.Form ("D1")
newsql="select nickname from useronline where onlineuserid='" & yourid & "'"
set newrecord=newconn.Execute (newsql)
if not newrecord.bof then
yournickname=newrecord("nickname")
end if
end if

'创建记录集对象
set myrecord=server.CreateObject ("ADODB.Recordset")
mysql="select * from UserOnLine where RoomName='" & myroom & "'"
myrecord.Open mysql,newconn,1,3
'如果是对大家说的
	if request.form("D1")="all" then
		tempstr="<font color='" & request.form("D2")  & "'>" & mynickname & Request.Form ("facing") & "对大家说:  " & request.form("T1") & "</font><font color=blue size=0.5>(" & time() & ")</font><br>"
		do while not myrecord.EOF 
		application(myrecord("OnLineUserId"))=tempstr & application(myrecord("OnLineUserId"))
		myrecord.MoveNext 
	loop	
'如果原始记录太多则删除部分
	if len(application(myroom))>1000 then
		length2=len(application(myroom))
		temppos=instrrev(application(myroom),"<br>",length2)-1
		application(myroom)=mid(application(myroom),1,temppos)
	end if
	
'如果是对某一个特定的聊天用户说的话,对应于if request.form("D1")="all" then语句
else
'向浏览器输出信息
	tempstr="<font color='" & request.form("D2")  & "'>" & mynickname & "只对" & yournickname & Request.Form ("facing")  & "说:" & request.form("T1") &"</font>" &"<font colovrr=blue size=0.5>(" & time() & ")</font><br>"
	application(yourid)=tempstr & application(yourid)
	application(myname)=tempstr & Application(myname)
end if'对应于if request.form("D1")="all" then语句

if len(application(myname))>20000 then
	length1=len(application(myname))
	temppos=instrrev(application(myname),"<br>",length1-4)-1
	application(myname)=mid(application(myname),1,temppos)
end if

'取消Lock方法的对Application对象的锁定,以便其他的用户能够访问
application.unlock

end if'与if left(Request.Form ("T1"),1)="/" then语句相对应
'输出信息,如果没有该语句将不会输出任何聊天信息
Response.Write application(UserID)

else'与if Request.ServerVariables ("REQUEST_METHOD")="POST" then语句相对应的
'输出信息
Response.Write application(UserID)

end if'与if Request.ServerVariables ("REQUEST_METHOD")="POST" then语句相对应的
'关闭数据源连接对象
newconn.Close 
set newconn=nothing
'changed变量记录已加入了新房间
if changed=true then			
%>
<script language="javascript">
<!--
//转到send.asp页面
parent.frames[1].location.href="send.asp"

//-->
</script>
<%
	end if
%>
<html>
<head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="refresh" content="10;url=content.asp?user=<% =UserID %>">
<!--定义每10秒刷新一次,并通过user向自身页面传递参数-->
<title>聊天内容</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<base target="ltop">
</head>
<body>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -