Pastebin

New pastes are no longer accepted · Stats

Latest Pastes

eohost.exe - Incomplete

#include <winsock.h>
#include <mysql.h>
#include <cstdio>

MYSQL mysql;
MYSQL_ROW row;
MYSQL_RES* result;
unsigned int num_fields;

void check_status()
{
    if ( mysql_query( &mysql, "SELECT port FROM servers" ) == 0 )
    {
        result = mysql_store_result( &mysql );
        num_fields = mysql_num_fields( result );

        while ( ( row = mysql_fetch_row( result ) ) )
        {
            int port = atoi(row[0]);

            // Check if the server is online or offline.
            // Store the result in the database.
        }
    }
}

void start_servers()
{
    if ( mysql_query( &mysql, "SELECT name, directory, port FROM servers WHERE needs_start=1" ) == 0 )
    {
        result = mysql_store_result( &mysql );
        num_fields = mysql_num_fields( result );

        while ( ( row = mysql_fetch_row( result ) ) )
        {
            char* name = row[0];
            char* directory = row[1];
            int port = atoi(row[2]);

            // Check if the server is already online.
            // Alter the config file.
            // Start the server.

            char buf[256];
            sprintf( buf, "UPDATE servers SET needs_start=0 WHERE name=\"%s\" LIMIT 1", name );
            printf( "%s\n", buf );

            if ( mysql_query( &mysql, buf ) != 0 )
            {
                printf( "Failed to update the database: Error: %s\n", mysql_error( &mysql ) );
                exit(-1);
            }
        }
    }
}

int main( int argc, char** argv )
{
    mysql_init( &mysql );

    if ( !mysql_real_connect( &mysql, "localhost", "root", "", "eohost", 0, NULL, 0 ) )
    {
        printf( "Failed to connect to database: Error: %s\n", mysql_error( &mysql ) );
        exit(-1);
    }

    while ( true )
    {
        check_status();
        start_servers();

        Sleep( 5 * ( 60 * 1000 ) ); // 5 Minutes.
    }

    mysql_close( &mysql );

    return 0;
}