示例#1
0
//--------------------------------------------------------------------------------------------
void TSessionManager::ConnectAsync( TIP_Port& ip_port, std::string& login, std::string& password, unsigned char subNet, ConnectResultCallback onResult )
{
  BL_ASSERT( flgNeedAnswerFromUp == false );

  mConnectResult = onResult;
  BeginWaitConnectUp();
  lockConnectUp();

  INetTransport* pTransport = mMngTransport->FindBySubNet( subNet );
  if( pTransport == nullptr )
  {
    unlockConnectUp();
    return mConnectResult( INVALID_HANDLE_SESSION );
  }

  if( mNavigateSession == nullptr )
  {
    unlockConnectUp();
    return mConnectResult( INVALID_HANDLE_SESSION );
  }
  //===================================================================
  // соединиться с сервером (верхнее соединение)
  if( pTransport->Connect( ip_port.ip, ip_port.port ) == false )
  {
    unlockConnectUp();
    return mConnectResult( INVALID_HANDLE_SESSION );// нет такого прослушивающего порта
  }// connect to event
  mIP_PortUp = ip_port; // запомнить параметры верхнего соединения

  TSession* pSession = mNavigateSession->FindSessionByIP( mIP_PortUp );
  if( pSession == nullptr )
    pSession = NewSession( mIP_PortUp, pTransport, true/*connect to*/ );
  else
  {
    unlockConnectUp();
    GetLogger( STR_NAME_MMO_ENGINE )->
      WriteF_time( "TSessionManager::Send(%s) sending to IP with exist session.\n", ip_port.ToString() );
    BL_FIX_BUG();
    return mConnectResult( INVALID_HANDLE_SESSION );
  }
  mSessionID_UP = pSession->GetID();
  pSession->SetLogin( login );
  pSession->SetPassword( password );
  pSession->SetState( TSession::StateWaitKeyAES );
  pSession->SendLogin();

  unlockConnectUp();
  // waiting recv...
}
示例#2
0
//-------------------------------------------------------------------------
void TSessionManager::Accept( unsigned int sessionID, std::string& password )
{
  if( mNavigateSession == nullptr )
  {
    BL_FIX_BUG();
    return;
  }
  TSession* pSession = mNavigateSession->FindSessionByID( sessionID );
  if( pSession == nullptr )
  {
    BL_FIX_BUG();
    return;
  }

  pSession->SetPassword( password );
  pSession->SetState( TSession::StateWaitConfirmation );
  pSession->SendKeyAES();
}