Ejemplo n.º 1
0
HX_RESULT	
CAsyncNetThread::DetachSocket(ThreadedConn* pSocket)
{
    HX_RESULT theErr = HXR_OK;

    //	Preliminary checks
    HX_ASSERT(this);
    HX_ASSERT(pSocket);

    //	Bail on bad input
    if (!this || !pSocket)
    {
	theErr = HXR_FAIL;
	goto exit;
    }

    if (m_ClientSocketsMap)
    {
	if (m_ClientSocketsMap->RemoveKey((void*)pSocket))
	{
	    pSocket->Release();
	    DecrementSocketsClientCount();
	}
    }

    CheckClients();

exit:
    return theErr;
}
Ejemplo n.º 2
0
void CServer::Think()
{
   int i;

   UpdateMsec(); // calculate the msec value
   CheckClients(); // check and update our client list

   BotManager()->Think();
   World()->Think();

   for (i = 0; i < GetMaxClients(); i++) {
      if (m_rgpClients[i] != NULL) {
         // check if this client is a bot
         CBaseBot *pBot = m_rgpClients[i]->GetBotPointer();
         if (pBot) {
            // this is a bot...
            pBot->BotThink(); // call its think function to make it run
         }
      }
   }
}
Ejemplo n.º 3
0
//	Message handler for PWM_ASYNC_DNS
//	Notifies the client win_net object that DNS has completed or
//	returned w/ an error.
LRESULT CAsyncSockN::OnAsyncDNS(WPARAM wParam, LPARAM lParam)
{
    void*	    handle	= (void*) (HANDLE) wParam;
    void*	    pVoid	= 0;
    win_net*	    pClient	= 0;
    DNS_REQUEST*    pDNSRequest	= NULL;

    // Bail if the client map has been previously deleted, this
    // is a sure sign of us already being cleaned up!
    if(!m_ClientHandlesMap)
    {
	return(TRUE);
    }

    DEBUGOUTSTR( "AsyncDNS come back\r\n" );

    // Based on the handle returned, find our client!
    // Note it might be missing from the map if we canceled
    // the DNS!
    if (m_ClientHandlesMap->Lookup(handle, pVoid))
    {
	*((ULONG32 *)&pClient) = (ULONG32)pVoid;

	// We should already have an async operation active on this socket!
#ifdef _DEBUG
	if ((void *)pClient->m_hAsyncHandle != handle)
	{
	    char szMessage[256]; /* Flawfinder: ignore */
	    sprintf(szMessage,"pClient->m_hAsyncHandle = %#lx\nhandle = %#lx", /* Flawfinder: ignore */
				pClient->m_hAsyncHandle,
				handle
			    );
	    MessageBox(NULL,szMessage,"Oops!",MB_OK);
	}
	HX_ASSERT((void *)pClient->m_hAsyncHandle == handle);
#endif

	// Tell win_net object to forget the Async handle
	pClient->m_hAsyncHandle = NULL;

	pClient->CB_DNSComplete(!WSAGETASYNCERROR(lParam));

	// If async DNS is done, then we can forget the Async handle
	if (m_ClientHandlesMap->RemoveKey(handle))
	{
	    DecrementHandlesClientCount();
	}
    }

#ifdef _DEBUG
    if (m_ClientHandlesMap->GetCount() != m_cbNumHandlesClients)
    {
	char szMessage[256]; /* Flawfinder: ignore */
	sprintf(szMessage,"m_ClientHandlesMap->GetCount() = %d\nm_cbNumHandlesClients = %d", /* Flawfinder: ignore */
			    m_ClientHandlesMap->GetCount(),
			    m_cbNumHandlesClients
			);
	MessageBox(NULL,szMessage,"Oops!",MB_OK);
    }
    HX_ASSERT(m_ClientHandlesMap->GetCount() == m_cbNumHandlesClients);
#endif

    if (sockGlobals.m_bWinSock2Suck)
    {
	pDNSRequest = (DNS_REQUEST*) sockGlobals.m_DNSQueue.RemoveHead();
	HX_DELETE(pDNSRequest);
    }

    // check to see if we are still in use.
    CheckClients();
    return (TRUE);
}
Ejemplo n.º 4
0
//	Our client win_net object calls this method to 
//	stop receiving async select notifications
//	on a socket.
HXBOOL CAsyncSockN::CancelSelect(win_net* fpSock)
{
    SOCKET	    theSocket;
    DNS_REQUEST*    pDNSRequest = NULL;
    LISTPOSITION    lPos;

    //	Preliminary checks
    HX_ASSERT(this);
    HX_ASSERT(fpSock);

    //	Bail on bad input
    if (!this || !fpSock)
    {
	return(FALSE);
    }

    m_bInCancelMode = TRUE;

    // If we haven't returned from an Asyn operation like GetHostByName
    // then we need to tell Winsock to cancel the opertation!
    HANDLE hAsyncHandle = fpSock->m_hAsyncHandle;
    if (hAsyncHandle)
    {
	sockObj->HXWSACancelAsyncRequest(hAsyncHandle);
	fpSock->m_hAsyncHandle = NULL;

	// If we've canceled the async DNS is done, 
	// then we can forget the Async handle
	if (m_ClientHandlesMap->RemoveKey((void*)hAsyncHandle))
	{
	    DecrementHandlesClientCount();
	}
    }

    if (sockGlobals.m_bWinSock2Suck)
    {
	lPos = sockGlobals.m_DNSQueue.GetHeadPosition();

	while (lPos)
	{
	    pDNSRequest = (DNS_REQUEST *)sockGlobals.m_DNSQueue.GetAt(lPos);

	    if (pDNSRequest->fpSock == fpSock)
	    {
		sockGlobals.m_DNSQueue.RemoveAt(lPos);
		HX_DELETE(pDNSRequest);
		break;
	    }

	    sockGlobals.m_DNSQueue.GetNext(lPos);
	}
    }

    //	Get and verify we have a good socket handle
    theSocket = fpSock->get_sock();
    
//    HX_ASSERT(theSocket != INVALID_SOCKET);
    /* This may actually happen since we do not check for CONN_CLOSED
     * condition in win_net any more
     */
    if (theSocket == INVALID_SOCKET)
    {
	m_bInCancelMode = FALSE;
	return FALSE;
    }

    //	Turn off async Notifications on the socket
    sockObj->HXWSAAsyncSelect(theSocket, m_hWnd, 0, 0);

    // According to the Winsock help, just cause we cancel
    // the notifications, doesn't mean we still won't get notified
    // of something that has already been posted to our window,
    // so... let's flush our message queue...
    //
    // HACK ATTACK: Notice that both of these message pumps
    // are needed. If you run a debug build or a retail build
    // on some machines without the two message pumps, you
    // won't have any trouble. But on some machines having only
    // this last message pump will cause a GPF.
    MSG msg;
    while (m_hWnd && PeekMessage(&msg, m_hWnd,0,0,PM_REMOVE))
    {
	// This will remove any messages!
	HX_TRACE("There's a message that would've go you!!\r\n");

	if(msg.message == WM_QUIT) 
	{   
	    // When peeking WM_QUIT message in the main thread of an application 
	    // we have to put it back into message queue to allow the application 
	    // to exit correctly. SB
	    PostQuitMessage(0);
	    break;
	}
	else
	{
	    // Even though we want them removed, we also want to act on them.
	    DispatchMessage(&msg);
	}
    }

    if (m_ClientSocketsMap)
    {
	//	Delete the mapping from socket handle to win_net object pointer
	if (m_ClientSocketsMap->RemoveKey((void*)theSocket))
	{
	    //	Decrement our client count and conditionally
	    //	delete ourselves.
	    DecrementSocketsClientCount();
	}
    }

    m_bInCancelMode = FALSE;

    // check to see if we are in use
    CheckClients();
    return (TRUE);
}