mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Address Brick-By-Brick builds not properly saving and make migrations automatic (#725)
* Properly store BBB in database
Store the BBB data in the database as the received SD0 packet as opposed to just the raw lxfml. Addressed several memory leaks as well.
* Add Sd0Conversion
Add brick by brick conversion commands with 2 parameters to tell the program what to do with the data.
Add zlib -> sd0 conversion. Files look good at a glance but should be tested in game to ensure stability. Tests to come.
* moving to laptop
ignore this commit. I need to move this to my laptop
* Add functionality to delete bad models
Adds functionality to delete bad models. Models are batched together and deleted in one commit.
More testing is needed to ensure data safety. Positive tests on a live database reveal the broken models were truncated and complete ones were kept around successfully. Tests should be done to ensure larger sd0 models are properly saved and not truncated since this command should be able to be run any time.
Valgrind tests need to be run as well to ensure no memory leaks exist.
* Delete from query change
Changed from delete to delete cascade and instead deleting from properties_contents as opposed to ugc.
* Address numerous bugs
DELETE CASCADE is not a valid SQL command so this was changed to a better delete statement.
Added user confirmation before deleting a broken model.
Address appending the string model appending bad data, causing excess deletion.
Addressed memory leaks with sql::Blob
* Error handling for string
* Even more proper handling...
* Add bounds check for cli command
Output a message if a bad command is used.
Update MasterServer.cpp
* Remove user interference
-Add back in mariadb build jobs so i dont nuke others systems
- Remove all user interference and consolidate work into one command since 1 depends on the next.
* Add comments
test
Revert "test"
This reverts commit fb831f268b7a2f0ccd20595aff64902ab4f4b4ee.
* Update CMakeMariaDBLists.txt
Test
* Improve migration runner
Migration runner now runs automatically.
- Resolved an issue where extremely large sql queries caused the database to go into an invalid state.
- Made migrations run automatically on server start.
- Resolved a tiny memory leak in migration runner? (discarded returned pointer)
- Moved sd0 migrations of brick models to be run automatically with migration runner.
- Created dummy file to tell when brick migrations have been run.
* Update README
Updated the README to reflect the new server migration state.
* Make model deleter actually delete models
My complicated sql actually did nothing... Tested that this new SQL properly gets rid of bad data.
* Revert "Update CMakeMariaDBLists.txt"
This reverts commit 8b859d8529
.
This commit is contained in:
@@ -85,71 +85,51 @@ int main(int argc, char** argv) {
|
||||
Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console"))));
|
||||
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
|
||||
|
||||
if (argc > 1 && (strcmp(argv[1], "-m") == 0 || strcmp(argv[1], "--migrations") == 0)) {
|
||||
//Connect to the MySQL Database
|
||||
std::string mysql_host = config.GetValue("mysql_host");
|
||||
std::string mysql_database = config.GetValue("mysql_database");
|
||||
std::string mysql_username = config.GetValue("mysql_username");
|
||||
std::string mysql_password = config.GetValue("mysql_password");
|
||||
//Connect to the MySQL Database
|
||||
std::string mysql_host = config.GetValue("mysql_host");
|
||||
std::string mysql_database = config.GetValue("mysql_database");
|
||||
std::string mysql_username = config.GetValue("mysql_username");
|
||||
std::string mysql_password = config.GetValue("mysql_password");
|
||||
|
||||
try {
|
||||
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
|
||||
} catch (sql::SQLException& ex) {
|
||||
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s", ex.what());
|
||||
Game::logger->Log("MigrationRunner", "Migrations not run");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
MigrationRunner::RunMigrations();
|
||||
Game::logger->Log("MigrationRunner", "Finished running migrations");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
|
||||
//Check CDClient exists
|
||||
const std::string cdclient_path = "./res/CDServer.sqlite";
|
||||
std::ifstream cdclient_fd(cdclient_path);
|
||||
if (!cdclient_fd.good()) {
|
||||
Game::logger->Log("WorldServer", "%s could not be opened", cdclient_path.c_str());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cdclient_fd.close();
|
||||
|
||||
//Connect to CDClient
|
||||
try {
|
||||
CDClientDatabase::Connect(cdclient_path);
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database");
|
||||
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
|
||||
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Get CDClient initial information
|
||||
try {
|
||||
CDClientManager::Instance()->Initialize();
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database");
|
||||
Game::logger->Log("WorldServer", "May be caused by corrupted file: %s", cdclient_path.c_str());
|
||||
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
|
||||
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Connect to the MySQL Database
|
||||
std::string mysql_host = config.GetValue("mysql_host");
|
||||
std::string mysql_database = config.GetValue("mysql_database");
|
||||
std::string mysql_username = config.GetValue("mysql_username");
|
||||
std::string mysql_password = config.GetValue("mysql_password");
|
||||
|
||||
try {
|
||||
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
|
||||
} catch (sql::SQLException& ex) {
|
||||
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s", ex.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
try {
|
||||
Database::Connect(mysql_host, mysql_database, mysql_username, mysql_password);
|
||||
} catch (sql::SQLException& ex) {
|
||||
Game::logger->Log("MasterServer", "Got an error while connecting to the database: %s", ex.what());
|
||||
Game::logger->Log("MigrationRunner", "Migrations not run");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
MigrationRunner::RunMigrations();
|
||||
|
||||
//Check CDClient exists
|
||||
const std::string cdclient_path = "./res/CDServer.sqlite";
|
||||
std::ifstream cdclient_fd(cdclient_path);
|
||||
if (!cdclient_fd.good()) {
|
||||
Game::logger->Log("WorldServer", "%s could not be opened", cdclient_path.c_str());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cdclient_fd.close();
|
||||
|
||||
//Connect to CDClient
|
||||
try {
|
||||
CDClientDatabase::Connect(cdclient_path);
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
Game::logger->Log("WorldServer", "Unable to connect to CDServer SQLite Database");
|
||||
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
|
||||
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Get CDClient initial information
|
||||
try {
|
||||
CDClientManager::Instance()->Initialize();
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
Game::logger->Log("WorldServer", "Failed to initialize CDServer SQLite Database");
|
||||
Game::logger->Log("WorldServer", "May be caused by corrupted file: %s", cdclient_path.c_str());
|
||||
Game::logger->Log("WorldServer", "Error: %s", e.errorMessage());
|
||||
Game::logger->Log("WorldServer", "Error Code: %i", e.errorCode());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//If the first command line argument is -a or --account then make the user
|
||||
//input a username and password, with the password being hidden.
|
||||
@@ -825,9 +805,9 @@ void ShutdownSequence() {
|
||||
int FinalizeShutdown() {
|
||||
//Delete our objects here:
|
||||
Database::Destroy("MasterServer");
|
||||
delete Game::im;
|
||||
delete Game::server;
|
||||
delete Game::logger;
|
||||
if (Game::im) delete Game::im;
|
||||
if (Game::server) delete Game::server;
|
||||
if (Game::logger) delete Game::logger;
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
|
Reference in New Issue
Block a user