Add infos into target window
[ryzomcore.git] / ryzom / server / src / server_share / log_command_gen.cpp
blob855c71ff79b619c93e50f926b2f16004353f25bd
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) 2019 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 "game_share/utils.h"
22 #include "log_command_gen.h"
25 #include "logger_service_itf.h"
26 #include "logger_service_client.h"
28 // A function fo force linking of this code module
29 void forceLink_Command(){}
34 class CCommandDesc
36 friend class CLoggerClient;
38 /// The list of log definition for this log class
39 std::vector<LGS::TLogDefinition> _LogDefs;
41 /// Stack of context variable
43 std::vector<NLMISC::CEntityId> _charId;
46 /// Counter of 'no context' object stacked.
47 uint32 _NoContextCount;
49 public:
50 /// constructor
51 CCommandDesc()
52 : _NoContextCount(0)
54 _LogDefs.resize(4);
57 LGS::TLogDefinition &logDef = _LogDefs[0];
59 logDef.setLogName("Command_ExecCtx");
61 logDef.setContext(true);
67 LGS::TLogDefinition &logDef = _LogDefs[1];
71 logDef.setLogName("Command_Exec");
72 logDef.setLogText("A character execute an admin command");
74 logDef.getParams().resize(3);
75 logDef.getListParams().resize(0);
78 logDef.getParams()[0].setName("charId");
79 logDef.getParams()[0].setType(LGS::TSupportedParamType::spt_entityId);
81 logDef.getParams()[1].setName("cmdName");
82 logDef.getParams()[1].setType(LGS::TSupportedParamType::spt_string);
83 logDef.getParams()[1].setList(false);
85 logDef.getParams()[2].setName("cmdArg");
86 logDef.getParams()[2].setType(LGS::TSupportedParamType::spt_string);
87 logDef.getParams()[2].setList(false);
92 LGS::TLogDefinition &logDef = _LogDefs[2];
96 logDef.setLogName("Command_ExecOnTarget");
97 logDef.setLogText("A character execute an admin command on its target");
99 logDef.getParams().resize(4);
100 logDef.getListParams().resize(0);
103 logDef.getParams()[0].setName("charId");
104 logDef.getParams()[0].setType(LGS::TSupportedParamType::spt_entityId);
106 logDef.getParams()[1].setName("targetId");
107 logDef.getParams()[1].setType(LGS::TSupportedParamType::spt_entityId);
108 logDef.getParams()[1].setList(false);
110 logDef.getParams()[2].setName("cmdName");
111 logDef.getParams()[2].setType(LGS::TSupportedParamType::spt_string);
112 logDef.getParams()[2].setList(false);
114 logDef.getParams()[3].setName("cmdArg");
115 logDef.getParams()[3].setType(LGS::TSupportedParamType::spt_string);
116 logDef.getParams()[3].setList(false);
121 LGS::TLogDefinition &logDef = _LogDefs[3];
125 logDef.setLogName("Command_TPOutsideNewbieland");
126 logDef.setLogText("A CSR has tp'ed a player outside of the newbieland");
128 logDef.getParams().resize(1);
129 logDef.getListParams().resize(0);
132 logDef.getParams()[0].setName("movedCharId");
133 logDef.getParams()[0].setType(LGS::TSupportedParamType::spt_entityId);
134 logDef.getParams()[0].setList(false);
139 // Register the log definitions
140 LGS::ILoggerServiceClient::addLogDefinitions(_LogDefs);
143 // Context var stack accessor
145 bool getContextVar_charId (NLMISC::CEntityId &value)
147 if (_charId.empty())
148 return false;
150 value = _charId.back();
151 return true;
154 void pushContextVar_charId (const NLMISC::CEntityId &value)
156 _charId.push_back(value);
158 void popContextVar_charId ()
160 _charId.pop_back();
164 void pushNoContext()
166 ++_NoContextCount;
168 void popNoContext()
170 nlassert(_NoContextCount > 0);
171 --_NoContextCount;
174 uint32 getNoContextCount()
176 return _NoContextCount;
180 // Instantiate the descriptor class
181 CCommandDesc CommandDesc;
185 const std::string TLogContext_Command_ExecCtx::_ContextName("Command_ExecCtx");
186 /// The constructor push a log context in the logger system
187 TLogContext_Command_ExecCtx::TLogContext_Command_ExecCtx(const NLMISC::CEntityId &charId)
189 if (LGS::ILoggerServiceClient::isInitialized())
190 LGS::ILoggerServiceClient::getInstance()->pushLogContext(_ContextName);
192 // stack the context param in the context class object
193 CommandDesc.pushContextVar_charId(charId);
197 /// The destructor pop a context in the logger system
198 TLogContext_Command_ExecCtx::~TLogContext_Command_ExecCtx()
200 if (LGS::ILoggerServiceClient::isInitialized())
201 LGS::ILoggerServiceClient::getInstance()->popLogContext(_ContextName);
203 // pop the context param in the context class object
204 CommandDesc.popContextVar_charId();
209 /// No context context. Use this to disable any contextual log underneath
210 TLogNoContext_Command::TLogNoContext_Command()
212 CommandDesc.pushNoContext();
215 TLogNoContext_Command::~TLogNoContext_Command()
217 CommandDesc.popNoContext();
222 void _log_Command_Exec(const std::string &cmdName, const std::string &cmdArg, const char *_filename_, uint _lineNo_)
224 static LGS::TLogInfo logInfo;
225 static bool init = false;
226 if (!init)
228 logInfo.setLogName("Command_Exec");
229 logInfo.getParams().resize(3);
230 logInfo.getListParams().resize(0);
234 // Context parameter
235 NLMISC::CEntityId charId;
236 if (!CommandDesc.getContextVar_charId(charId))
238 // If this bomb is thrown, you need to add a log context (or otherwise a 'noContext').
239 STOP_IF(CommandDesc.getNoContextCount() == 0, _filename_<<"("<<_lineNo_<<") : Missing log context for log 'Command'");
240 return;
244 logInfo.getParams()[0] = LGS::TParamValue(charId);
246 logInfo.getParams()[1] = LGS::TParamValue(cmdName);
248 logInfo.getParams()[2] = LGS::TParamValue(cmdArg);
251 logInfo.setTimeStamp(NLMISC::CTime::getSecondsSince1970());
253 if (LGS::ILoggerServiceClient::isInitialized())
254 LGS::ILoggerServiceClient::getInstance()->sendLog(logInfo);
257 void _log_Command_ExecOnTarget(const NLMISC::CEntityId &targetId, const std::string &cmdName, const std::string &cmdArg, const char *_filename_, uint _lineNo_)
259 static LGS::TLogInfo logInfo;
260 static bool init = false;
261 if (!init)
263 logInfo.setLogName("Command_ExecOnTarget");
264 logInfo.getParams().resize(4);
265 logInfo.getListParams().resize(0);
269 // Context parameter
270 NLMISC::CEntityId charId;
271 if (!CommandDesc.getContextVar_charId(charId))
273 // If this bomb is thrown, you need to add a log context (or otherwise a 'noContext').
274 STOP_IF(CommandDesc.getNoContextCount() == 0, _filename_<<"("<<_lineNo_<<") : Missing log context for log 'Command'");
275 return;
279 logInfo.getParams()[0] = LGS::TParamValue(charId);
281 logInfo.getParams()[1] = LGS::TParamValue(targetId);
283 logInfo.getParams()[2] = LGS::TParamValue(cmdName);
285 logInfo.getParams()[3] = LGS::TParamValue(cmdArg);
288 logInfo.setTimeStamp(NLMISC::CTime::getSecondsSince1970());
290 if (LGS::ILoggerServiceClient::isInitialized())
291 LGS::ILoggerServiceClient::getInstance()->sendLog(logInfo);
294 void _log_Command_TPOutsideNewbieland(const NLMISC::CEntityId &movedCharId, const char *_filename_, uint _lineNo_)
296 static LGS::TLogInfo logInfo;
297 static bool init = false;
298 if (!init)
300 logInfo.setLogName("Command_TPOutsideNewbieland");
301 logInfo.getParams().resize(1);
302 logInfo.getListParams().resize(0);
306 logInfo.getParams()[0] = LGS::TParamValue(movedCharId);
309 logInfo.setTimeStamp(NLMISC::CTime::getSecondsSince1970());
311 if (LGS::ILoggerServiceClient::isInitialized())
312 LGS::ILoggerServiceClient::getInstance()->sendLog(logInfo);