コード例 #1
0
void QuestsPacket::questFinish(Player* player, vector <Player*> players,short questid, int npcid, short nextquest, __int64 time){
	Packet packet = Packet();
	packet.addHeader(0x32);
	packet.addByte(1);
	packet.addShort(questid);
	packet.addByte(2);
	packet.addInt64(time);
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x6D);
	packet.addByte(6);
	packet.addShort(questid); 
	packet.addInt(npcid); 
	packet.addShort(nextquest); 
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x68);
	packet.addByte(9);
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x86);
	packet.addInt(player->getPlayerid());
	packet.addByte(9);
	packet.sendTo(player, players, 0);
}
コード例 #2
0
ファイル: ymodem.cpp プロジェクト: Gauraden/regiboard
bool YModem::SendFile(const std::string &path, YModem::SPort &out) {
  if (path.size() == 0 ||
      not out.is_open())
    return false;
  std::fstream firm_str(path.c_str());
  if (not firm_str.is_open())
    return false;
  firm_str.seekg(0, firm_str.end);
  const size_t kFileSize = firm_str.tellg();
  firm_str.seekg(0, firm_str.beg);
  // ожидание запроса
  WaitForResponse(out, Packet::kRequest);
  Packet::Sequence seq(&out);
  // инициализация соединения
  char buf[24];
  snprintf(buf, 24, "%u", (unsigned)kFileSize);
  const std::string kMsgs[] = {path, buf};
  SendInitialPkt(seq, kMsgs, 2);
  if (not IsResponse(out, Packet::kRequest)) {
    firm_str.close();
    return false;
  }
  // передача файла
  Array frame(NewFrame());
  size_t was_send     = 0;
  size_t last_percent = 0;
  do {
    firm_str.sync();
    firm_str.read((char*)frame.get(), kFrameSize);
    const size_t kWasRead = firm_str.gcount();
    if (kWasRead != kFrameSize) {
      memset(frame.get() + kWasRead, 0, kFrameSize - kWasRead);
    }
    seq.Send(Packet(Packet::kSTX, frame.get(), kFrameSize));
    was_send += kWasRead;
    if (not IsResponse(out, Packet::kACK)) {
      std::cout << "\t ! Ошибка передачи данных" << std::endl;
      break;
    }
    const size_t kPercent = was_send * 100 / kFileSize;
    if (kPercent > last_percent) {
      ShowPercentage("\t * Прогресс", kPercent);
      last_percent = kPercent;
    }
  } while (was_send < kFileSize);
  std::cout << std::endl;
  seq.Send(Packet(Packet::kEOT));
  IsResponse(out, Packet::kACK);
  seq.Send(Packet(Packet::kEOT));
  IsResponse(out, Packet::kACK);
  IsResponse(out, Packet::kRequest);
  SendClosingPkt(seq);
  firm_str.close();
  return true;
}
コード例 #3
0
ファイル: ip4and6.cpp プロジェクト: mmaraya/ipforensics
/**
 *  @todo Add command-line parameters for IPv4 network address and mask so we 
 *        can remove broadcast and multicast hosts from the result
 */
void IPForensics::load_hosts(std::string filename) {
  // open the filename
  char error[PCAP_ERRBUF_SIZE] {};
  pcap_t* pcap = pcap_open_offline(filename.c_str(), error);
  if (pcap == NULL) {
    throw std::runtime_error(error);
  }
  // exit if the data link is not Ethernet
  if (pcap_datalink(pcap) != DLT_EN10MB) {
    pcap_close(pcap);
    throw std::runtime_error("Link-layer type not IEEE 802.3 Ethernet");
  }
  // read the packets from the file
  const unsigned char * packet = NULL;
  struct pcap_pkthdr header;
  // if packet_count_ is set, read specified number of packets only
  if (packet_count_ > 0) {
    for (int i = 0; i < packet_count_; ++i) {
      packet = pcap_next(pcap, &header);
      if (packet != NULL) {
        packets_.push_back(Packet(packet));
      }
    }
  } else {
    // if packet_count_ is not set, read all packets
    packet = pcap_next(pcap, &header);
    while (packet != NULL) {
      packets_.push_back(Packet(packet));
      packet = pcap_next(pcap, &header);
    }
  }
  // close the packet capture
  pcap_close(pcap);
  // extract hosts from packets
  for (Packet p : packets_) {
    // add the source host
    std::set<Host>::iterator it = hosts_.find(static_cast<Host>(p.mac_src()));
    if (it == hosts_.end()) {
      add_host(p.mac_src(), p.ipv4_src(), p.ipv6_src());
    } else {
      update_host(it, p.ipv4_src(), p.ipv6_src());
    }
    // add the destination host
    it = hosts_.find(static_cast<Host>(p.mac_dst()));
    if (it == hosts_.end()) {
      add_host(p.mac_dst(), p.ipv4_dst(), p.ipv6_dst());
    } else {
      update_host(it, p.ipv4_dst(), p.ipv6_dst());
    }
  }
  // remove meaningless hosts
  clean_hosts(nullptr, nullptr);
}
コード例 #4
0
ファイル: AVDemuxThread.cpp プロジェクト: bianshifeng/QtAV
void AVDemuxThread::seekInternal(qint64 pos)
{
    if (audio_thread) {
        audio_thread->setDemuxEnded(false);
        audio_thread->packetQueue()->clear();
    }
    if (video_thread) {
        video_thread->setDemuxEnded(false);
        video_thread->packetQueue()->clear();
    }
    qDebug("seek to %lld ms (%f%%)", pos, double(pos)/double(demuxer->duration())*100.0);
    demuxer->seek(pos);
    // TODO: why queue may not empty?
    if (audio_thread) {
        audio_thread->packetQueue()->clear();
        audio_thread->packetQueue()->put(Packet());
    }
    if (video_thread) {
        video_thread->packetQueue()->clear();
        // TODO: the first frame (key frame) will not be decoded correctly if flush() is called.
        video_thread->packetQueue()->put(Packet());
    }
    //if (subtitle_thread) {
    //     subtitle_thread->packetQueue()->clear();
    //    subtitle_thread->packetQueue()->put(Packet());
    //}
#if RESUME_ONCE_ON_SEEK
    class PauseTask : public QRunnable {
    public:
        PauseTask(AVDemuxThread *dt, bool p)
            : pause(p)
            , demux_thread(dt)
        {}
        void run() {
            if (pause && !demux_thread->isPaused()) // what if user resume?
                demux_thread->pauseInternal(true);
            if (!pause && demux_thread->isPaused())
                demux_thread->pauseInternal(false);
        }
    private:
        bool pause;
        AVDemuxThread *demux_thread;
    };
    pause_tasks.clear();
    if (isPaused()) {
        pause_tasks.enqueue(new PauseTask(this, false));
        pause_tasks.enqueue(new PauseTask(this, true));
    } else {
        pause_tasks.enqueue(new PauseTask(this, true));
    }
#endif
}
コード例 #5
0
ファイル: commandCache.cpp プロジェクト: cstalder/Equalizer
int main( int argc, char **argv )
{
    co::init( argc, argv );
    {
        Reader readers[ N_READER ];
        for( size_t i = 0; i < N_READER; ++i )
            readers[i].start();

        co::CommandCache cache;
        co::LocalNodePtr node = new co::LocalNode;
        size_t nOps = 0;

        co::base::Clock clock;
        while( clock.getTime64() < RUNTIME )
        {
            co::Command& command = cache.alloc( node, node, sizeof( Packet ));
            Packet* packet = command.get< Packet >();
            *packet = Packet();

            readers[0].dispatchCommand( command );

            for( size_t i = 1; i < N_READER; ++i )
            {
                co::Command& clone = cache.clone( command );
                readers[i].dispatchCommand( clone );
            }
            ++nOps;
        }

        const uint64_t time = clock.getTime64();
        nOps *= N_READER;
        std::cout << nOps << " operations, " << nOps / time << " ops/ms"
                  << std::endl;

        for( size_t i = 0; i < N_READER; ++i )
        {
            co::Command& command = cache.alloc( node, node, sizeof( Packet ));
            Packet* packet = command.get< Packet >();
            *packet = Packet();
            packet->command = 1;

            readers[i].dispatchCommand( command );
            readers[i].join();
        }
    }

    TEST( co::exit( ));
    return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: packet.cpp プロジェクト: wysamuel/behavioral-model
Packet
Packet::make_new(size_t cxt, int ingress_port, packet_id_t id,
                 copy_id_t copy_id, int ingress_length,
                 PacketBuffer &&buffer, PHVSourceIface *phv_source) {
  return Packet(cxt, ingress_port, id, copy_id, ingress_length,
                std::move(buffer), phv_source);
}
コード例 #7
0
void Receiver::enterRVIMode(){
	int flag;
	int tCount = 0 ;
	pSerial_->sendPacket(Packet(RVI));
	while(true){
		try{
			flag = pSerial_->getPacket().flags();
			if (flag == ACK1){
				break;
			}
		}catch(int i){
			ENSURE_EXCEPTION(i, TIMEOUT_EXCEPTION);
				throw GOTO_RESET_EXCEPTION;

		}
	}

	while(!(pBuffer_->safe())){
		pSerial_->sendPacket((pBuffer_->peek()));
		pBuffer_->pop();	
	}
	if(pBuffer_->safe()){
		throw GOTO_IDLE_EXCEPTION;
	}
}
コード例 #8
0
void CRemoteConnection::ProcessRawPacket(const unsigned char* data, const unsigned length)
{
	lastReceiveTime=static_cast<float>(SDL_GetTicks())/1000.0f;

	const unsigned hsize = 9;
	int packetNum=*(int*)data;
	int ack=*(int*)(data+4);
	unsigned char nak = *(unsigned char*)(data+8);

	AckPackets(ack);

	if (nak > 0)	// we have lost $nak packets
	{
		int nak_abs = nak + firstUnacked - 1;
		if (nak_abs!=lastNak || lastNakTime < lastReceiveTime-0.1f)
		{
			// resend all packets from firstUnacked till nak_abs
			lastNak=nak_abs;
			lastNakTime=lastReceiveTime;
			for(int b=firstUnacked;b<=nak_abs;++b){
				SendRawPacket(unackedPackets[b-firstUnacked]->data,unackedPackets[b-firstUnacked]->length,b);
				++resentPackets;
			}
		}
	}

	if(!active || lastInOrder>=packetNum || waitingPackets.find(packetNum)!=waitingPackets.end())
		return;

	Packet* p=SAFE_NEW Packet(data+hsize,length-hsize);
	waitingPackets[packetNum]=p;

	dataRecv += length;
	recvOverhead += hsize;
}
コード例 #9
0
ファイル: packet.cpp プロジェクト: bqqbarbhg/netgame
Packet PacketPool::allocate(int size)
{
	if (size <= 0)
		return Packet();
	Packet ret(m_pages[m_alloc_page].get(), m_alloc_ptr, size);

	// Advance the allocation location
	m_alloc_ptr += size;
	// If there is not enough room in the current page
	if (m_alloc_ptr >= m_page_size - m_packet_size) {
		// Try to find an empty one
		unsigned int i;
		for (i = 0; i < m_pages.size(); i++) {
			if (*reinterpret_cast<unsigned int*>(m_pages[i].get()) == 0) {
				break;
			}
		}
		m_alloc_page = i;
		m_alloc_ptr = PAGE_HEADER_SIZE;
		// If the page doesn't exist create it
		if (i == m_pages.size()) {
			add_page();
		}
	}

	return ret;
}
コード例 #10
0
ファイル: Packet.cpp プロジェクト: karvaporo/QtAV
Packet Packet::fromAVPacket(const AVPacket *avpkt, double time_base)
{
    Packet pkt;
    if (fromAVPacket(&pkt, avpkt, time_base))
        return pkt;
    return Packet();
}
コード例 #11
0
ファイル: iproto_conn.cpp プロジェクト: PSIAlt/asio-libs
void Conn::onRead(const boost::system::error_code& error, std::shared_ptr< boost::asio::streambuf > rd_buf) {
	if( unlikely(error) ) {
		log_func("[iproto_conn] %s:%u read error: %s", ep.address().to_string().c_str(), ep.port(), error.message().c_str() );
		dismissCallbacks(CB_ERR);
		if( error != boost::asio::error::operation_aborted ) {
			reconnect();
		}
		return;
	}
	if( unlikely(!rd_buf) )
		rd_buf.reset(new boost::asio::streambuf);
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u onRead rd_buf->size=%zu", ep.address().to_string().c_str(), ep.port(), rd_buf->size());
	while( rd_buf->size() >= sizeof(Header) ) {
		const PacketPtr *buf = boost::asio::buffer_cast< const PacketPtr * >( rd_buf->data() );
		if( LOG_DEBUG )
			log_func("[iproto_conn] %s:%u onRead buffer iproto packet hdr: len=%u sync=%u msg=%u", ep.address().to_string().c_str(), ep.port(),
				buf->hdr.len, buf->hdr.sync, buf->hdr.msg);
		size_t want_read = sizeof(Header)+buf->hdr.len;
		if( want_read <= rd_buf->size() ) {
			invokeCallback(buf->hdr.sync, RequestResult(CB_OK, Packet(buf)) );
			rd_buf->consume( sizeof(Header) + buf->hdr.len );
		}else{
			size_t rd = want_read - rd_buf->size();
			if( LOG_DEBUG )
				log_func("[iproto_conn] %s:%u onRead want_read=%zu", ep.address().to_string().c_str(), ep.port(), rd);
			boost::asio::async_read(sock, *rd_buf, boost::asio::transfer_at_least(rd),
				boost::bind(&Conn::onRead, shared_from_this(), boost::asio::placeholders::error, rd_buf) );
			return;
		}
	}
	if( likely(sock.is_open()) )
		boost::asio::async_read(sock, *rd_buf, boost::asio::transfer_at_least(sizeof(Header)-rd_buf->size()),
			boost::bind(&Conn::onRead, shared_from_this(), boost::asio::placeholders::error, rd_buf) );
}
コード例 #12
0
ファイル: DropsPacket.cpp プロジェクト: Dephon/MapleStory_tms
void DropsPacket::removeDrop(vector <Player*> players, Drop* drop){
	Packet packet = Packet();
	packet.addHeader(0xBA);
	packet.addByte(0);
	packet.addInt(drop->getObjID());
	packet.sendTo(NULL, players, 1);
}
コード例 #13
0
ファイル: DSMSplitter.cpp プロジェクト: Blitzker/mpc-hc
bool CDSMSplitterFilter::DemuxLoop()
{
    HRESULT hr = S_OK;

    while (SUCCEEDED(hr) && !CheckRequest(nullptr) && m_pFile->GetRemaining()) {
        dsmp_t type;
        UINT64 len;

        if (!m_pFile->Sync(type, len)) {
            continue;
        }

        __int64 pos = m_pFile->GetPos();

        if (type == DSMP_SAMPLE) {
            CAutoPtr<Packet> p(DEBUG_NEW Packet());
            if (m_pFile->Read(len, p)) {
                if (p->rtStart != Packet::INVALID_TIME) {
                    p->rtStart -= m_pFile->m_rtFirst;
                    p->rtStop -= m_pFile->m_rtFirst;
                }

                hr = DeliverPacket(p);
            }
        }

        m_pFile->Seek(pos + len);
    }

    return true;
}
コード例 #14
0
//
// bool sendMsg(msg, toID, fromID, type)
// Last modified: 07Sep2006
//
// Attempts to send a packet to its destination
// based upon the given parameters, returning
// true if successful, false otherwise.
//
// Returns:     true if successful, false otherwise
// Parameters:
//      msg     in/out  the message being sent
//      toID    in      the ID of the cell receiving the packet
//      fromID  in      the ID of the cell sending the packet
//      type    in      the type of message being sent
//
bool Environment::sendMsg(const Message &msg,
                          const GLint    toID,
                          const GLint    fromID,
                          const GLint    type)
{
    return sendPacket(Packet(msg, toID, fromID, type));
}   // sendMsg(const Message &, const GLint, const GLint, const GLint)
コード例 #15
0
void QuestsPacket::giveMesos(Player* player, int amount){
	Packet packet = Packet();
	packet.addHeader(0x32);
	packet.addByte(5);
	packet.addInt(amount);
	packet.packetSend(player);
}
コード例 #16
0
ファイル: KOSocket.cpp プロジェクト: nikos32/snoxd-koserver
bool KOSocket::DecryptPacket(uint8 *in_stream, Packet & pkt)
{
    uint8* final_packet = nullptr;

    if (isCryptoEnabled())
    {
        // Invalid packet (all encrypted packets need a CRC32 checksum!)
        if (m_remaining < 4
                // Invalid checksum
                || m_crypto.JvDecryptionWithCRC32(m_remaining, in_stream, in_stream) < 0
                // Invalid sequence ID
                || ++m_sequence != *(uint32 *)(in_stream))
            return false;

        m_remaining -= 8; // remove the sequence ID & CRC checksum
        final_packet = &in_stream[4];
    }
    else
    {
        final_packet = in_stream; // for simplicity :P
    }

    m_remaining--;
    pkt = Packet(final_packet[0], (size_t)m_remaining);
    if (m_remaining > 0)
    {
        pkt.resize(m_remaining);
        memcpy((void*)pkt.contents(), &final_packet[1], m_remaining);
    }

    return true;
}
コード例 #17
0
ファイル: PacketQueue.cpp プロジェクト: 0vermind/NeoLoader
UINT CPacketQueue::Push(const string &Name, const CVariant& Data, int iPriority/*, uint32 uTTL*/)
{
	SVarPacket Packet(Name, Data, iPriority);
	Packet.Data.Freeze();
	ASSERT(Packet.Data.IsFrozen());
	Packet.uID = ++m_uLastID;
	/*if(uTTL != -1)
		Packet.uTTL = GetCurTick() + uTTL;*/

	m_QueueSize += Packet.Data.GetSize() + Packet.Name.size();

	if(iPriority)
	{
		//deque<SVarPacket>::iterator I = find_if(m_Queue.begin(), m_Queue.end(), ...);
		deque<SVarPacket>::iterator first = m_Queue.begin();
		deque<SVarPacket>::iterator last = m_Queue.end();
		for (; first != last; ++first) 
		{
			if (first->iPriority < iPriority) // find the first packet that has a lower priority than ours and insert it befoure it
			{ 
				last = first;
				break;
			}
		}
		m_Queue.insert(last, Packet);
	}
	else
		m_Queue.push_back(Packet);

	return m_uLastID;
}
コード例 #18
0
void Node::PacketGenerating(int time){//节点是否产生数据包,以及能量消耗
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}
	double pos = (double) (rand() + 1) / (double)RAND_MAX;
	if(time % SENSE_DURATION == 1){//因为是从第一秒开始计算的么
		if(pos <= POSIBILITY_PACKET_GENERATING){//产生数据包
			bufferedPackets.push(Packet(id, MAX_TIME));
		}
		if(currentWorkState == Sleeping){
			return;
		}
		
		int i = 0;
		while(!bufferedPackets.empty() && i < MAX_PACKETS_PER_SLOT){
			//RoutingWithBufferedPackets();
			bufferedPackets.pop();
			++i;
		}
		if(bufferedPackets.empty() && currentState == NonGatewayNode){
			pos = (double) (rand() + 1) / (double)RAND_MAX;
			if(pos <= POSIBILITY_PACKET_GENERATING){
				currentWorkState = Sleeping;
				workingTime = 0;
				relaxingTime = 0;
			}
		}
	}
}
コード例 #19
0
ファイル: PacketVector.cpp プロジェクト: dmitsov/PuzzleGame
void PktVector::push_back(const u_char *packet, u_int8_t ifType){
    if(m_size >= m_capacity)
        resize();
    m_collection[m_size] = Packet(packet,ifType);
    m_collection[m_size].SetPtrsToNull();
    m_size++;
}
コード例 #20
0
ファイル: microflo.cpp プロジェクト: pgreenwood/microflo
void Network::runSetup() {
    for (int i=0; i<MAX_NODES; i++) {
        if (nodes[i]) {
            nodes[i]->process(Packet(MsgSetup), -1);
        }
    }
}
コード例 #21
0
ファイル: Audio.cpp プロジェクト: ArminW/re-whisper
void LoopPlayer::addFrame(const QByteArray &packet, int seq) {
	if (DOUBLE_RAND < g.s.dPacketLoss) {
		qWarning("Drop");
		return;
	}

	bool restart = (qtLastFetch.elapsed() > 100);

	{
		QMutexLocker l(&qmLock);

		double time = qtTicker.elapsed();

		double r;
		if (restart)
			r = 0.0;
		else
			r = DOUBLE_RAND * g.s.dMaxPacketDelay;

		qmPackets.insert(static_cast<float>(time + r), Packet(seq, packet));
	}

	// Restart check
	if (qtLastFetch.elapsed() > 100) {
		AudioOutputPtr ao = g.ao;
		if (ao) {
			ao->addFrameToBuffer(this, QByteArray(), 0);
		}
	}

}
コード例 #22
0
uint32 FOnlineSessionNull::FindLANSession()
{
	uint32 Return = ERROR_IO_PENDING;

	// Recreate the unique identifier for this client
	GenerateNonce((uint8*)&LANSessionManager.LanNonce, 8);

	FOnValidResponsePacketDelegate ResponseDelegate = FOnValidResponsePacketDelegate::CreateRaw(this, &FOnlineSessionNull::OnValidResponsePacketReceived);
	FOnSearchingTimeoutDelegate TimeoutDelegate = FOnSearchingTimeoutDelegate::CreateRaw(this, &FOnlineSessionNull::OnLANSearchTimeout);

	FNboSerializeToBufferNull Packet(LAN_BEACON_MAX_PACKET_SIZE);
	LANSessionManager.CreateClientQueryPacket(Packet, LANSessionManager.LanNonce);
	if (LANSessionManager.Search(Packet, ResponseDelegate, TimeoutDelegate) == false)
	{
		Return = E_FAIL;

		FinalizeLANSearch();

		CurrentSessionSearch->SearchState = EOnlineAsyncTaskState::Failed;
		
		// Just trigger the delegate as having failed
		TriggerOnFindSessionsCompleteDelegates(false);
	}
	return Return;
}
コード例 #23
0
bool CMpaSplitterFilter::DemuxLoop()
{
	HRESULT hr = S_OK;

	int FrameSize;
	REFERENCE_TIME rtDuration;

	while (SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetPos() < m_pFile->GetEndPos() - 9) {
		if (!m_pFile->Sync(FrameSize, rtDuration)) {
			Sleep(1);
			continue;
		}

		CAutoPtr<Packet> p(DNew Packet());
		p->SetCount(FrameSize);
		m_pFile->ByteRead(p->GetData(), FrameSize);

		p->TrackNumber = 0;
		p->rtStart = m_rtStart;
		p->rtStop = m_rtStart + rtDuration;
		p->bSyncPoint = TRUE;

		hr = DeliverPacket(p);

		m_rtStart += rtDuration;
	}

	return true;
}
コード例 #24
0
ファイル: DropsPacket.cpp プロジェクト: Dephon/MapleStory_tms
void DropsPacket::explodeDrop(vector <Player*> players, Drop* drop){
	Packet packet = Packet();
	packet.addHeader(0xBA);
	packet.addByte(4);
	packet.addInt(drop->getObjID());
	packet.addShort(655);
	packet.sendTo(NULL, players, 1);
}
コード例 #25
0
void CUDTSocketListner::Process()
{
	for(;;) // repeat untill all pending connections are accepted
	{
		/*timeval tv;
		tv.tv_sec = 0;
		tv.tv_usec = 0;
		UDT::UDSET readfds;
		UD_ZERO(&readfds);
		UD_SET(m_Server, &readfds);
		int res	= UDT::select(0, &readfds, NULL, NULL, &tv);
		if (!((res != UDT::ERROR) && (UD_ISSET(m_Server, &readfds))))
			break;*/
		
		sockaddr_in6 sa; // sockaddr_in is smaller
		int sa_len = sizeof(sa); 
		UDTSOCKET Client = UDT::accept(m_Server, (sockaddr*)&sa, &sa_len);
		if (UDT::INVALID_SOCK == Client)
		{
			LogLine(LOG_ERROR, L"accept: %S", UDT::getlasterror().getErrorMessage());
			break;
		}
		else if(Client == NULL)
			break;
		
		ConfigSocket(Client);

		uint64_t SendKey = 0;
		int KeySize = sizeof(SendKey);
		UDT::getsockopt(Client, 0, UDT_SENDKEY, &SendKey, &KeySize);

		CSafeAddress Address((sockaddr*)&sa, sa_len, sa_len == sizeof(sockaddr_in) ? CSafeAddress::eUDT_IP4 : CSafeAddress::eUDT_IP6);
		Address.SetPassKey(SendKey);
		GetParent<CSmartSocket>()->AddSessions(Address, new CUDTSocketSession(this, Client, Address));
	}

	const uint64 Size = 0xFFFF;
	char Buffer[Size];
	for(;;) // repeat untill all data is read
	{
		sockaddr_in6 sa; // sockaddr_in is smaller
		int sa_len = sizeof(sa); 
		uint64_t RecvKey = 0;
		int Recived = UDT::recvfrom(m_Server, Buffer, Size, (sockaddr*)&sa, &sa_len, &RecvKey);
		if (UDT::ERROR == Recived)
		{
			LogLine(LOG_ERROR, L"recvfrom: %S", UDT::getlasterror().getErrorMessage());
			break;
		}
		else if(Recived == 0)
			break; // nothing more to be recived
		CBuffer Packet(Buffer, Recived, true);

		CSafeAddress Address((sockaddr*)&sa, sa_len, sa_len == sizeof(sockaddr_in) ? CSafeAddress::eUDT_IP4 : CSafeAddress::eUDT_IP6);
		Address.SetPassKey(RecvKey);
		ReceiveFrom(Packet, Address);
	}
}
コード例 #26
0
ファイル: MapPacket.cpp プロジェクト: Dephon/MapleStory_tms
void MapPacket::removePlayer(Player* player, vector <Player*> players){
	Packet packet = Packet();
	packet.addHeader(0x71);
	packet.addInt(player->getPlayerid());
	for(unsigned int i=0; i<players.size(); i++){
		if(player->getPlayerid() != players[i]->getPlayerid())
			packet.packetSend(players[i]);
	}
}	
コード例 #27
0
	int change_player_slot(int portal, LobbyInfo *info) {
		Packet response;
		const int error_check = standard_order_checking(portal, Packet(MsgType::ORDER_CHANGE_PLAYER_SLOT), &response);
		if(error_check != Error::success)	return error_check;
		
		read_LobbyInfo(response, info);
		
		return Error::success;
	}
コード例 #28
0
	int getLobbyInfo(int portal, LobbyInfo *info) {
		Packet response;
		const int error_check = standard_order_checking(portal, Packet(MsgType::QUERY_GAME_PLAYERS), &response);
		if(error_check != Error::success)	return error_check;

		read_LobbyInfo(response, info);

		return Error::success;
	}
コード例 #29
0
void QuestsPacket::giveItem(Player* player, int itemid, int amount){
	Packet packet = Packet();
	packet.addHeader(0x68); 
	packet.addByte(3);
	packet.addByte(1);
	packet.addInt(itemid);
	packet.addInt(amount);
	packet.packetSend(player);
}
コード例 #30
0
void QuestsPacket::acceptQuest(Player* player, short questid, int npcid){
	Packet packet = Packet();
	packet.addHeader(0x32);
	packet.addByte(1);
	packet.addShort(questid);
	packet.addByte(1);
	packet.addInt(0);
	packet.addInt(0);
	packet.addShort(0);
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x6D);
	packet.addByte(6);
	packet.addShort(questid);
	packet.addInt(npcid);
	packet.addInt(0);
	packet.packetSend(player);
}