bool QAcceptSocketsThread :: event(QEvent * event) { if (event->type() == QMTT_SIGNAL_EVENT) { MessageRef next; // Check for any new messages from our HTTP thread while(GetNextReplyFromInternalThread(next) >= 0) { switch(next()->what) { case AST_EVENT_NEW_SOCKET_ACCEPTED: { RefCountableRef tag; if (next()->FindTag(AST_NAME_SOCKET, tag) == B_NO_ERROR) { ConstSocketRef sref(tag, false); if (sref()) emit ConnectionAccepted(sref); } } break; } } return true; } else return QObject::event(event); }
void CNetworkModule::UpdateNetwork( void ) { // Create a packet RakNet::Packet * pPacket = NULL; // bool bDisconnect = false; // Process RakNet while( pPacket = m_pRakPeer->Receive() ) { // Is the packet invalid? if ( !pPacket ) continue; // Have we connected? if( pPacket->data[0] == ID_CONNECTION_REQUEST_ACCEPTED ) { // Call the connection accepted handler ConnectionAccepted( pPacket ); // Process this packet with the server browser pCore->GetGUI()->GetServerBrowser()->ProcessNetworkPacket( (DefaultMessageIDTypes)pPacket->data[0] ); } else if( pPacket->data[0] == ID_DISCONNECTION_NOTIFICATION || pPacket->data[0] == ID_CONNECTION_LOST || pPacket->data[0] == ID_NO_FREE_INCOMING_CONNECTIONS || pPacket->data[0] == ID_INVALID_PASSWORD || pPacket->data[0] == ID_CONNECTION_BANNED || pPacket->data[0] == ID_CONNECTION_ATTEMPT_FAILED || pPacket->data[0] == ID_ALREADY_CONNECTED ) { // Did we timeout? if( pPacket->data[0] == ID_DISCONNECTION_NOTIFICATION || pPacket->data[0] == ID_CONNECTION_LOST ) { // Stop multiplayer pCore->StopMultiplayer (); // Start multiplayer pCore->StartMultiplayer (); } // Set the network state SetNetworkState( NETSTATE_NONE ); // Process this packet with the server browser pCore->GetGUI()->GetServerBrowser()->ProcessNetworkPacket( (DefaultMessageIDTypes)pPacket->data[0] ); } // Deallocate the memory used by the packet m_pRakPeer->DeallocatePacket( pPacket ); // Should we disconnect? if ( bDisconnect ) { // Restart raknet Disconnect (); // bDisconnect = false; } } }
void CNetworkManager::UpdateNetwork() { // Create a packet RakNet::Packet * pPacket = NULL; // Process RakNet while(pPacket = m_pRakPeer->Receive()) { switch(pPacket->data[0]) { case ID_NO_FREE_INCOMING_CONNECTIONS: { g_pCore->GetChat()->Outputf(true, "#16C5F2The server is full. Rerying..."); // Set the network state SetNetworkState(NETSTATE_TIMEOUT); // Set the last connection try m_uiLastConnectionTry = GetTickCount(); break; } case ID_DISCONNECTION_NOTIFICATION: { g_pCore->GetChat()->Outputf(true, "#16C5F2The server connection closed."); // Set the network state SetNetworkState(NETSTATE_DISCONNECTED); // Shutdown the core //pCore->HandleNetworkShutdown(); break; } case ID_INVALID_PASSWORD: { g_pCore->GetChat()->Outputf(true, "#16C5F2Incorrect server password."); // Set the network state SetNetworkState(NETSTATE_DISCONNECTED); break; } case ID_CONNECTION_BANNED: { g_pCore->GetChat()->Outputf(true, "#16C5F2You're banned from this server."); // Set the network state SetNetworkState(NETSTATE_DISCONNECTED); break; } case ID_CONNECTION_LOST: { g_pCore->GetChat()->Outputf(true, "#16C5F2Lost connection to the server. Reconnecting..."); // Set the network state SetNetworkState(NETSTATE_TIMEOUT); // Handle the connection timeout g_pCore->OnNetworkTimeout(); // Set the last connection try m_uiLastConnectionTry = GetTickCount(); break; } case ID_CONNECTION_REQUEST_ACCEPTED: { ConnectionAccepted(pPacket); break; } case ID_CONNECTION_ATTEMPT_FAILED: { g_pCore->GetChat()->Outputf(true, "#16C5F2Failed to connect to the server. Retrying..."); // Set the network state SetNetworkState(NETSTATE_TIMEOUT); // Set the last connection try m_uiLastConnectionTry = GetTickCount(); break; } } // Deallocate the memory used by the packet m_pRakPeer->DeallocatePacket(pPacket); } }