diff options
author | Newe <speedy.wolfy@outlook.com> | 2021-05-25 23:00:54 +0200 |
---|---|---|
committer | Newe <speedy.wolfy@outlook.com> | 2021-05-25 23:00:54 +0200 |
commit | d6c30fc027d3ea71615c994ba1d6a1fc13636a76 (patch) | |
tree | cd528fbcea34d5fe182d52bcc7aca864bc04af65 | |
parent | [edit] Retrieve the event name from mongoDB event payload (diff) | |
download | server-d6c30fc027d3ea71615c994ba1d6a1fc13636a76.tar.xz |
[add] Mongo collection insert :)
-rw-r--r-- | src/mongoStub.cpp | 65 | ||||
-rw-r--r-- | src/mongoStub.hpp | 4 |
2 files changed, 50 insertions, 19 deletions
diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp index 3e7ae3df..7e5c4a6c 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,28 +17,55 @@ mongoStub::mongoStub() { } } -//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; +// Too slow for my liking +std::vector<mongoStub::mongoMessage> mongoStub::getNewMessages( + mongocxx::change_stream* colCs) { + std::vector<mongoStub::mongoMessage> retVec; - /*if(event["fullDocument"]["data"]){ - returnValue.data.push_back(event["fullDocument"]["data"].get_utf8().value.to_string()); - }*/ + for (auto&& event : *colCs) { + mongoStub::mongoMessage returnValue; + std::cout << bsoncxx::to_json(event) << std::endl; - - 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 evNameTmp = + event["fullDocument"]["event"].get_utf8().value.to_string(); + if (evNameTmp == "UDP_CONNECTION") { + handleUdpRequest(); + } else if (evNameTmp == "VOICE_REQUEST") { + continue; + } - //Oly listen to insert events (to avoid "precondition failed: data" exception) - if(event["operationType"].get_utf8().value.to_string()!="insert"){ - continue; - } - returnValue.eventName = event["fullDocument"]["event"].get_utf8().value.to_string(); - retVec.push_back(returnValue); + returnValue.eventName = evNameTmp; + retVec.push_back(returnValue); } - return retVec; + return retVec; } + +void mongoStub::handleUdpRequest() { + using bsoncxx::builder::basic::kvp; + using bsoncxx::builder::basic::sub_array; + using bsoncxx::builder::basic::sub_document; + + auto builder = bsoncxx::builder::basic::document{}; + + 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()); + std::cout << "Insert"<< std::endl; +} + +void handleVoiceRequest() {} \ No newline at end of file diff --git a/src/mongoStub.hpp b/src/mongoStub.hpp index 71bac792..18b899ae 100644 --- a/src/mongoStub.hpp +++ b/src/mongoStub.hpp @@ -23,6 +23,10 @@ class mongoStub{ std::vector<mongoMessage> getNewMessages(mongocxx::change_stream* colCs); + void handleUdpRequest(); + + void handleVoiceRequest(); + mongocxx::collection getCol() const { return col; } |