Пример #1
0
//================================================================================
// Returns if the memory should be considered as lost, ie:
// The entity does not exist, has died, is to be eliminated or 
// we have not received any update of it during the time limit of our memory.
//================================================================================
bool CEntityMemory::IsLost()
{
	if (GetEntity() == NULL || GetEntity()->IsMarkedForDeletion() || !GetEntity()->IsAlive())
		return true;

	return (GetTimeLeft() <= 0);
}
Пример #2
0
void ribi::gtst::ServerState::ResetTimeLeft()
{
    const int state_duration = GetStateDuration();
    assert(state_duration >= 0);
    this->SetTimeLeft(state_duration);
    assert(GetTimeLeft() >= -1); //-1 because of a possible clock tick
}
Пример #3
0
bool Client::Connect(Value& result)
{
    log_trace();
    if (socket_.IsConnected(0))
    {
        log_debug("Already connected");
        return true;
    }
    // Close the connection but keep any data that has been setup for the next message
    Close();
    ResetReceiveBuffer();

    log_debug("Create a new connection");
    socket_.Create();
    socket_.SetNonBlocking();

    socket_.Connect(host_.c_str(), port_);

    socket_.SetKeepAlive();
    socket_.SetTcpNoDelay();

    if (!socket_.IsConnected(GetTimeLeft()))
    {
        socket_.Close();
        return false;
    }
    return true;
}
Пример #4
0
bool Client::ReadHeader(Value& result)
{
    log_trace();
    // Read available data
    socket_.SetTimeout(0);
    while (true)
    {
        int bytesRead;
        bool eof;
        socket_.Receive(buffer_+bufferLength_, MaxBufferLength-bufferLength_, bytesRead, eof, 0);
        if (socket_.FatalError())
        {
            log_warn("error while reading header: " << socket_.GetLastError() << ", bytesRead=" << bytesRead);
            return false;
        }
        bufferLength_ += bytesRead;
        log_info("read=" << bytesRead << ", total=" << bufferLength_);

        switch (ProcessHeader(eof))
        {
            case HEADER_COMPLETE : return true;
            case HEADER_FAULT : return false;
        }
        unsigned timeLeft = GetTimeLeft();
        if (timeLeft == 0)
        {
            handler_->GenerateFaultResult(AnyRpcErrorTransportError,"Timeout reading response header",result);
            break;
        }
        socket_.WaitReadable(timeLeft);
    }
    return false;
}
Пример #5
0
wxString CMusikPlayer::GetTimeLeftStr()
{
	if(_CurrentSongIsNetStream())
	{
		return GetTimeStr();
	}
	else
		return SecToStr( GetTimeLeft( FMOD_SEC ) );
}
Пример #6
0
bool Client::WriteRequest(Value& result)
{
    log_trace();

    size_t bytesWritten;
    size_t bytesToSend;

    // write the header - it make be in several segments
    size_t headerBytesWritten = 0;
    while (headerBytesWritten < header_.Length())
    {
        const char* buffer = header_.GetBuffer(headerBytesWritten, bytesToSend);
        if (!socket_.Send(buffer, bytesToSend, bytesWritten, GetTimeLeft()))
            return false;

        headerBytesWritten += bytesWritten;

        if (bytesToSend < bytesWritten)
            return false;   // timeout
    }

    // write the request - it make be in several segments
    size_t requestBytesWritten = 0;
    while (requestBytesWritten < request_.Length())
    {
        const char* buffer = request_.GetBuffer(requestBytesWritten, bytesToSend);
        if (!socket_.Send(buffer, bytesToSend, bytesWritten, GetTimeLeft()))
            return false;

        requestBytesWritten += bytesWritten;

        if (bytesToSend < bytesWritten)
            return false;   // timeout
    }

    return true;
}
Пример #7
0
void CGameControllerCSBB::Tick()
{
	IGameController::Tick();

	
	if(GameServer()->m_World.m_ResetRequested || GameServer()->m_World.m_Paused)
		return;	

	m_RoundTick++;
		
	// no actual players (bots kicked if human_players == 0)
	if (CountPlayers() < 1 || m_NewGame)
	{
		GameServer()->m_CanRespawn = true;
	
		if (m_Round != 0 || m_GameState != CSBB_NEWBASE)
			Restart();
		
		m_RoundTick = 0;
	}
	else
	{
		if (CountPlayers() == 1)
		{
			Restart();
			AutoBalance();
			return;
		}
		
		AutoBalance();
		
		if (m_GameState == CSBB_NEWBASE)
		{
			CaptureBase();
			
			if (GameServer()->m_pArrow)
			{
				GameServer()->m_pArrow->m_Hide = false;
				GameServer()->m_pArrow->m_Target = m_apBombArea[m_Base]->m_Pos;
			}
		}
		if (m_GameState == CSBB_DEFENDING)
		{

			if (GameServer()->m_pArrow)
			{
				GameServer()->m_pArrow->m_Hide = false;
				GameServer()->m_pArrow->m_Target = m_apBombArea[m_Base]->m_Pos;
			}
			
			RoundWinLose();
		}
		if (m_GameState == CSBB_ENDING)
		{
			if (m_RoundTick >= g_Config.m_SvPreroundTime*Server()->TickSpeed())
			{
				if (m_aTeamscore[TEAM_RED] >= g_Config.m_SvNumRounds || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvNumRounds)
				{
					EndRound();
					m_NewGame = true;
					return;
				}
				
				NewBase();
				//AutoBalance();
				
				if (GameServer()->m_pArrow)
					GameServer()->m_pArrow->m_Hide = true;
				

			}
		}
	}
	
	
	
	


	GameServer()->UpdateAI();

	

	// warm welcome
	for (int c = 0; c < MAX_CLIENTS; c++)
	{
		CPlayer *pPlayer = GameServer()->m_apPlayers[c];
		if(!pPlayer)
			continue;
		
		if (!pPlayer->m_Welcomed && !pPlayer->m_IsBot)
		{
			GameServer()->SendBroadcast("Welcome to Counter-Strike: Base Bombing", pPlayer->GetCID(), true);
			pPlayer->m_Welcomed = true;
		}
	}
	
	
	
	
	// the bomb (red flag)
	CBomb *B = m_pBomb;
	
	if (!B)
		return;
	
	
	
	/*
	// always update bomb position
	if(B->m_pCarryingCharacter)
	{
		B->m_Pos = B->m_pCarryingCharacter->m_Pos;
	}
	else
	{
		if (B->m_Status == BOMB_CARRYING || B->m_Status == BOMB_IDLE)
		{
			B->m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
			GameServer()->Collision()->MoveBox(&B->m_Pos, &B->m_Vel, vec2(B->ms_PhysSize, B->ms_PhysSize), 0.5f);
			B->m_Status = BOMB_IDLE;
		}
	}
	*/
	
	
	if (m_Timeout || m_BombDefused || m_GameState != CSBB_DEFENDING)
		return;

	
	if (B->m_Status == BOMB_PLANTED)
	{
		B->m_Timer++;
		
		// bomb ticking sound
		int Time = Server()->TickSpeed();
		
		if (Server()->TickSpeed() / 30 + GetTimeLeft()*8 < Time)
			Time = Server()->TickSpeed() / 20 + GetTimeLeft()*4;
		
		if (++m_BombSoundTimer >= Time)
		{
			m_BombSoundTimer = 0;
			GameServer()->CreateSound(B->m_Pos, SOUND_CHAT_SERVER);
			GameServer()->CreateSound(B->m_Pos, SOUND_CHAT_SERVER);
		}
		
		// bomb defusing
		//CCharacter *apCloseCCharacters[MAX_CLIENTS];
		//int Num = GameServer()->m_World.FindEntities(B->m_Pos, CFlag::ms_PhysSize * 2, (CEntity**)apCloseCCharacters, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
		
		bool DefusingBomb = false;
		
		for (int i = 0; i < MAX_CLIENTS; i++)
		{
			CPlayer *pPlayer = GameServer()->m_apPlayers[i];
			if(!pPlayer)
				continue;

			CCharacter *pCharacter = pPlayer->GetCharacter();
			if (!pCharacter)
				continue;
		
			if(!pCharacter->IsAlive() || pPlayer->GetTeam() != m_DefendingTeam)
				continue;
			
			// check distance
			if (abs(pCharacter->m_Pos.x - B->m_Pos.x) < 150 && abs(pCharacter->m_Pos.y - B->m_Pos.y) < 150 &&
				pCharacter->IsGrounded())
			{
				DefusingBomb = true;
				m_aDefusing[i] = true;
				
				pPlayer->m_InterestPoints += 7;
							
				if (m_BombDefuseTimer == 0)
				{
					GameServer()->SendBroadcast("Defusing bomb", pPlayer->GetCID());
					//GameServer()->CreateSoundGlobal(SOUND_CTF_DROP, pPlayer->GetCID());
				}
			}
			else
			{
				if (m_aDefusing[i])
				{
					m_aDefusing[i] = false;
					GameServer()->SendBroadcast("", pPlayer->GetCID());
				}
			}
		}
		
		if (DefusingBomb)
		{
			// bomb defusing sound
			if (++m_BombActionTimer >= Server()->TickSpeed()/4)
			{
				m_BombActionTimer = 0;
				GameServer()->CreateSound(B->m_Pos, SOUND_BODY_LAND);
			}
			
			if (++m_BombDefuseTimer >= g_Config.m_SvBombDefuseTime*Server()->TickSpeed())
			{
				B->m_Hide = true;
				m_BombDefused = true;
				if (m_DefendingTeam == TEAM_RED)
					GameServer()->SendBroadcast("Bomb defused - Terrorists score!", -1, true);
				if (m_DefendingTeam == TEAM_BLUE)
					GameServer()->SendBroadcast("Bomb defused - Counter-terrorists score!", -1, true);
				GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_PL, -1);
							
				m_RoundTimeLimit = 0; // gamecontroller
				m_ResetTime = true; // gamecontroller
			}
		}
		else
		{
			m_BombDefuseTimer = 0;
		}
		
		return;
	}
	else
	{
		for (int c = 0; c < MAX_CLIENTS; c++)
		{
			bool BombPlantable = false;
			CPlayer *pPlayer = GameServer()->m_apPlayers[c];
			if(!pPlayer)
				continue;
			
			if(pPlayer->GetTeam() == m_DefendingTeam)
				continue;

			CCharacter *pCharacter = pPlayer->GetCharacter();
			if (!pCharacter)
				continue;
		
			if(!pCharacter->IsAlive() || pPlayer->GetTeam() == m_DefendingTeam)
				continue;
				
			if (m_Base >= 0)
			{
				if (m_apBombArea[m_Base] && !m_apBombArea[m_Base]->m_Hide)
				{
					
					// check distance
					if (abs(m_apBombArea[m_Base]->m_Pos.x - pCharacter->m_Pos.x) < 200 && abs(m_apBombArea[m_Base]->m_Pos.y - pCharacter->m_Pos.y) < 200 &&
						pCharacter->IsGrounded())
					{
						BombPlantable = true;
						//GameServer()->SendBroadcast("Inside range", pPlayer->GetCID());
						
						if (pCharacter->m_BombStatus != BOMB_PLANTING)
						{
							pCharacter->m_BombStatus = BOMB_PLANTING;
							m_aPlanting[c] = 0;
							
							GameServer()->SendBroadcast("Planting bomb", pPlayer->GetCID());
						}
						else if (pCharacter->m_BombStatus == BOMB_PLANTING)
						{
							// bomb planting sound
							if (++m_aBombActionTimer[c] >= Server()->TickSpeed()/4)
							{
								m_aBombActionTimer[c] = 0;
								GameServer()->CreateSound(B->m_Pos, SOUND_BODY_LAND);
							}
							
							pPlayer->m_InterestPoints += 6;
							
							if (++m_aPlanting[c] >= g_Config.m_SvBombPlantTime*Server()->TickSpeed())
							{
								pPlayer->m_InterestPoints += 120;
								
								B->m_pCarryingCharacter = NULL;
								B->m_Status = BOMB_PLANTED;
								pCharacter->m_BombStatus = BOMB_PLANTED;
								m_aPlanting[c] = 0;
								B->m_Timer = 0;
								GameServer()->SendBroadcast("Bomb planted!", -1, true);
								GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_PL, -1);
								
								B->m_Hide = false;
								B->m_Pos = pCharacter->m_Pos;
								B->m_Owner = c;
								
								m_RoundTimeLimit = g_Config.m_SvBombTime; // gamecontroller
								m_ResetTime = true; // gamecontroller
								
								return;
							}
						}
					}
				}
			}
			
			if (!BombPlantable)
			{
				pCharacter->m_BombStatus = BOMB_CARRYING;
				if (m_aPlanting[c] > 0)
					GameServer()->SendBroadcast("", c);
				
				m_aPlanting[c] = 0;
			}
		}
	}


	// don't add anything relevant here! possible return; above!
}
//---------------------------------------------------------------------------
bool ServerStateGroupReAssign::CanGoToNextState() const
{
  return GetTimeLeft() < 0;
}
Пример #9
0
void SetStatusStatus(void)
{
  char        szStatusStatusLine[MAX_BUF_MEDIUM];
  char        szCurrentStatusInfo[MAX_BUF_MEDIUM];
  char        szPercentString[MAX_BUF_MEDIUM];
  char        szPercentageCompleted[MAX_BUF_MEDIUM];
  static long lModLastValue = 0;
  double        dRate;
  static double dRateCounter;
  DWORD         dwTickNow;
  DWORD         dwTickDif;
  DWORD         dwKBytesSoFar;
  DWORD         dwRoundedRate;
  char          szTimeLeft[MAX_BUF_TINY];

  /* If the user just clicked on the Resume button, then the time lapsed
   * between gdwTickStart and when the Resume button was clicked needs to
   * be subtracted taken into account when calculating dwTickDif.  So
   * "this" lapsed time needs to be added to gdwTickStart. */
  if(gtiPaused.bTickDownloadResumed)
  {
    gdwTickStart = AddToTick(gdwTickStart, gtiPaused.dwTickDif);
    InitTickInfo();
  }

  /* GetTickCount() returns time in milliseconds.  This is more accurate,
   * which will allow us to get at a 2 decimal precision value for the
   * download rate. */
  dwTickNow = GetTickCount();
  if((gdwTickStart == 0) && gbStartTickCounter)
    dwTickNow = gdwTickStart = GetTickCount();

  dwTickDif = GetTickDif(dwTickNow, gdwTickStart);

  /* Only update the UI every UPDATE_INTERVAL_STATUS interval,
   * which is currently set to 1 sec. */
  if(!CheckInterval(&lModLastValue, UPDATE_INTERVAL_STATUS))
    return;

  if(glAbsoluteBytesSoFar == 0)
    dRateCounter = 0.0;
  else
    dRateCounter = dwTickDif / 1000;

  if(dRateCounter == 0.0)
    dRate = 0.0;
  else
    dRate = (glAbsoluteBytesSoFar - glBytesResumedFrom) / dRateCounter / 1024;

  dwKBytesSoFar = glAbsoluteBytesSoFar / 1024;

  /* Use a rate that is rounded to the nearest integer.  If dRate used directly,
   * the "Time Left" will jump around quite a bit due to the rate usually 
   * varying up and down by quite a bit. The rounded rate give a "more linear"
   * count down of the "Time Left". */
  dwRoundedRate = RoundDouble(dRate);
  if(dwRoundedRate > 0)
    GetTimeLeft((glTotalKb - dwKBytesSoFar) / dwRoundedRate,
                 szTimeLeft,
                 sizeof(szTimeLeft));
  else
    lstrcpy(szTimeLeft, "00:00:00");

  if(!gbShowDownloadRetryMsg)
  {
    GetConfigIniProfileString("Strings", "Status Download", "",
                            szStatusStatusLine, sizeof(szStatusStatusLine));
    if(*szStatusStatusLine != '\0')
      sprintf(szCurrentStatusInfo,
              szStatusStatusLine,
              szTimeLeft,
              dRate,
              dwKBytesSoFar,
              glTotalKb);
    else
      sprintf(szCurrentStatusInfo,
              "%s at %.2fKB/sec (%uKB of %uKB downloaded)",
              szTimeLeft,
              dRate,
              dwKBytesSoFar,
              glTotalKb);
  }
  else
  {
    GetConfigIniProfileString("Strings", "Status Retry", "",
			      szStatusStatusLine, sizeof(szStatusStatusLine));
    if(*szStatusStatusLine != '\0')
      sprintf(szCurrentStatusInfo,
              szStatusStatusLine,
              szTimeLeft,
              dRate,
              dwKBytesSoFar,
              glTotalKb);
    else
      sprintf(szCurrentStatusInfo,
              "%s at %.2KB/sec (%uKB of %uKB downloaded)",
              szTimeLeft,
              dRate,
              dwKBytesSoFar,
              glTotalKb);
  }

  GetConfigIniProfileString("Strings", "Status Percentage Completed", "",
			    szPercentageCompleted, sizeof(szPercentageCompleted));
  wsprintf(szPercentString, szPercentageCompleted, (int)GetPercentSoFar());

  /* Set the download dialog title */
  SetDlgItemText(dlgInfo.hWndDlg, IDC_STATUS_STATUS, szCurrentStatusInfo);
  SetDlgItemText(dlgInfo.hWndDlg, IDC_PERCENTAGE, szPercentString);
}
Пример #10
0
BOOL CHTTPClient::SendSSLRequest(char *szHost,
    char *szHostName,
    char *szPath,
    char *szUserID,
    char *szPassword,
    long lPort,
    char *szProxy,
    long lProxyPort,
    char *szProxyUser,
    char *szProxyPswd,
    char *szUserAgent,
    char *szPost,
    long dwTimeout,
    SSL **pssl,
    SSL_CTX **pssl_ctx,
    char *szTransaction)
{
    char *szConnectHost;
    char *szConnectionHeader = "Connection: close\r\n";
    char *szContentLength = "Content-Length: %d\r\n";
    char *szContentType = "Content-Type: application/x-www-form-urlencoded\r\n";
    char *szProxyConn = "Proxy-Connection: Keep-Alive\r\n";
    char *szPragma = "Pragma: no-cache\r\n";
    long lConnectPort;
    char *szBuffer = szSendBuffer;
    char szWork[256];
    char *lpWork;
    char *szGetMethod = "GET";
    char *szPostMethod = "POST";
    char *szMethod;
    BOOL RC = TRUE;
    BOOL bBIOset = FALSE;

    Base64Coder cBase64Coder;

    BIO *bio = 0;
    int done = 0, i, n;
    char buf[2048];

    // Got to have a host
    if (!szHost)
        return(FALSE);

    // Initialize strings used for cookies
    cDomain = szHostName;
    cPath = szPath;
    if (szTransaction)
        cTransaction = szTransaction;
    else
        cTransaction = "";

    // Clean up ssl storage
    try
    {
        if (ssl)
        {
            SSL_free(ssl);
            ssl = 0;
        }
    }
    catch(...)
    {
        ssl = 0;
    }

    try
    {

        // Initialise the ssl library now in rtm startup 

        // Create the context structure. Operate in the normal default SSLv3
        // in a SSLv2 header mode to maximize the number of servers
        // we can connect to.
        if (!ssl_ctx)
        {
            if (!pssl_ctx || !*pssl_ctx)
            {
                if ((ssl_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
                {
                    bConnectFailed = TRUE;
                    throw FALSE;
                }
            }
            else
                ssl_ctx = *pssl_ctx;
        }

        // Reset variables for response
        bHeader = FALSE;
        bReadComplete = FALSE;
        bHeadRequest = FALSE;
        lReceivedLength = 0;
        lContentLength = 0;
        cHeader = "";
        cContent = "";

        // turn on all vendor bug compatibility options
        SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);

        // Create the SSL structure - defaults are inherited from the SSL_CTX
        if ((ssl = SSL_new(ssl_ctx)) == NULL)
        {
            bConnectFailed = TRUE;
            throw FALSE;
        };

        // Set as client side
        SSL_set_connect_state(ssl);

        if (!szProxy)
        {
            // No proxy
            szConnectHost = szHost;
            lConnectPort = lPort;
        }
        else
        {
            // Proxy
            szConnectHost = szProxy;
            lConnectPort = lProxyPort;
        };

        sprintf(szWork, "%s:%u", szConnectHost, (unsigned int) lConnectPort);

        // Create a BIO to handle the connect and SSL handling
        if ((bio = BIO_new_connect(szWork)) == NULL)
        {
            bConnectFailed = TRUE;
            throw FALSE;
        };

        // If using proxy then have to tunnel through to the actual ssl server
        if (szProxy)
        {
            sprintf(szBuffer, "CONNECT %s:%u HTTP/1.0\r\nUser-Agent: %s\r\n", szHostName, (unsigned int) lPort, szUserAgent);

            if (szProxyUser && szProxyPswd && strlen(szProxyUser) > 0 && strlen(szProxyPswd) > 0)
            {
                sprintf(szWork, "%s:%s", szProxyUser, szProxyPswd);
                cBase64Coder.Encode(szWork);
                sprintf(szWork, "Proxy-Authorization: Basic %s\r\n", (LPCTSTR) cBase64Coder.EncodedMessage());
                strcat(szBuffer, szWork);
            }
            strcat(szBuffer, szProxyConn);
            strcat(szBuffer, szPragma);
            strcat(szBuffer, "\r\n");

            // Send connect request
            n = strlen(szBuffer);
            i = 0;
            do
            {
                i = BIO_write(bio, &(szBuffer[i]), n);
                if (i <= 0)
                {
                    bConnectFailed = TRUE;
                    BIO_free(bio);
                    throw FALSE;
                }
                n -= i;
            }
            while(n > 0);

            // Read response from proxy
            i = BIO_read(bio, buf, sizeof(buf));
            if (i <= 0)
            {
                bConnectFailed = TRUE;
                BIO_free(bio);
                throw FALSE;
            };

            buf[i] = '\0';
            lpWork = strstr(buf, "200");
            if (!lpWork)
            {
                bConnectFailed = TRUE;
                BIO_free(bio);
                throw FALSE;
            };

        };

        // Use the newly created connect BIO
        SSL_set_bio(ssl, bio, bio);
        bBIOset = TRUE;
        if (pSession && pssl)
        {
            SSL_set_session(ssl, pSession);
        }
        else
        {
            while(!done)
            {
                int i;
                struct tm *ptr;
                time_t lt;

                lt = time(NULL);

                PROTECT_CALL
                ptr = localtime(&lt);
                char *pszTime = asctime(ptr);
                RAND_seed((unsigned char *) pszTime, strlen(pszTime));
                UNPROTECT_CALL

                // The all important handshake
                i = SSL_do_handshake(ssl);

                switch(SSL_get_error(ssl, i))
                {
                    case SSL_ERROR_NONE: // Handshake has finished, so proceed
                        done = 1;
                        break;
                    case SSL_ERROR_WANT_READ:
                    case SSL_ERROR_WANT_WRITE:
                    case SSL_ERROR_WANT_CONNECT:
                        // Perform the handshake again. 
                        sleep(1);
                        break;
                    default:
                        bConnectFailed = TRUE;
                        throw FALSE;
                        break;
                };
            };
            pSession = SSL_get_session(ssl);
        };

        if (szPost)
            szMethod = szPostMethod;
        else
            szMethod = szGetMethod;

        // Build the request
        sprintf(szBuffer, "%s %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\n", szMethod, szPath, szUserAgent, szHostName);

        if (szUserID)
        {
            sprintf(szWork, "%s:%s", szUserID, szPassword);
            cBase64Coder.Encode(szWork);
            sprintf(szWork, "Authorization: Basic %s\r\n", (LPCTSTR) cBase64Coder.EncodedMessage());
            strcat(szBuffer, szWork);
        }

        if (szPost)
        {
            strcat(szBuffer, szContentType);
            sprintf(szWork, szContentLength, strlen(szPost));
            strcat(szBuffer, szWork);
            strcat(szBuffer, szProxyConn);
            strcat(szBuffer, szPragma);
        }
        else
        {
            strcat(szBuffer, szConnectionHeader);
        }

        if (!cTransaction.empty())
            SendCookie(szBuffer);

        // Indicate end of header
        strcat(szBuffer, "\r\n");

        sDebugSendHeader = szBuffer;

        if (szPost)
            strcat(szBuffer, szPost);

        dwStartTime = ::XPlatGetMilliseconds();

        // Send request
        n = strlen(szBuffer);
        i = 0;
        do
        {
            i = SSL_write(ssl, &(szBuffer[i]), n);
            if (i <= 0)
            {
                bConnectFailed = FALSE;
                throw FALSE;
            }
            n -= i;
        }
        while(n > 0);

        // Read from the other side of the protocol
        while(1)
        {
            i = SSL_read(ssl, buf, sizeof(buf));
            if (i <= 0)
                break;

            ProcessData((unsigned char *) buf, i);

            if (!GetTimeLeft(dwTimeout, dwStartTime))
            {
                // Timed out
                bConnectFailed = FALSE;
                throw FALSE;
            };
        };
        if (szPost && !strcmp(szStatus, "100"))
        {
            printf("status 100");
            strcat(szBuffer, szPost);
            // Reset variables for response
            bHeader = FALSE;
            bReadComplete = FALSE;
            bHeadRequest = FALSE;
            lReceivedLength = 0;
            lContentLength = 0;
            cHeader = "";
            cContent = "";


            // Send request
            n = strlen(szBuffer);
            i = 0;
            do
            {
                i = SSL_write(ssl, &(szBuffer[i]), n);
                if (i <= 0)
                {
                    bConnectFailed = FALSE;
                    throw FALSE;
                }
                n -= i;
            }
            while(n > 0);

            // Read from the other side of the protocol
            while(1)
            {
                i = SSL_read(ssl, buf, sizeof(buf));
                if (i <= 0)
                    break;

                ProcessData((unsigned char *) buf, i);

                if (!GetTimeLeft(dwTimeout, dwStartTime))
                {
                    // Timed out
                    bConnectFailed = FALSE;
                    throw FALSE;
                };
            };
        };
        Disconnected();
        throw TRUE;
    }

    catch(BOOL rc)
    {
        RC = rc;

    }

    catch(...)
    {
        RC = FALSE;
        if (!bBIOset && bio)
        {
            try
            {
                BIO_free(bio);
            }
            catch(...)
            {
            }
        }
    }

    if (pssl && pssl_ctx)
    {
        if (*pssl == 0)
        {
            *pssl = ssl;
            *pssl_ctx = ssl_ctx;
            ssl = 0;
        }
        ssl_ctx = 0;
    }

    return RC;

};
Пример #11
0
bool Client::ReadResponse(Value& result)
{
    log_trace();
    if (contentAvail_ >= contentLength_)
        return true;

    int bytesRead;
    bool eof;
    bool receiveResult = socket_.Receive(response_+contentAvail_, contentLength_-contentAvail_, bytesRead, eof, GetTimeLeft());
    contentAvail_ += bytesRead;
    if(response_)
    	response_[contentAvail_] = 0;
    if (!receiveResult)
        handler_->GenerateFaultResult(AnyRpcErrorTransportError,"Failed reading response",result);
    return receiveResult;
}
///Check if this state can go to the next state.1
bool ribi::gtst::ServerStateViewResultsVoting::CanGoToNextState() const
{
  return GetTimeLeft() < 0;
}
Пример #13
0
std::string Dynacoe::Clock::GetInfo() {
	return (Chain() << "Time Left: " << GetTimeLeft() << " ms");
}
Пример #14
0
void Dynacoe::Clock::OnDraw() {
	if (!GetHost() || IsExpired()) return;
	float ratio = lastDuration < 0 ? 1.f : GetTimeLeft() / float (lastDuration);
	std::string data = (Chain() << ratio);
	EmitEvent("clock-draw");
}
//---------------------------------------------------------------------------
///Check if this state can go to the next state.
bool ribi::gtst::ServerStateChat::CanGoToNextState() const
{
  return GetTimeLeft() < 0;
}