Small TOCLIENT_HELLO logging fix
[oweals/minetest.git] / src / network / connection.cpp
index b808c3ab60d7f0e6553b7e0955a97ae0c878cf30..6e8bbd6c3a4cc4e8bfcab3415d8377220ae49e9c 100644 (file)
@@ -20,10 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iomanip>
 #include <errno.h>
 #include "connection.h"
-#include "main.h"
 #include "serialization.h"
 #include "log.h"
 #include "porting.h"
+#include "network/networkpacket.h"
 #include "util/serialize.h"
 #include "util/numeric.h"
 #include "util/string.h"
@@ -2884,30 +2884,36 @@ void Connection::Disconnect()
        putCommand(c);
 }
 
-u32 Connection::Receive(u16 &peer_id, SharedBuffer<u8> &data)
+void Connection::Receive(NetworkPacket* pkt)
 {
        for(;;) {
                ConnectionEvent e = waitEvent(m_bc_receive_timeout);
                if (e.type != CONNEVENT_NONE)
-                       LOG(dout_con<<getDesc()<<": Receive: got event: "
-                                       <<e.describe()<<std::endl);
+                       LOG(dout_con << getDesc() << ": Receive: got event: "
+                                       << e.describe() << std::endl);
                switch(e.type) {
                case CONNEVENT_NONE:
                        throw NoIncomingDataException("No incoming data");
                case CONNEVENT_DATA_RECEIVED:
-                       peer_id = e.peer_id;
-                       data = SharedBuffer<u8>(e.data);
-                       return e.data.getSize();
+                       // Data size is lesser than command size, ignoring packet
+                       if (e.data.getSize() < 2) {
+                               continue;
+                       }
+
+                       pkt->putRawPacket(*e.data, e.data.getSize(), e.peer_id);
+                       return;
                case CONNEVENT_PEER_ADDED: {
                        UDPPeer tmp(e.peer_id, e.address, this);
                        if (m_bc_peerhandler)
                                m_bc_peerhandler->peerAdded(&tmp);
-                       continue; }
+                       continue;
+               }
                case CONNEVENT_PEER_REMOVED: {
                        UDPPeer tmp(e.peer_id, e.address, this);
                        if (m_bc_peerhandler)
                                m_bc_peerhandler->deletingPeer(&tmp, e.timeout);
-                       continue; }
+                       continue;
+               }
                case CONNEVENT_BIND_FAILED:
                        throw ConnectionBindFailed("Failed to bind socket "
                                        "(port already in use?)");