]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/handler/message-types/class_BaseMessageHandler.php
Continued rewriting:
[hub.git] / application / hub / main / handler / message-types / class_BaseMessageHandler.php
index 7770d236b39bd613c4163a46d8341ed3d28622c3..78902af7194494461aceafaa71856ab5ba18e676 100644 (file)
@@ -3,11 +3,11 @@
  * A general message handler, this class must be abstract to make the template
  * method pattern working.
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.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
@@ -58,55 +58,18 @@ abstract class BaseMessageHandler extends BaseDataHandler {
         * following data must always be present:
         *
         * - session-id  (for finding the node's record together with below data)
-        * - external-ip (hostname or IP number)
-        * - tcp-port    (TCP port for inbound connections)
+        * - external-address (hostname or IP number)
+        * - listen-port (TCP/UDP listen port for inbound connections)
         *
         * @param       $messageArray   An array with all minimum message data
         * @return      void
-        * @todo        Add something more, e.g. spreading information over DHT
         */
        protected function registerNodeByMessageData (array $messageData) {
                // Check if searchData has entries
-               assert(count($this->searchData) > 0);
+               assert(count($this->getSearchData()) > 0);
 
-               // Get a wrapper instance
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
-
-               // Get a search criteria class
-               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData=' . print_r($messageData, true));
-
-               // Search for the node's session id and external IP/hostname + TCP port
-               foreach ($this->searchData as $key) {
-                       // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
-
-                       // Is it there?
-                       assert(isset($messageData[$key]));
-
-                       // Add criteria
-                       $searchInstance->addCriteria('node_' . str_replace('my-', '', $key), $messageData[$key]);
-               } // END - foreach
-
-               // Only one entry is fine
-               $searchInstance->setLimit(1);
-
-               // Run the query
-               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
-
-               // Is there already an entry?
-               if ($resultInstance->next()) {
-                       // Entry found, so update it
-                       $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance);
-               } else {
-                       // Nothing found, so register it
-                       $wrapperInstance->registerNodeByMessageData($messageData, $this);
-               }
-
-               // Save last exception
-               $this->setLastException($wrapperInstance->getLastException());
+               // Let the DHT facade do the work
+               $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
        }
 }