void Library::showUsers(string search) const { IdentNum i; User userTemp; vector <IdentNum> usersFound; for (i=1;i<=users.size();i++) { userTemp=getUserByID(i); string userName = userTemp.getName(); size_t counter = 0; // conta as vezes seguidas que detecta chars iguais bool found = false; // quando counter for igual a search.size() found = true for (size_t k = 0; k < userName.size() && !found; ++k) { if (counter < search.size()) { char temp1 = toupper(search[counter]); char temp2 = toupper(userName[k]); if (temp1 == temp2) if (temp1 == ' ') if (counter > 0) counter++; else counter = 0; else counter++; else counter = 0; } if (counter == search.size()) { found = true; } } if (found) usersFound.push_back(userTemp.getID()); } if (usersFound.size()==0) cout << "Nao foi encontrado nenhum utilizador com esses termos.\n"; else { cout << "#### Utilizadores ####\n"; cout << "--------------------------------------------------------------- \n"; cout << "| ID | Nome | Activo |\n"; cout << "--------------------------------------------------------------- \n"; cout << setiosflags(ios::left); for(size_t k = 0;k<usersFound.size();k++) { i = usersFound[k]; User userTemp=getUserByID(i); cout << "| " << setw(MAXIDLENGTH) << userTemp.getID() << "| " << setw(MAXNAMELENGTH) << userTemp.getName() << "| "; if (userTemp.isActive()) cout << setw(8) << "Sim" << "|\n"; else cout << setw(8) << "Nao" << "|\n"; } cout << resetiosflags(ios::left); cout << "--------------------------------------------------------------- \n"; } }
bool CManager::getUserByName(const char * strName, IUser ** ppUser) { int type=0; for (int i = 0; i < strlen(strName); i++) { if (strName[i] == '@') { type = 1; break; } else if ((strName[i] <= 'z' && strName[i] >= 'a') || (strName[i] <= 'Z' && strName[i] >= 'A') || strName[i] == '_') type = 2; else if (strName[i] <= '9' && strName[i] >= '0') {} else { setError(InvalidParam, -1, "Invalid string."); return false; } } if (!type) { int nId; std::stringstream ss; ss << strName; ss >> nId; return getUserByID(nId, ppUser); }
unsigned checkPrivUser (ChatBot *bot, long userID) { PrivUser **users = bot->privUsers; ChatUser *user = getUserByID(bot->room, userID); if (user->isModerator || user->isRoomOwner) { return INT_MAX; } for (int i = 0; i < bot->numOfPrivUsers; i ++) { if (users[i]->userID == userID) { return users[i]->privLevel; } } return 0; }
void Library::showUsers() const { IdentNum i; if (users.size()==0) cout << "Nao existem utilizadores registados.\n"; else { cout << "#### Utilizadores ####\n"; cout << "--------------------------------------------------------------- \n"; cout << "| ID | Nome | Activo |\n"; cout << "--------------------------------------------------------------- \n"; cout << setiosflags(ios::left); for (i=1;i<=users.size();i++) { User userTemp=getUserByID(i); cout << "| " << setw(MAXIDLENGTH) << userTemp.getID() << "| " << setw(MAXNAMELENGTH) << userTemp.getName() << "| "; if (userTemp.isActive()) cout << setw(8) << "Sim" << "|\n"; else cout << setw(8) << "Nao" << "|\n"; } cout << resetiosflags(ios::left); cout << "--------------------------------------------------------------- \n"; } }