#include "NetCli_Talk.h"
#include "../../MainProc/NetGlobal.h"
//-------------------------------------------------------------------
NetCli_Talk*    NetCli_Talk::This         = NULL;

//-------------------------------------------------------------------
bool NetCli_Talk::_Init()
{
    _Net.RegOnSrvPacketFunction	( EM_PG_Talk_TalkTo         , _PG_Talk_TalkTo           );
    _Net.RegOnSrvPacketFunction	( EM_PG_Talk_Range          , _PG_Talk_Range            );
//    _Net.RegOnSrvPacketFunction	( EM_PG_Talk_Zone           , _PG_Talk_Zone             );
    _Net.RegOnSrvPacketFunction	( EM_PG_Talk_LtoC_SystemMsg , _PG_Talk_LtoC_SystemMsg   );
    _Net.RegOnSrvPacketFunction	( EM_PG_GM_LtoC_SendMsg     , _PG_GM_LtoC_SendMsg   );
    _Net.RegOnSrvPacketFunction	( EM_PG_Talk_Channel		, _PG_Talk_Channel   );

    return true;
}
//-------------------------------------------------------------------
bool NetCli_Talk::_Release()
{
    return true;
}
//-------------------------------------------------------------------
void NetCli_Talk::_PG_Talk_TalkTo         ( int Sockid , int Size , void* Data )
{

    PG_Talk_TalkTo* PG = (PG_Talk_TalkTo*) Data;
	This->Rev_TalkTo( PG->SenderName.Begin() , PG->TargetName.Begin(), PG->ContentSize , PG->Content.Begin() );
}
void NetCli_Talk::_PG_Talk_Range          ( int Sockid , int Size , void* Data )
{
    PG_Talk_Range* PG = (PG_Talk_Range*) Data;
    This->Rev_Range( PG->GItemID , PG->Name.Begin() , PG->ContentSize , PG->Content.Begin() );
}
/*
void NetCli_Talk::_PG_Talk_Zone           ( int Sockid , int Size , void* Data )
{
    PG_Talk_Zone* PG = (PG_Talk_Zone*) Data;
    This->Rev_Zone( PG->GItemID , PG->Name.Begin() , PG->ContentSize , PG->Content.Begin() );
}
*/
void NetCli_Talk::_PG_Talk_LtoC_SystemMsg ( int Sockid , int Size , void* Data )
{
    PG_Talk_LtoC_SystemMsg* PG = (PG_Talk_LtoC_SystemMsg*) Data;
    This->Rev_SystemMsg(  PG->ContentSize , PG->Content.Begin() );
}
void NetCli_Talk::_PG_GM_LtoC_SendMsg     ( int Sockid , int Size , void* Data )
{
    PG_GM_LtoC_SendMsg* PG = (PG_GM_LtoC_SendMsg*) Data;
    This->Rev_GmMsg(  PG->Content.Begin() );
}
void NetCli_Talk::_PG_Talk_Channel	    ( int Sockid , int Size , void* Data )
{
	PG_Talk_Channel* PG = (PG_Talk_Channel*) Data;
	This->Rev_Channel	 ( PG->Type , PG->ChannelID , PG->MsgType , (char*)PG->Name.Begin() , (char*)PG->Content.Begin() );

}
//-------------------------------------------------------------------
void NetCli_Talk::TalkTo( const char* TargetName , const char* Content )
{
    PG_Talk_TalkTo Send;
    Send.ContentSize = int( min( sizeof( Send.Content) , strlen( Content ) + 1 ));
//    strncpy( Send.Content , Content , sizeof( Send.Content ) );
//    strncpy( Send.Name , Name , sizeof( Send.Name ) );
    Send.Content		= Content;
	//Send.SenderName		= SenderName;
    Send.TargetName		= TargetName;
    
    SendToLocal( sizeof(Send) , &Send );
}
//-------------------------------------------------------------------
void NetCli_Talk::Range( const char* Content   )
{
    PG_Talk_Range Send;

    Send.ContentSize = int( min( sizeof( Send.Content) , strlen( Content ) + 1));
    Send.Content = Content;
    SendToLocal( sizeof(Send) , &Send );

}
//-------------------------------------------------------------------
/*
void NetCli_Talk::Zone( const char* Content )
{
    PG_Talk_Zone Send;

    Send.ContentSize = int( min( sizeof( Send.Content) , strlen( Content ) + 1 ));
//    strncpy( Send.Content , Content , sizeof( Send.Content ) );
    Send.Content = Content;

    SendToLocal( sizeof(Send) , &Send );

}
*/
//-------------------------------------------------------------------
void NetCli_Talk::GMCommand( const char* Content )
{
    PG_Talk_CtoL_GMCommand Send;

    Send.ContentSize = int( min( sizeof( Send.Content) , strlen( Content ) + 1 ));
//    strncpy( Send.Content , Content , sizeof( Send.Content ) );
    Send.Content = Content;

    SendToLocal( sizeof(Send) , &Send );
}
//-------------------------------------------------------------------
void NetCli_Talk::GMMsg       ( const char* Content )
{
    PG_GM_CtoL_SendMsg Send;
    Send.ContentSize = int( min( sizeof( Send.Content) , strlen( Content ) + 1 ));
    Send.Content = Content;

    SendToLocal( sizeof(Send) , &Send );

}
//-------------------------------------------------------------------
void NetCli_Talk::Channel( GroupObjectTypeEnum Type , int ChannelID , char* Name , char* Content )
{
	PG_Talk_Channel Send;
	Send.Type = Type;
	Send.ChannelID = ChannelID;
	Send.Name = Name;
	Send.Content = Content;
	Send.ContentSize = Send.Content.Size() + 1;

	switch( Type )
	{
	case EM_GroupObjectType_SysChannel:			//系統
	case EM_GroupObjectType_SysZoneChannel:		//每個區域都有的
	case EM_GroupObjectType_PlayerChannel:		//玩家的
	case EM_GroupObjectType_Party:				//隊伍
		SendToChat( sizeof(Send) , &Send );
		break;
	case EM_GroupObjectType_Guild:				//工會
		SendToLocal( sizeof(Send) , &Send );
		break;
	}
	
}