Example #1
0
SessionDescription SessionServer::getSessionDescriptionById(const QString &id) const
{
	for(Session *s : _sessions) {
		if(s->id() == id)
			return SessionDescription(*s);
	}

	return SessionDescription();
}
Example #2
0
SessionDescription SessionServer::getSessionDescriptionById(const QString &id, bool getExtended, bool getUsers) const
{
	for(SessionState *s : _sessions) {
		if(s->id() == id)
			return SessionDescription(*s, getExtended, getUsers);
	}

	if(_store)
		return _store->getSessionDescriptionById(id);

	return SessionDescription();
}
Example #3
0
SessionDescription Hibernation::getSessionDescriptionById(const QString &id) const
{
	for(const SessionDescription &sd : _sessions)
		if(sd.id == id)
			return sd;
	return SessionDescription();
}
Example #4
0
/**
 * @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();
}
Example #5
0
QList<SessionDescription> SessionServer::sessions() const
{
	QList<SessionDescription> descs;

	for(const Session *s : _sessions)
		descs.append(SessionDescription(*s));

	return descs;
}
Example #6
0
/**
 * @brief Handle the move of a client from the lobby to a session
 * @param session
 * @param client
 */
void SessionServer::moveFromLobby(Session *session, Client *client)
{
	logger::debug() << client << "moved from lobby to" << session;
	Q_ASSERT(_lobby.contains(client));
	_lobby.removeOne(client);

	// the session handles disconnect events from now on
	disconnect(client, &Client::loggedOff, this, &SessionServer::lobbyDisconnectedEvent);

	emit userLoggedIn();
	emit sessionChanged(SessionDescription(*session));
}
Example #7
0
QList<SessionDescription> SessionServer::sessions() const
{
	QList<SessionDescription> descs;

	foreach(const SessionState *s, _sessions)
		descs.append(SessionDescription(*s));

	if(_store)
		descs += _store->sessions();

	return descs;
}
Example #8
0
void SessionServer::initSession(SessionState *session)
{
	session->setHistoryLimit(_historyLimit);
	session->setPersistenceAllowed(allowPersistentSessions());

	connect(session, &SessionState::userConnected, this, &SessionServer::moveFromLobby);
	connect(session, &SessionState::userDisconnected, this, &SessionServer::userDisconnectedEvent);
	connect(session, &SessionState::sessionAttributeChanged, [this](SessionState *ses) { emit sessionChanged(SessionDescription(*ses)); });

	_sessions.append(session);

	emit sessionCreated(session);
	emit sessionChanged(SessionDescription(*session));
}
Example #9
0
void SessionServer::initSession(Session *session)
{
	session->setHistoryLimit(_historyLimit);
	session->setPersistenceAllowed(allowPersistentSessions());
	session->setWelcomeMessage(welcomeMessage());

	connect(session, &Session::userConnected, this, &SessionServer::moveFromLobby);
	connect(session, &Session::userDisconnected, this, &SessionServer::userDisconnectedEvent);
	connect(session, &Session::sessionAttributeChanged, [this](Session *ses) { emit sessionChanged(SessionDescription(*ses)); });

	connect(session, &Session::requestAnnouncement, this, &SessionServer::announceSession);
	connect(session, &Session::requestUnlisting, this, &SessionServer::unlistSession);

	_sessions.append(session);

	emit sessionCreated(session);
	emit sessionChanged(SessionDescription(*session));
}
Example #10
0
/**
 * @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();
}