Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / common / src / game_share / send_chat.cpp
blob40af570ec427c5661cb88ad3db29ac93bc7463f6
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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/>.
20 #include "stdpch.h"
21 #include "send_chat.h"
23 /**
24 * Send a chat line from system to a player that will be displayed as a normal chat sentence
25 * Sentence will be formated using "<ServiceName:ServiceId>" as prefix of chat string
27 void chatToPlayer(const NLMISC::CEntityId &id, const std::string &chatString)
29 NLNET::CMessage msgout("CHAT");
30 bool talkToPlayer = true;
31 msgout.serial(talkToPlayer, const_cast<NLMISC::CEntityId&>(id), const_cast<std::string&>(chatString));
32 sendMessageViaMirror("IOS", msgout);
35 /**
36 * Send a chat line from system to a group of player that will be displayed as a normal chat sentence
37 * Sentence will be formated using "<ServiceName:ServiceId>" as prefix of chat string
39 void chatToGroup(const NLMISC::CEntityId &id, const std::string &chatString)
41 NLNET::CMessage msgout("CHAT");
42 bool talkToPlayer = false;
43 msgout.serial(talkToPlayer, const_cast<NLMISC::CEntityId&>(id), const_cast<std::string&>(chatString));
44 sendMessageViaMirror("IOS", msgout);
47 /**
48 * Send a chat line from a bot (mainly NPC) in a chat channel (know as chat group).
49 * Chat group can be constructed from CChatGroup class.
50 * phraseId is a phrase identifier in the phrase translation file.
51 * param are the parameter of the phrase
53 void npcChatParamToChannel(const TDataSetRow &senderId, CChatGroup::TGroupType groupType, const std::string &phraseId, const std::vector<STRING_MANAGER::TParam> &params)
55 NLNET::CMessage msgout("NPC_CHAT_PARAM");
56 msgout.serial(const_cast<TDataSetRow&>(senderId));
57 msgout.serialEnum(groupType);
58 msgout.serial(const_cast<std::string&>(phraseId));
60 uint32 size = (uint32)params.size();
61 msgout.serial(size);
62 // params.resize(size);
63 for ( uint i = 0; i < size; i++ )
65 uint8 type8 = params[i].Type;
66 msgout.serial( type8 );
67 const_cast<STRING_MANAGER::TParam&>(params[i]).serialParam( false, msgout, (STRING_MANAGER::TParamType) type8 );
70 sendMessageViaMirror("IOS", msgout);
73 /**
74 * Send a chat line from a bot (mainly NPC) in a chat channel (know as chat group).
75 * Chat group can be constructed from CChatGroup class.
76 * phraseId is a phrase identifier in the phrase translation file.
78 void npcChatToChannel(const TDataSetRow &senderId, CChatGroup::TGroupType groupType, const std::string &phraseId)
80 NLNET::CMessage msgout("NPC_CHAT");
81 msgout.serial(const_cast<TDataSetRow&>(senderId));
82 msgout.serialEnum(groupType);
83 msgout.serial(const_cast<std::string&>(phraseId));
84 sendMessageViaMirror("IOS", msgout);
87 /**
88 * Send a chat line from a bot (mainly NPC) in a chat channel (know as chat group).
89 * Chat group can be constructed from CChatGroup class.
90 * phraseId is a phrase identifier in the phrase translation file.
92 void npcChatToChannelEx(const TDataSetRow &senderId, CChatGroup::TGroupType groupType, uint32 phraseId)
94 NLNET::CMessage msgout("NPC_CHAT_EX");
95 msgout.serial(const_cast<TDataSetRow&>(senderId));
96 msgout.serialEnum(groupType);
97 msgout.serial(phraseId);
98 sendMessageViaMirror("IOS", msgout);
102 * Send a chat line from a bot (mainly NPC) in a chat channel (know as chat group).
103 * Chat group can be constructed from CChatGroup class.
104 * sentence is the sentence to be sent.
106 void npcChatToChannelSentence(const TDataSetRow &senderId, CChatGroup::TGroupType groupType, ucstring& sentence)
108 NLNET::CMessage msgout("NPC_CHAT_SENTENCE");
109 msgout.serial(const_cast<TDataSetRow&>(senderId));
110 msgout.serialEnum(groupType);
111 msgout.serial(sentence);
112 sendMessageViaMirror("IOS", msgout);
116 * Request to the DSS to send a chat line from a bot in a chat channel
117 * Chat group can be constructed from CChatGroup class.
118 * sentenceId is the id of the sentence that must be sent by the DSS
120 void forwardToDss(const TDataSetRow &senderId, CChatGroup::TGroupType groupType, std::string& sentenceId,uint32 scenarioId)
122 nlinfo( ("forwarding to DSS : id: "+sentenceId).c_str());
123 NLNET::CMessage msgout("translateAndForward");
124 msgout.serial(const_cast<TDataSetRow&>(senderId));
125 msgout.serialEnum(groupType);
126 msgout.serial(sentenceId);
127 msgout.serial(scenarioId);
128 NLNET::CUnifiedNetwork::getInstance()->send("DSS",msgout);
132 * Request to the DSS to send a chat line from a bot in a chat channel
133 * Chat group can be constructed from CChatGroup class.
134 * sentenceId is the id of the sentence that must be sent by the DSS
136 void forwardToDssArg(const TDataSetRow &senderId, CChatGroup::TGroupType groupType, std::string& sentenceId,uint32 scenarioId,std::vector<float>& argValues)
138 nlinfo( ("forwarding to DSS : id: "+sentenceId).c_str());
139 NLNET::CMessage msgout("translateAndForwardArg");
140 msgout.serial(const_cast<TDataSetRow&>(senderId));
141 msgout.serialEnum(groupType);
142 msgout.serial(sentenceId);
143 msgout.serial(scenarioId);
144 uint32 size=(uint32)argValues.size(),i=0;
145 msgout.serial(size);
146 for(;i<size;++i)
148 msgout.serial(argValues[i]);
150 NLNET::CUnifiedNetwork::getInstance()->send("DSS",msgout);
154 * Send a tell line from a bot (mainly NPC) to a player
155 * phraseId is a phrase identifier in the phrase translation file.
157 void npcTellToPlayer(const TDataSetRow &senderId, const TDataSetRow &receiverId, const std::string &phraseId, bool needSenderNpc)
159 NLNET::CMessage msgout;
160 if ( needSenderNpc )
162 msgout.setType("NPC_TELL");
163 msgout.serial(const_cast<TDataSetRow&>(senderId));
165 else
167 msgout.setType("GHOST_TELL");
169 msgout.serial(const_cast<TDataSetRow&>(receiverId));
170 msgout.serial(const_cast<std::string&>(phraseId));
171 sendMessageViaMirror("IOS", msgout);
175 * Send a tell line from a bot (mainly NPC) to a player. Accept parametered strings
176 * phraseId is a phrase id obtained through the string manager
178 void npcTellToPlayerEx(const TDataSetRow &senderId, const TDataSetRow &receiverId, uint32 phraseId)
180 NLNET::CMessage msgout("NPC_TELL_EX");
181 msgout.serial(const_cast<TDataSetRow&>(senderId));
182 msgout.serial(const_cast<TDataSetRow&>(receiverId));
183 msgout.serial(phraseId);
184 sendMessageViaMirror("IOS", msgout);
187 /* End of send_chat.cpp */