Example #1
0
bool Master::_StartDB()
{
	Database_Main = Database::Create();

	std::string hostname, username, password, database;
	int port = 0;

	bool result = sConfig.GetString("Database.Username", &username);
	sConfig.GetString("Database.Password", &password);
	result = !result ? result : sConfig.GetString("Database.Hostname", &hostname);
	result = !result ? result : sConfig.GetString("Database.Name", &database);
	result = !result ? result : sConfig.GetInt("Database.Port", &port);

 	if(result == false)
	{
		CRITICAL_LOG("sql: One or more parameters were missing from Database directive.");
		return false;
	}

	// Initialize it
	if(!sDatabase.Initialize(hostname.c_str(), (unsigned int)port, username.c_str(),
		password.c_str(), database.c_str(), sConfig.GetIntDefault("Database.ConnectionCount", 5),
		16384))
	{
		CRITICAL_LOG("sql: Main database initialization failed. Exiting.");
		return false;
	}

    return true;
}
Example #2
0
bool Master::Run()
{
	if (!sConfig.SetSource(REALITY_CONFIG))
	{
		CRITICAL_LOG(format("Could not find configuration file %1%.") % REALITY_CONFIG);
		exit(0);
	}

	INFO_LOG(format("Reality v0.01 Alpha %1% bit version started") % (sizeof(int*) * 8));

	if( !_StartDB() )
	{
		CRITICAL_LOG("Error starting database!");

		Database::CleanupLibs();
		return false;
	}

	DEBUG_LOG("Initializing random number generators...");
	uint32 seed = uint32(time(NULL));
	new MTRand(seed);
	srand(seed);

	_HookSignals();

	//init thread manager
	ThreadPool.Startup();
	
	//start server threads
	AuthRunnable *authRun = new AuthRunnable();
	ThreadPool.ExecuteTask(authRun);
	MarginRunnable *marginRun = new MarginRunnable();
	ThreadPool.ExecuteTask(marginRun);
	GameRunnable *gameRun = new GameRunnable();
	ThreadPool.ExecuteTask(gameRun);

	//spawn console thread
	ConsoleThread *consoleRun = new ConsoleThread();
	ThreadPool.ExecuteTask(consoleRun);

	while (!Master::m_stopEvent)
	{
		Sleep(100);
	}

	authRun->Terminate();
	marginRun->Terminate();
	gameRun->Terminate();

	consoleRun->Terminate();
	
	DEBUG_LOG("Exiting...");
	ThreadPool.ShowStats();

	_UnhookSignals();
	_StopDB();

	return 0;
}
Example #3
0
DaemonConfigProject::DaemonConfigProject( DaemonConfig &TheConfig, int TheProjectNumber )
{
 ProjectCache.clear();

 if( TheProjectNumber > TheConfig.Number_Of_Projects() )
 {
  CRITICAL_LOG( "DaemonConfigProject::DaemonConfigProject; TheProjectNumber > TheConfig.Number_Of_Projects()" );
  return;
 }

 if( TheProjectNumber <= 0 )
 {
  CRITICAL_LOG( "DaemonConfigProject::DaemonConfigProject; TheProjectNumber <= 0" );
  return;
 }

 string ResourceCache = Parse_XML( TheConfig.ConfigurationXML, "resource" );

 VERBOSE_DEBUG_LOG( "DaemonConfigProject::DaemonConfigProject; Cached resource data with ResourceCache=" << ResourceCache );

 string Attributes;
 int FoundNumber, StartPos = 0;

 do
 {
  ProjectCache = Parse_XML( ResourceCache, "project", Attributes, StartPos );

  VERBOSE_DEBUG_LOG( "DaemonConfigProject::DaemonConfigProject; Cached project data with ProjectCache=" << ProjectCache );
 
  if( !ProjectCache.empty() )
   if( sscanf( Attributes.c_str(), "number='%d'", &FoundNumber ) != 1 )
    if( sscanf( Attributes.c_str(), "number=\"%d\"", &FoundNumber ) != 1 )
     CRITICAL_LOG( "DaemonConfigProject::DaemonConfigProject; Error in project tag with Attributes=" << Attributes );

 } while ( ( StartPos < ResourceCache.length() ) && ( FoundNumber != TheProjectNumber ) );

 if( FoundNumber != TheProjectNumber )
 {
  ProjectCache.clear();
  CRITICAL_LOG( "DaemonConfigProject::DaemonConfigProject; Project tag with number=" << TheProjectNumber << " not found, cache cleared" );
 }

}
Example #4
0
        Application::Application() :
            mImpl(new ApplicationImpl)
        {
            glfwSetErrorCallback(errorCallback);

            if (!glfwInit())
            {
                CRITICAL_LOG("Could not initialize GLFW");
                exit(EXIT_FAILURE);
            }
        }
Example #5
0
DaemonConfigProjectApplication::DaemonConfigProjectApplication( DaemonConfigProject &TheProject, int TheApplicationNumber )
{
 ApplicationCache.clear();

 if( TheApplicationNumber > TheProject.Number_Of_Applications() )
 {
  CRITICAL_LOG( "DaemonConfigProjectApplication::DaemonConfigProjectApplication; TheApplicationNumber > TheProject.Number_Of_Applications()" );
  return;
 }

 if( TheApplicationNumber <= 0 )
 {
  CRITICAL_LOG( "DaemonConfigProjectApplication::DaemonConfigProjectApplication; TheApplicationNumber <= 0" );
  return;
 }

 string Attributes;
 int FoundNumber, StartPos = 0;

 do
 {
  ApplicationCache = Parse_XML( TheProject.ProjectCache, "application", Attributes, StartPos );

  VERBOSE_DEBUG_LOG( "DaemonConfigProjectApplication::DaemonConfigProjectApplication; Cached application data with ApplicationCache=" << ApplicationCache );

  if( !ApplicationCache.empty() )
   if( sscanf( Attributes.c_str(), "number='%d'", &FoundNumber ) != 1 )
    if( sscanf( Attributes.c_str(), "number=\"%d\"", &FoundNumber ) != 1 )
     CRITICAL_LOG( "DaemonConfigProjectApplication::DaemonConfigProjectApplication; Error in application tag with Attributes=" << Attributes );

 } while ( ( StartPos < TheProject.ProjectCache.length() ) && ( FoundNumber != TheApplicationNumber ) );

 if( FoundNumber != TheApplicationNumber )
 {
  ApplicationCache.clear();
  CRITICAL_LOG( "DaemonConfigProjectApplication::DaemonConfigProjectApplication; Application tag with number=" << TheApplicationNumber << " not found, cache cleared" );
 } 

}
Example #6
0
DaemonConfig::DaemonConfig( string ConfigFile )
{
 NORMAL_LOG( "DaemonConfig::DaemonConfig; Reading config file " << ConfigFile );

 ConfigurationXML = ReadStringFromFile( ConfigFile );

 DEBUG_LOG( "DaemonConfig::DaemonConfig; The configuration read in: " << ConfigurationXML );

 ConfigurationXML = NormalizeString( Parse_XML( ConfigurationXML, "LGI" ) );

 if( ConfigurationXML.empty() )
  CRITICAL_LOG( "DaemonConfig::DaemonConfig; No data in LGI tag found" );
}
Example #7
0
bool Database::_Reconnect(DatabaseConnection &conn)
{
	MYSQL * temp, *temp2;

	temp = mysql_init( NULL );
	temp2 = mysql_real_connect( temp, mHostname.c_str(), mUsername.c_str(), mPassword.c_str(), mDatabaseName.c_str(), mPort, NULL , 0 );
	if( temp2 == NULL )
	{
		CRITICAL_LOG(format("Could not reconnect to database because of `%1%`") % mysql_error( temp ) );
		mysql_close( temp );
		return false;
	}

	if( conn.conn != NULL )
		mysql_close( conn.conn );

	conn.conn = temp;
	return true;
}
Example #8
0
bool Database::Initialize(const char* Hostname, unsigned int port, const char* Username, const char* Password, const char* DatabaseName, uint32 ConnectionCount, uint32 BufferSize)
{
	uint32 i;
	MYSQL * temp, * temp2;
	my_bool my_true = true;

	mHostname = string(Hostname);
	mUsername = string(Username);
	mPassword = string(Password);
	mDatabaseName = string(DatabaseName);

	INFO_LOG(format("MySQLDatabase Connecting to `%1%`, database `%2%`...") % Hostname % DatabaseName);

	for( i = 0; i < ConnectionCount; ++i )
	{
		temp = mysql_init( NULL );
		if(mysql_options(temp, MYSQL_SET_CHARSET_NAME, "utf8"))
			WARNING_LOG("MySQLDatabase Could not set utf8 character set.");

		if (mysql_options(temp, MYSQL_OPT_RECONNECT, &my_true))
			WARNING_LOG("MYSQL_OPT_RECONNECT could not be set, connection drops may occur but will be counteracted.");

		temp2 = mysql_real_connect( temp, Hostname, Username, Password, DatabaseName, port, NULL, 0 );
		if( temp2 == NULL )
		{
			CRITICAL_LOG(format("MySQLDatabase Connection failed due to: `%1%`") % mysql_error( temp ) );
			return false;
		}

		m_connections.push_back(DatabaseConnection(temp2));
	}

	// Spawn Database thread
	ThreadPool.ExecuteTask(this);

	// launch the query thread
	qt = new QueryThread(this);
	ThreadPool.ExecuteTask(qt);

	return true;
}
Example #9
0
        void Application::createWindow(int width, int height,
            std::string const& title)
        {
            if (mImpl->currentWindow != nullptr)
            {
                ERROR_LOG("Multiple windows are currently not supported.");
                return;
            }

            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
            glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

#ifdef ATLAS_PLATFORM_APPLE
            glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif

            mImpl->currentWindow = glfwCreateWindow(width, height, 
                title.c_str(), NULL, NULL);
            if (!mImpl->currentWindow)
            {
                glfwTerminate();
                CRITICAL_LOG("Could not create window.");
                exit(EXIT_FAILURE);
            }

            glfwMakeContextCurrent(mImpl->currentWindow);

            GLint major, minor;
            glGetIntegerv(GL_MAJOR_VERSION, &major);
            glGetIntegerv(GL_MINOR_VERSION, &minor);

            INFO_LOG("Created OpenGL context " + std::to_string(major) +
                "." + std::to_string(minor));

            glewExperimental = GL_TRUE;
            GLenum err = glewInit();
            if (err != GLEW_OK)
            {
                CRITICAL_LOG("Could not initialize GLEW.");
                glfwDestroyWindow(mImpl->currentWindow);
                glfwTerminate();
                exit(EXIT_FAILURE);
            }

            glfwSetKeyCallback(mImpl->currentWindow, 
                keyPressCallback);
            glfwSetWindowSizeCallback(mImpl->currentWindow, 
                windowSizeCallback);
            glfwSetFramebufferSizeCallback(mImpl->currentWindow,
                frameBufferSizeCallback);
            glfwSetMouseButtonCallback(mImpl->currentWindow, 
                mousePressCallback);
            glfwSetCursorPosCallback(mImpl->currentWindow, 
                mouseMoveCallback);
            glfwSetWindowCloseCallback(mImpl->currentWindow, 
                windowCloseCallback);

            // HACK: This clears out the errors generated by glew.
            // We need to find a better way of doing this. Maybe replace
            // GLEW in its entirety?
            GL_CLEAR_ERRORS();
        }