Add infos into target window
[ryzomcore.git] / ryzom / server / src / entities_game_service / admin.h
blob4e2141dd5c3b70b243e4afd54dac569e1625b42b
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/>.
19 #ifndef RY_ADMIN_H
20 #define RY_ADMIN_H
23 // Includes
26 #include <string>
27 #include <vector>
29 #include "server_share/log_character_gen.h"
31 struct CAdminCommand
33 std::string Name;
34 bool AddEId;
35 std::string Priv;
36 std::string ForwardToservice;
37 bool Audit;
41 // Functions
44 void initAdmin ();
45 void initCommandsPrivileges(const std::string & fileName);
46 void initPositionFlags(const std::string & fileName);
47 void getUCstringFromHash(const std::string & hash, ucstring & finaltext);
48 std::string getStringFromHash(const std::string &hash);
49 bool getAIInstanceFromGroupName(std::string& groupName, uint32& instanceNumber);
51 CAdminCommand * findAdminCommand(const std::string & name);
53 extern void GET_CHARACTER_Helper(std::string& command, const NLMISC::CEntityId& id, const std::string& adminCommand);
55 #define GET_ENTITY \
56 if (args.size() < 1) { nlwarning ("Missing argument number 0 that should be the eid"); return false; } \
57 CEntityId eid(args[0]); \
58 if (eid == CEntityId::Unknown) \
59 return true; \
60 TLogContext_Character_AdminCommand commandContext(eid); \
61 CEntityBase *e = CEntityBaseManager::getEntityBasePtr(eid); \
62 if(e == 0) \
63 { \
64 nlwarning ("Unknown entity '%s'", eid.toString().c_str()); \
65 return true; \
66 } \
67 if(!TheDataset.isAccessible(e->getEntityRowId())) \
68 { \
69 nlwarning ("'%s' is not valid in mirror", eid.toString().c_str()); \
70 return true; \
73 #define GET_CHARACTER \
74 if (args.size() < 1) { nlwarning ("Missing argument number 0 that should be the eid"); return false; } \
75 CEntityId eid(args[0]); \
76 if (eid == CEntityId::Unknown) \
77 return true; \
78 TLogContext_Character_AdminCommand commandContext(eid); \
79 CCharacter *c = PlayerManager.getChar(eid); \
80 if(c == 0) \
81 { \
82 log.displayNL ("Unknown player '%s' (%s)", eid.toString().c_str(), args[0].c_str()); \
83 goto offline; \
84 } \
85 if(!c->getEnterFlag()) \
86 { \
87 log.displayNL ("'%s' is not entered", eid.toString().c_str()); \
88 goto offline; \
89 } \
90 if(!TheDataset.isAccessible(c->getEntityRowId())) \
91 { \
92 log.displayNL ("'%s' is not valid in mirror", eid.toString().c_str()); \
93 goto offline; \
94 } \
95 goto end; \
96 offline: \
98 std::string command; \
99 std::string adminCommand; \
100 adminCommand = getName(); \
101 for( uint i = 0; i < args.size(); i++ ) \
103 adminCommand += string(" \"") + args[i] + string("\""); \
105 GET_CHARACTER_Helper( command, eid, adminCommand ); \
106 return true; \
108 end:
110 #define GET_ACTIVE_CHARACTER \
111 if (args.size() < 1) { nlwarning ("ERR: Missing argument number 0 that should be the uid"); return false; } \
112 uint32 uid; \
113 NLMISC::fromString(args[0], uid); \
114 CCharacter *c = CPlayerManager::getInstance().getActiveChar(uid); \
115 if(c == 0) \
117 log.displayNL ("ERR: Unknown player '%u' (%s)", uid, args[0].c_str()); \
118 return false; \
120 CEntityId eid = c->getId(); \
121 TLogContext_Character_AdminCommand commandContext(eid); \
122 if(!c->getEnterFlag()) \
124 log.displayNL ("ERR: '%s' is not entered", eid.toString().c_str()); \
125 return false; \
127 if(!TheDataset.isAccessible(c->getEntityRowId())) \
129 log.displayNL ("ERR: '%s' is not valid in mirror", eid.toString().c_str()); \
130 return false; \
133 #define GET_ACTIVE_CHARACTER2 \
134 if (args.size() < 1) { nlwarning ("ERR: Missing argument number 0 that should be the uid"); return false; } \
135 uint32 uid; \
136 NLMISC::fromString(args[0], uid); \
137 c = CPlayerManager::getInstance().getActiveChar(uid); \
138 if(c == 0) \
140 log.displayNL ("ERR: Unknown player '%u' (%s)", uid, args[0].c_str()); \
141 return false; \
143 CEntityId eid = c->getId(); \
144 TLogContext_Character_AdminCommand commandContext(eid); \
145 if(!c->getEnterFlag()) \
147 log.displayNL ("ERR: '%s' is not entered", eid.toString().c_str()); \
148 return false; \
150 if(!TheDataset.isAccessible(c->getEntityRowId())) \
152 log.displayNL ("ERR: '%s' is not valid in mirror", eid.toString().c_str()); \
153 return false; \
156 //#define GET_CHARACTER1 \
157 // if (args.size() < 2) { nlwarning ("Missing argument number 1 that should be the eid"); return false; } \
158 // CEntityId eid = CEntityIdTranslator::getInstance()->getByEntity(args[1]); \
159 // if (eid == CEntityId::Unknown) \
160 // return true; \
161 // CCharacter *c = PlayerManager.getChar(eid); \
162 // if(c == 0) \
163 //{ \
164 // log.displayNL ("Unknown player '%s' (%s)", eid.toString().c_str(), args[0].c_str()); \
165 // goto offline2; \
166 //} \
167 // if(!c->getEnterFlag()) \
168 //{ \
169 // log.displayNL ("'%s' is not entered", eid.toString().c_str()); \
170 // goto offline2; \
171 //} \
172 // if(!TheDataset.isAccessible(c->getEntityRowId())) \
173 //{ \
174 // log.displayNL ("'%s' is not valid in mirror", eid.toString().c_str()); \
175 // goto offline2; \
176 //} \
177 // goto end2; \
178 //offline2: \
179 //{\
180 // std::string command; \
181 // std::string adminCommand; \
182 // adminCommand = getName(); \
183 // for( uint i = 0; i < args.size(); i++ ) \
184 //{ \
185 // adminCommand += string(" \"") + args[i] + string("\""); \
186 //} \
187 // GET_CHARACTER_Helper( command, eid, adminCommand ); \
188 // return true; \
189 //} \
190 //end2:
192 #endif // RY_ADMIN_H
194 /* End of admin.h */