@@ -23,6 +23,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2323#include " event.hpp"
2424#include " entity.hpp"
2525#include " config.hpp"
26+ #include " cstdkbe/kbeversion.hpp"
2627#include " network/channel.hpp"
2728#include " network/tcp_packet_receiver.hpp"
2829#include " thread/threadpool.hpp"
@@ -60,6 +61,7 @@ componentID_(componentID),
6061mainDispatcher_ (dispatcher),
6162networkInterface_ (ninterface),
6263pTCPPacketReceiver_ (NULL ),
64+ pBlowfishFilter_ (NULL ),
6365time_ (),
6466timers_ (),
6567threadPool_ (),
@@ -81,6 +83,7 @@ entryScript_()
8183// -------------------------------------------------------------------------------------
8284ClientApp::~ClientApp ()
8385{
86+ SAFE_RELEASE (pBlowfishFilter_);
8487}
8588
8689// -------------------------------------------------------------------------------------
@@ -388,7 +391,24 @@ bool ClientApp::login(std::string accountName, std::string passwd,
388391
389392 getNetworkInterface ().dispatcher ().registerFileDescriptor (*pServerChannel_->endpoint (), pTCPPacketReceiver_);
390393
391- ret = ClientObjectBase::login ();
394+ // 先握手然后等helloCB之后再进行登录
395+ Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool ().createObject ();
396+ (*pBundle).newMessage (LoginappInterface::hello);
397+ (*pBundle) << KBEVersion::versionString ();
398+
399+ if (Mercury::g_channelExternalEncryptType == 1 )
400+ {
401+ pBlowfishFilter_ = new Mercury::BlowfishFilter ();
402+ (*pBundle).appendBlob (pBlowfishFilter_->key ());
403+ }
404+ else
405+ {
406+ std::string key = " " ;
407+ (*pBundle).appendBlob (key);
408+ }
409+
410+ pServerChannel_->pushBundle (pBundle);
411+ // ret = ClientObjectBase::login();
392412 }
393413
394414 return ret;
@@ -398,6 +418,28 @@ bool ClientApp::login(std::string accountName, std::string passwd,
398418void ClientApp::onHelloCB_ (Mercury::Channel* pChannel, const std::string& verInfo,
399419 COMPONENT_TYPE componentType)
400420{
421+ if (Mercury::g_channelExternalEncryptType == 1 )
422+ {
423+ pServerChannel_->pFilter (pBlowfishFilter_);
424+ pBlowfishFilter_ = NULL ;
425+ }
426+
427+ if (componentType == LOGINAPP_TYPE )
428+ {
429+ if (!ClientObjectBase::login ())
430+ {
431+ WARNING_MSG (" ClientApp::onHelloCB_: login is failed!\n " );
432+ return ;
433+ }
434+ }
435+ else
436+ {
437+ if (!ClientObjectBase::loginGateWay ())
438+ {
439+ WARNING_MSG (" ClientApp::onHelloCB_: login is failed!\n " );
440+ return ;
441+ }
442+ }
401443}
402444
403445// -------------------------------------------------------------------------------------
@@ -430,7 +472,25 @@ void ClientApp::onLoginSuccessfully(Mercury::Channel * pChannel, MemoryStream& s
430472
431473 getNetworkInterface ().dispatcher ().registerFileDescriptor (*pServerChannel_->endpoint (), pTCPPacketReceiver_);
432474
433- ret = ClientObjectBase::loginGateWay ();
475+ // 先握手然后等helloCB之后再进行登录
476+ Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool ().createObject ();
477+ (*pBundle).newMessage (BaseappInterface::hello);
478+ (*pBundle) << KBEVersion::versionString ();
479+
480+ if (Mercury::g_channelExternalEncryptType == 1 )
481+ {
482+ pBlowfishFilter_ = new Mercury::BlowfishFilter ();
483+ (*pBundle).appendBlob (pBlowfishFilter_->key ());
484+ pServerChannel_->pFilter (NULL );
485+ }
486+ else
487+ {
488+ std::string key = " " ;
489+ (*pBundle).appendBlob (key);
490+ }
491+
492+ pServerChannel_->pushBundle (pBundle);
493+ // ret = ClientObjectBase::loginGateWay();
434494 }
435495}
436496
0 commit comments