forked from slomkowski/mumsi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMumbleChannelJoiner.cpp
58 lines (43 loc) · 1.72 KB
/
MumbleChannelJoiner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#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")){
//std::vector<ChannelEntry> *channels = new std::vector<ChannelEntry>();
}
std::vector<mumble::MumbleChannelJoiner::ChannelEntry> mumble::MumbleChannelJoiner::channels;
void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) {
boost::smatch s;
ChannelEntry ent;
logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id);
ent.name = channel_name;
ent.id = channel_id;
channels.push_back(ent);
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);
}
}
/* 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);
}
}
void mumble::MumbleChannelJoiner::joinOtherChannel(mumble::MumbleCommunicator *mc, std::string channelNameRegex) {
this->channelNameRegex = boost::regex(channelNameRegex);
findJoinChannel(mc);
}