bool CPotentialPlayer :: Update( void *fd ) { if( m_DeleteMe ) return true; if( !m_Socket ) return false; m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); ProcessPackets( ); // make sure we don't keep this socket open forever (disconnect after five seconds) if( m_ConnectionState == 0 && GetTicks( ) - m_ConnectionTime > m_Game->m_GHost->m_DenyMaxReqjoinTime && !m_Banned ) { CONSOLE_Print( "[DENY] Kicking player: REQJOIN not received within a few seconds" ); m_DeleteMe = true; m_Game->m_GHost->DenyIP( GetExternalIPString( ), m_Game->m_GHost->m_DenyReqjoinDuration, "REQJOIN not received within a few seconds" ); } // don't call DoSend here because some other players may not have updated yet and may generate a packet for this player // also m_Socket may have been set to NULL during ProcessPackets but we're banking on the fact that m_DeleteMe has been set to true as well so it'll short circuit before dereferencing return m_DeleteMe || m_Error || m_Socket->HasError( ) || !m_Socket->GetConnected( ); }
void CBNLSClient::socketDataReady() { ExtractPackets( ); ProcessPackets( ); while( !m_OutPackets.isEmpty( ) ) m_Socket->write( m_OutPackets.dequeue( ) ); }
bool CBNLSClient :: Update( void *fd, void *send_fd ) { if( m_Socket->HasError( ) ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] disconnected from BNLS server due to socket error" ); return true; } if( !m_Socket->GetConnecting( ) && !m_Socket->GetConnected( ) && m_WasConnected ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] disconnected from BNLS server" ); return true; } if( m_Socket->GetConnected( ) ) { m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); ProcessPackets( ); if( GetTime( ) - m_LastNullTime >= 50 ) { m_Socket->PutBytes( m_Protocol->SEND_BNLS_NULL( ) ); m_LastNullTime = GetTime( ); } while( !m_OutPackets.empty( ) ) { m_Socket->PutBytes( m_OutPackets.front( ) ); m_OutPackets.pop( ); } m_Socket->DoSend( (fd_set *)send_fd ); return false; } if( m_Socket->GetConnecting( ) && m_Socket->CheckConnect( ) ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] connected" ); m_WasConnected = true; m_LastNullTime = GetTime( ); return false; } if( !m_Socket->GetConnecting( ) && !m_Socket->GetConnected( ) && !m_WasConnected ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] connecting to server [" + m_Server + "] on port " + UTIL_ToString( m_Port ) ); m_Socket->Connect( string( ), m_Server, m_Port ); return false; } return false; }
bool CPotentialPlayer :: Update( void *fd ) { if( m_DeleteMe ) return true; if( !m_Socket ) return false; m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); ProcessPackets( ); // don't call DoSend here because some other players may not have updated yet and may generate a packet for this player // also m_Socket may have been set to NULL during ProcessPackets but we're banking on the fact that m_DeleteMe has been set to true as well so it'll short circuit before dereferencing return m_DeleteMe || m_Error || m_Socket->HasError( ) || !m_Socket->GetConnected( ); }
bool CIRC :: Update( void *fd, void *send_fd ) { uint32_t Time = GetTime( ); if( m_Socket->GetConnected( ) ) { // the socket is connected and everything appears to be working properly if( Time - m_LastPacketTime > 210 ) { Print( "[IRC: " + m_Server + "] ping timeout, reconnecting" ); m_Socket->Reset( ); m_WaitingToConnect = true; return m_Exiting; } if( Time - m_LastAntiIdleTime > 60 ) { SendIRC( "TIME" ); m_LastAntiIdleTime = Time; } m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); m_Socket->DoSend( (fd_set *)send_fd ); return m_Exiting; } if( m_Socket->HasError( ) ) { // the socket has an error Print( "[IRC: " + m_Server + "] disconnected due to socket error, waiting 60 seconds to reconnect" ); m_Socket->Reset( ); m_WaitingToConnect = true; m_LastConnectionAttemptTime = Time; return m_Exiting; } if( !m_Socket->GetConnecting( ) && !m_Socket->GetConnected( ) && !m_WaitingToConnect ) { // the socket was disconnected Print( "[IRC: " + m_Server + "] disconnected, waiting 60 seconds to reconnect" ); m_Socket->Reset( ); m_WaitingToConnect = true; m_LastConnectionAttemptTime = Time; return m_Exiting; } if( m_Socket->GetConnecting( ) ) { // we are currently attempting to connect to irc if( m_Socket->CheckConnect( ) ) { // the connection attempt completed if( !m_OriginalNick ) m_Nickname = m_NicknameCpy; SendIRC( "NICK " + m_Nickname ); SendIRC( "USER " + m_Username + " " + m_Nickname + " " + m_Username + " :by h4x0rz88" ); m_Socket->DoSend( (fd_set *)send_fd ); Print( "[IRC: " + m_Server + "] connected" ); m_LastPacketTime = Time; return m_Exiting; } else if( Time - m_LastConnectionAttemptTime > 15 ) { // the connection attempt timed out (15 seconds) Print( "[IRC: " + m_Server + "] connect timed out, waiting 60 seconds to reconnect" ); m_Socket->Reset( ); m_LastConnectionAttemptTime = Time; m_WaitingToConnect = true; return m_Exiting; } } if( !m_Socket->GetConnecting( ) && !m_Socket->GetConnected( ) && ( Time - m_LastConnectionAttemptTime > 60 ) ) { // attempt to connect to irc Print( "[IRC: " + m_Server + "] connecting to server [" + m_Server + "] on port " + UTIL_ToString( m_Port ) ); if( m_ServerIP.empty( ) ) { m_Socket->Connect( string( ), m_Server, m_Port ); if( !m_Socket->HasError( ) ) { m_ServerIP = m_Socket->GetIPString( ); } } else { // use cached server IP address since resolving takes time and is blocking m_Socket->Connect( string( ), m_ServerIP, m_Port ); } m_WaitingToConnect = false; m_LastConnectionAttemptTime = Time; } return m_Exiting; }