/** Checks if this achievement has been achieved. */ void Achievement::check() { if(m_achieved) return; if(m_achievement_info->checkCompletion(this)) { //show achievement core::stringw s = StringUtils::insertValues(_("Completed achievement \"%s\"."), m_achievement_info->getTitle()); GUIEngine::DialogQueue::get()->pushDialog( new NotificationDialog(NotificationDialog::T_Achievements, s)); // Sends a confirmation to the server that an achievement has been // completed, if a user is signed in. if (PlayerManager::isCurrentLoggedIn()) { Online::HTTPRequest * request = new Online::HTTPRequest(true); PlayerManager::setUserDetails(request, "achieving"); request->addParameter("achievementid", m_id); request->queue(); } m_achieved = true; } } // check
/** Checks if this achievement has been achieved. */ void Achievement::check() { if(m_achieved) return; if(m_achievement_info->checkCompletion(this)) { //show achievement // Note: the "name" variable is required, see issue #2068 // calling _("...", info->getName()) is invalid because getName also calls // _() and thus the string it returns is mapped to a temporary buffer // in theory, it should return a copy of the string, but clang tries to // optimise away the copy core::stringw name = m_achievement_info->getName(); core::stringw s = _("Completed achievement \"%s\".", name); MessageQueue::add(MessageQueue::MT_ACHIEVEMENT, s); // Sends a confirmation to the server that an achievement has been // completed, if a user is signed in. if (PlayerManager::isCurrentLoggedIn()) { Online::HTTPRequest * request = new Online::HTTPRequest(true); PlayerManager::setUserDetails(request, "achieving"); request->addParameter("achievementid", m_id); request->queue(); } m_achieved = true; } } // check
/** Synchronises the achievements between local and online usage. It takes * the list of online achievements, and marks them all to be achieved * locally. Then it issues 'achieved' requests to the server for all local * achievements that are not set online. */ void AchievementsStatus::sync(const std::vector<uint32_t> & achieved_ids) { std::vector<bool> done; for(unsigned int i =0; i < achieved_ids.size(); ++i) { if(done.size()< achieved_ids[i]+1) done.resize(achieved_ids[i]+1); done[achieved_ids[i]] = true; Achievement * achievement = getAchievement(achieved_ids[i]); if(achievement != NULL) achievement->setAchieved(); } std::map<uint32_t, Achievement*>::iterator i; // String to collect all local ids that are not synched // to the online account std::string ids; for(i=m_achievements.begin(); i!=m_achievements.end(); i++) { unsigned int id = i->second->getID(); if(i->second->isAchieved() && (id>=done.size() || !done[id]) ) { ids=ids+StringUtils::toString(id)+","; } } if(ids.size()>0) { ids = ids.substr(0, ids.size() - 1); // delete the last "," in the string Log::info("Achievements", "Synching achievement %d to server.", ids.c_str()); Online::HTTPRequest * request = new Online::HTTPRequest(true, 2); PlayerManager::setUserDetails(request, "achieving"); request->addParameter("achievementid", ids); request->queue(); } } // sync
/** If the configuration of this installation has not been reported for the * current version, collect the hardware statistics and send it to STK's * server. */ void reportHardwareStats() { // Version of the hw report, which is stored in the DB. If new fields // are added, increase this version. Each STK installation will report // its configuration only once (per version number). So if the version // number is increased, a new report will be sent. const int report_version = 1; if(UserConfigParams::m_last_hw_report_version>=report_version) return; while(UserConfigParams::m_random_identifier==0) { RandomGenerator rg; UserConfigParams::m_random_identifier = rg.get(1<<30); user_config->saveConfig(); } Json json; #ifdef WIN32 json.add("os_win", 1); #else json.add("os_win", 0); #endif #ifdef __APPLE__ json.add("os_macosx", 1); #else json.add("os_macosx", 0); #endif #ifdef __linux__ json.add("os_linux", 1); json.add("os_unix", 1); #else json.add("os_linux", 0); json.add("os_unix", 0); #endif #ifdef DEBUG json.add("build_debug", 1); #endif json.add("os_version", getOSVersion()); unsigned int ogl_version = irr_driver->getGLSLVersion(); unsigned int major = ogl_version/100; unsigned int minor = ogl_version - 100*major; std::string version = StringUtils::insertValues("%d.%d", major, minor); json.add("GL_SHADING_LANGUAGE_VERSION", version); std::string vendor, renderer, full_version; irr_driver->getOpenGLData(&vendor, &renderer, &full_version); json.add("GL_VENDOR", vendor ); json.add("GL_RENDERER", renderer ); json.add("GL_VERSION", full_version ); json.add("gfx_drv_ver", "OpenGL "+vendor); std::string card_name = vendor; if(StringUtils::startsWith(card_name, "ATI Technologies Inc.")) card_name="ATI"; else if (StringUtils::startsWith(card_name, "NVIDIA Corporation")) card_name="NVIDIA"; else if(StringUtils::startsWith(card_name, "S3 Graphics")) card_name="S3"; json.add("gfx_card", card_name+" "+renderer); json.add("video_xres", UserConfigParams::m_width ); json.add("video_yres", UserConfigParams::m_height); int mem = getRAM(); if(mem>0) json.add("ram_total", mem); int nr_procs = getNumProcessors(); if(nr_procs>0) json.add("cpu_numprocs", nr_procs); json.add("GL_EXTENSIONS", getGLExtensions()); getGLLimits(&json); json.finish(); // ------------------------------------------------------------------------ /** A small class which sends the HW report to the STK server. On * completion, it will either update the last-submitted-hw-report version, * or log an error message (in which case next time STK is started it * wil try again to log the report). */ class HWReportRequest : public Online::HTTPRequest { private: /** Version number of the hw report. */ int m_version; public: HWReportRequest(int version) : Online::HTTPRequest(/*manage memory*/true, 1) , m_version(version) {} // -------------------------------------------------------------------- /** Callback after the request has been executed. */ virtual void callback() { // If the request contains incorrect data, it will not have a // download error, but return an error string as return value: if(hadDownloadError() || getData()=="<h1>Bad Request (400)</h1>") { Log::error("HW report", "Error uploading the HW report."); if(hadDownloadError()) Log::error("HW report", "%s", getDownloadErrorMessage()); else Log::error("HW report", "%s", getData().c_str()); } else { Log::info("HW report", "Upload successful."); UserConfigParams::m_last_hw_report_version = m_version; // The callback is executed by the main thread, so no need // to worry about locks when writing the file. user_config->saveConfig(); } } // callback }; // HWReportRequest // ------------------------------------------------------------------------ Online::HTTPRequest *request = new HWReportRequest(report_version); request->addParameter("user_id", UserConfigParams::m_random_identifier); request->addParameter("time", StkTime::getTimeSinceEpoch()); request->addParameter("type", "hwdetect"); request->addParameter("version", report_version); request->addParameter("data", json.toString()); request->setURL((std::string)UserConfigParams::m_server_hw_report+"/upload/v1/"); //request->setURL("http://127.0.0.1:8000/upload/v1/"); request->queue(); } // reportHardwareStats