MumbleChannelJoiner.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "MumbleChannelJoiner.hpp"
  2. #include <boost/algorithm/string.hpp>
  3. using namespace std;
  4. mumble::MumbleChannelJoiner::MumbleChannelJoiner(std::string channelNameRegex) : channelNameRegex(boost::regex(channelNameRegex)),
  5. logger(log4cpp::Category::getInstance("MumbleChannelJoiner")){
  6. //std::vector<ChannelEntry> *channels = new std::vector<ChannelEntry>();
  7. }
  8. std::vector<mumble::MumbleChannelJoiner::ChannelEntry> mumble::MumbleChannelJoiner::channels;
  9. void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) {
  10. boost::smatch s;
  11. ChannelEntry ent;
  12. logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id);
  13. ent.name = channel_name;
  14. ent.id = channel_id;
  15. channels.push_back(ent);
  16. if(boost::regex_match(channel_name, s, channelNameRegex)) {
  17. this->channel_id = channel_id;
  18. }
  19. }
  20. void mumble::MumbleChannelJoiner::maybeJoinChannel(mumble::MumbleCommunicator *mc) {
  21. if(channel_id > -1) {
  22. mc->joinChannel(channel_id);
  23. }
  24. }
  25. /* This is a secondary channel-switching object that relys on updates to the
  26. * class variable 'channels' for the channel list from the server.
  27. */
  28. void mumble::MumbleChannelJoiner::findJoinChannel(mumble::MumbleCommunicator *mc) {
  29. boost::smatch s;
  30. int found = -1;
  31. for(std::vector<ChannelEntry>::iterator it = channels.begin(); it != channels.end(); ++it) {
  32. if(boost::regex_match(it->name, s, channelNameRegex)) {
  33. found = it->id;
  34. }
  35. }
  36. if(found > -1) {
  37. mc->joinChannel(found);
  38. }
  39. }
  40. void mumble::MumbleChannelJoiner::joinOtherChannel(mumble::MumbleCommunicator *mc, std::string channelNameRegex) {
  41. this->channelNameRegex = boost::regex(channelNameRegex);
  42. findJoinChannel(mc);
  43. }