11#include <boost/lexical_cast.hpp>
27 +
" logged out.</span>";
29 return "<span class='chat-info'>"
37 result =
WString(
"<span class='")
47 return result +
"<span class='chat-highlight'>" + msg +
"</span>";
64 boost::recursive_mutex::scoped_lock lock(
mutex_);
69 clientInfo.
sessionId = WApplication::instance()->sessionId();
81 boost::recursive_mutex::scoped_lock lock(
mutex_);
88 boost::recursive_mutex::scoped_lock lock(
mutex_);
102 boost::recursive_mutex::scoped_lock lock(
mutex_);
104 UserSet::iterator i =
users_.find(user);
118 boost::recursive_mutex::scoped_lock lock(
mutex_);
120 UserSet::iterator i =
users_.find(user);
123 if (
users_.count(newUser) == 0) {
138 boost::recursive_mutex::scoped_lock lock(
mutex_);
140 for (
int i = 1;; ++i) {
141 std::string s =
"guest " + boost::lexical_cast<std::string>(i);
156 boost::recursive_mutex::scoped_lock lock(
mutex_);
172 if (app && app->
sessionId() == i->second.sessionId)
173 i->second.eventCallback(event);
176 boost::bind(i->second.eventCallback, event));
182 boost::recursive_mutex::scoped_lock lock(
mutex_);
boost::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.
boost::recursive_mutex mutex_
void sendMessage(const Wt::WString &user, const Wt::WString &message)
Send a message on behalve of a user.
Wt::WString suggestGuest()
Get a suggestion for a guest user name.
bool login(const Wt::WString &user)
Try to login with given user name.
std::string sessionId() const
WT_API void post(const std::string &sessionId, const boost::function< void()> &function, const boost::function< void()> &fallBackFunction=boost::function< void()>())
static WString fromUTF8(const std::string &value, bool checkValid=false)
std::string toUTF8() const
ChatEventCallback eventCallback