bool WaitingList::clientLogin(const Player* player) { if(player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->getAccountType() >= ACCOUNT_TYPE_GAMEMASTER || player->isAccountManager()) return true; if(waitList.empty() && Status::getInstance()->getPlayersOnline() < Status::getInstance()->getMaxPlayersOnline()) { //no waiting list and enough room return true; } cleanUpList(); uint32_t slot; WaitListIterator it = findClient(player, slot); if(it != waitList.end()) { if((Status::getInstance()->getPlayersOnline() + slot) <= Status::getInstance()->getMaxPlayersOnline()) { //should be able to login now delete *it; waitList.erase(it); return true; } else { //let them wait a bit longer (*it)->timeout = OTSYS_TIME() + (getTimeOut(slot) * 1000); return false; } } Wait* wait = new Wait(); if(player->isPremium()) { slot = 1; for(WaitListIterator it = waitList.begin(); it != waitList.end(); ++it) { if(!(*it)->premium) { waitList.insert(it, wait); break; } ++slot; } } else { waitList.push_back(wait); slot = (uint32_t)waitList.size(); } wait->name = player->getName(); wait->acc = player->getAccount(); wait->ip = player->getIP(); wait->premium = player->isPremium(); wait->timeout = OTSYS_TIME() + (getTimeOut(slot) * 1000); return false; }
// Test case: TestLookUp:1 // This test calls lookUp() for the condition where // the query has an OR operator. int TestLookUp1() { START_TEST_CASE; INVERTED_INDEX* testIndex = NULL; int wordHash; int wordHash2; testIndex = initStructure(testIndex); wordHash = hash1("dog") % MAX_NUMBER_OF_SLOTS; DocumentNode* docNode = NULL; docNode = newDocNode(docNode, 15, 1); WordNode* wordNode = NULL; wordNode = newWordNode(wordNode, docNode, "dog"); testIndex->hash[wordHash] = wordNode; wordHash2 = hash1("cat") % MAX_NUMBER_OF_SLOTS; DocumentNode* docNode2 = NULL; docNode2 = newDocNode(docNode2, 20, 2); WordNode* wordNode2 = NULL; wordNode2 = newWordNode(wordNode2, docNode2, "cat"); testIndex->hash[wordHash2] = wordNode2; char query[1000] = "dog OR cat"; sanitize(query); char* temp[1000]; BZERO(temp, 1000); char* queryList[2]; BZERO(queryList, 2); curateWords(queryList, query); SHOULD_BE(strcmp(queryList[0],"dog") == 0); SHOULD_BE(strcmp(queryList[1],"OR") == 0); SHOULD_BE(strcmp(queryList[2],"cat") == 0); DocumentNode* saved[1000]; BZERO(saved, 1000); lookUp(saved, queryList, testIndex); SHOULD_BE(saved[0]->document_id == docNode->document_id); SHOULD_BE(saved[0]->page_word_frequency == docNode->page_word_frequency); SHOULD_BE(saved[1]->document_id == docNode2->document_id); SHOULD_BE(saved[1]->page_word_frequency == docNode2->page_word_frequency); cleanUpList(saved); cleanUpQueryList(queryList); BZERO(saved, 1000); cleanUpIndex(testIndex); END_TEST_CASE; }
// Test case: TestLookUp:5 // This test calls lookUp() for the condition where // the query has both AND and OR int TestLookUp5() { START_TEST_CASE; INVERTED_INDEX* testIndex = NULL; int wordHash; int wordHash2; int wordHash3; int wordHash4; testIndex = initStructure(testIndex); wordHash = hash1("dog") % MAX_NUMBER_OF_SLOTS; DocumentNode* docNode = NULL; docNode = newDocNode(docNode, 15, 1); WordNode* wordNode = NULL; wordNode = newWordNode(wordNode, docNode, "dog"); testIndex->hash[wordHash] = wordNode; wordHash2 = hash1("cat") % MAX_NUMBER_OF_SLOTS; DocumentNode* docNode2 = NULL; docNode2 = newDocNode(docNode2, 15, 2); WordNode* wordNode2 = NULL; wordNode2 = newWordNode(wordNode2, docNode2, "cat"); testIndex->hash[wordHash2] = wordNode2; wordHash3 = hash1("mouse") % MAX_NUMBER_OF_SLOTS; DocumentNode* docNode3 = NULL; docNode3 = newDocNode(docNode3, 23, 2); WordNode* wordNode3 = NULL; wordNode3 = newWordNode(wordNode3, docNode3, "mouse"); testIndex->hash[wordHash3] = wordNode3; wordHash4 = hash1("lion") % MAX_NUMBER_OF_SLOTS; DocumentNode* docNode4 = NULL; docNode4 = newDocNode(docNode4, 23, 2); WordNode* wordNode4 = NULL; wordNode4 = newWordNode(wordNode4, docNode4, "lion"); testIndex->hash[wordHash4] = wordNode4; char query[1000] = "dog cat OR mouse lion"; sanitize(query); char* temp[1000]; BZERO(temp, 1000); char* queryList[1000]; BZERO(queryList, 1000); curateWords(queryList, query); DocumentNode* saved[1000]; BZERO(saved, 1000); lookUp(saved, queryList, testIndex); SHOULD_BE(saved[0]->document_id == docNode->document_id); SHOULD_BE(saved[0]->page_word_frequency == 3); SHOULD_BE(saved[1]->document_id == docNode3->document_id); SHOULD_BE(saved[1]->page_word_frequency == 4); cleanUpList(saved); cleanUpQueryList(queryList); BZERO(saved, 1000); cleanUpIndex(testIndex); END_TEST_CASE; }