Linux multi-monitor fullscreen support
[ryzomcore.git] / nelns / admin / public_html / las_connection.php
blobcd4d2a0244e6a75ac559f39f7dcc4bcb361ded7d
1 <?php
2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
4 //
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.
9 //
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');
20 // Functions
22 // This function connect to the LAS
23 $LASPort = 49899;
24 function connectToLAS($LASHost, &$fp, &$res)
26 global $LASPort;
28 // connect to the login service
29 $fp = fsockopen ($LASHost, $LASPort, $errno, $errstr, 30);
30 if (!$fp)
32 $res = "Can't connect to the log analyser service '$LASHost:$LASPort' ($errno: $errstr) (error code 1)";
33 return false;
35 else
37 $res = "";
38 return true;
42 function disconnectFromLAS(&$fp)
44 fclose($fp);
47 function logQuery($LASHost, $query, &$result, &$queryId)
49 if (!connectToLAS($LASHost, $fp, $result))
51 $result = "Failed to connect to LAS $LASHost (ec 1)";
52 return false;
55 // send the message that say that we want to add a user
56 $msgout = new CMemStream;
58 $fake = 0;
59 $msgout->serialuint32 ($fake); // fake used to number the packet
61 $messageType = 0;
62 $msgout->serialuint8 ($messageType);
64 $msgout->serialstring($query);
66 if (!sendMessage ($fp, $msgout))
68 $result = "Failed to send query to LAS $LASHost (ec 2)";
69 return false;
72 if (!waitMessage ($fp, $msgin))
74 $result = "Failed to wait for LAS $LASHost (ec 3)";
75 return false;
78 $result = '';
79 if (!$msgin->serialstring($result))
81 $result = "Failed to decode LAS message $LASHost (ec 4)";
82 return false;
85 fclose ($fp);
87 $pos = strpos($result, ':');
88 if ($pos === FALSE)
90 $result = "Failed to decode LAS message $LASHost (ec 5)";
91 return false;
94 $success = (substr($result, 0, $pos) == '1');
96 $result = substr($result, $pos+1);
98 if ($success)
100 $pos = strpos($result, ':');
101 if ($pos == FALSE)
103 $result = "Failed to decode LAS message $LASHost (ec 6)";
104 return false;
107 $queryId = substr($result, 0, $pos);
108 $result = substr($result, $pos+1);
111 return $success;
114 function getQueryResult($LASHost, $id, &$result, &$page, &$numpages)
116 if (!connectToLAS($LASHost, $fp, $result))
118 $result = "Failed to connect to LAS $LASHost (ec 7)";
119 return false;
122 // send the message that say that we want to add a user
123 $msgout = new CMemStream;
125 $fake = 0;
126 $msgout->serialuint32 ($fake); // fake used to number the packet
128 $messageType = 1;
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)";
137 return false;
140 if (!waitMessage ($fp, $msgin))
142 $result = "Failed to wait for LAS $LASHost (ec 9)";
143 return false;
146 $result = '';
147 if (!$msgin->serialstring($result))
149 $result = "Failed to decode LAS message $LASHost (ec 10)";
150 return false;
153 fclose ($fp);
155 $pos = strpos($result, ':');
156 if ($pos === FALSE)
158 $result = "Failed to decode LAS message $LASHost (ec 11)";
159 return false;
162 $success = (substr($result, 0, $pos) == '1');
164 if ($success)
166 ++$pos;
167 $npos = strpos($result, ':', $pos);
168 $numpages = substr($result, $pos, $npos-$pos);
169 ++$npos;
170 $pos = strpos($result, ':', $npos);
171 $page = substr($result, $npos, $pos-$npos);
173 $result = substr($result, $pos+1);
175 else
177 $result = substr($result, $pos+1);
180 return $success;
183 function displayLASQueries($LASHost, &$result)
185 if (!connectToLAS($LASHost, $fp, $result))
187 $result = "Failed to connect to LAS $LASHost (ec 12)";
188 return false;
191 // send the message that say that we want to add a user
192 $msgout = new CMemStream;
194 $fake = 0;
195 $msgout->serialuint32 ($fake); // fake used to number the packet
197 $messageType = 2;
198 $msgout->serialuint8 ($messageType);
200 if (!sendMessage ($fp, $msgout))
202 $result = "Failed to send query to LAS $LASHost (ec 13)";
203 return false;
206 if (!waitMessage ($fp, $msgin))
208 $result = "Failed to wait for LAS $LASHost (ec 14)";
209 return false;
212 $result = '';
213 if (!$msgin->serialstring($result))
215 $result = "Failed to decode LAS message $LASHost (ec 15)";
216 return false;
219 fclose ($fp);
221 $pos = strpos($result, ':');
222 if ($pos === FALSE)
224 $result = "Failed to decode LAS message $LASHost (ec 16)";
225 return false;
228 $success = (substr($result, 0, $pos) == '1');
230 if ($success)
232 ++$pos;
233 $npos = strpos($result, "\n", $pos);
234 $result = substr($result, $npos);
236 else
238 $result = substr($result, $pos+1);
241 return $success;