| 62 | } |
| 63 | |
| 64 | void CServerBrowserPingCache::Load() |
| 65 | { |
| 66 | if(m_pDisk) |
| 67 | { |
| 68 | std::vector<CEntry> vNewEntries; |
| 69 | |
| 70 | sqlite3 *pSqlite = m_pDisk.get(); |
| 71 | IConsole *pConsole = m_pConsole; |
| 72 | bool Error = false; |
| 73 | bool WarnedForBadAddress = false; |
| 74 | Error = Error || !m_pLoadStmt; |
| 75 | while(!Error) |
| 76 | { |
| 77 | int StepResult = SQLITE_HANDLE_ERROR(sqlite3_step(m_pLoadStmt.get())); |
| 78 | if(StepResult == SQLITE_DONE) |
| 79 | { |
| 80 | break; |
| 81 | } |
| 82 | else if(StepResult == SQLITE_ROW) |
| 83 | { |
| 84 | const char *pIpAddress = (const char *)sqlite3_column_text(m_pLoadStmt.get(), 0); |
| 85 | int Ping = sqlite3_column_int(m_pLoadStmt.get(), 1); |
| 86 | NETADDR Addr; |
| 87 | if(net_addr_from_str(&Addr, pIpAddress)) |
| 88 | { |
| 89 | if(!WarnedForBadAddress) |
| 90 | { |
| 91 | char aBuf[64]; |
| 92 | str_format(aBuf, sizeof(aBuf), "invalid address: %s", pIpAddress); |
| 93 | pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "serverbrowse_ping_cache", aBuf); |
| 94 | WarnedForBadAddress = true; |
| 95 | } |
| 96 | continue; |
| 97 | } |
| 98 | vNewEntries.push_back(CEntry{Addr, Ping}); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | Error = true; |
| 103 | } |
| 104 | } |
| 105 | if(Error) |
| 106 | { |
| 107 | pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "serverbrowse_ping_cache", "failed to load ping cache"); |
| 108 | return; |
| 109 | } |
| 110 | for(const auto &Entry : vNewEntries) |
| 111 | { |
| 112 | m_Entries[Entry.m_Addr] = Entry.m_Ping; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | int CServerBrowserPingCache::NumEntries() const |
| 118 | { |
nothing calls this directly
no test coverage detected