* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable { /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); // Set handler name $this->setHandlerName('answer_okay'); } /** * Creates an instance of this class * * @return $handlerInstance An instance of a HandleableMessage class */ public final static function createAnnouncementAnswerOkayHandler () { // Get new instance $handlerInstance = new AnnouncementAnswerOkayHandler(); // Return the prepared instance return $handlerInstance; } /** * Handles given message data array * * @param $messageData An array of message data * @param $packageInstance An instance of a Receivable class * @return void * @throws NodeSessionIdVerficationException If the provided session id is not matching * @todo Do some more here: Handle karma, et cetera? */ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) { // Get a database wrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class'); // Get also a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Lookup external session id/external IP/port $searchInstance->addCriteria('node_session_id' , $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]); $searchInstance->addCriteria('node_external_ip', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP]); $searchInstance->addCriteria('node_tcp_port' , $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT]); // Only one entry is fine $searchInstance->setLimit(1); // Run the query $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); // Is there an try? if (!$resultInstance->next()) { // This is fatal, caused by "stolen" session id and/or not matching IP number/port combination throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING); } // END - if // Update node data (include status code) $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance); // Get the node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); // Change state $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful(); // Prepare next message $this->prepareNextMessage($messageData, $packageInstance); } } // [EOF] ?>