public function startAll()
 {
     foreach ($this->plugins as $plugin) {
         try {
             Logger::debug("Starting plugin " . get_class($plugin));
             $plugin->onStart();
             Logger::debug("Attaching event");
             $events = $plugin->getEventList();
             if (is_array($events)) {
                 foreach ($events as $event) {
                     if (is_string($event)) {
                         EventDispatcher::getInstance()->addListener($plugin, $event);
                     }
                 }
             } else {
                 Logger::error("Event list is not an array");
             }
         } catch (\Exception $ex) {
             Logger::error("Error while starting " . get_class($plugin));
         }
     }
     if (count($this->plugins) > 0) {
         Logger::log("Plugins started");
     }
 }
Exemple #2
0
 private function processKill(\eBot\Message\Type\Kill $message)
 {
     $this->processPlayer($message->getUserId(), $message->getUserName(), $message->getUserTeam(), $message->getUserSteamid());
     $this->processPlayer($message->getKilledUserId(), $message->getKilledUserName(), $message->getKilledUserTeam(), $message->getKilledUserSteamid());
     if (!$this->waitForRestart && $this->enable && in_array($this->getStatus(), array(self::STATUS_FIRST_SIDE, self::STATUS_SECOND_SIDE, self::STATUS_OT_FIRST_SIDE, self::STATUS_OT_SECOND_SIDE))) {
         $killer = $this->findPlayer($message->userId, $message->userSteamid);
         $killed = $this->findPlayer($message->killedUserId, $message->killedUserSteamid);
         if ($this->firstFrag) {
             if ($killer != null) {
                 $killer->inc("firstKill");
                 $killer->gotFirstKill = true;
             }
             $this->firstFrag = false;
         }
         if ($killed != null) {
             $killed->set("alive", false);
         }
         if ($message->userTeam == $message->killedUserTeam) {
             if ($killer) {
                 $killer->inc("tk");
                 $killer->deinc("point");
             }
             if ($killed) {
                 $killed->inc("death");
             }
         } else {
             if ($killer) {
                 $killer->inc("killRound");
                 $killer->inc("kill");
                 $killer->inc("point");
                 if ($message->headshot) {
                     $killer->inc("hs");
                 }
             }
             if ($killed) {
                 $killed->inc("death");
             }
         }
         $killer_id = null;
         $killed_id = null;
         $killer_name = $message->userName;
         $killed_name = $message->killedUserName;
         if ($killer != null) {
             $killer_id = $killer->getId();
         }
         if ($killed != null) {
             $killed_id = $killed->getId();
         }
         //getNbRound
         \mysql_query("INSERT INTO player_kill\n                (`match_id`,`map_id`, `killer_team`,`killer_name`,`killer_id`,`killed_team`,`killed_name`,`killed_id`,`weapon`,`headshot`,`round_id`,`created_at`,`updated_at`)\n                VALUES\n                ('" . $this->match_id . "','" . $this->currentMap->getMapId() . "', '" . $message->userTeam . "', '" . addslashes($killer_name) . "', " . ($killer_id != null ? $killer_id : "NULL") . ", '" . $message->killedUserTeam . "' ,'" . addslashes($killed_name) . "', " . ($killed_id != null ? $killed_id : "NULL") . ", '" . $message->weapon . "', '" . $message->headshot . "','" . ($this->roundEndEvent ? $this->getNbRound() - 1 : $this->getNbRound()) . "', NOW(), NOW())\n                    ") or $this->addLog("Can't insert player_kill " . mysql_error(), Logger::ERROR);
         // Round Event
         $id = \mysql_insert_id();
         if (is_numeric($id)) {
             // Inserting round event
             \mysql_query("\n                    INSERT INTO `round`\n                    (`match_id`,`map_id`,`event_name`,`event_time`,`kill_id`,`round_id`,`created_at`,`updated_at`)\n                        VALUES\n                    ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', 'kill', '" . $this->getRoundTime() . "', {$id}, '" . ($this->roundEndEvent ? $this->getNbRound() - 1 : $this->getNbRound()) . "', NOW(), NOW())\n                        ");
         }
         // HeatMap !
         \mysql_query("INSERT INTO `players_heatmap`\n                            (`match_id`,`map_id`,`event_name`,`event_x`,`event_y`,`event_z`,`player_name`,`player_id`,`player_team`,`attacker_x`,`attacker_y`,`attacker_z`,`attacker_name`,`attacker_id`,`attacker_team`,`round_id`,`round_time`,`created_at`,`updated_at`) VALUES\n                            (" . $this->match_id . ", " . $this->currentMap->getMapId() . ", 'kill', '" . $message->killedPosX . "', '" . $message->killedPosY . "', '" . $message->killedPosZ . "','" . addslashes($message->killedUserName) . "', '" . $killed_id . "', '" . $message->killedUserTeam . "', '" . $message->killerPosX . "', '" . $message->killerPosY . "', '" . $message->killerPosZ . "', '" . $message->userName . "', '" . $killer_id . "', '" . $message->userTeam . "', '" . ($this->roundEndEvent ? $this->getNbRound() - 1 : $this->getNbRound()) . "', '" . $this->getRoundTime() . "', NOW(), NOW())\n                            ");
         if ($killer) {
             $killer->saveScore();
         }
         if ($killed) {
             $killed->saveScore();
         }
     }
     if ($message->killedUserTeam == "CT") {
         $this->nbLast["nb_ct"]--;
     } elseif ($message->killedUserTeam == "TERRORIST") {
         $this->nbLast["nb_t"]--;
     }
     $this->addLog($message->getUserName() . " killed " . $message->getKilledUserName() . " with " . $message->weapon . ($message->headshot ? " (headshot)" : "") . " (CT: " . $this->nbLast["nb_ct"] . " - T: " . $this->nbLast['nb_t'] . ")");
     $this->addMatchLog($this->getColoredUserNameHTML($message->getUserName(), $message->userTeam) . " killed " . $this->getColoredUserNameHTML($message->getKilledUserName(), $message->killedUserTeam) . " with " . $message->weapon . ($message->headshot ? " (headshot)" : "") . " (CT: " . $this->nbLast["nb_ct"] . " - T: " . $this->nbLast['nb_t'] . ")");
     $this->watchForSpecialSituation();
     if ($this->isMatchRound()) {
         $sendToWebsocket = json_encode(array('type' => 'kill', 'id' => $this->match_id, 'killer' => $message->getUserName(), 'killerPosX' => $message->killerPosX, 'killerPosY' => $message->killerPosY, 'weapon' => $message->getWeapon(), 'killed' => $message->getKilledUserName(), 'killedPosX' => $message->killedPosX, 'killedPosY' => $message->killedPosY, 'headshot' => $message->getHeadshot()));
         $this->websocket['livemap']->sendData($sendToWebsocket);
     }
     $event = new \eBot\Events\Event\Kill();
     $event->setMatch($this);
     $event->setUserId($message->getUserId());
     $event->setUserName($message->getUserName());
     $event->setUserTeam($message->getUserTeam());
     $event->setUserSteamid($message->getUserSteamid());
     $event->setKilledUserId($message->getKilledUserId());
     $event->setKilledUserName($message->getKilledUserName());
     $event->setKilledUserTeam($message->getKilledUserTeam());
     $event->setKilledUserSteamid($message->getKilledUserSteamid());
     $event->setHeadshot($message->getHeadshot());
     $event->setWeapon($message->getWeapon());
     \eBot\Events\EventDispatcher::getInstance()->dispatchEvent($event);
 }