#include "NetCli_Channel.h"

//-------------------------------------------------------------------
NetCli_Channel*    NetCli_Channel::This         = NULL;

//-------------------------------------------------------------------
bool NetCli_Channel::_Init()
{
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_LtoC_CreateChannelResult	 , _PG_ChannelBase_LtoC_CreateChannelResult	 );
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_LtoC_JoinChannelResult		 , _PG_ChannelBase_LtoC_JoinChannelResult		 );
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_LtoC_LeaveChannelResult		 , _PG_ChannelBase_LtoC_LeaveChannelResult		 );
	//¨Ó·½ chat
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_ChattoC_ClientConnectToChat		, _PG_ChannelBase_ChattoC_ClientConnectToChat	 );
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_ChattoC_DataTransmitCliToCli	, _PG_ChannelBase_ChattoC_DataTransmitCliToCli	 );
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_ChattoC_ChannelPlayerListResult	, _PG_ChannelBase_ChattoC_ChannelPlayerListResult	 );
	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_ChattoC_JoinPlayerDisabledResult, _PG_ChannelBase_ChattoC_JoinPlayerDisabledResult	 );

	_Net.RegOnSrvPacketFunction	( EM_PG_ChannelBase_ChattoC_SysChannel			, _PG_ChannelBase_ChattoC_SysChannel	 );

    return true;
}
//-------------------------------------------------------------------
bool NetCli_Channel::_Release()
{
    return true;
}
void NetCli_Channel::_PG_ChannelBase_ChattoC_SysChannel				( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_ChattoC_SysChannel* PG = (PG_ChannelBase_ChattoC_SysChannel*)Data;
	This->R_SysChannel( PG->Type , PG->ChannelID , (char*)PG->Name.Begin() );
}

void NetCli_Channel::_PG_ChannelBase_ChattoC_ChannelPlayerListResult	( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_ChattoC_ChannelPlayerListResult* PG = (PG_ChannelBase_ChattoC_ChannelPlayerListResult*)Data;

	vector<string> Name;

	for( int i = 0 ; i < PG->Count ; i++ )
	{
		Name.push_back( PG->PlayerNameList[i].Begin() );
	}

	This->R_ChannelPlayerListResult( PG->Type , PG->ChannelID , Name );

}
void NetCli_Channel::_PG_ChannelBase_ChattoC_JoinPlayerDisabledResult( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_ChattoC_JoinPlayerDisabledResult* PG = (PG_ChannelBase_ChattoC_JoinPlayerDisabledResult*)Data;

	This->R_JoinPlayerDisabledResult( PG->ChannelID , PG->Type , PG->JoinEnabled );
}


void NetCli_Channel::_PG_ChannelBase_LtoC_CreateChannelResult	( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_LtoC_CreateChannelResult* PG = (PG_ChannelBase_LtoC_CreateChannelResult*)Data;
	if( PG->Result == true )
	{
		This->R_CreateChannelOK( PG->ChannelID , PG->ChannelName.Begin() );
	}
	else
	{
		This->R_CreateChannelFailed( PG->ChannelName.Begin() );
	}
}
void NetCli_Channel::_PG_ChannelBase_LtoC_JoinChannelResult	( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_LtoC_JoinChannelResult* PG = (PG_ChannelBase_LtoC_JoinChannelResult*)Data;
	if( PG->Result == true )
	{
		This->R_JoinChannelOK( PG->ChannelID , PG->ChannelName.Begin() );
	}
	else
	{
		This->R_JoinChannelFailed( PG->ChannelName.Begin()  );
	}
}
void NetCli_Channel::_PG_ChannelBase_LtoC_LeaveChannelResult	( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_LtoC_LeaveChannelResult* PG = (PG_ChannelBase_LtoC_LeaveChannelResult*)Data;
	if( PG->Result == true )
	{
		This->R_LeaveChannelOK( PG->ChannelID );
	}
	else
	{
		This->R_LeaveChannelFailed( PG->ChannelID  );
	}
}
void NetCli_Channel::_PG_ChannelBase_ChattoC_DataTransmitCliToCli	( int Sockid , int Size , void* Data )
{
	PG_ChannelBase_ChattoC_DataTransmitCliToCli* PG = (PG_ChannelBase_ChattoC_DataTransmitCliToCli*)Data;
	This->R_ClitoCli_Data( PG->Data , PG->DataSize );
}


void NetCli_Channel::_PG_ChannelBase_ChattoC_ClientConnectToChat( int Sockid , int Size , void* Data )
{
	This->R_CliConnectToChat( Sockid );
}

void NetCli_Channel::S_CreateChannel			( const char* ChannelName , const char* Password )
{
	PG_ChannelBase_CtoL_CreateChannel Send;
	Send.ChannelName    = ChannelName;
	Send.Password		= Password;

	SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Channel::S_JoinChannel				( const char* ChannelName , const char* Password )
{
	PG_ChannelBase_CtoL_JoinChannel Send;
	Send.ChannelName = ChannelName;
	Send.Password = Password;
	SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Channel::S_LeaveChannel				( GroupObjectTypeEnum Type  , int ChannelID )
{
	PG_ChannelBase_CtoL_LeaveChannel Send;
	Send.ChannelID= ChannelID;
	Send.Type = Type;
	
	SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Channel::S_DataTransmitToCli_Group	( GroupObjectTypeEnum Type , int ChannelID , const char* Data , int DataSize )
{
	PG_ChannelBase_CtoChat_DataTransmitToCli_Group	Send;
	memcpy( Send.Data , Data , DataSize );
	Send.DataSize = DataSize;
	Send.Type = Type;
	Send.ChannelID = ChannelID;

	SendToChat(  sizeof(Send) , &Send );
}
void NetCli_Channel::S_DataTransmitToCli_Name	( char* Name , const char* Data , int DataSize )
{
	PG_ChannelBase_CtoChat_DataTransmitToCli_Name Send;
	memcpy( Send.Data , Data , DataSize );
	Send.DataSize = DataSize;
	Send.Name = Name;
	SendToChat(  sizeof(Send) , &Send );
}

void NetCli_Channel::S_ChannelPlayerList	( GroupObjectTypeEnum Type , int ChannelID )
{
	PG_ChannelBase_CtoChat_ChannelPlayerList Send;
	Send.Type = Type;
	Send.ChannelID = ChannelID;
	SendToChat(  sizeof(Send) , &Send );
}
void NetCli_Channel::S_JoinPlayerDisabled	( GroupObjectTypeEnum Type , int ChannelID , bool JoinEnabled )
{
	PG_ChannelBase_CtoChat_JoinPlayerDisabled Send;
	Send.Type = Type;
	Send.ChannelID = ChannelID;
	Send.JoinEnabled = JoinEnabled;
	SendToChat(  sizeof(Send) , &Send );
}
void NetCli_Channel::S_KickPlayer			( GroupObjectTypeEnum Type , int ChannelID , char* PlayerName )
{
	PG_ChannelBase_CtoChat_KickPlayer Send;
	Send.Type = Type;
	Send.ChannelID = ChannelID;
	Send.PlayerName = PlayerName;
	SendToChat(  sizeof(Send) , &Send );
}
void NetCli_Channel::S_SetManager			( GroupObjectTypeEnum Type , int ChannelID , char* PlayerName )
{
	PG_ChannelBase_CtoChat_SetManager Send;
	Send.Type = Type;
	Send.ChannelID = ChannelID;
	Send.PlayerName = PlayerName;
	SendToChat(  sizeof(Send) , &Send );
}
//°Ï°ìÀW¹DªºID
void NetCli_Channel::S_ChannelZoneID			( int MapZoneID )
{
	PG_ChannelBase_CtoChat_ZoneChannelID Send;
	Send.MapZoneID = MapZoneID;
	SendToChat(  sizeof(Send) , &Send );
}
