Teaspeak-Server/server/src/client/SpeakingClient.h

110 lines
4.6 KiB
C
Raw Normal View History

#pragma once
#include "ConnectedClient.h"
2020-11-28 11:09:25 +01:00
#include "./shared/WhisperHandler.h"
2020-11-07 13:17:51 +01:00
#include <json/json.h>
#include <src/rtc/lib.h>
2020-08-13 12:58:19 +02:00
namespace ts::server {
class VirtualServer;
class SpeakingClient : public ConnectedClient {
public:
struct VoicePacketFlags {
bool encrypted : 1;
bool head : 1;
bool fragmented : 1; /* used by MONO. IDK What this is */
bool new_protocol : 1;
char _unused : 4;
VoicePacketFlags() : encrypted{false}, head{false}, fragmented{false}, new_protocol{false}, _unused{0} { }
};
static_assert(sizeof(VoicePacketFlags) == 1);
enum HandshakeState {
BEGIN,
IDENTITY_PROOF,
SUCCEEDED
};
enum IdentityType : uint8_t {
TEASPEAK_FORUM,
TEAMSPEAK,
NICKNAME,
UNSET = 0xff
};
2020-11-07 13:17:51 +01:00
SpeakingClient(sql::SqlManager* a, const std::shared_ptr<VirtualServer>& b);
~SpeakingClient() override;
2020-08-13 12:58:19 +02:00
2020-11-28 11:09:25 +01:00
/* TODO: Remove this method. Currently only the music but uses that to broadcast his audio */
2020-08-13 12:58:19 +02:00
virtual void send_voice_packet(const pipes::buffer_view& /* voice packet data */, const VoicePacketFlags& /* flags */) = 0;
2020-11-28 11:09:25 +01:00
bool should_handle_voice_packet(size_t /* size */);
2020-08-13 12:58:19 +02:00
2020-11-28 11:09:25 +01:00
virtual bool shouldReceiveVoice(const std::shared_ptr<ConnectedClient> &sender);
2020-08-13 12:58:19 +02:00
bool shouldReceiveVoiceWhisper(const std::shared_ptr<ConnectedClient> &sender);
inline std::chrono::milliseconds takeSpokenTime() {
auto time = this->speak_time;
this->speak_time = std::chrono::milliseconds(0);
return time;
}
2020-11-28 11:09:25 +01:00
[[nodiscard]] inline whisper::WhisperHandler& whisper_handler() { return this->whisper_handler_; }
2020-08-13 12:58:19 +02:00
protected:
2021-01-28 20:59:15 +01:00
void tick_server(const std::chrono::system_clock::time_point &time) override;
2020-08-13 12:58:19 +02:00
public:
void updateChannelClientProperties(bool channel_lock, bool notify) override;
protected:
command_result handleCommand(Command &command) override;
public:
2020-11-07 13:17:51 +01:00
virtual void processJoin();
2020-08-13 12:58:19 +02:00
void processLeave();
virtual command_result handleCommandHandshakeBegin(Command&);
virtual command_result handleCommandHandshakeIdentityProof(Command &);
virtual command_result handleCommandClientInit(Command&);
2020-11-07 13:17:51 +01:00
virtual command_result handleCommandRtcSessionDescribe(Command &command);
virtual command_result handleCommandRtcSessionReset(Command &command);
virtual command_result handleCommandRtcIceCandidate(Command &);
virtual command_result handleCommandRtcBroadcast(Command &); /* Old method used 'till 1.5.0b4 */
virtual command_result handleCommandBroadcastAudio(Command &);
virtual command_result handleCommandBroadcastVideo(Command &);
virtual command_result handleCommandBroadcastVideoJoin(Command &);
virtual command_result handleCommandBroadcastVideoLeave(Command &);
virtual command_result handleCommandBroadcastVideoConfig(Command &);
virtual command_result handleCommandBroadcastVideoConfigure(Command &);
2020-11-07 13:17:51 +01:00
2020-08-13 12:58:19 +02:00
void triggerVoiceEnd();
2021-03-21 23:51:37 +01:00
void updateSpeak(bool onlyUpdate, const std::chrono::system_clock::time_point &time);
2020-11-07 13:17:51 +01:00
std::chrono::milliseconds speak_accuracy{1000};
2020-08-13 12:58:19 +02:00
2020-11-07 13:17:51 +01:00
std::mutex speak_mutex;
std::chrono::milliseconds speak_time{0};
2020-08-13 12:58:19 +02:00
std::chrono::system_clock::time_point speak_begin;
std::chrono::system_clock::time_point speak_last_packet;
std::chrono::system_clock::time_point speak_last_no_whisper_target;
std::chrono::system_clock::time_point speak_last_too_many_whisper_targets;
permission::v2::PermissionFlaggedValue max_idle_time{permission::v2::empty_permission_flagged_value};
struct {
HandshakeState state{HandshakeState::BEGIN};
IdentityType identityType{IdentityType::UNSET};
std::string proof_message;
//TeamSpeak
std::shared_ptr<ecc_key> identityKey;
//TeaSpeak
std::shared_ptr<Json::Value> identityData;
} handshake;
2020-11-07 13:17:51 +01:00
2020-11-28 11:09:25 +01:00
whisper::WhisperHandler whisper_handler_;
2020-11-15 23:30:51 +01:00
bool rtc_session_pending_describe{false};
2020-11-07 13:17:51 +01:00
rtc::RTCClientId rtc_client_id{0};
2020-08-13 12:58:19 +02:00
};
}