示例#1
0
void YggdrasilTask::executeTask()
{
	setStatus(getStateMessage(STATE_SENDING_REQUEST));

	// Get the content of the request we're going to send to the server.
	QJsonDocument doc(getRequestContent());

	auto worker = MMC->qnam();
	QUrl reqUrl("https://" + URLConstants::AUTH_BASE + getEndpoint());
	QNetworkRequest netRequest(reqUrl);
	netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");

	QByteArray requestData = doc.toJson();
	m_netReply = worker->post(netRequest, requestData);
	connect(m_netReply, &QNetworkReply::finished, this, &YggdrasilTask::processReply);
	connect(m_netReply, &QNetworkReply::uploadProgress, this, &YggdrasilTask::refreshTimers);
	connect(m_netReply, &QNetworkReply::downloadProgress, this, &YggdrasilTask::refreshTimers);
	connect(m_netReply, &QNetworkReply::sslErrors, this, &YggdrasilTask::sslErrors);
	timeout_keeper.setSingleShot(true);
	timeout_keeper.start(timeout_max);
	counter.setSingleShot(false);
	counter.start(time_step);
	progress(0, timeout_max);
	connect(&timeout_keeper, &QTimer::timeout, this, &YggdrasilTask::abort);
	connect(&counter, &QTimer::timeout, this, &YggdrasilTask::heartbeat);
}
示例#2
0
int
MSNet::simulate(SUMOTime start, SUMOTime stop) {
    // the simulation loop
    std::string quitMessage = "";
    myStep = start;
    do {
        if (myLogStepNumber) {
            preSimStepOutput();
        }
        simulationStep();
        if (myLogStepNumber) {
            postSimStepOutput();
        }
        MSNet::SimulationState state = simulationState(stop);
#ifndef NO_TRACI
        if (state!=SIMSTATE_RUNNING) {
            if (OptionsCont::getOptions().getInt("remote-port")!=0&&!traci::TraCIServer::wasClosed()) {
                state = SIMSTATE_RUNNING;
            }
        }
#endif
        if (state!=SIMSTATE_RUNNING) {
            quitMessage = "Simulation End: " + getStateMessage(state);
        }
    } while (quitMessage=="");
    WRITE_MESSAGE(quitMessage);
    // exit simulation loop
    closeSimulation(start);
    return 0;
}
示例#3
0
int
MSNet::simulate(SUMOTime start, SUMOTime stop) {
    // report the begin when wished
    WRITE_MESSAGE("Simulation started with time: " + time2string(start));
    // the simulation loop
    MSNet::SimulationState state = SIMSTATE_RUNNING;
    myStep = start;
    // preload the routes especially for TraCI
    loadRoutes();
#ifndef NO_TRACI
#ifdef HAVE_PYTHON
    if (OptionsCont::getOptions().isSet("python-script")) {
        traci::TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
        closeSimulation(start);
        WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
        WRITE_MESSAGE("Reason: Script ended");
        return 0;
    }
#endif
#endif
    while (state == SIMSTATE_RUNNING) {
        if (myLogStepNumber) {
            preSimStepOutput();
        }
        simulationStep();
        if (myLogStepNumber) {
            postSimStepOutput();
        }
        state = simulationState(stop);
#ifndef NO_TRACI
        if (state != SIMSTATE_RUNNING) {
            if (OptionsCont::getOptions().getInt("remote-port") != 0 && !traci::TraCIServer::wasClosed()) {
                state = SIMSTATE_RUNNING;
            }
        }
#endif
    }
    // report the end when wished
    WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
    WRITE_MESSAGE("Reason: " + getStateMessage(state));
    // exit simulation loop
    closeSimulation(start);
    return 0;
}
示例#4
0
int MSNet::simulate(SUMOTime start, SUMOTime stop)
{
  OptionsCont &oc = OptionsCont::getOptions();
  if(oc.getSimulationVerbosity()>1)
    std::cout<<"----> void MSNet::simulate(...)"<<std::endl;  
  //if((oc.getString("net-file").find("munchen"))||
  // (oc.getString("net-file").find("munich")))
  if(oc.getSafeBool("ger"))
    setCity("munchen");
  //else if(oc.getString("net-file").find("cambiano"))
  else if(oc.getSafeBool("ita"))
    setCity("cambiano");
  else
    setCity("unknown");
  // the simulation loop
  MSNet::SimulationState state = SIMSTATE_RUNNING;
  myStep = start;
#ifndef NO_TRACI
#ifdef HAVE_PYTHON
  if(OptionsCont::getOptions().isSet("python-script")) {
    traci::TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
    WRITE_MESSAGE("Simulation End: Script ended");
    closeSimulation(start);
    return 0;
  }
#endif
#endif
  // Initialize weather conditions
  if(oc.isSet("fiet"))
    setCurrentEnvTemp(oc.getFloat("fiet"));
  else
    setCurrentEnvTemp(5.3);
  if(oc.isSet("fieh"))
    setCurrentEnvHum(oc.getFloat("fieh"));
  else
    setCurrentEnvHum(67.8);
  while(state == SIMSTATE_RUNNING)
  {
    if(myLogStepNumber)
        preSimStepOutput();
    simulationStep();
    // FIXME Custom wait
    //for(int i=0;i++<0x00003fff;)for(int j=0;j++<0x00000fff;);
    if(oc.getSafeBool("rwc") || oc.getSafeBool("rlwc"))
      updateWeather();
    if(myLogStepNumber)
        postSimStepOutput();
    state = simulationState(stop);
#ifndef NO_TRACI
    if(state != SIMSTATE_RUNNING)
    {
      if(OptionsCont::getOptions().getInt("remote-port") != 0 && !traci::TraCIServer::wasClosed())
        state = SIMSTATE_RUNNING;
    }
#endif
  }
  WRITE_MESSAGE("Simulation End: " + getStateMessage(state));
  // exit simulation loop
  closeSimulation(start);
  return 0;
}
示例#5
0
void YggdrasilTask::processReply()
{
	setStatus(getStateMessage(STATE_PROCESSING_RESPONSE));

	if (m_netReply->error() == QNetworkReply::SslHandshakeFailedError)
	{
		emitFailed(
			tr("<b>SSL Handshake failed.</b><br/>There might be a few causes for it:<br/>"
			   "<ul>"
			   "<li>You use Windows XP and need to <a "
			   "href=\"http://www.microsoft.com/en-us/download/details.aspx?id=38918\">update "
			   "your root certificates</a></li>"
			   "<li>Some device on your network is interfering with SSL traffic. In that case, "
			   "you have bigger worries than Minecraft not starting.</li>"
			   "<li>Possibly something else. Check the MultiMC log file for details</li>"
			   "</ul>"));
		return;
	}

	// any network errors lead to offline mode right now
	if (m_netReply->error() >= QNetworkReply::ConnectionRefusedError &&
		m_netReply->error() <= QNetworkReply::UnknownNetworkError)
	{
		// WARNING/FIXME: the value here is used in MojangAccount to detect the cancel/timeout
		emitFailed("Yggdrasil task cancelled.");
		QLOG_ERROR() << "Yggdrasil task cancelled because of: " << m_netReply->error() << " : "
					 << m_netReply->errorString();
		return;
	}

	// Try to parse the response regardless of the response code.
	// Sometimes the auth server will give more information and an error code.
	QJsonParseError jsonError;
	QByteArray replyData = m_netReply->readAll();
	QJsonDocument doc = QJsonDocument::fromJson(replyData, &jsonError);
	// Check the response code.
	int responseCode = m_netReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

	if (responseCode == 200)
	{
		// If the response code was 200, then there shouldn't be an error. Make sure
		// anyways.
		// Also, sometimes an empty reply indicates success. If there was no data received,
		// pass an empty json object to the processResponse function.
		if (jsonError.error == QJsonParseError::NoError || replyData.size() == 0)
		{
			if (processResponse(replyData.size() > 0 ? doc.object() : QJsonObject()))
			{
				emitSucceeded();
				return;
			}

			// errors happened anyway?
			emitFailed(m_error ? m_error->m_errorMessageVerbose
							   : tr("An unknown error occurred when processing the response "
									"from the authentication server."));
		}
		else
		{
			emitFailed(tr("Failed to parse Yggdrasil JSON response: %1 at offset %2.")
						   .arg(jsonError.errorString())
						   .arg(jsonError.offset));
		}
		return;
	}

	// If the response code was not 200, then Yggdrasil may have given us information
	// about the error.
	// If we can parse the response, then get information from it. Otherwise just say
	// there was an unknown error.
	if (jsonError.error == QJsonParseError::NoError)
	{
		// We were able to parse the server's response. Woo!
		// Call processError. If a subclass has overridden it then they'll handle their
		// stuff there.
		QLOG_DEBUG() << "The request failed, but the server gave us an error message. "
						"Processing error.";
		emitFailed(processError(doc.object()));
	}
	else
	{
		// The server didn't say anything regarding the error. Give the user an unknown
		// error.
		QLOG_DEBUG() << "The request failed and the server gave no error message. "
						"Unknown error.";
		emitFailed(tr("An unknown error occurred when trying to communicate with the "
					  "authentication server: %1").arg(m_netReply->errorString()));
	}
}