AString cMojangAPI::MakeUUIDShort(const AString & a_UUID) { // Note: we only check the string's length, not the actual content switch (a_UUID.size()) { case 32: { // Already is a short UUID, only lowercase return StrToLower(a_UUID); } case 36: { // Remove the dashes from the string by appending together the parts between them: AString res; res.reserve(32); res.append(a_UUID, 0, 8); res.append(a_UUID, 9, 4); res.append(a_UUID, 14, 4); res.append(a_UUID, 19, 4); res.append(a_UUID, 24, 12); return StrToLower(res); } } LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str()); return ""; }
AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID) { // Note: we only check the string's length, not the actual content switch (a_UUID.size()) { case 36: { // Already is a dashed UUID, only lowercase return StrToLower(a_UUID); } case 32: { // Insert dashes at the proper positions: AString res; res.reserve(36); res.append(a_UUID, 0, 8); res.push_back('-'); res.append(a_UUID, 8, 4); res.push_back('-'); res.append(a_UUID, 12, 4); res.push_back('-'); res.append(a_UUID, 16, 4); res.push_back('-'); res.append(a_UUID, 20, 12); return StrToLower(res); } } LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str()); return ""; }
eMonsterType cMonster::StringToMobType(const AString & a_Name) { AString lcName = StrToLower(a_Name); // Search MCServer name: for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) { if (strcmp(g_MobTypeNames[i].m_lcName, lcName.c_str()) == 0) { return g_MobTypeNames[i].m_Type; } } // Not found. Search Vanilla name: for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) { if (strcmp(StrToLower(g_MobTypeNames[i].m_VanillaName).c_str(), lcName.c_str()) == 0) { return g_MobTypeNames[i].m_Type; } } // Not found: return mtInvalidType; }
AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames, bool a_UseOnlyCached) { // Convert all playernames to lowercase: AStringVector PlayerNames; for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr) { PlayerNames.push_back(StrToLower(*itr)); } // for itr - a_PlayerNames[] // Request the cache to populate any names not yet contained: if (!a_UseOnlyCached) { CacheNamesToUUIDs(PlayerNames); } // Retrieve from cache: size_t idx = 0; AStringVector res; res.resize(PlayerNames.size()); cCSLock Lock(m_CSNameToUUID); for (AStringVector::const_iterator itr = PlayerNames.begin(), end = PlayerNames.end(); itr != end; ++itr, ++idx) { cProfileMap::const_iterator itrN = m_NameToUUID.find(*itr); if (itrN != m_NameToUUID.end()) { res[idx] = itrN->second.m_UUID; } } // for itr - PlayerNames[] return res; }
/*==================================================================== * 函数名 : GetConfig * 功能 : 获得得配置文件中对于日志相关参数 * 算法实现 : 使用jasson解析,关键为Log对象的值,保存到日志结构体中 * 参数说明 : vspLogCfg 指向一个日志结构体 * 返回值说明: 成功 0 * 失败 -1 * ---------------------------------------------------------------------- * 修改记录: * 日 期 版本 修改人 走读人 修改记录 * 2014/12/20 v1.0 YLI YLI * ====================================================================*/ static int GetConfig(LogCfg *vspLogCfg) { FILE *fp = NULL; json_t *obj; json_t *logArr; const char *key; json_t *value; char keytmp[100]; size_t index = 0; if(getenv("A_PROFILE_NAME") == NULL) { printf("error:evn set error!!!\n"); return LOGFAIL; } if(strlen(getenv("A_PROFILE_NAME")) >= 256) { printf("error:config file name too long!!!\n"); return LOGFAIL; } memset(szCfgFile,0x00,sizeof szCfgFile); strcpy(szCfgFile,getenv("A_PROFILE_NAME")); if((fp = fopen(szCfgFile,"r")) == NULL) { printf("error:config file open error!!!\n"); return LOGFAIL; } obj = GetJsonObj(fp,J_LOG_KEY); if(obj == NULL) { printf("error:config file configuration error!!!\n"); printf("warning:please check \"log\" whether the lower\n"); return LOGFAIL; } //获得日志参数 logArr = json_object_get(obj,"log"); for(index = 0;index < json_array_size(logArr);index++) { json_object_foreach(json_array_get(logArr,index),key,value) { strcpy(keytmp,key); Trim(keytmp); StrToLower(keytmp); if(strncmp(keytmp,"logdir",6) == 0) { strcpy(vspLogCfg->logDir,json_string_value(value)); } else if(strcmp(keytmp,"logsize") == 0) { vspLogCfg->logFileMaxSize = (int)json_integer_value(value); } else if(0 == strcmp(keytmp,"achivesize")) { vspLogCfg->logAchiveSize = (int)json_integer_value(value); } } }
/** Read the SSL information from the config.xml \param[in] sslNode SSL node to read. \param[out] sslEnabled is SSL enabled \param[out] httpsPort HTTPS Port discovered */ void WebLogicFileReader::ReadConfigXmlForSslInformation( const XElementPtr& sslNode, bool& sslEnabled, string& httpsPort) { sslEnabled =false; httpsPort = ""; XElementList sslChildrenNodes; sslNode->GetChildren(sslChildrenNodes); for (size_t index = 0; index < sslChildrenNodes.size(); ++index) { if (sslChildrenNodes[index]->GetName() == WEBLOGIC_SSL_ENABLED_XML_NODE) { string narrow = sslChildrenNodes[index]->GetContent(); wstring wide = StrFromUTF8(narrow); wide = StrToLower(wide); sslEnabled = TRUE_TEXT == wide; } else if (sslChildrenNodes[index]->GetName() == WEBLOGIC_LISTEN_PORT_XML_NODE) { httpsPort = sslChildrenNodes[index]->GetContent(); } } }
void cHTTPMessage::AddHeader(const AString & a_Key, const AString & a_Value) { AString Key = StrToLower(a_Key); cNameValueMap::iterator itr = m_Headers.find(Key); if (itr == m_Headers.end()) { m_Headers[Key] = a_Value; } else { // The header-field key is specified multiple times, combine into comma-separated list (RFC 2616 @ 4.2) itr->second.append(", "); itr->second.append(a_Value); } // Special processing for well-known headers: if (Key == "content-type") { m_ContentType = m_Headers[Key]; } else if (Key == "content-length") { if (!StringToInteger(m_Headers[Key], m_ContentLength)) { m_ContentLength = 0; } } }
static void SelectAll(HWND hDlg, bool bEnable) { OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); for (int i=0; i < todo.getCount(); i++) { ListView_SetCheckState(hwndList, i, bEnable); db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(todo[i].tszOldName)), todo[i].bEnabled = bEnable); } }
void cMojangAPI::LoadCachesFromDisk(void) { try { // Open up the SQLite DB: SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); // Clean up old entries: { SQLite::Statement stmt(db, "DELETE FROM PlayerNameToUUID WHERE DateTime < ?"); Int64 LimitDateTime = time(NULL) - MAX_AGE; stmt.bind(1, LimitDateTime); stmt.exec(); } { SQLite::Statement stmt(db, "DELETE FROM UUIDToProfile WHERE DateTime < ?"); Int64 LimitDateTime = time(NULL) - MAX_AGE; stmt.bind(1, LimitDateTime); stmt.exec(); } // Retrieve all remaining entries: { SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID"); while (stmt.executeStep()) { AString PlayerName = stmt.getColumn(0); AString UUID = stmt.getColumn(1); Int64 DateTime = stmt.getColumn(2); UUID = MakeUUIDShort(UUID); m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime); m_UUIDToName[UUID] = sProfile(PlayerName, UUID, "", "", DateTime); } } { SQLite::Statement stmt(db, "SELECT PlayerName, UUID, Textures, TexturesSignature, DateTime FROM UUIDToProfile"); while (stmt.executeStep()) { AString PlayerName = stmt.getColumn(0); AString UUID = stmt.getColumn(1); AString Textures = stmt.getColumn(2); AString TexturesSignature = stmt.getColumn(2); Int64 DateTime = stmt.getColumn(4); UUID = MakeUUIDShort(UUID); m_UUIDToProfile[UUID] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime); } } } catch (const SQLite::Exception & ex) { LOGINFO("Loading MojangAPI cache failed: %s", ex.what()); } }
void cMojangAPI::LoadCachesFromDisk(void) { try { // Open up the SQLite DB: SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); // Retrieve all entries: { SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID"); while (stmt.executeStep()) { AString PlayerName = stmt.getColumn(0); AString StringUUID = stmt.getColumn(1); Int64 DateTime = stmt.getColumn(2); cUUID UUID; if (!UUID.FromString(StringUUID)) { continue; // Invalid UUID } m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime); m_UUIDToName[UUID] = sProfile(PlayerName, UUID, "", "", DateTime); } } { SQLite::Statement stmt(db, "SELECT PlayerName, UUID, Textures, TexturesSignature, DateTime FROM UUIDToProfile"); while (stmt.executeStep()) { AString PlayerName = stmt.getColumn(0); AString StringUUID = stmt.getColumn(1); AString Textures = stmt.getColumn(2); AString TexturesSignature = stmt.getColumn(2); Int64 DateTime = stmt.getColumn(4); cUUID UUID; if (!UUID.FromString(StringUUID)) { continue; // Invalid UUID } m_UUIDToProfile[UUID] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime); } } } catch (const SQLite::Exception & ex) { LOGINFO("Loading MojangAPI cache failed: %s", ex.what()); } }
bool TryLoadArcFile(const char *arcName, int drive) { C_File fl; char res[MAX_PATH]; char tmp[MAX_PATH], str[MAX_FNAME]; char files[MAX_FILES][MAX_FNAME]; int filesCount; string plugin_fn; strcpy(tmp, C_DirWork::ExtractExt(arcName)); if (!strlen(tmp)) { return false; } StrToLower(tmp); plugin_fn = config.FindDataFile("arc", tmp); if (plugin_fn.empty()) { return false; } sprintf(tmp, "%s list \"%s\" %s/files.txt", plugin_fn.c_str(), arcName, tempFolderName); if (system(tmp) == -1) DEBUG_MESSAGE("system failed"); sprintf(tmp, "%s/files.txt", tempFolderName); if (!C_File::FileExists(tmp)) return true; // "true" here means ONLY that the file is an archive fl.Read(tmp); for (filesCount = 0; !fl.Eof(); ) { fl.GetS(str, sizeof(str)); if (strcmp(str, "")) strcpy(files[filesCount++], str); } unlink(tmp); if (!filesCount) return true; // "true" here means ONLY that the file is an archive // currently load only first file sprintf(tmp, "%s extract \"%s\" \"%s\" %s", plugin_fn.c_str(), arcName, files[0], tempFolderName); if (system(tmp) == -1) DEBUG_MESSAGE("system failed"); strcpy(tmp, C_DirWork::ExtractFileName(files[0])); // TODO: check if lresult strlen > sizeof(res) sprintf(res, "%s/%s", tempFolderName, tmp); LoadNormalFile(res, drive, arcName); unlink(res); return true; // "true" here means ONLY that the file is an archive }
void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const cUUID & a_UUID) { Int64 Now = time(nullptr); { cCSLock Lock(m_CSNameToUUID); m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, a_UUID, "", "", Now); } { cCSLock Lock(m_CSUUIDToName); m_UUIDToName[a_UUID] = sProfile(a_PlayerName, a_UUID, "", "", Now); } NotifyNameUUID(a_PlayerName, a_UUID); }
void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID) { AString UUID = MakeUUIDShort(a_UUID); Int64 Now = time(NULL); { cCSLock Lock(m_CSNameToUUID); m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, UUID, "", "", Now); } { cCSLock Lock(m_CSUUIDToName); m_UUIDToName[UUID] = sProfile(a_PlayerName, UUID, "", "", Now); } }
void SetPrimaryProtocol(char *Protocol) { char ProtocolStr[8] = {0}; strncpy(ProtocolStr, Protocol, 3); StrToLower(ProtocolStr); if( strcmp(ProtocolStr, "tcp") == 0 ) { PrimaryProtocol = DNS_QUARY_PROTOCOL_TCP; NullSecondary = (ConfigGetStringList(&ConfigInfo, "UDPServer") == NULL); } else { PrimaryProtocol = DNS_QUARY_PROTOCOL_UDP; NullSecondary = (ConfigGetStringList(&ConfigInfo, "TCPServer") == NULL); } }
/* This function is out of date DAS */ const char * EnumName( const char * oldname ) { int j = 0; static char newname [MAX_LEN]; if( !oldname ) { return ( "" ); } strcpy( newname, ENUM_PREFIX ); j = strlen( ENUM_PREFIX ); newname [j] = ToUpper( oldname [0] ); strncpy( newname + j + 1, StrToLower( oldname + 1 ), MAX_LEN - j - 1 ); j = strlen( newname ); newname [j] = '\0'; return ( newname ); }
const char * SelectName( const char * oldname ) { int j = 0; static char newname [MAX_LEN]; if( !oldname ) { return ( "" ); } strcpy( newname, TYPE_PREFIX ); newname [0] = ToUpper( newname [0] ); j = strlen( TYPE_PREFIX ); newname [j] = ToUpper( oldname [0] ); strncpy( newname + j + 1, StrToLower( oldname + 1 ), MAX_LEN - j ); j = strlen( newname ); newname [j] = '\0'; return ( newname ); }
void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const cUUID & a_UUID, const Json::Value & a_Properties) { Int64 Now = time(nullptr); { cCSLock Lock(m_CSNameToUUID); m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, a_UUID, "", "", Now); } { cCSLock Lock(m_CSUUIDToName); m_UUIDToName[a_UUID] = sProfile(a_PlayerName, a_UUID, "", "", Now); } { cCSLock Lock(m_CSUUIDToProfile); m_UUIDToProfile[a_UUID] = sProfile(a_PlayerName, a_UUID, a_Properties, Now); } NotifyNameUUID(a_PlayerName, a_UUID); }
void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties) { AString UUID = MakeUUIDShort(a_UUID); Int64 Now = time(NULL); { cCSLock Lock(m_CSNameToUUID); m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, UUID, "", "", Now); } { cCSLock Lock(m_CSUUIDToName); m_UUIDToName[UUID] = sProfile(a_PlayerName, UUID, "", "", Now); } { cCSLock Lock(m_CSUUIDToProfile); m_UUIDToProfile[UUID] = sProfile(a_PlayerName, UUID, a_Properties, Now); } }
/** Test that FromString -> ToLongString preserves the original value for long UUIDs. */ static void UUIDFromStringToLongString() { const char TestStrings[][37]{ "01234567-89ab-cdef-0123-456789ABCDEF", "d188b264-8cc3-11e7-bb31-be2e44b06b34", "e760d270-d8b3-4288-b895-d9f78a31e083", "7052f2f2-5942-46ab-b8e3-fed602158870", "7f14d4b6-0cd8-4ba7-885c-8301b67ce891", "57be7039-2505-48b5-90af-272291fabcfa" }; for (auto TestString : TestStrings) { cUUID UUID; assert_test(UUID.FromString(TestString)); auto ResultString = UUID.ToLongString(); // Result should be equivalent to original assert_test(NoCaseCompare(ResultString, TestString) == 0); // And should be all lower case assert_test(ResultString == StrToLower(ResultString)); } }
static BOOL GetBoolealValueFromString(char *str) { if( isdigit(*str) ) { if( *str == '0' ) return FALSE; else return TRUE; } else { StrToLower(str); if( strstr(str, "false") != NULL ) return FALSE; else if( strstr(str, "true") != NULL ) return TRUE; if( strstr(str, "no") != NULL ) return FALSE; else if( strstr(str, "yes") != NULL ) return TRUE; } }
cUUID cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached) { // Convert the playername to lowercase: AString lcPlayerName = StrToLower(a_PlayerName); // Request the cache to query the name if not yet cached: if (!a_UseOnlyCached) { AStringVector PlayerNames{ lcPlayerName }; CacheNamesToUUIDs(PlayerNames); } // Retrieve from cache: cCSLock Lock(m_CSNameToUUID); cProfileMap::const_iterator itr = m_NameToUUID.find(lcPlayerName); if (itr == m_NameToUUID.end()) { // No UUID found return {}; } return itr->second.m_UUID; }
string Response::ExtractContentType(const string& file, eMode mode) { if (mode == ERROR_FILE_NOT_EXIST || mode == INTERNAL_ERROR) return "text/html; charset=utf-8"; if (mode == DIR_LIST) return DIR_LIST_CHARSET; size_t dot = file.rfind("."); if (dot == string::npos) { // File has no extension. Just send it as binary. return "application/octet-stream"; } string extension(file, dot+1, file.size() - dot - 1); StrToLower(extension); for (unsigned i=0; i<ARRAY_LENGTH(gContentTypes); i++) { if (extension == gContentTypes[i][0]) { return string(gContentTypes[i][1]); } } return "application/octet-stream"; }
/** Test that FromString -> ToShortString preserves the original value for short UUIDs. */ static void UUIDFromStringToShortString() { const char TestStrings[][33]{ "0123456789abcdef0123456789ABCDEF", "d188b2648cc311e7bb31be2e44b06b34", "e760d270d8b34288b895d9f78a31e083", "7052f2f2594246abb8e3fed602158870", "7f14d4b60cd84ba7885c8301b67ce891", "57be7039250548b590af272291fabcfa" }; for (auto TestString : TestStrings) { cUUID UUID; assert_test(UUID.FromString(TestString)); auto ResultString = UUID.ToShortString(); // Result should be equivalent to original assert_test(NoCaseCompare(ResultString, TestString) == 0); // And should be all lower case assert_test(ResultString == StrToLower(ResultString)); } }
cMonster::eType cMonster::StringToMobType(const AString & a_Name) { AString lcName(a_Name); StrToLower(lcName); // Binary-search for the lowercase name: int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1; while (hi - lo > 1) { int mid = (lo + hi) / 2; int res = strcmp(g_MobTypeNames[mid].m_lcName, lcName.c_str()); if (res == 0) { return g_MobTypeNames[mid].m_Type; } if (res < 0) { lo = mid; } else { hi = mid; } } // Range has collapsed to at most two elements, compare each: if (strcmp(g_MobTypeNames[lo].m_lcName, lcName.c_str()) == 0) { return g_MobTypeNames[lo].m_Type; } if ((lo != hi) && (strcmp(g_MobTypeNames[hi].m_lcName, lcName.c_str()) == 0)) { return g_MobTypeNames[hi].m_Type; } // Not found: return mtInvalidType; }
void test_util() { char tmp[100]; strcpy(tmp,"strIng"); printf("test string Lower to Upper\n"); printf("before:%s\n",tmp); StrToUpper(tmp); printf("after:%s\n",tmp); memset(tmp,0x00,sizeof tmp); strcpy(tmp,"STRiNG"); printf("test string Lower to Upper\n"); printf("before:%s\n",tmp); StrToLower(tmp); printf("after:%s\n",tmp); memset(tmp,0x00,sizeof tmp); strcpy(tmp,"STRiNG "); printf("test string remove right space\n"); printf("before:%s\n",tmp); RTrim(tmp); printf("after:%s\n",tmp); memset(tmp,0x00,sizeof tmp); strcpy(tmp," STRiNG"); printf("test string remove left space\n"); printf("before:%s\n",tmp); LTrim(tmp); printf("after:%s\n",tmp); memset(tmp,0x00,sizeof tmp); strcpy(tmp," STRiNG "); printf("test string remove left and right space\n"); printf("before:%s\n",tmp); Trim(tmp); printf("after:%s\n",tmp); }
void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID) { ASSERT(a_UUID.size() == 32); // Check if already present: { if (m_UUIDToProfile.find(a_UUID) != m_UUIDToProfile.end()) { return; } } // Create the request address: AString Address = m_UUIDToProfileAddress; ReplaceString(Address, "%UUID%", a_UUID); // Create the HTTP request: AString Request; Request += "GET " + Address + " HTTP/1.0\r\n"; // We need to use HTTP 1.0 because we don't handle Chunked transfer encoding Request += "Host: " + m_UUIDToProfileServer + "\r\n"; Request += "User-Agent: MCServer\r\n"; Request += "Connection: close\r\n"; Request += "Content-Length: 0\r\n"; Request += "\r\n"; // Get the response from the server: AString Response; if (!SecureRequest(m_UUIDToProfileServer, Request, Response)) { return; } // Check the HTTP status line: const AString Prefix("HTTP/1.1 200 OK"); AString HexDump; if (Response.compare(0, Prefix.size(), Prefix)) { LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__); LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); return; } // Erase the HTTP headers from the response: size_t idxHeadersEnd = Response.find("\r\n\r\n"); if (idxHeadersEnd == AString::npos) { LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__); LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); return; } Response.erase(0, idxHeadersEnd + 4); // Parse the returned string into Json: Json::Reader reader; Json::Value root; if (!reader.parse(Response, root, false) || !root.isObject()) { LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON!", __FUNCTION__); LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); return; } /* Example response: { "id": "b1caf24202a841a78055a079c460eee7", "name": "xoft", "properties": [ { "name": "textures", "value": "eyJ0aW1lc3RhbXAiOjE0MDcwNzAzMjEyNzEsInByb2ZpbGVJZCI6ImIxY2FmMjQyMDJhODQxYTc4MDU1YTA3OWM0NjBlZWU3IiwicHJvZmlsZU5hbWUiOiJ4b2Z0IiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iNzc5YmFiZjVhNTg3Zjk0OGFkNjc0N2VhOTEyNzU0MjliNjg4Mjk1YWUzYzA3YmQwZTJmNWJmNGQwNTIifX19", "signature": "XCty+jGEF39hEPrPhYNnCX087kPaoCjYruzYI/DS4nkL5hbjnkSM5Rh15hnUyv/FHhC8OF5rif3D1tQjtMI19KSVaXoUFXpbJM8/+PB8GDgEbX8Fc3u9nYkzOcM/xfxdYsFAdFhLQMkvase/BZLSuPhdy9DdI+TCrO7xuSTZfYmmwVuWo3w5gCY+mSIAnqltnOzaOOTcly75xvO0WYpVk7nJdnR2tvSi0wfrQPDrIg/uzhX7p0SnDqijmBU4QaNez/TNKiFxy69dAzt0RSotlQzqkDbyVKhhv9a4eY8h3pXi4UMftKEj4FAKczxLImkukJXuOn5NN15/Q+le0rJVBC60/xjKIVzltEsMN6qjWD0lQjey7WEL+4pGhCVuWY5KzuZjFvgqszuJTFz7lo+bcHiceldJtea8/fa02eTRObZvdLxbWC9ZfFY0IhpOVKfcLdno/ddDMNMQMi5kMrJ8MZZ/PcW1w5n7MMGWPGCla1kOaC55AL0QYSMGRVEZqgU9wXI5M7sHGZKGM4mWxkbEJYBkpI/p3GyxWgV6v33ZWlsz65TqlNrR1gCLaoFCm7Sif8NqPBZUAONHYon0roXhin/DyEanS93WV6i6FC1Wisscjq2AcvnOlgTo/5nN/1QsMbjNumuMGo37sqjRqlXoPb8zEUbAhhztYuJjEfQ2Rd8=" } ] } */ // Store the returned result into caches: AString PlayerName = root.get("name", "").asString(); if (PlayerName.empty()) { // No valid playername, bail out return; } Json::Value Properties = root.get("properties", ""); Int64 Now = time(NULL); { cCSLock Lock(m_CSUUIDToProfile); m_UUIDToProfile[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now); } { cCSLock Lock(m_CSUUIDToName); m_UUIDToName[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now); } { cCSLock Lock(m_CSNameToUUID); m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now); } }
void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames) { // Create a list of names to query, by removing those that are already cached: AStringVector NamesToQuery; NamesToQuery.reserve(a_PlayerNames.size()); { cCSLock Lock(m_CSNameToUUID); for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr) { if (m_NameToUUID.find(*itr) == m_NameToUUID.end()) { NamesToQuery.push_back(*itr); } } // for itr - a_PlayerNames[] } // Lock(m_CSNameToUUID) while (!NamesToQuery.empty()) { // Create the request body - a JSON containing up to MAX_PER_QUERY playernames: Json::Value root; int Count = 0; AStringVector::iterator itr = NamesToQuery.begin(), end = NamesToQuery.end(); for (; (itr != end) && (Count < MAX_PER_QUERY); ++itr, ++Count) { Json::Value req(*itr); root.append(req); } // for itr - a_PlayerNames[] NamesToQuery.erase(NamesToQuery.begin(), itr); Json::FastWriter Writer; AString RequestBody = Writer.write(root); // Create the HTTP request: AString Request; Request += "POST " + m_NameToUUIDAddress + " HTTP/1.0\r\n"; // We need to use HTTP 1.0 because we don't handle Chunked transfer encoding Request += "Host: " + m_NameToUUIDServer + "\r\n"; Request += "User-Agent: MCServer\r\n"; Request += "Connection: close\r\n"; Request += "Content-Type: application/json\r\n"; Request += Printf("Content-Length: %u\r\n", (unsigned)RequestBody.length()); Request += "\r\n"; Request += RequestBody; // Get the response from the server: AString Response; if (!SecureRequest(m_NameToUUIDServer, Request, Response)) { continue; } // Check the HTTP status line: const AString Prefix("HTTP/1.1 200 OK"); AString HexDump; if (Response.compare(0, Prefix.size(), Prefix)) { LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__); LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); continue; } // Erase the HTTP headers from the response: size_t idxHeadersEnd = Response.find("\r\n\r\n"); if (idxHeadersEnd == AString::npos) { LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__); LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); continue; } Response.erase(0, idxHeadersEnd + 4); // Parse the returned string into Json: Json::Reader reader; if (!reader.parse(Response, root, false) || !root.isArray()) { LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON!", __FUNCTION__); LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); continue; } // Store the returned results into cache: size_t JsonCount = root.size(); Int64 Now = time(NULL); { cCSLock Lock(m_CSNameToUUID); for (size_t idx = 0; idx < JsonCount; ++idx) { Json::Value & Val = root[idx]; AString JsonName = Val.get("name", "").asString(); AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString()); if (JsonUUID.empty()) { continue; } m_NameToUUID[StrToLower(JsonName)] = sProfile(JsonName, JsonUUID, "", "", Now); } // for idx - root[] } // cCSLock (m_CSNameToUUID) // Also cache the UUIDToName: { cCSLock Lock(m_CSUUIDToName); for (size_t idx = 0; idx < JsonCount; ++idx) { Json::Value & Val = root[idx]; AString JsonName = Val.get("name", "").asString(); AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString()); if (JsonUUID.empty()) { continue; } m_UUIDToName[JsonUUID] = sProfile(JsonName, JsonUUID, "", "", Now); } // for idx - root[] } } // while (!NamesToQuery.empty()) }
static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); switch (message) { case WM_INITDIALOG: TranslateDialogDefault(hDlg); SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon("check_update")); SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon("check_update", 1)); { OSVERSIONINFO osver = { sizeof(osver) }; if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6) { wchar_t szPath[MAX_PATH]; GetModuleFileName(NULL, szPath, SIZEOF(szPath)); TCHAR *ext = _tcsrchr(szPath, '.'); if (ext != NULL) *ext = '\0'; _tcscat(szPath, _T(".test")); HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) // Running Windows Vista or later (major version >= 6). Button_SetElevationRequiredState(GetDlgItem(hDlg, IDOK), !IsProcessElevated()); else { CloseHandle(hFile); DeleteFile(szPath); } } LVCOLUMN lvc = {0}; // Initialize the LVCOLUMN structure. // The mask specifies that the format, width, text, and // subitem members of the structure are valid. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; lvc.fmt = LVCFMT_LEFT; lvc.iSubItem = 0; lvc.pszText = TranslateT("Component Name"); lvc.cx = 220; // width of column in pixels ListView_InsertColumn(hwndList, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TranslateT("State"); lvc.cx = 120 - GetSystemMetrics(SM_CXVSCROLL); // width of column in pixels ListView_InsertColumn(hwndList, 1, &lvc); //enumerate plugins, fill in list ListView_DeleteAllItems(hwndList); /// LVGROUP lvg; lvg.cbSize = sizeof(LVGROUP); lvg.mask = LVGF_HEADER | LVGF_GROUPID; lvg.pszHeader = TranslateT("Plugins"); lvg.iGroupId = 1; ListView_InsertGroup(hwndList, 0, &lvg); lvg.pszHeader = TranslateT("Miranda NG Core"); lvg.iGroupId = 2; ListView_InsertGroup(hwndList, 0, &lvg); lvg.pszHeader = TranslateT("Languages"); lvg.iGroupId = 3; ListView_InsertGroup(hwndList, 0, &lvg); lvg.pszHeader = TranslateT("Icons"); lvg.iGroupId = 4; ListView_InsertGroup(hwndList, 0, &lvg); ListView_EnableGroupView(hwndList, TRUE); bool enableOk = false; OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)lParam; for (int i = 0; i < todo.getCount(); ++i) { LVITEM lvI = {0}; lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_GROUPID | LVIF_NORECOMPUTE; lvI.iGroupId = (_tcsstr(todo[i].tszOldName, _T("Plugins")) != NULL) ? 1 : ((_tcsstr(todo[i].tszOldName, _T("Languages")) != NULL) ? 3 : ((_tcsstr(todo[i].tszOldName, _T("Icons")) != NULL) ? 4 : 2)); lvI.iSubItem = 0; lvI.lParam = (LPARAM)&todo[i]; lvI.pszText = todo[i].tszOldName; lvI.iItem = i; ListView_InsertItem(hwndList, &lvI); ListView_SetCheckState(hwndList, lvI.iItem, todo[i].bEnabled); if (todo[i].bEnabled) enableOk = true; SetStringText(hwndList,i,todo[i].bDeleteOnly ? TranslateT("Deprecated!") : TranslateT("Update found!")); } if(enableOk) EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); } bShowDetails = false; ResizeVert(hDlg, 60); // do this after filling list - enables 'ITEMCHANGED' below SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam); Utils_RestoreWindowPositionNoSize(hDlg, 0, MODNAME, "ConfirmWindow"); return TRUE; case WM_NOTIFY: if (((LPNMHDR) lParam)->hwndFrom == hwndList) { switch (((LPNMHDR) lParam)->code) { case LVN_ITEMCHANGED: if (GetWindowLongPtr(hDlg, GWLP_USERDATA)) { NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam; if ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) { LVITEM lvI = {0}; lvI.iItem = nmlv->iItem; lvI.iSubItem = 0; lvI.mask = LVIF_PARAM; ListView_GetItem(hwndList, &lvI); FILEINFO *p = (FILEINFO*)lvI.lParam; db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(p->tszOldName)), p->bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem)); // Toggle the Download button bool enableOk = false; OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); for (int i=0; i < todo.getCount(); ++i) { if (todo[i].bEnabled) { enableOk = true; break; } } EnableWindow(GetDlgItem(hDlg, IDOK), enableOk ? TRUE : FALSE); } } break; } } break; case WM_COMMAND: if (HIWORD( wParam ) == BN_CLICKED) { switch(LOWORD(wParam)) { case IDOK: EnableWindow( GetDlgItem(hDlg, IDOK), FALSE); EnableWindow( GetDlgItem(hDlg, IDC_SELALL), FALSE); EnableWindow( GetDlgItem(hDlg, IDC_SELNONE), FALSE); mir_forkthread(ApplyUpdates, hDlg); return TRUE; case IDC_DETAILS: bShowDetails = !bShowDetails; ResizeVert(hDlg, bShowDetails ? 242 : 60); SetDlgItemText(hDlg, IDC_DETAILS, (bShowDetails ? TranslateT("<< Details") : TranslateT("Details >>"))); break; case IDC_SELALL: SelectAll(hDlg, true); break; case IDC_SELNONE: SelectAll(hDlg, false); break; case IDCANCEL: DestroyWindow(hDlg); return TRUE; } } break; case UM_ERROR: MessageBox(hDlg, TranslateT("Update failed! One of the components wasn't downloaded correctly. Try it again later."), TranslateT("Plugin Updater"), MB_OK | MB_ICONERROR); DestroyWindow(hDlg); break; case WM_CLOSE: DestroyWindow(hDlg); break; case WM_DESTROY: Skin_ReleaseIcon((HICON)SendMessage(hDlg, WM_SETICON, ICON_SMALL, 0)); Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "ConfirmWindow"); hwndDialog = NULL; delete (OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); SetWindowLongPtr(hDlg, GWLP_USERDATA, 0); #if MIRANDA_VER >= 0x0A00 db_set_dw(NULL, MODNAME, DB_SETTING_LAST_UPDATE, time(NULL)); #endif mir_forkthread(InitTimer, 0); break; } return FALSE; }
static void DrawCurrentShipForm() { FormPtr frmP = FrmGetActiveForm(); int i, j, k, Line, FirstEmptySlot; RectangularShortcuts( frmP, CurrentShipBButton ); FrmDrawForm( frmP ); FntSetFont( boldFont ); DrawChars( "Type:", 0, 18 ); DrawChars( "Equipment:", 0, 32 ); FntSetFont( stdFont ); if (ScarabStatus == 3) { StrCopy( SBuf, Shiptype[Ship.Type].Name); StrCat ( SBuf, "/hardened hull"); DrawChars( SBuf, 60, 18 ); } else DrawChars( Shiptype[Ship.Type].Name, 60, 18 ); Line = 32; for (i=0; i<MAXWEAPONTYPE+EXTRAWEAPONS; ++i) { j = 0; for (k=0; k<MAXWEAPON; ++k) { if (Ship.Weapon[k] == i) ++j; } if (j > 0) { SBuf[0] = '\0'; SBufMultiples( j, Weapontype[i].Name ); StrToLower( SBuf2, SBuf ); DrawChars( SBuf2, 60, Line ); Line += 14; } } for (i=0; i<MAXSHIELDTYPE+EXTRASHIELDS; ++i) { j = 0; for (k=0; k<MAXSHIELD; ++k) { if (Ship.Shield[k] == i) ++j; } if (j > 0) { SBuf[0] = '\0'; SBufMultiples( j, Shieldtype[i].Name ); StrToLower( SBuf2, SBuf ); DrawChars( SBuf2, 60, Line ); Line += 14; } } for (i=0; i<MAXGADGETTYPE+EXTRAGADGETS; ++i) { j = 0; for (k=0; k<MAXGADGET; ++k) { if (Ship.Gadget[k] == i) ++j; } if (j > 0) { if (i == EXTRABAYS) { j = j*5; StrIToA( SBuf, j ); StrCat( SBuf, " extra cargo bays" ); } else { StrCopy(SBuf, Gadgettype[i].Name ); } StrToLower( SBuf2, SBuf ); DrawChars( SBuf2, 60, Line ); Line += 14; } } if (EscapePod) { DrawChars( "an escape pod", 60, Line ); Line += 14; } if (AnyEmptySlots(&Ship)) { FntSetFont( boldFont ); DrawChars( "Unfilled: ", 0, Line ); FntSetFont( stdFont ); FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].WeaponSlots, Ship.Weapon ); if (FirstEmptySlot >= 0) { SBuf[0] = '\0'; SBufMultiples( Shiptype[Ship.Type].WeaponSlots - FirstEmptySlot, "weapon slot" ); DrawChars( SBuf, 60, Line ); Line += 14; } FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].ShieldSlots, Ship.Shield ); if (FirstEmptySlot >= 0) { SBuf[0] = '\0'; SBufMultiples( Shiptype[Ship.Type].ShieldSlots - FirstEmptySlot, "shield slot" ); DrawChars( SBuf, 60, Line ); Line += 14; } FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].GadgetSlots, Ship.Gadget ); if (FirstEmptySlot >= 0) { SBuf[0] = '\0'; SBufMultiples( Shiptype[Ship.Type].GadgetSlots - FirstEmptySlot, "gadget slot" ); DrawChars( SBuf, 60, Line ); Line += 14; } } }
const char * SEL_ITEMget_dmtype( Type t, const Linked_List l ) { const char * r = utype_member( l, t, 0 ); return StrToLower( r ? r : TYPEget_utype( t ) ); }