Пример #1
0
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {

	ERR_FAIL_COND(root_node == NULL);
	ERR_FAIL_COND(p_packet_len < 1);

	uint8_t packet_type = p_packet[0];

	switch (packet_type) {

		case NETWORK_COMMAND_SIMPLIFY_PATH: {

			_process_simplify_path(p_from, p_packet, p_packet_len);
		} break;

		case NETWORK_COMMAND_CONFIRM_PATH: {

			_process_confirm_path(p_from, p_packet, p_packet_len);
		} break;

		case NETWORK_COMMAND_REMOTE_CALL:
		case NETWORK_COMMAND_REMOTE_SET: {

			ERR_FAIL_COND(p_packet_len < 6);

			Node *node = _process_get_node(p_from, p_packet, p_packet_len);

			ERR_FAIL_COND(node == NULL);

			//detect cstring end
			int len_end = 5;
			for (; len_end < p_packet_len; len_end++) {
				if (p_packet[len_end] == 0) {
					break;
				}
			}

			ERR_FAIL_COND(len_end >= p_packet_len);

			StringName name = String::utf8((const char *)&p_packet[5]);

			if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {

				_process_rpc(node, name, p_from, p_packet, p_packet_len, len_end + 1);

			} else {

				_process_rset(node, name, p_from, p_packet, p_packet_len, len_end + 1);
			}

		} break;

		case NETWORK_COMMAND_RAW: {

			_process_raw(p_from, p_packet, p_packet_len);
		} break;
	}
}
Пример #2
0
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {

	ERR_EXPLAIN("Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it");
	ERR_FAIL_COND(root_node == NULL);
	ERR_EXPLAIN("Invalid packet received. Size too small.");
	ERR_FAIL_COND(p_packet_len < 1);

	uint8_t packet_type = p_packet[0];

	switch (packet_type) {

		case NETWORK_COMMAND_SIMPLIFY_PATH: {

			_process_simplify_path(p_from, p_packet, p_packet_len);
		} break;

		case NETWORK_COMMAND_CONFIRM_PATH: {

			_process_confirm_path(p_from, p_packet, p_packet_len);
		} break;

		case NETWORK_COMMAND_REMOTE_CALL:
		case NETWORK_COMMAND_REMOTE_SET: {

			ERR_EXPLAIN("Invalid packet received. Size too small.");
			ERR_FAIL_COND(p_packet_len < 6);

			Node *node = _process_get_node(p_from, p_packet, p_packet_len);

			ERR_EXPLAIN("Invalid packet received. Requested node was not found.");
			ERR_FAIL_COND(node == NULL);

			// Detect cstring end.
			int len_end = 5;
			for (; len_end < p_packet_len; len_end++) {
				if (p_packet[len_end] == 0) {
					break;
				}
			}

			ERR_EXPLAIN("Invalid packet received. Size too small.");
			ERR_FAIL_COND(len_end >= p_packet_len);

			StringName name = String::utf8((const char *)&p_packet[5]);

			if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {

				_process_rpc(node, name, p_from, p_packet, p_packet_len, len_end + 1);

			} else {

				_process_rset(node, name, p_from, p_packet, p_packet_len, len_end + 1);
			}

		} break;

		case NETWORK_COMMAND_RAW: {

			_process_raw(p_from, p_packet, p_packet_len);
		} break;
	}
}