2015-11-30 23:42:37 +01:00
|
|
|
#include "MumbleChannelJoiner.hpp"
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
mumble::MumbleChannelJoiner::MumbleChannelJoiner(std::string channelNameRegex) : channelNameRegex(boost::regex(channelNameRegex)),
|
|
|
|
logger(log4cpp::Category::getInstance("MumbleChannelJoiner")){
|
2017-05-24 22:38:45 +02:00
|
|
|
//std::vector<ChannelEntry> *channels = new std::vector<ChannelEntry>();
|
2015-11-30 23:42:37 +01:00
|
|
|
}
|
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
std::vector<mumble::MumbleChannelJoiner::ChannelEntry> mumble::MumbleChannelJoiner::channels;
|
|
|
|
|
2015-11-30 23:42:37 +01:00
|
|
|
void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) {
|
|
|
|
boost::smatch s;
|
2017-05-24 22:38:45 +02:00
|
|
|
ChannelEntry ent;
|
2015-11-30 23:42:37 +01:00
|
|
|
logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id);
|
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
ent.name = channel_name;
|
|
|
|
ent.id = channel_id;
|
|
|
|
|
|
|
|
channels.push_back(ent);
|
2015-11-30 23:42:37 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 22:38:45 +02:00
|
|
|
/* This is a secondary channel-switching object that relys on updates to the
|
|
|
|
* class variable 'channels' for the channel list from the server.
|
|
|
|
*/
|
|
|
|
void mumble::MumbleChannelJoiner::findJoinChannel(mumble::MumbleCommunicator *mc) {
|
|
|
|
boost::smatch s;
|
|
|
|
|
|
|
|
int found = -1;
|
|
|
|
|
|
|
|
for(std::vector<ChannelEntry>::iterator it = channels.begin(); it != channels.end(); ++it) {
|
|
|
|
if(boost::regex_match(it->name, s, channelNameRegex)) {
|
|
|
|
found = it->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(found > -1) {
|
|
|
|
mc->joinChannel(found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|