uint32_t MySQLBanCount( void *conn, string *error, uint32_t botid, string server ) { string EscServer = MySQLEscapeString( conn, server ); uint32_t Count = 0; string Query = "SELECT COUNT(*) FROM bans WHERE server='" + EscServer + "'"; if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 ) *error = mysql_error( (MYSQL *)conn ); else { MYSQL_RES *Result = mysql_store_result( (MYSQL *)conn ); if( Result ) { vector<string> Row = MySQLFetchRow( Result ); if( Row.size( ) == 1 ) Count = UTIL_ToUInt32( Row[0] ); else *error = "error counting bans [" + server + "] - row doesn't have 1 column"; mysql_free_result( Result ); } else *error = mysql_error( (MYSQL *)conn ); } return Count; }
CDBGamePlayerSummary *MySQLGamePlayerSummaryCheck( void *conn, string *error, uint32_t botid, string name ) { transform( name.begin( ), name.end( ), name.begin( ), (int(*)(int))tolower ); string EscName = MySQLEscapeString( conn, name ); CDBGamePlayerSummary *GamePlayerSummary = NULL; string Query = "SELECT MIN(DATE(datetime)), MAX(DATE(datetime)), COUNT(*), MIN(loadingtime), AVG(loadingtime), MAX(loadingtime), MIN(`left`/duration)*100, AVG(`left`/duration)*100, MAX(`left`/duration)*100, MIN(duration), AVG(duration), MAX(duration) FROM gameplayers LEFT JOIN games ON games.id=gameid WHERE LOWER(name)='" + EscName + "'"; if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 ) *error = mysql_error( (MYSQL *)conn ); else { MYSQL_RES *Result = mysql_store_result( (MYSQL *)conn ); if( Result ) { vector<string> Row = MySQLFetchRow( Result ); if( Row.size( ) == 12 ) { string FirstGameDateTime = Row[0]; string LastGameDateTime = Row[1]; uint32_t TotalGames = UTIL_ToUInt32( Row[2] ); uint32_t MinLoadingTime = UTIL_ToUInt32( Row[3] ); uint32_t AvgLoadingTime = UTIL_ToUInt32( Row[4] ); uint32_t MaxLoadingTime = UTIL_ToUInt32( Row[5] ); uint32_t MinLeftPercent = UTIL_ToUInt32( Row[6] ); uint32_t AvgLeftPercent = UTIL_ToUInt32( Row[7] ); uint32_t MaxLeftPercent = UTIL_ToUInt32( Row[8] ); uint32_t MinDuration = UTIL_ToUInt32( Row[9] ); uint32_t AvgDuration = UTIL_ToUInt32( Row[10] ); uint32_t MaxDuration = UTIL_ToUInt32( Row[11] ); GamePlayerSummary = new CDBGamePlayerSummary( string( ), name, FirstGameDateTime, LastGameDateTime, TotalGames, MinLoadingTime, AvgLoadingTime, MaxLoadingTime, MinLeftPercent, AvgLeftPercent, MaxLeftPercent, MinDuration, AvgDuration, MaxDuration ); } else *error = "error checking gameplayersummary [" + name + "] - row doesn't have 12 columns"; mysql_free_result( Result ); } else *error = mysql_error( (MYSQL *)conn ); } return GamePlayerSummary; }
CStatsDOTA :: CStatsDOTA( CBaseGame *nGame, string nConditions, string nSaveType ) : CStats( nGame ), m_SaveType( nSaveType ), m_Winner( 0 ), m_Min( 0 ), m_Sec( 0 ), m_TowerLimit( false ), m_KillLimit( 0 ), m_TimeLimit( 0 ), m_SentinelTowers( 0 ), m_ScourgeTowers( 0 ), m_SentinelKills( 0 ), m_ScourgeKills( 0 ), m_LastCreepTime( 0 ) { CONSOLE_Print( "[STATSDOTA] using dota stats" ); for( unsigned int i = 0; i < 12; ++i ) m_Players[i] = NULL; // process the win conditions if( !nConditions.empty( ) ) { stringstream SS; SS << nConditions; while( !SS.eof( ) ) { string Condition; SS >> Condition; if( SS.fail( ) ) { CONSOLE_Print( "[STATSDOTA] failed to process win conditions: " + nConditions ); break; } else if( Condition.length( ) >= 2 ) { string Key = Condition.substr( 0, 2 ); string Value = Condition.substr( 2 ); if( Key == "tw" ) m_TowerLimit = UTIL_ToUInt32( Value ); else if( Key == "ki" ) m_KillLimit = UTIL_ToUInt32( Value ); else if( Key == "tm" ) m_TimeLimit = UTIL_ToUInt32( Value ); } } }
inline void CIRC :: ExtractPackets( ) { string Token, PreviousToken, Recv = *( m_Socket->GetBytes( ) ); uint32_t Time = GetTime( ); unsigned int i; /* loop through whole recv buffer */ for( i = 0; i < Recv.size( ); ++i ) { // add chars to token if( Recv[i] != ' ' && Recv[i] != CR && Recv[i] != LF ) { Token += Recv[i]; } else if( Recv[i] == ' ' || Recv[i] == LF ) { // end of token, examine if( Token == "PRIVMSG" ) { // parse the PreviousToken as it holds the user info and then the Token for the message itself string Nickname, Hostname, Message, Command, Payload; bool IsCommand = true; unsigned int j = 1; // get nickname for( ; PreviousToken[j] != '!'; ++j ) Nickname += PreviousToken[j]; // skip username for( j += 2; PreviousToken[j] != '@'; ++j ); // get hostname for( ++j; j < PreviousToken.size( ); ++j ) Hostname += PreviousToken[j]; // skip channel for( i += 3; Recv[i] != ':'; ++i ); // process message for( ++i; Recv[i] != CR; ++i ) { Message += Recv[i]; if( Recv[i] == ' ' && IsCommand ) { IsCommand = false; continue; } if( Message.size( ) != 1 ) { if( IsCommand ) Command += tolower( Recv[i] ); else Payload += Recv[i]; } } // move position after the \n i += 2; if( Message.empty( ) ) { PreviousToken = Token; Token.clear( ); continue; } if( Message[0] != SOH ) { for( vector<CBNET *> :: iterator i = m_Aura->m_BNETs.begin( ); i != m_Aura->m_BNETs.end( ); ++i ) { if( Message[0] == (*i)->GetCommandTrigger( ) ) { CIncomingChatEvent event = CIncomingChatEvent( CBNETProtocol :: EID_IRC, Nickname, Message ); (*i)->ProcessChatEvent( &event ); break; } } if( Message[0] == m_CommandTrigger[0] ) { bool Root = Hostname.substr( 0, 6 ) == "Aurani" || Hostname.substr( 0, 8 ) == "h4x0rz88"; if( Command == "nick" && Root ) { SendIRC( "NICK :" + Payload ); m_Nickname = Payload; m_OriginalNick= false; } else if( Command == "dcclist" ) { string on, off; for( vector<CDCC *> :: iterator i = m_DCC.begin( ); i != m_DCC.end( ); ++i ) { if( (*i)->m_Socket->GetConnected( ) ) on += (*i)->m_Nickname + "[" + UTIL_ToString( (*i)->m_Port ) +"] "; else off += (*i)->m_Nickname + "[" + UTIL_ToString( (*i)->m_Port ) +"] "; } SendMessageIRC( "ON: " + on, string( ) ); SendMessageIRC( "OFF: " + off, string( ) ); } else if( Command == "bnetoff" ) { if( Payload.empty( ) ) { for( vector<CBNET *> :: iterator i = m_Aura->m_BNETs.begin( ); i != m_Aura->m_BNETs.end( ); ++i ) { (*i)->Deactivate( ); SendMessageIRC( "[BNET: " + (*i)->GetServerAlias( ) + "] deactivated.", string( ) ); } } else { for( vector<CBNET *> :: iterator i = m_Aura->m_BNETs.begin( ); i != m_Aura->m_BNETs.end( ); ++i ) { if( (*i)->GetServerAlias( ) == Payload ) { (*i)->Deactivate( ); SendMessageIRC( "[BNET: " + (*i)->GetServerAlias( ) + "] deactivated.", string( ) ); break; } } } } else if( Command == "bneton" ) { if( Payload.empty( ) ) { for( vector<CBNET *> :: iterator i = m_Aura->m_BNETs.begin( ); i != m_Aura->m_BNETs.end( ); ++i ) { (*i)->Activate( ); SendMessageIRC( "[BNET: " + (*i)->GetServerAlias( ) + "] activated.", string( ) ); } } else { for( vector<CBNET *> :: iterator i = m_Aura->m_BNETs.begin( ); i != m_Aura->m_BNETs.end( ); ++i ) { if( (*i)->GetServerAlias( ) == Payload ) { (*i)->Activate( ); SendMessageIRC( "[BNET: " + (*i)->GetServerAlias( ) + "] activated.", string( ) ); break; } } } } } } else if( Payload.size( ) > 12 && Payload.substr( 0, 4 ) == "CHAT" ) { // CHAT chat 3162588924 1025 string strIP, strPort; bool IsPort = false; for( unsigned int j = 10; j < ( Payload.size( ) - 1 ); ++j ) { if( !IsPort && Payload[j] == ' ' ) { IsPort = true; continue; } if( !IsPort ) strIP += Payload[j]; else strPort += Payload[j]; } unsigned int Port = UTIL_ToUInt16( strPort ); if( Port < 1024 || 1026 < Port ) Port = 1024; bool Local = false; for( vector<string> :: iterator i = m_Locals.begin( ); i != m_Locals.end( ); ++i ) { if( Nickname == (*i) ) { strIP = "127.0.0.1"; Local = true; break; } } if( !Local ) { unsigned long IP = UTIL_ToUInt32( strIP ), divider = 16777216UL; strIP = ""; for( int i = 0; i <= 3; ++i ) { stringstream ss; ss << (unsigned long) IP / divider; IP %= divider; divider /= 256; strIP += ss.str( ); if( i != 3 ) strIP += '.'; } } bool Existing = false; for( vector<CDCC *> :: iterator i = m_DCC.begin( ); i != m_DCC.end( ); ++i ) { if( (*i)->m_Nickname == Nickname ) { (*i)->Connect( strIP, Port ); Existing = true; break; } } if( !Existing ) m_DCC.push_back( new CDCC( this, strIP, Port, Nickname ) ); } // remember last packet time m_LastPacketTime = Time; } else if( Token == "391" ) { // move position after the \n (next packet) for( ++i; Recv[i] != CR; ++i ); i += 2; // remember last packet time m_LastPacketTime = Time; } else if( Token == "PING" ) { string Packet; // PING :blabla // skip until : for( ++i; Recv[i] != ':'; ++i ); for( ++i; Recv[i] != CR; ++i ) Packet += Recv[i]; SendIRC( "PONG :" + Packet ); // move position after the \n i += 2; // remember last packet time m_LastPacketTime = Time; } else if( Token == "NOTICE" ) { // move position after the \n for( ++i; Recv[i] != CR; ++i ); i += 2; // remember last packet time m_LastPacketTime = Time; } else if( Token == "221" ) { // Q auth if the server is QuakeNet if( m_Server.find( "quakenet.org" ) != string :: npos && !m_Password.empty( ) ) { SendMessageIRC( "AUTH " + m_Username + " " + m_Password, "*****@*****.**" ); SendIRC( "MODE " + m_Nickname + " +x" ); } // join channels for( vector<string> :: iterator j = m_Channels.begin( ); j != m_Channels.end( ); ++j ) { SendIRC( "JOIN " + (*j) ); } // move position after the \n for( ++i; Recv[i] != CR; ++i ); i += 2; // remember last packet time m_LastPacketTime = Time; } else if( Token == "433" ) { // nick taken, append _ m_OriginalNick = false; m_Nickname += '_'; SendIRC( "NICK " + m_Nickname ); // move position after the \n (next packet) for( ++i; Recv[i] != CR; ++i ); i += 2; // remember last packet time m_LastPacketTime = Time; } else if( Token == "353" ) { // move position after the \n (next packet) for( ++i; Recv[i] != CR; ++i ); i += 2; // remember last packet time m_LastPacketTime = Time; } else if( Token == "KICK" ) { string Channel, Victim; bool Space = false; // get channel for( ++i; Recv[i] != ' '; ++i ) Channel += Recv[i]; // get the victim for( ++i ; i < Recv.size( ); ++i ) { if( Recv[i] == ' ' ) Space = true; else if( Recv[i] == CR ) break; else if( Space && Recv[i] != ':' ) Victim += Recv[i]; } // we're the victim here! rejoin if( Victim == m_Nickname ) { SendIRC( "JOIN " + Channel ); } // move position after the \n i += 2; // remember last packet time m_LastPacketTime = Time; } // empty the token PreviousToken = Token; Token.clear( ); } } m_Socket->ClearRecvBuffer( ); }
CDBDotAPlayerSummary *MySQLDotAPlayerSummaryCheck( void *conn, string *error, uint32_t botid, string name ) { transform( name.begin( ), name.end( ), name.begin( ), (int(*)(int))tolower ); string EscName = MySQLEscapeString( conn, name ); CDBDotAPlayerSummary *DotAPlayerSummary = NULL; string Query = "SELECT games, kills, deaths, creepkills, creepdenies, assists, neutralkills, towerkills, raxkills, courierkills, wins, losses FROM dota_elo WHERE LOWER(name)='" + EscName + "'"; if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 ) *error = mysql_error( (MYSQL *)conn ); else { MYSQL_RES *Result = mysql_store_result( (MYSQL *)conn ); if( Result ) { vector<string> Row = MySQLFetchRow( Result ); if( Row.size( ) == 12 ) { uint32_t TotalGames = UTIL_ToUInt32( Row[0] ); if( TotalGames > 0 ) { uint32_t TotalKills = UTIL_ToUInt32( Row[1] ); uint32_t TotalDeaths = UTIL_ToUInt32( Row[2] ); uint32_t TotalCreepKills = UTIL_ToUInt32( Row[3] ); uint32_t TotalCreepDenies = UTIL_ToUInt32( Row[4] ); uint32_t TotalAssists = UTIL_ToUInt32( Row[5] ); uint32_t TotalNeutralKills = UTIL_ToUInt32( Row[6] ); uint32_t TotalTowerKills = UTIL_ToUInt32( Row[7] ); uint32_t TotalRaxKills = UTIL_ToUInt32( Row[8] ); uint32_t TotalCourierKills = UTIL_ToUInt32( Row[9] ); uint32_t TotalWins = UTIL_ToUInt32( Row[10] ); uint32_t TotalLosses = UTIL_ToUInt32( Row[11] ); // done DotAPlayerSummary = new CDBDotAPlayerSummary( string( ), name, TotalGames, TotalWins, TotalLosses, TotalKills, TotalDeaths, TotalCreepKills, TotalCreepDenies, TotalAssists, TotalNeutralKills, TotalTowerKills, TotalRaxKills, TotalCourierKills ); } } else *error = "error checking dotaplayersummary [" + name + "] - row doesn't have 10 columns"; mysql_free_result( Result ); } else *error = mysql_error( (MYSQL *)conn ); } return DotAPlayerSummary; }
void CGHostGenie :: LoadIPToCountryData( string file ) { ifstream in; in.open( file.c_str( ) ); if( in.fail( ) ) LogWarning( "[GHOST] warning - unable to read file [" + file + "], iptocountry data not loaded" ); else { LogInfo( "[GHOST] started loading [" + file + "]" ); // the begin and commit statements are optimizations // we're about to insert ~4 MB of data into the database so if we allow the database to treat each insert as a transaction it will take a LONG time // todotodo: handle begin/commit failures a bit more gracefully if( !m_DBLocal->Begin( ) ) LogWarning( "[GHOST] warning - failed to begin local database transaction, iptocountry data not loaded" ); else { unsigned char Percent = 0; string Line; string IP1; string IP2; string Country; CSVParser parser; // get length of file for the progress meter in.seekg( 0, ios :: end ); uint32_t FileLength = in.tellg( ); in.seekg( 0, ios :: beg ); while( !in.eof( ) ) { getline( in, Line ); if( Line.empty( ) ) continue; parser << Line; parser >> IP1; parser >> IP2; parser >> Country; m_DBLocal->FromAdd( UTIL_ToUInt32( IP1 ), UTIL_ToUInt32( IP2 ), Country ); // it's probably going to take awhile to load the iptocountry data (~10 seconds on my 3.2 GHz P4 when using SQLite3) // so let's print a progress meter just to keep the user from getting worried unsigned char NewPercent = (unsigned char)( (float)in.tellg( ) / FileLength * 100 ); if( NewPercent != Percent ) { if( NewPercent % 10 == 0 ) LogInfo( "[GHOST] iptocountry data: " + UTIL_ToString( NewPercent ) + "% loaded" ); Percent = NewPercent; if( ip2countryCallback ) ip2countryCallback( callbackObject, NewPercent ); } } if( !m_DBLocal->Commit( ) ) LogWarning( "[GHOST] warning - failed to commit local database transaction, iptocountry data not loaded" ); else LogInfo( "[GHOST] finished loading [ip-to-country.csv]" ); } in.close( ); } }