// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> bool Route::detachFrom(PublicObject* object) { if ( object == NULL ) return false; // check all possible parents Routing* routing = Routing::Cast(object); if ( routing != NULL ) { // If the object has been added already to the parent locally // just remove it by pointer if ( object == parent() ) return routing->remove(this); // The object has not been added locally so it must be looked up else { Route* child = routing->findRoute(publicID()); if ( child != NULL ) return routing->remove(child); else { SEISCOMP_DEBUG("Route::detachFrom(Routing): route has not been found"); return false; } } } SEISCOMP_ERROR("Route::detachFrom(%s) -> wrong class type", object->className()); return false; }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> bool Route::attachTo(PublicObject* parent) { if ( parent == NULL ) return false; // check all possible parents Routing* routing = Routing::Cast(parent); if ( routing != NULL ) return routing->add(this); SEISCOMP_ERROR("Route::attachTo(%s) -> wrong class type", parent->className()); return false; }
/** * @brief Calculated the new height level when something falls down from a certain position. * @param[in] routing Reference to client or server side routing table (clMap, svMap) * @param[in] pos Position in the map to start the fall (starting height is the z-value in this position) * @param[in] actorSize Give the field size of the actor (e.g. for 2x2 units) to check linked fields as well. * @return New z (height) value. * @return 0xFF if an error occurred. */ pos_t Grid_Fall (const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos) { int z = pos[2], base, diff; bool flier = false; /** @todo if an actor can fly, then set this to true. */ /* Is z off the map? */ if (z >= PATHFINDING_HEIGHT) { return 0xFF; } /* If we can fly, then obviously we won't fall. */ if (flier) return z; /* Easy math- get the floor, integer divide by CELL_HEIGHT, add to z. * If z < 0, we are going down. * If z >= CELL_HEIGHT, we are going up. * If 0 <= z <= CELL_HEIGHT, then z / 16 = 0, no change. */ base = routing.getFloor(actorSize, pos[0], pos[1], z); /* Hack to deal with negative numbers- otherwise rounds toward 0 instead of down. */ diff = base < 0 ? (base - (CELL_HEIGHT - 1)) / CELL_HEIGHT : base / CELL_HEIGHT; z += diff; /* The tracing code will set locations without a floor to -1. Compensate for that. */ if (z < 0) z = 0; else if (z >= PATHFINDING_HEIGHT) z = PATHFINDING_HEIGHT - 1; return z; }
/** * @brief Returns the height of the floor in a cell. * @param[in] routing Reference to client or server side routing table (clMap, svMap) * @param[in] actorSize width of the actor in cells * @param[in] pos Position in the map to check the height * @return The actual model height of the cell's floor. */ int Grid_Floor (const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos) { assert(pos[2] < PATHFINDING_HEIGHT); return QuantToModel(routing.getFloor(actorSize, pos[0], pos[1], pos[2] & (PATHFINDING_HEIGHT - 1))); }
/** * @brief Returns the height of the floor in a cell. * @param[in] routing Reference to client or server side routing table (clMap, svMap) * @param[in] actorSize width of the actor in cells * @param[in] pos Position in the map to check the height * @return The actual model height of the cell's ceiling. */ unsigned int Grid_Ceiling (const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos) { assert(pos[2] < PATHFINDING_HEIGHT); return QuantToModel(routing.getCeiling(actorSize, pos[0], pos[1], pos[2] & 7)); }
/** * @brief Calculates the routing of a map * @sa CheckUnit * @sa CheckConnections * @sa ProcessWorldModel */ void DoRouting (void) { int i; byte* data; vec3_t mins, maxs; pos3_t pos; /* Turn on trace debugging if requested. */ if (config.generateDebugTrace) debugTrace = true; /* Record the current mapTiles[0] state so we can remove all CLIPS when done. */ PushInfo(); /* build tracing structure */ EmitBrushes(); EmitPlanes(); /** This is needed for tracing to work!!! */ /** @note LEVEL_TRACING is not an actual level */ MakeTracingNodes(LEVEL_ACTORCLIP + 1); /* Reset the whole block of map data to 0 */ Nmap.init(); /* get world bounds for optimizing */ RT_GetMapSize(&mapTiles, mins, maxs); /* Com_Printf("Vectors: (%f, %f, %f) to (%f, %f, %f)\n", mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]); */ VecToPos(mins, wpMins); VecToPos(maxs, wpMaxs); /* Verify the world extents are not lopsided. */ assert(wpMins[0] <= wpMaxs[0]); assert(wpMins[1] <= wpMaxs[1]); assert(wpMins[2] <= wpMaxs[2]); /* scan area heights */ RunSingleThreadOn(CheckUnitThread, PATHFINDING_WIDTH * PATHFINDING_WIDTH * ACTOR_MAX_SIZE, config.verbosity >= VERB_NORMAL, "UNITCHECK"); /* scan connections */ RunSingleThreadOn(CheckConnectionsThread, PATHFINDING_WIDTH * PATHFINDING_WIDTH * (CORE_DIRECTIONS / (1 + RT_IS_BIDIRECTIONAL)) * (ACTOR_MAX_SIZE), config.verbosity >= VERB_NORMAL, "CONNCHECK"); /* Try to shrink the world bounds along the x and y coordinates */ for (i = 0; i < 2; i++) { /* for x and y, but not z */ int j = i ^ 1; /* if i points to x, j points to y and vice versa */ /* Increase the mins */ while (wpMaxs[j] > wpMins[j]) { VectorSet(pos, wpMins[0], wpMins[1], wpMaxs[2]); for (pos[i] = wpMins[i]; pos[i] <= wpMaxs[i]; pos[i]++) { /* for all cells in an x or y row */ if (Nmap.getFloor(1, pos[0], pos[1], wpMaxs[2]) + wpMaxs[2] * CELL_HEIGHT != -1) /* no floor ? */ break; } if (pos[i] <= wpMaxs[i]) /* found a floor before the end of the row ? */ break; /* break while */ wpMins[j]++; /* if it was an x-row, increase y-value of mins and vice versa */ } /* Decrease the maxs */ while (wpMaxs[j] > wpMins[j]) { VectorCopy(wpMaxs, pos); for (pos[i] = wpMins[i]; pos[i] <= wpMaxs[i]; pos[i]++) { if (Nmap.getFloor(1, pos[0], pos[1], wpMaxs[2]) + wpMaxs[2] * CELL_HEIGHT != -1) break; } if (pos[i] <= wpMaxs[i]) break; wpMaxs[j]--; } } /* Output the floor trace file if set */ if (config.generateTraceFile) { RT_WriteCSVFiles(Nmap, baseFilename, wpMins, wpMaxs); } /* store the data */ data = curTile->routedata; for (i = 0; i < 3; i++) wpMins[i] = LittleLong(wpMins[i]); data = CompressRouting((byte*)wpMins, data, sizeof(wpMins)); for (i = 0; i < 3; i++) wpMaxs[i] = LittleLong(wpMaxs[i]); data = CompressRouting((byte*)wpMaxs, data, sizeof(wpMaxs)); data = CompressRouting((byte*)&Nmap, data, sizeof(Nmap)); curTile->routedatasize = data - curTile->routedata; /* Ensure that we did not exceed our allotment of memory for this data. */ assert(curTile->routedatasize <= MAX_MAP_ROUTING); /* Remove the CLIPS fom the tracing structure by resetting it. */ PopInfo(); }
void TActionContext::execute() { T_TRACEFUNC(); try { httpSocket = new THttpSocket; if (!httpSocket->setSocketDescriptor(socketDesc)) { emitError(httpSocket->error()); delete httpSocket; httpSocket = 0; return; } else { socketDesc = 0; } while (!httpSocket->canReadRequest()) { if (stopped) { tSystemDebug("Detected stop request"); break; } // Check timeout if (!httpSocket->waitForReadyRead(10000)) { tWarn("Read timed out after 10 seconds."); break; } } if (!httpSocket->canReadRequest()) { httpSocket->abort(); delete httpSocket; httpSocket = 0; return; } THttpRequest httpRequest = httpSocket->read(); const THttpRequestHeader &hd = httpRequest.header(); // Access log QByteArray firstLine = hd.method() + ' ' + hd.path(); firstLine += QString(" HTTP/%1.%2").arg(hd.majorVersion()).arg(hd.minorVersion()).toLatin1(); TAccessLog accessLog(httpSocket->peerAddress().toString().toLatin1(), firstLine); tSystemDebug("method : %s", hd.method().data()); tSystemDebug("path : %s", hd.path().data()); Tf::HttpMethod method = httpRequest.method(); QString path = THttpUtility::fromUrlEncoding(hd.path().split('?').value(0)); // Routing info exists? Routing rt = TUrlRoute::instance().findRouting(method, path); tSystemDebug("Routing: controller:%s action:%s", rt.controller.data(), rt.action.data()); if (rt.isEmpty()) { // Default URL routing rt.params = path.split('/'); if (path.startsWith(QLatin1Char('/')) && !rt.params.isEmpty()) { rt.params.removeFirst(); // unuse first item } if (path.endsWith(QLatin1Char('/')) && !rt.params.isEmpty()) { rt.params.removeLast(); // unuse last item } // Direct view render mode? if (Tf::app()->treefrogSettings().value(DIRECT_VIEW_RENDER_MODE).toBool()) { // Direct view setting rt.controller = "directcontroller"; rt.action = "show"; QString tmp = rt.params.join("/"); rt.params.clear(); rt.params << tmp; } else { if (!rt.params.value(0).isEmpty()) { rt.controller = rt.params.takeFirst().toLower().toLatin1() + "controller"; if (!rt.params.value(0).isEmpty()) { rt.action = rt.params.takeFirst().toLatin1(); } } tSystemDebug("Active Controller : %s", rt.controller.data()); } } // Call controller method TDispatcher<TActionController> ctlrDispatcher(rt.controller); TActionController *controller = ctlrDispatcher.object(); if (controller) { controller->setActionName(rt.action); controller->setHttpRequest(httpRequest); openDatabase(); // Session if (controller->sessionEnabled()) { TSession session; QByteArray sessionId = httpRequest.cookie(TSession::sessionName()); if (!sessionId.isEmpty()) { session = TSessionManager::instance().find(sessionId); } controller->setSession(session); // Exports flash-variant controller->exportAllFlashVariants(); } // Verify authenticity token if (controller->forgeryProtectionEnabled() && !controller->protectFromForgeryExcept().contains(rt.action)) { if (method == Tf::Post || method == Tf::Put || method == Tf::Delete) { if (!controller->verifyRequest(httpRequest)) { throw SecurityException("Invalid authenticity token", __FILE__, __LINE__); } } } // Sets the default status code of HTTP response int statusCode = 404; // Not Found // Re-generate session ID if (controller->sessionEnabled() && (controller->session().id().isEmpty() || Tf::app()->treefrogSettings().value(AUTO_ID_REGENERATION).toBool())) { controller->session().regenerateId(); } if (controller->transactionEnabled()) { // Begins a transaction on the database beginTransaction(); } // Do filters if (controller->preFilter()) { // Dispathes bool dispatched = ctlrDispatcher.invoke(rt.action, rt.params); if (dispatched) { autoRemoveFiles = controller->autoRemoveFiles; // Set auto remove files // Post fileter controller->postFilter(); if (controller->transactionEnabled() && !controller->rollbackEnabled()) { // Commits a transaction to the database commitTransaction(); } // Session store if (controller->sessionEnabled()) { bool stored = TSessionManager::instance().store(controller->session()); if (stored) { controller->addCookie(TSession::sessionName(), controller->session().id(), QDateTime(), "/"); } } // Sets status code statusCode = (!controller->response.isBodyNull()) ? controller->statusCode() : 500 /* Internal Server Error */; } } controller->response.header().setStatusLine(statusCode, THttpUtility::getResponseReasonPhrase(statusCode)); accessLog.statusCode = statusCode; accessLog.responseBytes = writeResponse(controller->response.header(), controller->response.bodyIODevice(), controller->response.bodyLength()); // Outputs access log tAccessLog(accessLog); } if (!controller) { // GET Method? if (method == Tf::Get) { path.remove(0, 1); QFile reqPath(Tf::app()->publicPath() + path); QFileInfo fi(reqPath); if (fi.isFile() && fi.isReadable()) { QByteArray type = Tf::app()->internetMediaType(fi.suffix()); writeResponse(200, type, &reqPath, reqPath.size()); } else { writeResponse(404); // Not Found } } else if (method == Tf::Post) { // file upload? } else { // HEAD, DELETE, ... } } } catch (ClientErrorException &e) { tWarn("Caught ClientErrorException: status code:%d", e.statusCode()); writeResponse(e.statusCode()); } catch (SqlException &e) { tError("Caught SqlException: %s [%s:%d]", qPrintable(e.message()), qPrintable(e.fileName()), e.lineNumber()); } catch (SecurityException &e) { tError("Caught SecurityException: %s [%s:%d]", qPrintable(e.message()), qPrintable(e.fileName()), e.lineNumber()); } catch (RuntimeException &e) { tError("Caught RuntimeException: %s [%s:%d]", qPrintable(e.message()), qPrintable(e.fileName()), e.lineNumber()); } catch (...) { tError("Caught Exception"); } closeDatabase(); httpSocket->disconnectFromHost(); // Destorys the object in the thread which created it delete httpSocket; httpSocket = 0; }