Some changes
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "audio/VoiceConnection.h"
|
||||
#include "audio/AudioSender.h"
|
||||
#include "../logger.h"
|
||||
#include "../hwuid.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
@@ -11,8 +12,12 @@
|
||||
#include <misc/net.h>
|
||||
#include <misc/base64.h>
|
||||
#include <misc/endianness.h>
|
||||
#include <misc/strobf.h>
|
||||
#include <iomanip>
|
||||
|
||||
//#define FUZZ_VOICE
|
||||
//#define SHUFFLE_VOICE
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace tc::connection;
|
||||
@@ -195,6 +200,10 @@ void ServerConnection::schedule_resend(const std::chrono::system_clock::time_poi
|
||||
}
|
||||
}
|
||||
NAN_METHOD(ServerConnection::connect) {
|
||||
if(!this->protocol_handler) {
|
||||
Nan::ThrowError("ServerConnection not initialized");
|
||||
return;
|
||||
}
|
||||
if(info.Length() != 1) {
|
||||
Nan::ThrowError(tr("Invalid argument count"));
|
||||
return;
|
||||
@@ -231,8 +240,8 @@ NAN_METHOD(ServerConnection::connect) {
|
||||
return;
|
||||
}
|
||||
|
||||
unique_lock disconnect_lock(this->disconnect_lock, defer_lock);
|
||||
if(!disconnect_lock.try_lock_for(chrono::milliseconds(500))) {
|
||||
unique_lock _disconnect_lock(this->disconnect_lock, defer_lock);
|
||||
if(!_disconnect_lock.try_lock_for(chrono::milliseconds(500))) {
|
||||
Nan::ThrowError(tr("failed to acquire disconnect lock"));
|
||||
return;
|
||||
}
|
||||
@@ -294,7 +303,6 @@ NAN_METHOD(ServerConnection::connect) {
|
||||
}
|
||||
|
||||
this->socket->on_data = [&](const pipes::buffer_view& buffer) { this->protocol_handler->progress_packet(buffer); };
|
||||
|
||||
if(teamspeak->IsBoolean() && teamspeak->BooleanValue(info.GetIsolate()))
|
||||
this->protocol_handler->server_type = server_type::TEAMSPEAK;
|
||||
this->protocol_handler->connect();
|
||||
@@ -333,7 +341,9 @@ NAN_METHOD(ServerConnection::disconnect) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->protocol_handler->disconnect(*Nan::Utf8String(info[0]));
|
||||
if(this->protocol_handler) {
|
||||
this->protocol_handler->disconnect(*Nan::Utf8String(info[0]));
|
||||
}
|
||||
}
|
||||
|
||||
NAN_METHOD(ServerConnection::_error_message) {
|
||||
@@ -365,6 +375,11 @@ NAN_METHOD(ServerConnection::_send_command) {
|
||||
return ObjectWrap::Unwrap<ServerConnection>(info.Holder())->send_command(info);
|
||||
}
|
||||
NAN_METHOD(ServerConnection::send_command) {
|
||||
if(!this->protocol_handler) {
|
||||
Nan::ThrowError("ServerConnection not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
if(info.Length() != 3) {
|
||||
Nan::ThrowError("invalid argument count");
|
||||
return;
|
||||
@@ -432,6 +447,7 @@ NAN_METHOD(ServerConnection::send_command) {
|
||||
cmd["client_version"] = "0.0.1 [Build: 1549713549]";
|
||||
cmd["client_platform"] = "Linux";
|
||||
cmd["client_version_sign"] = "7XvKmrk7uid2ixHFeERGqcC8vupeQqDypLtw2lY9slDNPojEv//F47UaDLG+TmVk4r6S0TseIKefzBpiRtLDAQ==";
|
||||
cmd[strobf("hwid").string()] = system_uuid(); /* we dont want anybody to patch this out */
|
||||
}
|
||||
}
|
||||
this->protocol_handler->send_command(cmd);
|
||||
@@ -442,6 +458,11 @@ NAN_METHOD(ServerConnection::_send_voice_data) {
|
||||
}
|
||||
|
||||
NAN_METHOD(ServerConnection::send_voice_data) {
|
||||
if(!this->protocol_handler) {
|
||||
Nan::ThrowError("ServerConnection not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
if(info.Length() != 3) {
|
||||
Nan::ThrowError("invalid argument count");
|
||||
return;
|
||||
@@ -480,11 +501,13 @@ NAN_METHOD(ServerConnection::send_voice_data_raw) {
|
||||
auto flag_head = info[2]->BooleanValue(info.GetIsolate());
|
||||
|
||||
auto voice_data = info[0].As<v8::Float32Array>()->Buffer();
|
||||
auto vs = this->voice_connection->voice_sender();
|
||||
|
||||
vs->send_data(voice_data->GetContents().Data(), voice_data->GetContents().ByteLength() / (4 * channels), sample_rate, channels);
|
||||
auto vs = this->voice_connection ? this->voice_connection->voice_sender() : nullptr;
|
||||
if(vs) vs->send_data(voice_data->GetContents().Data(), voice_data->GetContents().ByteLength() / (4 * channels), sample_rate, channels);
|
||||
}
|
||||
|
||||
#ifdef SHUFFLE_VOICE
|
||||
static shared_ptr<ts::protocol::ClientPacket> shuffle_cached_packet;
|
||||
#endif
|
||||
void ServerConnection::send_voice_data(const void *buffer, size_t buffer_length, uint8_t codec, bool head) {
|
||||
auto _buffer = pipes::buffer{ts::protocol::ClientPacket::META_SIZE + buffer_length + 3};
|
||||
auto packet = make_shared<ts::protocol::ClientPacket>(_buffer);
|
||||
@@ -501,13 +524,19 @@ void ServerConnection::send_voice_data(const void *buffer, size_t buffer_length,
|
||||
packet->enable_flag(ts::protocol::PacketFlag::Compressed);
|
||||
packet->enable_flag(ts::protocol::PacketFlag::Unencrypted);
|
||||
|
||||
//#define FUZZ_VOICE
|
||||
#ifdef FUZZ_VOICE
|
||||
if((rand() % 10) < 2) {
|
||||
log_info(category::connection, tr("Dropping voice packet"));
|
||||
} else {
|
||||
this->protocol_handler->send_packet(packet);
|
||||
}
|
||||
#elif defined(SHUFFLE_VOICE)
|
||||
if(shuffle_cached_packet) {
|
||||
this->protocol_handler->send_packet(packet);
|
||||
this->protocol_handler->send_packet(std::exchange(shuffle_cached_packet, nullptr));
|
||||
} else {
|
||||
shuffle_cached_packet = packet;
|
||||
}
|
||||
#else
|
||||
this->protocol_handler->send_packet(packet);
|
||||
#endif
|
||||
@@ -525,10 +554,10 @@ void ServerConnection::close_connection() {
|
||||
}
|
||||
|
||||
this->event_loop_execute_connection_close = false;
|
||||
if(this->socket) {
|
||||
if(this->socket)
|
||||
this->socket->finalize();
|
||||
}
|
||||
this->protocol_handler->do_close_connection();
|
||||
if(this->protocol_handler)
|
||||
this->protocol_handler->do_close_connection();
|
||||
this->socket = nullptr;
|
||||
this->call_disconnect_result.call(0, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user