/*************************************************************************************************************
This file contains sending datas function
2012/6 by Dlxko
**************************************************************************************************************/
#include "SendData.h"

/************************** SEND DATA TO CLIENT ***************************/
int function_send_data (_client *current_client, char *buffer, int size)
{
	// Store the return information about the sending
	current_client->address_length = send(current_client->socket, buffer, size, 0);

	// Check for errors
	if (( current_client->address_length == SOCKET_ERROR ) || ( current_client->address_length != size )  || ( current_client->address_length == INVALID_SOCKET ))
	{
		std::cout << color(FOREGROUND_RED|FOREGROUND_BLUE) << "|ERR|->>"
			<< color(FOREGROUND_GREEN|FOREGROUND_GREEN) << "Send_data for ["
			<< color(FOREGROUND_GREEN|FOREGROUND_RED) << current_client->nick_name
			<< color(FOREGROUND_RED|FOREGROUND_RED) << "] Return wrong value! Hard offline? Disconnecting..."
			<< std::endl;

		function_disconnect_client ( current_client );
		return false;
	}
	else return true;
	
}