function test() { $server = array(); //we will use an array to store all the server data. //Open the socket connection to the IRC server $server['SOCKET'] = @fsockopen($server_host, $server_port, $errno, $errstr, 2); if ($server['SOCKET']) { //Ok, we have connected to the server, now we have to send the login commands. SendCommand("PASS NOPASS\n\r"); //Sends the password not needed for most servers SendCommand("NICK {$nickname}\n\r"); //sends the nickname SendCommand("USER {$nickname} USING PHP IRC\n\r"); //sends the user must have 4 paramters while (!feof($server['SOCKET'])) { $server['READ_BUFFER'] = fgets($server['SOCKET'], 1024); //get a line of data from the server echo "[RECIVE] " . $server['READ_BUFFER'] . "<br>\n\r"; //display the recived data from the server /* IRC Sends a "PING" command to the client which must be anwsered with a "PONG" Or the client gets Disconnected */ //Now lets check to see if we have joined the server if (strpos($server['READ_BUFFER'], "422")) { //If we have joined the server SendCommand("JOIN {$server_chan}\n\r"); //Join the chanel } if (substr($server['READ_BUFFER'], 0, 6) == "PING :") { SendCommand("PONG :" . substr($server['READ_BUFFER'], 6) . "\n\r"); //Reply with pong //As you can see i dont have it reply with just "PONG" //It sends PONG and the data recived after the "PING" text on that recived line //Reason being is some irc servers have a "No Spoof" feature that sends a key after the PING //Command that must be replied with PONG and the same key sent. } flush(); //This flushes the output buffer forcing the text in the while loop to be displayed "On demand" } } }
function ExtGPIO() { global $args; $result = array(); $gpio = $args['gpio']; $mode = $args['mode']; $val = $args['val']; check($gpio, "gpio", __FUNCTION__); check($mode, "mode", __FUNCTION__); check($val, "val", __FUNCTION__); $status = SendCommand(sprintf("ExtGPIO,%s,%s,%s", $gpio, $mode, $val)); $status = explode(',', $status, 14); if ((int) $status[1] >= 0) { $result['status'] = 'success'; $result['result'] = $status[6]; } else { $result['status'] = 'failed'; } returnJSON($result); }
<?php /** * 飞信机器人--事件插件--好友邀请 * 功能: 当对方增加机器人为好友时,收到此事件。在该事件中,可以根据对方的号码来做不同的处理 * 作者: Kelvin * 联系: msn:shichangguo@msn.com, qq:191848423 */ require_once './plugins/inc/config.inc.php'; require_once './plugins/inc/utils.inc.php'; //require_once('./plugins/inc/session.inc.php'); $srvMobile = $argv[1]; $uri = base64_decode($argv[2]); SendCommand("accept_contact_request {$uri}"); sleep(5); SendCommand("buddy-delete {$uri}");
function GetTestMode() { header("Content-Type: application/json"); echo SendCommand("GetTestMode"); }
function connectToIRC($host, $port, $nick, $channels, $onJoin, $authMethod) { global $serverThreads; $thisServer = array(); $thisServer["SOCKET"] = @fsockopen($host, $port, $errno, $errstr, 2); $thisServer["USERDATA"] = new ircUsersData($host); $thisServer["USERDATA"]->addUserData("BawkBotPermissions", "*", "*", array("isAuthenticated" => 0)); $thisServer["host"] = $host; $thisServer["authMethod"] = $authMethod; $thisServer["nick"] = $nick; $thisServer["channels"] = array(); if ($thisServer['SOCKET']) { SendCommand($thisServer, "PASS NOPASS\r\n"); SendCommand($thisServer, "NICK {$nick}\r\n"); SendCommand($thisServer, "USER nick USING PHP IRC\r\n"); $authed = 0; while (!feof($thisServer['SOCKET']) && $authed != 2) { $thisServer['READ_BUFFER'] = fgets($thisServer['SOCKET'], 1024); echo "[RECEIVE] " . str_replace("\r\n", "", $thisServer['READ_BUFFER']) . "\r\n"; if (strpos($thisServer['READ_BUFFER'], "376")) { foreach ($channels as $key => $chan) { SendCommand($thisServer, "JOIN {$chan}\r\n"); $thisServer["channels"][] = $chan; } SendCommand($thisServer, $onJoin . "\r\n"); $authed++; } if (substr($thisServer['READ_BUFFER'], 0, 6) == "PING :") { SendCommand($thisServer, "PONG :" . substr($thisServer['READ_BUFFER'], 6) . "\r\n"); $authed++; } } $serverThreads[] = $thisServer; } else { print "Failed connection."; } }
* 功能: 新消息到达时激活 * 作者: Kelvin * 联系: msn:shichangguo@msn.com, qq:191848423 */ require_once './plugins/inc/config.inc.php'; require_once './plugins/inc/utils.inc.php'; require_once './plugins/inc/session.inc.php'; $srvMobile = $argv[1]; $uri = base64_decode($argv[2]); //消息发起人URI $message = strip_tags(base64_decode($argv[3])); // Base64 编码的消息 $type = base64_decode($argv[4]); //消息类型 /* if( $type=='text/plain' && substr($message,0,1)=='#' ) { $time = date('Y-m-d H:i:s'); file_put_contents("/var/www/record.txt",$time."\t".$uri."\t".$message."\n",FILE_APPEND); SendCommand("longsms $uri 谢谢您的参与!"); exit; } */ $session = new CSession($srvMobile, $srvFetion, $uri); $retMsg = $session->handleMsg($message, $type); if ($type == 'text/plain') { $retMsg = strip_tags(strip_tags($retMsg)); SendCommand("longsms {$uri} {$retMsg}"); } else { SendCommand("chat {$uri} {$retMsg}"); }
function SaveFPDv1() { global $settings; $outputCount = 12; $carr = array(); for ($i = 0; $i < 1024; $i++) { $carr[$i] = 0x0; } $i = 0; // Header $carr[$i++] = 0x55; $carr[$i++] = 0x55; $carr[$i++] = 0x55; $carr[$i++] = 0x55; $carr[$i++] = 0x55; $carr[$i++] = 0xcc; $_SESSION['PixelnetDMXentries'] = NULL; for ($o = 0; $o < $outputCount; $o++) { // Active Output if (isset($_POST['FPDchkActive'][$o])) { $active = 1; $carr[$i++] = 1; } else { $active = 0; $carr[$i++] = 0; } // Start Address $startAddress = intval($_POST['FPDtxtStartAddress'][$o]); $carr[$i++] = $startAddress % 256; $carr[$i++] = $startAddress / 256; // Type $type = intval($_POST['pixelnetDMXtype'][$o]); $carr[$i++] = $type; $_SESSION['PixelnetDMXentries'][] = new PixelnetDMXentry($active, $type, $startAddress); } $f = fopen($settings['configDirectory'] . "/Falcon.FPDV1", "wb"); fwrite($f, implode(array_map("chr", $carr)), 1024); fclose($f); SendCommand('w'); }
function ExtGPIO() { $gpio = $_GET['gpio']; $mode = $_GET['mode']; $val = $_GET['val']; check($gpio, "gpio", __FUNCTION__); check($mode, "mode", __FUNCTION__); check($val, "val", __FUNCTION__); $status = SendCommand(sprintf("ExtGPIO,%s,%s,%s", $gpio, $mode, $val)); $status = explode(',', $status, 14); if ((int) $status[1] >= 0) { $doc = new DomDocument('1.0'); $root = $doc->createElement('Status'); $root = $doc->appendChild($root); $temp = $doc->createElement('Success'); $temp = $root->appendChild($temp); $result = $doc->createTextNode((int) $status[6]); $result = $temp->appendChild($result); echo $doc->saveHTML(); } else { EchoStatusXML('Failed'); } }