eNetworkResponse CNetworkModule::Connect( String strHost, unsigned short usPort, String strPass ) { // Are we already connected? if( IsConnected() ) { // Disconnect Disconnect(); } // Store the connection info SetLastConnection( strHost, usPort, strPass ); #ifdef DEBUG CLogFile::Printf( "Connection to %s:%d, password: %s", strHost.Get(), usPort, strPass.Get() ); #endif // Attempt to connect int iConnectionResult = m_pRakPeer->Connect( strHost.Get(), usPort, strPass.Get(), strPass.GetLength() ); // Set the network state SetNetworkState( NETSTATE_CONNECTING ); // Did we fail to connect? if( iConnectionResult != RakNet::INVALID_PARAMETER ) { // Set the network state SetNetworkState( NETSTATE_NONE ); // Set the last connection try m_uiLastConnectionTry = (unsigned int)SharedUtility::GetTime(); } return (eNetworkResponse)iConnectionResult; }
void CNetworkManager::Connect(CString strHost, unsigned short usPort, CString strPass) { // Are we already connected? if(IsConnected()) { // Disconnect Disconnect(); } // Store the connection info SetLastConnection(strHost, usPort, strPass); // Attempt to connect int iConnectionResult = m_pRakPeer->Connect(strHost.Get(), usPort, strPass.Get(), strPass.GetLength()); // Set the network state SetNetworkState(NETSTATE_CONNECTING); // Create the string for the connection message CString strMessage("Failed to connected!"); // Get the result from the connection switch(iConnectionResult) { case 0: strMessage.Format("Connecting to %s:%d...", strHost.Get(), usPort); break; case 1: strMessage.Set("Failed to connect! (Invalid parameter)"); break; case 2: strMessage.Set("Failed to connect! (Cannot resolve domain name)"); break; case 3: strMessage.Set("Failed to connect! (Already connected)"); break; case 4: strMessage.Set("Failed to connect! (Connection attempt already in progress)"); break; case 5: strMessage.Set("Failed to connect! (Security initialization failed)"); break; case 6: strMessage.Set("Failed to connect! (No host set)"); break; } // Did we fail to connect? if(iConnectionResult != 0) { // Set the network state SetNetworkState(NETSTATE_DISCONNECTED); // Set the last connection try m_uiLastConnectionTry = (unsigned int)SharedUtility::GetTime(); } CGUI* pGUI = g_pCore->GetGUI(); if (pGUI) { //pGUI->ClearView(CGUI::GUI_SERVER); //pGUI->SetView(CGUI::GUI_SERVER); } // Output the connection message g_pCore->GetChat()->Outputf(true, "#16C5F2%s", strMessage.Get()); }