2019-07-17 19:37:18 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <json/json.h>
|
|
|
|
#include "ConnectedClient.h"
|
|
|
|
|
|
|
|
namespace ts {
|
|
|
|
namespace server {
|
2020-01-26 18:04:38 +01:00
|
|
|
class VirtualServer;
|
2019-07-17 19:37:18 +02:00
|
|
|
class SpeakingClient : public ConnectedClient {
|
|
|
|
public:
|
2020-01-24 02:57:58 +01:00
|
|
|
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
|
|
|
|
};
|
2019-07-17 19:37:18 +02:00
|
|
|
|
2020-01-26 18:04:38 +01:00
|
|
|
SpeakingClient(sql::SqlManager* a, const std::shared_ptr<VirtualServer>& b) : ConnectedClient(a, b) {
|
2020-01-24 02:57:58 +01:00
|
|
|
speak_begin = std::chrono::system_clock::now();
|
|
|
|
speak_last_packet = std::chrono::system_clock::now();
|
2019-07-17 19:37:18 +02:00
|
|
|
};
|
2019-10-20 12:09:28 +02:00
|
|
|
~SpeakingClient() override = default;
|
2019-07-17 19:37:18 +02:00
|
|
|
|
2020-01-24 02:57:58 +01:00
|
|
|
//Voice
|
|
|
|
virtual void send_voice_packet(const pipes::buffer_view& /* voice packet data */, const VoicePacketFlags& /* flags */) = 0;
|
|
|
|
virtual bool shouldReceiveVoice(const std::shared_ptr<ConnectedClient> &sender);
|
|
|
|
|
|
|
|
//Whisper
|
|
|
|
bool shouldReceiveVoiceWhisper(const std::shared_ptr<ConnectedClient> &sender);
|
|
|
|
virtual void send_voice_whisper_packet(const pipes::buffer_view& /* voice packet data */, const VoicePacketFlags& /* flags */) = 0;
|
|
|
|
|
|
|
|
inline std::chrono::milliseconds takeSpokenTime() {
|
|
|
|
auto time = this->speak_time;
|
|
|
|
this->speak_time = std::chrono::milliseconds(0);
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
void tick(const std::chrono::system_clock::time_point &time) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
public:
|
|
|
|
void updateChannelClientProperties(bool channel_lock, bool notify) override;
|
|
|
|
|
|
|
|
protected:
|
2020-01-25 23:42:37 +01:00
|
|
|
command_result handleCommand(Command &command) override;
|
2020-01-24 02:57:58 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
void handlePacketVoice(const pipes::buffer_view&, bool head, bool fragmented);
|
|
|
|
virtual void handlePacketVoiceWhisper(const pipes::buffer_view&, bool /* new */);
|
|
|
|
|
|
|
|
void processJoin();
|
|
|
|
void processLeave();
|
|
|
|
|
2020-01-25 23:42:37 +01:00
|
|
|
virtual command_result handleCommandHandshakeBegin(Command&);
|
|
|
|
virtual command_result handleCommandHandshakeIdentityProof(Command &);
|
|
|
|
virtual command_result handleCommandClientInit(Command&);
|
2020-01-24 02:57:58 +01:00
|
|
|
|
|
|
|
void triggerVoiceEnd();
|
|
|
|
inline void updateSpeak(bool onlyUpdate, const std::chrono::system_clock::time_point &time);
|
|
|
|
std::chrono::milliseconds speak_accuracy = std::chrono::seconds{1};
|
|
|
|
|
|
|
|
threads::Mutex speak_lock;
|
|
|
|
std::chrono::milliseconds speak_time = std::chrono::milliseconds{0};
|
|
|
|
std::chrono::system_clock::time_point speak_begin;
|
|
|
|
std::chrono::system_clock::time_point speak_last_packet;
|
|
|
|
|
2020-02-28 11:24:07 +01:00
|
|
|
std::chrono::system_clock::time_point speak_last_no_whisper_target;
|
|
|
|
std::chrono::system_clock::time_point speak_last_too_many_whisper_targets;
|
|
|
|
|
2020-01-24 02:57:58 +01:00
|
|
|
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;
|
2019-07-17 19:37:18 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|