7 #ifndef SIMPLECHATSERVER_H_
8 #define SIMPLECHATSERVER_H_
10 #include <Wt/WSignal.h>
11 #include <Wt/WString.h>
std::function< void(const ChatEvent &)> ChatEventCallback
Encapsulate a chat event.
const Wt::WString & user() const
Get the user who caused the event.
const Wt::WString & data() const
Get the extra data for this event.
const Wt::WString & message() const
Get the message of the event.
ChatEvent(Type type, const Wt::WString &user, const Wt::WString &data=Wt::WString::Empty)
ChatEvent(const Wt::WString &user, const Wt::WString &message)
const Wt::WString formattedHTML(const Wt::WString &user, Wt::TextFormat format) const
Get the message formatted as HTML, rendered for the given user.
Type type() const
Get the event type.
Type
Enumeration for the event type.
bool changeName(const Wt::WString &user, const Wt::WString &newUser)
Changes the name.
bool disconnect(Client *client)
Disconnect from the chat server.
SimpleChatServer(const SimpleChatServer &)=delete
std::map< Client *, ClientInfo > ClientMap
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.
SimpleChatServer & operator=(const SimpleChatServer &)=delete
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.
static const WString Empty
ChatEventCallback eventCallback