예제 #1
0
void MumbleClient::disconnectAllStations()
{

    for(int i =0; i<_stations.size(); i++)
    {
        Station *s = _stations.at(i);
        if((s->_called_by == _session_id) &&
                (s->_in_call == 1) &&
                (s->_conference_id == _channel_id))
        {
            s->_called_by = 0;
            s->_in_call = 0;
            s->_conference_id = -1;

            MumbleProto::UserState us;
            us.set_channel_id(1);
            us.set_session(s->_id);
            us.set_actor(_session_id);
            us.set_self_mute(true);
            us.set_self_deaf(true);
            int size = us.ByteSize();
            quint8 data[size];
            us.SerializeToArray(data,size);
            this->sendMessage(data,9,size);

        }
    }


}
예제 #2
0
int MumbleClient::disconnectStation(QString radio_id)
{
    int sessid = 0;
    for(int i =0; i<_stations.size(); i++)
    {
        Station *s = _stations.at(i);
        if(s->_radio_id == radio_id)
        {
            sessid = s->_id;
            if(s->_conference_id != _channel_id)
                return -2;
            if(s->_called_by != _session_id)
                return -3;
            s->_called_by = 0;
            s->_in_call = 0;
            s->_conference_id = -1;
        }
    }
    if(sessid ==0)
        return -1;
    MumbleProto::UserState us;
    us.set_channel_id(1);
    us.set_session(sessid);
    us.set_actor(_session_id);
    us.set_self_mute(true);
    us.set_self_deaf(true);
    int size = us.ByteSize();
    quint8 data[size];
    us.SerializeToArray(data,size);
    this->sendMessage(data,9,size);
    return 0;
}
예제 #3
0
void MumbleClient::processServerSync(quint8 *message, quint64 size)
{
    MumbleProto::ServerSync sync;
    sync.ParseFromArray(message,size);
    _session_id = sync.session();
    _max_bandwidth = sync.max_bandwidth();
    std::string welcome = sync.welcome_text();
    _synchronized = true;
    qDebug() << QString::fromStdString(welcome)
             << " max bandwidth: " << _max_bandwidth
             << " session: " << QString::number(_session_id);
#ifndef NO_CRYPT
    createChannel();
#endif
    MumbleProto::UserState us;
    us.set_session(_session_id);
    us.set_actor(_session_id);
    us.set_self_deaf(true);
    us.set_self_mute(true);
    us.set_comment(_settings->_callsign.toStdString().c_str());
    int msize = us.ByteSize();
    quint8 data[msize];
    us.SerializeToArray(data,msize);
    this->sendMessage(data,9,msize);
}
예제 #4
0
	void MumBotState::updateUserState(MumbleProto::UserState msg, bool del) {
        std::lock_guard<std::mutex> lock(userStateMutex_);
		uint32_t id = msg.session();

		if (userStates_.count(id) == 0) { //new user state
			userStates_[id] = msg;
		}
		else if (!del) { //user state update
			MumbleProto::UserState cstate = userStates_[id];
			cstate.MergeFrom(msg);
			userStates_[id] = cstate;

		}
		else {
			userStates_.erase(id);
		}

		std::cout << userStates_[id].name() << " " <<userStates_[id].session() << "\n";
	}
예제 #5
0
void MumbleClient::SetChannel(const std::string& channelName)
{
	if (!m_connectionInfo.isConnected)
	{
		return;
	}

	if (channelName == m_curManualChannel)
	{
		return;
	}

	m_curManualChannel = channelName;

	// check if the channel already exists
	std::wstring wname = ToWide(channelName);

	for (const auto& channel : m_state.GetChannels())
	{
		if (channel.second.GetName() == wname)
		{
			// join the channel
			MumbleProto::UserState state;
			state.set_session(m_state.GetSession());
			state.set_channel_id(channel.first);

			Send(MumbleMessageType::UserState, state);
			return;
		}
	}

	// it does not, create the channel
	{
		MumbleProto::ChannelState chan;
		chan.set_parent(0);
		chan.set_name(channelName);
		chan.set_temporary(true);

		Send(MumbleMessageType::ChannelState, chan);
	}
}
예제 #6
0
void MumbleClient::joinChannel(int id)
{
    MumbleProto::UserState us;
    us.set_session(_session_id);
    us.set_self_deaf(false);
    us.set_self_mute(false);
    us.set_channel_id(id);
    int size = us.ByteSize();
    quint8 data[size];
    us.SerializeToArray(data,size);
    this->sendMessage(data,9,size);
    _channel_id = id;

}
예제 #7
0
void MumbleClient::setMute(bool mute)
{
    while(!_synchronized)
    {
        usleep(10000);
        QCoreApplication::processEvents();
    }
    MumbleProto::UserState us;
    us.set_self_deaf(mute);
    us.set_self_mute(mute);
    us.set_session(_session_id);
    us.set_actor(_session_id);
    int msize = us.ByteSize();
    quint8 mdata[msize];
    us.SerializeToArray(mdata,msize);
    this->sendMessage(mdata,9,msize);
}
예제 #8
0
void MumbleClient::disconnectFromCall()
{
    if(_channel_id < 2)
    {
        qDebug() << "something went wrong";
        return;
    }
    _temp_channel_name = "";
    MumbleProto::UserState us;
    us.set_channel_id(1);
    us.set_session(_session_id);
    us.set_self_mute(true);
    us.set_self_deaf(true);
    int size = us.ByteSize();
    quint8 data[size];
    us.SerializeToArray(data,size);
    this->sendMessage(data,9,size);
}
예제 #9
0
QString MumbleClient::createChannel(QString channel_name)
{
    QString name;
    if(channel_name == "")
    {
        int rand_len = 8;
        char rand[9];
        genRandomStr(rand,rand_len);
        name = QString::fromLocal8Bit(rand);
    }
    else
    {
        name = channel_name;
    }
    _temp_channel_name = name;
    MumbleProto::ChannelState channel;
    channel.set_parent(0);
    channel.set_name(name.toStdString());
    channel.set_temporary(true);
    int size = channel.ByteSize();
    quint8 data[size];
    channel.SerializeToArray(data,size);
    quint16 type = 7;
    this->sendMessage(data,type,size);
    emit channelName(_temp_channel_name);
    MumbleProto::UserState us;
    us.set_self_deaf(false);
    us.set_self_mute(false);
    us.set_session(_session_id);
    us.set_actor(_session_id);
    int msize = us.ByteSize();
    quint8 mdata[msize];
    us.SerializeToArray(mdata,msize);
    this->sendMessage(mdata,9,msize);
    return name;
}
예제 #10
0
파일: Messages.cpp 프로젝트: Keridos/mumble
void MainWindow::msgUserState(const MumbleProto::UserState &msg) {
	ACTOR_INIT;
	SELF_INIT;
	ClientUser *pDst = ClientUser::get(msg.session());
	bool bNewUser = false;

	if (! pDst) {
		if (msg.has_name()) {
			pDst = pmModel->addUser(msg.session(), u8(msg.name()));
			bNewUser = true;
		} else {
			return;
		}
	}

	if (msg.has_user_id())
		pmModel->setUserId(pDst, msg.user_id());

	if (msg.has_hash()) {
		pmModel->setHash(pDst, u8(msg.hash()));
		const QString &name = Database::getFriend(pDst->qsHash);
		if (! name.isEmpty())
			pmModel->setFriendName(pDst, name);
		if (Database::isLocalMuted(pDst->qsHash))
			pDst->setLocalMute(true);
		if (Database::isLocalIgnored(pDst->qsHash))
			pDst->setLocalIgnore(true);
	}

	if (bNewUser)
		g.l->log(Log::UserJoin, tr("%1 connected.").arg(Log::formatClientUser(pDst, Log::Source)));

	if (msg.has_self_deaf() || msg.has_self_mute()) {
		if (msg.has_self_mute())
			pDst->setSelfMute(msg.self_mute());
		if (msg.has_self_deaf())
			pDst->setSelfDeaf(msg.self_deaf());

		if (pSelf && pDst != pSelf && (pDst->cChannel == pSelf->cChannel)) {
			QString name = pDst->qsName;
			if (pDst->bSelfMute && pDst->bSelfDeaf)
				g.l->log(Log::OtherSelfMute, tr("%1 is now muted and deafened.").arg(Log::formatClientUser(pDst, Log::Target)));
			else if (pDst->bSelfMute)
				g.l->log(Log::OtherSelfMute, tr("%1 is now muted.").arg(Log::formatClientUser(pDst, Log::Target)));
			else
				g.l->log(Log::OtherSelfMute, tr("%1 is now unmuted.").arg(Log::formatClientUser(pDst, Log::Target)));
		}
	}

	if (msg.has_recording()) {
		pDst->setRecording(msg.recording());

		// Do nothing during initial sync
		if (pSelf) {
			if (pDst == pSelf) {
				if (pDst->bRecording) {
					g.l->log(Log::Recording, tr("Recording started"));
				} else {
					g.l->log(Log::Recording, tr("Recording stopped"));
				}
			} else if (pDst->cChannel->allLinks().contains(pSelf->cChannel)) {
				if (pDst->bRecording) {
					g.l->log(Log::Recording, tr("%1 started recording.").arg(Log::formatClientUser(pDst, Log::Source)));
				} else {
					g.l->log(Log::Recording, tr("%1 stopped recording.").arg(Log::formatClientUser(pDst, Log::Source)));
				}
			}
		}
	}

	if (msg.has_priority_speaker()) {
		if (pSelf && ((pDst->cChannel == pSelf->cChannel) || (pSrc == pSelf))) {
			if ((pSrc == pDst) && (pSrc == pSelf)) {
				if (pDst->bPrioritySpeaker) {
					g.l->log(Log::YouMuted, tr("You revoked your priority speaker status."));
				} else  {
					g.l->log(Log::YouMuted, tr("You assumed priority speaker status."));
				}
			} else if ((pSrc != pSelf) && (pDst == pSelf) ) {
				if (pDst->bPrioritySpeaker) {
					g.l->log(Log::YouMutedOther, tr("%1 revoked your priority speaker status.").arg(Log::formatClientUser(pSrc, Log::Source)));
				} else  {
					g.l->log(Log::YouMutedOther, tr("%1 gave you priority speaker status.").arg(Log::formatClientUser(pSrc, Log::Source)));
				}
			} else if ((pSrc == pSelf) && (pSrc != pDst)) {
				if (pDst->bPrioritySpeaker) {
					g.l->log(Log::YouMutedOther, tr("You revoked priority speaker status for %1.").arg(Log::formatClientUser(pDst, Log::Target)));
				} else  {
					g.l->log(Log::YouMutedOther, tr("You gave priority speaker status to %1.").arg(Log::formatClientUser(pDst, Log::Target)));
				}
			} else if ((pSrc == pDst) && (pSrc != pSelf)) {
				if (pDst->bPrioritySpeaker) {
					g.l->log(Log::OtherMutedOther, tr("%1 revoked own priority speaker status.").arg(Log::formatClientUser(pSrc, Log::Source)));
				} else {
					g.l->log(Log::OtherMutedOther, tr("%1 assumed priority speaker status.").arg(Log::formatClientUser(pSrc, Log::Source)));
				}
			} else if ((pSrc != pSelf) && (pDst != pSelf)) {
				if (pDst->bPrioritySpeaker) {
					g.l->log(Log::OtherMutedOther, tr("%1 revoked priority speaker status for %2.").arg(Log::formatClientUser(pSrc, Log::Source), Log::formatClientUser(pDst, Log::Target)));
				} else if (!pDst->bPrioritySpeaker) {
					g.l->log(Log::OtherMutedOther, tr("%1 gave priority speaker status to %2.").arg(Log::formatClientUser(pSrc, Log::Source), Log::formatClientUser(pDst, Log::Target)));
				}
			}
		}

		pDst->setPrioritySpeaker(msg.priority_speaker());
	}

	if (msg.has_deaf() || msg.has_mute() || msg.has_suppress()) {
		if (msg.has_mute())
			pDst->setMute(msg.mute());
		if (msg.has_deaf())
			pDst->setDeaf(msg.deaf());
		if (msg.has_suppress())
			pDst->setSuppress(msg.suppress());

		if (pSelf && ((pDst->cChannel == pSelf->cChannel) || (pSrc == pSelf))) {
			if (pDst == pSelf) {
				if (msg.has_mute() && msg.has_deaf() && pDst->bMute && pDst->bDeaf) {
					g.l->log(Log::YouMuted, tr("You were muted and deafened by %1.").arg(Log::formatClientUser(pSrc, Log::Source)));
				} else if (msg.has_mute() && msg.has_deaf() && !pDst->bMute && !pDst->bDeaf) {
					g.l->log(Log::YouMuted, tr("You were unmuted and undeafened by %1.").arg(Log::formatClientUser(pSrc, Log::Source)));
				} else {
					if (msg.has_mute()) {
						if (pDst->bMute)
							g.l->log(Log::YouMuted, tr("You were muted by %1.").arg(Log::formatClientUser(pSrc, Log::Source)));
						else
							g.l->log(Log::YouMuted, tr("You were unmuted by %1.").arg(Log::formatClientUser(pSrc, Log::Source)));
					}

					if (msg.has_deaf()) {
						if (!pDst->bDeaf)
							g.l->log(Log::YouMuted, tr("You were undeafened by %1.").arg(Log::formatClientUser(pSrc, Log::Source)));
					}
				}

				if (msg.has_suppress()) {
					if (pDst->bSuppress)
						g.l->log(Log::YouMuted, tr("You were suppressed."));
					else {
						if (msg.has_channel_id())
							g.l->log(Log::YouMuted, tr("You were unsuppressed."));
						else
							g.l->log(Log::YouMuted, tr("You were unsuppressed by %1.").arg(Log::formatClientUser(pSrc, Log::Source)));
					}
				}

				updateTrayIcon();
			} else if (pSrc == pSelf) {
				if (msg.has_mute() && msg.has_deaf() && pDst->bMute && pDst->bDeaf) {
					g.l->log(Log::YouMutedOther, tr("You muted and deafened %1.").arg(Log::formatClientUser(pDst, Log::Target)));
				} else if (msg.has_mute() && msg.has_deaf() && !pDst->bMute && !pDst->bDeaf) {
					g.l->log(Log::YouMutedOther, tr("You unmuted and undeafened %1.").arg(Log::formatClientUser(pDst, Log::Target)));
				} else {
					if (msg.has_mute()) {
						if (pDst->bMute)
							g.l->log(Log::YouMutedOther, tr("You muted %1.").arg(Log::formatClientUser(pDst, Log::Target)));
						else
							g.l->log(Log::YouMutedOther, tr("You unmuted %1.").arg(Log::formatClientUser(pDst, Log::Target)));
					}

					if (msg.has_deaf()) {
						if (!pDst->bDeaf)
							g.l->log(Log::YouMutedOther, tr("You undeafened %1.").arg(Log::formatClientUser(pDst, Log::Target)));
					}
				}

				if (msg.has_suppress()) {
					if (! msg.has_channel_id()) {
						if (pDst->bSuppress)
							g.l->log(Log::YouMutedOther, tr("You suppressed %1.").arg(Log::formatClientUser(pDst, Log::Target)));
						else
							g.l->log(Log::YouMutedOther, tr("You unsuppressed %1.").arg(Log::formatClientUser(pDst, Log::Target)));
					}
				}
			} else {
				if (msg.has_mute() && msg.has_deaf() && pDst->bMute && pDst->bDeaf) {
					g.l->log(Log::OtherMutedOther, tr("%1 muted and deafened by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
				} else if (msg.has_mute() && msg.has_deaf() && !pDst->bMute && !pDst->bDeaf) {
					g.l->log(Log::OtherMutedOther, tr("%1 unmuted and undeafened by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
				} else {
					if (msg.has_mute()) {
						if (pDst->bMute)
							g.l->log(Log::OtherMutedOther, tr("%1 muted by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
						else
							g.l->log(Log::OtherMutedOther, tr("%1 unmuted by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
					}

					if (msg.has_deaf()) {
						if (!pDst->bDeaf)
							g.l->log(Log::OtherMutedOther, tr("%1 undeafened by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
					}
				}

				if (msg.has_suppress()) {
					if (! msg.has_channel_id()) {
						if (pDst->bSuppress)
							g.l->log(Log::OtherMutedOther, tr("%1 suppressed by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
						else
							g.l->log(Log::OtherMutedOther, tr("%1 unsuppressed by %2.").arg(Log::formatClientUser(pDst, Log::Target), Log::formatClientUser(pSrc, Log::Source)));
					}
				}
			}
		}
	}

	if (msg.has_channel_id()) {
		Channel *c = Channel::get(msg.channel_id());
		if (!c) {
			qWarning("MessageUserMove for unknown channel.");
			c = Channel::get(0);
		}

		Channel *old = pDst->cChannel;
		if (c != old) {
			bool log = pSelf && !((pDst == pSelf) && (pSrc == pSelf));

			if (log) {
				if (pDst == pSelf) {
					g.l->log(Log::ChannelJoin, tr("You were moved to %1 by %2.").arg(Log::formatChannel(c)).arg(Log::formatClientUser(pSrc, Log::Source)));
				} else if (pDst->cChannel == pSelf->cChannel) {
					if (pDst == pSrc)
						g.l->log(Log::ChannelLeave, tr("%1 moved to %2.").arg(Log::formatClientUser(pDst, Log::Target)).arg(Log::formatChannel(c)));
					else
						g.l->log(Log::ChannelLeave, tr("%1 moved to %2 by %3.").arg(Log::formatClientUser(pDst, Log::Target)).arg(Log::formatChannel(c)).arg(Log::formatClientUser(pSrc, Log::Source)));
				} else if (pSrc == pSelf) {
					g.l->log(Log::ChannelJoin, tr("You moved %1 to %2.").arg(Log::formatClientUser(pDst, Log::Target)).arg(Log::formatChannel(c)));
				}
			}

			pmModel->moveUser(pDst, c);

			if (pDst == pSelf) {
				g.mw->updateChatBar();
				qsDesiredChannel = c->getPath();
			}

			if (log && (pDst != pSelf) && (pDst->cChannel == pSelf->cChannel)) {
				if (pDst == pSrc)
					g.l->log(Log::ChannelJoin, tr("%1 entered channel.").arg(Log::formatClientUser(pDst, Log::Target)));
				else
					g.l->log(Log::ChannelJoin, tr("%1 moved in from %2 by %3.").arg(Log::formatClientUser(pDst, Log::Target)).arg(Log::formatChannel(old)).arg(Log::formatClientUser(pSrc, Log::Source)));

				if (pDst->bRecording)
					g.l->log(Log::Recording, tr("%1 is recording").arg(Log::formatClientUser(pDst, Log::Target)));
			}
		}
	}
	if (msg.has_name()) {
		QString oldName = pDst->qsName;
		QString newName = u8(msg.name());
		pmModel->renameUser(pDst, newName);
		if (! oldName.isNull() && oldName != newName) {
			g.l->log(Log::UserRenamed, tr("%1 renamed to %2.").arg(Log::formatClientUser(pDst, Log::Target, oldName),
				Log::formatClientUser(pDst, Log::Target)));
		}
	}
	if (msg.has_texture_hash()) {
		pDst->qbaTextureHash = blob(msg.texture_hash());
		pDst->qbaTexture = QByteArray();
		g.o->verifyTexture(pDst);
	}
	if (msg.has_texture()) {
		pDst->qbaTexture = blob(msg.texture());
		if (pDst->qbaTexture.isEmpty()) {
			pDst->qbaTextureHash = QByteArray();
		} else {
			pDst->qbaTextureHash = sha1(pDst->qbaTexture);
			Database::setBlob(pDst->qbaTextureHash, pDst->qbaTexture);
		}
		g.o->verifyTexture(pDst);
	}
	if (msg.has_comment_hash())
		pmModel->setCommentHash(pDst, blob(msg.comment_hash()));
	if (msg.has_comment())
		pmModel->setComment(pDst, u8(msg.comment()));
	if (msg.icons_size()) {
		QList<QByteArray> ql;
		for (int i=0;i<msg.icons_size();++i) {
			ql << blob(msg.icons(i));
		}
		pmModel->setIcons(pDst, ql);
	}
}
예제 #11
0
void MumbleClient::processUserState(quint8 *message, quint64 size)
{

    MumbleProto::UserState us;
    us.ParseFromArray(message,size);
    if((_session_id==-1) && (us.has_channel_id()))
    {
        _channel_id = us.channel_id();
        qDebug() << " Joined channel: " << _channel_id;

    }
    if(us.session() == _session_id)
    {
        if(us.has_channel_id())
        {
            _channel_id = us.channel_id();
            qDebug() << " Joined channel: " << _channel_id;
            if(_channel_id > 1)
            {
                emit channelReady(_channel_id);
            }
        }
        for(int i=0; i < _stations.size(); i++)
        {
            Station *s = _stations.at(i);
            if(s->_id == _session_id)
            {

                delete s;
                s = NULL;
                _stations.remove(i);
            }
        }
    }
    else
    {
        bool set_station = false;
        for(int i=0; i < _stations.size(); i++)
        {
            Station *s = _stations.at(i);
            if(s->_id == us.session())
            {
                s->_conference_id = us.channel_id();

                if(us.has_self_mute())
                    s->_mute = us.self_mute();
                if(us.has_deaf())
                    s->_deaf = us.self_deaf();
                if(us.has_comment())
                    s->_callsign = QString::fromStdString(us.comment());
                set_station = true;
            }
        }
        if(!set_station)
        {
            Station *s = new Station;
            s->_id = us.session();
            s->_radio_id = QString::fromStdString(us.name());
            s->_conference_id = us.channel_id();

            if(us.has_self_mute())
                s->_mute = us.self_mute();
            if(us.has_deaf())
                s->_deaf = us.self_deaf();
            if(us.has_comment())
                s->_callsign = QString::fromStdString(us.comment());
            _stations.push_back(s);
            emit newStation(s);
        }
    }
    /* Just debug code
    for(int i = 0;i < _stations.size();i++)
    {
        Station *s = _stations.at(i);
        qDebug() << "Session: " << QString::number(s->_id)
                 << " radio_id: " << s->_radio_id << " channel: "
                 << QString::number(s->_conference_id) << s->_callsign;
    }
    */

    StationList sl;
    for(int i =0; i<_stations.size(); ++i)
    {
        sl.append(*(_stations.at(i)));
    }
    emit onlineStations(sl);

}