//-----------------------------------------------------------------------------
void TScLoginClient_ClientImpl::TryLogin(unsigned int ip, unsigned short port, unsigned char subNet,
                                         void* pLogin, int sizeLogin, void* pPassword, int sizePassword)
{
	if(Begin()==false)
  {
    // генерация ошибки
    GetLogger(STR_NAME_MMO_ENGINE)->
      WriteF_time("TScenarioLoginClient::TryLogin() scenario is not active.\n");
    BL_FIX_BUG();
    return;
  }
  Context()->SetNeedLeaveQueue(false);
  Context()->SetSubNet(subNet);

  TContainer cMITM;
  TBreakPacket bpLP;// контейнер для всего пакета
  if(Context()->GetMS()->GetUseCryptTCP())
  {
    // если данные шифруются, то формировать так:
    // получить RSA public key от ManagerSession
    TContainer cRSA;
    bool resRSA = Context()->GetMS()->GetRSAPublicKeyForUp(cRSA);
    BL_ASSERT(resRSA);
    TCryptMITM cryptMITM;
    bool res = cryptMITM.Calc(cRSA.GetPtr(), cRSA.GetSize(),
      pLogin, sizeLogin, pPassword, sizePassword, cMITM);
    BL_ASSERT(res);

    bpLP.PushFront(cMITM.GetPtr(), cMITM.GetSize());
		// сохранить на будущее
		Context()->Set_L_AES_RSA(cMITM.GetPtr(), cMITM.GetSize());
  }
  else
  {
    // иначе просто отправить данные:
    // формирование пакета
    bpLP.PushFront((char*)pLogin,    sizeLogin);
    bpLP.PushFront((char*)pPassword, sizePassword);
  }
  THeaderTryLoginC2M h;
  bpLP.PushFront((char*)&h, sizeof(h));

  // отослать пакет для попытки авторизации
  SetID_SessionClientMaster(Context()->GetMS()->Send(ip, port, bpLP, subNet));
  if(GetID_SessionClientMaster()==INVALID_HANDLE_SESSION)
  {
    // Генерация ошибки
    TEventError event;
    event.code = LoginClient_ClientMasterNotReady;
    Context()->GetSE()->AddEventCopy(&event, sizeof(event));
    End();
    return;
  }
  
  SetTimeWaitForNow();
}
Пример #2
0
int main(int argc, char **argv)
{
  // 3EB92D12773E8BF8061AFF68D5C187CEAA8DBFB7
  TLoadFromFile loader;
  bool res = loader.ReOpen("d:\\dbltj\\загадка.txt");
  //bool res = loader.ReOpen("d:\\dbltj\\Virtual Zeppelin-The Lemon Song.flv");
  if(res==false)
    return 1;
  unsigned char bufferFile[BUFSIZE];

  TSHA256 md5;
  md5.Begin();
  //------------------------------------------------
  unsigned int size = loader.Size();
  for( unsigned int i = 0 ; i < size ;  )
  {
    int sizeRead = loader.Read(bufferFile, BUFSIZE, i);
    i += sizeRead;
    md5.Calc(bufferFile, sizeRead);
  }
  // Помещаем вычисленный хэш в буфер md_buf
  TContainer result;
  md5.End(result);
  //------------------------------------------------
  // Отображаем результат
  for( int i = 0; i < result.GetSize(); i++) 
    printf("%02x", ((unsigned char*)result.GetPtr())[i]);
  return 0;
} 
Пример #3
0
//---------------------------------------------------------------------
void TSession::SendKeyRSA(TContainer& c_keyRSA)
{
  TBreakPacket bp;
  bp.PushFront((char*)c_keyRSA.GetPtr(), c_keyRSA.GetSize());

  SendData(eKeyRSA, bp, true);
  RefreshLastTime();
}
Пример #4
0
//----------------------------------------------------------------------------------
TContainer TBasePacket_PCS::Pack()
{
  TBreakPacket bp;
  bp.PushBack( (char*)&mType, sizeof(mType));
  TContainer fromInherit = PackInherit();
  bp.PushBack( fromInherit.GetPtr(), fromInherit.GetSize() );
  bp.Collect();
  TContainer result;
  result.Entrust( (char*)bp.GetCollectPtr(), bp.GetSize() );
  bp.UnlinkCollect();
  return result;
}
Пример #5
0
//-------------------------------------------------------------------------
bool TBaseServer::IsSessionSecurity(unsigned int id_session, void* crypt, int size_crypt, 
                                    void* pLogin, int sizeLogin, void* pPassword, int sizePassword)
{
  TContainer cRSA;
  // получить по сессии RSA от транспорта
  if(mManagerSession->GetRSAPublicKey(id_session, cRSA)==false)
    return false;

  TCryptMITM cryptMITM;
  TContainer cMITM;
  if(cryptMITM.Calc(cRSA.GetPtr(), cRSA.GetSize(),
    pLogin, sizeLogin, pPassword, sizePassword, cMITM)==false)
    return false;
  // сравнить по размеру
  if(size_crypt!=cMITM.GetSize())
    return false;
  // сравнить по содержимому
  if(memcmp(crypt, cMITM.GetPtr(), size_crypt)!=0)
    return false;

  return true;
}
Пример #6
0
//----------------------------------------------------------------------------------
void TBasePacket_PCS::Unpack(TContainer c)
{
  char* p  = c.GetPtr()  + sizeof(mType);
  int size = c.GetSize() - sizeof(mType);
  UnpackInherit(p, size);
}
Пример #7
0
//-------------------------------------------------------------------
int main(int argc, char** argv)
{
#if 0
  // внутри MMOEngine
  nsMMOEngine::TEventTryLogin erfd;
  erfd.id_session = 1;
  erfd.sizeData   = 100;
  TContainer* pC  = new TContainer;
  pC->SetData(NULL, sizeof(nsMMOEngine::TEventTryLogin) + erfd.sizeData);
  memcpy(pC->GetPtr(), &erfd, sizeof(nsMMOEngine::TEventTryLogin));
  // внутри DeveloperDLL
  nsMMOEngine::TBaseEvent* pBE = (nsMMOEngine::TBaseEvent*)pC->GetPtr();
  switch(pBE->mType)
  {
    case nsMMOEngine::TBase::eTryLogin:
    {
      nsMMOEngine::TEventTryLogin* pERFD = (nsMMOEngine::TEventTryLogin*)pBE;
      break;
    }
    default:;
  }
  delete pC;
#endif
    g_ShareTest->Init("Client");

	TArgData d;
	GetByArg(argc,argv,d);
	printf("port=%u,TimeSleep=%d,cnt=%d\n",d.port_client, d.time_sleep, d.cnt);

  INetTransport* pNetTransport = g_ShareTest->GetTransport();

  bool res = pNetTransport->Open(d.port_client);
  g_ShareTest->Register();

	pNetTransport->Start();

  TBreakPacket packetForSend;
	if(pNetTransport->Connect(d.ip, TShareTest::ePortServer))
	{
		unsigned int start = ht_GetMSCount();
		for(int i = 0 ; i < TShareTest::eCntRecvPacket ;)
		{
			for(int j = 0 ; j < d.cnt ; j++ )
			{
        packetForSend.UnlinkPart();
        packetForSend.PushFront(g_ShareTest->GetPacket(), TShareTest::eSizePacket);
        pNetTransport->Send(d.ip, TShareTest::ePortServer, packetForSend, true);
				i++;
				if(i==TShareTest::eCntRecvPacket)
					break;
			}
			ht_msleep(d.time_sleep);
      if(g_ShareTest->IsDisconnect())
        break;
		}
		start = ht_GetMSCount() - start;
    printf("time=%d ms, v=%f \n",
      start,float(TShareTest::eSizePacket*TShareTest::eCntRecvPacket)/(start*1000));
	}
  pNetTransport->Close(d.ip,TShareTest::ePortServer);
	pNetTransport->Stop();
  BL_ASSERT(pNetTransport->IsActive()==false);
  g_ShareTest->Unregister();

  //_getch();
  return 0;
}