예제 #1
0
 public function performAlias($command)
 {
     if (array_key_exists($command[0], $this->aliases)) {
         $newCommand = str_replace("\\[", "<~~~~~~~~~BAWKBOTCOMMAND------>", $this->aliases[$command[0]]);
         $i = 0;
         //Searches for square brackets, and returns them as an array.
         if (preg_match_all("/\\[([^\\]]*)\\]/", $newCommand, $matches)) {
             $groupText = "";
             foreach ($matches[1] as $k => $group) {
                 //$group = "x-x"
                 $range = explode("-", $group);
                 if (in_array("in", $range) == false) {
                     if ($range[1] == "*") {
                         $range[1] = 250;
                         //Safe number, I guess.
                     }
                     if (count($range) == 1) {
                         $groupText = trim($command[$range[0]]);
                     } else {
                         //Assumed two.
                         $groupText = "";
                         for ($a = $range[0]; $a < $range[1]; $a++) {
                             if (isset($command[$a])) {
                                 $groupText .= trim($command[$a]) . " ";
                             } else {
                                 break;
                             }
                         }
                     }
                     $newCommand = str_replace("[" . $group . "]", trim($groupText), trim($newCommand));
                 }
             }
             $i++;
         }
         $command = parse_delimiters($newCommand, " ");
     }
     return str_replace("<~~~~~~~~~BAWKBOTCOMMAND------>", "[", $command);
 }
예제 #2
0
function bawkBotExecuteCommand($server, $messageNick, $messageType, $messageChan, $messageCont, $messageMask = "", $choke = false)
{
    global $plugins, $aliaser, $messageQueue, $mysql_statistics, $mysql_statistics;
    $isCommand = substr($messageCont, 0, 1) == COMMANDSYMBOL;
    $preAliaser = $messageCont;
    if ($isCommand) {
        do {
            $pipeCount = substr_count($messageCont, "|");
            $messageCommands = parse_delimiters($messageCont, "|");
            foreach ($messageCommands as &$tmpMsg) {
                $tmp = parse_delimiters(substr($tmpMsg, 1), " ");
                $tmpMsg = COMMANDSYMBOL . implode(" ", $aliaser->performAlias($tmp));
            }
            $messageCont = implode(" | ", $messageCommands);
        } while ($pipeCount != substr_count($messageCont, "|"));
        $messageCommands = parse_delimiters($messageCont, "|");
    } else {
        $messageCommands = array($messageCont);
    }
    $pipeCommandCounter = 1;
    $stdin = array();
    //The output of a message if it is piped. If it returns multiple lines, they are concatenated
    //together with a space in between.
    if ($isCommand) {
        if ($mysql_statistics) {
            $queryString = sprintf("INSERT INTO `commands` (`time`,`server`,`nick`,`hostmask`,`type`,`channel`,`prealiser`,`message`,`choked`) VALUES ('%d','%s','%s','%s','%s','%s','%s','%s','%d')", time(), addslashes($server['host']), addslashes($messageNick), addslashes($messageMask), addslashes($messageType), addslashes($messageChan), addslashes($preAliaser), addslashes($messageCont), addslashes($choke));
            mysql_query($queryString, $mysql_statistics);
        }
        $stdinCnt = 1;
        foreach ($messageCommands as $message) {
            $counter = 1;
            foreach ($stdin as $stdinval) {
                $message = str_replace_outside_quotes("[in-" . $counter . "]", '"' . trim($stdin[$counter]) . '"', $message);
                $counter++;
            }
            if (isset($stdin[$stdinCnt - 1])) {
                $message = str_replace_outside_quotes("[in]", '"' . trim($stdin[$stdinCnt - 1]) . '"', $message);
            }
            $stdin[$stdinCnt] = "";
            $command = parse_delimiters(substr($message, 1, strlen($message)), ' ');
            $message = COMMANDSYMBOL . implode($command, " ");
            /*End aliasing. Output is the final (valid) command.*/
            /*Plugin messenger / pipe output manager*/
            foreach ($plugins as $key => $plugin) {
                if (in_array(trim($messageType . "." . strtolower(trim($command[0]))), $plugin['object']->getHooks())) {
                    //Get the permission level for the plugin, and the user.
                    if ($server["USERDATA"]->existsUserData("BawkBotPermissions", $messageChan, $messageNick, "PermissionLevel") && $server["USERDATA"]->existsUserData("BawkBotPermissions", $messageChan, $messageNick, "isAuthenticated")) {
                        $userPermissionsData = $server["USERDATA"]->getUserData("BawkBotPermissions", $messageChan, $messageNick);
                        $userPermissionsLevel = $userPermissionsData['isAuthenticated'] ? $userPermissionsData["PermissionLevel"] : 0;
                    } else {
                        $userPermissionsLevel = 0;
                        $server["USERDATA"]->addUserData("BawkBotPermissions", $messageChan, $messageNick, array("PermissionLevel" => 0, "isAuthenticated" => 0));
                    }
                    $pluginPermissionsLevel = $plugin['object']->getUserPermissions($server, $messageChan, $messageNick, $message);
                    //Make sure we have enough permissions, make sure the permissions on the plugin is set, and make sure we're not ignored.
                    if ((int) $userPermissionsLevel >= (int) $pluginPermissionsLevel && (int) $pluginPermissionsLevel <= 9000 && (int) $userPermissionsLevel >= 0) {
                        $finalMsg = $message;
                        if (substr(trim($message), -1, 1) == "&") {
                            $finalMsg = substr($finalMsg, 0, strlen($finalMsg) - 1);
                        }
                        //Push the data to the plugin, signal for it to process, and receive output.
                        $plugin['object']->pushMessage($server, $messageChan, $messageNick, $finalMsg, $messageType, $messageMask);
                        $plugin['object']->pluginLogic();
                        $output = $plugin['object']->receiveOutput();
                        foreach ($output as $msgKey => $toPrint) {
                            //If we have an ampersand at the end of our command, make sure we output the message no matter what.
                            if (substr(trim($message), -1, 1) == "&") {
                                $stdin[$stdinCnt] .= trim($toPrint->getMessage()) . " " . chr(3);
                            }
                            if ($pipeCommandCounter >= count($messageCommands) || substr(trim($message), -1, 1) == "&") {
                                //Print outputs of the plugin
                                if (trim($toPrint->getMessage()) != "") {
                                    $outMessages = str_split($toPrint->getMessage(), 400);
                                    foreach ($outMessages as $outMessage) {
                                        SendMessage($toPrint->getServer(), $toPrint->getChannel(), $outMessage);
                                    }
                                }
                            } else {
                                //Prepare it for the next pipe down the line...
                                /*chr(3) is used because it is neutral to the client (invisible), 
                                  doesn't break IRC, and is splitable.*/
                                $stdin[$stdinCnt] .= $toPrint->getMessage() . " " . chr(3);
                            }
                        }
                        $stdinCnt++;
                    } else {
                        if ($userPermissionsLevel >= 0) {
                            //Silence ignored people.
                            SendCommand($server, "PRIVMSG NickServ STATUS " . $messageNick . "\r\n");
                            SendMessage($server, $messageChan, "Permission Denied. To do this, you need level: " . $pluginPermissionsLevel . " for `" . strtolower(trim($command[0])) . "`, you have: " . $userPermissionsLevel);
                        }
                    }
                }
            }
            $pipeCommandCounter++;
        }
        //foreach (piping loop)
    }
    //This sends off the chat to plugins that request it. Note that a chr(4) is appended to the beginning of the message.
    if (!$choke) {
        foreach ($plugins as $key => $plugin) {
            if (in_array("BawkBot.logMsg", $plugin['object']->getHooks())) {
                $plugin['object']->pushMessage($server, $messageChan, $messageNick, chr(4) . $messageCont, $messageType, $messageMask);
                $plugin['object']->pluginLogic();
                $output = $plugin['object']->receiveOutput();
                foreach ($output as $idk => $toPrint) {
                    //Print outputs of the plugin
                    if (trim($toPrint->getMessage()) != "") {
                        $outMessages = str_split($toPrint->getMessage(), 400);
                        foreach ($outMessages as $outMessage) {
                            SendMessage($toPrint->getServer(), $toPrint->getChannel(), $outMessage);
                        }
                    }
                }
            }
        }
    }
    //Sends chat responses that bawkbot sends out.
    foreach ($plugins as $key => $plugin) {
        if (in_array("BawkBot.Messages", $plugin['object']->getHooks()) || in_array("BawkBot.logMsg", $plugin['object']->getHooks())) {
            foreach ($messageQueue as $outMessage) {
                $plugin['object']->pushMessage($server, $messageChan, "BawkBot", chr(4) . $outMessage, $messageType, $messageMask);
                $plugin['object']->pluginLogic();
            }
        }
    }
    $messageQueue = array();
}