summary refs log tree commit diff
path: root/src/mongoStub.cpp
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-25 23:38:06 +0200
committerGitHub <noreply@github.com>2021-05-25 23:38:06 +0200
commitd2fb1ee4588436eca9bb0097bd06ca05dbc3e5f0 (patch)
tree28421cf19cd53b2e75fe64d844215145967d1ee3 /src/mongoStub.cpp
parentMerge pull request #20 from ItsNewe/master (diff)
parent[del] Deleted .proto (diff)
downloadserver-d2fb1ee4588436eca9bb0097bd06ca05dbc3e5f0.tar.xz
Merge pull request #21 from ItsNewe/master
Mongo payload data retrieval
Diffstat (limited to 'src/mongoStub.cpp')
-rw-r--r--src/mongoStub.cpp70
1 files changed, 64 insertions, 6 deletions
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