% Option Explicit %>
<%
' do not show login screen if a valid session exists
If (Session("chatname") <> "") Then
Response.Redirect "chat.html"
Response.End
End If
Dim mode, x, errorMessage
mode = Request("mode")
If ( (mode = "userLogin") ) Then
If ( Len(Request("username")) > 20 ) Then
errorMessage = "Seu apelido não deve ser maior do que 20 caracteres"
Else
If ( Len(Request("username")) < 1 ) Then
errorMessage = "Você deve digitar um apelido para entrar no chat"
Else
Dim requestedUsername
' Check if this user exist already
requestedUsername = Server.HTMLEncode( Request("username") )
If (Not FindUser(requestedUsername)) Then
' Session will timeout after X minutes, i.e. user will be logged out
' if there's not entered any text within X minutes.
Session.TimeOut = TIMEOUT
Session("chatname") = requestedUsername
' tell all other users about this new user
For x = MESSAGES To 2 Step -1
Application("chatline_" & x) = Application("chatline_" & x-1)
Next
Application("chatline_1") = " " & requestedUsername & " entrou na sala " & now & "
"
' push new username onto our users stack
For x = USERS To 2 Step -1
Application("onlineUser_" & x) = Application("onlineUser_" & x-1)
Next
Application("onlineUser_1") = Session("chatname")
Response.Redirect "chat.html"
Response.End
Else
errorMessage = "Sinto Muito, mas você não pode usar este apelido. Outro usuário entrou na sala com ele."
End If
End If
End If
End If
%>