1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
21 #include "string_manager_sender.h"
22 #include "nel/net/unified_network.h"
23 #include "nel/net/message.h"
24 #include "nel/net/service.h"
25 #include "nel/net/service.h"
26 #include "nel/misc/string_conversion.h"
27 #include "nel/misc/variable.h"
29 #include "synchronised_message.h"
32 using namespace NLMISC
;
34 NLMISC::CVariable
<bool> DebugPhraseSender("debug", "DebugPhraseSender", "Send debug phrase message to the IOS", false, 0, true);
36 namespace STRING_MANAGER
39 void TParam::serial(NLMISC::IStream
&f
)
41 serialParam(true, f
, invalid_value
);
44 bool TParam::serialParam(bool debug
, NLMISC::IStream
& f
,TParamType type
)
49 TParamType checkType
= NB_PARAM_TYPES
;
52 if (!f
.isReading() && type
!= invalid_value
)
54 nlassert(Type
== type
);
58 f
.serialEnum(checkType
);
60 if (f
.isReading() && type
!= invalid_value
)
62 if (type
!= checkType
)
64 nlwarning("Serializing a string TParam : need a '%s', receive a '%s' !",
65 paramTypeToString(type
).c_str(),
66 paramTypeToString(checkType
).c_str());
86 f
.serial(const_cast<NLMISC::CSheetId
&>(SheetId
));
94 f
.serial(const_cast<NLMISC::CEntityId
&>(EId
));
102 // identifier (string)
103 f
.serial(const_cast<std::string
&>(Identifier
));
119 case classification_type
:
122 f
.serial(const_cast<uint32
&>(Enum
));
126 f
.serial(const_cast<sint32
&>(Int
));
130 f
.serial(const_cast<uint32
&>(Time
));
133 f
.serial(const_cast<uint64
&>(Money
));
137 f
.serial(const_cast<uint32
&>(StringId
));
143 nlwarning("Invalid parameter type : can't be self");
146 nlwarning("Invalid parameter type : unknown (%d)", Type
);
152 static uint32 SequenceCounter
= 0;
154 uint32
pickStringSerialNumber()
156 SequenceCounter
= (SequenceCounter
+1) & 0xffffff ;
157 if (SequenceCounter
== 0)
160 uint32 stringSeq
= SequenceCounter
++;
162 stringSeq
= (NLNET::IService::getInstance()->getServiceId().get() << 24) | (stringSeq
& 0xffffff);
169 * Generic method used to send localised texts to clients ( whether they are ingame or in the character creation process )
170 * this method is inline and declared there so that it cannot be accessed from elsewhere.
171 * Use sendStringToClient or sendStringToUser
173 inline uint32
sendString(NLNET::CMessage
& msg
, const std::string
&stringName
, const std::vector
<TParam
> ¶ms
, ISender
*sender
)
175 uint32 stringSeq
= pickStringSerialNumber();
177 msg
.serial(stringSeq
);
178 msg
.serial(const_cast<std::string
&>(stringName
));
180 for (uint i
=0; i
<params
.size(); ++i
)
182 const TParam
¶m
= params
[i
];
183 if (!((TParam
&)param
).serialParam(DebugPhraseSender
, msg
, param
.Type
) )
189 // send the message through network.
190 // NLNET::CUnifiedNetwork::getInstance()->send("IOS", msg);
191 sendMessageViaMirror("IOS", msg
);
195 // send message with sender interface
196 sender
->send(msg
, DebugPhraseSender
);
202 //-----------------------------------------------
204 //-----------------------------------------------
205 void setPhrase(const std::string
&phraseName
, const ucstring
&phraseContent
)
207 NLNET::CMessage
msg("SET_PHRASE");
208 std::string mutablePhraseName
= phraseName
;
209 ucstring mutablePhraseContent
= phraseContent
;
210 msg
.serial(mutablePhraseName
);
211 msg
.serial(mutablePhraseContent
);
212 sendMessageViaMirror("IOS", msg
);
215 //-----------------------------------------------
216 // sendStringToClient
217 //-----------------------------------------------
218 uint32
sendStringToClient(const TDataSetRow
&clientRowId
, const std::string
&stringName
, const std::vector
<TParam
> ¶ms
, ISender
*sender
)
220 BOMB_IF(stringName
.empty(), "Trying to send a phrase to IOS with an empty phraseName", return 0;);
221 if (DebugPhraseSender
)
223 NLNET::CMessage
msg("PHRASE_DEBUG");
224 msg
.serial(const_cast<TDataSetRow
&>(clientRowId
));
225 return sendString( msg
,stringName
,params
,sender
);
229 NLNET::CMessage
msg("PHRASE");
230 msg
.serial(const_cast<TDataSetRow
&>(clientRowId
));
231 return sendString( msg
,stringName
,params
,sender
);
235 void sendSystemStringToClientAudience(const TDataSetRow
&clientRowId
, const std::vector
<NLMISC::CEntityId
> &excluded
, CChatGroup::TGroupType audience
, const char * stringName
, const std::vector
<TParam
> ¶ms
, ISender
*sender
)
237 BOMB_IF(strlen(stringName
) == 0, "Trying to send a phrase to IOS with an empty stringName", return;);
238 if (DebugPhraseSender
)
240 NLNET::CMessage
msg("BROADCAST_SYSTEM_PHRASE_DEBUG");
241 msg
.serial(const_cast<TDataSetRow
&>(clientRowId
));
242 msg
.serialCont(const_cast<vector
<CEntityId
> &>(excluded
));
243 msg
.serialEnum(audience
);
244 sendString( msg
,stringName
,params
,sender
);
248 NLNET::CMessage
msg("BROADCAST_SYSTEM_PHRASE");
249 msg
.serial(const_cast<TDataSetRow
&>(clientRowId
));
250 msg
.serialCont(const_cast<vector
<CEntityId
> &>(excluded
));
251 msg
.serialEnum(audience
);
252 sendString( msg
,stringName
,params
,sender
);
256 void sendCustomEmoteTextToClientAudience(const TDataSetRow
&clientRowId
, const std::vector
<NLMISC::CEntityId
> &excluded
, const char * stringName
, const std::vector
<STRING_MANAGER::TParam
> ¶ms
, ISender
*sender
)
258 BOMB_IF(strlen(stringName
) == 0, "Trying to send a custom emot phrase to IOS with an empty stringName", return;);
260 // send crowd emote message to IOS
261 NLNET::CMessage
msgout2("EMOTE_CROWD");
262 std::string
stringNameStr(stringName
);
263 msgout2
.serial( const_cast<TDataSetRow
&>(clientRowId
) );
264 msgout2
.serial(const_cast<string
&>(stringNameStr
));
266 uint32 size
= (uint32
)params
.size();
267 msgout2
.serial(size
);
268 for ( uint i
= 0; i
< size
; i
++ )
270 uint8 type8
= (uint8
)params
[i
].Type
;
271 msgout2
.serial(type8
);
272 const_cast<STRING_MANAGER::TParam
&>(params
[i
]).serialParam( false, msgout2
, params
[i
].Type
);
274 msgout2
.serialCont(const_cast<std::vector
<NLMISC::CEntityId
> &>(excluded
));
275 sendMessageViaMirror("IOS", msgout2
);
280 //-----------------------------------------------
282 //-----------------------------------------------
283 uint32
sendStringToUser(uint32 userId
, const std::string
&stringName
, const std::vector
<TParam
> ¶ms
, ISender
*sender
)
285 BOMB_IF(stringName
.empty(), "Trying to send a phrase to IOS with an empty phraseName", return 0;);
286 if (DebugPhraseSender
)
288 NLNET::CMessage
msg("PHRASE_USER_DEBUG");
290 return sendString( msg
,stringName
,params
,sender
);
294 NLNET::CMessage
msg("PHRASE_USER");
296 return sendString( msg
,stringName
,params
,sender
);
300 NL_BEGIN_STRING_CONVERSION_TABLE (TParamType
)
301 NL_STRING_CONVERSION_TABLE_ENTRY( item
)
302 NL_STRING_CONVERSION_TABLE_ENTRY( place
)
303 NL_STRING_CONVERSION_TABLE_ENTRY( creature
)
304 NL_STRING_CONVERSION_TABLE_ENTRY( skill
)
305 NL_STRING_CONVERSION_TABLE_ENTRY( role
)
306 // NL_STRING_CONVERSION_TABLE_ENTRY( career )
307 // NL_STRING_CONVERSION_TABLE_ENTRY( job )
308 NL_STRING_CONVERSION_TABLE_ENTRY( ecosystem
)
309 NL_STRING_CONVERSION_TABLE_ENTRY( race
)
310 NL_STRING_CONVERSION_TABLE_ENTRY( sbrick
)
311 NL_STRING_CONVERSION_TABLE_ENTRY( faction
)
312 NL_STRING_CONVERSION_TABLE_ENTRY( guild
)
313 NL_STRING_CONVERSION_TABLE_ENTRY( player
)
314 NL_STRING_CONVERSION_TABLE_ENTRY( bot
)
315 NL_STRING_CONVERSION_TABLE_ENTRY( integer
)
316 NL_STRING_CONVERSION_TABLE_ENTRY( time
)
317 NL_STRING_CONVERSION_TABLE_ENTRY( money
)
318 NL_STRING_CONVERSION_TABLE_ENTRY( compass
)
319 NL_STRING_CONVERSION_TABLE_ENTRY( string_id
)
320 NL_STRING_CONVERSION_TABLE_ENTRY( dyn_string_id
)
321 NL_STRING_CONVERSION_TABLE_ENTRY( self
)
322 NL_STRING_CONVERSION_TABLE_ENTRY( creature_model
)
323 NL_STRING_CONVERSION_TABLE_ENTRY( entity
)
324 NL_STRING_CONVERSION_TABLE_ENTRY( body_part
)
325 NL_STRING_CONVERSION_TABLE_ENTRY( score
)
326 NL_STRING_CONVERSION_TABLE_ENTRY( sphrase
)
327 NL_STRING_CONVERSION_TABLE_ENTRY( characteristic
)
328 NL_STRING_CONVERSION_TABLE_ENTRY( damage_type
)
329 NL_STRING_CONVERSION_TABLE_ENTRY( bot_name
)
330 NL_STRING_CONVERSION_TABLE_ENTRY( power_type
)
331 NL_STRING_CONVERSION_TABLE_ENTRY( literal
)
332 NL_STRING_CONVERSION_TABLE_ENTRY( title
)
333 NL_STRING_CONVERSION_TABLE_ENTRY( event_faction
)
334 NL_STRING_CONVERSION_TABLE_ENTRY( classification_type
)
335 NL_STRING_CONVERSION_TABLE_ENTRY( outpost
)
336 NL_STRING_CONVERSION_TABLE_ENTRY( clan
)
337 NL_END_STRING_CONVERSION_TABLE(TParamType
, ParamTypeConversion
, NB_PARAM_TYPES
)
339 //-----------------------------------------------
341 //-----------------------------------------------
342 TParamType
stringToParamType( const std::string
& str
)
344 return ParamTypeConversion
.fromString( str
);
347 //-----------------------------------------------
349 //-----------------------------------------------
350 const std::string
& paramTypeToString( TParamType type
)
352 return ParamTypeConversion
.toString( type
);
356 void TParam::setEId(const NLMISC::CEntityId
& eId
)
362 NLMISC::CEntityId
TParam::getEId() const
367 TAIAlias
TParam::getAIAlias() const
372 void TParam::setAIAlias(TAIAlias aiAlias
)
375 EId
= CEntityId::Unknown
;
378 void TParam::setEIdAIAlias(const NLMISC::CEntityId
& eId
, TAIAlias aiAlias
)