diff --git a/Shootmania/Elite/Classes/Log.php b/Shootmania/Elite/Classes/Log.php index 2b02c8e..be80435 100644 --- a/Shootmania/Elite/Classes/Log.php +++ b/Shootmania/Elite/Classes/Log.php @@ -2,139 +2,414 @@ namespace ManiaLivePlugins\Shootmania\Elite\Classes; -class Log { - private $serverLogin; - +/** + * Finally, a light, permissions-checking logging class. + * + * Originally written for use with wpSearch + * + * Usage: + * $log = new KLogger('/var/log/', KLogger::INFO); + * $log->logInfo('Returned a million search results'); //Prints to the log file + * $log->logFatal('Oh dear.'); //Prints to the log file + * $log->logDebug('x = 5'); //Prints nothing due to current severity threshhold + * + * @author Kenny Katzgrau + * @since July 26, 2008 — Last update July 1, 2012 + * @link http://codefury.net + * @version 0.2.0 + */ + +/** + * Class documentation + */ +class Log +{ + /** + * Error severity, from low to high. From BSD syslog RFC, secion 4.1.1 + * @link http://www.faqs.org/rfcs/rfc3164.html + */ + const EMERG = 0; // Emergency: system is unusable + const ALERT = 1; // Alert: action must be taken immediately + const CRIT = 2; // Critical: critical conditions + const ERR = 3; // Error: error conditions + const WARN = 4; // Warning: warning conditions + const NOTICE = 5; // Notice: normal but significant condition + const INFO = 6; // XML RPC Callbacks + const DEBUG = 7; // SQL Queries + + //custom logging level + /** + * Log nothing at all + */ + const OFF = 8; + /** + * Alias for CRIT + * @deprecated + */ + const FATAL = 2; + + /** + * Internal status codes + */ + const STATUS_LOG_OPEN = 1; + const STATUS_OPEN_FAILED = 2; + const STATUS_LOG_CLOSED = 3; + + /** + * We need a default argument value in order to add the ability to easily + * print out objects etc. But we can't use NULL, 0, FALSE, etc, because those + * are often the values the developers will test for. So we'll make one up. + */ + const NO_ARGUMENTS = 'KLogger::NO_ARGUMENTS'; + + /** + * Current status of the log file + * @var integer + */ + private $_logStatus = self::STATUS_LOG_CLOSED; + /** + * Holds messages generated by the class + * @var array + */ + private $_messageQueue = array(); + /** + * Path to the log file + * @var string + */ + private $_logFilePath = null; + /** + * Current minimum logging threshold + * @var integer + */ + private $_severityThreshold = self::DEBUG; + /** + * This holds the file handle for this instance's log file + * @var resource + */ + private $_fileHandle = null; - function __construct($serverLogin) { - $this->serverLogin = $serverLogin; - $this->config = Config::getInstance(); - } - - public function Normal($message) { - if ($this->config->Normal == true) - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Normal_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Normal_Log-'" . $this->serverLogin . "'"); - } - } - else - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Normal_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Normal_Log-'" . $this->serverLogin . "'"); - } - } + private $serverLogin; + /** + * Standard messages produced by the class. Can be modified for il8n + * @var array + */ + private $_messages = array( + //'writefail' => 'The file exists, but could not be opened for writing. Check that appropriate permissions have been set.', + 'writefail' => 'The file could not be written to. Check that appropriate permissions have been set.', + 'opensuccess' => 'The log file was opened successfully.', + 'openfail' => 'The file could not be opened. Check permissions.', + ); + + /** + * Default severity of log messages, if not specified + * @var integer + */ + private static $_defaultSeverity = self::DEBUG; + /** + * Valid PHP date() format string for log timestamps + * @var string + */ + private static $_dateFormat = 'Y-m-d G:i:s'; + /** + * Octal notation for default permissions of the log file + * @var integer + */ + private static $_defaultPermissions = 0777; + /** + * Array of KLogger instances, part of Singleton pattern + * @var array + */ + private static $instances = array(); + + /** + * Partially implements the Singleton pattern. Each $logDirectory gets one + * instance. + * + * @param string $logDirectory File path to the logging directory + * @param integer $severity One of the pre-defined severity constants + * @return KLogger + */ + public static function instance($logDirectory = false, $severity = false, $serverlogin) + { + if ($severity === false) { + $severity = self::$_defaultSeverity; + } + + if ($logDirectory === false) { + if (count(self::$instances) > 0) { + return current(self::$instances); + } else { + $logDirectory = dirname(__FILE__); + } + } + + if (in_array($logDirectory, self::$instances)) { + return self::$instances[$logDirectory]; + } + + self::$instances[$logDirectory] = new self($logDirectory, $severity, $serverlogin); + + return self::$instances[$logDirectory]; } - - public function Spectator($message) { - if ($this->config->Spectator == true) - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Spectator_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Spectator_Log-'" . $this->serverLogin . "'"); - } - } - else - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Spectator_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Spectator_Log-'" . $this->serverLogin . "'"); - } - } - } - - public function Console($message) { - if ($this->config->Console == true) - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Console_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Console_Log-'" . $this->serverLogin . "'"); - } - } - else - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Console_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Console_Log-'" . $this->serverLogin . "'"); - } - } + + /** + * Class constructor + * + * @param string $logDirectory File path to the logging directory + * @param integer $severity One of the pre-defined severity constants + * @return void + */ + public function __construct($logDirectory, $severity, $serverlogin) + { + $logDirectory = rtrim($logDirectory, '\\/'); + + if ($severity === self::OFF) { + return; + } + + $this->_logFilePath = $logDirectory + . DIRECTORY_SEPARATOR + . 'log_' + . ''.date('Y-m-d').'_' + . ''.$serverlogin.'' + . '.txt'; + + $this->_severityThreshold = $severity; + if (!file_exists($logDirectory)) { + mkdir($logDirectory, self::$_defaultPermissions, true); + } + + if (file_exists($this->_logFilePath) && !is_writable($this->_logFilePath)) { + $this->_logStatus = self::STATUS_OPEN_FAILED; + $this->_messageQueue[] = $this->_messages['writefail']; + return; + } + + if (($this->_fileHandle = fopen($this->_logFilePath, 'a'))) { + $this->_logStatus = self::STATUS_LOG_OPEN; + $this->_messageQueue[] = $this->_messages['opensuccess']; + } else { + $this->_logStatus = self::STATUS_OPEN_FAILED; + $this->_messageQueue[] = $this->_messages['openfail']; + } } - - public function Debug($message) { - if ($this->config->Debug == true) - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Debug_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Debug_Log-'" . $this->serverLogin . "'"); - } - } - else - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Debug_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Debug_Log-'" . $this->serverLogin . "'"); - } - } + + /** + * Class destructor + */ + public function __destruct() + { + if ($this->_fileHandle) { + fclose($this->_fileHandle); + } } - - public function Callbacks($message) { - if ($this->config->Callbacks == true) - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Callbacks_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Callbacks_Log-'" . $this->serverLogin . "'"); - } - } - else - { - try - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Callbacks_Log-'" . $this->serverLogin . "'"); - } - catch(\Exception $e) - { - \ManiaLive\Utilities\Logger::log($message, true, "ElitePlugin_Callbacks_Log-'" . $this->serverLogin . "'"); - } - } - } - -} \ No newline at end of file + /** + * Writes a $line to the log with a severity level of DEBUG + * + * @param string $line Information to log + * @return void + */ + public function logDebug($line, $args = self::NO_ARGUMENTS) + { + $this->log(print_r($line, true), self::DEBUG); + } + + /** + * Returns (and removes) the last message from the queue. + * @return string + */ + public function getMessage() + { + return array_pop($this->_messageQueue); + } + + /** + * Returns the entire message queue (leaving it intact) + * @return array + */ + public function getMessages() + { + return $this->_messageQueue; + } + + /** + * Empties the message queue + * @return void + */ + public function clearMessages() + { + $this->_messageQueue = array(); + } + + /** + * Sets the date format used by all instances of KLogger + * + * @param string $dateFormat Valid format string for date() + */ + public static function setDateFormat($dateFormat) + { + self::$_dateFormat = $dateFormat; + } + + /** + * Writes a $line to the log with a severity level of INFO. Any information + * can be used here, or it could be used with E_STRICT errors + * + * @param string $line Information to log + * @return void + */ + public function logInfo($line, $args = self::NO_ARGUMENTS) + { + $this->log(print_r($line,true), self::INFO, $args); + } + + /** + * Writes a $line to the log with a severity level of NOTICE. Generally + * corresponds to E_STRICT, E_NOTICE, or E_USER_NOTICE errors + * + * @param string $line Information to log + * @return void + */ + public function logNotice($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::NOTICE, $args); + } + + /** + * Writes a $line to the log with a severity level of WARN. Generally + * corresponds to E_WARNING, E_USER_WARNING, E_CORE_WARNING, or + * E_COMPILE_WARNING + * + * @param string $line Information to log + * @return void + */ + public function logWarn($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::WARN, $args); + } + + /** + * Writes a $line to the log with a severity level of ERR. Most likely used + * with E_RECOVERABLE_ERROR + * + * @param string $line Information to log + * @return void + */ + public function logError($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::ERR, $args); + } + + /** + * Writes a $line to the log with a severity level of FATAL. Generally + * corresponds to E_ERROR, E_USER_ERROR, E_CORE_ERROR, or E_COMPILE_ERROR + * + * @param string $line Information to log + * @return void + * @deprecated Use logCrit + */ + public function logFatal($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::FATAL, $args); + } + + /** + * Writes a $line to the log with a severity level of ALERT. + * + * @param string $line Information to log + * @return void + */ + public function logAlert($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::ALERT, $args); + } + + /** + * Writes a $line to the log with a severity level of CRIT. + * + * @param string $line Information to log + * @return void + */ + public function logCrit($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::CRIT, $args); + } + + /** + * Writes a $line to the log with a severity level of EMERG. + * + * @param string $line Information to log + * @return void + */ + public function logEmerg($line, $args = self::NO_ARGUMENTS) + { + $this->log($line, self::EMERG, $args); + } + + /** + * Writes a $line to the log with the given severity + * + * @param string $line Text to add to the log + * @param integer $severity Severity level of log message (use constants) + */ + public function log($line, $severity, $args = self::NO_ARGUMENTS) + { + if ($this->_severityThreshold >= $severity) { + $status = $this->_getTimeLine($severity); + + $line = "$status $line"; + + if($args !== self::NO_ARGUMENTS) { + /* Print the passed object value */ + $line = $line . '; ' . var_export($args, true); + } + + $this->writeFreeFormLine($line . PHP_EOL); + } + } + + /** + * Writes a line to the log without prepending a status or timestamp + * + * @param string $line Line to write to the log + * @return void + */ + public function writeFreeFormLine($line) + { + if ($this->_logStatus == self::STATUS_LOG_OPEN + && $this->_severityThreshold != self::OFF) { + if (fwrite($this->_fileHandle, $line) === false) { + $this->_messageQueue[] = $this->_messages['writefail']; + } + } + } + + private function _getTimeLine($level) + { + $time = date(self::$_dateFormat); + + switch ($level) { + case self::EMERG: + return "$time - EMERG -->"; + case self::ALERT: + return "$time - ALERT -->"; + case self::CRIT: + return "$time - CRIT -->"; + case self::FATAL: # FATAL is an alias of CRIT + return "$time - FATAL -->"; + case self::NOTICE: + return "$time - NOTICE -->"; + case self::INFO: + return "$time - INFO -->"; + case self::WARN: + return "$time - WARN -->"; + case self::DEBUG: + return "$time - DEBUG -->"; + case self::ERR: + return "$time - ERROR -->"; + default: + return "$time - LOG -->"; + } + } +} diff --git a/Shootmania/Elite/Config.php b/Shootmania/Elite/Config.php index d15be19..5487428 100644 --- a/Shootmania/Elite/Config.php +++ b/Shootmania/Elite/Config.php @@ -16,6 +16,8 @@ class Config extends \ManiaLib\Utils\Singleton * @var int */ public $competition_id = 0; - + + /** boolean */ + public $ReplayLocalSave = true; } ?> diff --git a/Shootmania/Elite/Elite.php b/Shootmania/Elite/Elite.php index 7bd6b36..6738a10 100644 --- a/Shootmania/Elite/Elite.php +++ b/Shootmania/Elite/Elite.php @@ -70,9 +70,9 @@ class Elite extends \ManiaLive\PluginHandler\Plugin { private $playerIDs = array(); function onInit() { - $this->setVersion('1.0.5q'); + $this->setVersion('1.0.5r'); - $this->logger = new Log($this->storage->serverLogin); + $this->logger = new Log('./logs/', Log::DEBUG, $this->storage->serverLogin); $this->mapdirectory = $this->connection->getMapsDirectory(); } @@ -376,8 +376,8 @@ function onReady() { $this->connection->setModeScriptSettings(array('S_UseScriptCallbacks' => true)); - $this->connection->setModeScriptSettings(array('S_RestartMatchOnTeamChange' => true)); //Debug Way... - $this->connection->setModeScriptSettings(array('S_UsePlayerClublinks' => true)); //Debug Way... + $this->connection->setModeScriptSettings(array('S_RestartMatchOnTeamChange' => true)); //logDebug Way... + $this->connection->setModeScriptSettings(array('S_UsePlayerClublinks' => true)); //logDebug Way... $this->connection->setModeScriptSettings(array('S_Mode' => 1)); $this->connection->setCallVoteRatios(array(array('Command' => 'SetModeScriptSettingsAndCommands', 'Ratio' => 0.4 ))); @@ -494,6 +494,7 @@ function WarmUp_Extend($login) { $vote->cmdName = 'Echo'; $vote->cmdParam = array('Set WarmUp Extend', 'map_warmup_extend'); $this->connection->callVote($vote, 0.5, 0, 1); + $this->logger->logInfo("Extend WarmUp"); } function WarmUp_Stop($login) { @@ -501,6 +502,7 @@ function WarmUp_Stop($login) { $vote->cmdName = 'Echo'; $vote->cmdParam = array('Set Warmup Stop', 'map_warmup_end'); $this->connection->callVote($vote, 0.5, 0, 1); + $this->logger->logInfo("WarmUp is going to End"); } function pause($login) { @@ -508,32 +510,36 @@ function pause($login) { $vote->cmdName = 'Echo'; $vote->cmdParam = array('Set Map to Pause', 'map_pause'); $this->connection->callVote($vote, 0.5, 0, 1); + $this->logger->logInfo("Map is going to be paused"); } function S_Mode0($login) { $this->connection->setModeScriptSettings(array('S_Mode' => 0)); + $this->logger->logInfo("Set S_Mode to: Free"); } function S_Mode1($login) { $this->connection->setModeScriptSettings(array('S_Mode' => 1)); + $this->logger->logInfo("Set S_Mode to: Classic"); } function InitiateVotes($login){ $this->connection->setCallVoteRatiosEx(false, array( new Structures\VoteRatio('SetModeScriptSettingsAndCommands', 0.) )); + $this->logger->logInfo("Set Votes Active for all Players"); } function DeactivateVotes($login){ $this->connection->setCallVoteRatiosEx(false, array( new Structures\VoteRatio('SetModeScriptSettingsAndCommands', -1.) )); + $this->logger->logInfo("Set Votes to deactivate"); } function newmatch($login) { $match = $this->getServerCurrentMatch($this->storage->serverLogin); if ($match) { - //var_dump($match); $this->updateMatchState($match); } @@ -544,10 +550,12 @@ function newmatch($login) { function bo3($login) { $this->connection->setModeScriptSettings(array('S_MapWin' => 2)); + $this->logger->logInfo("Set S_MapWin to: 2"); } function bo5($login) { $this->connection->setModeScriptSettings(array('S_MapWin' => 3)); + $this->logger->logInfo("Set S_MapWin to: 3"); } /* Callbacks and Methods */ @@ -559,7 +567,7 @@ public function onVoteUpdated($stateName, $login, $cmdName, $cmdParam) { SET `NextMap` = '1' where `match_id` = " . $this->db->quote($this->MatchNumber) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; $this->db->execute($queryNextMap); - $this->logger->Debug($queryNextMap); + $this->logger->logDebug($queryNextMap); } } } @@ -617,7 +625,7 @@ function getServerCurrentMatch($serverLogin) { 'SELECT id FROM matches ' . 'where MatchEnd = "0000-00-00 00:00:00" and `matchServerLogin` = ' . $this->db->quote($serverLogin) . '')->fetchSingleValue(); - $this->logger->Normal($CurrentMatchÏd); + $this->logger->logDebug($CurrentMatchÏd); return $this->db->execute( 'SELECT id FROM matches ' . 'where MatchEnd = "0000-00-00 00:00:00" and `matchServerLogin` = ' . $this->db->quote($serverLogin) . @@ -627,16 +635,16 @@ function getServerCurrentMatch($serverLogin) { function updateMatchState($matchId) { $state = date('Y-m-d H:i:s'); $matches_update = "UPDATE matches SET `MatchEnd` = " . $this->db->quote($state) . " WHERE id = " . intval($matchId) . ""; - $this->logger->Debug($matches_update); + $this->logger->logDebug($matches_update); $this->db->execute($matches_update); $match_maps_update = "UPDATE match_maps SET `MapEnd` = " . $this->db->quote($state) . " WHERE match_id = " . intval($matchId) . ""; - $this->logger->Debug($match_maps_update); + $this->logger->logDebug($match_maps_update); $this->db->execute($match_maps_update); } public function onModeScriptCallback($event, $json) { - $this->logger->Callbacks($event); - $this->logger->Callbacks($json); + $this->logger->logInfo($event); + $this->logger->logInfo($json); switch ($event) { case 'BeginMatch': $this->onXmlRpcEliteMatchStart(new JsonCallbacks\BeginMatch($json)); @@ -685,11 +693,11 @@ public function onModeScriptCallback($event, $json) { $this->BlueScoreMatch = $ClanEndMatchDataVariables['Clan1MatchPoints']; $this->RedScoreMatch = $ClanEndMatchDataVariables['Clan2MatchPoints']; $qmmsb = "UPDATE `matches` SET `Matchscore_blue` = " . $this->db->quote($this->BlueScoreMatch) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsb); + $this->logger->logDebug($qmmsb); $this->db->execute($qmmsb); //MatchScore Red $qmmsr = "UPDATE `matches` SET Matchscore_red = " . $this->db->quote($this->RedScoreMatch) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsr); + $this->logger->logDebug($qmmsr); $this->db->execute($qmmsr); } $this->onXmlRpcEliteEndMatch(new JsonCallbacks\EndMatch($json)); @@ -700,11 +708,11 @@ public function onModeScriptCallback($event, $json) { $this->BlueScoreMatch = $ClanEndMapDataVariables['Clan1MatchPoints']; $this->RedScoreMatch = $ClanEndMapDataVariables['Clan2MatchPoints']; $qmmsb = "UPDATE `matches` SET `Matchscore_blue` = " . $this->db->quote($this->BlueScoreMatch) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsb); + $this->logger->logDebug($qmmsb); $this->db->execute($qmmsb); //MatchScore Red $qmmsr = "UPDATE `matches` SET Matchscore_red = " . $this->db->quote($this->RedScoreMatch) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsr); + $this->logger->logDebug($qmmsr); $this->db->execute($qmmsr); } $this->onXmlRpcEliteEndMap(new JsonCallbacks\EndMap($json)); @@ -715,11 +723,11 @@ public function onModeScriptCallback($event, $json) { $this->BlueScoreMatch = $json[0]; $this->RedScoreMatch = $json[1]; $qmmsb = "UPDATE `matches` SET `Matchscore_blue` = " . $this->db->quote($this->BlueScoreMatch) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsb); + $this->logger->logDebug($qmmsb); $this->db->execute($qmmsb); //MatchScore Red $qmmsr = "UPDATE `matches` SET Matchscore_red = " . $this->db->quote($this->RedScoreMatch) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsr); + $this->logger->logDebug($qmmsr); $this->db->execute($qmmsr); } break; @@ -740,7 +748,7 @@ function updateServerChallenges() { //get database challenges $q = "SELECT * FROM `maps`;"; $query = $this->db->query($q); - $this->logger->Debug($q); + $this->logger->logDebug($q); $databaseUid = array(); @@ -769,7 +777,7 @@ public function insertMap($data) { imagejpeg($mapInfo->thumbnail, './www/media/images/thumbnails/'.$mapInfo->uid.'.jpg', 100); } $q = "INSERT INTO `maps` (`uid`, `name`, `author`) VALUES (" . $this->db->quote($data->uId) . "," . $this->db->quote($data->name) . "," . $this->db->quote($data->author) . ")"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->query($q); } @@ -790,7 +798,7 @@ function insertPlayer($player) { $zone[2] = "World"; } $q = "SELECT * FROM `players` WHERE `login` = " . $this->db->quote($player->login) . ";"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $execute = $this->db->execute($q); if ($execute->recordCount() == 0) { @@ -805,7 +813,7 @@ function insertPlayer($player) { )"; $this->db->execute($q); $this->playerIDs[$player->login] = $this->db->insertID(); - $this->logger->Debug($q); + $this->logger->logDebug($q); $name = \ManiaLib\Utils\Formatting::stripColors(\ManiaLib\Utils\Formatting::stripStyles($player->nickName)); $qnick = "INSERT INTO `player_nicknames` ( `player_id`, @@ -819,14 +827,14 @@ function insertPlayer($player) { " . $this->db->quote($this->competition_id) . " )"; $this->db->execute($qnick); - $this->logger->debug($qnick); + $this->logger->logDebug($qnick); } else { $q = "SELECT * FROM `players` WHERE `login` = " . $this->db->quote($player->login) . ";"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $getplayerid = $this->db->execute($q)->fetchObject(); $q = "SELECT * FROM `player_nicknames` WHERE `player_id` = " . $this->db->quote($getplayerid->id) . " and `competition_id` = " . $this->db->quote($this->competition_id) . ";"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $executeids = $this->db->execute($q); if ($executeids->recordCount() == 0) { @@ -841,7 +849,7 @@ function insertPlayer($player) { " . $this->db->quote($player->nickName) . ", " . $this->db->quote($name) . ", " . $this->db->quote($this->competition_id) . ");"; - $this->logger->debug($qnick); + $this->logger->logDebug($qnick); $this->db->execute($qnick); }else{ @@ -850,7 +858,7 @@ function insertPlayer($player) { `player_nickname_Clean` = " . $this->db->quote($name) . " WHERE `player_id` = " . $this->db->quote($getplayerid->id) . " AND `competition_id` = " . $this->db->quote($this->competition_id) . ";"; - $this->logger->debug($qnick); + $this->logger->logDebug($qnick); $this->db->execute($qnick); } } @@ -863,7 +871,7 @@ function onXmlRpcEliteBeginWarmUp(JsonCallbacks\BeginWarmup $content) { WHERE `match_id` =" . $this->db->quote($this->MatchNumber) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); } else { @@ -883,7 +891,7 @@ function onXmlRpcEliteEndWarmUp(JsonCallbacks\EndWarmup $content) { WHERE `match_id` = " . $this->db->quote($this->MatchNumber) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); } else { @@ -924,7 +932,7 @@ function onXmlRpcEliteMatchStart(JsonCallbacks\BeginMatch $content) { " . $this->db->quote($this->storage->serverLogin) . ", " . $this->db->quote($this->competition_id) . " )"; - $this->logger->Debug($qmatch); + $this->logger->logDebug($qmatch); $this->db->execute($qmatch); $this->MatchNumber = $this->db->insertID(); } @@ -932,7 +940,7 @@ function onXmlRpcEliteMatchStart(JsonCallbacks\BeginMatch $content) { function onXmlRpcEliteMapStart(JsonCallbacks\BeginMap $content) { $mapmatch = "SELECT * FROM `match_maps` WHERE `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `map_id` = " . $this->db->quote($this->getMapid()) . ""; - $this->logger->Debug($mapmatch); + $this->logger->logDebug($mapmatch); $mapmatchexecute = $this->db->execute($mapmatch); if ($mapmatchexecute->recordCount() == 0) { $qmapmatch = "INSERT INTO `match_maps` ( @@ -950,7 +958,7 @@ function onXmlRpcEliteMapStart(JsonCallbacks\BeginMap $content) { '" . date('Y-m-d H:i:s') . "', " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($qmapmatch); + $this->logger->logDebug($qmapmatch); $this->db->execute($qmapmatch); $this->MapNumber = $this->db->insertID(); } else { @@ -986,11 +994,11 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { $qcblnk = "SELECT * FROM `clublinks` WHERE `Clublink_Name` = " . $this->db->quote($blue->name) . ";"; - $this->logger->Debug($qcblnk); + $this->logger->logDebug($qcblnk); $bluename = $this->db->execute($qcblnk)->fetchObject(); $qcblnk = "SELECT * FROM `clublinks` WHERE `Clublink_Name` = " . $this->db->quote($red->name) . ";"; - $this->logger->Debug($qcblnk); + $this->logger->logDebug($qcblnk); $redname = $this->db->execute($qcblnk)->fetchObject(); $MatchName = '' . $bluename->Clublink_Name_Clean . ' vs ' . $redname->Clublink_Name_Clean . ''; @@ -1011,7 +1019,7 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { teamBlue_emblem = " . $this->db->quote($blue->emblemUrl) . ", teamBlue_RGB = " . $this->db->quote($blue->rGB) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsb); + $this->logger->logDebug($qmmsb); $this->db->execute($qmmsb); $qmmsr = "UPDATE `matches` @@ -1019,13 +1027,13 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { teamRed_emblem = " . $this->db->quote($red->emblemUrl) . ", teamRed_RGB = " . $this->db->quote($red->rGB) . " WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qmmsr); + $this->logger->logDebug($qmmsr); $this->db->execute($qmmsr); foreach ($this->storage->players as $login => $player) { $shots_table = "SELECT * FROM `shots` WHERE `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `round_id` = " . $this->db->quote($content->turnNumber) . " and `player_id` = " . $this->db->quote($this->getPlayerId($login)) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ";"; - $this->logger->Debug($shots_table); + $this->logger->logDebug($shots_table); $execute = $this->db->execute($shots_table); if ($execute->recordCount() == 0) { $shots_insert = "INSERT INTO `shots` ( @@ -1047,14 +1055,14 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { '0', " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($shots_insert); + $this->logger->logDebug($shots_insert); $this->db->execute($shots_insert); } else { } $playermapinfo = "SELECT * FROM `player_maps` WHERE `player_id` = " . $this->db->quote($this->getPlayerId($login)) . " AND `match_id` = " . $this->db->quote($this->MatchNumber) . " AND `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ";"; - $this->logger->Debug($playermapinfo); + $this->logger->logDebug($playermapinfo); $pmiexecute = $this->db->execute($playermapinfo); @@ -1073,7 +1081,7 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { " . $this->db->quote($this->storage->serverLogin) . " )"; //var_dump($pmi); - $this->logger->Debug($pmi); + $this->logger->logDebug($pmi); $this->db->execute($pmi); } } //end foreach @@ -1083,7 +1091,7 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { $attackingClan = $teams[$content->attackingClan]; $q = "SELECT * FROM `match_details` WHERE `map_id` = " . $this->db->quote($this->getMapid()) . " and `team_id` = " . $this->db->quote($this->getTeamid($attackingClan->clubLinkUrl, $attackingClan->name)) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ";"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $execute = $this->db->execute($q); if ($execute->recordCount() == 0) { $q = "INSERT INTO `match_details` ( @@ -1109,7 +1117,7 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { '0', " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); } else { @@ -1122,7 +1130,7 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { `match_id` = " . $this->db->quote($this->MatchNumber) . " AND `team_id` = " . $this->db->quote($this->getTeamid($defendingClan->clubLinkUrl, $defendingClan->name)) . " AND `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ";"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $execute = $this->db->execute($q); if ($execute->recordCount() == 0) { @@ -1149,7 +1157,7 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { '0', " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); } else { @@ -1167,14 +1175,14 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { `match_id` = " . $this->db->quote($this->MatchNumber) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($mapmatchAtk); + $this->logger->logDebug($mapmatchAtk); $this->db->execute($mapmatchAtk); $q = "SELECT * FROM `player_maps` WHERE `player_id` = " . $this->db->quote($AtkPlayer) . " AND `match_id` = " . $this->db->quote($this->MatchNumber) . " AND `match_map_id` = " . $this->db->quote($this->MapNumber) . " AND `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $Atker = $this->db->execute($q)->fetchObject(); $q = "UPDATE `player_maps` @@ -1184,12 +1192,13 @@ function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { `match_map_id` = " . $this->db->quote($this->MapNumber) . " AND `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " AND `match_id` = " . $this->MatchNumber . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); } } function updateClublink($url) { + $this->logger->logWarn('ClublinkURL: '.$url.''); $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers @@ -1216,11 +1225,15 @@ function updateClublink($url) { $xml = simplexml_load_string($content); // incase the xml is malformed, bail out - if ($xml === false) - return; + if ($xml === false){ + $this->logger->logWarn("XML is not correct"); + return; + } - if ($xml->getName() != "club") + if ($xml->getName() != "club"){ + $this->logger->logDebug("Clublink is not Correct or not a proper Clublink XML"); return; + } $zone = explode("|", $xml->zone); if ($zone[0] == "") { @@ -1228,12 +1241,12 @@ function updateClublink($url) { } $qcblnk = "SELECT * FROM `clublinks` WHERE `Clublink_URL` = " . $this->db->quote($url) . ";"; - $this->logger->Debug($qcblnk); + $this->logger->logDebug($qcblnk); $execute = $this->db->execute($qcblnk); - $this->logger->Debug("Select Clublinks"); + $this->logger->logDebug("Select Clublinks"); if ($execute->recordCount() == 0) { - $this->logger->Debug("Insert Clublinks"); + $this->logger->logDebug("Insert Clublinks"); $name = \ManiaLib\Utils\Formatting::stripColors(\ManiaLib\Utils\Formatting::stripStyles($xml->name)); $name = preg_replace('/[^A-Za-z0-9 _\-\+\&]/','',$name); $qClublink = "INSERT INTO `clublinks` ( @@ -1254,7 +1267,7 @@ function updateClublink($url) { " . $this->db->quote($url) . " )"; $this->db->execute($qClublink); - $this->logger->Debug($qClublink); + $this->logger->logDebug($qClublink); } else { $name = \ManiaLib\Utils\Formatting::stripColors(\ManiaLib\Utils\Formatting::stripStyles($xml->name)); $name = preg_replace('/[^A-Za-z0-9 _\-\+\&]/','',$name); @@ -1267,13 +1280,13 @@ function updateClublink($url) { `Clublink_Secondary_RGB` = " . $this->db->quote($xml->color['secondary']) . " WHERE `Clublink_URL` = " . $this->db->quote($url) . ""; $this->db->execute($UClublink); - $this->logger->Debug($UClublink); + $this->logger->logDebug($UClublink); } } function onXmlRpcEliteEndTurn(JsonCallbacks\EndTurn $content) { $message = 'Blue - Red: '.$this->BlueMapScore.' - '.$this->RedMapScore.''; - $this->logger->Console($message); + $this->logger->logNotice($message); $attackingClan = $this->connection->getTeamInfo($content->attackingClan); $defendingClan = $this->connection->getTeamInfo($content->defendingClan); @@ -1285,70 +1298,78 @@ function onXmlRpcEliteEndTurn(JsonCallbacks\EndTurn $content) { WHERE `match_id` = " . $this->db->quote($this->MatchNumber) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($mapmatchAtk); + $this->logger->logDebug($mapmatchAtk); $this->db->execute($mapmatchAtk); $qatk = "UPDATE `match_details` SET `attack` = attack + 1 WHERE `team_id` = " . $this->db->quote($this->getTeamid($attackingClan->clubLinkUrl, $attackingClan->name)) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($qatk); + $this->logger->logDebug($qatk); $this->db->execute($qatk); if ($content->winType == 'Capture') { + $message = 'pole Captured by: '.$content->attackingPlayer->login.''; + $this->logger->logNotice($message); $qcapture = "UPDATE `match_details` SET `capture` = capture + 1 WHERE `team_id` = " . $this->db->quote($this->getTeamid($attackingClan->clubLinkUrl, $attackingClan->name)) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($qcapture); + $this->logger->logDebug($qcapture); $this->db->execute($qcapture); $attackerId = $this->getPlayerId($content->attackingPlayer->login); $q = "UPDATE `player_maps` SET `atkSucces` = atkSucces + 1 WHERE `player_id` = " . $this->db->quote($attackerId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; $this->db->execute($q); - $this->logger->Debug($q); + $this->logger->logDebug($q); } if ($content->winType == 'DefenseEliminated') { + $message = ''.$attackingClan->name.' eliminated defending clan: '.$defendingClan->name.''; + $this->logger->logNotice($message); $qawe = "UPDATE `match_details` SET `attackWinEliminate` = attackWinEliminate + 1 WHERE `team_id` = " . $this->db->quote($this->getTeamid($attackingClan->clubLinkUrl, $attackingClan->name)) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($qawe); + $this->logger->logDebug($qawe); $this->db->execute($qawe); $attackerId = $this->getPlayerId($content->attackingPlayer->login); $q = "UPDATE `player_maps` SET `atkSucces` = atkSucces + 1 WHERE `player_id` = " . $this->db->quote($attackerId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; $this->db->execute($q); - $this->logger->Debug($q); + $this->logger->logDebug($q); } $qdef = "UPDATE `match_details` SET `defence` = defence + 1 WHERE `team_id` = " . $this->db->quote($this->getTeamid($defendingClan->clubLinkUrl, $defendingClan->name)) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($qdef); + $this->logger->logDebug($qdef); $this->db->execute($qdef); if ($content->winType == 'TimeLimit') { + $message = 'Defending Clan wins on TimeOver.'; + $this->logger->logNotice($message); $qtl = "UPDATE `match_details` SET `timeOver` = timeOver + 1 WHERE `team_id` = " . $this->db->quote($this->getTeamid($defendingClan->clubLinkUrl, $defendingClan->name)) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($qtl); + $this->logger->logDebug($qtl); $this->db->execute($qtl); $attackerId = $this->getPlayerId($content->attackingPlayer->login); $q = "UPDATE `player_maps` SET `timeOver` = timeOver + 1 WHERE `player_id` = " . $this->db->quote($attackerId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; $this->db->execute($q); - $this->logger->Debug($q); + $this->logger->logDebug($q); } if ($content->winType == 'AttackEliminated') { + $message = ''.$defendingClan->name.' eliminated Attacking clan: '.$attackingClan->name.''; + $this->logger->logNotice($message); $qde = "UPDATE `match_details` SET `defenceWinEliminate` = defenceWinEliminate + 1 WHERE `team_id` = " . $this->db->quote($this->getTeamid($defendingClan->clubLinkUrl, $defendingClan->name)) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($qde); + $this->logger->logDebug($qde); $this->db->execute($qde); } @@ -1363,7 +1384,9 @@ function onXmlRpcEliteEndTurn(JsonCallbacks\EndTurn $content) { $qth = "UPDATE `player_maps` SET `elimination_3x` = elimination_3x + 1 WHERE `player_id` = " . $this->db->quote($PlayerIdEndTurn) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($qth); + $this->logger->logDebug($qth); + $message = ''.$playerlogin.' shot attacker 3 times in round.'; + $this->logger->logNotice($message); $this->db->execute($qth); } } @@ -1383,7 +1406,7 @@ function onXmlRpcEliteArmorEmpty(JsonCallbacks\OnArmorEmpty $content) { $victim = $content->event->victim; if ($shooter == NULL) { - $this->logger->Normal('Player ' . $victim->login . ' was killed in offzone.'); + $this->logger->logNotice('Player ' . $victim->login . ' was killed in offzone.'); return; } @@ -1403,50 +1426,50 @@ function onXmlRpcEliteArmorEmpty(JsonCallbacks\OnArmorEmpty $content) { " . $this->db->quote($this->getMapid()) . ", " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); // update kill/death statistics $shooterId = $this->getPlayerId($content->event->shooter->login); $q = "UPDATE `player_maps` SET `kills` = kills + 1 WHERE `player_id` = " . $this->db->quote($shooterId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); $eliminations_table = "UPDATE `shots` SET `eliminations` = eliminations + 1, `weapon_id` = " . $this->db->quote($content->event->weaponNum) . " WHERE `player_id` = " . $this->db->quote($shooterId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `round_id` = " . $this->db->quote($this->TurnNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($eliminations_table); + $this->logger->logDebug($eliminations_table); $this->db->execute($eliminations_table); $victimId = $this->getPlayerId($content->event->victim->login); $q = "UPDATE `player_maps` SET `deaths` = deaths + 1 WHERE `player_id` = " . $this->db->quote($victimId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; $this->db->execute($q); - $this->logger->Debug($q); + $this->logger->logDebug($q); - $this->logger->Normal('[' . date('H:i:s') . '] [ShootMania] [Elite] ' . $content->event->victim->login . ' was killed by ' . $content->event->shooter->login); + $this->logger->logDebug('[' . date('H:i:s') . '] [ShootMania] [Elite] ' . $content->event->victim->login . ' was killed by ' . $content->event->shooter->login); } function onXmlRpcEliteShoot(JsonCallbacks\OnShoot $content) { $message = ''.$content->event->shooter->login.' shot with '.$content->event->weaponNum.''; - $this->logger->Normal($message); + $this->logger->logNotice($message); if (!isset($this->TurnNumber)) $this->TurnNumber = 0; $shooterId = $this->getPlayerId($content->event->shooter->login); $q = "UPDATE `player_maps` SET `shots` = shots + 1 WHERE `player_id` = " . $this->db->quote($shooterId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); $shots_table = "UPDATE `shots` SET `shots` = shots + 1, `weapon_id` = " . $this->db->quote($content->event->weaponNum) . " WHERE `player_id` = " . $this->db->quote($shooterId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `round_id` = " . $this->db->quote($this->TurnNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($shots_table); + $this->logger->logDebug($shots_table); $this->db->execute($shots_table); } function onXmlRpcEliteHit(JsonCallbacks\OnHit $content) { $message = ''.$content->event->shooter->login.' hit '.$content->event->victim->login.' with '.$content->event->weaponNum.''; - $this->logger->Normal($message); + $this->logger->logNotice($message); if (!isset($this->TurnNumber)) $this->TurnNumber = 0; @@ -1455,22 +1478,22 @@ function onXmlRpcEliteHit(JsonCallbacks\OnHit $content) { $shooterId = $this->getPlayerId($content->event->shooter->login); $q = "UPDATE `player_maps` SET `hits` = hits + 1 WHERE `player_id` = " . $this->db->quote($shooterId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); $hits_table = "UPDATE `shots` SET `hits` = hits + 1, `weapon_id` = " . $this->db->quote($content->event->weaponNum) . " WHERE `player_id` = " . $this->db->quote($shooterId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `round_id` = " . $this->db->quote($this->TurnNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($hits_table); + $this->logger->logDebug($hits_table); $this->db->execute($hits_table); // victim info $victimId = $this->getPlayerId($content->event->victim->login); $q1 = "UPDATE `player_maps` SET `counterhits` = counterhits + 1 WHERE `player_id` = " . $this->db->quote($victimId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($q1); + $this->logger->logDebug($q1); $this->db->execute($q1); $counterhits_table = "UPDATE `shots` SET `counterhits` = counterhits + 1, `weapon_id` = " . $this->db->quote($content->event->weaponNum) . " WHERE `player_id` = " . $this->db->quote($victimId) . " and `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `round_id` = " . $this->db->quote($this->TurnNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($counterhits_table); + $this->logger->logDebug($counterhits_table); $this->db->execute($counterhits_table); // hitdistance @@ -1495,13 +1518,13 @@ function onXmlRpcEliteHit(JsonCallbacks\OnHit $content) { " . $this->db->quote($this->getWeaponName($content->event->weaponNum)) . ", " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($qhitdist); + $this->logger->logDebug($qhitdist); $this->db->execute($qhitdist); } function onXmlRpcEliteCapture(JsonCallbacks\OnCapture $content) { $message = ''.$content->event->player->login.' captured the pole'; - $this->logger->Normal($message); + $this->logger->logNotice($message); $map = $this->storage->currentMap; $qCap = "INSERT INTO `captures` ( @@ -1517,7 +1540,7 @@ function onXmlRpcEliteCapture(JsonCallbacks\OnCapture $content) { " . $this->db->quote($this->getMapid()) . ", " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($qCap); + $this->logger->logDebug($qCap); $this->db->execute($qCap); // update capture statistics @@ -1528,13 +1551,13 @@ function onXmlRpcEliteCapture(JsonCallbacks\OnCapture $content) { `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); } function onXmlRpcEliteNearMiss(JsonCallbacks\OnNearMiss $content) { $message = ''.$content->event->shooter->login.' did a nearmissdist of '.$content->event->missDist.' cm'; - $this->logger->Normal($message); + $this->logger->logNotice($message); $shooterId = $this->getPlayerId($content->event->shooter->login); $q = "UPDATE `player_maps` SET nearmisses = nearmisses + 1 @@ -1542,7 +1565,7 @@ function onXmlRpcEliteNearMiss(JsonCallbacks\OnNearMiss $content) { `match_map_id` = " . $this->db->quote($this->MapNumber) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `match_id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); $this->db->execute($q); $qnearmiss = "INSERT INTO `nearmisses` ( @@ -1564,19 +1587,19 @@ function onXmlRpcEliteNearMiss(JsonCallbacks\OnNearMiss $content) { " . $this->db->quote($this->getWeaponName($content->event->weaponNum)) . ", " . $this->db->quote($this->storage->serverLogin) . " )"; - $this->logger->Debug($qnearmiss); + $this->logger->logDebug($qnearmiss); $this->db->execute($qnearmiss); } function onXmlRpcEliteEndMap(JsonCallbacks\EndMap $content) { $message = 'Blue: '.$content->clan1MapScore.' - Red: '.$content->clan2MapScore.''; - $this->logger->Normal($message); + $this->logger->logNotice($message); $querymapEnd = "UPDATE `match_maps` SET `MapEnd` = '" . date('Y-m-d H:i:s') . "', `TurnNumber` = " . $this->db->quote($this->TurnNumber) . ", `AllReady` = '0' where `match_id` = " . $this->db->quote($this->MatchNumber) . " and `map_id` = " . $this->db->quote($this->getMapid()) . " and `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . ""; - $this->logger->Debug($querymapEnd); + $this->logger->logDebug($querymapEnd); $this->db->execute($querymapEnd); } @@ -1589,8 +1612,9 @@ function onXmlRpcEliteEndMatch(JsonCallbacks\EndMatch $content) { WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($queryMapWinSettingsEnd); + $this->logger->logDebug($queryMapWinSettingsEnd); $this->db->execute($queryMapWinSettingsEnd); + if($this->config->ReplayLocalSave == true){ $dataDir = $this->connection->gameDataDirectory(); $dataDir = str_replace('\\', '/', $dataDir); $file = $this->connection->getServername(); @@ -1628,18 +1652,19 @@ function onXmlRpcEliteEndMatch(JsonCallbacks\EndMatch $content) { // create and open the archive if ($zip->open("$zipfilename", \ZipArchive::CREATE) !== TRUE) { - die ("Could not open archive"); + $this->logger->logError("Could not open archive"); } // add each file in the file list to the archive foreach ($filelist as $key=>$value) { $new_filename = substr($key,strrpos($key,'/') + 1); $zip->addFile(realpath($key), $new_filename) or die ("ERROR: Could not add file: $key"); + } // close the archive $zip->close(); - echo "Archive ". $zipfilename2 . " created successfully."; + $this->logger->logInfo("Archive ". $zipfilename2 . " created successfully."); $challengeFile = $dataDir."Replays/".$name; //Rename folder @@ -1651,9 +1676,9 @@ function onXmlRpcEliteEndMatch(JsonCallbacks\EndMatch $content) { WHERE `matchServerLogin` = " . $this->db->quote($this->storage->serverLogin) . " and `id` = " . $this->db->quote($this->MatchNumber) . ""; - $this->logger->Debug($queryMapWinSettingsEnd); + $this->logger->logDebug($queryMapWinSettingsEnd); $this->db->execute($queryMapWinSettingsEnd); - + } // set server back to old value. $data = $this->connection->getServerTags(); @@ -1676,13 +1701,13 @@ function onXmlRpcEliteEndMatch(JsonCallbacks\EndMatch $content) { function getMapid(){ $q = "SELECT id FROM `maps` WHERE `uid` = " . $this->db->quote($this->storage->currentMap->uId) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); return $this->db->execute($q)->fetchObject()->id; } function getTeamid($clubLinkUrl, $teamname){ $q = "SELECT id FROM `clublinks` WHERE `Clublink_URL` = " . $this->db->quote($clubLinkUrl) . " and Clublink_Name = " . $this->db->quote($teamname) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); return $this->db->execute($q)->fetchObject()->id; } @@ -1692,7 +1717,7 @@ function getPlayerId($login) { return $this->playerIDs[$login]; } else { $q = "SELECT id FROM `players` WHERE `login` = " . $this->db->quote($login) . ""; - $this->logger->Debug($q); + $this->logger->logDebug($q); return $this->db->execute($q)->fetchObject()->id; } }