MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / ProcessInboundFrame

Method ProcessInboundFrame

Sources/Jazz2/UI/DiscordRpcClient.cpp:254–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252 }
253
254 void DiscordRpcClient::ProcessInboundFrame(const char* json, std::size_t length, std::size_t allocated)
255 {
256 LOGD("{}", StringView(json, length));
257
258 Json::CharReaderBuilder builder;
259 auto reader = std::unique_ptr<Json::CharReader>(builder.newCharReader());
260 Json::Value doc; std::string errors;
261 if (reader->parse(json, json + length, &doc, &errors)) {
262 std::string_view cmd;
263 if (doc["cmd"].get(cmd) == Json::SUCCESS && cmd == "DISPATCH"sv) {
264 const auto& data = doc["data"];
265 if (data.isObject()) {
266 const auto& user = data["user"]; // {"id":"123456789","username":"nick.name","discriminator":"0","global_name":"Display Name","avatar":"123456789abcdef","avatar_decoration_data":null,"bot":false,"flags":32,"premium_type":0}
267 std::string_view userId, userGlobalName;
268 if (user.isObject() && user["id"].get(userId) == Json::SUCCESS && user["global_name"].get(userGlobalName) == Json::SUCCESS) {
269 _userId = stou64(userId.data(), userId.size());
270 _userDisplayName = userGlobalName;
271 LOGD("Connected to Discord as user \"{}\" ({})", _userDisplayName, _userId);
272 }
273 }
274 }
275 }
276 }
277
278 bool DiscordRpcClient::WriteFrame(Opcodes opcode, const char* buffer, std::uint32_t bufferSize)
279 {

Callers 1

OnBackgroundThreadMethod · 0.80

Calls 7

stou64Function · 0.85
newCharReaderMethod · 0.80
isObjectMethod · 0.80
parseMethod · 0.45
getMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected