/*************************************************************************************************************
* This file contains main function
* 2012/8 by Dlxko
* Version 3.0
**************************************************************************************************************/
#include "Main.h"

// Init GTK+2
using namespace std;
int main( int argc, char **argv );

// GTK main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
{
	return main (__argc, __argv);
}

// Main function of server
int main(int argc, char *argv[])
{
	// Start threads support
	if( ! g_thread_supported() )
		g_thread_init( NULL );

	// GTK init
	gtk_init (&argc, &argv);

	//Create server window
	create_server_window();

	// Start Server
	function_start_server();

	// Create serverinfo
	create_serverinfo();

	// Check MySQL accounts
	if( (function_mysql_returned("SELECT * FROM accounts")) == 4 )
		function_showgtk_fatal("Couldn't init MySQL or some table doesn't exist!");

	// Check MySQL buddylist
	if( (function_mysql_returned("SELECT * FROM buddylist")) == 4 )
		function_showgtk_fatal("Couldn't init MySQL or some table doesn't exist!");

	// Check MySQL events
	if( (function_mysql_returned("SELECT * FROM events")) == 4 )
		function_showgtk_fatal("Couldn't init MySQL or some table doesn't exist!");

	// Check MySQL messages
	if( (function_mysql_returned("SELECT * FROM messages")) == 4 )
		function_showgtk_fatal("Couldn't init MySQL or some table doesn't exist!");

	// Loop 5s
	g_timeout_add (DETECT_OFFLINES_REPEAT, function_junk_broadcast, NULL);

	// Create loop
	gtk_main();

	// Exit
	return 0;
}