#include "StdAfx.h"
#include "GameAgentNetwork.h"
#include "../common/CommonNetworkMsgStruct.h"
#include "../Common/Protocol.h"
#include "ServerToolDlg.h"


cGameAgentNetwork::cGameAgentNetwork(void)
{
}


cGameAgentNetwork::~cGameAgentNetwork(void)
{
}


bool cGameAgentNetwork::SuccessConnect()	
{ 
	mIsConnect = true; 

	CListCtrl* pChannelListC = (CListCtrl*)mpDlg->GetDlgItem( IDC_CHANNEL_LC );

	pChannelListC->SetItemText( mNumber, CHANNEL_AGENT, _T("ON") );

	return true;
}


bool cGameAgentNetwork::DisConnect( WPARAM wParam )
{
	if( cNetwork::DisConnect( wParam ) == false )
		return false;

	CListCtrl* pChannelListC = (CListCtrl*)mpDlg->GetDlgItem( IDC_CHANNEL_LC );

	pChannelListC->SetItemText( mNumber, CHANNEL_AGENT, _T("OFF") );

	return true;
}


void cGameAgentNetwork::Process()
{
	if( mIsConnect == false )
	{
		if( mConnectCheckTime > GetTickCount() )
			return;

		mConnectCheckTime = GetTickCount() + 1000;

		Connect();
	}
}


void cGameAgentNetwork::SendOn()
{
	MSGROOT sendMsg;
	sendMsg.Category = NM_SERVERTOOL;
	sendMsg.Protocol = NM_SERVERTOOL_CHANNEL_ON_REQ;

	Send( (char*)&sendMsg, sizeof(sendMsg) );
}


void cGameAgentNetwork::SendOff()
{
	MSGROOT sendMsg;
	sendMsg.Category = NM_SERVERTOOL;
	sendMsg.Protocol = NM_SERVERTOOL_CHANNEL_OFF_REQ;

	Send( (char*)&sendMsg, sizeof(sendMsg) );
}