14 Wt::TextFormat
format)
const
18 return Wt::WString(
"<span class='chat-info'>")
19 + Wt::WWebWidget::escapeText(
user_) +
" joined.</span>";
21 return Wt::WString(
"<span class='chat-info'>")
24 Wt::WWebWidget::escapeText(
user_))
25 +
" logged out.</span>";
27 return "<span class='chat-info'>"
30 (Wt::WWebWidget::escapeText(
user_) +
" is"))
31 +
" now known as " + Wt::WWebWidget::escapeText(
data_) +
".</span>";
35 result = Wt::WString(
"<span class='")
39 +
"'>" + Wt::WWebWidget::escapeText(
user_) +
":</span>";
44 if (
message_.toUTF8().find(
user.toUTF8()) != std::string::npos)
45 return result +
"<span class='chat-highlight'>" +
msg +
"</span>";
62 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
79 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
86 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
100 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
102 UserSet::iterator
i =
users_.find(user);
116 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
118 UserSet::iterator
i =
users_.find(user);
136 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
138 for (
int i = 1;; ++
i) {
139 std::string
s =
"guest " + std::to_string(
i);
154 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
156 Wt::WApplication *
app = Wt::WApplication::instance();
170 if (
app &&
app->sessionId() ==
i->second.sessionId)
171 i->second.eventCallback(
event);
174 std::bind(
i->second.eventCallback,
event));
180 std::unique_lock<std::recursive_mutex>
lock(
mutex_);
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
std::function< void(const ChatEvent &)> ChatEventCallback
Encapsulate a chat event.
const Wt::WString formattedHTML(const Wt::WString &user, Wt::TextFormat format) const
Get the message formatted as HTML, rendered for the given user.
const Wt::WString & user() const
Get the user who caused the event.
bool changeName(const Wt::WString &user, const Wt::WString &newUser)
Changes the name.
bool disconnect(Client *client)
Disconnect from the chat server.
SimpleChatServer(Wt::WServer &server)
Create a new chat server.
UserSet users()
Get the users currently logged in.
void postChatEvent(const ChatEvent &event)
void logout(const Wt::WString &user)
Logout from the server.
std::set< Wt::WString > UserSet
Typedef for a collection of user names.
bool connect(Client *client, const ChatEventCallback &handleEvent)
Connects to the chat server.
void sendMessage(const Wt::WString &user, const Wt::WString &message)
Send a message on behalve of a user.
std::recursive_mutex mutex_
Wt::WString suggestGuest()
Get a suggestion for a guest user name.
bool login(const Wt::WString &user)
Try to login with given user name.