MCPcopy Create free account
hub / github.com/ZDoom/Raze / Open

Method Open

libraries/discordrpc/src/rpc_connection.cpp:23–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23void RpcConnection::Open()
24{
25 if (state == State::Connected) {
26 return;
27 }
28
29 if (state == State::Disconnected && !connection->Open()) {
30 return;
31 }
32
33 if (state == State::SentHandshake) {
34 JsonDocument message;
35 if (Read(message)) {
36 auto cmd = GetStrMember(&message, "cmd");
37 auto evt = GetStrMember(&message, "evt");
38 if (cmd && evt && !strcmp(cmd, "DISPATCH") && !strcmp(evt, "READY")) {
39 state = State::Connected;
40 if (onConnect) {
41 onConnect(message);
42 }
43 }
44 }
45 }
46 else {
47 sendFrame.opcode = Opcode::Handshake;
48 sendFrame.length = (uint32_t)JsonWriteHandshakeObj(
49 sendFrame.message, sizeof(sendFrame.message), RpcVersion, appId);
50
51 if (connection->Write(&sendFrame, sizeof(MessageFrameHeader) + sendFrame.length)) {
52 state = State::SentHandshake;
53 }
54 else {
55 Close();
56 }
57 }
58}
59
60void RpcConnection::Close()
61{

Callers 1

Discord_UpdateConnectionFunction · 0.45

Calls 4

GetStrMemberFunction · 0.85
JsonWriteHandshakeObjFunction · 0.85
CloseFunction · 0.50
WriteMethod · 0.45

Tested by

no test coverage detected