| 41 | }; |
| 42 | |
| 43 | CServerBrowserPingCache::CServerBrowserPingCache(IConsole *pConsole, IStorage *pStorage) : |
| 44 | m_pConsole(pConsole) |
| 45 | { |
| 46 | m_pDisk = SqliteOpen(pConsole, pStorage, "ddnet-cache.sqlite3"); |
| 47 | if(!m_pDisk) |
| 48 | { |
| 49 | pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "serverbrowse_ping_cache", "failed to open ddnet-cache.sqlite3"); |
| 50 | return; |
| 51 | } |
| 52 | sqlite3 *pSqlite = m_pDisk.get(); |
| 53 | static const char TABLE[] = "CREATE TABLE IF NOT EXISTS server_pings (ip_address TEXT PRIMARY KEY NOT NULL, ping INTEGER NOT NULL, utc_timestamp TEXT NOT NULL)"; |
| 54 | if(SQLITE_HANDLE_ERROR(sqlite3_exec(pSqlite, TABLE, nullptr, nullptr, nullptr))) |
| 55 | { |
| 56 | m_pDisk = nullptr; |
| 57 | pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "serverbrowse_ping_cache", "failed to create server_pings table"); |
| 58 | return; |
| 59 | } |
| 60 | m_pLoadStmt = SqlitePrepare(pConsole, pSqlite, "SELECT ip_address, ping FROM server_pings"); |
| 61 | m_pStoreStmt = SqlitePrepare(pConsole, pSqlite, "INSERT OR REPLACE INTO server_pings (ip_address, ping, utc_timestamp) VALUES (?, ?, datetime('now'))"); |
| 62 | } |
| 63 | |
| 64 | void CServerBrowserPingCache::Load() |
| 65 | { |
nothing calls this directly
no test coverage detected