bool CBNCSUtilInterface :: HELP_SID_AUTH_CHECK( bool TFT, string war3Path, string keyROC, string keyTFT, string valueStringFormula, string mpqFileName, BYTEARRAY clientToken, BYTEARRAY serverToken ) { // set m_EXEVersion, m_EXEVersionHash, m_EXEInfo, m_InfoROC, m_InfoTFT string FileWar3EXE = war3Path + "war3.exe"; string FileStormDLL = war3Path + "Storm.dll"; if( !UTIL_FileExists( FileStormDLL ) ) FileStormDLL = war3Path + "storm.dll"; string FileGameDLL = war3Path + "game.dll"; bool ExistsWar3EXE = UTIL_FileExists( FileWar3EXE ); bool ExistsStormDLL = UTIL_FileExists( FileStormDLL ); bool ExistsGameDLL = UTIL_FileExists( FileGameDLL ); if( ExistsWar3EXE && ExistsStormDLL && ExistsGameDLL ) { // todotodo: check getExeInfo return value to ensure 1024 bytes was enough char buf[1024]; uint32_t EXEVersion; getExeInfo( FileWar3EXE.c_str( ), (char *)&buf, 1024, (uint32_t *)&EXEVersion, BNCSUTIL_PLATFORM_X86 ); m_EXEInfo = buf; m_EXEVersion = UTIL_CreateByteArray( EXEVersion, false ); uint32_t EXEVersionHash; checkRevisionFlat( valueStringFormula.c_str( ), FileWar3EXE.c_str( ), FileStormDLL.c_str( ), FileGameDLL.c_str( ), extractMPQNumber( mpqFileName.c_str( ) ), (unsigned long *)&EXEVersionHash ); m_EXEVersionHash = UTIL_CreateByteArray( EXEVersionHash, false ); m_KeyInfoROC = CreateKeyInfo( keyROC, UTIL_ByteArrayToUInt32( clientToken, false ), UTIL_ByteArrayToUInt32( serverToken, false ) ); if( TFT ) m_KeyInfoTFT = CreateKeyInfo( keyTFT, UTIL_ByteArrayToUInt32( clientToken, false ), UTIL_ByteArrayToUInt32( serverToken, false ) ); if( m_KeyInfoROC.size( ) == 36 && ( !TFT || m_KeyInfoTFT.size( ) == 36 ) ) return true; else { if( m_KeyInfoROC.size( ) != 36 ) CONSOLE_Print( "[BNCSUI] unable to create ROC key info - invalid ROC key" ); if( TFT && m_KeyInfoTFT.size( ) != 36 ) CONSOLE_Print( "[BNCSUI] unable to create TFT key info - invalid TFT key" ); } } else { if( !ExistsWar3EXE ) CONSOLE_Print( "[BNCSUI] unable to open [" + FileWar3EXE + "]" ); if( !ExistsStormDLL ) CONSOLE_Print( "[BNCSUI] unable to open [" + FileStormDLL + "]" ); if( !ExistsGameDLL ) CONSOLE_Print( "[BNCSUI] unable to open [" + FileGameDLL + "]" ); } return false; }
void CCCBot :: UpdateSwearList( ) { if( UTIL_FileExists( SwearsFile ) ) { ifstream file; file.open( SwearsFile, ios :: app ); if( !file.fail( ) ) { m_SwearList.clear( ); string line; while( !file.eof( ) ) { getline( file, line ); if( !line.empty( ) ) { if( find( m_SwearList.begin( ), m_SwearList.end( ), line ) == m_SwearList.end( ) && line[0] != '#' ) { transform( line.begin( ), line.end( ), line.begin( ), (int(*)(int))tolower ); m_SwearList.push_back( line ); } } } if( m_SwearList.size( ) ) CONSOLE_Print( "[CONFIG] updated swear list file (" + UTIL_ToString( m_SwearList.size( ) ) + ")" ); file.close( ); } } else { ofstream file; file.open( SwearsFile ); if( !file.fail( ) ) { CONSOLE_Print( "[CONFIG] creating a new, blank swears.cfg file" ); file << "#########################################################" << endl; file << "### THIS FILE CONTAINS ALL BANNED PHRASES AND WORDS! ####" << endl; file << "#########################################################" << endl; file << "# setting the # character on the first position will comment out your line" << endl; file.close( ); } } }
int main( ) { // seed the RNG srand( (unsigned int) time( NULL ) ); // check if the log folder exists if( !UTIL_FileExists( "log" ) ) { #ifdef WIN32 CreateDirectoryA( "log", NULL ); #else system( "mkdir log" ); system( "chmod 777 log" ); #endif } // check if the cfg folder exists if( !UTIL_FileExists( "cfg" ) ) { #ifdef WIN32 CreateDirectoryA( "cfg", NULL ); #else system( "mkdir cfg" ); system( "chmod 777 cfg" ); #endif } // read config file CConfig CFG; CFG.Read( CFGFile ); gLog = CFG.GetInt( "bot_log", 1 ) == 0 ? false : true; // catch SIGABRT and SIGINT signal( SIGABRT, SignalCatcher ); signal( SIGINT, SignalCatcher ); #ifndef WIN32 // disable SIGPIPE since some systems like OS X don't define MSG_NOSIGNAL signal( SIGPIPE, SIG_IGN ); #endif // initialize curses gCurses = true; initscr( ); #ifdef WIN32 resize_term( 28, 97 ); #endif clear( ); noecho( ); cbreak( ); gMainWindow = newwin( LINES - 3, COLS - 17, 0, 0 ); gBottomBorder = newwin( 1, COLS, LINES - 3, 0 ); gRightBorder = newwin( LINES - 3, 1, 0, COLS - 17 ); gInputWindow = newwin( 2, COLS, LINES - 2, 0 ); gChannelWindow = newwin( LINES - 3, 16, 0, COLS - 16 ); mvwhline( gBottomBorder, 0, 0, 0, COLS ); mvwvline( gRightBorder, 0, 0, 0, LINES ); wrefresh( gBottomBorder ); wrefresh( gRightBorder ); scrollok( gMainWindow, TRUE ); keypad( gInputWindow, TRUE ); scrollok( gInputWindow, TRUE ); CONSOLE_Draw( ); nodelay( gInputWindow, TRUE ); // print something for logging purposes CONSOLE_Print( "[CCBOT] starting up" ); #ifdef WIN32 // increase process priority CONSOLE_Print( "[CCBOT] setting process priority to \"high\"" ); SetPriorityClass( GetCurrentProcess( ), HIGH_PRIORITY_CLASS ); // initialize winsock CONSOLE_Print( "[CCBOT] starting winsock" ); WSADATA wsadata; if( WSAStartup( MAKEWORD( 2, 2 ), &wsadata ) != 0 ) { CONSOLE_Print( "[CCBOT] error starting winsock" ); return 1; } #endif // initialize ccbot gCCBot = new CCCBot( &CFG ); while( true ) { // block for 50ms on all sockets - if you intend to perform any timed actions more frequently you should change this // that said it's likely we'll loop more often than this due to there being data waiting on one of the sockets but there aren't any guarantees if( gCCBot->Update( ) ) break; bool Quit = false; int c = wgetch( gInputWindow ); while( c != ERR ) { if( c == 8 || c == 127 || c == KEY_BACKSPACE || c == KEY_DC ) { // Backspace, Delete if( !gInputBuffer.empty( ) ) gInputBuffer.erase( gInputBuffer.size( ) - 1, 1 ); } else if( c == 9 ) { // Tab } #ifdef WIN32 else if( c == 10 || c == 13 || c == PADENTER ) #else else if( c == 10 || c == 13 ) #endif { // CR, LF // process input buffer now string Command = gInputBuffer; if( Command[0] == gCCBot->m_BNETs[0]->GetCommandTrigger( ) ) { CONSOLE_Print( "[CONSOLE] " + Command ); CIncomingChatEvent event = CIncomingChatEvent( CBNETProtocol :: CONSOLE_INPUT, 0, 0, gCCBot->m_BNETs[0]->GetRootAdmin( ), Command ); gCCBot->m_BNETs[0]->ProcessChatEvent( &event ); } else gCCBot->m_BNETs[0]->QueueChatCommand( Command, false ); gInputBuffer.clear( ); } #ifdef WIN32 else if( c == 22 ) { // Paste char *clipboard = NULL; long length = 0; if( PDC_getclipboard( &clipboard, &length ) == PDC_CLIP_SUCCESS ) { gInputBuffer += string( clipboard, length ); PDC_freeclipboard( clipboard ); } } #endif else if( c == 27 ) { // Escape button gInputBuffer.clear( ); } else if( c >= 32 && c <= 255 ) { // Printable characters gInputBuffer.push_back( c ); } #ifdef WIN32 else if( c == PADSLASH ) gInputBuffer.push_back( '/' ); else if( c == PADSTAR ) gInputBuffer.push_back( '*' ); else if( c == PADMINUS ) gInputBuffer.push_back( '-' ); else if( c == PADPLUS ) gInputBuffer.push_back( '+' ); #endif else if( c == KEY_RESIZE ) CONSOLE_Resize( ); // clamp input buffer size if( gInputBuffer.size( ) > 200 ) gInputBuffer.erase( 200 ); c = wgetch( gInputWindow ); gInputWindowChanged = true; } CONSOLE_Draw( ); if( Quit ) break; } // shutdown ghost CONSOLE_Print( "[CCBOT] shutting down" ); delete gCCBot; gCCBot = NULL; #ifdef WIN32 // shutdown winsock CONSOLE_Print( "[CCBOT] shutting down winsock" ); WSACleanup( ); #endif // shutdown curses endwin( ); if( gRestart ) { #ifdef WIN32 _spawnl( _P_OVERLAY, "ccbot.exe", "ccbot.exe", NULL ); #else execl( "ccbot++", "ccbot++", NULL ); #endif } return 0; }