From 08f962e1f02df357f5554413357952faf33fe210 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 11 Aug 2009 21:48:33 +0000 Subject: [PATCH] Task handler added, a lot rewrites - Task handler added - New Interface HandleableTask added (for task handlers) - A lot interfaces/classes/exceptions extended (sorry for lame description) - State resolver added (shouldn't we move this to core?) --- .gitattributes | 14 +- application/hub/config.php | 23 +- application/hub/debug.php | 4 +- .../lists/class_InvalidListHashException.php | 2 +- .../class_ListGroupAlreadyAddedException.php | 2 +- .../lists/class_NoListGroupException.php | 2 +- .../interfaces/handler/class_Handleable.php | 2 +- .../handler/network/class_Networkable.php | 11 +- .../hub/interfaces/handler/task/.htaccess | 1 + .../task/class_HandleableTask.php} | 13 +- .../pool/class_PoolableListener.php | 35 --- .../interfaces/visitor/class_Visitable.php | 2 +- .../hub/interfaces/visitor/class_Visitor.php | 2 +- .../visitor/pool/class_PoolVisitor.php | 2 +- .../listener/class_ListenerPoolVisitor.php | 2 +- .../console/class_HubConsoleMainCommand.php | 28 +-- .../query/local/class_LocalQueryConnector.php | 12 +- .../class_HubConsoleDefaultNewsController.php | 6 +- .../filter/activation/class_HubActivation | 8 +- .../main/filter/bootstrap/class_HubBootstrap | 8 +- ...s_HubBootstrapExtraBootstrappingFilter.php | 8 +- .../class_HubBootstrapGenerateHubIdFilter.php | 8 +- ...ss_HubBootstrapGenerateSessionIdFilter.php | 8 +- .../class_HubBootstrapInitQueuesFilter.php | 8 +- .../class_HubBootstrapListenerPoolFilter.php | 8 +- ...lass_HubBootstrapRestoreNodeListFilter.php | 8 +- application/hub/main/filter/class_ | 8 +- .../hub/main/filter/console/class_Console | 8 +- .../class_ConsoleWelcomeTeaserFilter.php | 8 +- application/hub/main/filter/node/class_Node | 2 +- .../node/class_NodeInitializationFilter.php | 2 +- .../main/filter/shutdown/class_HubShutdown | 8 +- .../class_HubShutdownDeinitQueuesFilter.php | 8 +- .../class_HubShutdownFlushNodeListFilter.php | 8 +- .../class_HubShutdownListenerPoolFilter.php | 8 +- .../shutdown/class_HubShutdownNodeFilter.php | 8 +- application/hub/main/filter/task/.htaccess | 1 + .../class_TaskHandlerInitializerFilter.php | 76 +++++++ application/hub/main/handler/network/class_ | 24 +- .../class_BaseNetworkPackageHandler.php | 32 +++ .../hub/main/handler/network/tcp/class_ | 208 ++++++++++++++++++ .../tcp/class_TcpNetworkPackageHandler.php | 49 ++++- .../udp/class_UdpNetworkPackageHandler.php | 22 +- application/hub/main/handler/tasks/.htaccess | 1 + .../main/handler/tasks/class_TaskHandler.php | 65 ++++++ .../main/listener/tcp/class_TcpListener.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 2 +- .../class_HubConsoleCommandResolver.php | 2 +- .../class_HubConsoleControllerResolver.php | 2 +- application/hub/main/resolver/state/.htaccess | 1 + .../state/class_BaseStateResolver.php | 165 ++++++++++++++ .../hub/main/resolver/state/network/.htaccess | 1 + .../network/class_NetworkStateResolver.php | 92 ++++++++ application/hub/main/states/generic/.htaccess | 1 + index.php | 2 +- 55 files changed, 840 insertions(+), 203 deletions(-) create mode 100644 application/hub/interfaces/handler/task/.htaccess rename application/hub/interfaces/{pool/class_PoolableClient.php => handler/task/class_HandleableTask.php} (70%) mode change 100755 => 100644 delete mode 100755 application/hub/interfaces/pool/class_PoolableListener.php create mode 100644 application/hub/main/filter/task/.htaccess create mode 100644 application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php create mode 100644 application/hub/main/handler/network/tcp/class_ create mode 100644 application/hub/main/handler/tasks/.htaccess create mode 100644 application/hub/main/handler/tasks/class_TaskHandler.php create mode 100644 application/hub/main/resolver/state/.htaccess create mode 100644 application/hub/main/resolver/state/class_BaseStateResolver.php create mode 100644 application/hub/main/resolver/state/network/.htaccess create mode 100644 application/hub/main/resolver/state/network/class_NetworkStateResolver.php create mode 100644 application/hub/main/states/generic/.htaccess diff --git a/.gitattributes b/.gitattributes index a0c821e2c..83bf2e2b3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -20,6 +20,8 @@ application/hub/interfaces/handler/.htaccess -text application/hub/interfaces/handler/class_Handleable.php -text application/hub/interfaces/handler/network/.htaccess -text application/hub/interfaces/handler/network/class_Networkable.php -text +application/hub/interfaces/handler/task/.htaccess -text +application/hub/interfaces/handler/task/class_HandleableTask.php -text application/hub/interfaces/listener/.htaccess -text application/hub/interfaces/listener/class_Listenable.php -text application/hub/interfaces/lists/.htaccess -text @@ -28,8 +30,6 @@ application/hub/interfaces/nodes/.htaccess -text application/hub/interfaces/nodes/class_NodeHelper.php -text application/hub/interfaces/pool/.htaccess -text application/hub/interfaces/pool/class_Poolable.php -text -application/hub/interfaces/pool/class_PoolableClient.php -text -application/hub/interfaces/pool/class_PoolableListener.php -text application/hub/interfaces/pool/client/.htaccess -text application/hub/interfaces/pool/client/class_PoolableClient.php -text application/hub/interfaces/pool/listener/.htaccess -text @@ -105,6 +105,8 @@ application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php -te application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php -text application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php -text application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php -text +application/hub/main/filter/task/.htaccess -text +application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php -text application/hub/main/handler/.htaccess -text application/hub/main/handler/class_ -text application/hub/main/handler/class_BaseHandler.php -text @@ -112,9 +114,12 @@ application/hub/main/handler/network/.htaccess -text application/hub/main/handler/network/class_ -text application/hub/main/handler/network/class_BaseNetworkPackageHandler.php -text application/hub/main/handler/network/tcp/.htaccess -text +application/hub/main/handler/network/tcp/class_ -text application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php -text application/hub/main/handler/network/udp/.htaccess -text application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php -text +application/hub/main/handler/tasks/.htaccess -text +application/hub/main/handler/tasks/class_TaskHandler.php -text application/hub/main/iterator/.htaccess -text application/hub/main/iterator/class_ -text application/hub/main/iterator/class_BaseIterator.php -text @@ -182,11 +187,16 @@ application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.ph application/hub/main/resolver/controller/.htaccess -text application/hub/main/resolver/controller/console/.htaccess -text application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php -text +application/hub/main/resolver/state/.htaccess -text +application/hub/main/resolver/state/class_BaseStateResolver.php -text +application/hub/main/resolver/state/network/.htaccess -text +application/hub/main/resolver/state/network/class_NetworkStateResolver.php -text application/hub/main/states/.htaccess -text application/hub/main/states/class_ -text application/hub/main/states/class_BaseState.php -text application/hub/main/states/client/.htaccess -text application/hub/main/states/client/class_BaseClientState.php -text +application/hub/main/states/generic/.htaccess -text application/hub/main/states/hub/.htaccess -text application/hub/main/states/hub/class_BaseHubState.php -text application/hub/main/visitor/.htaccess -text diff --git a/application/hub/config.php b/application/hub/config.php index ddf8b6fd4..380a74b26 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -117,15 +117,21 @@ $cfg->setConfigEntry('default_hubconsole_command', 'main'); // CFG: HUBCONSOLE-CMD-RESOLVER-CLASS $cfg->setConfigEntry('hubconsole_cmd_resolver_class', 'HubConsoleCommandResolver'); +// CFG: NETWORK-STATE-RESOLVER-CLASS +$cfg->setConfigEntry('network_state_resolver_class', 'NetworkStateResolver'); + // CFG: NEWS-DOWNLOAD-FILTER $cfg->setConfigEntry('news_download_filter', 'NewsDownloadFilter'); // CFG: NEWS-PROCESS-FILTER $cfg->setConfigEntry('news_process_filter', 'NewsProcessFilter'); -// CFG: NODE-INITIALIZATION-FILTER +// CFG: NODE-INITIALIZER-FILTER $cfg->setConfigEntry('node_initializer_filter', 'NodeInitializationFilter'); +// CFG: HUB-ACTIVATION-TASK-HANDLER-INITIALIZER-FILTER +$cfg->setConfigEntry('hub_activation_task_handler_initializer_filter', 'TaskHandlerInitializerFilter'); + // CFG: CONSOLE-WELCOME-TEASER-FILTER $cfg->setConfigEntry('console_welcome_teaser_filter', 'ConsoleWelcomeTeaserFilter'); @@ -165,5 +171,20 @@ $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader'); // CFG: NEWS-MAIN-LIMIT $cfg->setConfigEntry('news_main_limit', 5); +// CFG: TASK-HANDLER-CLASS +$cfg->setConfigEntry('task_handler_class', 'TaskHandler'); + +// CFG: TASK-NETWORK-PACKAGE-READER-STARTUP-DELAY +$cfg->setConfigEntry('task_network_package_reader_startup_delay', 5000); + +// CFG: TASK-NETWORK-PACKAGE-READER-INTERVAL-DELAY +$cfg->setConfigEntry('task_network_package_reader_interval_delay', 10); + +// CFG: TASK-QUERY-HANDLER-STARTUP-DELAY +$cfg->setConfigEntry('task_query_handler_startup_delay', 3000); + +// CFG: TASK-QUERY-HANDLER-INTERVAL-DELAY +$cfg->setConfigEntry('task_query_handler_interval_delay', 10); + // [EOF] ?> diff --git a/application/hub/debug.php b/application/hub/debug.php index 3103b74bf..5f222924a 100644 --- a/application/hub/debug.php +++ b/application/hub/debug.php @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -// Hub main loop debugging -define('HUB_DEBUG_MAIN', true); +// Set error reporting +error_reporting(E_ALL | E_STRICT); // [EOF] ?> diff --git a/application/hub/exceptions/lists/class_InvalidListHashException.php b/application/hub/exceptions/lists/class_InvalidListHashException.php index faf6bb01f..19f1b60f0 100644 --- a/application/hub/exceptions/lists/class_InvalidListHashException.php +++ b/application/hub/exceptions/lists/class_InvalidListHashException.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php b/application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php index d401037dc..fc7098ed7 100644 --- a/application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php +++ b/application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/exceptions/lists/class_NoListGroupException.php b/application/hub/exceptions/lists/class_NoListGroupException.php index ee8e28284..6348edf2b 100644 --- a/application/hub/exceptions/lists/class_NoListGroupException.php +++ b/application/hub/exceptions/lists/class_NoListGroupException.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/interfaces/handler/class_Handleable.php b/application/hub/interfaces/handler/class_Handleable.php index a143bced3..e7775272a 100644 --- a/application/hub/interfaces/handler/class_Handleable.php +++ b/application/hub/interfaces/handler/class_Handleable.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/interfaces/handler/network/class_Networkable.php b/application/hub/interfaces/handler/network/class_Networkable.php index bb4ce5028..fb4302141 100644 --- a/application/hub/interfaces/handler/network/class_Networkable.php +++ b/application/hub/interfaces/handler/network/class_Networkable.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -22,6 +22,15 @@ * along with this program. If not, see . */ interface Networkable extends Handleable { + /** + * Processes a package from given resource. This is mostly useful for TCP + * package handling and is implemented in the TcpListener class + * + * @param $resource A valid resource identifier + * @return void + * @throws InvalidResourceException If the given resource is invalid + */ + function processResourcePackage ($resource); } // diff --git a/application/hub/interfaces/handler/task/.htaccess b/application/hub/interfaces/handler/task/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/handler/task/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/pool/class_PoolableClient.php b/application/hub/interfaces/handler/task/class_HandleableTask.php old mode 100755 new mode 100644 similarity index 70% rename from application/hub/interfaces/pool/class_PoolableClient.php rename to application/hub/interfaces/handler/task/class_HandleableTask.php index c74c72f52..7bcb9df35 --- a/application/hub/interfaces/pool/class_PoolableClient.php +++ b/application/hub/interfaces/handler/task/class_HandleableTask.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,15 +21,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface PoolableClient extends Poolable { +interface HandleableTask extends Handleable { /** - * Adds a socket resource to the client pool + * Registers a task with a task handler. This method throws a + * TaskAlreadyRegisteredException if the task has already been registered * - * @param $socketResource A valid (must be!) socket resource + * @param $taskName A task name to register the task on + * @param $taskInstance The instance we should register as a task * @return void - * @todo 0% done */ - function addClient ($socketResource); + function registerTask ($taskName, Visitable $taskInstance); } // diff --git a/application/hub/interfaces/pool/class_PoolableListener.php b/application/hub/interfaces/pool/class_PoolableListener.php deleted file mode 100755 index 162d8a6c7..000000000 --- a/application/hub/interfaces/pool/class_PoolableListener.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 . - */ -interface PoolableListener extends Poolable { - /** - * Adds a listener instance to this pool - * - * @param $listenerInstance An instance of a Listenable class - * @return void - */ - function addListener (Listenable $listenerInstance); -} - -// -?> diff --git a/application/hub/interfaces/visitor/class_Visitable.php b/application/hub/interfaces/visitor/class_Visitable.php index 8319c3163..6211f0548 100644 --- a/application/hub/interfaces/visitor/class_Visitable.php +++ b/application/hub/interfaces/visitor/class_Visitable.php @@ -31,5 +31,5 @@ interface Visitable extends FrameworkInterface { function accept (Visitor $visitorInstance); } -// +// [EOF] ?> diff --git a/application/hub/interfaces/visitor/class_Visitor.php b/application/hub/interfaces/visitor/class_Visitor.php index e2bce7923..b098a70e6 100644 --- a/application/hub/interfaces/visitor/class_Visitor.php +++ b/application/hub/interfaces/visitor/class_Visitor.php @@ -24,5 +24,5 @@ interface Visitor extends FrameworkInterface { } -// +// [EOF] ?> diff --git a/application/hub/interfaces/visitor/pool/class_PoolVisitor.php b/application/hub/interfaces/visitor/pool/class_PoolVisitor.php index f7df6893e..6a9b6c8e0 100644 --- a/application/hub/interfaces/visitor/pool/class_PoolVisitor.php +++ b/application/hub/interfaces/visitor/pool/class_PoolVisitor.php @@ -31,5 +31,5 @@ interface PoolVisitor extends Visitor { function visitPool (Poolable $poolInstance); } -// +// [EOF] ?> diff --git a/application/hub/interfaces/visitor/pool/listener/class_ListenerPoolVisitor.php b/application/hub/interfaces/visitor/pool/listener/class_ListenerPoolVisitor.php index e99be2dc0..109b75d3a 100644 --- a/application/hub/interfaces/visitor/pool/listener/class_ListenerPoolVisitor.php +++ b/application/hub/interfaces/visitor/pool/listener/class_ListenerPoolVisitor.php @@ -39,5 +39,5 @@ interface ListenerPoolVisitor extends PoolVisitor { function visitDecorator (Listenable $listenerInstance); } -// +// [EOF] ?> diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index c9e4a44b0..4be290c52 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -1,10 +1,10 @@ * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -55,23 +55,11 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { * @param $requestInstance An instance of a class with an Requestable interface * @param $responseInstance An instance of a class with an Responseable interface * @return void - * @throws NullPointerException When $applicationInstance is null - * @throws InvalidInterfaceException When $applicationInstance does not implement ManageableApplication - * @todo ~10% done */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get a registry and the application instance from it $applicationInstance = Registry::getRegistry()->getInstance('app'); - // Is this a ManageableApplication instance? - if (is_null($applicationInstance)) { - // Something really bad went wrong - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!$applicationInstance instanceof ManageableApplication) { - // Something went badly wrong - throw new InvalidInterfaceException(array($this, 'ManageableApplication'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); - } // END - if - // ----------------------- Bootstrapping phase ------------------------ // Try to bootstrap the node and pass the request instance to it for // extra arguments which mostly override config entries or enable special @@ -83,17 +71,14 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a NullPointerException here - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } // END - if - // -------------------------- Hub activation -------------------------- // Activates the hub by doing some final preparation steps and setting // the attribute $hubIsActive to true $nodeInstance->activateHub($requestInstance, $responseInstance); + // Get task handler instance + $handlerInstance = Registry::getRegistry()->getInstance('task'); + // Debug message $this->debugOutput('MAIN: --- Entering main loop. ---'); @@ -101,7 +86,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { // This is the main loop. Queried calls should come back here very fast // so the whole application runs on nice speed. This while-loop goes // until the hub is no longer active. - while ($nodeInstance->isHubActive()) { + while (($nodeInstance->isHubActive()) && ($handlerInstance->hasTasksLeft())) { // Handle the listeners // @TODO We may have to catch some exceptions here $nodeInstance->getListenerPoolInstance()->handleListenerPool(); @@ -136,6 +121,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_listener_pool_filter')); // Add hub activation filters + $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('hub_activation_task_handler_initializer_filter')); // Add shutdown filters $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_flush_node_list_filter')); diff --git a/application/hub/main/connectors/query/local/class_LocalQueryConnector.php b/application/hub/main/connectors/query/local/class_LocalQueryConnector.php index 8dbdc5bec..c410ca156 100644 --- a/application/hub/main/connectors/query/local/class_LocalQueryConnector.php +++ b/application/hub/main/connectors/query/local/class_LocalQueryConnector.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class LocalQueryConnector extends BaseQueryConnector implements Connectable, Queryable { +class LocalQueryConnector extends BaseQueryConnector implements Connectable, Queryable, Visitable { /** * Protected constructor * @@ -48,6 +48,16 @@ class LocalQueryConnector extends BaseQueryConnector implements Connectable, Que // Finally return it return $connectorInstance; } + + /** + * Accepts the visitor to rpocess the visit "request" + * + * @param $visitorInstance An instance of a Visitor class + * @return void + */ + public function accept (Visitor $visitorInstance) { + $this->partialStub('visitor='.$visitorInstance->__toString()); + } } // [EOF] diff --git a/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php b/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php index 9c2068eb6..842bd2606 100644 --- a/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php +++ b/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -115,7 +115,7 @@ class HubConsoleDefaultNewsController extends BaseController implements Controll * @param $filterInstance A Filterable class * @return void */ - public function addHubActivationFilter (Filterable $filterInstance) { + public function addActivationFilter (Filterable $filterInstance) { $this->addFilter('activation', $filterInstance); } @@ -126,7 +126,7 @@ class HubConsoleDefaultNewsController extends BaseController implements Controll * @param $responseInstance A Responseable class * @return void */ - public function executeHubActivationFilters (Requestable $requestInstance, Responseable $responseInstance) { + public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) { $this->executeFilters('activation', $requestInstance, $responseInstance); } diff --git a/application/hub/main/filter/activation/class_HubActivation b/application/hub/main/filter/activation/class_HubActivation index 5c3d3dd44..babe06470 100644 --- a/application/hub/main/filter/activation/class_HubActivation +++ b/application/hub/main/filter/activation/class_HubActivation @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubActivation???Filter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END if - // Now do something $this->partialStub('Please implement this step.'); } diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrap b/application/hub/main/filter/bootstrap/class_HubBootstrap index 25b2ee339..37520419c 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrap +++ b/application/hub/main/filter/bootstrap/class_HubBootstrap @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrap???Filter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now do something $this->partialStub('Please implement this step.'); } diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapExtraBootstrappingFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapExtraBootstrappingFilter.php index ed47a082f..cb7474687 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrapExtraBootstrappingFilter.php +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapExtraBootstrappingFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrapExtraBootstrappingFilter extends BaseFilter implements Filtera // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Do some extra bootstrapping steps $nodeInstance->doBootstrapping(); } diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateHubIdFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateHubIdFilter.php index e00ca12c3..e922b5798 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateHubIdFilter.php +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateHubIdFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrapGenerateHubIdFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // --------------------- Hub-id acquirement phase --------------------- // Acquire a hub-id. This step generates on first launch a new one and // on any later launches it will restore the hub-id from the database. diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateSessionIdFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateSessionIdFilter.php index 1dcaf870b..e8ae454ae 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateSessionIdFilter.php +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapGenerateSessionIdFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrapGenerateSessionIdFilter extends BaseFilter implements Filterab // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // ------------------- More generic bootstrap steps ------------------- // Generate the session id which will only be stored in RAM and kept for // the whole "session". diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php index 27882b4c2..5bb4f1572 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrapInitQueuesFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now init the queues $nodeInstance->initQueues(); } diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php index b083bcb40..7fdcd3ada 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrapListenerPoolFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now do something $nodeInstance->initializeListenerPool(); } diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapRestoreNodeListFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapRestoreNodeListFilter.php index b889d2b37..6def96e30 100644 --- a/application/hub/main/filter/bootstrap/class_HubBootstrapRestoreNodeListFilter.php +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapRestoreNodeListFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class HubBootstrapRestoreNodeListFilter extends BaseFilter implements Filterable // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Restore a previously downloaded bootstrap-node list. $nodeInstance->bootstrapRestoreNodeList(); } diff --git a/application/hub/main/filter/class_ b/application/hub/main/filter/class_ index 382b6859d..f432f1079 100644 --- a/application/hub/main/filter/class_ +++ b/application/hub/main/filter/class_ @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -58,12 +58,6 @@ class Hub!!!???Filter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now do something $this->partialStub('Please implement this step.'); } diff --git a/application/hub/main/filter/console/class_Console b/application/hub/main/filter/console/class_Console index 6d5c26efe..52f584f36 100644 --- a/application/hub/main/filter/console/class_Console +++ b/application/hub/main/filter/console/class_Console @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -58,12 +58,6 @@ class Console???Filter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Implement this! $this->partialStub('Please implement this method.'); } diff --git a/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php b/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php index 065be4bf2..29e7282c4 100644 --- a/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php +++ b/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -57,12 +57,6 @@ class ConsoleWelcomeTeaserFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now output the teaser $nodeInstance->outputConsoleTeaser(); } diff --git a/application/hub/main/filter/node/class_Node b/application/hub/main/filter/node/class_Node index 355b084a5..9495b56af 100644 --- a/application/hub/main/filter/node/class_Node +++ b/application/hub/main/filter/node/class_Node @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/main/filter/node/class_NodeInitializationFilter.php b/application/hub/main/filter/node/class_NodeInitializationFilter.php index 5dd157e7c..55471b161 100644 --- a/application/hub/main/filter/node/class_NodeInitializationFilter.php +++ b/application/hub/main/filter/node/class_NodeInitializationFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/main/filter/shutdown/class_HubShutdown b/application/hub/main/filter/shutdown/class_HubShutdown index e5bf73321..aeefaf44f 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdown +++ b/application/hub/main/filter/shutdown/class_HubShutdown @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -58,12 +58,6 @@ class HubShutdown???Filter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now do something $this->partialStub('Please implement this step.'); } diff --git a/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php index 299cc7c83..aba685df3 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php +++ b/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -58,12 +58,6 @@ class HubShutdownDeinitQueuesFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Get query instance $queryInstance = $nodeInstance->getQueryInstance(); diff --git a/application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php index f55f3f034..28c169e77 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php +++ b/application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -58,12 +58,6 @@ class HubShutdownFlushNodeListFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Now do something $this->partialStub('Please implement this step.'); } diff --git a/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php index 5a1e79d5a..f9e725df5 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php +++ b/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -58,12 +58,6 @@ class HubShutdownListenerPoolFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Get listener pool instance $listenerPoolInstance = $nodeInstance->getListenerPoolInstance(); diff --git a/application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php index 826acd48a..56919564e 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php +++ b/application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php @@ -6,7 +6,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -59,12 +59,6 @@ class HubShutdownNodeFilter extends BaseFilter implements Filterable { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - // Shutdown the node. This should be the last line $nodeInstance->doShutdown(); } diff --git a/application/hub/main/filter/task/.htaccess b/application/hub/main/filter/task/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/task/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php b/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php new file mode 100644 index 000000000..1da56ef04 --- /dev/null +++ b/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php @@ -0,0 +1,76 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 . + */ +class TaskHandlerInitializerFilter extends BaseFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createTaskHandlerInitializerFilter () { + // Get a new instance + $filterInstance = new TaskHandlerInitializerFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If we need to interrupt the filter chain + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Get a new task handler instance + $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class'); + + // Register some tasks and provide both instances for this: + // 1.) Network package reader, needs to be delayed a little + $handlerInstance->registerTask('network_package_reader', $nodeInstance->getListenerPoolInstance()); + // 2.) Query instance + $handlerInstance->registerTask('query_handler', $nodeInstance->getQueryInstance()); + + // Put the task handler in registry + Registry::getRegistry()->addInstance('task', $handlerInstance); + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/network/class_ b/application/hub/main/handler/network/class_ index 57d7a75a0..b130b4662 100644 --- a/application/hub/main/handler/network/class_ +++ b/application/hub/main/handler/network/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class ???NetworkPackageHandler extends BaseNetworkPackageHandler implements !!! { +class ???NetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable { /** * Protected constructor * @@ -35,7 +35,7 @@ class ???NetworkPackageHandler extends BaseNetworkPackageHandler implements !!! /** * Creates an instance of this class * - * @return $handlerInstance An instance of a !!! class + * @return $handlerInstance An instance of a Networkable class */ public final static function create???NetworkPackageHandler () { // Get new instance @@ -44,6 +44,26 @@ class ???NetworkPackageHandler extends BaseNetworkPackageHandler implements !!! // Return the prepared instance return $handlerInstance; } + + /** + * Processes a package from given resource. This is mostly useful for TCP + * package handling and is implemented in the TcpListener class + * + * @param $resource A valid resource identifier + * @return void + * @throws InvalidResourceException If the given resource is invalid + * @todo 0% + */ + public function processResourcePackage ($resource) { + // Check the resource + if (!is_resource($resource)) { + // Throw an exception + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); + } // END - if + + // Implement processing here + $this->partialStub('Please implement this method.'); + } } // [EOF] diff --git a/application/hub/main/handler/network/class_BaseNetworkPackageHandler.php b/application/hub/main/handler/network/class_BaseNetworkPackageHandler.php index b9762e384..8d13405f6 100644 --- a/application/hub/main/handler/network/class_BaseNetworkPackageHandler.php +++ b/application/hub/main/handler/network/class_BaseNetworkPackageHandler.php @@ -22,6 +22,19 @@ * along with this program. If not, see . */ class BaseNetworkPackageHandler extends BaseHandler { + // Error codes + const SOCKET_ERROR_GENERAL = 'general_error'; + const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint'; + const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; + const SOCKET_ERROR_EMPTY_DATA = 'empty_data'; + const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; + const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; + + /** + * Error code from socket + */ + private $errorCode = -1; + /** * Protected constructor * @@ -32,6 +45,25 @@ class BaseNetworkPackageHandler extends BaseHandler { // Call parent constructor parent::__construct($className); } + + /** + * Setter for error code + * + * @param $errorCode The error code we shall set + * @return void + */ + protected final function setErrorCode ($errorCode) { + $this->errorCode = $errorCode; + } + + /** + * Getter for error code + * + * @return $errorCode The error code + */ + public final function getErrorCode () { + return $this->errorCode; + } } // [EOF] diff --git a/application/hub/main/handler/network/tcp/class_ b/application/hub/main/handler/network/tcp/class_ new file mode 100644 index 000000000..968182332 --- /dev/null +++ b/application/hub/main/handler/network/tcp/class_ @@ -0,0 +1,208 @@ +while (count($clients) > 0) { + // create a copy, so $clients doesn't get modified by socket_select() + $read = $clients; + + // get a list of all the clients that have data to be read from + // if there are no clients with data, go to next iteration + $left = @socket_select($read, $write = null, $except = null, 0, 150); + if ($left < 1) { + continue; + } + + // check if there is a client trying to connect + if (in_array($mainSocket, $read)) { + // accept the client, and add him to the $clients array + $new_sock = socket_accept($mainSocket); + $clients[] = $new_sock; + + // send the client a welcome message + socket_write($new_sock, "No noobs, but I'll make an exception. :)\n". + "There are ".(count($clients) - 1)." client(s) connected to the server.\n"); + + socket_getpeername($new_sock, $ip); + out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}"); + + // Notify all chatter + if (count($clients) > 2) { + foreach ($clients as $send_sock) { + if ($send_sock != $mainSocket && $send_sock != $new_sock) { + socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n"); + } + } + } + + // remove the listening socket from the clients-with-data array + $key = array_search($mainSocket, $read); + unset($read[$key]); + } + + // loop through all the clients that have data to read from + foreach ($read as $read_sock) { + // Get client data + socket_getpeername($read_sock, $ip); + + // read until newline or 1024 bytes + // socket_read while show errors when the client is disconnected, so silence the error messages + $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ); + + // check if the client is disconnected + if (($data === false) || (in_array(strtolower(trim($data)), $leaving))) { + + // remove client for $clients array + $key = array_search($read_sock, $clients); + unset($clients[$key]); + out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1).""); + + // Notify all chatter + if (count($clients) > 1) { + foreach ($clients as $send_sock) { + if ($send_sock != $mainSocket) { + socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n"); + } + } + } + + // continue to the next client to read from, if any + socket_write($read_sock, "Server: Good bye.\n"); + socket_shutdown($read_sock, 2); + socket_close($read_sock); + continue; + } elseif (in_array(trim($data), $shutdown)) { + // Is he allowed to shutdown? + if (!in_array($ip, $masters)) { + out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!"); + socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n"); + $data = ""; + continue; + } + + // Close all connections a leave here + foreach ($clients as $client) { + // Send message to client + if ($client !== $mainSocket && $client != $read_sock) { + socket_write($client, "Server: Shutting down! Thank you for joining us.\n"); + } + + // Quit him + socket_shutdown($client, 2); + socket_close($client); + } // end foreach + + // Leave the loop + $data = ""; + $clients = array(); + continue; + } + + // trim off the trailing/beginning white spaces + $data = trim($data); + + // Test for HTML codes + $tags = strip_tags($data); + + // check if there is any data after trimming off the spaces + if (!empty($data) && $tags == $data && count($clients) > 2) { + // Send confirmation to "chatter" + socket_write($read_sock, "\nServer: Message accepted.\n"); + + // send this to all the clients in the $clients array (except the first one, which is a listening socket) + foreach ($clients as $send_sock) { + + // if its the listening sock or the client that we got the message from, go to the next one in the list + if ($send_sock == $mainSocket || $send_sock == $read_sock) + continue; + + // write the message to the client -- add a newline character to the end of the message + socket_write($send_sock, "{$ip}:{$data}\n"); + + } // end of broadcast foreach + } elseif ($tags != $data) { + // HTML codes are not allowed + out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!"); + socket_write($read_sock, "Server: HTML is forbidden!\n"); + } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) { + // No one else will hear the "chatter" + out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself."); + socket_write($read_sock, "Server: No one will hear you!\n"); + } + } // end of reading foreach +} + +// close the listening socket +socket_close($mainSocket); + +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 . + */ +class ???Listener extends BaseListener implements Listenable, Visitable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $nodeInstance A NodeHelper instance + * @return $listenerInstance An instance a prepared listener class + */ + public final static function create???Listener (NodeHelper $nodeInstance) { + // Get new instance + $listenerInstance = new ???Listener(); + + // Set the application instance + $listenerInstance->setNodeInstance($nodeInstance); + + // Return the prepared instance + return $listenerInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + * @todo 0% done + */ + public function initListener() { + $this->partialStub('Need to implement this method.'); + } + + /** + * "Listens" for incoming network packages + * + * @return void + * @todo 0% done + */ + public function doListen() { + $this->partialStub('Need to implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php b/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php index 805c7627b..f2544adcd 100644 --- a/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php +++ b/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php @@ -35,15 +35,62 @@ class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw /** * Creates an instance of this class * - * @return $handlerInstance An instance of a !!! class + * @return $handlerInstance An instance of a Networkable class */ public final static function createTcpNetworkPackageHandler () { // Get new instance $handlerInstance = new TcpNetworkPackageHandler(); + // Initialize new resolver instance + $resolverInstance = ObjectFactory::createObjectByConfiguredName('network_state_resolver_class'); + + // Set it in this class + $handlerInstance->setResolverInstance($resolverInstance); + // Return the prepared instance return $handlerInstance; } + + /** + * Processes a package from given resource. This is mostly useful for TCP + * package handling and is implemented in the TcpListener class + * + * @param $resource A valid resource identifier + * @return void + * @throws InvalidResourceException If the given resource is invalid + * @todo 0% + */ + public function processResourcePackage ($resource) { + // Check the resource + if (!is_resource($resource)) { + // Throw an exception + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); + } // END - if + + // Reset error code to unhandled + $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED); + + // Read the raw data from socket + $rawData = socket_read($resource, 1500, PHP_BINARY_READ); + + // Is it valid? + if (($rawData === false) || (socket_last_error($resource) > 0)) { + // Network error or connection lost + $this->setErrorCode(socket_last_error($resource)); + } elseif (empty($rawData)) { + // The peer did send nothing to us + $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA); + } elseif (!$this->isPackageDataValid($rawData)) { + // Invalid package data + $this->setErrorCode(self::PACKAGE_ERROR_INVALID_DATA); + } else { + // Low-level checks are all green + $this->setErrorCode(self::PACKAGE_LEVEL_CHECK_OKAY); + } + + // Get a state from the resolver for this package + $stateInstance = $this->getResolverInstance()->resolveStateByPackage($this, $rawData); + } } // [EOF] diff --git a/application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php b/application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php index ce6489d7e..c62e7fca8 100644 --- a/application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php +++ b/application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php @@ -35,7 +35,7 @@ class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw /** * Creates an instance of this class * - * @return $handlerInstance An instance of a !!! class + * @return $handlerInstance An instance of a Networkable class */ public final static function createUdpNetworkPackageHandler () { // Get new instance @@ -44,6 +44,26 @@ class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw // Return the prepared instance return $handlerInstance; } + + /** + * Processes a package from given resource. This is mostly useful for TCP + * package handling and is implemented in the TcpListener class + * + * @param $resource A valid resource identifier + * @return void + * @throws InvalidResourceException If the given resource is invalid + * @todo 0% + */ + public function processResourcePackage ($resource) { + // Check the resource + if (!is_resource($resource)) { + // Throw an exception + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); + } // END - if + + // Implement processing here + $this->partialStub('Please implement this method.'); + } } // [EOF] diff --git a/application/hub/main/handler/tasks/.htaccess b/application/hub/main/handler/tasks/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/handler/tasks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/handler/tasks/class_TaskHandler.php b/application/hub/main/handler/tasks/class_TaskHandler.php new file mode 100644 index 000000000..c9b6c2040 --- /dev/null +++ b/application/hub/main/handler/tasks/class_TaskHandler.php @@ -0,0 +1,65 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 . + */ +class TaskHandler extends BaseHandler implements Registerable, HandleableTask { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a HandleableTask class + */ + public final static function createTaskHandler () { + // Get new instance + $handlerInstance = new TaskHandler(); + + // Output debug message + $handlerInstance->debugOutput('TASK-HANDLER: Task handler initialized.'); + + // Return the prepared instance + return $handlerInstance; + } + + /** + * Registers a task with a task handler. This method throws a + * TaskAlreadyRegisteredException if the task has already been registered + * + * @param $taskName A task name to register the task on + * @param $taskInstance The instance we should register as a task + * @return void + */ + public function registerTask ($taskName, Visitable $taskInstance) { + $this->partialStub('taskName=' . $taskName . '/' . $taskInstance->__toString()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index df8b0111d..50e6c0685 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -191,7 +191,7 @@ class TcpListener extends BaseListener implements Listenable { $current = $this->getIteratorInstance()->current(); // Handle it here - $this->getPackageInstance()->processPackage($current); + $this->getPackageInstance()->processResourcePackage($current); // Advance to next entry. This should be the last line $this->getIteratorInstance()->next(); diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index ea65be5b7..c6aba05b6 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -413,7 +413,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $controllerInstance = Registry::getRegistry()->getInstance('controller'); // Run all filters for the hub activation - $controllerInstance->executeHubActivationFilters($requestInstance, $responseInstance); + $controllerInstance->executeActivationFilters($requestInstance, $responseInstance); // ----------------------- Last step from here ------------------------ // Activate the hub. This is ALWAYS the last step in this method diff --git a/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php b/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php index f5a7fe1bd..54d2304f2 100644 --- a/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php +++ b/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php b/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php index 7bb04a909..c8f291c7a 100644 --- a/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php +++ b/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * diff --git a/application/hub/main/resolver/state/.htaccess b/application/hub/main/resolver/state/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/resolver/state/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/resolver/state/class_BaseStateResolver.php b/application/hub/main/resolver/state/class_BaseStateResolver.php new file mode 100644 index 000000000..a7dbc979c --- /dev/null +++ b/application/hub/main/resolver/state/class_BaseStateResolver.php @@ -0,0 +1,165 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 . + */ +class BaseStateResolver extends BaseResolver { + /** + * Prefix for local, remote or other resolver + */ + private $statePrefix = ''; + + /** + * Validated state name + */ + private $stateName = ''; + + /** + * Protected constructor + * + * @param $className Name of the real class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Setter for state prefix + * + * @param $statePrefix Last validated statePrefix + * @return void + */ + protected final function setStatePrefix ($statePrefix) { + $this->statePrefix = $statePrefix; + } + + /** + * Getter for state prefix + * + * @param $statePrefix Last validated statePrefix + * @return void + */ + protected final function getStatePrefix () { + return $this->statePrefix; + } + + /** + * Setter for state name + * + * @param $stateName Last validated state name + * @return void + */ + protected final function setStateName ($stateName) { + $this->stateName = $stateName; + } + + /** + * Getter for state name + * + * @return $stateName Last validated state name + */ + public final function getStateName () { + return $this->stateName; + } + + /** + * "Loads" a given state and instances it if not yet cached. If the + * state was not found an InvalidStateException is thrown + * + * @param $stateName A state name we shall look for + * @return $stateInstance A loaded state instance + * @throws InvalidStateException Thrown if even the requested + * state class is missing (bad!) + */ + protected function loadState ($stateName) { + // Init state instance + $stateInstance = null; + + // Create state class name + $className = $this->getStatePrefix() . '' . $this->convertToClassName($stateName) . 'State'; + + // ... and set it + $this->setClassName($className); + + // Is this class loaded? + if (!class_exists($this->getClassName())) { + // Throw an exception here + throw new InvalidStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE); + } // END - if + + // Initialize the state + $stateInstance = ObjectFactory::createObjectByName( + $this->getClassName(), + array($this) + ); + + // Return the result + return $stateInstance; + } + + /** + * Checks wether the given state is valid + * + * @param $stateName The default state we shall execute + * @return $isValid Wether the given state is valid + * @throws EmptyVariableException Thrown if given state is not set + * @throws DefaultStateException Thrown if default state was not found + */ + public function isStateValid ($stateName) { + // By default nothing shall be valid + $isValid = false; + + // Is a state set? + if (empty($stateName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'stateName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } // END - if + + // Create class name + $className = $this->statePrefix . $this->convertToClassName($stateName) . 'State'; + + // Now, let us create the full name of the state class + $this->setClassName($className); + + // Try it hard to get an state + while ($isValid === false) { + // Is this class already loaded? + if (class_exists($this->getClassName())) { + // This class does exist. :-) + $isValid = true; + } elseif ($this->getClassName() != $this->statePrefix.'DefaultNewsState') { + // Set default state + $this->setClassName($this->statePrefix . 'DefaultNewsState'); + } else { + // All is tried, give it up here + throw new DefaultStateException($this, self::EXCEPTION_DEFAULT_STATE_GONE); + } + } // END - while + + // Return the result + return $isValid; + } +} + +// [EOF] +?> diff --git a/application/hub/main/resolver/state/network/.htaccess b/application/hub/main/resolver/state/network/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/resolver/state/network/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/resolver/state/network/class_NetworkStateResolver.php b/application/hub/main/resolver/state/network/class_NetworkStateResolver.php new file mode 100644 index 000000000..11c129e0c --- /dev/null +++ b/application/hub/main/resolver/state/network/class_NetworkStateResolver.php @@ -0,0 +1,92 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 . + */ +class NetworkStateResolver extends BaseStateResolver implements StateResolver { + /** + * Last successfull resolved state (name) + */ + private $lastStateName = ''; + + /** + * Last successfull resolved state (instance) + */ + private $lastStateInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to 'Network' + $this->setStatePrefix('Network'); + } + + /** + * Creates an instance of a resolver class with a given state + * + * @return $resolverInstance The prepared state resolver instance + * @throws EmptyVariableException Thrown if default state is not set + * @throws InvalidStateException Thrown if default state is invalid + */ + public final static function createNetworkStateResolver () { + // Create the new instance + $resolverInstance = new NetworkStateResolver(); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an state instance for a given package class + * + * @param $packageInstance An instance of a package class + * @param $rawData The raw data + * @return $stateInstance An instance of the resolved state + * @todo 0% + */ + public function resolveStateByPackage (Networkable $packageInstance, $rawData) { + // Get error code + $errorCode = $packageInstance->getErrorCode(); + + // Is the code a number, then we have to change it + if ($errorCode == 134) { + // Transport endpoint not connected, should be handled else! + $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT; + } elseif (is_int($errorCode)) { + // Debug output (because we might want to handle it like the above(s) + $this->debugOutput(__METHOD__ . ': errorCode=' . $errorCode); + + // Change it only in this class + $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_GENERAL; + } // END - if + + $this->partialStub('errorCode='.$errorCode.',rawData[] = '.gettype($rawData).'('.strlen($rawData).')'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/generic/.htaccess b/application/hub/main/states/generic/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/generic/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/index.php b/index.php index cf898bf7d..f717dd4fa 100644 --- a/index.php +++ b/index.php @@ -12,7 +12,7 @@ define('DEVELOPER', true); * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * -- 2.39.5