#include "stdafx.h"
/*#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
#include "Authorization.h"
#include "Natives.h"

#define NAME       "vampir-kolik"
#define DATABASE   "bd_keys_for_programs_vampir-kolik"

extern HPLAYER vHostPlayer;
extern char vIP[100];
extern bool bIP;

bool fChekAuthorization(char *vKey)
{
	char vMessage[100];
	if (bIP == FALSE)
	{
		sprintf(vMessage,"Error = 'No internet connection.'");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
	}
	int vLenKey;
	int vvi;
	if (vKey)
	{
		vLenKey = 0;
		vLenKey = strlen(vKey);
		if (vLenKey != 19) return FALSE;
		for (vvi = 0; vvi < 2; vvi++)
		{
			if(vKey[4 + vvi * 5] != '-') return FALSE;
		}
	}
	MYSQL* obj;
    MYSQL_RES* res;
    MYSQL_ROW row;
	char vSQL[200];
	char vRes[5];
	char vHost[20];
	char vName[20];
	char vPassword[20];
	char vDB[40];
	int vFlagResult;
    vFlagResult = 0;
	sprintf(vHost,"%s\0",vIP);
	sprintf(vName,"%s\0",NAME);
	sprintf(vPassword,"123456789");
	sprintf(vDB,"%s\0",DATABASE);

    if(!(obj = mysql_init(0)))
    {
		sprintf(vMessage,"Error! mysql_init");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
    }
    
    if(!mysql_real_connect(obj, vHost, vName, vPassword, vDB, 3306, NULL, 0))
    {
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
    }
    else 
    {
		sprintf(vMessage,"Connect DB succes!!!");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
    }
    sprintf(vSQL,"SELECT * FROM `keys_for_programs_vampir-kolik` WHERE `key` = '%s';\0",vKey);
	
    if(mysql_query(obj, vSQL))
    {
        sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
        goto m1;
    }
    

    if (res = mysql_store_result(obj))
    {
        while(row = mysql_fetch_row(res))
        {
			sprintf(vRes,"%s\0",row[1]);
			if (memcmp("0",vRes,1) == 0)
			{
				vFlagResult = 1;
			}
			else
			{
				vFlagResult = 0;
			}
        }
    }
	else
	{
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
	}
	try
	{
		mysql_close(obj);
	}
	catch(...)
	{
	}

	if (vFlagResult == 0)
	{
		return FALSE;
	}

	if(!(obj = mysql_init(0)))
    {
		sprintf(vMessage,"Error! mysql_init");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
    }

	if(!mysql_real_connect(obj, vHost, vName, vPassword, vDB, 3306, NULL, 0))
    {
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
    }
    else 
    {
		sprintf(vMessage,"Connect database succes!!!");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
    }
    sprintf(vSQL,"UPDATE `keys_for_programs_vampir-kolik` SET `activation`=true WHERE `key` = '%s';\0",vKey);
	
    
    if(mysql_query(obj, vSQL))
	{    
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
        goto m1;
	}
m1:
    try
	{
		mysql_close(obj);
	}
	catch(...)
	{
	}
	if (vFlagResult == 1)
	{
		return TRUE;
	}
	return FALSE;
}

bool fAddWin(char *vNickName, char *vDate, char *vGame_time, char *vÑountry, wchar_t *vÑountryUnicode)
{
	char vMessage[200];
	if (bIP == FALSE)
	{
		sprintf(vMessage,"Error = 'No internet connection.'");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
	}
	if (vNickName == NULL || vDate == NULL || vGame_time == NULL) return FALSE;
	if (strlen(vNickName) <= 0 || strlen(vDate) < 0 || strlen(vGame_time) < 0) return FALSE;
	MYSQL* obj;
    MYSQL_RES* res;
    MYSQL_ROW row;
	char vSQL[200];
	char vHost[20];
	char vName[20];
	char vPassword[20];
	char vDB[40];
	int vFlagResult;
    vFlagResult = 0;
	sprintf(vHost,"%s\0",vIP);
	sprintf(vName,"%s\0",NAME);
	sprintf(vPassword,"123456789");
	sprintf(vDB,"%s\0",DATABASE);

	if(!(obj = mysql_init(0)))
    {
		sprintf(vMessage,"Error! mysql_init");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
    }
	if(!mysql_real_connect(obj, vHost, vName, vPassword, vDB, 3306, NULL, CLIENT_SSL))
    {
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
    }
    else 
    {
		sprintf(vMessage,"Connect database succes!!!");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
    }
	//UPDATE `pachx_content` SET `introtext`= CONCAT(introtext, '%s') WHERE `alias` = 'win1';\0
	if (vÑountry != NULL)
	{
		sprintf(vSQL,"INSERT INTO `win1` (`name`, `date`, `game_time`, `country`) VALUES ('%s', '%s', '%s', '%s');\0",vNickName,vDate,vGame_time,vÑountry);
	}
    if (vÑountryUnicode != NULL)
	{
		sprintf(vSQL,"INSERT INTO `win1` (`name`, `date`, `game_time`, `country`) VALUES ('%s', '%s', '%s', '%hs');\0",vNickName,vDate,vGame_time,vÑountryUnicode);
	}

    if(mysql_query(obj, vSQL))
	{    
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
        goto m1;
	}
	else
	{
		vFlagResult = 1;
	}
m1:
    try
	{
		mysql_close(obj);
	}
	catch(...)
	{
	}
	if (vFlagResult == 1)
	{
		return TRUE;
	}
	return FALSE;
}

bool fAddSQL(char *vSQL)
{
	char vMessage[200];
	if (bIP == FALSE)
	{
		sprintf(vMessage,"Error = 'No internet connection.'");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
	}
	if (vSQL == NULL) return FALSE;
	if (strlen(vSQL) <= 0) return FALSE;
	MYSQL* obj;
    MYSQL_RES* res;
    MYSQL_ROW row;
	char vHost[20];
	char vName[20];
	char vPassword[20];
	char vDB[40];
	int vFlagResult;
    vFlagResult = 0;
	sprintf(vHost,"%s\0",vIP);
	sprintf(vName,"%s\0",NAME);
	sprintf(vPassword,"123456789");
	sprintf(vDB,"%s\0",DATABASE);

	if(!(obj = mysql_init(0)))
    {
		sprintf(vMessage,"Error! mysql_init");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
    }
	if(!mysql_real_connect(obj, vHost, vName, vPassword, vDB, 3306, NULL, CLIENT_SSL))
    {
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
    }
    else 
    {
		sprintf(vMessage,"Connect database succes!!!");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
    }
    
    if(mysql_query(obj, vSQL))
	{    
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
        goto m1;
	}
	else
	{
		vFlagResult = 1;
	}
m1:
	try
	{
		mysql_close(obj);
	}
	catch(...)
	{
	}
	if (vFlagResult == 1)
	{
		return TRUE;
	}
	return FALSE;
}

bool fGetCountry(char *vCountry, char *vNickName)
{
	char vMessage[100];
	if (bIP == FALSE)
	{
		sprintf(vMessage,"Error = 'No internet connection.'");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
	}
	if (vNickName == NULL) return FALSE;
	if (strlen(vNickName) <= 0) return FALSE;
	MYSQL* obj;
    MYSQL_RES* res;
    MYSQL_ROW row;
	char vSQL[200];
	char vHost[20];
	char vName[20];
	char vPassword[20];
	char vDB[40];
	char vUser_id[12];
	int vFlagResult;
    vFlagResult = 0;
	sprintf(vHost,"%s\0",vIP);
	sprintf(vName,"%s\0",NAME);
	sprintf(vPassword,"123456789");
	sprintf(vDB,"%s\0","bd_for_joomla");

	if(!(obj = mysql_init(0)))
    {
		sprintf(vMessage,"Error! mysql_init");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
    }
    
    if(!mysql_real_connect(obj, vHost, vName, vPassword, vDB, 3306, NULL, 0))
    {
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
    }
    else 
    {
		//sprintf(vMessage,"Connect DB succes!!!");
		//DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
    }
    sprintf(vSQL,"SELECT `id` FROM `pachx_users` WHERE `name` = '%s';\0",vNickName);
	
    if(mysql_query(obj, vSQL))
    {
        sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
        goto m1;
    }
    

    if (res = mysql_store_result(obj))
    {
        while(row = mysql_fetch_row(res))
        {
			sprintf(vUser_id,"%s\0",row[0]);
			break;
        }
    }
	else
	{
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
	}
	try
	{
		mysql_close(obj);
	}
	catch(...)
	{
	}
	if (strlen(vUser_id) <= 0)
	{
		return FALSE;
	}

    if(!(obj = mysql_init(0)))
    {
		sprintf(vMessage,"Error! mysql_init");
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		return FALSE;
    }
    
    if(!mysql_real_connect(obj, vHost, vName, vPassword, vDB, 3306, NULL, 0))
    {
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
    }
    else 
    {
		//sprintf(vMessage,"Connect DB succes!!!");
		//DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
    }
    sprintf(vSQL,"SELECT `profile_value` FROM `pachx_user_profiles` WHERE `user_id` = '%s' and `profile_key` = 'profile.country';\0",vUser_id);
	
    if(mysql_query(obj, vSQL))
    {
        sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
        goto m1;
    }
    

    if (res = mysql_store_result(obj))
    {
        while(row = mysql_fetch_row(res))
        {
			sprintf(vCountry,"%s\0",row[0]);
			vFlagResult = 1;
			break;
        }
    }
	else
	{
		sprintf(vMessage,"Error = %s",mysql_error(obj));
		DisplayTextToPlayer( vHostPlayer, 0.0, 0.0, vMessage );
		goto m1;
	}

m1:
    try
	{
		mysql_close(obj);
	}
	catch(...)
	{
	}
	if (vFlagResult == 1)
	{
		return TRUE;
	}
	return FALSE;
}*/