Merge branch 'ryzom/rites' into main/gingo-test
[ryzomcore.git] / ryzom / server / www / libs / admin_modules_itf.php
blob9399fffb5b08abda9168bc7b5ecc4c3261bfb42d
1 <?php
3 include_once('nel_message.php');
5 /////////////////////////////////////////////////////////////////
6 // WARNING : this is a generated file, don't change it !
7 /////////////////////////////////////////////////////////////////
9 class CAdminServiceWeb extends CCallbackClient
12 function globalCmd($command)
14 $msg = new CMessage;
15 $msg->setName("GCMD");
18 $msg->serialString($command);
20 return parent::sendMessage($msg);
25 function controlCmd($serviceAlias, $command)
27 $msg = new CMessage;
28 $msg->setName("CCMD");
31 $msg->serialString($serviceAlias);
32 $msg->serialString($command);
34 return parent::sendMessage($msg);
39 function serviceCmd($serviceAlias, $command)
41 $msg = new CMessage;
42 $msg->setName("SCMD");
45 $msg->serialString($serviceAlias);
46 $msg->serialString($command);
48 return parent::sendMessage($msg);
53 function getShardOrders()
55 $msg = new CMessage;
56 $msg->setName("GSO");
60 $ret = "";
61 $ret = parent::sendMessage($msg);
62 if ($ret == false)
64 // error during send
65 $this->invokeError("getShardOrders", "Error in 'sendMessage'");
66 return false;
69 $retMsg = parent::waitMessage();
70 if ($ret == false)
72 // error during send
73 $this->invokeError("getShardOrders", "Error in 'waitMessage'");
74 return false;
76 if (!($retMsg->MsgName === "R_GSO"))
78 // error during send
79 $this->invokeError("getShardOrders", "Invalid response, awaited 'R_GSO', received '".$retMsg->MsgName."'");
80 return false;
83 // serial the return value
84 $nbElem = 0;
85 $retMsg->serialUInt32($nbElem);
86 $retValue = array();
87 for ($i=0; $i<$nbElem;$i++)
89 $retMsg->serialString($item);
90 $retValue[] = $item;
94 // return the return value
95 return $retValue;
100 function getStates()
102 $msg = new CMessage;
103 $msg->setName("GS");
105 echo "ok";
107 $ret = "";
108 $ret = parent::sendMessage($msg);
109 if ($ret == false)
111 // error during send
112 $this->invokeError("getStates", "Error in 'sendMessage'");
113 return false;
115 echo "ok";
116 $retMsg = parent::waitMessage();
117 if ($ret == false)
119 // error during send
120 $this->invokeError("getStates", "Error in 'waitMessage'");
121 return false;
123 echo "ok";
124 if (!($retMsg->MsgName === "R_GS"))
126 // error during send
127 $this->invokeError("getStates", "Invalid response, awaited 'R_GS', received '".$retMsg->MsgName."'");
128 return false;
130 echo "ok\n";
131 // serial the return value
132 $nbElem = 0;
133 $retMsg->serialUInt32($nbElem);
134 $retValue = array();
135 echo $nbElem."\n";
136 for ($i=0; $i<$nbElem;$i++)
138 $retMsg->serialString($item);
139 $retValue[] = $item;
143 // return the return value
144 return $retValue;
149 function getHighRezGraph($varAddr, $startDate, $endDate, $milliStep)
151 $msg = new CMessage;
152 $msg->setName("GHRG");
155 $msg->serialString($varAddr);
156 $msg->serialUint32($startDate);
157 $msg->serialUint32($endDate);
158 $msg->serialUint32($milliStep);
160 $ret = "";
161 $ret = parent::sendMessage($msg);
162 if ($ret == false)
164 // error during send
165 $this->invokeError("getHighRezGraph", "Error in 'sendMessage'");
166 return false;
169 $retMsg = parent::waitMessage();
170 if ($ret == false)
172 // error during send
173 $this->invokeError("getHighRezGraph", "Error in 'waitMessage'");
174 return false;
176 if (!($retMsg->MsgName === "R_GHRG"))
178 // error during send
179 $this->invokeError("getHighRezGraph", "Invalid response, awaited 'R_GHRG', received '".$retMsg->MsgName."'");
180 return false;
183 // serial the return value
184 $nbElem = 0;
185 $retMsg->serialUInt32($nbElem);
186 $retValue = array();
187 for ($i=0; $i<$nbElem;$i++)
189 $retMsg->serialString($item);
190 $retValue[] = $item;
194 // return the return value
195 return $retValue;
201 function waitCallback()
203 $message = parent::waitMessage();
205 if ($message == false)
206 return false;
208 switch($message->MsgName)
210 case "CMDR":
211 $this->commandResult_skel($message);
212 break;
213 default:
214 return false;
217 return true;
221 function commandResult_skel(&$message)
223 $message->serialString($serviceAlias);
224 $message->serialString($result);
226 $this->commandResult($serviceAlias, $result);
230 /////////////////////////////////////////////////////////////////
231 // Copy paste this part of code in your derived class
232 // and implement code to ract to incoming message
233 /////////////////////////////////////////////////////////////////
235 function commandResult($serviceAlias, $result)
241 class MyAdminService extends CAdminServiceWeb
243 function commandResult($serviceModuleName, $result)
245 global $command_return_data;
247 $command_return_data = trim("===[ Service ". strtoupper($serviceModuleName) ." returned ]===\n". trim($result) ."\n\n");
252 function parseDumpGuildList($data)
254 $server = '';
255 $result = array();
257 reset($data);
258 foreach($data as $server_data)
260 $data_ary = explode("\n",$server_data);
261 reset($data_ary);
262 foreach($data_ary as $rline)
264 $rline = trim($rline);
266 if (preg_match('/^===\[ Service ([^\ ]+) returned \]===/', $rline, $params))
268 $server = $params[1];
269 $result[$server] = array();
270 $result[$server]['name'] = array();
271 $result[$server]['dump'] = array();
273 elseif (preg_match("/^id = ([[:digit:]]+)\:([[:digit:]]+) \(([^\ ]+)\) (\(0x[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\)), name = '([^\']+)', ([[:digit:]]+) members/",$rline,$params))
275 // id = 101:1 (Local) (0x0006500001:0c:00:88), name = 'Les Gardiens de l Atrium', 21 members
276 if ($server != '')
278 $result[$server]['dump'][] = $params;
279 $result[$server]['name'][] = $params[5];
286 return $result;
290 function parseDumpOutpostList($data)
292 $server = '';
293 $result = array();
295 reset($data);
296 foreach($data as $server_data)
298 $data_ary = explode("\n",$server_data);
299 reset($data_ary);
300 foreach($data_ary as $rline)
302 $rline = trim($rline);
304 if (preg_match("/^([[:digit:]]+)\: Alias\: \((A\:[[:digit:]]+\:[[:digit:]]+)\), Name\: '([^\']+)', Sheet\: '([^\']+)', State\: '([^\']+)', Level\: ([[:digit:]]+), Owner\: '([^\']+)'/",$rline,$params))
306 $result[$params[3]] = $params;
312 return $result;
317 function parseDisplayPlayers($data)
319 $server = '';
320 $result = array();
322 reset($data);
323 $data = str_replace('\\\'', '', $data);
325 foreach($data as $server_data)
327 $data_ary = explode("\n",$server_data);
328 reset($data_ary);
329 foreach($data_ary as $rline)
331 $rline = trim($rline);
333 if (preg_match('/^Player: ([[:digit:]]+) Name: ([^ ]+) ID: (\(0x[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\)) FE: [[:digit:]]+ Sheet: [a-z]+\.race_stats - [[:digit:]]+ Priv: ([^ ]+) Pos: ([0-9]+),(-[0-9]+),([0-9\-]+) Session: [0-9]01/',$rline,$params))
335 // Player: 723931 Name: Deodand(Atys) ID: (0x0000b0bdb0:00:00:8b) FE: 139 Sheet: tryker.race_stats - 533 Priv: \&#039;\&#039; Pos: 15264,-34428,-3 Session: 101
336 $result[$params[1]] = $params;
342 return $result;
346 function parseDumpGuild($data)
348 $server = '';
349 $result = array();
351 reset($data);
352 foreach($data as $server_data)
354 $data_ary = explode("\n",$server_data);
356 reset($data_ary);
357 foreach($data_ary as $rline)
359 if (preg_match('/^===\[ Service ([^\ ]+) returned \]===/',$rline,$params))
361 $server = $params[1];
362 $result[$server] = array();
364 // <GUILD_DUMP> Guild id: 1, name: 'Les Gardiens de l Atrium', eid: (0x0000000001:0c:00:81)
365 //if (ereg("^[[:space:]]*\<GUILD_DUMP\> Guild id: ([[:digit:]]+), name: \'([[:alnum:]]+)\', eid: (\(0x[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\))$",$rline,$params))
366 elseif (preg_match('/^\<GUILD_DUMP\> Guild id: ([[:digit:]]+)\:([[:digit:]]+) \(([^\ ]+)\), name: \'([A-Za-z0-9\ _-]+)\', eid: (\(0x[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\))/',$rline,$params))
368 $guild_name = $params[4];
369 $result[$server] = array();
370 $result[$server]['dump'] = $params;
372 // Description: 'French CSR'
373 elseif (preg_match('/^[[:space:]]*Description: \'(.*)\'/',$rline,$params))
375 if ($server != '')
377 $result[$server]['desc'] = $params[1];
380 // Icon: 0x0000000000000681
381 elseif (preg_match('/^[[:space:]]*Icon: (0x[[:alnum:]]+)/',$rline,$params))
383 if ($server != '')
385 $result[$server]['icon'] = hexdec($params[1]);
388 // Money: 65500000
389 elseif (preg_match('/^[[:space:]]*Money: ([[:alnum:]]+)/',$rline,$params))
391 if ($server != '')
393 $result[$server]['money'] = $params[1];
396 // Race: Fyros
397 elseif (preg_match('/^[[:space:]]*Race: (.*)/',$rline,$params))
399 if ($server != '')
401 $result[$server]['race'] = $params[1];
404 // Building: building_instance_FY_guild_327
405 elseif (preg_match('/^[[:space:]]*Building: (.*)/',$rline,$params))
407 if ($server != '')
409 $result[$server]['building'] = $params[1];
412 // Civ Allegiance: Fyros
413 elseif (preg_match('/^[[:space:]]*Civ Allegiance: (.*)/',$rline,$params))
415 if ($server != '')
417 $result[$server]['civ'] = $params[1];
420 // Cult Allegiance: Kami
421 elseif (preg_match('/^[[:space:]]*Cult Allegiance: (.*)/',$rline,$params))
423 if ($server != '')
425 $result[$server]['cult'] = $params[1];
428 // Nb of members: 27
429 elseif (preg_match('/^[[:space:]]*Nb of members: ([[:digit:]]+)/',$rline,$params))
431 if ($server != '')
433 $result[$server]['count'] = $params[1];
436 // Member 'Yotto' (0x00000096f0:00:00:86), index: 2, grade: HighOfficer, enter time: 60960905
437 elseif (preg_match('/^[[:space:]]*Member \'([^\ ]+)\' (\(0x[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\:[[:alnum:]]+\)), index: ([[:digit:]]+), grade: ([[:alnum:]]+), enter time: ([[:digit:]]+)/',$rline,$params))
439 if ($server != '')
441 $result[$server][$params[4]][] = $params[1];
446 return $result;
449 function querySelectedShard($name, $service_name, $fullcmd, $cmd='', $waitCallback=true, $is_control=false) {
450 global $command_return_data;
452 $nel_result = array();
453 $nel_status = !$waitCallback;
455 $p_result = null;
457 $adminService = new MyAdminService;
459 if ($adminService->connect($name, '46700', $res) !== false) {
460 $command_return_data = '';
462 //echo "NEL[$service_name] : $service_command\n";
463 if (is_array($fullcmd)) {
464 foreach ($fullcmd as $service_command) {
465 if ($is_control)
466 $adminService->controlCmd($service_name, $service_command);
467 else
468 $adminService->serviceCmd($service_name, $service_command);
470 } else {
471 if ($is_control)
472 $adminService->controlCmd($service_name, $fullcmd);
473 else
474 $adminService->serviceCmd($service_name, $fullcmd);
475 $service_command = $fullcmd;
476 //echo "NEL[$service_name] : OK\n";
477 if ($waitCallback && $adminService->waitCallback()) {
478 //echo "NEL[$service_name] : Successful!\n";
480 $nel_status = true;
481 $nel_result[] = $command_return_data;
482 //print_r($command_return_data);
483 } else {
484 //echo "NEL[$service_name] : Failed!\n";
488 @$adminService->close();
491 if ($nel_status) {
492 if (strlen($cmd) > 0) {
493 $func_name = 'parse'.ucfirst($cmd);
494 if (function_exists($func_name))
495 $p_result = call_user_func($func_name,$nel_result);
499 return array('status' => $nel_status, 'query' => $service_name.':'.$service_command, 'raw' => $nel_result, 'parsed' => $p_result);
502 function queryShard($service_name, $fullcmd, $cmd='', $waitCallback=true, $is_control=false)
504 return querySelectedShard('localhost', $service_name, $fullcmd, $cmd, $waitCallback, $is_control);