Server::Server(CreateUserLookupFn *createUserLookup, QObject *parent) : QObject(parent) { group = new User_Group(createUserLookup, this); connect(group, SIGNAL(userAuthenticated()), this, SLOT(userAuthenticated())); connect(group, SIGNAL(userDisconnected()), this, SLOT(userDisconnected())); connect(&listener, SIGNAL(newConnection()), this, SLOT(acceptNewConnection())); sessionUpdateTimer.setSingleShot(true); connect(&sessionUpdateTimer, SIGNAL(timeout()), this, SLOT(updateNextSession())); }
/** * @brief Handle client disconnect from a session * * The session takes care of the client itself. Here, we clean up after the session * in case it needs to be closed. * @param session */ void SessionServer::userDisconnectedEvent(SessionState *session) { bool delSession = false; if(session->userCount()==0) { logger::debug() << session << "Last user left"; bool hasSnapshot = session->mainstream().hasSnapshot(); // A non-persistent session is deleted when the last user leaves // A persistent session can also be deleted if it doesn't contain a snapshot point. if(!hasSnapshot || !session->isPersistent()) { if(hasSnapshot) logger::info() << session << "Closing non-persistent session"; else logger::info() << session << "Closing persistent session due to lack of snapshot point!"; delSession = true; } // If the hibernatable flag is set, it means we want to put the session // into storage as soon as possible delSession |= session->isHibernatable(); } if(delSession) destroySession(session); else emit sessionChanged(SessionDescription(*session)); emit userDisconnected(); }
/** * @brief Handle client disconnect while the client was not yet logged in * @param client */ void SessionServer::lobbyDisconnectedEvent(Client *client) { logger::debug() << "non-logged in client from" << client->peerAddress() << "removed"; Q_ASSERT(_lobby.contains(client)); _lobby.removeOne(client); client->deleteLater(); emit userDisconnected(); }
void ChatChannel::removeUser(QString channelId, QString userId) { if (channelId == _id) { emit userDisconnected(getUser(userId)); _users.remove(userId); emit usersUpdated(); } }
ClientUser::ClientUser(MyServer *server, int socketfd, QMap<QString, QString> *d):QObject() { this->server = server; this->dictionary = d; socket=new QTcpSocket(); socket->setSocketDescriptor(socketfd); //this->setSocketDescriptor(socketfd); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); // connect(this, SIGNAL(destroyed()), this, SLOT(userDisconnected())); connect(socket, SIGNAL(disconnected()), this,SLOT(userDisconnected())); }
void ChatCore::connection_established() { worker = std::unique_ptr<Worker>( new Worker(this, &this->msg_queue, &this->mutex)); // connect(worker.get(), SIGNAL(authorization_failed()), // SLOT(authorization_failed())); connect(worker.get(), SIGNAL(online_users(QString)), SIGNAL(onlineUsers(QString))); connect(worker.get(), SIGNAL(msg_from_user(QString, QString)), SIGNAL(newMess(QString, QString))); connect(worker.get(), SIGNAL(user_connected(QString)), SIGNAL(userConnected(QString))); connect(worker.get(), SIGNAL(user_disconnected(QString)), SIGNAL(userDisconnected(QString))); worker->start(); emit connected("Connected successfully"); }
/** * @brief Handle client disconnect from a session * * The session takes care of the client itself. Here, we clean up after the session * in case it needs to be closed. * @param session */ void SessionServer::userDisconnectedEvent(Session *session) { bool delSession = false; if(session->userCount()==0) { logger::debug() << session << "Last user left"; // A non-persistent session is deleted when the last user leaves // A persistent session can also be deleted if it doesn't contain a snapshot point. if(!session->isPersistent()) { logger::info() << session << "Closing non-persistent session"; logger::info() << session << "History size was" << session->mainstream().lengthInBytes() << "bytes"; delSession = true; } } if(delSession) destroySession(session); else emit sessionChanged(SessionDescription(*session)); emit userDisconnected(); }
void SessionState::removeUser(Client *user) { Q_ASSERT(_clients.contains(user)); if(user->isUploadingSnapshot()) { abandonSnapshotPoint(); } _clients.removeOne(user); _userids.release(user->id()); if(!_drawingctx[user->id()].penup) addToCommandStream(MessagePtr(new protocol::PenUp(user->id()))); addToCommandStream(MessagePtr(new protocol::UserLeave(user->id()))); // Make sure there is at least one operator in the session bool hasOp=false; foreach(const Client *c, _clients) { if(c->isOperator()) { hasOp=true; break; } } if(!hasOp && !_clients.isEmpty()) _clients.first()->grantOp(); // Reopen the session when the last user leaves if(_clients.isEmpty()) { setClosed(false); } user->deleteLater(); _lastEventTime = QDateTime::currentDateTime(); emit userDisconnected(this); }