Пример #1
0
//send some data on an fd, for a special slot and connection_id
eData eDVBCISlot::sendData(unsigned char* data, int len)
{
#ifdef x_debug
	printf("%s: %p, %d\n", __func__, data, len);
#endif

	unsigned char *d = (unsigned char*) malloc(len + 5);

	/* should we send a data last ? */
	if (data != NULL)
	{
		if ((data[2] >= T_SB) && (data[2] <= T_NEW_T_C))
		{
			memcpy(d, data, len);
		}
		else
		{
			//send data_last and data
			memcpy(d + 5, data, len);
			d[0] = getSlotID();
			d[1] = connection_id;
			d[2] = T_DATA_LAST;
			d[3] = len + 1; 		/* len */
			d[4] = connection_id; 	/* transport connection identifier*/
			len += 5;
		}
	}
	else
	{
		//send a data last only
		d[0] = getSlotID();
		d[1] = connection_id;
		d[2] = T_DATA_LAST;
		d[3] = len + 1; 		/* len */
		d[4] = connection_id; 	/* transport connection identifier*/
		len = 5;
	}

#ifdef x_debug
	printf("write (%d): > ", getSlotID());
	for (int i=0; i < len; i++)
		printf("%02x ",d[i]);
	printf("\n");
#endif

#ifdef direct_write
	res = write(fd, d, len);

	free(d);
	if (res < 0 || res != len)
	{
		printf("error writing data to fd %d, slot %d: %m\n", fd, getSlotID());
		return eDataError;
	}
#else
	sendqueue.push( queueData(d, len) );
#endif
	return eDataReady;
}
Пример #2
0
void LFGQueue::UpdateQueueTimers(uint8 queueId, time_t currTime)
{
    TC_LOG_TRACE("lfg.queue.timers.update", "Updating queue timers...");
    for (LfgQueueDataContainer::iterator itQueue = QueueDataStore.begin(); itQueue != QueueDataStore.end(); ++itQueue)
    {
        LfgQueueData& queueinfo = itQueue->second;
        uint32 dungeonId = (*queueinfo.dungeons.begin());
        uint32 queuedTime = uint32(currTime - queueinfo.joinTime);
        uint8 role = PLAYER_ROLE_NONE;
        int32 waitTime = -1;
        int32 wtTank = waitTimesTankStore[dungeonId].time;
        int32 wtHealer = waitTimesHealerStore[dungeonId].time;
        int32 wtDps = waitTimesDpsStore[dungeonId].time;
        int32 wtAvg = waitTimesAvgStore[dungeonId].time;

        for (LfgRolesMap::const_iterator itPlayer = queueinfo.roles.begin(); itPlayer != queueinfo.roles.end(); ++itPlayer)
            role |= itPlayer->second;
        role &= ~PLAYER_ROLE_LEADER;

        switch (role)
        {
            case PLAYER_ROLE_NONE:                                // Should not happen - just in case
                waitTime = -1;
                break;
            case PLAYER_ROLE_TANK:
                waitTime = wtTank;
                break;
            case PLAYER_ROLE_HEALER:
                waitTime = wtHealer;
                break;
            case PLAYER_ROLE_DAMAGE:
                waitTime = wtDps;
                break;
            default:
                waitTime = wtAvg;
                break;
        }

        if (queueinfo.bestCompatible.empty())
            FindBestCompatibleInQueue(itQueue);

        LfgQueueStatusData queueData(queueId, dungeonId, queueinfo.joinTime, waitTime, wtAvg, wtTank, wtHealer, wtDps, queuedTime, queueinfo.tanks, queueinfo.healers, queueinfo.dps);
        for (LfgRolesMap::const_iterator itPlayer = queueinfo.roles.begin(); itPlayer != queueinfo.roles.end(); ++itPlayer)
        {
            uint64 pguid = itPlayer->first;
            LFGMgr::SendLfgQueueStatus(pguid, queueData);
        }
    }
}
Пример #3
0
void tsyn::Connection::receive( const tsyn::Data & receivedData )
{
  QueueData::Ref queueData( new QueueData );
  queueData->timestamp = 0ULL;

  for ( size_t i = 0; i < 8; ++i )
  {
    queueData->timestamp <<= 8;
    queueData->timestamp |= ( receivedData[i] & 0xff );
  }
  queueData->peerId = "TODO";
  queueData->payload = receivedData.substr( HEADER_LENGTH );

  m_receiveQueue.push( std::move(queueData) );
}
Пример #4
0
void LfgQueue::UpdateQueueTimers(time_t currTime)
{
    for (LfgQueueDataMap::const_iterator itQueue = m_QueueDataMap.begin(); itQueue != m_QueueDataMap.end(); ++itQueue)
    {
        const LfgQueueData &queueinfo = itQueue->second;
        uint32 dungeonId = (*queueinfo.dungeons.begin());
        uint32 queuedTime = uint32(currTime - queueinfo.joinTime);
        uint8 role = PLAYER_ROLE_NONE;
        int32 waitTime = -1;
        int32 wtTank = m_waitTimesTank[dungeonId].time;
        int32 wtHealer = m_waitTimesHealer[dungeonId].time;
        int32 wtDps = m_waitTimesDps[dungeonId].time;
        int32 wtAvg = m_waitTimesAvg[dungeonId].time;

        for (LfgRolesMap::const_iterator itPlayer = queueinfo.roles.begin(); itPlayer != queueinfo.roles.end(); ++itPlayer)
            role |= itPlayer->second;
        role &= ~PLAYER_ROLE_LEADER;

        switch (role)
        {
            case PLAYER_ROLE_NONE:                                // Should not happen - just in case
                waitTime = -1;
                break;
            case PLAYER_ROLE_TANK:
                waitTime = wtTank;
                break;
            case PLAYER_ROLE_HEALER:
                waitTime = wtHealer;
                break;
            case PLAYER_ROLE_DAMAGE:
                waitTime = wtDps;
                break;
            default:
                waitTime = wtAvg;
                break;
        }

        LfgQueueStatusData queueData(dungeonId, waitTime, wtAvg, wtTank, wtHealer, wtDps, queuedTime, queueinfo.tanks, queueinfo.healers, queueinfo.dps);
        for (LfgRolesMap::const_iterator itPlayer = queueinfo.roles.begin(); itPlayer != queueinfo.roles.end(); ++itPlayer)
        {
            uint64 pguid = itPlayer->first;
            LFGMgr::SendLfgQueueStatus(pguid, queueData);
        }
    }
}
Пример #5
0
static bool transmitData(tSlot* slot, unsigned char* d, int len)
{
#ifdef direct_write
	int res = write(slot->fd, d, len);

	free(d);
	if (res < 0 || res != len)
	{
		printf("error writing data to fd %d, slot %d: %m\n", slot->fd, slot->slot);
		return eDataError;
	}
#else
#if y_debug
	printf("SendData with data (len %d) >\n", len);
	for (int i = 0; i < len; i++)
		printf("%02x ", d[i]);
	printf("\n");
#endif
	slot->sendqueue.push(queueData(d, len));
#endif
	return true;
}
Пример #6
0
void ExternalOutput::write(std::shared_ptr<DataPacket> packet) {
  queueData(packet->data, packet->length, packet->type);
}
Пример #7
0
//send some data on an fd, for a special slot and connection_id
eData sendData(tSlot* slot, unsigned char* data, int len)
{	
        dprintf(DEBUG_DEBUG, "%s: %p, %d\n", __func__, data, len);
       
	unsigned char *d = (unsigned char*) malloc(len + 5);
		
	// only poll connection if we are not awaiting an answer
	slot->pollConnection = false;	
		
	/* 
	should we send a data last ?
	*/
	if (data != NULL)
	{
		if ((data[2] >= T_SB) && (data[2] <= T_NEW_T_C))
		{
			memcpy(d, data, len);
		} 
		else
		{
			//send data_last and data
			memcpy(d + 5, data, len);

			d[0] = slot->slot;
			d[1] = slot->connection_id;
			d[2] = T_DATA_LAST; 	
			if (len > 127)
				d[3] = 4; 		/* pointer to next length */
			else
				d[3] = len + 1; 	/* len */
			d[4] = slot->connection_id; 	/* transport connection identifier*/

			len += 5;	
		}
	}
	else
	{
		//send a data last only
		d[0] = slot->slot;
		d[1] = slot->connection_id;
		d[2] = T_DATA_LAST; 	
		if (len > 127)
			d[3] = 4; 		/* pointer to next length */
		else
			d[3] = len + 1; 	/* len */
		d[4] = slot->connection_id; 	/* transport connection identifier*/

		len = 5;	
	}

#ifdef direct_write
	res = write(slot->fd, d, len); 

	free(d);
	if (res < 0 || res != len) 
	{ 
		printf("error writing data to fd %d, slot %d: %m\n", slot->fd, slot->slot);
		return eDataError; 
	}
#else
	slot->sendqueue.push( queueData(d, len) );
#endif	 
	
	return eDataReady;
}