Add infos into target window
[ryzomcore.git] / ryzom / server / src / general_utilities_service / gus_chat.h
blob988719a67c3a8f386580431548fea0d6a2cbcaa7
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef GUS_CHAT_H
18 #define GUS_CHAT_H
20 //-----------------------------------------------------------------------------
21 // includes
22 //-----------------------------------------------------------------------------
24 #include "nel/misc/displayer.h"
25 #include "gus_client_manager.h"
28 //-----------------------------------------------------------------------------
29 // GUS namespace
30 //-----------------------------------------------------------------------------
32 namespace GUS
34 //-----------------------------------------------------------------------------
35 // forward class declarations
36 //-----------------------------------------------------------------------------
38 class IChatCallback;
39 class CChatChannel;
42 //-----------------------------------------------------------------------------
43 // class IChatCallback
44 //-----------------------------------------------------------------------------
46 class IChatCallback
48 public:
49 /// a client is ready to receive message in this chat channel
50 virtual void clientReadyInChannel(CChatChannel *chatChannel, GUS::TClientId clientId) {}
52 // A player has typed some text in the chat in forward mode
53 // Overloaded only when the channel is open with 'forward player input'
54 // flag.
55 virtual void receiveMessage(GUS::TClientId clientId,const ucstring& txt) {}
57 // The chat channel ask if this player should be inserted in the channel.
58 // Only overloaded if the channel is open in non automatiuc player insertion.
60 virtual bool isClientAllowedInChatChannel(GUS::TClientId clientId, CChatChannel *chatChannel) {return true;}
64 //-----------------------------------------------------------------------------
65 // class CChatChannel
66 //-----------------------------------------------------------------------------
68 class CChatChannel: public NLMISC::CRefCount
70 public:
71 //-----------------------------------------------------------------------------
72 // Public interface
73 //-----------------------------------------------------------------------------
74 virtual ~CChatChannel() {}
76 // open the chat channel on all clients and set its name
77 // If historySize is set other than 0, the the chat channel is
78 // configured with the given lien of history.
80 virtual void openChannel(const NLMISC::CSString& channelTitle, uint32 historySize, bool noBroadcast, bool forwardInput, bool autoInsertPlayer)=0;
82 // close the chat channel previously opened on all clients
83 virtual void closeChannel()=0;
85 // add a client to the chat channel
86 virtual void addClient(GUS::TClientId clientId)=0;
88 // remove a client from the chat channel
89 virtual void removeClient(GUS::TClientId clientId)=0;
91 // send a text to the chat channel for all clients
92 virtual void broadcastMessage(const ucstring& speakerName, const ucstring& txt)=0;
94 // send a text to the chat channel for all clients (UTF-8 encoded)
95 virtual void broadcastMessage(const std::string& speakerNameUtf8, const std::string& txtUtf8)=0;
97 // send a text to the chat channel for the given client
98 virtual void sendMessage(GUS::TClientId clientId, const ucstring& speakerName, const ucstring& txt)=0;
100 // send a text to the chat channel for the given client (UTF-8 encoded)
101 virtual void sendMessage(GUS::TClientId clientId, const std::string& speakerNameUtf8, const std::string& txtUtf8)=0;
103 // setup a callback to be called whenever a player sends a text to this chat channel
104 virtual void setChatCallback(IChatCallback *callback)=0;
106 // get the channel name used with the IOS / EGS
107 virtual const NLMISC::CSString& getChannelName() const=0;
109 // get the channel title that was set in openChannel()
110 virtual const NLMISC::CSString& getChannelTitle() const=0;
112 // set the channel title and inform the IOS of the title
113 virtual void setChannelTitle(const NLMISC::CSString& title) =0;
115 typedef NLMISC::CSmartPtr<CChatChannel> TChatChannelPtr;
118 //-----------------------------------------------------------------------------
119 // class CChatManager
120 //-----------------------------------------------------------------------------
122 class CChatManager
124 public:
125 //-----------------------------------------------------------------------------
126 // Public interface
127 //-----------------------------------------------------------------------------
129 // get the singleton instance
130 static CChatManager* getInstance();
132 // Create a new named chat channel. Note, the channel is closed by default.
133 // - can return NULL if a channel with that name already exist.
134 virtual TChatChannelPtr createChatChannel(const NLMISC::CSString &channelName) =0;
136 // remove the given chat channel, closing it on all client screens
137 virtual void removeChannel(CChatChannel *channel) =0;
139 // Return a previously created chat channel or a NULL pointer.
140 virtual TChatChannelPtr getChatChannel(const NLMISC::CSString& channelName) =0;
142 // Set the title for a chat channel (and inform the IOS) - this operation returns
143 // false if a chat channel already exists with the given title
144 // the title is 'liberated' when the chat channel object is destroyed or its title changed
145 // note that setChatChannelTitle(NULL,title) simply tests whether a title is allocated
146 // to an existing chat channel - it is non-destructive and does not block future use of the title
147 virtual bool setChatChannelTitle(CChatChannel *channel,const NLMISC::CSString& channelTitle) =0;
151 //-----------------------------------------------------------------------------
152 // class CChatBroadcastDisplayer
153 //-----------------------------------------------------------------------------
154 // NLMISC::IDisplayer class for broadcasting to a gus chat channel
156 class CChatBroadcastDisplayer: public NLMISC::IDisplayer
158 public:
159 CChatBroadcastDisplayer(CChatChannel* channel);
160 void doDisplay(const NLMISC::CLog::TDisplayInfo& args,const char *message);
161 private:
162 TChatChannelPtr _Channel;
166 //-----------------------------------------------------------------------------
167 // class CChatDisplayer
168 //-----------------------------------------------------------------------------
169 // NLMISC::IDisplayer class for sending messages to a given user in a given gus chat channel
171 class CChatDisplayer: public NLMISC::IDisplayer
173 public:
174 CChatDisplayer(CChatChannel* channel,TClientId clientId);
175 void doDisplay(const NLMISC::CLog::TDisplayInfo& args,const char *message);
176 private:
177 TChatChannelPtr _Channel;
178 TClientId _ClientId;
184 //-----------------------------------------------------------------------------
185 #endif