SoFunction
Updated on 2025-04-13

Private chat in the chat room


I once made a relatively complex chat room that has almost all the functions of a BBS chat room, but because it is made with application, it is a waste of resources. I think using a database is more reliable and simpler.
Such a database chat can be set, with the structure as follows:

Field name, type, length, note
1..OBJECT CHAR 10 Operation object, ALL or someone
2..MSG CHAR 250 Message Content
3..TIME DATETIME Send time
4..SENDER CHAR 10 Sender
5.. ROOM CHAR 10 Room name, room where the sender is located

Normally OBJECT is ALL, and someone can be specified when you need to whisper.
When displaying the content, just say "Select * from chat where object='all' or object='" & session("userid") & "'. Session ("USER ID") is the identity authentication of the current user.
In this way, the chat content that every user sees is what they “should” see. If combined with other data tables, such as ROOM and USER, you can also complete functions such as stealth, kicking people, opening rooms, closing rooms, hiding rooms, etc. If you add an emoticon configuration file EMOTE. TXT can do expressions. Of course, doing this requires an explanation program when sending the message, which is used to determine what kind of command the user has entered and modify the data table accordingly.

roking:roking@ 

Let’s talk about the overall concept first: use application objects to save all chat public information, such as visitor ID, room status, public chat information, etc., and at the same time, use the Senssion object to save personal related information for everyone, such as: expressions, colors, conversation targets, etc.
The user's display area takes out public chat information from the application object and displays it with private chat for himself. . . .


nikl:nikl@ 

"Wrinkle" can be easily implemented with two built-in objects Application and Session. I hope it can be helpful!

When the user logs in, they create independent Application & Session objects for him. For example, there are three users, nikl hero viki, when they log in, use ASP's Request to obtain three user names and store a variable (such as name) and then initialize the Session and Application:
Session("Uname")=name 
Application(who)="" 
The whisper message exists in the variable says, and the person who is talking. For example:
nikl to viki: Have you eaten?
The server executes the code, and after the conditional judgment, the whisper is passed in. The content of the conversation "Have you eaten?" and the conversation object "VIKI" are assigned to the variables say and who; the information (have you eaten?) is passed into Application("viki") (code: Application(who)=say). The destination user side only needs to refresh the Application(Session"Uname") variable to see the information, and the program ends.
Please note:
<%=Application(Session("name"))%> on the VIKI side is actually <%=Application(VIKI))%>  (Session("Uname") has been defined as "VIKI" and exists in the browser when the information content box is refreshed) Therefore, when the Session("Uname") will be replaced by "VIKI", VIKI can see the whispering message sent by NIKL, while <%=Application(Session("Uname"))%> on the hero side is actually <%=Application(hero)%> This variable is empty, so hero cannot see the information sent by NIKL to VIKI. In this way, a whisper teleportation was cleverly completed.