/*************************************************************************************************************
* This file contains checking friendstates
* 2012/8 by Dlxko
* Version 3.0
**************************************************************************************************************/
#include "ChckFriendstate.h"

// Local static variables
static int friend_state_counter;

// Function to chcheck friendstate
bool function_check_friendstate(_client *counter_client, _client *current_client)
{
	// Reset counter
	friend_state_counter = 0;
	mysql_return_value = 0;

	// Get the first friend state
	memset(mysql_text, 0,MYSQL_TEXT_SIZE);
	sprintf_s(mysql_text, "SELECT * FROM  buddylist WHERE client_name = '%s' AND friend_name = '%s'", counter_client->nick_name, current_client->nick_name);
	mysql_return_value = function_mysql_returned(mysql_text);

	// Set the first handler to one
	if (mysql_return_value == MORE_ROWS_OR_SEARCHED)
		friend_state_counter = 1;

	// Get the second friend state
	memset(mysql_text, 0,MYSQL_TEXT_SIZE);
	sprintf_s(mysql_text, "SELECT * FROM  buddylist WHERE client_name = '%s' AND friend_name = '%s'", current_client->nick_name, counter_client->nick_name);
	mysql_return_value = function_mysql_returned(mysql_text);

	// If both states ok send true value else send false
	if (mysql_return_value == MORE_ROWS_OR_SEARCHED && friend_state_counter == 1)
		return true;
	else
		return false;
}