$responseType = self::getResponseTypeFromSystem();
// Create a new request object
- $requestInstance = ObjectFactory::createObjectByName($this->convertToClassName($response) . 'Request');
+ $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
// Remember request instance here
$this->setRequestInstance($requestInstance);
} // END - if
// ... and a new response object
- $responseClass = sprintf('%sResponse', $this->convertToClassName($response));
+ $responseClass = sprintf('%sResponse', self::convertToClassName($response));
$responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
// Remember response instance here
} // END - if
// Get a controller resolver
- $resolverClass = $this->convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
+ $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
$resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
// Get a controller instance as well
// CFG: HUB-BOOTSTRAP-NODES
$cfg->setConfigEntry('hub_bootstrap_nodes', 'tcp://188.138.90.169:9060');
+// CFG: ENABLE-FEATURE-HUBCOINS-REWARD
+// Disable this if you don't want to "earn" HubCoins: $cfg->setConfigEntry('enable_feature_hubcoins_reward', 'N');
+
// [EOF]
?>
// CFG: NODE-DEFAULT-MODE (can be 'regular', 'list', 'master' or 'boot', default is 'regular')
$cfg->setConfigEntry('node_default_mode', 'regular');
+// CFG: ENABLE-FEATURE-HUBCOIN-REWARD
+$cfg->setConfigEntry('enable_feature_hubcoin_reward', 'Y');
+
+// CFG: FEATURE-HUBCOIN-REWARD-CLASS
+$cfg->setConfigEntry('feature_hubcoin_reward_class', 'HubcoinsRewardFeature');
+
// CFG: TEMPLATE-ENGINE
$cfg->setConfigEntry('tpl_engine', 'ConsoleOutput');
* Feeds the hash and sender (as recipient for the 'sender' reward) to the
* miner's queue, unless the message is not a "reward claim" message as this
* leads to an endless loop. You may wish to run the miner to get some
- * reward ("HubCoins") for "mining" this hash.
+ * reward ("Hubcoins") for "mining" this hash.
*
* @param $messageData Array with message data
* @return void
*/
protected function getSocketErrorHandlerFromCode ($errorCode) {
// Create a name from translated error code
- $handlerName = 'socketError' . $this->convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
+ $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
// Is the call-back method there?
if (!method_exists($this, $handlerName)) {
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A HubcoinReward Feature class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class HubcoinRewardFeature extends BaseFeature implements Feature {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this Feature class and prepares it for usage
+ *
+ * @param $appInstance A manageable application
+ * @return $featureInstance An instance of this Feature class
+ */
+ public final static function createHubcoinRewardFeature (ManageableApplication $appInstance) {
+ // Get a new instance
+ $featureInstance = new HubcoinRewardFeature();
+
+ // Return the prepared instance
+ return $featureInstance;
+ }
+
+ /**
+ * Checks whether this feature can be made available to other classes.
+ *
+ * @return $isAvailable Whether this feature is available
+ */
+ public function isFeatureAvailable () {
+ // Testing this feature is pretty simple:
+ $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === 'Y') && (extension_loaded('scrypt')) && (is_callable('scrypt')));
+
+ // Return status
+ return $isAvailable;
+ }
+
+ /**
+ * Feature method 'generateHash'
+ *
+ * @param
+}
+
+// [EOF]
+?>
}
// Now convert the cruncher-mode in a class name
- $className = 'Hub' . $this->convertToClassName($cruncherMode) . 'Cruncher';
+ $className = 'Hub' . self::convertToClassName($cruncherMode) . 'Cruncher';
// And try to instance it
try {
}
// Now convert the miner-mode in a class name
- $className = 'Hub' . $this->convertToClassName($minerMode) . 'Miner';
+ $className = 'Hub' . self::convertToClassName($minerMode) . 'Miner';
// And try to instance it
try {
$checksFailed++;
} // END -if
- // If scrypt() is not found (ext-scrypt) then the "HubCoins reward" is not working
+ // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
// Mark it as working
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "HubCoin reward" feature enabled.');
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature enabled.');
$this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
} else {
// Not working (not all have ext-scrypt installed
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "HubCoin reward" feature disabled.');
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
}
// Are all tests passed?
$checksFailed++;
} // END - if
- // If scrypt() is not found (ext-scrypt) then the "HubCoins reward" is not working
+ // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
// Mark it as working
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "HubCoin reward" feature enabled.');
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature enabled.');
$this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
} else {
// Not working (not all have ext-scrypt installed
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "HubCoin reward" feature disabled.');
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
}
// Are all tests passed?
);
// Construct call-back name from package error code
- $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]] = 'handlePackageBy' . $this->convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]);
+ $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]] = 'handlePackageBy' . self::convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]);
// Abort if the call-back method is not there
if (!method_exists($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]])) {
*/
private function generatePackageHash ($content, $senderId) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: extension_scrypt_loaded=' . intval($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded')) . ' - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: isFeatureAvailable(hubcoin_reward)=' . intval(FrameworkFeature::isFeatureAvailable('hubcoin_reward')) . ' - CALLED!');
// Is the feature enabled?
- if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) {
+ if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
// Feature is not enabled
return NULL;
} // END - if
// Hash content and sender id together, use scrypt
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $senderId . ',content()=' . strlen($content));
- $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data));
+ $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data)));
// Debug message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ' - EXIT!');
*/
private function isPackageHashValid (array $decodedArray) {
// Is the feature enabled?
- if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) {
+ if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
// Feature is not enabled, so hashes are always valid
return TRUE;
} // END - if
// Check validity
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',decodedArray=' . print_r($decodedArray, TRUE));
//* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE));
- $isHashValid = Scrypt::checkScrypt($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]);
+ $isHashValid = FrameworkFeature::callFeature('hubcoin_reward', 'checkHash', array($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]));
// Return it
//* DEBUG-DIE: */ die(__METHOD__ . ': isHashValid=' . intval($isHashValid) . ',decodedArray=' . print_r($decodedArray, TRUE));
* Feeds the hash and sender (as recipient for the 'sender' reward) to the
* miner's queue, unless the message is not a "reward claim" message as this
* leads to an endless loop. You may wish to run the miner to get some
- * reward ("HubCoins") for "mining" this hash.
+ * reward ("Hubcoins") for "mining" this hash.
*
* @param $messageData Array with message data
* @return void
*/
public function feedHashToMiner (array $messageData) {
// Is the feature enabled?
- if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) {
+ if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
/*
* Feature is not enabled, don't feed the hash to the miner as it
*may be invalid.
$stateInstance = NULL;
// Create state class name
- $className = $this->getStatePrefix() . '' . $this->convertToClassName($stateName) . 'State';
+ $className = $this->getStatePrefix() . '' . self::convertToClassName($stateName) . 'State';
// ... and set it
$this->setClassName($className);
} // END - if
// Create class name
- $className = $this->statePrefix . $this->convertToClassName($stateName) . 'State';
+ $className = $this->statePrefix . self::convertToClassName($stateName) . 'State';
// Now, let us create the full name of the state class
$this->setClassName($className);
// Is the template dependency set?
if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
// Get a temporay template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . $this->convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class');
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . self::convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class');
// Then load it
$templateInstance->loadXmlTemplate($templateDependency);
*/
public final function startElement ($resource, $element, array $attributes) {
// Initial method name which will never be called...
- $methodName = 'init' . $this->convertToClassName($this->xmlTemplateType);
+ $methodName = 'init' . self::convertToClassName($this->xmlTemplateType);
// Make the element name lower-case
$element = strtolower($element);
//* DEBUG: */ echo "START: >".$element."<<br />\n";
if (in_array($element, $this->getMainNodes())) {
// Okay, main node found!
- $methodName = 'start' . $this->convertToClassName($element);
+ $methodName = 'start' . self::convertToClassName($element);
// Set it
$this->setCurrMainNode($element);
} elseif (in_array($element, $this->getSubNodes())) {
// Sub node found
- $methodName = 'start' . $this->convertToClassName($element);
+ $methodName = 'start' . self::convertToClassName($element);
} else {
// Invalid node name found
throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
} // END - if
// Construct method name
- $methodName = 'finish' . $this->convertToClassName($nodeName);
+ $methodName = 'finish' . self::convertToClassName($nodeName);
// Call the corresponding method
//* DEBUG: */ echo "call: ".$methodName."<br />\n";
-Subproject commit c397ac084fc4f194ddae9fd84ce7233197598704
+Subproject commit 1f81d21b97669832b84da3680d046eb9e4afba64