3 * A HubcoinReward Feature class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class HubcoinRewardFeature extends BaseFeature implements Feature {
26 * Protected constructor
30 protected function __construct () {
31 // Call parent constructor
32 parent::__construct(__CLASS__);
36 * Creates an instance of this Feature class and prepares it for usage
38 * @return $featureInstance An instance of this Feature class
40 public final static function createHubcoinRewardFeature () {
42 $featureInstance = new HubcoinRewardFeature();
44 // Return the prepared instance
45 return $featureInstance;
49 * Checks whether this feature can be made available to other classes.
51 * @return $isAvailable Whether this feature is available
53 public function isFeatureAvailable () {
55 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
57 // Testing this feature is pretty simple:
58 $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
61 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
68 * Feature method 'generateHash'
70 * @param $data Data to hash
71 * @return $hash Finished hash
73 public function featureMethodGenerateHash ($data) {
75 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
77 // Make sure the feature is available
78 assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
81 $hash = Scrypt::hashScrypt($data);
84 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
86 // Return generated hash
91 * Feature method 'checkHash'
93 * @param $data Data to check hash for
94 * @param $hash Previously generated hash for valdiation
95 * @return $isValid Whether the given hash matches a new one from given data
97 public function featureMethodCheckHash ($data, $hash) {
99 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
101 // Make sure the feature is available
102 assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
105 $isValid = Scrypt::checkScrypt($data, $hash);
108 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));