Example #1
0
//-------------------------------------------------------------------------------------	
bool ClientApp::updateChannel(bool loginapp, std::string accountName, std::string passwd, 
								   std::string ip, KBEngine::uint32 port)
{
	if(pServerChannel_->pEndPoint())
	{
		pServerChannel_->stopSend();
		networkInterface().dispatcher().deregisterReadFileDescriptor(*pServerChannel_->pEndPoint());
		networkInterface().deregisterChannel(pServerChannel_);
	}

	bool ret = loginapp ? (initLoginappChannel(accountName, passwd, ip, port) != NULL) : (initBaseappChannel() != NULL);
	if(ret)
	{
		if(pTCPPacketReceiver_)
			pTCPPacketReceiver_->pEndPoint(pServerChannel_->pEndPoint());
		else
			pTCPPacketReceiver_ = new Network::TCPPacketReceiver(*pServerChannel_->pEndPoint(), networkInterface());

		if(pTCPPacketSender_)
			pTCPPacketSender_->pEndPoint(pServerChannel_->pEndPoint());
		else
			pTCPPacketSender_ = new Network::TCPPacketSender(*pServerChannel_->pEndPoint(), networkInterface());

		pServerChannel_->pPacketSender(pTCPPacketSender_);
		networkInterface().registerChannel(pServerChannel_);
		networkInterface().dispatcher().registerReadFileDescriptor(*pServerChannel_->pEndPoint(), pTCPPacketReceiver_);
	}

	return ret;
}
Example #2
0
//-------------------------------------------------------------------------------------	
bool ClientApp::login(std::string accountName, std::string passwd, 
								   std::string ip, KBEngine::uint32 port)
{
	connectedGateway_ = false;

	bool exist = false;
	
	if(canReset_)
		reset();

	if(pServerChannel_->endpoint())
	{
		lastAddr = pServerChannel_->endpoint()->addr();
		getNetworkInterface().dispatcher().deregisterFileDescriptor(*pServerChannel_->endpoint());
		exist = getNetworkInterface().findChannel(pServerChannel_->endpoint()->addr()) != NULL;
	}

	bool ret = initLoginappChannel(accountName, passwd, ip, port) != NULL;
	if(ret)
	{
		if(!exist)
		{
			getNetworkInterface().registerChannel(pServerChannel_);
			pTCPPacketReceiver_ = new Mercury::TCPPacketReceiver(*pServerChannel_->endpoint(), getNetworkInterface());
		}
		else
		{
			pTCPPacketReceiver_->endpoint(pServerChannel_->endpoint());
		}

		getNetworkInterface().dispatcher().registerFileDescriptor(*pServerChannel_->endpoint(), pTCPPacketReceiver_);
		
		// 先握手然后等helloCB之后再进行登录
		Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
		(*pBundle).newMessage(LoginappInterface::hello);
		(*pBundle) << KBEVersion::versionString();

		if(Mercury::g_channelExternalEncryptType == 1)
		{
			pBlowfishFilter_ = new Mercury::BlowfishFilter();
			(*pBundle).appendBlob(pBlowfishFilter_->key());
		}
		else
		{
			std::string key = "";
			(*pBundle).appendBlob(key);
		}

		pServerChannel_->pushBundle(pBundle);
		//ret = ClientObjectBase::login();
	}

	return ret;
}