<%
'If1
If len(Request("UserName"))=0 or len(Request("CRNAME"))=0 then
Session("PPLCHATMESS")="请输入你在聊天室中使用的名字"
Response.Redirect("../chat.asp")
End If
'EIf1

Session("CRNAME")=Server.HtmlEncode(Request("CRNAME"))
Session("username")=Server.HtmlEncode(Request("UserName"))

'IF1
If IsEmpty(Application(SESSION("CRNAME")&"sentences")) then
dim sentences(60)
dim whotowho(60,2)
dim OUN(60) 'Online User Name
dim OULT(60) 'Online User Last Timer
OUN(1)=Session("username")
OULT(1)=Now
cur=1
sentences(cur)="<font color=#FF0000>欢迎光临风铃聊天室！希望您聊得开心！ Running at "&Now&"</font>"
whotowho(cur,1)="System"
whotowho(cur,2)="大家"

cur=cur+1
If cur>60 then cur=1
sentences(cur)="<font color=#FF0000>[公告]</font>"&Session("username")&"刚刚进入<u>"&Session("CRNAME")&"</u>……<font color=#B0B0B0>("&Now&")</font>"
whotowho(cur,1)="System"
whotowho(cur,2)="大家"
Application.Lock
Application(SESSION("CRNAME")&"sentences")=sentences
Application(SESSION("CRNAME")&"whotowho")=whotowho
Application(SESSION("CRNAME")&"OUN")=OUN
Application(SESSION("CRNAME")&"OULT")=OULT
Application(SESSION("CRNAME")&"cur")=cur
Application(SESSION("CRNAME")&"usernum")=1
Application.UnLock

else

OUN=Application(SESSION("CRNAME")&"OUN")
OULT=Application(SESSION("CRNAME")&"OULT")
for i=1 to 60
'IF2
If Session("username")=OUN(i) and abs(DateDiff("s",OULT(i),Now))<130 then
Session("PPLCHATMESS")="已经有人正在使用<font color=#0000FF>"&Session("username")&"</font>这个名字在本聊天室聊天，请换用其它名字登录。"
Response.Redirect("chat.asp")
End If
'EIF2
next
'检测人数是否超出最大限量（60）
'IF2
If Application(SESSION("CRNAME")&"usernum")>=59 then
Session("PPLCHATMESS")="对不起本聊天室已经满员，请进入其它聊天室。"
Response.Redirect("chat.asp")
End If
'EIF2

usernum=0 '在线人数

OUN=Application(SESSION("CRNAME")&"OUN")
OULT=Application(SESSION("CRNAME")&"OULT")
sentences=Application(SESSION("CRNAME")&"sentences")
cur=Application(SESSION("CRNAME")&"cur")
whotowho=Application(SESSION("CRNAME")&"whotowho")

for i=1 to 60
If len(OUN(i))>0 then usernum=usernum+1 '统计在线人数
next

'删除过期聊天用户
for i=usernum to 1 step -1
If abs(DateDiff("s",OULT(i),Now))>120 then
cur=cur+1
if cur>60 then cur=1

sentences(cur)="<font color=#FF0000>[公告]</font>"&OUN(i)&"刚刚离开<u>"&Session("CRNAME")&"</u>……<font color=#B0B0B0>("&OULT(i)&")</font>"
whotowho(cur,1)="System"
whotowho(cur,2)="大家"

for os=i to usernum-1
OUN(os)=OUN(os+1)
OULT(os)=OULT(os+1)
next
OUN(usernum)=EMPTY
OULT(usernum)=EMPTY
usernum=usernum-1
End If
next


End If
'EIF1


Application.Lock
Application(SESSION("CRNAME")&"sentences")=sentences
Application(SESSION("CRNAME")&"whotowho")=whotowho
Application(SESSION("CRNAME")&"usernum")=usernum
Application(SESSION("CRNAME")&"cur")=cur
Application(SESSION("CRNAME")&"OUN")=OUN
Application(SESSION("CRNAME")&"OULT")=OULT
Application.unLock

Response.Redirect("chat.asp")
%>
