static void cb_receive_node_create(const uint8 session_id,
		const uint32 node_id,
		const uint32 parent_id,
		const uint16 user_id,
		const uint16 custom_type)
{
	struct ParticleSenderNode *sender_node;
	struct Particle_Sender *sender;

#if NO_DEBUG_PRINT != 1
	printf("%s() session_id: %d, node_id: %d, parent_id: %d, user_id: %d, custom_type: %d\n",
			__FUNCTION__, session_id, node_id, parent_id, user_id, custom_type);
#endif

	if(user_id != ctx->verse.user_id) {
		return;
	}

	if(parent_id == ctx->verse.avatar_id) {
		switch(custom_type) {
		case PARTICLE_SCENE_NODE:
			if(ctx->verse.particle_scene_node == NULL) {
				/* Create node of particle scene */
				ctx->verse.particle_scene_node = create_particle_scene_node(node_id);

				/* Add node to lookup table*/
				lu_add_item(ctx->verse.lu_table, node_id, ctx->verse.particle_scene_node);

				vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY, VRS_SCENE_PARENT_NODE_ID, node_id);
				vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);
				vrs_send_taggroup_create(session_id, VRS_DEFAULT_PRIORITY, node_id, PARTICLE_SCENE_TG);
			}
			break;
		case PARTICLE_SENDER_NODE:
			if(v_list_count_items(&ctx->verse.particle_scene_node->senders) < (int32)ctx->sender_count) {
				sender_node = create_particle_sender_node(ctx->verse.particle_scene_node, node_id);

				/* Find unassigned sender */
				sender = ctx->senders.first;
				while(sender != NULL) {
					if(sender->sender_node == NULL) {
						break;
					}
					sender = sender->next;
				}

				/* Create reference */
				if(sender != NULL) {
					sender->sender_node = sender_node;
					sender_node->sender = sender;
				}

				/* Is it sender node created by this client */
				if(parent_id == ctx->verse.avatar_id) {
					ctx->sender = sender;
				}

				/* Add node to lookup table*/
				lu_add_item(ctx->verse.lu_table, node_id, sender_node);

				v_list_add_tail(&ctx->verse.particle_scene_node->senders, sender_node);

				vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY,
						node_id, 0, 0);
				vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY,
						ctx->verse.particle_scene_node->node_id, node_id);
				vrs_send_taggroup_create(session_id, VRS_DEFAULT_PRIORITY,
						node_id, PARTICLE_SENDER_TG);
				vrs_send_layer_create(session_id, VRS_DEFAULT_PRIORITY,
						node_id, 0xFFFF, VRS_VALUE_TYPE_REAL32, 3, PARTICLE_POS_LAYER);
			}
			break;
		}
	}
}
Ejemplo n.º 2
0
/**
 * \brief This function is callback function for receiving of node_create
 * command. It means, that this function is called, when verse_callback_update
 * is executed and there are any data in appropriate incoming queue.
 *
 * \param[in]	session_id	The ID of session with some verse server
 * \param[in]	node_id		The ID of new node
 * \param[in]	parent_id	The ID of parent node
 * \param[in]	user_id		The User ID of the owner of this node
 */
static void cb_receive_node_create(const uint8_t session_id,
		const uint32_t node_id,
		const uint32_t parent_id,
		const uint16_t user_id,
		const uint16_t custom_type)
{
	printf("%s() session_id: %d, node_id: %d, parent_id: %d, user_id: %d, custom_type: %d\n",
			__FUNCTION__, session_id, node_id, parent_id, user_id, custom_type);

	/* Is node special node? */
	if(node_id==VRS_ROOT_NODE_ID) {
		printf("\tRoot Node\n");
	} else if(node_id==VRS_AVATAR_PARENT_NODE_ID) {
		printf("\tParent of Avatar Nodes\n");
		/* Try to delete node, that could not be deleted */
		vrs_send_node_destroy(session_id, VRS_DEFAULT_PRIORITY, node_id);
	} else if(node_id==VRS_USERS_PARENT_NODE_ID) {
		printf("\tParent of User Nodes\n");
		/* Example of node subscribe command */
		vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);
	} else if(node_id==VRS_SCENE_PARENT_NODE_ID) {
		printf("\tParent of Scene Nodes\n");
		/* Example of node un-subscribe command */
		vrs_send_node_unsubscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0);
	} else if(node_id==VRS_ROOT_NODE_ID) {
		printf("\tUser Node of SuperUser\n");
	} else if(parent_id==VRS_USERS_PARENT_NODE_ID) {
		printf("\tUser Node\n");
	} else if(node_id==VRS_RESERVED_NODE_ID) {
		printf("\tReservered Node ID (should never be received by client from server)\n");
	} else if(node_id>=VRS_FIRST_COMMON_NODE_ID) {
		printf("\tCommon Node\n");
	}

	/* My Avatar Node */
	if(node_id == my_avatar_id) {
		/* Client should subscribe to his avarat node to be able receive information
		 * about nodes, that was created by this client */
		printf("\tMy Avatar Node\n");
		vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);

		/* Test of sending wrong node_perm command (client doesn't own this node) */
		vrs_send_node_perm(session_id, VRS_DEFAULT_PRIORITY, node_id, my_user_id, VRS_PERM_NODE_READ | VRS_PERM_NODE_WRITE);
	}

	/* Who is owner of this node? */
	if(my_user_id != -1 && my_user_id == user_id) {
		printf("\tNode owned by me\n");
	} else if(user_id==VRS_SUPER_USER_UID) {
		printf("\tNode owned by super user (server)\n");
	} else {
		printf("\tNode owned by someone else\n");
	}

	/* Who created this node? */
	if(my_avatar_id != -1 && my_avatar_id == parent_id) {
		printf("\tNode created from this client\n");
		printf("\tParent of this node is my avatar node: %d\n", parent_id);
	} else {
		printf("\tNode created by somebody else\n");
		printf("\tParent of this node is: %d\n", parent_id);
	}

	/* Example of subscribing to node created from this client */
	if((my_user_id != -1 && my_user_id == user_id) &&
			(my_avatar_id != -1 && my_avatar_id == parent_id))
	{
		my_test_node_id = node_id;

		/* Test of subscribing to my own node */
		vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0);

		/* Test of changing priority of my node */
		vrs_send_node_prio(session_id, VRS_DEFAULT_PRIORITY, node_id, my_test_node_prio);

		/* Test of changing parent of my node */
		vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY, VRS_SCENE_PARENT_NODE_ID, node_id);

		/* Test of adding new node permission */
		vrs_send_node_perm(session_id, VRS_DEFAULT_PRIORITY, node_id, 100, VRS_PERM_NODE_READ | VRS_PERM_NODE_WRITE);
	}
}