/**
  *
  * @param string $function_name
  * @param int $instance_id
  * @return 2 - function was runing, 1 - function have been started, false - error, 3 - bad function
  */
 private function startFunction($function_name, $instance_id = false)
 {
     $function_name = mb_strtolower($function_name, "UTF-8");
     if (!isset($this->multibot_config[$function_name])) {
         return "3";
     }
     if (($finstance_id = $this->getInstanceId($function_name)) && !$instance_id) {
         $this->sendToInstance($finstance_id, "start " . $function_name);
         $status = $this->readFromInstance($finstance_id);
         if ($status == "runing") {
             return "2";
         } elseif ($status == "started") {
             return "1";
         } else {
             return false;
         }
     } elseif ($instance_id) {
         if ($finstance_id = $this->getInstanceId($function_name)) {
             $this->unsetFunction($function_name);
         }
         if (!isset($this->instance_list['instances'][$instance_id])) {
             return false;
         } else {
             $this->sendToInstance($instance_id, "start " . $function_name);
             $status = $this->readFromInstance($instance_id);
             if ($status == "runing") {
                 return "2";
             } elseif ($status == "started") {
                 return "1";
             } else {
                 return false;
             }
         }
     } else {
         if ($this->general_config['multibot_config']['protect_primary_instance']) {
             if ($this->multibot_config[$function_name]['general_config']['primary_instance']) {
                 $this->addFunction($function_name, 0);
                 $this->refreshFunctionsStatus();
                 return "1";
             } else {
                 $instance_list = $this->instance_list['instances'];
                 unset($instance_list[0]);
                 $instance_id = getSmallerIndex($instance_list);
                 $this->addFunction($function_name, $instance_id);
                 $this->refreshFunctionsStatus();
                 return "1";
             }
         }
         $instance_id = getSmallerIndex($this->instance_list['instances']);
         $this->addFunction($function_name, $instance_id);
         $this->refreshFunctionsStatus();
         return "1";
     }
 }
示例#2
0
     foreach ($multibot_config as $function_name => $function_vars) {
         if (!isset($function_vars['general_config']['weight'])) {
             $function_vars['general_config']['weight'] = 1;
             $multibotObject->addError($lang['commmands_mode']['empty_weight'] . " " . $function_name);
         }
         if (!isset($function_vars['general_config']['primary_instance'])) {
             $function_vars['general_config']['primary_instance'] = false;
         }
         if ($function_vars['general_config']['enable'] && $function_vars['general_config']['primary_instance']) {
             $instance_list[0]['functions'][] = $function_name;
             $instance_list[0]['weight'] += $function_vars['general_config']['weight'];
             if ($general_config['multibot_config']['protect_primary_instance']) {
                 $instance_list[0]['weight'] += 1000;
             }
         } elseif ($function_vars['general_config']['enable']) {
             $index = getSmallerIndex($instance_list);
             $instance_list[$index]['functions'][] = $function_name;
             $instance_list[$index]['weight'] += $function_vars['general_config']['weight'];
         }
     }
     foreach ($instance_list as $instance) {
         $multibotObject->createInstance($instance);
     }
 } else {
     $multibotObject->addInfo($lang['commands_mode']['only_commands']);
 }
 //*****************************************************************************
 //*********************************** Loop ************************************
 //*****************************************************************************
 $tsAdminSocket = $multibotObject->getTsAdminSocket();
 $whoAmi_timer = date('r', time() + 120);
示例#3
0
             }
         }
     } else {
         if (isset($this->conifg['multibotConfig'][$commandInfo['command'][1]]['primary_instance']) && $this->conifg['multibotConfig'][$commandInfo['command'][1]]['primary_instance'] == true) {
             $status = $this->sendToInstance(0, "start " . $commandInfo['command'][1]);
             $r = $this->readFromInstance(0);
             if (!$status) {
                 $id = 0;
                 $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['commands_instance_connect_error'] . $id);
             } elseif ($r == "started") {
                 $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['command_start_function_start']);
             } else {
                 $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['commands_unknown_error']);
             }
         } else {
             $id = getSmallerIndex($this->instanceList['instances']);
             $this->instanceList['instances'][$id]['functions'][] = $commandInfo['command'][1];
             $this->instanceList['instances'][$id]['weight'] = $this->instanceList['instances'][$id]['weight'] + $this->config['multibotConfig'][$commandInfo['command'][1]]['weight'];
             $status = $this->sendToInstance($id, "start " . $commandInfo['command'][1]);
             $r = $this->readFromInstance($id);
             if (!$status) {
                 $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['commands_instance_connect_error'] . $id);
             } elseif ($r == "started") {
                 $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['command_start_function_start']);
             } else {
                 $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['commands_unknown_error']);
             }
         }
     }
 } else {
     $tsAdmin->sendMessage(1, $commandInfo['clientId'], $this->lang['commands_unknown_function']);