Add infos into target window
[ryzomcore.git] / ryzom / server / src / ai_data_service / commands.cpp
blob0521c4ddec0cf4f814308246798676f3365d16a0
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/>.
20 // Nel Misc
21 #include "nel/net/service.h"
22 #include "nel/misc/command.h"
24 // Game share
25 #include "game_share/macro_manager.h"
27 // locals
28 #include "ai_files.h"
29 #include "ai_manager.h"
30 #include "ai_service.h"
32 using namespace NLMISC;
33 using namespace NLNET;
34 using namespace std;
37 //-------------------------------------------------------------------------
38 // utility routines
40 static void argsToManagerVector(const vector<string> &args, vector<CAIManager *> &theManagers)
42 if(args.size()==0)
44 for (uint i=0;i<CAIManager::numManagers();++i)
45 theManagers.push_back(CAIManager::getManagerByIdx(i));
47 else
49 for (uint i=0;i<args.size();++i)
51 int id=CAIManager::nameToId(args[i]);
52 if (i==-1)
53 nlwarning("Can't find a manger record for: %s",args[i].c_str());
54 else
55 theManagers.push_back(CAIManager::getManagerById(id));
60 //-------------------------------------------------------------------------
61 // scanning the hard disk for interesting files, compiling
62 // where nessessary and allerting ai_service(s) of data file changes
64 NLMISC_COMMAND(aiRescanDirectories,"Rescan disk file directories","")
66 if(args.size()!=0) return false;
67 COMMAND_MACRO_RECORD_TEST
69 CAIFiles::scan();
71 return true;
74 NLMISC_COMMAND(aiMake,"scan the hard disk for interesting files, recompile as necessary and allert services","")
76 COMMAND_MACRO_RECORD_TEST
78 // rescan the source and object directories for files
79 CAIFiles::scan();
81 // build the list of ai managers to act on
82 vector<CAIManager *> theManagers;
83 argsToManagerVector(args,theManagers);
85 // do the work
86 for (uint i=0;i<theManagers.size();++i)
88 if (theManagers[i]->needCompile())
90 //nlinfo("Compiling manager: %04d: %s",theManagers[i]->id(),theManagers[i]->name());
91 theManagers[i]->compile();
93 else
94 nlinfo("Manager is up to date: %04d: %s",theManagers[i]->id(),theManagers[i]->name().c_str());
97 return true;
100 NLMISC_COMMAND(aiClean,"delete all generated files on the hard disk (next 'make' will rebuild everything)","")
102 COMMAND_MACRO_RECORD_TEST
104 // rescan the source and object directories for files
105 CAIFiles::scan();
107 // build the list of ai managers to act on
108 vector<CAIManager *> theManagers;
109 argsToManagerVector(args,theManagers);
111 // do the work
112 for (uint i=0;i<theManagers.size();++i)
114 nlinfo("Cleaning: %04d: %s",theManagers[i]->id(),theManagers[i]->name().c_str());
115 theManagers[i]->clean();
118 return true;
121 //-------------------------------------------------------------------------
123 NLMISC_COMMAND(aiDisplayServices,"list the ai services, their parameters and their lists of running managers","[<service id>[...]]")
125 if(args.size()!=0) return false;
126 COMMAND_MACRO_RECORD_TEST
128 return true;
131 NLMISC_COMMAND(aiDisplayManagers,"Display the known ai manager list","[<manager name|id>[...]]")
133 COMMAND_MACRO_RECORD_TEST
135 // build the list of ai managers to act on
136 vector<CAIManager *> theManagers;
137 argsToManagerVector(args,theManagers);
139 // do the work
140 for (uint i=0;i<theManagers.size();++i)
141 theManagers[i]->display();
143 return true;
146 //-------------------------------------------------------------------------
147 NLMISC_COMMAND(aiOpenAllManagers,"Open all managers and automatically assign to ai services","")
149 if(args.size()!=0) return false;
150 COMMAND_MACRO_RECORD_TEST
152 for (uint i=0;i<CAIManager::numManagers();++i)
153 if (!CAIManager::getManagerByIdx(i)->isOpen())
154 CAIManager::getManagerByIdx(i)->open();
156 return true;
159 NLMISC_COMMAND(aiOpenManagers,"Open managers and automatically assign to ai services","<manager name|id>[...]")
161 if(args.size()<1) return false;
162 COMMAND_MACRO_RECORD_TEST
164 for (uint i=0;i<args.size();++i)
166 int id=CAIManager::nameToId(args[i]);
167 if (i==-1)
168 nlwarning("Can't find a manger record for: %s",args[i].c_str());
169 else
170 CAIManager::getManagerById(id)->open();
173 return true;
176 NLMISC_COMMAND(aiAssignManagers,"Open managers and assign to specified ai service","<service><manager name|id>[...]")
178 if(args.size()<2) return false;
179 COMMAND_MACRO_RECORD_TEST
181 // convert args[0] to service id and verify existance in services list
182 NLNET::TServiceId service(atoi(args[0].c_str()));
183 if (service.get()==0 && args[0]!="0")
185 nlwarning("Invalid service id: %s",args[0].c_str());
186 return false;
189 // iterate through args assigning managers to service
190 for (uint i=1;i<args.size();++i)
192 int id=CAIManager::nameToId(args[i]);
193 if (i==-1)
194 nlwarning("Can't find a manger record for: %s",args[i].c_str());
195 else
196 CAIManager::getManagerById(id)->assign(service);
199 return true;
202 NLMISC_COMMAND(aiReassignManagers,"Save & close managers on existing services and open on specified ai service","<service><manager name|id>[...]")
204 if(args.size()<2) return false;
205 COMMAND_MACRO_RECORD_TEST
207 // convert args[0] to service id and verify existance in services list
208 NLNET::TServiceId service(atoi(args[0].c_str()));
209 if (service.get()==0 && args[0]!="0")
211 nlwarning("Invalid service id: %s",args[0].c_str());
212 return false;
215 // iterate through args reassigning managers to service
216 for (uint i=1;i<args.size();++i)
218 int id=CAIManager::nameToId(args[i]);
219 if (i==-1)
220 nlwarning("Can't find a manger record for: %s",args[i].c_str());
221 else
222 CAIManager::getManagerById(id)->reassign(service);
225 return true;
228 //-------------------------------------------------------------------------
229 NLMISC_COMMAND(aiCloseAllManagers,"Close all managers across all ai services on the shard","")
231 if(args.size()!=0) return false;
232 COMMAND_MACRO_RECORD_TEST
234 for (uint i=0;i<CAIManager::numManagers();++i)
235 if (CAIManager::getManagerByIdx(i)->isOpen())
236 CAIManager::getManagerByIdx(i)->close();
238 return true;
241 NLMISC_COMMAND(aiCloseManagers,"Close listed managers","<manager name|id>[...]")
243 if(args.size()<1) return false;
244 COMMAND_MACRO_RECORD_TEST
246 for (uint i=0;i<args.size();++i)
248 int id=CAIManager::nameToId(args[i]);
249 if (i==-1)
250 nlwarning("Can't find a manger record for: %s",args[i].c_str());
251 else
252 CAIManager::getManagerById(id)->close();
255 return true;
258 //-------------------------------------------------------------------------