added dedibuild to error and usage reporting
This commit is contained in:
		| @@ -69,7 +69,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 	 * Private properties | ||||
| 	 */ | ||||
| 	/** @var ManiaControl $maniaControl */ | ||||
| 	private $maniaControl = null; | ||||
| 	private $maniaControl    = null; | ||||
| 	private $updateManialink = false; | ||||
| 	/** @var ManiaLink $manialink */ | ||||
| 	private $manialink = null; | ||||
| @@ -229,8 +229,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 	 * Open a Mx Karma Session | ||||
| 	 */ | ||||
| 	private function mxKarmaOpenSession() { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) | ||||
| 		) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| @@ -253,26 +252,26 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 		$this->mxKarma['connectionInProgress'] = true; | ||||
|  | ||||
| 		$this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($mxKarmaCode) { | ||||
| 			                                    $this->mxKarma['connectionInProgress'] = false; | ||||
| 			                                    if ($error) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    $data = json_decode($json); | ||||
| 			                                    if (!$data) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    if ($data->success) { | ||||
| 				                                    $this->mxKarma['session'] = $data->data; | ||||
| 				                                    $this->activateSession($mxKarmaCode); | ||||
| 			                                    } else { | ||||
| 				                                    Logger::logError("Error while authenticating on Mania-Exchange Karma"); | ||||
| 				                                    // TODO remove temp trigger | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message); | ||||
| 				                                    $this->mxKarma['connectionInProgress'] = false; | ||||
| 			                                    } | ||||
| 		                                    }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); | ||||
| 			$this->mxKarma['connectionInProgress'] = false; | ||||
| 			if ($error) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error); | ||||
| 				return; | ||||
| 			} | ||||
| 			$data = json_decode($json); | ||||
| 			if (!$data) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data); | ||||
| 				return; | ||||
| 			} | ||||
| 			if ($data->success) { | ||||
| 				$this->mxKarma['session'] = $data->data; | ||||
| 				$this->activateSession($mxKarmaCode); | ||||
| 			} else { | ||||
| 				Logger::logError("Error while authenticating on Mania-Exchange Karma"); | ||||
| 				// TODO remove temp trigger | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message); | ||||
| 				$this->mxKarma['connectionInProgress'] = false; | ||||
| 			} | ||||
| 		}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -288,32 +287,32 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 		$query .= '&activationHash=' . urlencode($hash); | ||||
|  | ||||
| 		$this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($query) { | ||||
| 			                                    $this->mxKarma['connectionInProgress'] = false; | ||||
| 			                                    if ($error) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    $data = json_decode($json); | ||||
| 			                                    if (!$data) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    if ($data->success && $data->data->activated) { | ||||
| 				                                    Logger::log('Successfully authenticated on Mania-Exchange Karma'); | ||||
| 			$this->mxKarma['connectionInProgress'] = false; | ||||
| 			if ($error) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); | ||||
| 				return; | ||||
| 			} | ||||
| 			$data = json_decode($json); | ||||
| 			if (!$data) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); | ||||
| 				return; | ||||
| 			} | ||||
| 			if ($data->success && $data->data->activated) { | ||||
| 				Logger::log('Successfully authenticated on Mania-Exchange Karma'); | ||||
|  | ||||
| 				                                    // Fetch the Mx Karma Votes | ||||
| 				                                    $this->getMxKarmaVotes(); | ||||
| 			                                    } else { | ||||
| 				                                    if ($data->data->message === 'invalid hash') { | ||||
| 					                                    $permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); | ||||
| 					                                    $this->maniaControl->getChat()->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission); | ||||
| 				                                    } else { | ||||
| 					                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query); | ||||
| 				                                    } | ||||
| 				                                    Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message); | ||||
| 				                                    unset($this->mxKarma['session']); | ||||
| 			                                    } | ||||
| 		                                    }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); | ||||
| 				// Fetch the Mx Karma Votes | ||||
| 				$this->getMxKarmaVotes(); | ||||
| 			} else { | ||||
| 				if ($data->data->message === 'invalid hash') { | ||||
| 					$permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); | ||||
| 					$this->maniaControl->getChat()->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission); | ||||
| 				} else { | ||||
| 					$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query); | ||||
| 				} | ||||
| 				Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message); | ||||
| 				unset($this->mxKarma['session']); | ||||
| 			} | ||||
| 		}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -331,8 +330,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 	 * Fetch the mxKarmaVotes for the current map | ||||
| 	 */ | ||||
| 	public function getMxKarmaVotes(Player $player = null) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) | ||||
| 		) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| @@ -370,47 +368,45 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 		} | ||||
|  | ||||
| 		$content = json_encode($properties); | ||||
| 		$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, | ||||
| 		                                                                                                                                                                                 $error) use | ||||
| 		                                    ( | ||||
| 			                                    &$player | ||||
| 		                                    ) { | ||||
| 			                                    if ($error) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    $data = json_decode($json); | ||||
| 			                                    if (!$data) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 		$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) use ( | ||||
| 			&$player | ||||
| 		) { | ||||
| 			if ($error) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); | ||||
| 				return; | ||||
| 			} | ||||
| 			$data = json_decode($json); | ||||
| 			if (!$data) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			                                    if ($data->success) { | ||||
| 				                                    // Fetch averages if it's for the whole server | ||||
| 				                                    if (!$player) { | ||||
| 					                                    $this->mxKarma['voteCount']       = $data->data->votecount; | ||||
| 					                                    $this->mxKarma['voteAverage']     = $data->data->voteaverage; | ||||
| 					                                    $this->mxKarma['modeVoteCount']   = $data->data->modevotecount; | ||||
| 					                                    $this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage; | ||||
| 				                                    } | ||||
| 			if ($data->success) { | ||||
| 				// Fetch averages if it's for the whole server | ||||
| 				if (!$player) { | ||||
| 					$this->mxKarma['voteCount']       = $data->data->votecount; | ||||
| 					$this->mxKarma['voteAverage']     = $data->data->voteaverage; | ||||
| 					$this->mxKarma['modeVoteCount']   = $data->data->modevotecount; | ||||
| 					$this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage; | ||||
| 				} | ||||
|  | ||||
| 				                                    foreach ($data->data->votes as $votes) { | ||||
| 					                                    $this->mxKarma['votes'][$votes->login] = $votes->vote; | ||||
| 				                                    } | ||||
| 				foreach ($data->data->votes as $votes) { | ||||
| 					$this->mxKarma['votes'][$votes->login] = $votes->vote; | ||||
| 				} | ||||
|  | ||||
| 				                                    $this->updateManialink = true; | ||||
| 				                                    $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); | ||||
| 				                                    Logger::logInfo('MX-Karma Votes successfully fetched!'); | ||||
| 			                                    } else { | ||||
| 				                                    // Problem occurred | ||||
| 				                                    Logger::logError('Error while fetching votes: ' . $data->data->message); | ||||
| 				                                    if ($data->data->message === 'invalid session') { | ||||
| 					                                    unset($this->mxKarma['session']); | ||||
| 				                                    } else { | ||||
| 					                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); | ||||
| 				                                    } | ||||
| 			                                    } | ||||
| 		                                    }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); | ||||
| 				$this->updateManialink = true; | ||||
| 				$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); | ||||
| 				Logger::logInfo('MX-Karma Votes successfully fetched!'); | ||||
| 			} else { | ||||
| 				// Problem occurred | ||||
| 				Logger::logError('Error while fetching votes: ' . $data->data->message); | ||||
| 				if ($data->data->message === 'invalid session') { | ||||
| 					unset($this->mxKarma['session']); | ||||
| 				} else { | ||||
| 					$this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); | ||||
| 				} | ||||
| 			} | ||||
| 		}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -487,29 +483,28 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
|  | ||||
| 		$content = json_encode($properties); | ||||
|  | ||||
| 		$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, | ||||
| 		                                                                                                                                                                             $error) { | ||||
| 			                                    if ($error) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    $data = json_decode($json); | ||||
| 			                                    if (!$data) { | ||||
| 				                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); | ||||
| 				                                    return; | ||||
| 			                                    } | ||||
| 			                                    if ($data->success) { | ||||
| 				                                    Logger::logInfo('Votes successfully submitted!'); | ||||
| 			                                    } else { | ||||
| 				                                    // Problem occurred | ||||
| 				                                    Logger::logError("Error while updating votes: '{$data->data->message}'"); | ||||
| 				                                    if ($data->data->message === "invalid session") { | ||||
| 					                                    unset($this->mxKarma['session']); | ||||
| 				                                    } else { | ||||
| 					                                    $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); | ||||
| 				                                    } | ||||
| 			                                    } | ||||
| 		                                    }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); | ||||
| 		$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) { | ||||
| 			if ($error) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); | ||||
| 				return; | ||||
| 			} | ||||
| 			$data = json_decode($json); | ||||
| 			if (!$data) { | ||||
| 				$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); | ||||
| 				return; | ||||
| 			} | ||||
| 			if ($data->success) { | ||||
| 				Logger::logInfo('Votes successfully submitted!'); | ||||
| 			} else { | ||||
| 				// Problem occurred | ||||
| 				Logger::logError("Error while updating votes: '{$data->data->message}'"); | ||||
| 				if ($data->data->message === "invalid session") { | ||||
| 					unset($this->mxKarma['session']); | ||||
| 				} else { | ||||
| 					$this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); | ||||
| 				} | ||||
| 			} | ||||
| 		}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -595,9 +590,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 		} | ||||
|  | ||||
| 		// Calculate actual voting | ||||
| 		$vote -= $voteLow; | ||||
| 		$vote     -= $voteLow; | ||||
| 		$voteHigh -= $voteLow; | ||||
| 		$vote /= $voteHigh; | ||||
| 		$vote     /= $voteHigh; | ||||
|  | ||||
| 		// Save vote | ||||
| 		$map = $this->maniaControl->getMapManager()->getCurrentMap(); | ||||
| @@ -754,13 +749,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 		$karmaSettingName = self::buildKarmaSettingName($serverLogin); | ||||
|  | ||||
| 		switch ($setting->setting) { | ||||
| 			case $karmaSettingName: | ||||
| 			{ | ||||
| 			case $karmaSettingName: { | ||||
| 				$this->mxKarmaOpenSession(); | ||||
| 				break; | ||||
| 			} | ||||
| 			case self::SETTING_WIDGET_ENABLE: | ||||
| 			{ | ||||
| 			case self::SETTING_WIDGET_ENABLE: { | ||||
| 				if ($setting->value) { | ||||
| 					$this->updateManialink = true; | ||||
| 					$this->handle1Second(time()); | ||||
| @@ -803,8 +796,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 			$voteCount = $votes['count']; | ||||
| 		} | ||||
|  | ||||
| 		if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE) | ||||
| 		) { | ||||
| 		if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) { | ||||
| 			// Build karma manialink | ||||
| 			$this->buildManialink(); | ||||
|  | ||||
| @@ -893,7 +885,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 		$count = 0; | ||||
| 		while ($vote = $result->fetch_object()) { | ||||
| 			$votes[$vote->vote] = $vote; | ||||
| 			$count += $vote->count; | ||||
| 			$count              += $vote->count; | ||||
| 		} | ||||
| 		$votes['count'] = $count; | ||||
| 		$result->free(); | ||||
| @@ -968,13 +960,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 	 * @param Map $map | ||||
| 	 */ | ||||
| 	public function importMxKarmaVotes(Map $map) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) | ||||
| 		) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING) | ||||
| 		) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING)) { | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| @@ -1039,8 +1029,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { | ||||
| 	 * Save Mx Karma Votes at MapEnd | ||||
| 	 */ | ||||
| 	public function sendMxKarmaVotes(Map $map) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) | ||||
| 		) { | ||||
| 		if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user