home *** CD-ROM | disk | FTP | other *** search
/ .net 2000 August / NET74.ISO / pc / Software / Flash / PC / flash4full.exe / data1.cab / Samples / Sample_Pages / Chat / dochat.asp < prev    next >
Encoding:
Text File  |  1999-06-15  |  1.5 KB  |  66 lines

  1. <% 
  2.  
  3. ' Encode a number from 0..15 to a single hex digit
  4. Function HexChar(ByVal i)
  5.     If i < 10 Then
  6.         HexChar = Chr(i+Asc("0"))
  7.     Else
  8.         HexChar = Chr(i-10+Asc("A"))
  9.     End If
  10. End Function
  11.  
  12. ' Encode the control and punctuation characters in a string to %xx hex values
  13. Function URLEncode(ByVal s)
  14.     Dim result, ch
  15.     Do While Len(s) > 0
  16.         ch = Asc(s)
  17.         s = Right(s, Len(s)-1)
  18.         If (ch >= Asc("a") And ch <= Asc("z")) Or (ch >= Asc("A") And ch <= Asc("Z")) Then
  19.             result = result & Chr(ch)
  20.         ElseIf ch = Asc(" ") Then
  21.             result = result & "+"
  22.         Else
  23.             'result = result & "*" & ch
  24.             'result = result & "!" & (ch/16) & (ch mod 16)
  25.             result = result & "%" & HexChar(Int(ch/16)) & HexChar(ch Mod 16)
  26.         End If
  27.     Loop
  28.     URLEncode = result
  29. End Function
  30.  
  31. ' Never cache the chat session
  32. Response.Expires = 0
  33.  
  34. ' Get the action to perform
  35. action = Request.QueryString("action")
  36.  
  37. ' Get the passed data
  38. msg = Request.form("msg")
  39. user = Request.form("user")
  40. id = Request.form("id")
  41. If Len(id) = 0 Then
  42.     id = "default"
  43. End If
  44.  
  45. ' Protect access to the chat session
  46. Application.Lock
  47. If action = "send" Then
  48.     ' Add the string to the chat session
  49.     list = Application(id)
  50.     list = list + user + ": " + msg + chr(13)
  51.     Application(id) = list
  52. ElseIf action = "clear" Then
  53.     ' Clear the chat session
  54.     list = ""
  55.     Application(id) = list
  56. Else 'If action = "update" Then
  57.     ' Just return the current chat session
  58.     list = Application(id)
  59. End If
  60. Application.Unlock
  61.  
  62. ' Return the chat session
  63. response.write("list="+URLEncode(list))
  64.  
  65. %>
  66.