专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » qq聊天室私聊:聊天室实现私聊(一) »正文

qq聊天室私聊:聊天室实现私聊(一)

来源: 发布时间:星期四, 2009年2月12日 浏览:115次 评论:0


几个要好网友在聊天室里闲聊时侯总会遇上有些话题是不想同聊天室内别聊友看见那么聊天室支持悄悄话功能将是什分有必要实现悄悄话思路方法很多现在小虎介绍下利用session对象来实现它用session对象来实现悄悄话是有优缺点session对象应用其实就是客户端cookies使用如果客户端cookies不支持或关闭了那么运行起来就有问题了那么使用session对象就没好处了吗??非也至少在编程上大大减少了工作量嘛试想下如果需要保存该用户聊天名字那么使用session对象就能直接保存他名字了如果没有session对象解决思路方法看来就只有在处理发言FORM里设几个隐含textbox对象来保存这样处理起来会比教烦锁但好处是通用性广就算浏览器不支持cookies仍然可用

说到这里大伙不妨试试网上众多ASP聊天室试把浏览器安全选项(总是接受cookies关了)看看那个聊天室仍然正常地能使用那个就问题百出来呵呵~~不要找小虎聊天室来试哦....我聊天室也需要cookies来支持不用session对象编程真是烦锁很多而且大部分浏览器安全配置默认值是总是接受cookies所以也不用太但心只有少部分用户是比教特别

现在从聊天室发言开始到处理发言显示发言步地让大家了解下是如何处理最后就加上悄悄话功能

  首先我们聊天室主要提供如下元素:发言人(你名字)动作(叫嚷抱抱...等)对象(这句话是向谁说呢?)发言内容等 4大元素

  其中发言人(你聊天名字)名字是保存在发言FORMuser隐藏文本框中这样每当发言时侯在处理发言says.asp就可以用request.form("user")来取得聊天名字而动作则是由下拉框action来提供你可以自定义很多动作类型以满足区别聊友需要而发言对象也是由下拉框whoto来选定这些名单是列出当前聊天室内所有用户名称如何判断有新用户进聊天室以及退出处理这里先不说了构造个完整聊天室要做工作还是挺多最后由个says文本框提供发言内容

  有了这几个主要聊天元素我们就可以进行发言处理了

  请看看下面片段

 

\'取得说话内容,并过滤其中脚本语句
usersays=request.form("says")
instr(usersays,"<script")>0 then
usersays=""
end

\'判断是否有谈话内容没有话就不作处理

len(usersays)<>0 then
session("whoto")=request.form("whoto")
session("action")=request.form("action")
instr(usersays,chr(39))>0 then
usersays=replace(usersays,chr(39),"\\"&chr(39))
end
instr(usersays,chr(34))>0 then
usersays=replace(usersays,chr(34),"\\"&chr(34))
end

application.lock

\'定义个交谈缓冲区后面将给大家仔细分析

dim chats(20)
for n=1 to 20
chats(n)=application("chats")(n)
next
username=request.Form("user")


usertime=Time
usertime="("&right(usertime,8)&")"
user_whoto=request.Form("whoto")
user_action=request.Form("action")
application("counter")>19 then
application("counter")=0
end
\'不是耳语就加
request.form("action")<>"耳语" then
application("counter")=application("zj_1counter")+1
counter=application("zj_1counter")
\'用户动作处理

select request.FORM("action")
"说话"
request.FORM("whoto")="ALL" then
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> :<font color=#0000aa> "&usersays&"</font><BR><BR>"

chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>和<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
end
"叫嚷"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>冲<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>大叫</I>:<B><font color=#0000aa> "&usersays&"</font></B><BR><BR>"
"亲亲"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>亲了亲<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>脸颊</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"拥抱"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>轻轻抱着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font></I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"


"暴怒"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>朝<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>横眉竖目道</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"轻推"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>轻轻地推了推<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>胳膊</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"傻笑"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>傻兮兮朝<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>笑笑</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"拳打"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对准<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>就是拳</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"脚踢"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>凌空腿踢在<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>脑袋上</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"告戒"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>拉着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>手语气心长地说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"耳光"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>狠狠地掴了<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>几个耳光</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"鞠躬"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>毕恭毕敬地向<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>弯腰鞠躬</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"歉意"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>感到十 2分歉意低声对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"惊讶"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>惊讶对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>吐了吐舌头</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"哈欠"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>张大嘴巴打了个哈欠</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"微笑"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>微微笑</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"握手"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>紧紧握住<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>手</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"


"耸肩"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>耸耸双肩</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"安慰"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>拍拍<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>肩膀双眼关切说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"生气"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>气鼓鼓嘟嘴对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>道</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"大哭"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>忍不住对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>放声大哭</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"抽泣"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>双手捂着脸对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>呜呜咽咽</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"承诺"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>把胸脯拍得噼啪响</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"不舍"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>依依不舍地拉着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>衣角</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"深情"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>用深情眼神痴痴地看着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font></I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"迷惑"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>抓抓头皮看着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>露出迷惑神情</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"不解"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>用不可思意眼神看着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font></I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"幸灾"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>幸灾乐祸地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"大笑"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>捧腹大笑</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"皱眉"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>皱着眉头对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font></I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"


"委屈"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>很委屈地看着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>眼泪哗啦啦地往下流</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"高兴"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>兴高采烈地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"沮丧"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>满脸沮丧地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"失望"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>垂头丧气地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"神经"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>神经兮兮地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"神秘"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>非常神秘地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>说</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"撒娇"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>拉着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>手撒娇</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"鬼脸"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>做了个鬼脸</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
"无奈"
chats(counter)="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>对着<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>很无奈地</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
end select

\'是耳语


\'耳语处理
application("chat")="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>悄悄地对<font color=#00bb00>&nbsp;"&request.FORM("whoto")&" </font>耳语</I>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
\'对谁说
application("chatto")=request.FORM("whoto")
\'说话
application("owner")=username
session("chat")="true"
end


\'谈话全局化
application("chats")=chats


application.unlock


end

  上面是把用户发言和动作以及说话对象生成html语句并保存起来用以后面在聊天室中显示出来其中请大家注意下耳语是保存在application("chat")这个全局应用对象中好了下节先为大家详细分析下说话内容是如何处理

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: