| 114 | |
| 115 | |
| 116 | void ServerListCache::loadCache() { |
| 117 | std::string fileName = getCacheFilename(); |
| 118 | if (fileName == "") { return; } |
| 119 | std::ifstream inFile(fileName.c_str(), std::ios::in | std::ios::binary); |
| 120 | |
| 121 | if (inFile) { |
| 122 | char buffer[max_string + 1]; |
| 123 | while (inFile) { |
| 124 | std::string serverIndex; |
| 125 | ServerItem info; |
| 126 | |
| 127 | inFile.read(buffer, sizeof(buffer)); //read the index of the map |
| 128 | if ((size_t)inFile.gcount() < sizeof(buffer)) { break; } // failed to read entire string |
| 129 | serverIndex = buffer; |
| 130 | |
| 131 | bool infoWorked = info.readFromFile(inFile); |
| 132 | // after a while it is doubtful that player counts are accurate |
| 133 | if (info.getAgeMinutes() > (time_t)30) { info.ping.zeroPlayerCounts(); } |
| 134 | if (!infoWorked) { break; } |
| 135 | |
| 136 | serverCache.insert(SRV_STR_MAP::value_type(serverIndex, info)); |
| 137 | } |
| 138 | inFile.close(); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | |
| 143 | bool ServerListCache::clearCache() { |
nothing calls this directly
no test coverage detected