diff --git a/.gitignore b/.gitignore index 4286771..da3351e 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ build/ # IntelliJ *.iml .idea/ + +# Boost +include/boost/ diff --git a/include/mumlib.hpp b/include/mumlib.hpp index 95afe02..ef84744 100644 --- a/include/mumlib.hpp +++ b/include/mumlib.hpp @@ -50,10 +50,18 @@ namespace mumlib { void sendAudioData(int16_t *pcmData, int pcmLength); + void sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength); + void sendTextMessage(std::string message); void joinChannel(int channelId); + void sendVoiceTarget(int targetId, int channelId); + + void sendUserState(mumlib::UserState state, bool val); + + void sendUserState(mumlib::UserState state, std::string value); + private: _Mumlib_Private *impl; }; diff --git a/include/mumlib/enums.hpp b/include/mumlib/enums.hpp index b4a9b43..ea189f9 100644 --- a/include/mumlib/enums.hpp +++ b/include/mumlib/enums.hpp @@ -45,4 +45,14 @@ namespace mumlib { OPUS }; + enum class UserState { + MUTE, + DEAF, + SUPPRESS, + SELF_MUTE, + SELF_DEAF, + COMMENT, + PRIORITY_SPEAKER, + RECORDING + }; } \ No newline at end of file diff --git a/src/CryptState.cpp b/src/CryptState.cpp index 0760374..467955d 100644 --- a/src/CryptState.cpp +++ b/src/CryptState.cpp @@ -181,7 +181,8 @@ bool mumlib::CryptState::decrypt(const unsigned char *source, unsigned char *dst #define SHIFTBITS 63 typedef uint64_t subblock; -#define SWAP64(x) ({register uint64_t __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;}) +// #define SWAP64(x) ({register uint64_t __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;}) +#define SWAP64(x) (__builtin_bswap64(x)) #define SWAPPED(x) SWAP64(x) typedef subblock keyblock[BLOCKSIZE]; diff --git a/src/mumlib.cpp b/src/mumlib.cpp index 08197d1..16e5c4b 100644 --- a/src/mumlib.cpp +++ b/src/mumlib.cpp @@ -152,7 +152,7 @@ namespace mumlib { links_remove.push_back(channelState.links_remove(i)); } - this->channelId = channel_id; + // this->channelId = channel_id; callback.channelState( channelState.name(), @@ -369,7 +369,7 @@ namespace mumlib { void Mumlib::disconnect() { if (not impl->externalIoService) { - impl->ioService.reset(); + impl->ioService.stop(); } if (impl->transport.getConnectionState() != ConnectionState::NOT_CONNECTED) { impl->transport.disconnect(); @@ -390,6 +390,12 @@ namespace mumlib { impl->transport.sendEncodedAudioPacket(encodedData, length); } + void Mumlib::sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength) { + uint8_t encodedData[5000]; + int length = impl->audio.encodeAudioPacket(targetId, pcmData, pcmLength, encodedData, 5000); + impl->transport.sendEncodedAudioPacket(encodedData, length); + } + void Mumlib::sendTextMessage(string message) { MumbleProto::TextMessage textMessage; textMessage.set_actor(impl->sessionId); @@ -404,4 +410,63 @@ namespace mumlib { impl->transport.sendControlMessage(MessageType::USERSTATE, userState); impl->channelId = channelId; } + + void Mumlib::sendVoiceTarget(int targetId, int channelId) { + MumbleProto::VoiceTarget voiceTarget; + MumbleProto::VoiceTarget_Target voiceTargetTarget; + voiceTargetTarget.set_channel_id(channelId); + voiceTargetTarget.set_children(true); + voiceTarget.set_id(targetId); + voiceTarget.add_targets()->CopyFrom(voiceTargetTarget); + impl->transport.sendControlMessage(MessageType::VOICETARGET, voiceTarget); + } + + void Mumlib::sendUserState(mumlib::UserState field, bool val) { + MumbleProto::UserState userState; + + switch (field) { + case UserState::MUTE: + userState.set_mute(val); + break; + case UserState::DEAF: + userState.set_deaf(val); + break; + case UserState::SUPPRESS: + userState.set_suppress(val); + break; + case UserState::SELF_MUTE: + userState.set_self_mute(val); + break; + case UserState::SELF_DEAF: + userState.set_self_deaf(val); + break; + case UserState::PRIORITY_SPEAKER: + userState.set_priority_speaker(val); + break; + case UserState::RECORDING: + userState.set_recording(val); + break; + default: + // in any other case, just ignore the command + return; + } + + impl->transport.sendControlMessage(MessageType::USERSTATE, userState); + } + + void Mumlib::sendUserState(mumlib::UserState field, std::string val) { + MumbleProto::UserState userState; + + switch (field) { + case UserState::COMMENT: + // TODO: if comment longer than 128 bytes, we need to set the SHA1 hash + userState.set_comment(val); + break; + default: + // in any other case, just ignore the command + return; + } + + impl->transport.sendControlMessage(MessageType::USERSTATE, userState); + } }