// *************************************************************** // Function: ConnectToDatabase.cpp // *************************************************************** #include "Main.h" //************************************ // Name: ConnectToDB // // Tries to connect to the database once. // // Parameters: // // Return: // true - Connection successful // false - Connection failed //************************************ bool ConnectToDb() { #ifndef WIN32 //wtf is wrong here? strings are screwed in linux *FIX* gDatabaseInfo.password[strlen(gDatabaseInfo.password) - 1] = '\0'; gDatabaseInfo.host[strlen(gDatabaseInfo.host) - 1] = '\0'; gDatabaseInfo.username[strlen(gDatabaseInfo.username) - 1] = '\0'; gDatabaseInfo.database_name[strlen(gDatabaseInfo.database_name) - 1] = '\0'; #endif gDatabase.Init(); if (!gDatabase.EstablishConnections(gDatabaseInfo.host, gDatabaseInfo.username, gDatabaseInfo.password, gDatabaseInfo.database_name, gDatabaseInfo.port, gDatabaseInfo.maxPipes)) { gCoreLog.LOCATION; gCoreLog.error("Failed to connect to database! Host: %s User: %s Pass: %s DBName: %s, Port: %u", gDatabaseInfo.host, gDatabaseInfo.username, gDatabaseInfo.password, gDatabaseInfo.database_name, gDatabaseInfo.port); return false; } return true; } //************************************ // Name: ConnectToDatabase // // Tries X times to connect to the database. // // Parameters: // // Return: // true - Connection successful // false - Could not connect //************************************ bool ConnectToDatabase() { gCoreLog.WriteCategory("[Connecting]"); gCoreLog.Section("GWLP Database..."); int retry_counter=0; while (!ConnectToDb()) { gCoreLog.LOCATION; gCoreLog.warning("Trying again..."); if (gShuttingDown || retry_counter>=gServerConfig.maxRetryConnects) { gCoreLog.SectionFail(); return false; } retry_counter++; } gCoreLog.SectionOk(); return true; }