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) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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 CHAT_MANAGER_H
23 #define CHAT_MANAGER_H
26 #include "chat_client.h"
29 #include "nel/misc/types_nl.h"
30 #include "nel/net/message.h"
31 #include "nel/misc/displayer.h"
34 #include "game_share/ryzom_entity_id.h"
35 //#include "game_share/chat_static_database.h"
36 //#include "game_share/chat_dynamic_database.h"
37 #include "game_share/base_types.h"
38 #include "game_share/string_manager_sender.h"
39 #include "game_share/dyn_chat.h"
51 * \author Stephane Coutelas
52 * \author Nevrax France
61 /// exception thrown when client is unknown
62 struct EChatClient
: public NLMISC::Exception
64 EChatClient( const NLMISC::CEntityId
& id
) : Exception ("Don't have chat infos for the char "+id
.toString()) {}
67 /// exception thrown when group is unknown
68 struct EChatGroup
: public NLMISC::Exception
70 EChatGroup( const TGroupId
& gId
) : Exception ("Can't find the group "+gId
.toString()) {}
74 * Init the manager. Init the static and dynamic databases
76 void init( /*const std::string& staticDBFileName, const std::string& dynDBFileName*/ );
78 /** A service has gone down
80 void onServiceDown(const std::string
&serviceShortName
);
83 * Reset ChatLog management
88 * Check if the client is already registered in the chat manager.
90 bool checkClient( const TDataSetRow
& id
);
92 * Add a client (add client to universe grp in the same time)
93 * \param id is the client character id
95 void addClient( const TDataSetRow
& id
);
99 * \param id is the client character id
101 void removeClient( const TDataSetRow
& id
);
104 * Get the client infos
105 * \param id is the client character id
107 CChatClient
& getClient( const TDataSetRow
& id
);
110 * Return a reference on the static database
112 // CChatStaticDatabase& getStaticDB() { return _StaticDB; }
115 * Return a reference on the dynamic database
117 // CChatDynamicDatabase& getDynamicDB() { return _DynDB; }
121 * \param gId is the group id
122 * \param gType is the type of the group
124 void addGroup( TGroupId gId
, CChatGroup::TGroupType gType
, const std::string
&groupName
);
127 * Remove a chat group
128 * \param gId is the group's id
130 void removeGroup( TGroupId gId
);
133 * Add a character to a chat group
134 * \param gId is the group's id
135 * \param charId is the character's id
137 void addToGroup( TGroupId gId
, const TDataSetRow
&charId
);
140 * Remove a character from a chat group
141 * \param gId is the group's id
142 * \param charId is the character's id
144 void removeFromGroup( TGroupId gId
, const TDataSetRow
&charId
);
148 * \param gId is the group's id
151 CChatGroup
& getGroup( const TGroupId
& gId
);
154 * Check if a message need be deeplized or not
155 * \param itCl is the client info
156 * \param ucstr is the chat content
157 * \param senderLang is lang code of sender
158 * \param langs is string to fill all langs where translated
159 * \param nbrReceivers is a integer to fill with number of players who will receive the message
161 void checkNeedDeeplize(const TDataSetRow
& sender
, const ucstring
& ucstr
, const std::string
& senderLang
, std::string
&langs
, uint
&nbrReceivers
, TGroupId grpId
= NLMISC::CEntityId::Unknown
);
164 * Transmit a chat message
165 * \param sender is the id of the talking char
166 * \param str is the chat content
168 void chat( const TDataSetRow
& sender
, const ucstring
& ucstr
, std::string rocketId
= "" );
171 * Transmit a chat message to a group
172 * \param gId is the group's id
173 * \param str is the chat content
174 * \param sender is the id of the talking char
175 * \param excluded is a container of player that must not receive this chat
177 void chatInGroup( TGroupId
& grpId
, const ucstring
& ucstr
, const TDataSetRow
& sender
, const std::vector
<TDataSetRow
> & excluded
= std::vector
<TDataSetRow
>());
180 * Transmit a far chat message to a group
182 void farChatInGroup(TGroupId
&grpId
, uint32 homeSessionId
, const ucstring
&text
, const ucstring
&senderName
);
185 * Transmit a chat message to the receiver
186 * \param sender is the id of the speaking char
187 * \param receiver is the id of the listening char
188 * \param str is the chat content
190 void tell( const TDataSetRow
& sender
, const std::string
& receiver
, const ucstring
& ucstr
);
192 * Transmit a chat message to the receiver
194 void farTell( const NLMISC::CEntityId
&senderCharId
, const ucstring
&senderName
, bool havePrivilege
, const ucstring
& receiver
, const ucstring
& ucstr
);
196 * Transmit a chat message to the receiver
197 * \param sender is the id of the speaking char
198 * \param receiver is the id of the listening char
199 * \param str is the identifier of a phrase to send to client
201 void tell2( const TDataSetRow
& sender
, const TDataSetRow
& receiver
, const std::string
& phraseId
);
204 * Transmit a chat message
205 * \param sender is the id of the talking char
206 * \param phraseId is the phrase name in phrase file
208 void chat2( const TDataSetRow
& sender
, const std::string
&phraseId
);
213 * Transmit a chat message
214 * \param sender is the id of the talking char
215 * \param phraseId is the phrase name in phrase file
216 * \param params is parameter of the phrase
219 void chatParam( const TDataSetRow
& sender
, const std::string
&phraseId
, const std::vector
<STRING_MANAGER::TParam
>& params
);
222 * Transmit a chat message
223 * \param sender is the id of the talking char
224 * \param phraseId is the phrase string Id ( as uint32)
225 * \param sendSender is true -> client will now the sender id
226 * \param ignored : targeted entities that must be ignored.
228 void chat2Ex( const TDataSetRow
& sender
, uint32 phraseId
);
231 * Transmit a chat message to a group
232 * \param gId is the group's id
233 * \param phraseId is the phrase name in phrase file
234 * \param sender is the id of the talking char
235 * \param excluded is a container of player that must not receive this chat
237 void chatInGroup2( TGroupId
& grpId
, const std::string
&phraseId
, const TDataSetRow
& sender
, const std::vector
<TDataSetRow
> & excluded
= std::vector
<TDataSetRow
>() );
238 // same as chatInGroup2 but use phrase with parameters
239 void chatParamInGroup( TGroupId
& grpId
, const std::string
&phraseId
, const std::vector
<STRING_MANAGER::TParam
> & params
, const TDataSetRow
& sender
, const std::vector
<TDataSetRow
> & excluded
= std::vector
<TDataSetRow
>() );
242 * Transmit a chat message to a group
243 * \param gId is the group's id
244 * \param phraseId is the phrase id (uint32)
245 * \param sender is the id of the talking char
246 * \param excluded is a container of player that must not receive this chat
248 void chatInGroup2Ex( TGroupId
& grpId
, uint32 phraseId
, const TDataSetRow
& sender
, const std::vector
<TDataSetRow
> & excluded
= std::vector
<TDataSetRow
>() );
251 * send an emote text to the target audience
252 * \param sender is the id of the talking char
253 * \param phraseId is the phrase id (string)
254 * \param params is the phrase params
255 * \param excluded is a container of player that must not receive this chat
257 void sendEmoteTextToAudience( const TDataSetRow
& sender
,const std::string
& phraseId
, const TVectorParamCheck
& params
, const std::vector
<TDataSetRow
> & excluded
);
260 * send an emote text to the target player
261 * \param target is the id of the target char
262 * \param phraseId is the phrase id (uint32)
264 void sendEmoteTextToPlayer( const TDataSetRow
& sender
, const TDataSetRow
& target
, uint32 phraseId
)
266 sendChat2Ex( CChatGroup::say
, target
, phraseId
, sender
);
270 * send an emote custom text to the target and target audience
271 * \param sender is the id of the talking char
272 * \param str is the custom phrase
274 void sendEmoteCustomTextToAll( const TDataSetRow
& sender
, const ucstring
& str
);
277 * Send a message to the client to add a new string in the dynamic database
278 * \param receiver is the id of the client's character
279 * \param index is the index of the string
280 * \param frontendId is the id of the frontend managing the receiver
282 // void addDynStr( const NLMISC::CEntityId& receiver, uint32 index, NLNET::TServiceId frontendId );
284 /// Display the list of clients
285 void displayChatClients(NLMISC::CLog
&log
);
287 /// Display the list of chat group with the registered players (do not list universe)
288 void displayChatGroups(NLMISC::CLog
&log
, bool displayUniverse
, bool displayPlayerAudience
);
290 // display the content of oine chat group
291 void displayChatGroup(NLMISC::CLog
&log
, TGroupId gid
, CChatGroup
&chatGroup
);
293 void displayChatAudience(NLMISC::CLog
&log
, const NLMISC::CEntityId
&eid
, bool updateAudience
);
295 /// add a user that ignores tells
296 void addUserIgnoringTells( const NLMISC::CEntityId
&eid
)
298 _UsersIgnoringTells
.insert( eid
);
301 /// remove a user that ignores tells
302 void removeUserIgnoringTells( const NLMISC::CEntityId
&eid
)
304 _UsersIgnoringTells
.erase( eid
);
308 void addMutedUser( const NLMISC::CEntityId
&eid
);
310 /// remove a muted user
311 void removeMutedUser( const NLMISC::CEntityId
&eid
);
313 // add a muted universe channel user
314 void addUniverseMutedUser( const NLMISC::CEntityId
&eid
);
316 // remove a muted universe channel user
317 void removeUniverseMutedUser( const NLMISC::CEntityId
&eid
);
320 CDynChat
&getDynChat() { return _DynChat
; }
322 // send historic of a dyn chat channel to the given player
323 void sendHistoric(const TDataSetRow
&receiver
, TChanID chanID
);
325 /// Filter text send from client for removing any color code
326 ucstring
filterClientInputColorCode(ucstring
&text
);
328 /// Filter text send from client for removing any forbiden or harming content
329 ucstring
filterClientInput(ucstring
&text
);
331 /// Subscribe special ring users in the ring universe chat
332 void subscribeCharacterInRingUniverse(const NLMISC::CEntityId
&charEId
);
333 /// Unsubscribe special ring users in the ring universe chat
334 void unsubscribeCharacterInRingUniverse(const NLMISC::CEntityId
&charEId
);
339 typedef std::map
< TDataSetRow
, CChatClient
*> TClientInfoCont
;
341 TClientInfoCont _Clients
;
344 std::map
< TGroupId
, CChatGroup
> _Groups
;
346 /// chat group name index.
347 std::map
<NLMISC::TStringId
, TGroupId
> _GroupNames
;
350 // CChatStaticDatabase _StaticDB;
353 // CChatDynamicDatabase _DynDB;
356 NLMISC::CFileDisplayer _Displayer
;
359 /// users ignoring tells
360 std::set
<NLMISC::CEntityId
> _UsersIgnoringTells
;
363 std::set
<NLMISC::CEntityId
> _MutedUsers
;
365 /// muted universe users
366 std::set
<NLMISC::CEntityId
> _MutedUniverseUsers
;
368 /// Temporary list of users (to avoid large amount of reallocs...)
369 std::list
<NLMISC::CEntityId
> _DestUsers
;
375 friend void cbSysChat( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
);
376 friend void cbNpcTell( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
);
377 friend void cbGhostTell( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
);
378 friend void cbNpcTellEx( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
);
379 friend void cbDynChatServiceChat( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
);
380 friend void cbDynChatServiceTell( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
);
384 * Send a chat message
385 * \param senderChatMode is the chat mode of the sender
386 * \param receiver is the id of the receiver
387 * \param str is the message content
388 * \param sender is the id of the sender
389 * \param chanID If the chat group is CChatGroup::dyn_chan, gives target channel .
390 * \param senderName Can be used to replace the sender name with a specific string
392 void sendChat( CChatGroup::TGroupType senderChatMode
, const TDataSetRow
&receiver
, const ucstring
& ucstr
, const TDataSetRow
&sender
= TDataSetRow(), TChanID chanID
= NLMISC::CEntityId::Unknown
, const ucstring
&senderName
= ucstring());
396 * Send a far chat message
398 void sendFarChat(const std::string
&name
, const ucstring
& ucstr
, const std::string
&chan
, const std::string
&rocketId
= "");
399 void sendFarChat( CChatGroup::TGroupType senderChatMode
, const TDataSetRow
&receiver
, const ucstring
& ucstr
, const ucstring
&senderName
, TChanID chanID
= NLMISC::CEntityId::Unknown
);
402 * Send a chat message
403 * \param senderChatMode is the chat mode of the sender
404 * \param receiver is the id of the receiver
405 * \param phraseId the string manager string number of the chat phrase
406 * \param sender is the id of the sender
408 void sendChat2( CChatGroup::TGroupType senderChatMode
, const TDataSetRow
&receiver
, const std::string
&phraseId
, const TDataSetRow
&sender
= TDataSetRow() );
409 // Same as sendChat2 but we can use phrase with parameters
410 void sendChatParam( CChatGroup::TGroupType senderChatMode
, const TDataSetRow
&receiver
, const std::string
&phraseId
, const std::vector
<STRING_MANAGER::TParam
>& params
, const TDataSetRow
&sender
= TDataSetRow() );
413 * Send a chat message, using the string manager. Allow parametered string to be sent
414 * \param senderChatMode is the chat mode of the sender
415 * \param receiver is the id of the receiver
416 * \param phraseId the string manager string number of the chat phrase
417 * \param sender is the id of the sender
418 * \param customTxt is a custom text which can be added immediately after the chat message, on the same line
420 void sendChat2Ex( CChatGroup::TGroupType senderChatMode
, const TDataSetRow
&receiver
, uint32 phraseId
, const TDataSetRow
&sender
= TDataSetRow(), ucstring customTxt
= ucstring(""));
423 * Send a custom emote chat message
424 * \param sender is the id of the sender
425 * \param receiver is the id of the receiver
426 * \param ucstr is the message content
428 void sendChatCustomEmote( const TDataSetRow
&sender
, const TDataSetRow
&receiver
, const ucstring
& ucstr
);
432 TChanID
getChanId(const std::string name
);
436 #endif // CHAT_MANAGER_H
438 /* End of chat_manager.h */