// ----------------------------------------------------------------------------------- void dispAdditionalInfo( void ) { /* We now need to display the mission time, game time, average unit experience level an number of artefacts found */ /* Firstly, top of the screen, number of artefacts found */ sprintf( text, _("ARTIFACTS RECOVERED: %d"), missionData.artefactsFound ); iV_DrawText( text, (pie_GetVideoBufferWidth() - iV_GetTextWidth(text))/2, 300 + D_H ); /* Get the mission result time in a string - and write it out */ getAsciiTime( (char*)&text2, gameTime - missionData.missionStarted ); sprintf( text, _("Mission Time - %s"), text2 ); iV_DrawText( text, (pie_GetVideoBufferWidth() - iV_GetTextWidth(text))/2, 320 + D_H); /* Write out total game time so far */ getAsciiTime( (char*)&text2, gameTime ); sprintf( text, _("Total Game Time - %s"), text2 ); iV_DrawText( text, (pie_GetVideoBufferWidth() - iV_GetTextWidth(text))/2, 340 + D_H ); if (Cheated) { // A quick way to flash the text ((gameTime2 / 250) % 2) ? iV_SetTextColour(WZCOL_RED) : iV_SetTextColour(WZCOL_YELLOW); sprintf( text, _("You cheated!")); iV_DrawText( text, (pie_GetVideoBufferWidth() - iV_GetTextWidth(text))/2, 360 + D_H ); iV_SetTextColour(WZCOL_TEXT_BRIGHT); } }
TEST_F(PlistBenchmark, bench_parse_plist_content) { // using LOG(ERROR) as a quick hack so that gtest displays the log line even // when the test passes LOG(ERROR) << "Starting: " << getAsciiTime(); LOG(ERROR) << "Performing " << FLAGS_iterations << " iterations"; int time = getUnixTime(); for (int i = 0; i < FLAGS_iterations; ++i) { std::string content = getPlistContent(); pt::ptree tree; auto s = parsePlistContent(content, tree); EXPECT_TRUE(s.ok()); EXPECT_EQ(s.toString(), "OK"); EXPECT_EQ(tree.get<bool>("Disabled"), true); EXPECT_THROW(tree.get<bool>("foobar"), pt::ptree_bad_path); EXPECT_EQ(tree.get<std::string>("Label"), "com.apple.FileSyncAgent.sshd"); std::vector<std::string> program_arguments = { "/System/Library/CoreServices/FileSyncAgent.app/Contents/Resources/" "FileSyncAgent_sshd-keygen-wrapper", "-i", "-f", "/System/Library/CoreServices/FileSyncAgent.app/Contents/Resources/" "FileSyncAgent_sshd_config", }; pt::ptree program_arguments_tree = tree.get_child("ProgramArguments"); std::vector<std::string> program_arguments_parsed; for (const auto& argument : program_arguments_tree) { program_arguments_parsed.push_back(argument.second.get<std::string>("")); } EXPECT_EQ(program_arguments_parsed, program_arguments); } LOG(ERROR) << "Ending: " << getAsciiTime(); LOG(ERROR) << "Benchmark executed in " << (getUnixTime() - time) << " seconds"; }
//**************************************************************************************** // Challenge menu //***************************************************************************************** bool addChallenges() { char sPath[PATH_MAX]; const char *sSearchPath = "challenges"; UDWORD slotCount; static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; static char sSlotFile[totalslots][totalslotspace]; char **i, **files; (void) PHYSFS_mkdir(sSearchPath); // just in case psRequestScreen = widgCreateScreen(); // init the screen widgSetTipFont(psRequestScreen, font_regular); /* add a form to place the tabbed form on */ W_FORMINIT sFormInit; sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q sFormInit.id = CHALLENGE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD) CHALLENGE_X; sFormInit.y = (SWORD) CHALLENGE_Y; sFormInit.width = CHALLENGE_W; // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) sFormInit.height = (slotsInColumn * CHALLENGE_ENTRY_H + CHALLENGE_HGAP * slotsInColumn) + CHALLENGE_BANNER_DEPTH + 20; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = CHALLENGE_FORM; sFormInit.id = CHALLENGE_BANNER; sFormInit.x = CHALLENGE_HGAP; sFormInit.y = CHALLENGE_VGAP; sFormInit.width = CHALLENGE_W - (2 * CHALLENGE_HGAP); sFormInit.height = CHALLENGE_BANNER_DEPTH; sFormInit.disableChildren = false; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = 0; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label W_LABINIT sLabInit; sLabInit.formID = CHALLENGE_BANNER; sLabInit.id = CHALLENGE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 3; sLabInit.width = CHALLENGE_W - (2 * CHALLENGE_HGAP); //CHALLENGE_W; sLabInit.height = CHALLENGE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = "Challenge"; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. W_BUTINIT sButInit; sButInit.formID = CHALLENGE_BANNER; sButInit.x = 8; sButInit.y = 8; sButInit.width = iV_GetImageWidth(IntImages, IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages, IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0, IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = CHALLENGE_CANCEL; sButInit.pTip = _("Close"); sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots sButInit = W_BUTINIT(); sButInit.formID = CHALLENGE_FORM; sButInit.width = CHALLENGE_ENTRY_W; sButInit.height = CHALLENGE_ENTRY_H; sButInit.pDisplay = displayLoadSlot; for (slotCount = 0; slotCount < totalslots; slotCount++) { sButInit.id = slotCount + CHALLENGE_ENTRY_START; if (slotCount < slotsInColumn) { sButInit.x = 22 + CHALLENGE_HGAP; sButInit.y = (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + ( slotCount * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2 * CHALLENGE_HGAP + CHALLENGE_ENTRY_W); sButInit.y = (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + ( (slotCount % slotsInColumn) * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H))); } else { sButInit.x = 22 + (3 * CHALLENGE_HGAP + (2 * CHALLENGE_ENTRY_W)); sButInit.y = (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + ( (slotCount % slotsInColumn) * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sstrcpy(sPath, sSearchPath); sstrcat(sPath, "/*.ini"); debug(LOG_SAVE, "Searching \"%s\" for challenges", sPath); // add challenges to buttons files = PHYSFS_enumerateFiles(sSearchPath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char description[totalslotspace]; char highscore[totalslotspace]; const char *name, *difficulty, *map, *givendescription; inifile *inif; // See if this filename contains the extension we're looking for if (!strstr(*i, ".ini")) { // If it doesn't, move on to the next filename continue; } /* First grab any high score associated with this challenge */ inif = inifile_load(CHALLENGE_SCORES); sstrcpy(sPath, *i); sPath[strlen(sPath) - 4] = '\0'; // remove .ini sstrcpy(highscore, "no score"); if (inif) { char key[64]; bool victory; int seconds; ssprintf(key, "%s:Player", sPath); name = inifile_get(inif, key, "NO NAME"); ssprintf(key, "%s:Victory", sPath); victory = inifile_get_as_bool(inif, key, false); ssprintf(key, "%s:Seconds", sPath); seconds = inifile_get_as_int(inif, key, -1); if (seconds > 0) { getAsciiTime(key, seconds * GAME_TICKS_PER_SEC); ssprintf(highscore, "%s by %s (%s)", key, name, victory ? "Victory" : "Survived"); } inifile_delete(inif); } ssprintf(sPath, "%s/%s", sSearchPath, *i); inif = inifile_load(sPath); inifile_set_current_section(inif, "challenge"); if (!inif) { debug(LOG_ERROR, "Could not open \"%s\"", sPath); continue; } name = inifile_get(inif, "Name", "BAD NAME"); map = inifile_get(inif, "Map", "BAD MAP"); difficulty = inifile_get(inif, "difficulty", "BAD DIFFICULTY"); givendescription = inifile_get(inif, "description", ""); ssprintf(description, "%s, %s, %s. %s", map, difficulty, highscore, givendescription); button = (W_BUTTON*)widgGetFromID(psRequestScreen, CHALLENGE_ENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Set the button-text */ sstrcpy(sSlotCaps[slotCount], name); // store it! sstrcpy(sSlotTips[slotCount], description); // store it, too! sstrcpy(sSlotFile[slotCount], sPath); // store filename inifile_delete(inif); /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; button->pUserData = (void *)sSlotFile[slotCount]; slotCount++; // go to next button... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); challengesUp = true; return true; }
static void displayExtraGubbins(UDWORD height) { char str[128]; //draw grid iV_Line(MULTIMENU_FORM_X+MULTIMENU_C0 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C0 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C8 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C8 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C9 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C9 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C10 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C10 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C11 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C11 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X , MULTIMENU_FORM_Y+MULTIMENU_PLAYER_H, MULTIMENU_FORM_X+MULTIMENU_FORM_W, MULTIMENU_FORM_Y+MULTIMENU_PLAYER_H, WZCOL_BLACK); iV_SetFont(font_regular); // font iV_SetTextColour(WZCOL_TEXT_BRIGHT); // main wz text color // draw timer getAsciiTime(str, gameTime); iV_DrawText(str, MULTIMENU_FORM_X+MULTIMENU_C2, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET) ; // draw titles. iV_DrawText(_("Alliances"), MULTIMENU_FORM_X+MULTIMENU_C0, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); iV_DrawText(_("Score"), MULTIMENU_FORM_X+MULTIMENU_C8, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); iV_DrawText(_("Kills"), MULTIMENU_FORM_X+MULTIMENU_C9, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); if(getDebugMappingStatus()) { // shows # units for *all* players in debug mode ONLY! iV_DrawText(_("Units"), MULTIMENU_FORM_X+MULTIMENU_C10, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); iV_DrawText(_("Power"), MULTIMENU_FORM_X+MULTIMENU_C11, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); } else { // shows # units for *yourself* (+ team member?) only. iV_DrawText(_("Units"), MULTIMENU_FORM_X+MULTIMENU_C10, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); // ping is useless for non MP games, so display something useful depending on mode. if (runningMultiplayer()) { iV_DrawText(_("Ping"), MULTIMENU_FORM_X+MULTIMENU_C11, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); } else { iV_DrawText(_("Structs"), MULTIMENU_FORM_X+MULTIMENU_C11, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); } } #ifdef DEBUG { unsigned int width; sprintf(str,"Traf: %u/%u", NETgetBytesSent(), NETgetBytesRecvd()); width = iV_GetTextWidth(str); iV_DrawText(str, MULTIMENU_FORM_X, MULTIMENU_FORM_Y + MULTIMENU_FORM_H); sprintf(str,"Pack: %u/%u", NETgetPacketsSent(), NETgetPacketsRecvd()); iV_DrawText(str, MULTIMENU_FORM_X + 20 + width, MULTIMENU_FORM_Y + MULTIMENU_FORM_H); } #endif return; }
void scoreDataToScreen(WIDGET *psWidget, ScoreDataToScreenCache& cache) { int index, x, y, width, height; bool bMoreBars; if (!bDispStarted) { bDispStarted = true; dispST = realTime; audio_PlayTrack(ID_SOUND_BUTTON_CLICK_5); } fillUpStats(); pie_UniTransBoxFill(16 + D_W, MT_Y_POS - 16, pie_GetVideoBufferWidth() - D_W - 16, MT_Y_POS + 256 + 16, WZCOL_SCORE_BOX); iV_Box(16 + D_W, MT_Y_POS - 16, pie_GetVideoBufferWidth() - D_W - 16, MT_Y_POS + 256 + 16, WZCOL_SCORE_BOX_BORDER); cache.wzLabelText_UnitLosses.setText(_("Unit Losses"), font_regular); cache.wzLabelText_UnitLosses.render(LC_X + D_W, 80 + 16 + D_H, WZCOL_FORM_TEXT); cache.wzLabelText_StructureLosses.setText(_("Structure Losses"), font_regular); cache.wzLabelText_StructureLosses.render(LC_X + D_W, 140 + 16 + D_H, WZCOL_FORM_TEXT); cache.wzLabelText_ForceInformation.setText(_("Force Information"), font_regular); cache.wzLabelText_ForceInformation.render(LC_X + D_W, 200 + 16 + D_H, WZCOL_FORM_TEXT); index = 0; bMoreBars = true; while (bMoreBars) { /* Is it time to display this bar? */ if (infoBars[index].bActive) { /* Has it been queued before? */ if (infoBars[index].bQueued == false) { /* Don't do this next time...! */ infoBars[index].bQueued = true; /* Play a sound */ audio_PlayTrack(ID_SOUND_BUTTON_CLICK_5); } x = infoBars[index].topX + D_W; y = infoBars[index].topY + D_H; width = infoBars[index].width; height = infoBars[index].height; iV_Box(x, y, x + width, y + height, WZCOL_BLACK); /* Draw the background border box */ pie_BoxFill(x - 1, y - 1, x + width + 1, y + height + 1, WZCOL_MENU_BACKGROUND); /* Draw the interior grey */ pie_BoxFill(x, y, x + width, y + height, WZCOL_MENU_SCORES_INTERIOR); if (((realTime - dispST) > infoBars[index].queTime)) { /* Now draw amount filled */ const float mul = (realTime - dispST < BAR_CRAWL_TIME) ? (float)(realTime - dispST) / (float)BAR_CRAWL_TIME : 1.f; const float length = (float)infoBars[index].percent / 100.f * (float)infoBars[index].width * mul; if ((int)length > 4) { /* Black shadow */ pie_BoxFill(x + 1, y + 3, x + length - 1, y + height - 1, WZCOL_MENU_SHADOW); /* Solid coloured bit */ pie_BoxFill(x + 1, y + 2, x + length - 4, y + height - 4, getColour(index)); } } /* Now render the text by the bar */ sprintf(text, getDescription((MR_STRING)infoBars[index].stringID), infoBars[index].number); if (index >= cache.wzInfoBarText.size()) { cache.wzInfoBarText.resize(index + 1); } cache.wzInfoBarText[index].setText(text, font_regular); cache.wzInfoBarText[index].render(x + width + 16, y + 12, WZCOL_FORM_TEXT); /* If we're beyond STAT_ROOKIE, then we're on rankings */ if (index >= STAT_GREEN && index <= STAT_ACE) { iV_DrawImage(IntImages, (UWORD)(IMAGE_LEV_0 + (index - STAT_GREEN)), x - 8, y + 2); } } /* Move onto the next bar */ index++; if ((index > STAT_ACE) || (infoBars[index].topX == 0 && infoBars[index].topY == 0)) { bMoreBars = false; } } /* We now need to display the mission time, game time, average unit experience level an number of artefacts found */ /* Firstly, top of the screen, number of artefacts found */ sprintf(text, _("ARTIFACTS RECOVERED: %d"), missionData.artefactsFound); cache.wzInfoText_ArtifactsFound.setText(text, font_regular); cache.wzInfoText_ArtifactsFound.render((pie_GetVideoBufferWidth() - cache.wzInfoText_ArtifactsFound.width()) / 2, 300 + D_H, WZCOL_FORM_TEXT); /* Get the mission result time in a string - and write it out */ getAsciiTime((char *)&text2, gameTime - missionData.missionStarted); sprintf(text, _("Mission Time - %s"), text2); cache.wzInfoText_MissionTime.setText(text, font_regular); cache.wzInfoText_MissionTime.render((pie_GetVideoBufferWidth() - cache.wzInfoText_MissionTime.width()) / 2, 320 + D_H, WZCOL_FORM_TEXT); /* Write out total game time so far */ getAsciiTime((char *)&text2, gameTime); sprintf(text, _("Total Game Time - %s"), text2); cache.wzInfoText_TotalGameTime.setText(text, font_regular); cache.wzInfoText_TotalGameTime.render((pie_GetVideoBufferWidth() - cache.wzInfoText_TotalGameTime.width()) / 2, 340 + D_H, WZCOL_FORM_TEXT); if (Cheated) { // A quick way to flash the text PIELIGHT cheatedTextColor = ((realTime / 250) % 2) ? WZCOL_RED : WZCOL_YELLOW; sprintf(text, "%s", _("You cheated!")); cache.wzInfoText_Cheated.setText(text, font_regular); cache.wzInfoText_Cheated.render((pie_GetVideoBufferWidth() - cache.wzInfoText_Cheated.width()) / 2, 360 + D_H, cheatedTextColor); } }
static void displayExtraGubbins(UDWORD height) { char str[128]; //draw grid iV_Line(MULTIMENU_FORM_X+MULTIMENU_C0 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C0 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C8 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C8 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C9 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C9 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C10 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C10 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X+MULTIMENU_C11 -6 , MULTIMENU_FORM_Y, MULTIMENU_FORM_X+MULTIMENU_C11 -6 , MULTIMENU_FORM_Y+height, WZCOL_BLACK); iV_Line(MULTIMENU_FORM_X , MULTIMENU_FORM_Y+MULTIMENU_PLAYER_H, MULTIMENU_FORM_X+MULTIMENU_FORM_W, MULTIMENU_FORM_Y+MULTIMENU_PLAYER_H, WZCOL_BLACK); iV_SetFont(font_regular); // font iV_SetTextColour(WZCOL_TEXT_BRIGHT); // main wz text color // draw timer getAsciiTime(str, gameTime); iV_DrawText(str, MULTIMENU_FORM_X+MULTIMENU_C2, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET) ; // draw titles. iV_DrawText(_("Alliances"), MULTIMENU_FORM_X+MULTIMENU_C0, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); iV_DrawText(_("Score"), MULTIMENU_FORM_X+MULTIMENU_C8, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); iV_DrawText(_("Kills"), MULTIMENU_FORM_X+MULTIMENU_C9, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); iV_DrawText(_("Units"), MULTIMENU_FORM_X+MULTIMENU_C10, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); if (getDebugMappingStatus()) { iV_DrawText(_("Power"), MULTIMENU_FORM_X+MULTIMENU_C11, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); } else { // ping is useless for non MP games, so display something useful depending on mode. if (runningMultiplayer()) { iV_DrawText(_("Ping"), MULTIMENU_FORM_X+MULTIMENU_C11, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); } else { iV_DrawText(_("Structs"), MULTIMENU_FORM_X+MULTIMENU_C11, MULTIMENU_FORM_Y+MULTIMENU_FONT_OSET); } } #ifdef DEBUG iV_SetFont(font_small); for (unsigned q = 0; q < 2; ++q) { unsigned xPos = 0; unsigned yPos = q*12; bool isTotal = q != 0; char const *srText[2] = {_("Sent/Received per sec —"), _("Total Sent/Received —")}; sprintf(str, srText[q]); iV_DrawText(str, MULTIMENU_FORM_X + xPos, MULTIMENU_FORM_Y + height + yPos); xPos += iV_GetTextWidth(str) + 20; sprintf(str, _("Traf: %u/%u"), NETgetStatistic(NetStatisticRawBytes, true, isTotal), NETgetStatistic(NetStatisticRawBytes, false, isTotal)); iV_DrawText(str, MULTIMENU_FORM_X + xPos, MULTIMENU_FORM_Y + height + yPos); xPos += iV_GetTextWidth(str) + 20; sprintf(str, _("Uncompressed: %u/%u"), NETgetStatistic(NetStatisticUncompressedBytes, true, isTotal), NETgetStatistic(NetStatisticUncompressedBytes, false, isTotal)); iV_DrawText(str, MULTIMENU_FORM_X + xPos, MULTIMENU_FORM_Y + height + yPos); xPos += iV_GetTextWidth(str) + 20; sprintf(str, _("Pack: %u/%u"), NETgetStatistic(NetStatisticPackets, true, isTotal), NETgetStatistic(NetStatisticPackets, false, isTotal)); iV_DrawText(str, MULTIMENU_FORM_X + xPos, MULTIMENU_FORM_Y + height + yPos); } #endif return; }
QueryData genTime(QueryContext& context) { Row r; // Request UNIX time (a wrapper around std::time). auto local_time = std::time(nullptr); auto osquery_time = getUnixTime(); auto osquery_timestamp = getAsciiTime(); // The concept of 'now' is configurable. struct tm gmt; gmtime_r(&local_time, &gmt); struct tm now; if (FLAGS_utc) { now = gmt; } else { localtime_r(&local_time, &now); } struct tm local; localtime_r(&local_time, &local); char weekday[10] = {0}; strftime(weekday, sizeof(weekday), "%A", &now); char timezone[5] = {0}; strftime(timezone, sizeof(timezone), "%Z", &now); char local_timezone[5] = {0}; strftime(local_timezone, sizeof(local_timezone), "%Z", &local); char iso_8601[21] = {0}; strftime(iso_8601, sizeof(iso_8601), "%FT%TZ", &gmt); r["weekday"] = SQL_TEXT(weekday); r["year"] = INTEGER(now.tm_year + 1900); r["month"] = INTEGER(now.tm_mon + 1); r["day"] = INTEGER(now.tm_mday); r["hour"] = INTEGER(now.tm_hour); r["minutes"] = INTEGER(now.tm_min); r["seconds"] = INTEGER(now.tm_sec); r["timezone"] = SQL_TEXT(timezone); if (r["timezone"].empty()) { r["timezone"] = "UTC"; } r["local_time"] = INTEGER(local_time); r["local_timezone"] = SQL_TEXT(local_timezone); if (r["local_timezone"].empty()) { r["local_timezone"] = "UTC"; } r["unix_time"] = INTEGER(osquery_time); r["timestamp"] = SQL_TEXT(osquery_timestamp); // Date time is provided in ISO 8601 format, then duplicated in iso_8601. r["datetime"] = SQL_TEXT(iso_8601); r["iso_8601"] = SQL_TEXT(iso_8601); QueryData results; results.push_back(r); return results; }