// 1.user not in meeting // 2.user in meeting and not is admin -->set offline // 3.user in meeting and is admin --> destroy meeting int Msm::logout(string id) { if (!have_member(id)) { LOG(LOG_ERROR, "%s not login.", id.c_str()); return -1; } Member *m = get_member(id); int fd = m->get_sockfd(); if (fd != -1) { if (epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &ev) == -1) { LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", fd, strerror(errno)); } close(fd); m->set_sockfd(-1); LOG(LOG_INFO, "close sockfd: %d", fd); } if (m->get_meeting() != NULL) { if (m->get_meeting()->get_admin() == id) { destroy_meeting(m->get_meeting()->get_id()); } else { m->set_offline(); } } return unregister_member(id); }
string filter(user* up,vector<string> myvec) { string names; //getline(cin,names); vector<string> user_names; for(int i=1;i<myvec.size();i++) user_names.push_back(myvec[i]); for(int i=0;i<user_names.size();i++) if(!have_member(user_names[i])) return "this user does not exist : "+user_names[i]+'\n'; if(up==NULL) return "You are not signed in.\n"; return up->filter(user_names)+'\n'; }
// 1. user login first // 2. old user not in meeting and online --> send msg to he and replace he // 3. old user not in meeting and offline --> replace he and online // 4. old user in meeting and is not admin and online --> send msg to // he and replace he and send meeting info to new user and online and // into meeting and tell other user // 5. old user in meeting and is admin and online --> same 4 // 6. old user in meeting and is not admin and offline --> 4 (don't // send msg to he) // 7. old user in meeting and is admin and offline --> same 4(dont't // sned msg to he) int Msm::login(string id, string name, int sockfd) { Member *m = new Member(id, name); Meeting *meeting = NULL; if (have_member(id)) { Member *m_old = get_member(id); m->set_volum(m_old->get_volum()); m->set_status(m_old->get_status()); // close old sockfd int old_fd; old_fd = m_old->get_sockfd(); // send msg to old user if (m_old->is_online()) { MsmReqMsg msg(id, "close", "duplicate user"); msg.send_msg(old_fd); } #if 1 if (old_fd != -1 && old_fd != sockfd) { if (epoll_ctl(epollfd, EPOLL_CTL_DEL, old_fd, &ev) == -1) { LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", old_fd, strerror(errno)); return errno; } close(old_fd); m_old->set_sockfd(-1); LOG(LOG_INFO, "close sockfd: %d", old_fd); } #endif // delete old user in meeting meeting = m_old->get_meeting(); if (meeting != NULL) { meeting->del_member(m_old); } // delete struct old user logout(m_old->get_id()); } register_member(m); m->set_sockfd(sockfd); m->set_online(); if (meeting != NULL) { /// TODO: send meeting info to user meeting->add_member(m); } LOG(LOG_DEBUG, "%s login", id.c_str()); return 0; }
string remove_user_from_card(user* up,vector <string> myvec) { if(myvec.size()!=3) return "Invalid input.\n"; int card_id=stoint(myvec[1]); string username=myvec[2]; if(!have_member(username)) return "this user does not exist\n"; if(up==NULL) return "You are not signed in.\n"; try { up->remove_user_from_card(card_id,username); return "Done.\n"; } catch(Bad_Access ex) { return "you are not in aboard.\n"; } catch(Bad_card_Existance ex2) { return "This card does not exist in this board.\n"; } }