Advertisement
Rochet2

Untitled

May 29th, 2015
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.57 KB | None | 0 0
  1. enum DatabaseTypes
  2. {
  3.     DATABASE_WORLD,
  4.     DATABASE_AUTH,
  5.     DATABASE_CHARACTER,
  6.     COUNT_DATABASES,
  7. };
  8.  
  9. struct DBVersion
  10. {
  11.     uint32 expected_version;
  12.     uint32 expected_structure;
  13.     uint32 expected_content;
  14. };
  15.  
  16. static const DBVersion databaseVersions[COUNT_DATABASES] = {
  17.     {123, 123, 123}, // DATABASE_WORLD
  18.     {123, 123, 123}, // DATABASE_AUTH
  19.     {123, 123, 123}, // DATABASE_CHARACTER
  20. };
  21.  
  22. bool Database::CheckDatabaseVersion(DatabaseTypes database)
  23. {
  24.     const DBVersion& dbversion = databaseVersions[database];
  25.  
  26.     // Fetch the world database version table information
  27.     QueryResult* result = PQuery("SELECT * FROM db_version LIMIT 1");
  28.     if (!result)
  29.     {
  30.         // db_version table does not exist
  31.         sLog.outErrorDb("The table `db_version` in your [%s] database is missing or corrupt.", database);
  32.         sLog.outErrorDb();
  33.         sLog.outErrorDb("  [A] You have database version: --> Version: MaNGOS can not verify your database version or its existence.");
  34.         sLog.outErrorDb();
  35.         sLog.outErrorDb("  [B] You need database version: --> Version: %u Structure: %u Content: %u", dbversion.expected_version, dbversion.expected_structure, dbversion.expected_content);
  36.         sLog.outErrorDb();
  37.         sLog.outErrorDb("Please verify your database location or your database integrity.");
  38.         return false;
  39.     }
  40.  
  41.     Field* fields = result->Fetch();
  42.     uint32 version = fields[0].GetUInt32();
  43.     uint32 structure = fields[1].GetUInt32();
  44.     uint32 content = fields[2].GetUInt32();
  45.     std::string name = fields[3].GetCppString();
  46.  
  47.     delete result;
  48.  
  49.     // Check if the world database version matches the required core version
  50.     if (structure == dbversion.expected_structure)
  51.     {
  52.         sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected version!", database);
  53.         sLog.outErrorDb();
  54.         sLog.outErrorDb("  [A] You have database version: --> Version: %u Structure: %u Content: %u", version, structure, content);
  55.         sLog.outErrorDb();
  56.         sLog.outErrorDb("  [B] You need database version: --> Version: %u Structure: %u Content: %u", dbversion.expected_version, dbversion.expected_structure, dbversion.expected_content);
  57.         sLog.outErrorDb();
  58.         sLog.outErrorDb("You must apply all updates after [A] to [B] to use mangos with this database.");
  59.         sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", database);
  60.         return false;
  61.     }
  62.    
  63.     // World DB is not up to date, but structure is correct. Send warning but start core
  64.     if (version != dbversion.expected_version || content != dbversion.expected_content)
  65.     {
  66.         sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected version!", database);
  67.         sLog.outErrorDb();
  68.         sLog.outErrorDb("  [A] You have database version: --> Version: %u Structure: %u Content: %u", version, structure, content);
  69.         sLog.outErrorDb();
  70.         sLog.outErrorDb("  [B] You need database version: --> Version: %u Structure: %u Content: %u", dbversion.expected_version, dbversion.expected_structure, dbversion.expected_content);
  71.         sLog.outErrorDb();
  72.         sLog.outErrorDb("You are missing content updates or you have content updates beyond the expected core version.");
  73.         sLog.outErrorDb("It is recommended to run ALL database updates up to the required core version.");
  74.         sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", database);
  75.     }
  76.     return true;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement