// Includes
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include "winsock.h"
#include <mysql.h>

// MyIncludes
#include "Config.h"
#include "..\Functions\ColorText.h"

// Pragma
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib,"libmysql.lib")

// Std defines
using std::cout;
using std::endl;
using std::string;

//Client structure
struct _client
{
	bool		connected;
	sockaddr_in	address;
	SOCKET		socket;
	fd_set		socket_data;
	int			address_length;
	int			client_acess;
	char		nick_name[10];
};

/******** RecvData.h ***********/
// If message is online message
extern bool buddy_was_found;
// Reveiving buffers
extern char data0[LENGHT_SIZE+1];
extern char data1[DATA_ONE_SIZE+1];
extern char data2[BUFFER_SIZE];
extern char data3[BUFFER_SIZE];
// Reg variables
extern char reg1[DATA_ONE_SIZE+1];
extern char reg2[DATA_ONE_SIZE+1];
extern char reg3[DATA_ONE_SIZE+1];
extern char reg4[DATA_ONE_SIZE+1];
extern char reg5[DATA_ONE_SIZE+1];
extern char reg6[DATA_ONE_SIZE+1];
extern char reg7[DATA_ONE_SIZE+1];
extern char reg8[DATA_ONE_SIZE+1];
// Functions
extern void	function_receive_data();

/******************* Main.h ******************/
// Client structure define
extern _client client[MAX_CLIENTS];
// Global onlines counter
extern int	clients_connected;
// Sending global buffers
extern char buffer2_text[BUFFER_SIZE];
extern char buffer2_text_len_char[LENGHT_SIZE];
extern int buffer2_text_len;
extern char buffer_text[BUFFER_SIZE];
extern char buffer_text_len_char[LENGHT_SIZE];
extern int buffer_text_len;
extern char buffer3_text[BUFFER_SIZE];
extern char buffer3_text_len_char[LENGHT_SIZE];
extern int buffer3_text_len;
// MySql global stores
extern char mysql_text[MYSQL_TEXT_SIZE];
extern int mysql_return_value;
extern MYSQL_RES *mysql_result;
extern MYSQL_ROW mysql_row;
extern MYSQL_RES *mysql_result2;
extern MYSQL_ROW mysql_row2;

/********************* Warnings.h *********************/
// Functions
extern void function_show_error(char msg[400]);
extern void function_show_warning(char msg[400]);
extern void function_show_ready(char msg[400]);
// Variables
extern char warnings_tmp[400];

/********************** Mysql.h ********************/
// Functions
extern int function_mysql_returned(char * argumenty);
extern MYSQL_RES *function_mysql_result(char * argument);
//Variables
extern MYSQL mySQL;

/********************************** Functions.h ******************************/
// Functions
extern void function_midcopy ( char* input, char* output, int start_pos, int stop_pos );

/******************** OfflineMessages.h ******************/
// Functions
extern void function_send_offline_messages(_client *current_client);

/********** ServerStartEnd ************/
// WinSock variables
extern sockaddr_in	server_address;
extern sockaddr	server_socket_address;
extern SOCKET server_socket;
// Functions
extern void	function_start_server();
extern void	function_end_server();

/**************** BuddiesUpdate.h ***************/
// Functions
extern void function_budies_update(int type, int buddy);

/******************************** ChckFriendstate.h ***********************************/
// Functions
extern bool function_check_friendstate(_client *counter_client, _client *current_client);

/****************** AcpDisClient.h ***************************/
// Functions
extern void function_accept_connections();
extern void function_disconnect_client(_client *current_client);

/******************************* AcpRcvClient.h ********************************/
// Functions
extern bool	function_accept_client ( _client *current_client );
extern bool	function_receive_client ( _client *current_client, char *buffer, int size );

/********************************* SendData.h ********************************/
// Functions
extern int function_send_data ( _client *current_client, char *buffer, int size );

/*************************************** BroadBuddies.h *******************************/
// Functions
extern void function_broadcast_buddies ( char *message,  _client *current_client, int size);

/****************** ChckClient.h ********************/
// Functions
extern bool function_check_client(_client *current_client);