diff --git a/src/main.cpp b/src/main.cpp
index bd4ebbec..372eaa00 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,16 +30,18 @@ int main(int argc, char **argv){
auto mongoHandler = std::make_unique<mongoStub>();
mongocxx::options::change_stream options;
+ //voiceEvents collection watcher
mongocxx::change_stream colCs = mongoHandler->getCol().watch(options);
+ std::cout << "Server created and listening for events" << std::endl;
+
//Check for new messages in the collection
for (;;){
- std::vector<std::string> t = mongoHandler->getNewMessages(&colCs);
+ std::vector<mongoStub::mongoMessage> t = mongoHandler->getNewMessages(&colCs);
for(auto &i : t){
- std::cout << i << std::endl;
+ std::cout << "[" << i.eventName << "] " << std::endl;
}
}
- std::cout << "Server created" << std::endl;
return 0;
}
\ No newline at end of file
diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp
index 50312fc6..ccd2abda 100644
--- a/src/mongoStub.cpp
+++ b/src/mongoStub.cpp
@@ -6,7 +6,7 @@ mongoStub::mongoStub() {
if (this->db) {
this->col = db["events"];
-
+
} else {
std::cout << "db not found";
exit(-1);
@@ -17,10 +17,68 @@ mongoStub::mongoStub() {
}
}
-std::vector<std::string>mongoStub::getNewMessages(mongocxx::change_stream* colCs) {
- std::vector<std::string> retVec;
- for (const auto& event : *colCs) {
- retVec.push_back(bsoncxx::to_json(event));
+// Too slow for my liking
+std::vector<mongoStub::mongoMessage> mongoStub::getNewMessages(
+ mongocxx::change_stream* colCs) {
+ std::vector<mongoStub::mongoMessage> retVec;
+
+ for (auto&& event : *colCs) {
+ mongoStub::mongoMessage returnValue;
+
+ std::cout << bsoncxx::to_json(event) << std::endl;
+
+ // Only listen to insert events (to avoid "precondition failed: data"
+ // exception)
+ if (event["operationType"].get_utf8().value.to_string() != "insert") {
+ continue;
+ }
+
+ std::string evName = event["fullDocument"]["event"].get_utf8().value.to_string();
+
+ if(evName.substr(0, 7)=="VSERVER"){ continue; } //Ignore the event if it's been emited by a voice server
+
+ if (evName == "UDP_CONNECTION") {
+ handleUdpRequest(
+ event["fullDocument"]["data"]["d"]["address"].get_utf8().value.to_string(),
+ event["fullDocument"]["data"]["d"]["port"].get_int32().value,
+ event["fullDocument"]["data"]["d"]["mode"].get_utf8().value.to_string()
+ );
+
+ } else if (evName == "VOICE_REQUEST") {
+ //TODO
+ continue;
+ }
+
+ returnValue.eventName = evName;
+ retVec.push_back(returnValue);
}
- return retVec;
+
+ return retVec;
}
+
+
+void mongoStub::handleUdpRequest(std::string address, int port, std::string mode) {
+ using bsoncxx::builder::basic::kvp;
+ using bsoncxx::builder::basic::sub_array;
+ using bsoncxx::builder::basic::sub_document;
+
+ auto builder = bsoncxx::builder::basic::document{};
+
+ //Handle UDP socket stuff (later tho)
+
+ builder.append(kvp("event", "VSERVER_UDP_RESPONSE"));
+ builder.append(kvp("op", "4"));
+ builder.append(kvp("d", [](sub_document subdoc) {
+ subdoc.append(kvp("mode", "CRYPT_MODE")),
+ subdoc.append(kvp("secret_key", [](sub_array subarr) {
+ subarr.append(1, 2, 3, 5); // HOW DO I GEN A SKEY?
+ }));
+ }));
+
+
+ bsoncxx::stdx::optional<mongocxx::result::insert_one> r= col.insert_one(builder.view());
+}
+
+void mongoStub::handleVoiceRequest() {
+ //Is this really needed? idk
+}
\ No newline at end of file
diff --git a/src/mongoStub.hpp b/src/mongoStub.hpp
index 3cee472c..2809142f 100644
--- a/src/mongoStub.hpp
+++ b/src/mongoStub.hpp
@@ -7,16 +7,25 @@
#include <vector>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
-#include <mongocxx/v_noabi/mongocxx/change_stream.hpp>
+#include <mongocxx/change_stream.hpp>
#include <bsoncxx/json.hpp>
+#include <bsoncxx/document/element.hpp>
-class mongoStub : boost::noncopyable {
+class mongoStub{
public:
mongoStub();
- std::vector<std::string> getNewMessages(mongocxx::change_stream* colCs);
+
+ struct mongoMessage{
+ std::string eventName;
+ std::vector<std::string> data;
+ };
+
+ std::vector<mongoMessage> getNewMessages(mongocxx::change_stream* colCs);
mongocxx::collection getCol() const { return col; }
+
+
private:
mongocxx::instance instance;
@@ -24,6 +33,9 @@ class mongoStub : boost::noncopyable {
mongocxx::database db;
mongocxx::collection col;
mongocxx::change_stream* colCs = nullptr;
+
+ void handleUdpRequest(std::string address, int port, std::string mode);
+ void handleVoiceRequest();
};
#endif
diff --git a/src/protodefs/protos.proto b/src/protodefs/protos.proto
deleted file mode 100644
index 11face5f..00000000
--- a/src/protodefs/protos.proto
+++ /dev/null
@@ -1,24 +0,0 @@
-syntax = "proto3";
-
-package fosscordMedia;
-
-service fosscordInternals{
- rpc vRequest(voiceRequest) returns (voiceAnswer) {}
-}
-
-message voiceRequest{ //OP1 from gw
- uint64 userid = 1;
- uint64 guildid = 2;
- string ip=3;
- uint32 port=4;
- string protocol=5;
- string rtcConnectionId=6;
-}
-
-message voiceAnswer{//OP2 and OP4 to gw
- string ip=1;
- uint32 port=3;
- repeated string modes=2;
- int32 ssrc=4;
- string audioCodec=5;
-}
\ No newline at end of file
|