2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //include_once('../config.php');
22 // This function connect to the LAS
24 function connectToLAS($LASHost, &$fp, &$res)
28 // connect to the login service
29 $fp = fsockopen ($LASHost, $LASPort, $errno, $errstr, 30);
32 $res = "Can't connect to the log analyser service '$LASHost:$LASPort' ($errno: $errstr) (error code 1)";
42 function disconnectFromLAS(&$fp)
47 function logQuery($LASHost, $query, &$result, &$queryId)
49 if (!connectToLAS($LASHost, $fp, $result))
51 $result = "Failed to connect to LAS $LASHost (ec 1)";
55 // send the message that say that we want to add a user
56 $msgout = new CMemStream
;
59 $msgout->serialuint32 ($fake); // fake used to number the packet
62 $msgout->serialuint8 ($messageType);
64 $msgout->serialstring($query);
66 if (!sendMessage ($fp, $msgout))
68 $result = "Failed to send query to LAS $LASHost (ec 2)";
72 if (!waitMessage ($fp, $msgin))
74 $result = "Failed to wait for LAS $LASHost (ec 3)";
79 if (!$msgin->serialstring($result))
81 $result = "Failed to decode LAS message $LASHost (ec 4)";
87 $pos = strpos($result, ':');
90 $result = "Failed to decode LAS message $LASHost (ec 5)";
94 $success = (substr($result, 0, $pos) == '1');
96 $result = substr($result, $pos+
1);
100 $pos = strpos($result, ':');
103 $result = "Failed to decode LAS message $LASHost (ec 6)";
107 $queryId = substr($result, 0, $pos);
108 $result = substr($result, $pos+
1);
114 function getQueryResult($LASHost, $id, &$result, &$page, &$numpages)
116 if (!connectToLAS($LASHost, $fp, $result))
118 $result = "Failed to connect to LAS $LASHost (ec 7)";
122 // send the message that say that we want to add a user
123 $msgout = new CMemStream
;
126 $msgout->serialuint32 ($fake); // fake used to number the packet
129 $msgout->serialuint8 ($messageType);
131 $str = $id.":".$page;
132 $msgout->serialstring($str);
134 if (!sendMessage ($fp, $msgout))
136 $result = "Failed to send query to LAS $LASHost (ec 8)";
140 if (!waitMessage ($fp, $msgin))
142 $result = "Failed to wait for LAS $LASHost (ec 9)";
147 if (!$msgin->serialstring($result))
149 $result = "Failed to decode LAS message $LASHost (ec 10)";
155 $pos = strpos($result, ':');
158 $result = "Failed to decode LAS message $LASHost (ec 11)";
162 $success = (substr($result, 0, $pos) == '1');
167 $npos = strpos($result, ':', $pos);
168 $numpages = substr($result, $pos, $npos-$pos);
170 $pos = strpos($result, ':', $npos);
171 $page = substr($result, $npos, $pos-$npos);
173 $result = substr($result, $pos+
1);
177 $result = substr($result, $pos+
1);
183 function displayLASQueries($LASHost, &$result)
185 if (!connectToLAS($LASHost, $fp, $result))
187 $result = "Failed to connect to LAS $LASHost (ec 12)";
191 // send the message that say that we want to add a user
192 $msgout = new CMemStream
;
195 $msgout->serialuint32 ($fake); // fake used to number the packet
198 $msgout->serialuint8 ($messageType);
200 if (!sendMessage ($fp, $msgout))
202 $result = "Failed to send query to LAS $LASHost (ec 13)";
206 if (!waitMessage ($fp, $msgin))
208 $result = "Failed to wait for LAS $LASHost (ec 14)";
213 if (!$msgin->serialstring($result))
215 $result = "Failed to decode LAS message $LASHost (ec 15)";
221 $pos = strpos($result, ':');
224 $result = "Failed to decode LAS message $LASHost (ec 16)";
228 $success = (substr($result, 0, $pos) == '1');
233 $npos = strpos($result, "\n", $pos);
234 $result = substr($result, $npos);
238 $result = substr($result, $pos+
1);