]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/connection.cpp
Make dungeon masters though and make oerkkis disappear when they get to you (because...
[dragonfireclient.git] / src / connection.cpp
index 6c37ff63bf9d5f81806025db91e67b39d719248f..89cb7dd0b3dd8aad8298e3e331a441038056ee63 100644 (file)
@@ -320,7 +320,7 @@ IncomingSplitBuffer::~IncomingSplitBuffer()
        This will throw a GotSplitPacketException when a full
        split packet is constructed.
 */
-void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
+SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
 {
        u32 headersize = BASE_HEADER_SIZE + 7;
        assert(p.data.getSize() >= headersize);
@@ -363,9 +363,9 @@ void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
        // Set chunk data in buffer
        sp->chunks[chunk_num] = chunkdata;
        
-       // If not all chunks are received, return
+       // If not all chunks are received, return empty buffer
        if(sp->allReceived() == false)
-               return;
+               return SharedBuffer<u8>();
 
        // Calculate total size
        u32 totalsize = 0;
@@ -392,8 +392,8 @@ void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
        // Remove sp from buffer
        m_buf.remove(seqnum);
        delete sp;
-       
-       throw GotSplitPacketException(fulldata);
+
+       return fulldata;
 }
 void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
 {
@@ -497,7 +497,7 @@ Connection::Connection(
        m_protocol_id = protocol_id;
        m_max_packet_size = max_packet_size;
        m_timeout = timeout;
-       m_peer_id = PEER_ID_NEW;
+       m_peer_id = PEER_ID_INEXISTENT;
        //m_waiting_new_peer_id = false;
        m_indentation = 0;
        m_peerhandler = peerhandler;
@@ -534,8 +534,8 @@ void Connection::Connect(Address address)
        
        m_socket.Bind(0);
        
-       // Send a dummy packet to server with peer_id = PEER_ID_NEW
-       m_peer_id = PEER_ID_NEW;
+       // Send a dummy packet to server with peer_id = PEER_ID_INEXISTENT
+       m_peer_id = PEER_ID_INEXISTENT;
        SharedBuffer<u8> data(0);
        Send(PEER_ID_SERVER, 0, data, true);
 
@@ -568,7 +568,7 @@ bool Connection::Connected()
        if(node == NULL)
                return false;
        
-       if(m_peer_id == PEER_ID_NEW)
+       if(m_peer_id == PEER_ID_INEXISTENT)
                return false;
        
        return true;
@@ -643,7 +643,7 @@ SharedBuffer<u8> Channel::ProcessPacket(
                        con->PrintInfo();
                        dout_con<<"Got new peer id: "<<peer_id_new<<"... "<<std::endl;
 
-                       if(con->GetPeerID() != PEER_ID_NEW)
+                       if(con->GetPeerID() != PEER_ID_INEXISTENT)
                        {
                                con->PrintInfo(derr_con);
                                derr_con<<"WARNING: Not changing"
@@ -709,21 +709,17 @@ SharedBuffer<u8> Channel::ProcessPacket(
                                con->GetProtocolID(),
                                peer_id,
                                channelnum);
-               try{
-                       // Buffer the packet
-                       incoming_splits.insert(packet, reliable);
-               }
-               // This exception happens when all the pieces of a packet
-               // are collected.
-               catch(GotSplitPacketException &e)
+               // Buffer the packet
+               SharedBuffer<u8> data = incoming_splits.insert(packet, reliable);
+               if(data.getSize() != 0)
                {
                        con->PrintInfo();
                        dout_con<<"RETURNING TYPE_SPLIT: Constructed full data, "
-                                       <<"size="<<e.getData().getSize()<<std::endl;
-                       return e.getData();
+                                       <<"size="<<data.getSize()<<std::endl;
+                       return data;
                }
                con->PrintInfo();
-               dout_con<<"BUFFERING TYPE_SPLIT"<<std::endl;
+               dout_con<<"BUFFERED TYPE_SPLIT"<<std::endl;
                throw ProcessedSilentlyException("Buffered a split packet chunk");
        }
        else if(type == TYPE_RELIABLE)
@@ -951,7 +947,7 @@ u32 Connection::Receive(u16 &peer_id, u8 *data, u32 datasize)
                        throw InvalidIncomingDataException("Channel doesn't exist");
                }
 
-               if(peer_id == PEER_ID_NEW)
+               if(peer_id == PEER_ID_INEXISTENT)
                {
                        /*
                                Somebody is trying to send stuff to us with no peer id.
@@ -994,7 +990,7 @@ u32 Connection::Receive(u16 &peer_id, u8 *data, u32 datasize)
                /*
                        The peer was not found in our lists. Add it.
                */
-               if(peer_id == PEER_ID_NEW)
+               if(peer_id == PEER_ID_INEXISTENT)
                {
                        // Somebody wants to make a new connection
 
@@ -1016,7 +1012,7 @@ u32 Connection::Receive(u16 &peer_id, u8 *data, u32 datasize)
                        }
 
                        PrintInfo();
-                       dout_con<<"Receive(): Got a packet with peer_id=PEER_ID_NEW,"
+                       dout_con<<"Receive(): Got a packet with peer_id=PEER_ID_INEXISTENT,"
                                        " giving peer_id="<<peer_id_new<<std::endl;
 
                        // Create a peer
@@ -1042,7 +1038,7 @@ u32 Connection::Receive(u16 &peer_id, u8 *data, u32 datasize)
                if(node == NULL)
                {
                        // Peer not found
-                       // This means that the peer id of the sender is not PEER_ID_NEW
+                       // This means that the peer id of the sender is not PEER_ID_INEXISTENT
                        // and it is invalid.
                        PrintInfo(derr_con);
                        derr_con<<"Receive(): Peer not found"<<std::endl;
@@ -1125,7 +1121,9 @@ void Connection::Send(u16 peer_id, u8 channelnum,
 {
        assert(channelnum < CHANNEL_COUNT);
        
-       Peer *peer = GetPeer(peer_id);
+       Peer *peer = GetPeerNoEx(peer_id);
+       if(peer == NULL)
+               return;
        Channel *channel = &(peer->channels[channelnum]);
 
        u32 chunksize_max = m_max_packet_size - BASE_HEADER_SIZE;
@@ -1317,7 +1315,7 @@ Peer* Connection::GetPeer(u16 peer_id)
 
        if(node == NULL){
                // Peer not found
-               throw PeerNotFoundException("Peer not found (possible timeout)");
+               throw PeerNotFoundException("GetPeer: Peer not found (possible timeout)");
        }
 
        // Error checking