diff --git a/CMakeLists.txt b/CMakeLists.txt index 77a6e96..ee6dbd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(SOURCE_FILES PjsuaCommunicator.hpp MumbleCommunicator.cpp MumbleCommunicator.hpp + MumbleChannelJoiner.cpp + MumbleChannelJoiner.hpp Configuration.cpp Configuration.hpp IncomingConnectionValidator.cpp diff --git a/MumbleChannelJoiner.cpp b/MumbleChannelJoiner.cpp new file mode 100644 index 0000000..30ad1b1 --- /dev/null +++ b/MumbleChannelJoiner.cpp @@ -0,0 +1,25 @@ +#include "MumbleChannelJoiner.hpp" + +#include +using namespace std; + +mumble::MumbleChannelJoiner::MumbleChannelJoiner(std::string channelNameRegex) : channelNameRegex(boost::regex(channelNameRegex)), +logger(log4cpp::Category::getInstance("MumbleChannelJoiner")){ +} + +void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) { + boost::smatch s; + logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id); + + + if(boost::regex_match(channel_name, s, channelNameRegex)) { + this->channel_id = channel_id; + } +} + +void mumble::MumbleChannelJoiner::maybeJoinChannel(mumble::MumbleCommunicator *mc) { + if(channel_id > -1) { + mc->joinChannel(channel_id); + } +} + diff --git a/MumbleChannelJoiner.hpp b/MumbleChannelJoiner.hpp new file mode 100644 index 0000000..356d022 --- /dev/null +++ b/MumbleChannelJoiner.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include +#include +#include "MumbleCommunicator.hpp" + +namespace mumble { + class MumbleChannelJoiner : boost::noncopyable { + public: + MumbleChannelJoiner(std::string channelNameRegex); + + void checkChannel(std::string channel_name, int channel_id); + void maybeJoinChannel(mumble::MumbleCommunicator *mc); + + private: + log4cpp::Category &logger; + boost::regex channelNameRegex; + int channel_id; + }; +} diff --git a/MumbleCommunicator.cpp b/MumbleCommunicator.cpp index 5a72378..55009a5 100644 --- a/MumbleCommunicator.cpp +++ b/MumbleCommunicator.cpp @@ -17,6 +17,28 @@ namespace mumble { uint32_t pcm_data_size) override { communicator->onIncomingPcmSamples(sessionId, sequenceNumber, pcm_data, pcm_data_size); } + + virtual void channelState( + std::string name, + int32_t channel_id, + int32_t parent, + std::string description, + std::vector links, + std::vector inks_add, + std::vector links_remove, + bool temporary, + int32_t position) override { + communicator->onIncomingChannelState(name, channel_id); + } + + virtual void serverSync( + std::string welcome_text, + int32_t session, + int32_t max_bandwidth, + int64_t permissions) override { + communicator->onServerSync(); + }; + }; } @@ -51,3 +73,7 @@ mumble::MumbleCommunicator::~MumbleCommunicator() { void mumble::MumbleCommunicator::sendTextMessage(std::string message) { mum->sendTextMessage(message); } + +void mumble::MumbleCommunicator::joinChannel(int channel_id) { + mum->joinChannel(channel_id); +} diff --git a/MumbleCommunicator.hpp b/MumbleCommunicator.hpp index 6eb752e..0b6be5b 100644 --- a/MumbleCommunicator.hpp +++ b/MumbleCommunicator.hpp @@ -38,8 +38,18 @@ namespace mumble { */ std::function onIncomingPcmSamples; + /** + * This callback is called when a channel state message (e.g. Channel + * information) is received. Arguments: channel_id, name + */ + std::function onIncomingChannelState; + + std::function onServerSync; + void sendTextMessage(std::string message); + void joinChannel(int channel_id); + public: boost::asio::io_service &ioService; diff --git a/config.ini.example b/config.ini.example index 5a02a2b..34630ab 100644 --- a/config.ini.example +++ b/config.ini.example @@ -13,3 +13,4 @@ host = example.org port = 64738 user = mumsi password = foobar +channelNameExpression = diff --git a/main.cpp b/main.cpp index 443f3be..a31b416 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include "PjsuaCommunicator.hpp" #include "MumbleCommunicator.hpp" #include "IncomingConnectionValidator.hpp" +#include "MumbleChannelJoiner.hpp" #include "Configuration.hpp" #include @@ -32,6 +33,8 @@ int main(int argc, char *argv[]) { mumble::MumbleCommunicator mumbleCommunicator(ioService); + mumble::MumbleChannelJoiner mumbleChannelJoiner(conf.getString("mumble.channelNameExpression")); + using namespace std::placeholders; pjsuaCommunicator.onIncomingPcmSamples = std::bind( &mumble::MumbleCommunicator::sendPcmSamples, @@ -47,6 +50,17 @@ int main(int argc, char *argv[]) { &pjsuaCommunicator, _1, _2, _3, _4); + mumbleCommunicator.onIncomingChannelState = std::bind( + &mumble::MumbleChannelJoiner::checkChannel, + &mumbleChannelJoiner, + _1, _2); + + mumbleCommunicator.onServerSync = std::bind( + &mumble::MumbleChannelJoiner::maybeJoinChannel, + &mumbleChannelJoiner, + &mumbleCommunicator); + + mumbleCommunicator.connect( conf.getString("mumble.user"), conf.getString("mumble.password"),