public function process() { $o = new Object(); $o->setTeam($this->datas["team"]); switch ($this->datas["team_win"]) { case "Target_Bombed": $o->setType("bombeexploded"); $o->setTeamWin("T"); break; case "Terrorists_Win": $o->setType("normal"); $o->setTeamWin("T"); break; case "Target_Saved": $o->setType("saved"); $o->setTeamWin("CT"); break; case "Bomb_Defused": $o->setType("bombdefused"); $o->setTeamWin("CT"); break; case "CTs_Win": $o->setType("normal"); $o->setTeamWin("CT"); break; } return $o; }
private function processRoundScored(\eBot\Message\Type\RoundScored $message) { $this->addLog("RoundScore : " . $message->getTeamWin()); if ($this->getStatus() == self::STATUS_KNIFE) { $this->winKnife = $message->getTeamWin() == "T" ? "TERRORIST" : $message->getTeamWin(); $this->addLog($message->getTeamWin() . " won the knife round"); $this->setStatus(self::STATUS_END_KNIFE, true); $this->currentMap->setStatus(Map::STATUS_END_KNIFE, true); $team = $this->side['team_a'] == \strtolower($message->getTeamWin()) ? $this->teamAName : $this->teamBName; $this->say("{$team} won the knife, !stay or !switch"); $this->roundEndEvent = true; return; } 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))) { // Add point foreach ($this->players as $player) { $player->saveKillRound(); } $teamWin = $this->currentMap->addRound($message->getTeamWin()); $bestActionType = ""; $bestActionParam = array(); if ($message->type != "saved") { if ($this->specialSituation['active']) { $nbAlive = 0; foreach ($this->players as $k => $v) { if ($v->get("alive") && $v->get("currentSide") != "other") { $nbAlive++; } } $team = strtolower($message->team_win); if ($nbAlive == 1) { if ($this->specialSituation['side'] == strtolower($team) || $this->specialSituation['side'] == "both" || $this->specialSituation['side2'] == "both") { if ($this->specialSituation['side2'] == "both") { if ($this->specialSituation['side'] != "both") { $nbAlive = 0; foreach ($this->players as $k => $v) { if ($v->get("alive") && $v->get("currentSide") != "other") { $nbAlive++; $id = $k; } } if ($this->specialSituation['id'] != $id) { $this->addLog("situationSpecialchecker2 found another player"); $this->specialSituation['side'] = "both"; $this->specialSituation['situation'] = 1; } } } if ($this->specialSituation['side'] == "both") { $id = 0; $nbAlive = 0; foreach ($this->players as $k => $v) { if ($v->get("alive") && $v->get("currentSide") != "other") { $nbAlive++; $id = $k; } } $this->specialSituation['id'] = $id; if ($nbAlive == 2) { $this->addLog("Incohérence situation spéciale"); } else { if ($this->players[$id]) { $bestActionType = "1v1"; $bestActionParam = array("player" => $this->players[$id]->getId(), "playerName" => $this->players[$id]->get("name")); mysql_query("UPDATE players SET nb1 = nb1 + 1 WHERE id = '" . $this->players[$id]->getId() . "'") or Logger::error("Can't update " . $this->players[$id]->getId() . " situation"); $this->addLog("Situation spécial réussie 1v" . $this->specialSituation['situation'] . " (" . $this->players[$id]->get("name") . ")"); $this->addMatchLog("<b>" . htmlentities($this->players[$id]->get("name")) . "</b> a mis un 1v" . $this->specialSituation['situation'] . " !"); $this->players[$id]->inc("v1"); $text = \addslashes(\serialize(array("situation" => 1, "player" => $this->players[$id]->getId(), "playerName" => $this->players[$id]->get("name")))); // Round TimeLine \mysql_query("\n INSERT INTO `round`\n (`match_id`,`map_id`,`event_name`,`event_text`,`event_time`,`round_id`,`created_at`,`updated_at`)\n VALUES\n ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', '1vx_ok', '{$text}','" . $this->getRoundTime() . "', '" . $this->getNbRound() . "', NOW(), NOW())\n "); } } } else { $id = $this->specialSituation['id']; if ($this->players[$id]) { $bestActionType = "1v" . $this->specialSituation['situation']; $bestActionParam = array("player" => $this->players[$id]->getId(), "playerName" => $this->players[$id]->get("name")); $this->addMatchLog("<b>" . htmlentities($this->players[$id]->get("name")) . "</b> a mis un 1v" . $this->specialSituation['situation'] . " !"); mysql_query("UPDATE players SET nb" . $this->specialSituation['situation'] . " = nb" . $this->specialSituation['situation'] . " + 1 WHERE id='" . $this->players[$id]->getId() . "'") or Logger::error("Can't update " . $this->players[$id]->getId() . " situation"); $this->players[$id]->inc("v" . $this->specialSituation['situation']); $this->addLog("Situation spécial réussie 1v" . $this->specialSituation['situation'] . " (" . $this->players[$id]->get("name") . ")"); $text = \addslashes(\serialize(array("situation" => $this->specialSituation['situation'], "player" => $this->players[$id]->getId(), "playerName" => $this->players[$id]->get("name")))); // Round TimeLine \mysql_query("\n INSERT INTO `round`\n (`match_id`,`map_id`,`event_name`,`event_text`,`event_time`,`round_id`,`created_at`,`updated_at`)\n VALUES\n ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', '1vx_ok', '{$text}','" . $this->getRoundTime() . "', '" . $this->getNbRound() . "', NOW(), NOW())\n "); } } } } else { $this->addLog("Situation ratée - alive players: {$nbAlive}"); } } } if ($message->type == "bombdefused") { if ($this->gameBombDefuser != null) { $this->gameBombDefuser->inc("defuse"); $this->gameBombDefuser->inc("point", 3); $this->gameBombDefuser->saveScore(); // Round TimeLine \mysql_query("\n INSERT INTO `round`\n (`match_id`,`map_id`,`event_name`,`event_time`,`round_id`,`created_at`,`updated_at`)\n VALUES\n ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', 'bomb_defused', '" . $this->getRoundTime() . "', '" . $this->getNbRound() . "', NOW(), NOW())\n "); } } if ($message->type == "bombeexploded") { if ($this->gameBombPlanter != null) { $this->gameBombPlanter->inc("bombe"); $this->gameBombPlanter->inc("point", 2); $this->gameBombPlanter->saveScore(); // Round TimeLine \mysql_query("\n INSERT INTO `round`\n (`match_id`,`map_id`,`event_name`,`event_time`,`round_id`,`created_at`,`updated_at`)\n VALUES\n ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', 'bomb_exploded', '" . $this->getRoundTime() . "', '" . $this->getNbRound() . "', NOW(), NOW())\n "); } } // Round TimeLine \mysql_query("\n INSERT INTO `round`\n (`match_id`,`map_id`,`event_name`,`event_time`,`round_id`,`created_at`,`updated_at`)\n VALUES\n ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', 'round_end', '" . $this->getRoundTime() . "', '" . $this->getNbRound() . "', NOW(), NOW())\n "); $this->score["team_a"] = $this->currentMap->getScore1(); $this->score["team_b"] = $this->currentMap->getScore2(); if ($this->getNbRound() == $this->maxRound - 1) { // Ensure that halftime_pausetimer is set $this->rcon->send("mp_halftime_pausetimer 1"); } $this->say("" . $this->teamAName . " " . $this->currentMap->getScore1() . " - " . $this->currentMap->getScore2() . " " . $this->teamBName); $this->addLog($this->teamAName . " (" . $this->currentMap->getScore1() . ") - (" . $this->currentMap->getScore2() . ") " . $this->teamBName); $this->addMatchLog("Un round a été marqué - " . $this->teamAName . " (" . $this->currentMap->getScore1() . ") - (" . $this->currentMap->getScore2() . ") " . $this->teamBName); @mysql_query("UPDATE `matchs` SET score_a = '" . $this->score["team_a"] . "', score_b ='" . $this->score["team_b"] . "' WHERE id='" . $this->match_id . "'") or $this->addLog("Can't match " . $this->match_id . " scores", Logger::ERROR); // ROUND SUMMARY $nb = 0; $playerBest = null; foreach ($this->players as $player) { if ($player->killRound > $nb) { $playerBest = $player; $nb = $player->killRound; } elseif ($player->killRound == $nb) { $tmp = $player->currentSide == "ct" ? "CT" : "TERRORIST"; if ($tmp == $teamWin) { $playerBest = $player; } } } if ($playerBest != null) { $playerId = $playerBest->getId(); $playerFirstKill = (int) $playerBest->gotFirstKill; } else { $playerId = "NULL"; $playerFirstKill = "NULL"; } $data = $this->rcon->send("mp_backup_round_file_last"); if (preg_match('!"mp_backup_round_file_last" = "(?<backup>[a-zA-Z0-9\\-_\\.]+)"!', $data, $match)) { $backupFile = "'" . $match["backup"] . "'"; } else { $backupFile = 'NULL'; } if ($bestActionType == "") { if ($playerBest != null) { $bestActionType = $nb . "kill"; $bestActionParam = array("player" => $playerBest->getId(), "playerName" => $playerBest->get("name")); } else { $bestActionType = null; $bestActionParam = null; } } mysql_query("INSERT INTO round_summary\n (`match_id`,`map_id`,`score_a`,`score_b`,`bomb_planted`,`bomb_defused`,`bomb_exploded`,`ct_win`, `t_win`,`round_id`,`win_type`,`team_win`,`best_killer`,`best_killer_fk`,`best_killer_nb`,`best_action_type`,`best_action_param`, `backup_file_name`,`created_at`,`updated_at`)\n VALUES\n ('" . $this->match_id . "', '" . $this->currentMap->getMapId() . "', '" . $this->score["team_a"] . "', '" . $this->score["team_b"] . "',\n '" . ($this->gameBombPlanter != null) . "',\n '" . ($message->type == "bombdefused") . "',\n '" . ($message->type == "bombeexploded") . "',\n '" . ($message->getTeamWin() == "CT") . "',\n '" . ($message->getTeamWin() != "CT") . "',\n '" . ($this->getNbRound() - 1) . "',\n '" . $message->type . "','" . $teamWin . "',\n {$playerId}, " . $playerFirstKill . ", {$nb}, " . ($bestActionType != null ? "'{$bestActionType}'" : "NULL") . ", " . ($bestActionParam != null ? "'" . addslashes(serialize($bestActionParam)) . "'" : "NULL") . ",\n " . $backupFile . ",\n NOW(),\n NOW()\n )") or $this->addLog("Can't insert round summary match " . $this->match_id . " - " . mysql_error(), Logger::ERROR); // END ROUND SUMMARY // Prevent the OverTime bug if ($this->config_ot) { if ($this->score['team_a'] + $this->score['team_b'] == $this->maxRound * 2 - 1) { $this->rcon->send("mp_overtime_enable 1"); $this->rcon->send("mp_overtime_maxrounds " . $this->ot_maxround * 2); $this->rcon->send("mp_overtime_startmoney " . $this->ot_startmoney); $this->rcon->send("mp_overtime_halftime_pausetimer 1"); } } foreach ($this->players as &$player) { $player->snapshot($this->getNbRound() - 1); } $this->resetSpecialSituation(); if ($this->getStatus() == self::STATUS_FIRST_SIDE) { if ($this->score["team_a"] + $this->score["team_b"] == $this->maxRound) { $this->swapSides(); $this->setStatus(self::STATUS_WU_2_SIDE, true); $this->currentMap->setStatus(Map::STATUS_WU_2_SIDE, true); $this->saveScore(); $this->rcon->send("mp_halftime_pausetimer 1"); } } elseif ($this->getStatus() == self::STATUS_SECOND_SIDE) { if ($this->score["team_a"] + $this->score["team_b"] == $this->maxRound * 2 || $this->score["team_a"] > $this->maxRound && !$this->config_full_score || $this->score["team_b"] > $this->maxRound && !$this->config_full_score) { if ($this->score["team_a"] == $this->score["team_b"] && $this->config_ot) { $this->setStatus(self::STATUS_WU_OT_1_SIDE, true); $this->currentMap->setStatus(Map::STATUS_WU_OT_1_SIDE, true); $this->maxRound = $this->ot_maxround; $this->currentMap->addOvertime(); $this->nbOT++; $this->addLog("Going to overtime"); $this->say("Going to overtime"); $this->currentMap->setNbMaxRound($this->ot_maxround); //$this->rcon->send("mp_do_warmup_period 1; mp_warmuptime 30; mp_warmup_pausetimer 1"); //$this->rcon->send("mp_restartgame 1"); //$this->sendTeamNames(); } else { $this->currentMap->setStatus(Map::STATUS_MAP_ENDED, true); $this->lookEndingMatch(); } $this->saveScore(); } } elseif ($this->getStatus() == self::STATUS_OT_FIRST_SIDE) { $scoreToReach = $this->oldMaxround * 2 + $this->ot_maxround + $this->ot_maxround * 2 * ($this->nbOT - 1); if ($this->score["team_a"] + $this->score["team_b"] == $scoreToReach) { $this->setStatus(self::STATUS_WU_OT_2_SIDE, true); $this->currentMap->setStatus(Map::STATUS_WU_OT_2_SIDE, true); $this->saveScore(); $this->swapSides(); //$this->sendTeamNames(); // Not needed anymore with last updates // $this->rcon->send("mp_restartgame 1"); $this->rcon->send("mp_halftime_pausetimer 1"); } } elseif ($this->getStatus() == self::STATUS_OT_SECOND_SIDE) { $scoreToReach = $this->oldMaxround * 2 + $this->ot_maxround * 2 + $this->ot_maxround * 2 * ($this->nbOT - 1); $scoreToReach2 = $this->oldMaxround + $this->ot_maxround + $this->ot_maxround * ($this->nbOT - 1); if ($this->score["team_a"] + $this->score["team_b"] == $scoreToReach || $this->score["team_a"] > $scoreToReach2 || $this->score["team_b"] > $scoreToReach2) { if ($this->score["team_a"] == $this->score["team_b"]) { $this->setStatus(self::STATUS_WU_OT_1_SIDE, true); $this->currentMap->setStatus(Map::STATUS_WU_OT_1_SIDE, true); $this->maxRound = $this->ot_maxround; $this->currentMap->addOvertime(); $this->currentMap->setNbMaxRound($this->ot_maxround); $this->nbOT++; $this->addLog("Going to overtime"); //$this->rcon->send("mp_do_warmup_period 1; mp_warmuptime 30; mp_warmup_pausetimer 1"); //$this->rcon->send("mp_restartgame 1"); } else { $this->currentMap->setStatus(Map::STATUS_MAP_ENDED, true); $this->lookEndingMatch(); } $this->saveScore(); } } // Dispatching to Websocket $this->websocket['match']->sendData(json_encode(array('message' => 'status', 'content' => $this->getStatusText(false), 'id' => $this->match_id))); $this->websocket['match']->sendData(json_encode(array('message' => 'button', 'content' => $this->getStatus(), 'id' => $this->match_id))); $this->websocket['match']->sendData(json_encode(array('message' => 'score', 'scoreA' => $this->score['team_a'], 'scoreB' => $this->score['team_b'], 'id' => $this->match_id))); // Dispatching events $event = new \eBot\Events\Event\RoundScored(); $event->setMatch($this); $event->setTeamA($this->teamAName); $event->setTeamB($this->teamAName); $event->setScoreA($this->score["team_a"]); $event->setScoreB($this->score["team_b"]); $event->setStatus($this->getStatus()); \eBot\Events\EventDispatcher::getInstance()->dispatchEvent($event); } $this->roundEndEvent = true; }