Exemplo n.º 1
0
void vc_handler_deletemember(ascent_socket *s, ascent_packet *p)
{
	uint16 channel_id;
	uint8 member_id;
	voice_channel *ch;

	channel_id = ascentpacket_readu16(p);
	member_id = ascentpacket_readu8(p);

	ch = voice_channel_get((int)channel_id);
	if( ch == NULL )
	{
		log_write(ERROR, "client is requesting us to delete a member from a nonexistant channel");
		return;
	}

	if( member_id >= ch->member_slots )
	{
		log_write(ERROR, "client sent out of range voicechat member id");
		return;
	}

	log_write(DEBUG, "channel id %u slot %u is now disabled.", (int)channel_id, (int)member_id);
	ch->members[member_id].active = 0;
	ch->members[member_id].used = 0;
}
Exemplo n.º 2
0
void vc_handler_deletechannel(ascent_socket *s, ascent_packet *p)
{
	uint16 channel_id;
	voice_channel *ch;

	channel_id = ascentpacket_readu16(p);

	ch = voice_channel_get((int)channel_id);
	if( ch == NULL )
	{
		log_write(ERROR, "client is requesting us to delete a nonexistant channel");
		return;
	}

	log_write(DEBUG, "deleting channel id %u", (int)channel_id);
	if( voice_channel_remove(ch->channel_id) < 0 )
	{
		--s->channelcount;
		--g_channelCount;
	}
}
Exemplo n.º 3
0
int voicechat_client_socket_read_handler(network_socket *s, int act)
{
	struct sockaddr_in read_address;
	char buffer[10000] = {0};			// people needing a bigger buffer, again can go to hell
	int bytes;

	uint16 channel_id;
	uint8 user_id;
	int i;

	voice_channel * chn;
	voice_channel_member * memb;

	if( act == IOEVENT_ERROR )
	{
		log_write(ERROR, "UDP Socket read an error!");
		return 0;
	}

	if( (bytes = network_read_data(s, buffer, 10000, (struct sockaddr*)&read_address)) < 0 )
	{
		log_write(ERROR, "UDP socket read error bytes!");
		return 0;
	}

	log_write(DEBUG, "udp socket got %d bytes from address %s", bytes, inet_ntoa(read_address.sin_addr));
	channel_id = *(uint16*)(&buffer[5]);
	user_id = buffer[4];

	chn = voice_channel_get((int)channel_id);
	log_write(DEBUG, "channel %u userid %u", (int)channel_id, (int)user_id);
	if( chn == NULL )
	{
		log_write(ERROR, "udp client sent invalid voice channel.");
		return 0;
	}

	if( user_id >= chn->member_slots )
	{
		log_write(ERROR, "udp client sent out of range user id.");
		return 0;
	}

	memb = &chn->members[user_id];

	// client initial packet check
	if( bytes == 7 )
	{
		if( memb->used && memcmp(&memb->client_address, &read_address, sizeof(struct sockaddr)) )
		{
			log_write(ERROR, "udp client is sending a different read address than it should be. desync maybe?");
		}

		memcpy(&memb->client_address, &read_address, sizeof(struct sockaddr));
		//printf("client %u address set to %s\n", (int)user_id, inet_ntoa(chn->members[user_id].client_address.sin_addr));
		memb->used = 1;		
	}
	else
	{
		// distribute the packet
		for( i = 0; i < chn->member_slots; ++i )
		{
			if( i == user_id || !chn->members[i].used || !chn->members[i].active )
				continue;			// don't send to yourself :P
			
			//printf("writing to client %u address %s\n", i, inet_ntoa(chn->members[i].client_address.sin_addr));
			if( network_write_data( s, buffer, bytes, (struct sockaddr*)&chn->members[i].client_address ) < 0 )
			{
				log_write(ERROR, "network_write_data to UDP client %s failed.", inet_ntoa(chn->members[i].client_address.sin_addr));
			}
		}
	}
	
	return 0;
}