1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef CLIENT_CHAT_MANAGER_H
23 #define CLIENT_CHAT_MANAGER_H
26 #include "nel/misc/types_nl.h"
29 //#include "game_share/chat_static_database.h"
30 #include "game_share/chat_group.h"
31 #include "game_share/dyn_chat.h"
43 //#define OLD_STRING_SYSTEM
47 * \author Stephane Coutelas
48 * \author Nevrax France
52 #ifdef OLD_STRING_SYSTEM
54 struct CDynamicStringInfos
59 /// index in the infos buffer, same as the index in the client dynamic string known buffer
62 /// true if the string has a Huffman code
65 /// true if we received the association
69 CDynamicStringInfos() : Associated(false), Index(0xffffffff), IsHuffman(true), Str("???") { }
76 * CChatDynamicDatabase
77 * \author Stephane Coutelas
78 * \author Nevrax France
81 #ifdef OLD_STRING_SYSTEM
83 class CChatDynamicDatabase
87 /// Add a string to dynamic base( used by client, add the string with its code )
88 /// \param index the index of the string
89 /// \param str the string
90 /// \param huffCode the Huffman code(may be empty)
91 /// \return the index of the string
92 uint32
add( uint32 index
, ucstring
& str
, std::vector
<bool>& huffCode
); // OLD
94 /// Get the string from its Huffman code
95 /// \param str will be filled with the string
96 /// \param bms contains the Huffman code
97 void decodeString( ucstring
& str
, NLMISC::CBitMemStream
& bms
); // OLD
99 /// Get infos on the dynamic string
100 CDynamicStringInfos
* getDynamicStringInfos( uint32 index
);
103 ~CChatDynamicDatabase();
107 /// Provides a Huffman tree to get huffman code of a string
111 std::map
< uint32
, CDynamicStringInfos
*> _Data
;
113 /// Map to find index from the string (only for uncoded strings)
114 std::map
< ucstring
, uint32
> _StringToIndex
; // OLD
123 // ***************************************************************************
126 * \author Stephane Coutelas
127 * \author Nevrax France
130 class CClientChatManager
137 * \param mode in which channel should this message goes
138 * \param dynChatId is valid only if mode==dyn_chat. This the Id of channel (not the index in DB!)
140 virtual void displayChat(TDataSetIndex compressedSenderIndex
, const std::string
&ucstr
, const std::string
&rawMessage
, CChatGroup::TGroupType mode
, NLMISC::CEntityId dynChatId
, std::string
&senderName
, uint bubbleTimer
=0) =0;
142 * display a player tell message
144 virtual void displayTell(/*TDataSetIndex senderIndex, */const std::string
&ucstr
, const std::string
&senderName
) =0;
147 * \param dynChatDbIndex is valid only if mode==dyn_chat. Contrary to displayChat, this is the Db Index (0..MaxDynChanPerPlayer)
149 virtual void clearChannel(CChatGroup::TGroupType mode
, uint32 dynChatDbIndex
) =0;
153 CClientChatManager();
155 * Init the manager. Init the static database
157 void init( const std::string
& staticDBFileName
);
159 // InGame init/release. call init after init of database
161 void releaseInGame();
164 * Return a reference on the static database
166 // CChatStaticDatabase& getStaticDB() { return _StaticDB; }
169 * Return a reference on the dynamic database
171 // #ifdef OLD_STRING_SYSTEM
172 // CChatDynamicDatabase& getDynamicDB() { return _DynamicDB; }
176 * Transmit a chat message to the last target group (see setChatMode)
177 * \param str is the chat content (truncated to 255 char max)
178 * \param isChatTeam special case for Chat TEAM
180 void chat( const std::string
& str
, bool isChatTeam
= false );
183 * Transmit a chat message to the receiver
184 * \param receiver is the name of the listening char (truncated to 255 char max)
185 * \param str is the chat content (truncated to 255 char max)
187 void tell( const std::string
& receiver
, const std::string
& str
);
189 /** Get the last name of the people with which a 'tell' has been done, then move that name at the start of the list
191 const std::string
*cycleLastTell();
193 /** Set the max number of name in the tell list
195 void setTellListSize(uint numPeople
);
199 * Add or remove a character from the ignore list
200 * \param filter is the filter id
202 void filter( uint8 filter
);
205 * Change the chat mode
206 * \param mode is the chat mode( say/shout/group/clade )
207 * \param dynChannelId the dynamic channel id (if group==dyn_chat).
208 * Not the db index! Use getDynamicChannelIdFromDbIndex() if you got a dbIndex
210 void setChatMode(CChatGroup::TGroupType group
, TChanID dynamicChannelId
=NLMISC::CEntityId::Unknown
);
212 /// Reset the chat mode to force the client to resend it. Used during far TP.
213 void resetChatMode();
216 * update chat mode button
218 void updateChatModeAndButton(uint mode
, uint32 dynamicChannelDbIndex
= 0);
221 * Get the string for a tell. display now if ready or delay in flushBuffer()
223 void processTellString(NLMISC::CBitMemStream
& bms
, IChatDisplayer
&chatDisplayer
);
226 * Get the string for a far tell. display now if ready or delay in flushBuffer()
228 void processFarTellString(NLMISC::CBitMemStream
& bms
, IChatDisplayer
&chatDisplayer
);
231 * Extract and decode the chat string from the stream. display now if ready or delay in flushBuffer()
233 void processChatString( NLMISC::CBitMemStream
& bms
, IChatDisplayer
&chatDisplayer
);
236 * Extract and decode the chat string from the stream. display now if ready or delay in flushBuffer()
237 * Difference with processTellString() is that processTellString2() receive a DynamicString for the message
239 void processTellString2(NLMISC::CBitMemStream
& bms
, IChatDisplayer
&chatDisplayer
);
242 * Extract and decode the chat string from the stream. display now if ready or delay in flushBuffer()
243 * Difference with processChatString() is that processChatString2() receive a DynamicString for the message
245 void processChatString2(NLMISC::CBitMemStream
& bms
, IChatDisplayer
&chatDisplayer
);
248 * Extract and decode the chat string from the stream.
249 * the stream here is only a iunt32 for the id of the dynamic string
250 * \param type where do you want this string to go (dyn_chat is not allowed)
252 void processChatStringWithNoSender( NLMISC::CBitMemStream
& bms
, CChatGroup::TGroupType type
, IChatDisplayer
&chatDisplayer
);
255 * Process any waiting string
257 void flushBuffer(IChatDisplayer
&chatDisplayer
);
260 * Extract and decode the chat string from a vector a uint64
261 * \param args vector of argument
262 * \param str string with parameter values at end
263 * \param result decoded string
264 * \return true if the string is finalize, false if some param are missing from network
266 bool getString( std::string
&result
, std::vector
<uint64
>& args
, const std::string
& strbase
);
268 // build a sentence to be displayed in the chat (e.g add "you say", "you shout", "[user name] says" or "[user name] shout")
269 static void buildChatSentence(TDataSetIndex compressedSenderIndex
, const std::string
&sender
, const std::string
&msg
, CChatGroup::TGroupType type
, std::string
&result
);
270 // build a sentence to be displayed in the tell
271 static void buildTellSentence(const std::string
&sender
, const std::string
&msg
, std::string
&result
);
274 /// \name Dynamic Chat channel mgt
276 // Use info from DB SERVER:DYN_CHAT. return 0 if fails
277 TChanID
getDynamicChannelIdFromDbIndex(uint32 dbIndex
);
278 // Use info from DB SERVER:DYN_CHAT. return -1 if fails
279 sint32
getDynamicChannelDbIndexFromId(TChanID channelId
);
280 // return true if channel exist (getDynamicChannelDbIndexFromId>=0 && <MaxDynChan)
281 bool isDynamicChannelExist(TChanID channelId
);
282 // get the name id from the db index
283 uint32
getDynamicChannelNameFromDbIndex(uint32 dbIndex
);
292 // CChatStaticDatabase _StaticDB;
295 // #ifdef OLD_STRING_SYSTEM
296 // CChatDynamicDatabase _DynamicDB;
299 // List of messages that wait for String to complete.
302 TDataSetIndex CompressedIndex
;
305 NLMISC::CEntityId DynChatChanID
;
306 // For Chat and Tell messages
307 ucstring Content
; // FIXME: UTF-8 (serial)
308 // For Chat2 and Tell2 messages
310 // Use PhraseId or Content?
312 // displayTell() or displayChat()
315 CChatMsgNode(const CChatMsg
&chatMsg
, bool displayAsTell
)
317 CompressedIndex
= chatMsg
.CompressedIndex
;
318 SenderNameId
= chatMsg
.SenderNameId
;
319 ChatMode
= chatMsg
.ChatMode
;
320 DynChatChanID
= chatMsg
.DynChatChanID
;
321 Content
= chatMsg
.Content
;
324 DisplayAsTell
= displayAsTell
;
327 CChatMsgNode(const CChatMsg2
&chatMsg
, bool displayAsTell
)
329 CompressedIndex
= chatMsg
.CompressedIndex
;
330 SenderNameId
= chatMsg
.SenderNameId
;
331 ChatMode
= chatMsg
.ChatMode
;
332 DynChatChanID
= NLMISC::CEntityId::Unknown
;
333 PhraseId
= chatMsg
.PhraseId
;
335 DisplayAsTell
= displayAsTell
;
338 std::list
<CChatMsgNode
> _ChatBuffer
;
341 std::list
<std::string
> _TellPeople
; // the last people on which tells ha been done
343 uint _MaxNumTellPeople
;
345 /// \name Dynamic Chat channel mgt
347 TChanID _ChatDynamicChannelId
;
348 NLMISC::CCDBNodeLeaf
*_DynamicChannelNameLeaf
[CChatGroup::MaxDynChanPerPlayer
];
349 NLMISC::CCDBNodeLeaf
*_DynamicChannelIdLeaf
[CChatGroup::MaxDynChanPerPlayer
];
350 // Id cached. If different from precedent, then the channel must be flushed
351 enum {DynamicChannelEmptyId
=-1};
352 uint32 _DynamicChannelIdCache
[CChatGroup::MaxDynChanPerPlayer
];
353 void updateDynamicChatChannels(IChatDisplayer
&chatDisplayer
);
359 * Extract and decode the chat string from the stream
360 * \param bms the bit mem stream
361 * \param str string with parameter values at end (str will change after)
362 * \return decoded string (str)
364 std::string
getString( NLMISC::CBitMemStream
& bms
, std::string
& str
);
368 /** This class enable you to store a static string + arg and evaluate it every frame.
369 All args could perhaps not be translated because all dynamic string are not received right now.
370 So you can call getString() every time to
372 #ifdef OLD_STRING_SYSTEM
375 ucstring StaticString
; // OLD
377 std::vector
<uint64
> Args
;
379 bool getString (ucstring
&result
, CClientChatManager
*mng
); // OLD
381 void setString (const ucstring
&staticStringId
, CClientChatManager
*mng
); // OLD
387 #endif // CLIENT_CHAT_MANAGER_H
389 /* End of client_chat_manager.h */