首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 代码乐园 >
    7i24 .Com  
  一个只有一个文件,功能强大的聊天室

7i24.Com不停为您服务
一个只有一个文件,功能强大的聊天室

<%@ Language=VBScript codepage=936%>
<%option explicit%>
<%
const CMAXLINE = 100
const CMAXUSER = 10
const CMAXROOM = 5
''tp = main,getchat,snddata,content,input
''ucd =
''line=
''on error resume next

dim vtp, vucd, vline, vroom
dim vcount, vcount2, i, v
vtp = Request.QueryString("tp")
vucd = Request.QueryString("ucd")
vline = Request.QueryString("line")
vroom = Request.QueryString("room")
if vtp = "" then vtp = "roomlist"
if vucd = "" then vucd = "guest"
if vline = "" then vline = 0 else vline = cint(vline)
if vroom = "" then vroom = 1
%>

<%
'' Initial chat data
'' roomsize - chat room size

'' chatroom* - chat room list room
'' chatroomchatsize* - chatsize room
'' chatroomusersize* - usersize room

'' chatuser** - chat user list room_user
'' chatusertime** - user active lasttime room_user

'' chatdata** - chat data room_line
'' chatdatauser** - chat user room_line
'' chatdatatouser** - chat to user room_line
'' chatdatatype** - chat data type room_line

if Application.Contents("roomsize") = "" then
''Application.Lock
Application.Contents("roomsize") = CMAXROOM
for i = 1 to CMAXROOM
Application.Contents("chatroom_" & i) = "room" & i
Application.Contents("chatroomchatsize_" & i) = 0
Application.Contents("chatroomusersize_" & i) = 0
next
''Application.UnLock
end if

%>

<HTML>
<%Response.Expires = 0%>
<%if vtp = "roomlist" then%>
<%Response.Write Application.Contents("roomsize")%>
<TABLE cellpadding=0 cellspacing=0 border=1 center>
<TR>
<TD>Chat Room</TD>
<TD>lines</TD>
<TD>users</TD>
</TR>
<%
for i = 1 to cint(Application.Contents("roomsize"))
Response.Write "<TR>" & vbCrlf
Response.Write "<TD>" & _
"<A HREF=chat.asp?tp=login&ucd=guest&room=" & i & ">" & _
Application.Contents("chatroom_" & i) & "</A></TD>" & vbCrlf
Response.Write "<TD>" & Application.Contents("chatroomchatsize_" & i)
& "</TD>" & vbCrlf
Response.Write "<TD>" & Application.Contents("chatroomusersize_" & i)
& "</TD>" & vbCrlf
Response.Write "</TR>" & vbCrlf
next
%>
</TABLE>
<%elseif vtp = "login" then%>
<CENTER>
<H1>Chat in <%=Application.Contents("chatroom_" & vroom)%></H1>
<FORM action="chat.asp">
<INPUT type=hidden id=tp name=tp value=main>
<INPUT type=hidden id=room name=room value=<%=vroom%>>
<INPUT type=text size=20 maxlength=20 id=ucd name=ucd>
<INPUT type=submit value=LogIn>
</FORM>
<CENTER>
<%elseif vtp = "main" then%>
<%
'' Add User to user list
if Application.Contents("chatuser_" & vroom & "_" & vucd) = "" then
''Application.Lock
Application.Contents("chatuser_" & vroom & "_" & vucd) = vucd
Application.Contents("chatusertime_" & vroom & "_" & vucd) = Now
Application.Contents("chatroomusersize_" & vroom) = _
Application.Contents("chatroomusersize_" & vroom) + 1
vcount = cint(Application.Contents("chatroomchatsize_" & vroom)) + 1
Application.Contents("chatroomchatsize_" & vroom) = vcount
Application.Contents("chatdata_" & vroom & "_" & vcount) = "<FONT
color=red>" & vucd & "</FONT> come in room at " & now()
Application.Contents("chatdatauser_" & vroom & "_" & vcount) = vucd
''Application.UnLock
end if
%>
<HEAD>
<TITLE><%=Application.Contents("chatroom_" & vroom)%></TITLE>
</HEAD>
<SCRIPT id=mainjs language=javascript>
var vline, vucd, vroom;
vline = 0;
vucd = ''<%=vucd%>'';
vroom = <%=vroom%>;
function AddChatData(vData){
content.chatdata.innerHTML = vData + content.chatdata.innerHTML;
}
function setLine(tline){
vline = tline;
}
function pp() {
//this.getchat.location = ''chat.asp?tp=getchat&room=<%=vroom%>&ucd=<%
=vucd%>&line='' + vline;
}
function setPageCome(p) {
pagecome = p;
}
var ti;
var timeout;
var pagecome;
timeout = 0;
pagecome = 0;
function rrr(){
var today = new Date();
clearTimeout(ti);
window.status = "welcome to sodick chat room";
timeout = timeout + 100;
if (timeout > 1000 || pagecome==1) {
timeout = 0;
pagecome = 0;
this.getchat.location = ''chat.asp?tp=getchat&room=<%=vroom%>&ucd=<%
=vucd%>&line='' + vline +"&nowt=" + today.getTime(); ;
}
window.status = "welcome to sodick chat room";
ti = setTimeout(''rrr();'', 1000);
}
ti = setTimeout(''rrr();'', 1000);
//window.location.reload();
</SCRIPT>
<FRAMESET cols="80%,*" name=chatroom>
<FRAMESET rows="100,60%,*,0,0">
<FRAME name=ad src="http://webdev/eMake/advert/adver.asp" scroll=no>
<FRAME name=content src="chat.asp?tp=content&room=<%=vroom%>&ucd=<%
=vucd%>">
<FRAME name=input src="chat.asp?tp=input&room=<%=vroom%>&ucd=<%=vucd%
>">
<FRAME name=getchat src="chat.asp?tp=getchat&room=<%=vroom%>&ucd=<%
=vucd%>">
<FRAME name=sndchat src="chat.asp?tp=sndchat&room=<%=vroom%>&ucd=<%
=vucd%>">
</FRAMESET>
<FRAME src="chat.asp?tp=userlist&room=<%=vroom%>">
</FRAMESET>
<%elseif vtp = "getchat" then%>
<%
'' Support multiple character sets.
''Session.Codepage = 65001
''Response.Charset = "UTF-8"

Response.CacheControl = "no-cache"

''HTTP/1.0 Compatibility
Response.AddHeader "Pragma", "no-cache"
Response.Expires = 0

%>
<SCRIPT>

function window_onload() {
<%
vCount = cint(Application.Contents("chatroomchatsize_" & vroom))
for i = vLine + 1 to vCount
v = "<FONT color=blue>" & Application.Contents("chatdatauser_" &
vroom & "_" & i) & "</FONT>" & _
":> " & Application.Contents("chatdata_" & vroom & "_" & i) & "<BR>"
Response.Write "this.top.AddChatData(""" & v & """);" & vbCrlf
next
Response.Write "this.top.setLine(" & vCount & ");" & vbCrlf
Response.Write "this.top.setPageCome(1);" & vbCrlf
%>
}
</SCRIPT>
<BODY language=javascript onload="return window_onload();">
<%Response.Write "Now:" & Hour(now()) & ":" & minute(now()) & ":" &
Second(now())%>
</BODY>
<%elseif vtp = "sndchat" then%>
<%
if Request.QueryString("chattext") <> "" then
vcount = cint(Application.Contents("chatroomchatsize_" & vroom)) + 1
''Application.Lock
Application.Contents("chatroomchatsize_" & vroom) = vcount
Application.Contents("chatdata_" & vroom & "_" & vcount) = _
Hour(now()) & ":" & minute(now()) & ":" & Second(now()) & " " &
Request.QueryString("chattext")
Application.Contents("chatdatauser_" & vroom & "_" & vcount) = vucd
''Application.UnLock
end if
%>
<%elseif vtp = "content" then%>
<%
''Response.AddHeader "REFRESH", "5"
''Response.Write Application.Contents("chatroomchatsize_" & vroom)
''for i = cint(Application.Contents("chatroomchatsize_" & vroom)) to
1 step -1
'' Response.Write Application.Contents("chatdatauser_" & vroom & "_"
& i) & ":"
'' Response.Write Application.Contents("chatdata_" & vroom & "_" & i)
& "<BR>" & vbCrlf
''next
%>
<SPAN id=chatdata>
</SPAN>
<%elseif vtp = "input" then%>
<FORM action="chat.asp" target=sndchat>
<INPUT type=hidden id=tp name=tp value=sndchat>
<INPUT type=hidden id=room name=room value=<%=vroom%>>
<INPUT type=hidden id=ucd name=ucd value=<%=vucd%>>
<INPUT type=text id=chattext name=chattext size=50 maxlength=200>
<INPUT type=submit id=send name=send value="send">
</FORM>
<%elseif vtp="userlist" then%>

<TABLE>
<%
''Response.Write Application.Contents("chatroomusersize_" & vroom)
for each v in Application.Contents
if left(v,10) = "chatuser_" & vroom then
Response.Write "<TR>" & vbCrlf
Response.Write "<TD>" & Application.Contents(v) & "</TD>" & vbCrlf
Response.Write "</TR>" & vbCrlf
end if
next
''for i = 1 to cint(Application.Contents("chatroomusersize_" & vroom))
'' Response.Write "<TR>" & vbCrlf
'' Response.Write "<TD>" & Application.Contents("chatuser_" & vroom
& "_" & i) & "</TD>" & vbCrlf
'' Response.Write "</TR>" & vbCrlf
''next
%>
</TABLE>

<%elseif vtp="outputdata" then%>
<%Response.Write Application.Contents("roomsize")%>
<%
for each v in Application.Contents
Response.Write v & " " & Application.Contents(v) & "<BR>" & vbCrlf
next
%>
<%elseif vtp="reset" then%>
<%
Application.Contents("roomsize") = ""
for each v in Application.Contents
if left(v, 4) = "chat" then
Application.Contents(v) = ""
end if
next
Response.Write "Clear Ok."
%>
<%else%>
<%="I don''t know"%>
<%end if%>
</HTML>



  2002年1月9日  阅读 1655 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:
§实现聊天室的悄悄话功能(上)
§实现聊天室的悄悄话功能(中)
§实现聊天室的悄悄话功能(下)
§也谈在asp聊天室程序中实现悄悄话功能

上一篇: 开心ICQ的一些原理
下一篇: 实现聊天室的悄悄话功能(上)
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利