Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / input_output_service / messages.cpp
blobe7ddf8e85ebffae85ea8a3fb29e39e01c0066e09
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/>.
18 #include "stdpch.h"
19 #include "messages.h"
21 #include <nel/misc/entity_id.h>
22 #include <nel/net/unified_network.h>
24 #include "game_share/ryzom_mirror_properties.h"
26 #include "input_output_service.h"
27 /*#include "game_share/tick_event_handler.h"
28 #include "game_share/msg_client_server.h"
29 #include "game_share/mode_and_behaviour.h" //TEMP!!!
30 #include "game_share/news_types.h"
31 #include "game_share/bot_chat_types.h"
32 #include "game_share/brick_types.h"
33 #include "game_share/loot_harvest_state.h"*/
34 #include "game_share/generic_xml_msg_mngr.h"
36 /*#include <nel/misc/command.h>*/
38 using namespace std;
39 using namespace NLMISC;
40 using namespace NLNET;
43 extern CGenericXmlMsgHeaderManager GenericXmlMsgHeaderMngr;
45 extern CVariable<bool> VerboseChatManagement;
47 typedef NLMISC::CTwinMap<TChanID, string> TChanTwinMap;
48 extern TChanTwinMap _ChanNames;
51 //-----------------------------------------------
52 // cbImpulsionReadyString :
54 //-----------------------------------------------
57 void cbImpulsionReadyString( CMessage& msgin, const string &serviceName, TServiceId serviceId )
59 nlwarning("cbImpulsionReadyString : deprecated");
60 // Read sender and bitmemstream
61 CEntityId sender;
62 uint8 nbBitsToSkip;
63 CBitMemStream bms(true);
64 msgin.serial(sender);
65 msgin.serial(nbBitsToSkip);
66 msgin.serialMemStream(bms);
68 // Unpack bitmemstream
69 uint32 xmlcode;
70 bms.serial(xmlcode, nbBitsToSkip); // the XML code was already read by tbe sender service
71 std::string languageCode;
72 bms.serial(languageCode);
74 nlinfo("<impulsionRdy> send ready for client %s using language %s",sender.toString().c_str(), languageCode.c_str());
76 CCharacterInfos * charInfos = IOS->getCharInfos( sender );
77 if( charInfos != NULL )
79 // charInfos->Id.getDynamicId() = serviceId;
80 // read the language code used by the client for this session
81 charInfos->Language = SM->checkLanguageCode(languageCode);
82 nldebug ("set user %s to front end %d using language code %s", sender.toString().c_str(), serviceId, SM->getLanguageCodeString(charInfos->Language).c_str());
85 // send back the cache time stamp info
86 uint32 timestamp = SM->getCacheTimestamp();
88 // now, build the message for the client.
89 NLMISC::CBitMemStream bmsOut;
90 GenericXmlMsgHeaderMngr.pushNameToStream( "STRING_MANAGER:RELOAD_CACHE", bmsOut);
91 bmsOut.serial(timestamp);
93 // send the message to Front End
94 NLNET::CMessage msgout( "IMPULS_CH_ID" );
95 NLMISC::CEntityId destId = sender;
96 uint8 channel = 1;
97 msgout.serial( destId );
98 msgout.serial( channel );
100 msgout.serialBufferWithSize((uint8*)bmsOut.buffer(), bmsOut.length());
101 NLNET::CUnifiedNetwork::getInstance()->send(charInfos->EntityId.getDynamicId(), msgout);
103 else
105 nlwarning("<cbImpulsionReadyString> The character %s doesn't have infos",sender.toString().c_str());
111 //-----------------------------------------------
112 // cbImpulsionChat :
114 //-----------------------------------------------
115 void cbImpulsionChat( CMessage& msgin, const string &serviceName, TServiceId serviceId )
117 CEntityId sender;
118 msgin.serial(sender);
120 ucstring ucstr;
123 msgin.serial(ucstr);
125 catch(const Exception &e)
127 nlwarning("<impulsionChat> %s",e.what());
128 return;
131 // Do a general filtering on client input
132 ucstr = IOS->getChatManager().filterClientInput(ucstr);
134 if( ShowChat )
136 nlinfo("<impulsionChat> CHAT received : %s",ucstr.toString().c_str());
141 TDataSetRow senderRow = TheDataset.getDataSetRow(sender);
142 IOS->getChatManager().getClient(senderRow).updateAudience();
143 IOS->getChatManager().chat( senderRow, ucstr );
145 catch(const Exception &e)
147 nlwarning("<impulsionChat> %s",e.what());
149 } // impulsionChat //
152 //-----------------------------------------------
153 // cbImpulsionChatTeam :
155 //-----------------------------------------------
156 void cbImpulsionChatTeam( CMessage& msgin, const string &serviceName, TServiceId serviceId )
158 CEntityId sender;
159 msgin.serial(sender);
161 ucstring ucstr;
164 msgin.serial(ucstr);
166 catch(const Exception &e)
168 nlwarning("<impulsionChatTeam> %s",e.what());
169 return;
172 // Do a general filtering on client input
173 ucstr = IOS->getChatManager().filterClientInput(ucstr);
175 if( ShowChat )
177 nlinfo("<impulsionChatTeam> CHAT_TEAM received : %s",ucstr.toString().c_str());
182 TDataSetRow senderRow = TheDataset.getDataSetRow(sender);
183 // get current chat mode
184 const CChatGroup::TGroupType chatModeBck = IOS->getChatManager().getClient(senderRow).getChatMode();
185 // set chat mode to group
186 IOS->getChatManager().getClient(senderRow).setChatMode( CChatGroup::team );
187 //IOS->getChatManager().getClient(sender).updateAudience(); // only for say and shout
188 // send the message
189 IOS->getChatManager().chat( senderRow, ucstr );
190 // reset chat mode to old value
191 IOS->getChatManager().getClient(senderRow).setChatMode( chatModeBck );
193 catch(const Exception &e)
195 nlwarning("<impulsionChatTeam> %s",e.what());
197 } // impulsionChatTeam //
200 //-----------------------------------------------
201 // cbImpulsionTell :
203 //-----------------------------------------------
204 void cbImpulsionTell( CMessage& msgin, const string &serviceName, TServiceId serviceId )
206 CEntityId sender;
207 msgin.serial(sender);
209 string receiver;
210 ucstring str;
213 msgin.serial(receiver);
214 msgin.serial(str);
216 catch(const Exception &e)
218 nlwarning("<impulsionTell> %s",e.what());
219 return;
222 // Do a general filtering on client input
223 str = IOS->getChatManager().filterClientInput(str);
225 if( ShowChat )
227 string senderName;
228 CCharacterInfos *ci = IOS->getCharInfos(sender);
229 if (ci == NULL)
230 senderName = sender.toString();
231 else
232 senderName = IOS->getRocketName(ci->Name);
234 nlinfo("<impulsionTell> TELL %s to %s: '%s'", senderName.c_str(), receiver.c_str(), str.toString().c_str());
236 TDataSetRow senderRow = TheDataset.getDataSetRow(sender);
238 IOS->getChatManager().tell( senderRow, receiver, str );
240 } // impulsionTell //
242 //-----------------------------------------------
243 // setIgnoreStatus
245 //-----------------------------------------------
246 static void updateIgnoreStatus(CMessage& msgin, const string &serviceName, TServiceId serviceId, bool ignored)
248 CEntityId senderId;
249 CEntityId ignoredId;
253 msgin.serial(senderId);
254 msgin.serial(ignoredId);
255 IOS->getChatManager().getClient(TheDataset.getDataSetRow(senderId)).setIgnoreStatus(ignoredId, ignored);
257 catch(const Exception &e)
259 nlwarning("<impulsionIgnore> %s",e.what());
260 return;
264 //-----------------------------------------------
265 // cbImpulsionIgnore :
267 //-----------------------------------------------
268 void cbImpulsionIgnore( CMessage& msgin, const string &serviceName, TServiceId serviceId )
270 updateIgnoreStatus(msgin, serviceName, serviceId, true);
271 } // impulsionIgnore //
273 //-----------------------------------------------
274 // cbImpulsionUnignore :
276 //-----------------------------------------------
277 void cbImpulsionUnignore( CMessage& msgin, const string &serviceName, TServiceId serviceId )
279 updateIgnoreStatus(msgin, serviceName, serviceId, false);
280 } // impulsionUnignore //
282 //-----------------------------------------------
283 // cbImpulsionUnignoreAll :
285 //-----------------------------------------------
286 void cbImpulsionUnignoreAll( CMessage& msgin, const string &serviceName, TServiceId serviceId )
288 CEntityId senderId;
289 vector<CEntityId> ignoredIds;
293 msgin.serial(senderId);
294 msgin.serialCont(ignoredIds);
295 for ( vector<CEntityId>::const_iterator it=ignoredIds.begin(); it!=ignoredIds.end(); ++it )
297 IOS->getChatManager().getClient(TheDataset.getDataSetRow(senderId)).setIgnoreStatus(*it, false);
300 catch(const Exception &e)
302 nlwarning("<impulsionIgnoreAll> %s",e.what());
303 return;
306 } // impulsionUnignoreAll //
309 //-----------------------------------------------
310 // cbImpulsionFilter :
312 //-----------------------------------------------
313 void cbImpulsionFilter( CMessage& msgin, const string &serviceName, TServiceId serviceId )
315 CEntityId sender;
316 msgin.serial(sender);
318 uint8 filterId;
321 msgin.serial( filterId );
323 catch(const Exception &e)
325 nlwarning("<impulsionFilter> %s",e.what());
326 return;
329 CCharacterInfos * charInfos = IOS->getCharInfos( sender );
330 if( charInfos != NULL )
334 IOS->getChatManager().getClient(TheDataset.getDataSetRow(sender)).filter( filterId );
336 catch(const Exception &e)
338 nlwarning("<impulsionFilter> %s",e.what());
341 else
343 nlwarning("<impulsionFilter>The character %s doesn't have infos",sender.toString().c_str());
345 } // impulsionFilter //
348 static const char* DebugChatModeName[] =
350 "say",
351 "shout",
352 "team",
353 "guild",
354 "civilization",
355 "territory",
356 "universe",
357 "tell",
358 "player",
359 "arround",
360 "system",
361 "region",
362 "nbChatMode",
365 //-----------------------------------------------
366 // cbImpulsionChatMode :
368 //-----------------------------------------------
369 void cbImpulsionChatMode( CMessage& msgin, const string &serviceName, TServiceId serviceId )
371 CEntityId sender;
372 msgin.serial(sender);
374 uint8 chatMode;
375 TChanID chanID;
378 msgin.serial( chatMode );
379 msgin.serial(chanID);
381 catch(const Exception &e)
383 nlwarning("<cbImpulsionChatMode> %s",e.what());
384 return;
386 CCharacterInfos * charInfos = IOS->getCharInfos( sender );
387 if( charInfos != NULL )
391 switch( chatMode )
393 case CChatGroup::say :
394 case CChatGroup::shout :
395 case CChatGroup::team :
396 case CChatGroup::guild :
397 case CChatGroup::region :
398 case CChatGroup::universe :
399 IOS->getChatManager().getClient(TheDataset.getDataSetRow(sender)).setChatMode( static_cast<CChatGroup::TGroupType>(chatMode));
400 nldebug("IOS: Chat mode --> %s", DebugChatModeName[chatMode]);
401 break;
402 case CChatGroup::dyn_chat:
403 IOS->getChatManager().getClient(TheDataset.getDataSetRow(sender)).setChatMode( static_cast<CChatGroup::TGroupType>(chatMode), chanID);
404 break;
405 default:
406 if (chatMode < CChatGroup::nbChatMode)
407 nlwarning("<cbImpulsionChatMode>(CHAT_MODE) The chat mode '%s' can't be set", DebugChatModeName[chatMode]);
408 else
409 nlwarning("<cbImpulsionChatMode>(CHAT_MODE) The chat mode %d is out of enum !", chatMode);
412 catch(const Exception &e)
414 nlwarning("<cbImpulsionChatMode> %s",e.what());
417 else
419 nlwarning("<cbImpulsionChatMode> The character %s doesn't have infos",sender.toString().c_str());
422 } // cbImpulsionChatMode //
425 //-----------------------------------------------
426 // cbImpulsionAfkTxt :
428 //-----------------------------------------------
429 void cbImpulsionAfkTxt( CMessage& msgin, const string &serviceName, TServiceId serviceId )
431 CEntityId sender;
432 msgin.serial(sender);
434 ucstring afkTxt;
437 msgin.serial( afkTxt );
439 catch(const Exception &e)
441 nlwarning("<cbImpulsionAfkTxt> %s",e.what());
442 return;
445 // Do a general filtering on client input
446 afkTxt = IOS->getChatManager().filterClientInputColorCode(afkTxt);
448 CCharacterInfos * charInfos = IOS->getCharInfos( sender );
449 if( charInfos != NULL )
451 charInfos->AfkCustomTxt = afkTxt;
453 else
455 nlwarning("<cbImpulsionAfkTxt> The character %s doesn't have infos",sender.toString().c_str());
458 } // cbImpulsionAfkTxt //
461 //-----------------------------------------------
462 // cbImpulsionStringRqId :
464 //-----------------------------------------------
465 //void cbImpulsionStringRqId( CMessage& msgin, const string &serviceName, TServiceId serviceId )
467 // CEntityId sender;
468 // msgin.serial(sender);
470 // uint32 stringId;
471 // msgin.serial(stringId);
473 // SM->requestString(sender, stringId);
477 //-----------------------------------------------
478 // cbImpulsionStringRqUid :
480 //-----------------------------------------------
481 void cbImpulsionStringRqUid( CMessage& msgin, const string &serviceName, TServiceId serviceId )
483 uint32 userId;
484 msgin.serial(userId);
486 uint32 stringId;
487 msgin.serial(stringId);
489 SM->requestString(userId, stringId);
493 struct CReceiver
495 // CEntityId Id;
496 TDataSetRow DataSetIndex;
497 CBitMemStream BMS;
498 // uint16 FrontendId;
502 //-----------------------------------------------
503 // cbStaticString :
505 //-----------------------------------------------
506 static void cbStaticString(CMessage& msgin, const string &serviceName, TServiceId serviceId)
509 // read receiver id
510 CEntityId receiver;
511 set<CEntityId> excluded;
512 string strId;
514 msgin.serial( receiver );
515 msgin.serialCont( excluded );
516 msgin.serial( strId );
518 nlwarning("cbStaticString : service %u(%s) use deprecated phrase system. Trying to output string '%s'."
519 , serviceId.get(), serviceName.c_str(),
520 strId.c_str());
521 return;
522 } // cbStaticString //
526 //-----------------------------------------------
527 // cbChatMessage :
529 //-----------------------------------------------
530 static void cbChatMessage(CMessage& msgin, const string &serviceName, TServiceId serviceId)
532 TDataSetRow entityId;
533 string str;
537 msgin.serial(entityId);
538 msgin.serial(str);
540 catch(const Exception &e)
542 nlwarning("<cbChatMessage> %s",e.what());
543 return;
548 CChatGroup::TGroupType oldMode = IOS->getChatManager().getClient(entityId).getChatMode();
549 if ( oldMode != CChatGroup::say )
550 IOS->getChatManager().getClient(entityId).setChatMode(CChatGroup::say);
552 IOS->getChatManager().getClient(entityId).updateAudience();
553 IOS->getChatManager().chat( entityId, str );
555 if ( oldMode != CChatGroup::say )
556 IOS->getChatManager().getClient(entityId).setChatMode(oldMode);
558 catch(const Exception &e)
560 nlwarning("<cbChatMessage> %s",e.what());
562 } // cbChatMessage //
565 //-----------------------------------------------
566 // cbRemoveEntity :
568 //-----------------------------------------------
569 /*static void cbRemoveEntity(CMessage& msgin, const string &serviceName, TServiceId serviceId)
571 // read entity id
572 CEntityId entityId;
575 msgin.serial( entityId );
577 catch(const Exception &e)
579 nlwarning("<cbRemoveEntity> %s",e.what());
580 return;
583 // remove entity
584 IOS->removeEntity( entityId );
586 nldebug("<cbRemoveEntity> Removing entity %s",entityId.toString().c_str());
590 //-----------------------------------------------
591 // cbCharacterName :
593 //-----------------------------------------------
594 static void cbCharacterName(CMessage& msgin, const string &serviceName, TServiceId serviceId)
596 TDataSetRow chId;
597 ucstring name;
601 // read character id
602 msgin.serial( chId );
604 // character's name
605 msgin.serial( name );
607 catch(const Exception &e)
609 nlwarning("<cbCharacterName> %s",e.what());
610 return;
613 IOS->addCharacterName( chId, name, TSessionId(0) );
615 } // cbCharacterName //
617 //-----------------------------------------------
618 // cbCharacterNameId :
620 //-----------------------------------------------
621 static void cbCharacterNameId(CMessage& msgin, const string &serviceName, TServiceId serviceId)
623 TDataSetRow chId;
624 uint32 stringId;
627 // read character id
628 msgin.serial( chId );
630 // character's string Id
631 msgin.serial( stringId );
633 catch(const Exception &e)
635 nlwarning("<cbCharacterName> %s",e.what());
636 return;
638 IOS->addCharacterName( chId, SM->getString( stringId ), TSessionId(0) );
640 } // cbCharacterNameId //
642 //-----------------------------------------------
643 // cbCharacterNameAndLang :
645 //-----------------------------------------------
646 static void cbCharacterNameAndLang(CMessage& msgin, const string &serviceName, TServiceId serviceId)
648 TDataSetRow chId;
649 ucstring name;
650 TSessionId sessionId;
651 string language;
652 std::vector<NLMISC::CEntityId> ignoreList;
653 bool havePrivilege;
656 // read character id
657 msgin.serial( chId );
659 // character's name
660 msgin.serial( name );
662 // character home mainland session
663 msgin.serial( sessionId );
665 // language
666 msgin.serial(language);
668 // ignoreList
669 msgin.serialCont(ignoreList);
671 // privilege
672 msgin.serial( havePrivilege );
674 catch(const Exception &e)
676 nlwarning("<cbCharacterName> %s",e.what());
677 return;
680 IOS->addCharacterName( chId, name, sessionId );
681 CCharacterInfos *ci = IOS->getCharInfos(TheDataset.getEntityId(chId), false);
682 if (ci)
684 ci->Language = SM->checkLanguageCode(language);
685 ci->HavePrivilege = havePrivilege;
686 IOS->getChatManager().getClient(chId).setIgnoreList(ignoreList);
689 } // cbCharacterNameAndLang //
691 //-----------------------------------------------
692 // cbCharacterEventFaction :
694 //-----------------------------------------------
695 static void cbCharacterEventFaction(CMessage& msgin, const string &serviceName, TServiceId serviceId)
697 TDataSetRow chId;
698 string eventFaction;
701 // read character id
702 msgin.serial( chId );
704 // event faction
705 msgin.serial( eventFaction );
707 catch(const Exception &e)
709 nlwarning("<cbCharacterEventFaction> %s", e.what());
710 return;
713 CCharacterInfos *ci = IOS->getCharInfos(TheDataset.getEntityId(chId), false);
714 if ( ci && TheDataset.isAccessible(chId) )
716 if (eventFaction.empty())
717 ci->UntranslatedEventFactionId = 0;
718 else
719 ci->UntranslatedEventFactionId = SM->storeString( eventFaction );
721 // CMirrorPropValue<TYPE_EVENT_FACTION_ID> propEventFactionId( TheDataset, chId, DSPropertyEVENT_FACTION_ID );
722 // propEventFactionId = SM->translateEventFaction( ci->UntranslatedEventFactionId );
724 else
726 nlwarning("cbCharacterEventFaction: character has not been registered yet in IOS!");
729 } // cbCharacterEventFaction //
732 //-----------------------------------------------
733 // cbAddGroup :
735 //-----------------------------------------------
736 static void cbAddGroup( CMessage& msgin, const string &serviceName, TServiceId serviceId )
738 TGroupId gId;
739 uint8 gType;
743 msgin.serial( gId );
744 msgin.serial( gType );
746 catch(const Exception &e)
748 nlwarning("<cbAddGroup> %s",e.what());
749 return;
752 IOS->getChatManager().addGroup( gId, (CChatGroup::TGroupType)gType, "" );
754 if (VerboseChatManagement)
755 nldebug("IOS: cbAddGroup Adding group %s with type '%s'",
756 gId.toString().c_str(),
757 CChatGroup::groupTypeToString((CChatGroup::TGroupType)gType).c_str());
759 } // cbAddGroup //
761 //-----------------------------------------------
762 // cbAddNamedGroup :
764 //-----------------------------------------------
765 static void cbAddNamedGroup( CMessage& msgin, const string &serviceName, TServiceId serviceId )
767 TGroupId gId;
768 uint8 gType;
769 string name;
773 msgin.serial( gId );
774 msgin.serial( gType );
775 msgin.serial( name );
777 catch(const Exception &e)
779 nlwarning("<cbAddGroup> %s",e.what());
780 return;
783 IOS->getChatManager().addGroup( gId, (CChatGroup::TGroupType)gType, name );
785 if (VerboseChatManagement)
786 nldebug("IOS: cbAddGroup Adding named group %s with type '%s' as '%s'",
787 gId.toString().c_str(),
788 CChatGroup::groupTypeToString((CChatGroup::TGroupType)gType).c_str(),
789 name.c_str());
791 } // cbAddGroup //
793 //-----------------------------------------------
794 // cbRemoveGroup :
796 //-----------------------------------------------
797 static void cbRemoveGroup( CMessage& msgin, const string &serviceName, TServiceId serviceId )
799 TGroupId gId;
803 msgin.serial( gId );
805 catch(const Exception &e)
807 nlwarning("<cbRemoveGroup> %s",e.what());
808 return;
811 IOS->getChatManager().removeGroup( gId );
813 nldebug("IOS: cbRemoveGroup Removing group %s",gId.toString().c_str());
815 } // cbRemoveGroup //
818 //-----------------------------------------------
819 // cbAddToGroup :
821 //-----------------------------------------------
822 static void cbAddToGroup( CMessage& msgin, const string &serviceName, TServiceId serviceId )
824 TGroupId gId;
825 CEntityId charId;
829 msgin.serial( gId );
830 msgin.serial( charId );
832 catch(const Exception& e)
834 nlwarning("<cbAddToGroup> %s",e.what());
835 return;
838 TDataSetRow charRow = TheDataset.getDataSetRow(charId);
840 if(charRow.getIndex() == 0xffffff)
842 nlwarning("id.getIndex() == 0xffffff for entity %s, skip it", charId.toString().c_str());
843 return;
846 // if not already register in chat manager, add it
847 if (!IOS->getChatManager().checkClient(charRow))
848 IOS->getChatManager().addClient( charRow );
849 //IOS->getChatManager().getClient(charId).setChatMode(say);
851 IOS->getChatManager().addToGroup( gId, charRow );
853 nldebug("IOS: cbAddToGroup Adding %s to group %s",charId.toString().c_str(), gId.toString().c_str());
855 } // cbAddToGroup //
858 //-----------------------------------------------
859 // cbRemoveFromGroup :
861 //-----------------------------------------------
862 static void cbRemoveFromGroup( CMessage& msgin, const string &serviceName, TServiceId serviceId )
864 TGroupId gId;
865 CEntityId charId;
869 msgin.serial( gId );
870 msgin.serial( charId );
872 catch(const Exception& e)
874 nlwarning("<cbRemoveFromGroup> %s",e.what());
875 return;
878 TDataSetRow charRow = TheDataset.getDataSetRow(charId);
880 if (charRow.isValid())
882 IOS->getChatManager().removeFromGroup( gId, charRow );
884 nldebug("IOS: cbAddToGroup Removing %s:%x from group %s",
885 charId.toString().c_str(),
886 charRow.getIndex(),
887 gId.toString().c_str());
890 } // cbRemoveFromGroup //
894 //-----------------------------------------------
895 // cbSendDynamicId :
897 //-----------------------------------------------
898 //static void cbSendDynamicId( CMessage& msgin, const string &serviceName, TServiceId serviceId )
900 // CEntityId clientId;
901 // CEntityId entityId;
903 // try
904 // {
905 // msgin.serial( clientId );
906 // msgin.serial( entityId );
907 // }
908 // catch(const Exception& e)
909 // {
910 // nlwarning("<cbSendDynamicId> %s",e.what());
911 // return;
912 // }
914 // CCharacterInfos * clientInfos = IOS->getCharInfos( clientId );
915 // CCharacterInfos * entityInfos = IOS->getCharInfos( entityId );
916 // if( clientInfos != NULL )
917 // {
918 // if( entityInfos != NULL )
919 // {
920 // try
921 // {
922 // if( IOS->getChatManager().getClient(clientInfos->DataSetIndex).knowString(entityInfos->OldNameIndex) == false )
923 // {
924 // IOS->getChatManager().addDynStr( clientId, entityInfos->OldNameIndex, serviceId );
925 // }
926 // }
927 // catch(const CChatManager::EChatClient& e)
928 // {
929 // nlwarning("<cbSendDynamicId> %s",e.what());
930 // }
931 // }
932 // else
933 // {
934 // nlwarning("<cbSendDynamicId> Infos about the other character %s not found",entityId.toString().c_str());
935 // }
936 // }
937 // else
938 // {
939 // nlwarning("<cbSendDynamicId> Infos about the receiver %s not found",clientId.toString().c_str());
940 // }
942 //} // cbSendDynamicId //
945 //-----------------------------------------------
946 // cbSysChat :
948 //-----------------------------------------------
949 void cbSysChat( CMessage& msgin, const string &serviceName, TServiceId serviceId )
951 bool talkToUser;
952 CEntityId talkTo;
953 string chatString;
955 msgin.serial(talkToUser);
956 msgin.serial(talkTo);
957 msgin.serial(chatString);
959 if (talkToUser)
961 IOS->getChatManager().sendChat(CChatGroup::tell, TheDataset.getDataSetRow(talkTo), ucstring("{no_bubble}<"+serviceName+":"+toString(serviceId.get())+"> "+chatString));
963 else
965 IOS->getChatManager().chatInGroup(talkTo, ucstring("{no_bubble}<"+serviceName+":"+toString(serviceId.get())+"> ")+chatString, TDataSetRow());
968 } // cbSysChat //
971 //-----------------------------------------------
972 // cbNpcTell :
974 //-----------------------------------------------
975 void cbNpcTell( CMessage& msgin, const string &serviceName, TServiceId serviceId )
977 TDataSetRow sender;
978 TDataSetRow receiver;
979 string phraseId;
981 msgin.serial(sender);
982 msgin.serial(receiver);
983 msgin.serial(phraseId);
985 CChatManager &cm = IOS->getChatManager();
989 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
990 if (sender == INVALID_DATASET_ROW || !sender.isValid())
992 nlwarning("cbNpcTell : ignoring chat because NPC %u not yet in mirror", sender.getIndex()/*.toString().c_str()*/);
993 return;
995 // CChatClient &client = cm.getClient(sender);
996 cm.sendChat2(CChatGroup::tell, receiver, phraseId, sender);
998 catch(const CChatManager::EChatClient &)
1000 nlwarning("cbNpcTell : ignoring chat because NPC info not available yet");
1005 //-----------------------------------------------
1006 // cbGhostTell :
1008 //-----------------------------------------------
1009 void cbGhostTell( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1011 TDataSetRow receiver;
1012 string phraseId;
1014 msgin.serial(receiver);
1015 msgin.serial(phraseId);
1017 CChatManager &cm = IOS->getChatManager();
1019 cm.sendChat2(CChatGroup::tell, receiver, phraseId);
1022 //-----------------------------------------------
1023 // cbNpcTellEx :
1025 //-----------------------------------------------
1026 void cbNpcTellEx( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1028 TDataSetRow sender;
1029 TDataSetRow receiver;
1030 uint32 phraseId;
1032 msgin.serial(sender);
1033 msgin.serial(receiver);
1034 msgin.serial(phraseId);
1036 CChatManager &cm = IOS->getChatManager();
1040 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
1041 if (sender == INVALID_DATASET_ROW || !sender.isValid())
1043 nlwarning("cbNpcTell : ignoring chat because NPC %u not valid", sender.getIndex()/*.toString().c_str()*/);
1044 return;
1046 // CChatClient &client = cm.getClient(sender);
1047 cm.sendChat2Ex(CChatGroup::tell, receiver, phraseId, sender);
1049 catch(const CChatManager::EChatClient &)
1051 nlwarning("cbNpcTell : ignoring chat because NPC info not available yet");
1056 //-----------------------------------------------
1057 // cbNpcChatEx :
1059 //-----------------------------------------------
1060 void cbNpcChatEx( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1062 TDataSetRow sender;
1063 CChatGroup::TGroupType type = CChatGroup::nbChatMode;
1064 uint32 phraseId;
1066 msgin.serial(sender);
1067 msgin.serialEnum(type);
1068 msgin.serial(phraseId);
1070 CChatManager &cm = IOS->getChatManager();
1074 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
1075 if (sender == INVALID_DATASET_ROW)
1077 nlwarning("cbNpcChatEx : ignoring chat because NPC %s:%x Invalid",
1078 TheDataset.getEntityId(sender).toString().c_str(),
1079 sender.getIndex());
1080 return;
1082 CChatClient &client = cm.getClient(sender);
1083 client.setChatMode(type);
1084 client.updateAudience();
1085 cm.chat2Ex(sender, phraseId);
1087 catch(const CChatManager::EChatClient &)
1089 nlwarning("cbNpcChatEx : ignoring chat because NPC info not available yet");
1094 //-----------------------------------------------
1095 // cbNpcChat :
1097 //-----------------------------------------------
1098 void cbNpcChat( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1100 TDataSetRow sender;
1101 CChatGroup::TGroupType type = CChatGroup::nbChatMode;
1102 string phraseId;
1104 msgin.serial(sender);
1105 msgin.serialEnum(type);
1106 msgin.serial(phraseId);
1108 CChatManager &cm = IOS->getChatManager();
1112 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
1113 if ( !sender.isValid() || !TheDataset.isDataSetRowStillValid(sender) )
1115 nlwarning("cbNpcChat : ignoring chat because NPC %x not yet/not anymore in mirror",
1116 sender.getIndex());
1117 return;
1119 CChatClient &client = cm.getClient(sender);
1120 client.setChatMode(type);
1121 client.updateAudience();
1122 cm.chat2(sender, phraseId);
1124 catch(const CChatManager::EChatClient &)
1126 nlwarning("cbNpcChat : ignoring chat because NPC info not available yet");
1130 //-----------------------------------------------
1131 // cbNpcChatDyn :
1133 //-----------------------------------------------
1134 void cbNpcChatParam( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
1136 TDataSetRow sender;
1137 CChatGroup::TGroupType type = CChatGroup::nbChatMode;
1138 string phraseId;
1139 std::vector<STRING_MANAGER::TParam> params;
1141 msgin.serial(sender);
1142 msgin.serialEnum(type);
1143 msgin.serial(phraseId);
1145 uint32 size;
1146 msgin.serial(size);
1147 params.resize(size);
1148 for ( uint i = 0; i < size; i++ )
1150 uint8 type8;
1151 msgin.serial( type8 );
1152 params[i].serialParam( false, msgin, (STRING_MANAGER::TParamType) type8 );
1155 CChatManager &cm = IOS->getChatManager();
1159 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
1160 if ( !sender.isValid() || !TheDataset.isDataSetRowStillValid(sender) )
1162 nlwarning("cbNpcChat : ignoring chat because NPC %x not yet/not anymore in mirror",
1163 sender.getIndex());
1164 return;
1166 CChatClient &client = cm.getClient(sender);
1167 client.setChatMode(type);
1168 client.updateAudience();
1169 cm.chatParam(sender, phraseId, params);
1171 catch(const CChatManager::EChatClient &)
1173 nlwarning("cbNpcChat : ignoring chat because NPC info not available yet");
1178 //-----------------------------------------------
1179 // cbNpcChatSentence :
1181 //-----------------------------------------------
1182 void cbNpcChatSentence( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1184 TDataSetRow sender;
1185 CChatGroup::TGroupType type = CChatGroup::nbChatMode;
1186 ucstring sentence;
1188 msgin.serial(sender);
1189 msgin.serialEnum(type);
1190 msgin.serial(sentence);
1192 CChatManager &cm = IOS->getChatManager();
1196 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
1197 if ( !sender.isValid() || !TheDataset.isDataSetRowStillValid(sender) )
1199 nlwarning("cbNpcChatSentence : ignoring chat because NPC %x not yet/not anymore in mirror",
1200 sender.getIndex());
1201 return;
1203 CChatClient &client = cm.getClient(sender);
1204 client.setChatMode(type);
1205 client.updateAudience();
1206 cm.chat(sender, sentence);
1208 catch(const CChatManager::EChatClient &)
1210 nlwarning("cbNpcChatSentence : ignoring chat because NPC info not available yet");
1214 //-----------------------------------------------
1215 // cbNpcChatSentenceEx :
1217 //-----------------------------------------------
1218 void cbNpcChatSentenceEx( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1220 ucstring name;
1221 ucstring sentence;
1222 TChanID id;
1223 TDataSetRow sender;
1224 msgin.serial(id);
1225 msgin.serial(name);
1226 msgin.serial(sentence);
1227 if(id.isUnknownId())
1229 nlwarning("bad channel id : %s unable to chat! ",id.toString().c_str());
1230 return;
1232 CCharacterInfos* cInfo = IOS->getCharInfos(name);
1233 sender = cInfo->DataSetIndex;
1234 if(sender.isValid())
1236 CChatManager &cm = IOS->getChatManager();
1237 CChatClient &client = cm.getClient(sender);
1238 client.setChatMode(CChatGroup::dyn_chat,id);
1239 client.updateAudience();
1240 cm.chat(sender,sentence);
1242 else
1244 nlwarning("sender %s:%x invalid! unable to chat!",name.toString().c_str(),sender.getIndex());
1248 void cbNpcChatSentenceChannel( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1250 ucstring sentence;
1251 TChanID id;
1252 TDataSetRow sender;
1253 msgin.serial(id);
1254 msgin.serial(sender);
1255 msgin.serial(sentence);
1257 if(sender.isValid())
1259 CChatManager &cm = IOS->getChatManager();
1260 CChatClient &client = cm.getClient(sender);
1261 client.setChatMode(CChatGroup::dyn_chat,id);
1262 client.updateAudience();
1263 cm.chat(sender,sentence);
1264 nlwarning("%s said %s !",sender.toString().c_str(),sentence.toString().c_str());
1265 }else
1267 nlwarning("sender %x invalid! unable to chat!",sender.getIndex());
1272 //-----------------------------------------------
1273 // cbGroupDynString :
1275 //-----------------------------------------------
1276 void cbGroupDynString( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1278 TDataSetRow sender;
1279 vector<CEntityId> excluded;
1280 uint32 phraseId;
1282 msgin.serial(sender);
1283 msgin.serialCont(excluded);
1284 msgin.serial(phraseId);
1286 CChatManager &cm = IOS->getChatManager();
1290 // TDataSetRow dsr = TheDataset.getDataSetRow(sender);
1291 if (sender == INVALID_DATASET_ROW || !sender.isValid())
1293 nlwarning("cbGroupDynString : ignoring group message because entity %x not yet in mirror", sender.getIndex());
1294 return;
1297 list<CReceiver> receiverList;
1299 CChatClient &client = cm.getClient(sender);
1300 client.updateAudience();
1301 CChatGroup group = client.getSayAudience();
1303 CChatGroup::TMemberCont::iterator itM;
1304 for( itM = group.Members.begin(); itM != group.Members.end(); ++itM )
1306 const CEntityId &id = TheDataset.getEntityId(*itM);
1308 // skip it if excluded
1309 if ( std::find(excluded.begin(), excluded.end(), id) != excluded.end() )
1310 continue;
1312 // send message to client front end
1313 CMessage msgout( "IMPULSION_ID" );
1314 msgout.serial( const_cast<CEntityId&> (id) );
1315 CBitMemStream bms;
1316 if ( ! GenericXmlMsgHeaderMngr.pushNameToStream( "STRING:DYN_STRING", bms) )
1318 nlwarning("Msg name CHAT:DYN_STRING not found");
1320 else
1322 bms.serial( phraseId );
1323 msgout.serialBufferWithSize((uint8*)bms.buffer(), bms.length());
1324 CUnifiedNetwork::getInstance()->send( TServiceId(id.getDynamicId()), msgout );
1328 catch(const CChatManager::EChatClient &)
1330 nlwarning("cbGroupDynString : ignoring group message because entity info not available yet");
1332 } // cbGroupDynString //
1334 void cbPhrasePrepare( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1336 SM->receivePhrase(msgin, false, serviceName);
1339 void cbPhrasePrepareDebug( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1341 SM->receivePhrase(msgin, true, serviceName);
1344 void cbUserPhrasePrepare( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1346 SM->receiveUserPhrase(msgin, false);
1349 void cbUserPhrasePrepareDebug( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1351 SM->receiveUserPhrase(msgin, true);
1354 void cbBroadcastSystemPhrase( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1356 SM->broadcastSystemMessage(msgin, false);
1359 void cbBroadcastSystemPhraseDebug( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1361 SM->broadcastSystemMessage(msgin, true);
1364 // message STORE_STRING
1365 void cbStoreString( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1367 ucstring str;
1368 msgin.serial(str);
1369 uint32 stringId = SM->storeString(str);
1371 CMessage msgOut("STORE_STRING_RESULT");
1372 msgOut.serial(str);
1373 msgOut.serial(stringId);
1375 CUnifiedNetwork::getInstance()->send(serviceId, msgOut);
1378 void cbGetString(CMessage& msgin, const string &serviceName, TServiceId serviceId )
1380 uint32 nameIndex;
1381 msgin.serial( nameIndex );
1382 SM->sendString( nameIndex, serviceId );
1385 void cbRetrieveEntityNames( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1387 SM->retrieveEntityNames( serviceId );
1390 void cbUserLanguage( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1392 uint32 userId;
1393 TServiceId frontEndId;
1394 string lang;
1395 msgin.serial( userId );
1396 msgin.serial( frontEndId );
1397 msgin.serial( lang );
1398 SM->updateUserLanguage( userId,frontEndId, lang );
1400 // Note: removeUserLanguage() is never called, currently
1403 void cbRemoveUserLanguage( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1405 uint32 userId;
1406 msgin.serial( userId );
1407 SM->removeUserLanguage( userId );
1410 void cbIgnoreTellMode( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1412 NLMISC::CEntityId userId;
1413 bool mode;
1414 msgin.serial( userId );
1415 msgin.serial( mode );
1416 CChatManager &cm = IOS->getChatManager();
1417 if ( mode )
1418 cm.addUserIgnoringTells( userId );
1419 else
1420 cm.removeUserIgnoringTells( userId );
1423 void cbMutePlayer( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1425 NLMISC::CEntityId userId;
1426 bool mode;
1427 msgin.serial( userId );
1428 msgin.serial( mode );
1429 CChatManager &cm = IOS->getChatManager();
1430 if ( mode )
1431 cm.addMutedUser( userId );
1432 else
1433 cm.removeMutedUser( userId );
1436 void cbUniverseMode( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1438 NLMISC::CEntityId userId;
1439 bool mode;
1440 msgin.serial( userId );
1441 msgin.serial( mode );
1443 CChatGroup::TGroupType type = (mode)?CChatGroup::universe : CChatGroup::say;
1444 CCharacterInfos * charInfos = IOS->getCharInfos( userId );
1445 if( charInfos != NULL )
1449 IOS->getChatManager().getClient(TheDataset.getDataSetRow(userId)).setChatMode( type );
1451 catch(const Exception& e)
1453 nlwarning("<impulsionChatMode> %s",e.what());
1456 else
1458 nlwarning("<impulsionChatMode> The character %s doesn't have infos",userId.toString().c_str());
1462 void cbMuteUniverse( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1464 NLMISC::CEntityId userId;
1465 bool mode;
1466 msgin.serial( userId );
1467 msgin.serial( mode );
1468 CChatManager &cm = IOS->getChatManager();
1469 if ( mode )
1470 cm.addUniverseMutedUser(userId);
1471 else
1472 cm.removeUniverseMutedUser(userId);
1475 //-----------------------------------------------
1476 // cbEmoteCrowd : a crowd receive an emote ( e.g. : everybody except the main target )
1478 //-----------------------------------------------
1479 void cbEmoteCrowd( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1481 TDataSetRow sender;
1482 string phraseTextId;
1483 TVectorParamCheck params;
1484 vector<TDataSetRow> ignored;
1486 CChatManager &cm = IOS->getChatManager();
1490 msgin.serial(sender);
1491 msgin.serial(phraseTextId);
1492 uint32 size;
1493 msgin.serial(size);
1494 params.resize(size);
1495 for ( uint i = 0; i < size; i++ )
1497 uint8 type8;
1498 msgin.serial( type8 );
1499 params[i].serialParam( false, msgin, (STRING_MANAGER::TParamType) type8 );
1501 msgin.serialCont( ignored );
1503 // get the plyer
1504 if ( sender == TDataSetRow::createFromRawIndex(INVALID_DATASET_ROW) )
1506 nlwarning("cbNpcChat : ignoring emote because PC %x Invalid", sender.getIndex());
1507 return;
1509 // send the phrase
1510 cm.sendEmoteTextToAudience(sender, phraseTextId, params,ignored);
1512 catch(const CChatManager::EChatClient &)
1514 nlwarning("cbNpcChatEx : ignoring chat because NPC info not available yet");
1519 //-----------------------------------------------
1520 // cbEmoteSolePlayer : a unique receive an emote ( e.g. : the main target )
1522 //-----------------------------------------------
1523 void cbEmoteSolePlayer( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1525 TDataSetRow sender;
1526 TDataSetRow target;
1527 uint32 phraseId;
1528 msgin.serial(sender);
1529 msgin.serial(target);
1530 msgin.serial(phraseId);
1531 CChatManager &cm = IOS->getChatManager();
1532 cm.sendEmoteTextToPlayer(sender, target, phraseId );
1536 //-----------------------------------------------
1537 // cbCustomEmote
1538 //-----------------------------------------------
1539 void cbCustomEmote( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1541 TDataSetRow sender;
1542 ucstring emoteCustomText;
1544 CChatManager &cm = IOS->getChatManager();
1548 msgin.serial(sender);
1549 msgin.serial(emoteCustomText);
1551 // filter emote text
1552 emoteCustomText = IOS->getChatManager().filterClientInputColorCode(emoteCustomText);
1554 // get the player
1555 if ( sender == TDataSetRow::createFromRawIndex(INVALID_DATASET_ROW) )
1557 nlwarning("<cbCustomEmote> ignoring emote because PC %x Invalid", sender.getIndex());
1558 return;
1560 // send the phrase
1561 cm.sendEmoteCustomTextToAll(sender, emoteCustomText);
1563 catch(const CChatManager::EChatClient &)
1565 nlwarning("<cbCustomEmote> exception, ignoring emote");
1568 } // cbCustomEmote //
1572 //-----------------------------------------------
1573 // cbSetPhrase : change the content of a phrase
1575 //-----------------------------------------------
1576 void cbSetPhrase( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1578 SM->setPhrase(msgin);
1581 void cbSetPhraseLang( CMessage& msgin, const string& serviceName, TServiceId serviceId )
1583 SM->setPhraseLang(msgin);
1586 //-----------------------------------------------
1587 // Add a new channel in the dyn chat
1589 //-----------------------------------------------
1590 void cbDynChatAddChan(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1592 TChanID chanID;
1593 bool noBroadcast;
1594 bool forwardInput;
1595 bool unify;
1596 string name;
1598 msgin.serial(chanID);
1599 msgin.serial(noBroadcast);
1600 msgin.serial(forwardInput);
1601 msgin.serial(unify);
1602 msgin.serial(name);
1604 nlinfo("cbDynChatAddChan: add channel : %s", name.c_str());
1605 bool res = IOS->getChatManager().getDynChat().addChan(chanID, noBroadcast, forwardInput, unify);
1606 if (!res)
1607 nlwarning("Couldn't add chan %s", chanID.toString().c_str());
1608 else
1610 if (_ChanNames.getA(name) != NULL)
1611 _ChanNames.removeWithB(name);
1612 if (_ChanNames.getB(chanID) != NULL)
1613 _ChanNames.removeWithA(chanID);
1614 _ChanNames.add(chanID, name);
1615 nlinfo("cbDynChatAddChan: add channel %s",chanID.toString().c_str());
1619 //-----------------------------------------------
1620 // Remove a channel from the dyn chat
1622 //-----------------------------------------------
1623 void cbDynChatRemoveChan(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1625 TChanID chanID;
1626 msgin.serial(chanID);
1627 bool res = IOS->getChatManager().getDynChat().removeChan(chanID);
1628 if (res && _ChanNames.getB(chanID) != NULL)
1629 _ChanNames.removeWithA(chanID);
1631 if (!res) nlwarning("Couldn't remove chan %s", chanID.toString().c_str());
1635 //-----------------------------------------------
1636 // Add a session to the dyn chat
1638 //-----------------------------------------------
1639 void addSession(TDataSetRow client,TChanID chan,bool writeRight)
1642 if (!IOS->getChatManager().checkClient(client))
1643 IOS->getChatManager().addClient( client );
1645 CDynChatSession *session = IOS->getChatManager().getDynChat().addSession(chan, client);
1646 if (!session)
1648 nlwarning("Couldn't create session");
1649 return;
1652 session->WriteRight = writeRight;
1653 // send channel historic to client
1654 IOS->getChatManager().sendHistoric(client, chan);
1655 nldebug("IOS: session added %s:%x!! on channel %s",TheDataset.getEntityId(client).toString().c_str(),client.getIndex(),chan.toString().c_str());
1658 void cbDynChatAddSession(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1660 TChanID chan;
1661 TDataSetRow client;
1662 bool writeRight;
1663 msgin.serial(chan);
1664 msgin.serial(client);
1665 msgin.serial(writeRight);
1666 addSession(client,chan,writeRight);
1669 if (!IOS->getChatManager().checkClient(client))
1670 IOS->getChatManager().addClient( client );
1672 CDynChatSession *session = IOS->getChatManager().getDynChat().addSession(chan, client);
1673 if (!session)
1675 nlwarning("Couldn't create session");
1676 return;
1679 session->WriteRight = writeRight;
1680 // send channel historic to client
1681 IOS->getChatManager().sendHistoric(client, chan);
1682 nlwarning("session added %s:%x!! on channel %s",TheDataset.getEntityId(client).toString().c_str(),client.getIndex(),chan.toString().c_str());
1686 //-----------------------------------------------
1687 // Add a session to the dyn chat, using the name of a npc
1688 // TODO: factorize some code with cbDynChatAddSession
1689 //-----------------------------------------------
1690 void cbDynChatAddSessionWithName(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1692 TChanID chan;
1693 TDataSetRow client;
1694 ucstring clientName;
1695 bool writeRight;
1696 msgin.serial(chan);
1697 msgin.serial(clientName);
1698 msgin.serial(writeRight);
1700 if(chan.isUnknownId())
1702 nlwarning("unknown channel id! unable to add session!");
1703 return;
1705 CCharacterInfos* cInfo = IOS->getCharInfos(clientName);
1706 client = cInfo->DataSetIndex;
1707 if(client.isValid())
1709 addSession(client,chan,writeRight);
1711 if (!IOS->getChatManager().checkClient(client))
1712 IOS->getChatManager().addClient( client );
1714 CDynChatSession *session = IOS->getChatManager().getDynChat().addSession(chan, client);
1715 if (!session)
1717 nlwarning("Couldn't create session");
1718 return;
1721 session->WriteRight = writeRight;
1722 // send channel historic to client
1723 IOS->getChatManager().sendHistoric(client, chan);
1726 else
1728 nlwarning("sender %s:%x invalid! unable to add session!",clientName.c_str(),client.getIndex());
1731 //-----------------------------------------------
1732 // Remove a session from the dyn chat
1734 //-----------------------------------------------
1735 void cbDynChatRemoveSession(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1737 TChanID chan;
1738 TDataSetRow client;
1739 msgin.serial(chan);
1740 msgin.serial(client);
1741 bool res = IOS->getChatManager().getDynChat().removeSession(chan, client);
1742 if (!res) nlwarning("Couldn't remove session");
1745 //-----------------------------------------------
1746 // Remove a session from the dyn chat, using the name of the npc
1747 // TODO: factorize some code with cbDynChatRemoveSession
1748 //-----------------------------------------------
1749 void cbDynChatRemoveSessionWithName(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1751 TChanID chan;
1752 ucstring clientName;
1753 TDataSetRow client;
1754 msgin.serial(chan);
1755 msgin.serial(clientName);
1756 CCharacterInfos* cInfo = IOS->getCharInfos(clientName);
1757 client = cInfo->DataSetIndex;
1758 if(client.isValid())
1761 CMessage msgout("DYN_CHAT:REMOVE_SESSION");
1762 msgout.serial(chan);
1763 msgout.serial(client);
1764 CUnifiedNetwork::getInstance()->send("EGS",msgout);
1765 return;
1767 bool res = IOS->getChatManager().getDynChat().removeSession(chan, client);
1768 if (!res) nlwarning("Couldn't remove session");
1773 //-----------------------------------------------
1774 // Set read only flag for a dyn chat session
1776 //-----------------------------------------------
1777 void cbDynChatSetWriteRight(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1779 TChanID chan;
1780 TDataSetRow client;
1781 bool writeRight;
1782 msgin.serial(chan);
1783 msgin.serial(client);
1784 msgin.serial(writeRight);
1785 CDynChatSession *session = IOS->getChatManager().getDynChat().getSession(chan, client);
1786 if (!session)
1788 nlwarning("Unknown session");
1789 return;
1791 session->WriteRight = writeRight;
1794 //-----------------------------------------------
1795 // Set the historic size for a channel
1796 //-----------------------------------------------
1797 void cbDynChatSetHistoricSize(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1799 TChanID chanID;
1800 uint32 historicSize;
1801 msgin.serial(chanID);
1802 msgin.serial(historicSize);
1803 CDynChatChan *chan = IOS->getChatManager().getDynChat().getChan(chanID);
1804 if (!chan)
1806 nlwarning("Unknown chan");
1807 return;
1809 chan->Historic.setMaxSize(historicSize);
1811 void cbDynChatSetHideBubble(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1813 TChanID chanID;
1814 bool hideBubble;
1816 msgin.serial(chanID);
1817 msgin.serial(hideBubble);
1819 CChatManager &cm = IOS->getChatManager();
1820 CDynChatChan *chan = cm.getDynChat().getChan(chanID);
1821 if (!chan)
1823 nlwarning("Unknown chan");
1824 return;
1826 chan->HideBubble = hideBubble;
1829 void cbDynChatSetUniversalChannel(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1831 TChanID chanID;
1832 bool universalChannel;
1834 msgin.serial(chanID);
1835 msgin.serial(universalChannel);
1837 CChatManager &cm = IOS->getChatManager();
1838 CDynChatChan *chan = cm.getDynChat().getChan(chanID);
1839 if (!chan)
1841 nlwarning("Unknown chan");
1842 return;
1844 chan->UniversalChannel = universalChannel;
1847 void cbDynChatServiceChat(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1849 TChanID chanID;
1850 ucstring text;
1851 ucstring senderName;
1853 msgin.serial(chanID);
1854 msgin.serial(senderName);
1855 msgin.serial(text);
1857 CChatManager &cm = IOS->getChatManager();
1858 CDynChatChan *chan = cm.getDynChat().getChan(chanID);
1859 if (!chan)
1861 nlwarning("Unknown chan");
1862 return;
1865 // add msg to the historic
1866 CDynChatChan::CHistoricEntry entry;
1867 entry.String = text;
1868 entry.SenderString = senderName;
1869 chan->Historic.push(entry);
1871 // send the message to all the player in this chat
1872 CDynChatSession *dcc = chan->getFirstSession();
1873 if(!dcc) nlwarning(("nobody hears on channel "+chanID.toString()).c_str());
1875 while (dcc)
1877 cm.sendChat(CChatGroup::dyn_chat, dcc->getClient()->getID(), text, TDataSetRow(), chanID, senderName);
1878 dcc = dcc->getNextChannelSession(); // next session in this channel
1882 void cbDynChatServiceTell(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1884 TChanID chanID;
1885 ucstring text;
1886 TDataSetRow player;
1887 ucstring senderName;
1889 msgin.serial(chanID);
1890 msgin.serial(senderName);
1891 msgin.serial(player);
1892 msgin.serial(text);
1894 CChatManager &cm = IOS->getChatManager();
1895 CDynChatChan *chan = cm.getDynChat().getChan(chanID);
1896 if (!chan)
1898 nlwarning("Unknown chan");
1899 return;
1902 // NB: we don't put 'tell' text in channel history
1904 // send the message to the designated player in this chat
1905 CDynChatSession *dcc = chan->getFirstSession();
1906 while (dcc)
1908 if (dcc->getClient()->getID() == player)
1910 cm.sendChat(CChatGroup::dyn_chat, dcc->getClient()->getID(), text, TDataSetRow(), chanID, senderName);
1911 dcc = dcc->getNextChannelSession(); // next session in this channel
1912 // no more needed to continue
1913 break;
1915 dcc = dcc->getNextChannelSession(); // next session in this channel
1919 //-----------------------------------------------
1920 // Reset the dyn chat (all channel & sessions are removed)
1922 //-----------------------------------------------
1923 void cbDynChatReset(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1925 IOS->getChatManager().getDynChat().removeAllChannels();
1928 //-----------------------------------------------
1929 // update the alias list
1931 //-----------------------------------------------
1932 void cbUpdateAIAlias(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1935 enum {Set=0, Add = 1, Delete=2 };
1937 uint32 subcommand;
1938 msgin.serial(subcommand);
1941 switch(subcommand)
1944 case Set:
1945 IOS->getAIAliasManager().clear();
1947 case Add:
1950 uint32 size;
1951 msgin.serial(size);
1952 uint first = 0;
1953 uint last = size;
1954 for ( ;first != last; ++first)
1956 uint32 alias;
1957 std::string name;
1958 msgin.serial(alias);
1959 msgin.serial(name);
1960 IOS->getAIAliasManager().add(alias, name);
1963 break;
1966 case Add: break;
1967 case Delete: break;
1969 default:
1970 nlwarning("<updateAlias> invalid message");
1971 return;
1976 void cbRequestDsr(CMessage& msgin, const string &serviceName, TServiceId serviceId)
1978 //CMessage msg("DSR_VALUE");
1979 ucstring name;
1980 TDataSetRow client;
1981 msgin.serial(name);
1982 CCharacterInfos* cInfo = IOS->getCharInfos(name);
1983 if(!cInfo)return;
1984 client = cInfo->DataSetIndex;
1985 if(client.isValid())
1987 CMessage msg("DSR_VALUE");
1988 nlwarning("dsr value sent! %s = %s",name.toString().c_str(),client.toString().c_str());
1989 msg.serial(name);
1990 msg.serial(client);
1991 CUnifiedNetwork::getInstance()->send(serviceName,msg);
1996 void cbUserDontTranslateLanguages( CMessage& msgin, const string &serviceName, TServiceId serviceId )
1998 TDataSetRow player;
1999 msgin.serial(player);
2001 string langs;
2004 msgin.serial(langs);
2006 catch(const Exception &e)
2008 nlwarning("<impulsionTell> %s",e.what());
2009 return;
2012 if (player == INVALID_DATASET_ROW)
2014 nlwarning("cbUserTranslateLanguage : ignoring chat because Player %s:%x Invalid",
2015 TheDataset.getEntityId(player).toString().c_str(),
2016 player.getIndex());
2017 return;
2020 CChatManager &cm = IOS->getChatManager();
2022 if (!cm.checkClient(player))
2023 IOS->getChatManager().addClient(player);
2025 CChatClient &client = cm.getClient(player);
2027 nlinfo("USER DISBALED TRANSLATIONS: %s", langs.c_str());
2028 vector<string> vlangs;
2029 NLMISC::splitString(langs, "|", vlangs);
2030 client.resetDisabledTranslations();
2031 for (uint i=0; i<vlangs.size(); i++)
2033 if (vlangs[i].size() == 3)
2035 if (vlangs[i][0] == '>')
2036 client.disableSendTranslation(vlangs[i].substr(1));
2037 else if (vlangs[i][0] == '<')
2038 client.disableReceiveTranslation(vlangs[i].substr(1));
2044 //void cbAddDM(CMessage& msgin, const string &serviceName, TServiceId serviceId)
2046 // uint32 charId;
2047 // msgin.serial(charId);
2049 // // rebuild the entity id
2050 // CEntityId eid(RYZOMID::player, charId, 0, 0);
2051 // // retrieve the datasetrow
2052 // TDataSetRow rowId = TheDataset.getDataSetRow(eid);
2053 // if (rowId.isValid())
2054 // {
2055 // // we need to add it in the universe chat
2056 // IOS->getChatManager().addToGroup(TGroupId(RYZOMID::chatGroup, 0), rowId);
2057 // }
2060 //void cbRemoveDM(CMessage& msgin, const string &serviceName, TServiceId serviceId)
2062 // uint32 charId;
2063 // msgin.serial(charId);
2065 // // rebuild the entity id
2066 // CEntityId eid(RYZOMID::player, charId, 0, 0);
2067 // // retrieve the datasetrow
2068 // TDataSetRow rowId = TheDataset.getDataSetRow(eid);
2069 // if (rowId.isValid())
2070 // {
2071 // // we need to remove it from the universe chat
2072 // IOS->getChatManager().removeFromGroup(TGroupId(RYZOMID::chatGroup, 0), rowId);
2073 // }
2077 //----------------------------
2078 // CbArray
2079 //----------------------------
2080 TUnifiedCallbackItem CbIOSArray[]=
2082 // Received from clients (via FS)
2083 // { "READY_STRING", cbImpulsionReadyString },
2084 { "CLIENT:STRING:CHAT", cbImpulsionChat },
2085 { "CLIENT:STRING:CHAT_TEAM", cbImpulsionChatTeam },
2086 { "CLIENT:STRING:TELL", cbImpulsionTell },
2087 { "CLIENT:STRING:FILTER", cbImpulsionFilter },
2088 { "CLIENT:STRING:CHAT_MODE", cbImpulsionChatMode },
2089 { "CLIENT:STRING:AFK_TXT", cbImpulsionAfkTxt },
2090 // { "STRING_RQ_ID", cbImpulsionStringRqId },
2091 { "STRING_RQ_UID", cbImpulsionStringRqUid },
2093 // Received from the back-end
2094 { "STATIC_STRING", cbStaticString },
2095 { "CHAT_MESSAGE", cbChatMessage },
2096 { "CHARACTER_NAME", cbCharacterName }, // receive a character name
2097 { "CHARACTER_NAME_ID", cbCharacterNameId }, // receive a character name with a string manager string Id
2098 { "CHARACTER_NAME_LANG", cbCharacterNameAndLang }, // receive a character name and a language code (for player)
2099 { "CHARACTER_EVENT_FACTION", cbCharacterEventFaction },
2100 { "ADD_GROUP", cbAddGroup },
2101 { "ADD_NAMED_GROUP", cbAddNamedGroup },
2102 { "REMOVE_GROUP", cbRemoveGroup },
2103 { "ADD_TO_GROUP", cbAddToGroup },
2104 { "REMOVE_FROM_GROUP", cbRemoveFromGroup },
2105 // { "SEND_DYNAMIC_ID", cbSendDynamicId },
2106 { "CHAT", cbSysChat }, // talk to a user or a whole group
2108 { "NPC_CHAT", cbNpcChat }, // Npc talk to a chat group
2109 { "NPC_CHAT_PARAM", cbNpcChatParam }, // Npc talk to a chat group (with parameter)
2111 { "NPC_TELL", cbNpcTell }, // Npc tell to a player
2112 { "GHOST_TELL", cbGhostTell }, // Npc tell to a player, without Npc :)
2114 { "NPC_TELL_EX", cbNpcTellEx }, // Extended Npc tell to a player. Receive a stringId (uint32), obtained through the PHRASE message for example
2115 { "NPC_CHAT_EX", cbNpcChatEx }, // Extended Npc chat . Receive a stringId (uint32), obtained through the PHRASE message for example
2116 { "NPC_CHAT_SENTENCE", cbNpcChatSentence}, //Npc chat. receive the sentence to chat
2117 { "NPC_CHAT_SENTENCE_CHANNEL",cbNpcChatSentenceChannel},
2118 { "NPC_CHAT_SENTENCE_EX",cbNpcChatSentenceEx},//Npc chat. receive the name of the npc which talks, and the sentence
2120 { "GROUP_DYN_STRING", cbGroupDynString }, // send a system dynamic string to a group
2121 { "PHRASE", cbPhrasePrepare },
2122 { "PHRASE_DEBUG", cbPhrasePrepareDebug },
2123 { "PHRASE_USER", cbUserPhrasePrepare },
2124 { "PHRASE_USER_DEBUG", cbUserPhrasePrepareDebug },
2125 { "BROADCAST_SYSTEM_PHRASE", cbBroadcastSystemPhrase },
2126 { "BROADCAST_SYSTEM_PHRASE_DEBUG", cbBroadcastSystemPhraseDebug },
2127 { "STORE_STRING", cbStoreString },
2128 { "GET_STRING", cbGetString },
2129 { "RETR_ENTITY_NAMES", cbRetrieveEntityNames },
2130 { "USER_LANGUAGE", cbUserLanguage }, // receive an association between a userId and a language
2131 { "REMOVE_USER_LANGUAGE", cbRemoveUserLanguage },
2132 { "SET_USER_DONT_TRANSLATE_LANGS", cbUserDontTranslateLanguages },
2134 { "IGNORE_TELL_MODE", cbIgnoreTellMode }, // receive an ignore tell mode command from EGS
2135 { "IGNORE", cbImpulsionIgnore },
2136 { "UNIGNORE", cbImpulsionUnignore },
2137 { "UNIGNORE_ALL", cbImpulsionUnignoreAll },
2138 { "MUTE_PLAYER", cbMutePlayer }, // receive a mute player command from EGS
2139 { "UNIVERSE_MODE", cbUniverseMode }, // receive a universe mode command from EGS
2140 { "MUTE_UNIVERSE", cbMuteUniverse }, // received a mute universe channel from EGS
2142 { "EMOTE_CROWD", cbEmoteCrowd }, // EGS wants IOS to dispatch an emote texte to all users around the "emoting" player
2143 { "EMOTE_PLAYER", cbEmoteSolePlayer }, // EGS wants IOS to dispatch an emote texte to a unique player
2144 { "CUSTOM_EMOTE", cbCustomEmote }, // EGS wants IOS to dispatch an emote custom text to all users around
2146 { "SET_PHRASE", cbSetPhrase }, // AIS wants IOS to change a phrase content
2147 { "SET_PHRASE_LANG", cbSetPhraseLang }, // AIS or EGS wants IOS to change a phrase content for a language
2149 { "UPDATE_AIALIAS", cbUpdateAIAlias},
2151 // Dyn chat, received from egs
2152 { "DYN_CHAT:ADD_CHAN", cbDynChatAddChan },
2153 { "DYN_CHAT:REMOVE_CHAN", cbDynChatRemoveChan },
2154 { "DYN_CHAT:ADD_SESSION", cbDynChatAddSession },
2155 { "DYN_CHAT:ADD_SESSION_WITH_NAME", cbDynChatAddSessionWithName},//add a session, receive a npc name
2156 { "DYN_CHAT:REMOVE_SESSION", cbDynChatRemoveSession },
2157 { "DYN_CHAT:REMOVE_SESSION_WITH_NAME", cbDynChatRemoveSessionWithName },//remove a session, receive a npc name
2158 { "DYN_CHAT:SET_WRITE_RIGHT", cbDynChatSetWriteRight },
2160 { "DYN_CHAT:RESET", cbDynChatReset },
2161 { "DYN_CHAT:SET_HISTORIC_SIZE", cbDynChatSetHistoricSize },
2162 { "DYN_CHAT:SERVICE_CHAT", cbDynChatServiceChat }, // a service send a chat message in the channel without sender id
2163 { "DYN_CHAT:SERVICE_TELL", cbDynChatServiceTell }, // a service send a chat message to a specific client in the channel without sender id
2164 { "DYN_CHAT:SET_HIDE_BUBBLE", cbDynChatSetHideBubble }, // a service send a chat message to a specific client in the channel without sender id
2165 { "DYN_CHAT:SET_UNIVERSAL_CHANNEL", cbDynChatSetUniversalChannel },
2166 //received from DSS
2167 { "REQUEST_DSR", cbRequestDsr},
2168 // { "ADD_DM", cbAddDM }, // A character enter a ring session that he own
2169 // { "REMOVE_DM", cbRemoveDM } // A character leave a DSS
2173 //-------------------------------------------------------------------------
2174 // singleton initialisation and release
2176 void CMessages::init()
2178 // setup the callback array
2179 CUnifiedNetwork::getInstance()->addCallbackArray( CbIOSArray, sizeof(CbIOSArray)/sizeof(CbIOSArray[0]) );
2182 void CMessages::release()