Changeset 607
- Timestamp:
- Jun 27, 2009, 9:09:12 PM (15 years ago)
- Location:
- trunk/inc
- Files:
-
- 1 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/inc/teamspeakdisplay/teamspeakdisplay.php
r405 r607 18 18 19 19 class teamspeakDisplayClass { 20 21 // Removes subsequent end of line charachter from the right part of a string 22 function _stripEOL($evalString) { 23 $newLen = strlen($evalString); 24 while (((substr($evalString, $newLen - 1, 1) == "\r")) || ((substr($evalString, $newLen - 1, 1) == "\n"))) { 25 $newLen--; 26 } 27 return substr($evalString, 0, $newLen); 28 } 29 30 // Opens a connection to the teamspeak server 31 function _openConnection(&$socket, $host, $port, $timeout) { 32 @$socket = fsockopen($host, $port, $errno, $errstr, $timeout); 33 if ($socket and ($this->_stripEOL(fgets($socket, 4096)) == "[TS]")) { 34 return true; 35 } else { 36 return false; 37 } 38 } 39 40 // Closes the connection to the Teamspeak server 41 function _closeConnection($socket) { 42 fputs($socket, "quit\n"); 43 fclose($socket); 44 } 45 // odstrannie diakritiky 46 function Kodovani ($string) 47 { 48 $st_new = strtr($string, 49 "\xe1\xe4\xe8\xef\xe9\xec\xed\xbe\xe5\xf2\xf3\xf6\xf5\xf4\xf8\xe0\x9a\x9d\xfa\xf9\xfc\xfb\xfd\x9e\xc1\xc4\xc8\xcf\xc9\xcc\xcd\xbc\xc5\xd2\xd3\xd6\xd5\xd4\xd8\xc0\x8a\x8d\xda\xd9\xdc\xdb\xdd\x8e", 50 "aacdeeillnoooorrstuuuuyzAACDEEILLNOOOORRSTUUUUYZ" 51 ); 20 21 // Removes subsequent end of line charachter from the right part of a string 22 function _stripEOL($evalString) { 23 $newLen = strlen($evalString); 24 while (((substr($evalString, $newLen - 1, 1) == "\r")) || ((substr($evalString, $newLen - 1, 1) == "\n"))) { 25 $newLen--; 26 } 27 return substr($evalString, 0, $newLen); 28 } 29 30 // Opens a connection to the teamspeak server 31 function _openConnection(&$socket, $host, $port, $timeout) { 32 @$socket = fsockopen($host, $port, $errno, $errstr, $timeout); 33 if ($socket and ($this->_stripEOL(fgets($socket, 4096)) == "[TS]")) { 34 return true; 35 } else { 36 return false; 37 } 38 } 39 40 // Closes the connection to the Teamspeak server 41 function _closeConnection($socket) { 42 fputs($socket, "quit\n"); 43 fclose($socket); 44 } 45 // odstrannie diakritiky 46 function Kodovani ($string) 47 { 48 $st_new = ToUTF8($string); 49 // $st_new = strtr($string, "\xe1\xe4\xe8\xef\xe9\xec\xed\xbe\xe5\xf2\xf3\xf6\xf5\xf4\xf8\xe0\x9a\x9d\xfa\xf9\xfc\xfb\xfd\x9e\xc1\xc4\xc8\xcf\xc9\xcc\xcd\xbc\xc5\xd2\xd3\xd6\xd5\xd4\xd8\xc0\x8a\x8d\xda\xd9\xdc\xdb\xdd\x8e","aacdeeillnoooorrstuuuuyzAACDEEILLNOOOORRSTUUUUYZ" ); 52 50 $st_new = htmlspecialchars($st_new); 53 51 return $st_new; 54 52 } 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 echo("for(var i = 0; i < string.length; i++) {\n");359 echo("if (forbiddenChars.indexOf(string.charAt(i)) > -1) {\n");360 echo("return false;\n");361 echo("}\n");362 echo("}\n");363 echo("return true;\n");364 365 366 echo("enterSubChannel_" . $jsTeamspeakId . "(null, false, null);\n");367 368 369 echo("enterSubChannel_" . $jsTeamspeakId . "(channelName, channelPassworded, null);\n");370 371 372 echo("var serveraddress = 'teamspeak://" . $settings["serveraddress"] . ":" . $settings["serverudpport"] . "';\n");373 echo("var nickname=window.prompt('Enter your nickname', '');\n");374 echo("if (nickname == null) {\n");375 echo("return;\n");376 echo("} else if (! stringOk_" . $jsTeamspeakId . "(nickname, '" . str_replace("'", "\\'", $settings["forbiddennicknamechars"]) . "')) {\n");377 echo("window.alert('Could not enter the teamspeak server because the nickname you entered contains one or more of these forbidden characters: " . str_replace("'", "\\'", $settings["forbiddennicknamechars"]) . "');\n");378 echo("return;\n");379 echo("} else if (nickname == \"\") {\n");380 echo("window.alert('Could not enter the teamspeak server because you did not enter your nickname');\n");381 echo("return;\n");382 echo("}\n");383 echo("serveraddress = serveraddress + \"/nickname=\" + escape(nickname);\n");384 385 echo("var password=window.prompt('Enter the teamspeak server password for " . $serverInfo["serverinfo"]["server_name"] . "', '');\n");386 echo("if (password == null) {\n");387 echo("return;\n");388 echo("} else if (password == \"\") {\n");389 echo("window.alert('Could not enter the teamspeak server because you did not enter a server password');\n");390 echo("return;\n");391 echo("}\n");392 echo("serveraddress = serveraddress + \"?password=\" + escape(password);\n");393 394 echo("if (channelName != null) { serveraddress = serveraddress + \"?channel=\" + escape(channelName); }\n");395 echo("if (channelPassworded) {\n");396 echo("var channelpassword=window.prompt('Enter the channel password for channel ' + channelName, '');\n");397 echo("if (channelpassword == null) {\n");398 echo("return;\n");399 echo("} else if (channelpassword == \"\") {\n");400 echo("window.alert('Could not enter the teamspeak server because you did not enter a channel password');\n");401 echo("return;\n");402 echo("}\n");403 echo("serveraddress = serveraddress + \"?channelpassword=\" + escape(channelpassword);\n");404 echo("}\n");405 echo("if (subChannelName != null) { serveraddress = serveraddress + \"?subchannel=\" + escape(subChannelName); }\n");406 echo("window.location=serveraddress;\n");407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 53 54 // Returns the part of evalString until a tab (or the end of a string) and deletes the 55 // returned part from evalString (including the possible tab that follows) 56 function _stripPartFromString(&$evalString) { 57 $pos = strpos($evalString, "\t"); 58 if(is_integer($pos)) { 59 $result = substr($evalString, 0, $pos); 60 $evalString = substr($evalString, $pos + 1); 61 } else { 62 $result = $evalString; 63 $evalString = ""; 64 } 65 return $result; 66 } 67 68 // Removes the surrounding quotes from evalString and returns the result 69 function _stripQuotes($evalString) { 70 if(strpos($evalString, '"') == 0) $evalString = substr($evalString, 1, strlen($evalString) - 1); 71 if(strrpos($evalString, '"') == strlen($evalString) - 1) $evalString = substr($evalString, 0, strlen($evalString) - 1); 72 return $evalString; 73 } 74 75 // Request, read and parse the server info: 76 function _getServerInfo($socket) { 77 fputs($socket, "si\n"); 78 $result = array(); 79 do { 80 $buffer = $this->_stripEOL(fgets($socket, 4096)); 81 if (($buffer != "OK") && (strtoupper(substr($buffer, 0, 5)) != "ERROR")) { 82 $pos = strpos($buffer, '='); 83 if ($pos !== False) { 84 $result[substr($buffer, 0, $pos)] = substr($buffer, $pos + 1); 85 } 86 } 87 } while (($buffer != "OK") && (strtoupper(substr($buffer, 0, 5)) != "ERROR") && (!feof($socket))); 88 return $result; 89 } 90 91 function _setPlayerDisplayImage(&$playerInfo) { 92 // Determine the right userpicture: 93 if (($playerInfo["attribute"] & 8) == 8) { $playerImage = "away"; } 94 else if (($playerInfo["attribute"] & 32) == 32) { $playerImage = "mutespeakers"; } 95 else if (($playerInfo["attribute"] & 16) == 16) { $playerImage = "mutemicrophone"; } 96 else if (($playerInfo["attribute"] & 1) == 1) { $playerImage = "channelcommander"; } 97 else { $playerImage = "normal"; } 98 $playerInfo["displayimage"] = $playerImage; 99 } 100 101 function _setPlayerDisplayName(&$playerInfo) { 102 // Determine the player status (U = Unregistered, R = Registered, SA = Server Admin, 103 // CA = Channel Admin, AO = Auto-Operator, AV = Auto-Voice, O = Operator, V = Voice) 104 if (($playerInfo["userstatus"] & 4) == 4) { $playerstatus = "R"; } else { $playerstatus = 'U'; } 105 if (($playerInfo["userstatus"] & 1) == 1) { $playerstatus .= " SA"; } 106 if (($playerInfo["privileg"] & 1) == 1) { $playerstatus .= " CA"; } 107 if (($playerInfo["privileg"] & 8) == 8) { $playerstatus .= " AO"; } 108 if (($playerInfo["privileg"] & 16) == 16) { $playerstatus .= " AV"; } 109 if (($playerInfo["privileg"] & 2) == 2) { $playerstatus .= " O"; } 110 if (($playerInfo["privileg"] & 4) == 4) { $playerstatus .= " V"; } 111 if (($playerInfo["attribute"] & 64) == 64) { $playerstatus .= " Rec"; } 112 113 // Determine the player attributes to be listed behind the player status (WV = Want Voice) 114 if (($playerInfo["attribute"] & 2) == 2) { $playerattributes = ' WV'; } else { $playerattributes = ''; } 115 116 $playerInfo["displayname"] = $playerInfo["playername"] . " (" . $playerstatus . ")" . $playerattributes; 117 } 118 119 function _getPlayerList($socket) { 120 // Request, read and parse the player list 121 fputs($socket, "pl\n"); 122 $buffer = $this->_stripEOL(fgets($socket, 4096)); 123 $result = array(); 124 if (strtoupper(substr($buffer, 0, 5)) == "ERROR") { return $result; } 125 do { 126 $buffer = $this->_stripEOL(fgets($socket, 4096)); 127 if (($buffer != "OK") && (strtoupper(substr($buffer, 0, 5)) != "ERROR")) { 128 $playerid = $this->_stripPartFromString($buffer); 129 $result[$playerid] = array( 130 "playerid" => $playerid, 131 "channelid" => $this->_stripPartFromString($buffer), 132 "receivedpackets" => $this->_stripPartFromString($buffer), 133 "receivedbytes" => $this->_stripPartFromString($buffer), 134 "sentpackets" => $this->_stripPartFromString($buffer), 135 "sentbytes" => $this->_stripPartFromString($buffer), 136 "paketlost" => $this->_stripPartFromString($buffer) / 100, 137 "pingtime" => $this->_stripPartFromString($buffer), 138 "totaltime" => $this->_stripPartFromString($buffer), 139 "idletime" => $this->_stripPartFromString($buffer), 140 "privileg" => $this->_stripPartFromString($buffer), 141 "userstatus" => $this->_stripPartFromString($buffer), 142 "attribute" => $this->_stripPartFromString($buffer), 143 "ip" => $this->_stripPartFromString($buffer), 144 "playername" => $this->_stripQuotes($this->_stripPartFromString($buffer)), 145 "loginname" => $this->_stripQuotes($this->_stripPartFromString($buffer)) 146 ); 147 $this->_setPlayerDisplayImage($result[$playerid]); 148 $this->_setPlayerDisplayName($result[$playerid]); 149 } 150 } while (($buffer != "OK") && (strtoupper(substr($buffer, 0, 5)) != "ERROR") && (!feof($socket))); 151 return $result; 152 } 153 154 function _getLimitedPlayerList($socket, $channelList) { 155 $playerList = $this->_getPlayerList($socket); 156 $result = array(); 157 foreach($playerList as $playerInfo) { 158 foreach($channelList as $channelInfo) { 159 if ($playerInfo["channelid"] == $channelInfo["channelid"]) { 160 $result[$playerInfo["playerid"]] = $playerInfo; 161 } 162 } 163 } 164 return $result; 165 } 166 167 function _setChannelDisplayName(&$channelInfo) { 168 if ($channelInfo["parent"] != -1) { 169 $channelInfo["displayname"] = $channelInfo["channelname"]; 170 } else { 171 // Determine the channel status (U = Unregisterd, R = Registered, M = Moderated, 172 // P = Passworded, S = Sub-channels, D = Default). 173 if (($channelInfo["flags"] & 1) == 1) { $channelstatus = 'U'; } else { $channelstatus = 'R'; } 174 if (($channelInfo["flags"] & 2) == 2) { $channelstatus .= 'M'; } 175 if (($channelInfo["flags"] & 4) == 4) { $channelstatus .= 'P'; } 176 if (($channelInfo["flags"] & 8) == 8) { $channelstatus .= 'S'; } 177 if (($channelInfo["flags"] & 16) == 16) { $channelstatus .= 'D'; } 178 $channelInfo["displayname"] = $channelInfo["channelname"] . " (" . $channelstatus . ")"; 179 } 180 } 181 182 function _getChannelList($socket) { 183 // Request, read and parse the channel list 184 fputs($socket, "cl\n"); 185 $buffer = $this->_stripEOL(fgets($socket, 4096)); 186 $result = array(); 187 if (strtoupper(substr($buffer, 0, 5)) == "ERROR") { return $result; } 188 do { 189 $buffer = $this->_stripEOL(fgets($socket, 4096)); 190 if (($buffer != "OK") && (strtoupper(substr($buffer, 0, 5)) != "ERROR")) { 191 $channelid = $this->_stripPartFromString($buffer); 192 $result[$channelid] = array( 193 "channelid" => $channelid, 194 "codec" => $this->_stripPartFromString($buffer), 195 "parent" => $this->_stripPartFromString($buffer), 196 "order" => $this->_stripPartFromString($buffer), 197 "maxplayers" => $this->_stripPartFromString($buffer), 198 "channelname" => $this->_stripQuotes($this->_stripPartFromString($buffer)), 199 "flags" => $this->_stripPartFromString($buffer), 200 "password" => $this->_stripPartFromString($buffer), 201 "topic" => $this->_stripQuotes($this->_stripPartFromString($buffer)) 202 ); 203 $this->_setChannelDisplayName($result[$channelid]); 204 } 205 } while (($buffer != "OK") && (strtoupper(substr($buffer, 0, 5)) != "ERROR") && (!feof($socket))); 206 return $result; 207 } 208 209 function _getLimitedChannelList($socket, $limitChannel) { 210 $channelList = $this->_getChannelList($socket); 211 $result = array(); 212 foreach($channelList as $channelInfo) { 213 if ($channelInfo["parent"] == -1) { 214 if ($channelInfo["channelname"] == $limitChannel) { 215 $result[$channelInfo["channelid"]] = $channelInfo; 216 foreach($channelList as $subChannelInfo) { 217 if ($subChannelInfo["parent"] == $channelInfo["channelid"]) { 218 $result[$subChannelInfo["channelid"]] = $subChannelInfo; 219 } 220 } 221 } 222 } 223 } 224 return $result; 225 } 226 227 function _selectServer($socket, $port) { 228 // Request the server to select the server which is hosted on the port set in serverUDPPort 229 fputs($socket, "sel ".$port . "\n"); 230 231 // Read server response on request to select a server 232 return ($this->_stripEOL(fgets($socket, 4096)) == "OK"); 233 } 234 235 // Queries the Teamspeak server 236 function queryTeamspeakServerEx($settings) { 237 $result = array(); 238 239 // Try to establish a connection to the teamspeak server 240 if (! $this->_openConnection($socket, $settings["serveraddress"], $settings["serverqueryport"], 0.3)) { 241 $result["queryerror"] = 1; 242 } else if (! $this->_selectServer($socket, $settings["serverudpport"])) { 243 $result["queryerror"] = 2; 244 $this->_closeConnection($socket); 245 } else { 246 $result["queryerror"] = 0; 247 $result["serverinfo"] = $this->_getServerInfo($socket); 248 $result["channellist"] = ($settings["limitchannel"] == "") ? $this->_getChannelList($socket) : $this->_getLimitedChannelList($socket, $settings["limitchannel"]); 249 $result["playerlist"] = ($settings["limitchannel"] == "") ? $this->_getPlayerList($socket) : $this->_getLimitedPlayerList($socket, $result["channellist"]); 250 $this->_closeConnection($socket); 251 } 252 return $result; 253 } 254 255 function queryTeamspeakServer($serverAddress, $serverUDPPort, $serverQueryPort) { 256 $settings = $this->getDefaultSettings(); 257 $settings["serveraddress"] = $serverAddress; 258 $settings["serverudpport"] = $serverUDPPort; 259 $settings["serverqueryport"] = $serverQueryPort; 260 return $this->queryTeamspeakServerEx($settings); 261 } 262 263 function _orderAlphaGetString($string) { 264 $lowerstring = strtolower($string); 265 $result = ""; 266 for ($i = 0; $i < strlen($lowerstring); $i++) { 267 if (strpos("0123456789abcdefghijklmnopqrstuvwxyz", substr($lowerstring, $i, 1)) !== false) { 268 $result .= substr($lowerstring, $i, 1); 269 } 270 } 271 return $result; 272 } 273 274 function _orderAlpha($str1, $str2) { 275 return strcmp($this->_orderAlphaGetString($str1), $this->_orderAlphaGetString($str2)); 276 } 277 278 function _compareChannel($a, $b) { 279 if ($a["order"] != $b["order"]) { return ($a["order"] < $b["order"]) ? -1 : 1; } 280 else { return $this->_orderAlpha($a["displayname"], $b["displayname"]); } 281 } 282 283 function _comparePlayer($a, $b) { 284 // Determine userlevel (0 = Not server admin, 1 = Server admin) 285 $userlevela = $a["userstatus"] & 1; 286 $userlevelb = $b["userstatus"] & 1; 287 if ($userlevela != $userlevelb) { return ($userlevela < $userlevelb) ? 1 : -1; } 288 else { return $this->_orderAlpha($a["displayname"], $b["displayname"]); } 289 } 290 291 function sortServerInfo(&$serverInfo) { 292 usort($serverInfo["channellist"], array($this, "_compareChannel")); 293 usort($serverInfo["playerlist"], array($this, "_comparePlayer")); 294 } 295 296 function _formatTime($totaltime) { 297 $hours = floor($totaltime / 3600); 298 $minutes = floor(($totaltime % 3600) / 60); 299 return (($hours < 10) ? "0" : "") . $hours . ":" . (($minutes < 10) ? "0" : "") . $minutes; 300 } 301 302 // Returns the codec name 303 function _getCodecName($codec) { 304 if ($codec == 0) { return "CELP 5.1 Kbit"; } 305 else if ($codec == 1) { return "CELP 6.3 Kbit"; } 306 else if ($codec == 2) { return "GSM 14.8 Kbit"; } 307 else if ($codec == 3) { return "GSM 16.4 Kbit"; } 308 else if ($codec == 4) { return "CELP Windows 5.2 Kbit"; } 309 else if ($codec == 5) { return "Speex 3.4 Kbit"; } 310 else if ($codec == 6) { return "Speex 5.2 Kbit"; } 311 else if ($codec == 7) { return "Speex 7.2 Kbit"; } 312 else if ($codec == 8) { return "Speex 9.3 Kbit"; } 313 else if ($codec == 9) { return "Speex 12.3 Kbit"; } 314 else if ($codec == 10) { return "Speex 16.3 Kbit"; } 315 else if ($codec == 11) { return "Speex 19.5 Kbit"; } 316 else if ($codec == 12) { return "Speex 25.9 Kbit"; } 317 else { return "Unknown (" . $codec . ")"; } 318 } 319 320 function getDefaultSettings() { 321 $result = array(); 322 $result["serveraddress"] = ""; 323 $result["serverudpport"] = 8767; 324 $result["serverqueryport"] = 51234; 325 $result["limitchannel"] = ""; 326 $result["forbiddennicknamechars"] = "()[]{}"; 327 return $result; 328 } 329 330 // Main function (queries, sorts and displays the teamspeak serverinfo). Its code is not 331 // very readable... well what shall I say about it... it was hard to write so it should 332 // be hard to read >:) 333 function displayTeamspeakEx($settings) { 334 $serverInfo = $this->queryTeamspeakServerEx($settings); 335 336 echo("<div id=\"teamspeakdisplay\">\n"); 337 if ($serverInfo["queryerror"] != 0) { 338 $popupInfo = "Server address: " . $settings["serveraddress"] . (($settings["serverudpport"] != 8767) ? (":" . $settings["serverudpport"]): ""); 339 if ($serverInfo["queryerror"] == 1) { 340 $popupInfo .= ", Error: could not connect to query port"; 341 } else { 342 $popupInfo .= ", Error: no server running on port " . $settings["serverudpport"]; 343 } 344 echo("<table><tr><td>"); 345 echo("<img src=\"inc/teamspeakdisplay/teamspeak_offline.png\" alt=\"\" title=\"" . $popupInfo . "\">"); 346 echo("</td><td class=\"teamspeakserver\" title=\"" . $popupInfo . "\">"); 347 echo("Server offline"); 348 echo("</td></tr></table>\n"); 349 } else { 350 $this->sortServerInfo($serverInfo); 351 352 // Generate javascript for teamspeak hyperlinks 353 $jsTeamspeakId = md5($settings["serveraddress"] . ":" . $settings["serverudpport"]); 354 echo("<script type=\"text/javascript\"><!--\n"); 355 echo("function stringOk_" . $jsTeamspeakId . "(string, forbiddenChars) {\n"); 356 echo(" for(var i = 0; i < string.length; i++) {\n"); 357 echo(" if (forbiddenChars.indexOf(string.charAt(i)) > -1) {\n"); 358 echo(" return false;\n"); 359 echo(" }\n"); 360 echo(" }\n"); 361 echo(" return true;\n"); 362 echo("}\n"); 363 echo("function enterServer_" . $jsTeamspeakId . "() {\n"); 364 echo(" enterSubChannel_" . $jsTeamspeakId . "(null, false, null);\n"); 365 echo("}\n"); 366 echo("function enterChannel_" . $jsTeamspeakId . "(channelName, channelPassworded) {\n"); 367 echo(" enterSubChannel_" . $jsTeamspeakId . "(channelName, channelPassworded, null);\n"); 368 echo("}\n"); 369 echo("function enterSubChannel_" . $jsTeamspeakId . "(channelName, channelPassworded, subChannelName) {\n"); 370 echo(" var serveraddress = 'teamspeak://" . $settings["serveraddress"] . ":" . $settings["serverudpport"] . "';\n"); 371 echo(" var nickname=window.prompt('Enter your nickname', '');\n"); 372 echo(" if (nickname == null) {\n"); 373 echo(" return;\n"); 374 echo(" } else if (! stringOk_" . $jsTeamspeakId . "(nickname, '" . str_replace("'", "\\'", $settings["forbiddennicknamechars"]) . "')) {\n"); 375 echo(" window.alert('Could not enter the teamspeak server because the nickname you entered contains one or more of these forbidden characters: " . str_replace("'", "\\'", $settings["forbiddennicknamechars"]) . "');\n"); 376 echo(" return;\n"); 377 echo(" } else if (nickname == \"\") {\n"); 378 echo(" window.alert('Could not enter the teamspeak server because you did not enter your nickname');\n"); 379 echo(" return;\n"); 380 echo(" }\n"); 381 echo(" serveraddress = serveraddress + \"/nickname=\" + escape(nickname);\n"); 382 if ($serverInfo["serverinfo"]["server_password"] == "1") { 383 echo(" var password=window.prompt('Enter the teamspeak server password for " . $serverInfo["serverinfo"]["server_name"] . "', '');\n"); 384 echo(" if (password == null) {\n"); 385 echo(" return;\n"); 386 echo(" } else if (password == \"\") {\n"); 387 echo(" window.alert('Could not enter the teamspeak server because you did not enter a server password');\n"); 388 echo(" return;\n"); 389 echo(" }\n"); 390 echo(" serveraddress = serveraddress + \"?password=\" + escape(password);\n"); 391 } 392 echo(" if (channelName != null) { serveraddress = serveraddress + \"?channel=\" + escape(channelName); }\n"); 393 echo(" if (channelPassworded) {\n"); 394 echo(" var channelpassword=window.prompt('Enter the channel password for channel ' + channelName, '');\n"); 395 echo(" if (channelpassword == null) {\n"); 396 echo(" return;\n"); 397 echo(" } else if (channelpassword == \"\") {\n"); 398 echo(" window.alert('Could not enter the teamspeak server because you did not enter a channel password');\n"); 399 echo(" return;\n"); 400 echo(" }\n"); 401 echo(" serveraddress = serveraddress + \"?channelpassword=\" + escape(channelpassword);\n"); 402 echo(" }\n"); 403 echo(" if (subChannelName != null) { serveraddress = serveraddress + \"?subchannel=\" + escape(subChannelName); }\n"); 404 echo(" window.location=serveraddress;\n"); 405 echo("}\n"); 406 echo("//--></script>\n"); 407 408 $popupInfo = "Server address: " . $settings["serveraddress"] . (($settings["serverudpport"] != 8767) ? (":" . $settings["serverudpport"]): "") . ", Max players: " . $serverInfo["serverinfo"]["server_maxusers"] . ", Uptime: " . $this->_formatTime($serverInfo["serverinfo"]["server_uptime"]); 409 410 // Print the topmost element of the teamspeak tree 411 echo("<table><tr><td>"); 412 echo("<img src=\"inc/teamspeakdisplay/teamspeak_online.png\" alt=\"\" title=\"" . $popupInfo . "\">"); 413 echo("</td><td class=\"teamspeakserver\" title=\"" . $popupInfo . "\">"); 414 echo("<a class=\"teamspeakserver\" href=\"javascript:enterServer_" . $jsTeamspeakId . "();\">"); 415 echo(str_replace(" ", " ", $this -> Kodovani($serverInfo["serverinfo"]["server_name"]))); 416 echo("</a>"); 417 echo("</td></tr></table>\n"); 418 419 // Count the number of channels to be listed: 420 $currentchannels = 0; 421 foreach($serverInfo["channellist"] as $channelInfo) { 422 if ($channelInfo["parent"] == -1) { 423 $currentchannels++; 424 } 425 } 426 427 // Initialize the channelcounter to zero 428 $counter = 0; 429 430 // Loop through all channels: 431 foreach($serverInfo["channellist"] as $channelInfo) { if ($channelInfo["parent"] == -1) { 432 433 // determine number of players in channel 434 $currentplayers = 0; 435 foreach($serverInfo["playerlist"] as $playerInfo) { 436 if($playerInfo["channelid"] == $channelInfo["channelid"]) $currentplayers++; 437 } 438 439 // Count the number of channels to be listed: 440 $currentplayersandsubchannels = $currentplayers; 441 foreach($serverInfo["channellist"] as $subchannelInfo) { 442 if ($subchannelInfo["parent"] == $channelInfo["channelid"]) { 443 $currentplayersandsubchannels++; 444 } 445 } 446 447 $popupInfo = "Max players: " . $channelInfo["maxplayers"] . ", Codec: " . $this->_getCodecName($channelInfo["codec"]); 448 if ($channelInfo["topic"] != "") { $popupInfo = $popupInfo . ", Topic: " . $channelInfo["topic"]; } 449 450 // Display channel: 451 echo("<table><tr><td>"); 452 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter + 1) == $currentchannels) ? "3" : "2") . ".png\" alt=\"\">"); 453 echo("<img src=\"inc/teamspeakdisplay/channel.png\" alt=\"\" title=\"" . $popupInfo . "\">"); 454 echo("</td><td class=\"teamspeakchannel\" title=\"" . $popupInfo . "\">"); 455 echo("<a class=\"teamspeakchannel\" href=\"javascript:enterChannel_" . $jsTeamspeakId . "('" . str_replace("'", "\'", $channelInfo["channelname"]) . "', " . (($channelInfo["password"]) == "1" ? "true" : "false") . ");\">"); 456 echo(str_replace(" ", " ", $this -> Kodovani($channelInfo["displayname"]))); 457 echo("</a>"); 458 echo("</td></tr></table>\n"); 459 460 // Initialize the playercounter for this channel to zero 461 $counter_playerandsubchannels = 0; 462 463 // Loop through all players in the current channel: 464 foreach($serverInfo["playerlist"] as $playerInfo) { 465 466 // Is the current player in the current channel? 467 if ($playerInfo["channelid"] == $channelInfo["channelid"]) { 468 469 $popupInfo = "Time online: " . $this->_formatTime($playerInfo["totaltime"]) . ", Time idle: " . $this->_formatTime($playerInfo["idletime"]) . ", Ping: " . $playerInfo["pingtime"] . "ms"; 470 471 // Display player: 472 echo("<table><tr><td>"); 473 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter + 1) == $currentchannels) ? "4" : "1") . ".png\" alt=\"\">"); 474 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter_playerandsubchannels + 1) == $currentplayersandsubchannels) ? "3" : "2") . ".png\" alt=\"\">"); 475 echo("<img src=\"inc/teamspeakdisplay/player_" . $playerInfo["displayimage"] . ".png\" alt=\"" . $playerInfo["displayimage"] . "\" title=\"" . $popupInfo . "\">"); 476 echo("</td><td class=\"teamspeakplayer\" title=\"" . $popupInfo . "\">"); 477 echo(str_replace(" ", " ", $this -> Kodovani($playerInfo["displayname"]))); 478 echo("</td></tr></table>\n"); 479 480 // Increase the player counter: 481 $counter_playerandsubchannels++; 482 } 483 } 484 485 // Loop through all channels: 486 foreach($serverInfo["channellist"] as $subchannelInfo) { if ($subchannelInfo["parent"] == $channelInfo["channelid"]) { 487 // determine number of players in channel 488 $currentplayers = 0; 489 foreach($serverInfo["playerlist"] as $playerInfo) { 490 if($playerInfo["channelid"] == $subchannelInfo["channelid"]) $currentplayers++; 491 } 492 493 $popupInfo = "Max players: " . $subchannelInfo["maxplayers"] . ", Codec: " . $this->_getCodecName($subchannelInfo["codec"]); 494 if ($subchannelInfo["topic"] != "") { $popupInfo = $popupInfo . ", Topic: " . $subchannelInfo["topic"]; } 495 496 // Display channel: 497 echo("<table><tr><td>"); 498 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter + 1) == $currentchannels) ? "4" : "1") . ".png\" alt=\"\">"); 499 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter_playerandsubchannels + 1) == $currentplayersandsubchannels) ? "3" : "2") . ".png\" alt=\"\">"); 500 echo("<img src=\"inc/teamspeakdisplay/channel.png\" alt=\"\" title=\"" . $popupInfo . "\">"); 501 echo("</td><td class=\"teamspeaksubchannel\" title=\"" . $popupInfo . "\">"); 502 echo("<a class=\"teamspeaksubchannel\" href=\"javascript:enterSubChannel_" . $jsTeamspeakId . "('" . str_replace("'", "\'", $channelInfo["channelname"]) . "', " . (($channelInfo["password"]) == "1" ? "true" : "false") . ", '" . str_replace("'", "\'", $subchannelInfo["channelname"]) . "');\">"); 503 echo(str_replace(" ", " ", $this -> Kodovani($subchannelInfo["displayname"]))); 504 echo("</a>"); 505 echo("</td></tr></table>\n"); 506 507 // Initialize the playercounter for this channel to zero 508 $counter_player = 0; 509 510 // Loop through all players in the current channel: 511 foreach($serverInfo["playerlist"] as $playerInfo) { 512 513 // Is the current player in the current channel? 514 if ($playerInfo["channelid"] == $subchannelInfo["channelid"]) { 515 516 $popupInfo = "Time online: " . $this->_formatTime($playerInfo["totaltime"]) . ", Time idle: " . $this->_formatTime($playerInfo["idletime"]) . ", Ping: " . $playerInfo["pingtime"] . "ms"; 517 518 // Display player: 519 echo("<table><tr><td>"); 520 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter + 1) == $currentchannels) ? "4" : "1") . ".png\" alt=\"\">"); 521 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter_playerandsubchannels + 1) == $currentplayersandsubchannels) ? "4" : "1") . ".png\" alt=\"\">"); 522 echo("<img src=\"inc/teamspeakdisplay/treeimage" . ((($counter_player + 1) == $currentplayers) ? "3" : "2") . ".png\" alt=\"\">"); 523 echo("<img src=\"inc/teamspeakdisplay/player_" . $playerInfo["displayimage"] . ".png\" alt=\"" . $playerInfo["displayimage"] . "\" title=\"" . $popupInfo . "\">"); 524 echo("</td><td class=\"teamspeakplayer\" title=\"" . $popupInfo . "\">"); 525 echo(str_replace(" ", " ", $this -> Kodovani($playerInfo["displayname"]))); 526 echo("</td></tr></table>\n"); 527 528 // Increase the player counter: 529 $counter_player++; 530 } 531 } 532 533 // Increase the channelcounter 534 $counter_playerandsubchannels++; 535 } } 536 537 // Increase the channelcounter 538 $counter++; 539 } } 540 } 541 echo("</div>\n"); 542 } 543 544 function displayTeamspeak($serverAddress, $serverUDPPort=8767, $serverQueryPort=51234) { 545 $settings = $this->getDefaultSettings(); 546 $settings["serveraddress"] = $serverAddress; 547 $settings["serverudpport"] = $serverUDPPort; 548 $settings["serverqueryport"] = $serverQueryPort; 549 $this->displayTeamspeakEx($settings); 550 } 551 554 552 } 555 553
Note:
See TracChangeset
for help on using the changeset viewer.