MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / poll

Method poll

modules/multiplayer/scene_multiplayer.cpp:76–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76Error SceneMultiplayer::poll() {
77 _update_status();
78 if (last_connection_status == MultiplayerPeer::CONNECTION_DISCONNECTED) {
79 return OK;
80 }
81
82 multiplayer_peer->poll();
83
84 _update_status();
85 if (last_connection_status != MultiplayerPeer::CONNECTION_CONNECTED) {
86 // We might be still connecting, or polling might have resulted in a disconnection.
87 return OK;
88 }
89
90 while (multiplayer_peer->get_available_packet_count()) {
91 int sender = multiplayer_peer->get_packet_peer();
92 const uint8_t *packet;
93 int len;
94
95 int channel = multiplayer_peer->get_packet_channel();
96 MultiplayerPeer::TransferMode mode = multiplayer_peer->get_packet_mode();
97
98 Error err = multiplayer_peer->get_packet(&packet, len);
99 ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error getting packet! %d", err));
100
101#ifdef DEBUG_ENABLED
102 _profile_bandwidth("in", len);
103#endif
104
105 if (pending_peers.has(sender)) {
106 ERR_CONTINUE(len < 2 || (packet[0] & CMD_MASK) != NETWORK_COMMAND_SYS || packet[1] != SYS_COMMAND_AUTH);
107 // Auth message.
108 PackedByteArray pba;
109 pba.resize(len - 2);
110 if (pba.size()) {
111 memcpy(pba.ptrw(), &packet[2], len - 2);
112 // User callback
113 const Variant sv = sender;
114 const Variant pbav = pba;
115 const Variant *argv[2] = { &sv, &pbav };
116 Variant ret;
117 Callable::CallError ce;
118 auth_callback.callp(argv, 2, ret, ce);
119 ERR_CONTINUE_MSG(ce.error != Callable::CallError::CALL_OK, "Failed to call authentication callback");
120 } else {
121 // Remote complete notification.
122 pending_peers[sender].remote = true;
123 if (pending_peers[sender].local) {
124 pending_peers.erase(sender);
125 _admit_peer(sender);
126 }
127 }
128 continue; // Auth in progress.
129 }
130
131 ERR_CONTINUE(!connected_peers.has(sender));
132
133 if (len && (packet[0] & CMD_MASK) == NETWORK_COMMAND_SYS) {

Callers 1

Calls 15

vformatFunction · 0.85
on_network_processMethod · 0.80
sizeMethod · 0.65
get_packet_peerMethod · 0.45
get_packet_channelMethod · 0.45
get_packet_modeMethod · 0.45
get_packetMethod · 0.45
hasMethod · 0.45
resizeMethod · 0.45
ptrwMethod · 0.45
callpMethod · 0.45

Tested by

no test coverage detected