]> git.lizzy.rs Git - minetest.git/blobdiff - src/socket.cpp
tuned error reporting a bit
[minetest.git] / src / socket.cpp
index 9ff30e10ff487678f4f270f45080f37d46ead77f..ab3ca62c58d6ee90ee1dc050c92dd7207a9daedd 100644 (file)
@@ -23,9 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iostream>
 #include <stdlib.h>
 #include <errno.h>
+#include "utility.h"
 
 // Debug printing options
+// Set to 1 for debug output
 #define DP 0
+// This is prepended to everything printed here
 #define DPS ""
 
 bool g_sockets_initialized = false;
@@ -50,6 +53,8 @@ void sockets_cleanup()
 
 Address::Address()
 {
+       m_address = 0;
+       m_port = 0;
 }
 
 Address::Address(unsigned int address, unsigned short port)
@@ -107,6 +112,12 @@ void Address::setAddress(unsigned int address)
        m_address = address;
 }
 
+void Address::setAddress(unsigned int a, unsigned int b,
+               unsigned int c, unsigned int d)
+{
+       m_address = (a<<24) | (b<<16) | ( c<<8) | d;
+}
+
 void Address::setPort(unsigned short port)
 {
        m_port = port;
@@ -194,8 +205,8 @@ void UDPSocket::Send(const Address & destination, const void * data, int size)
 {
        bool dumping_packet = false;
        if(INTERNET_SIMULATOR)
-               dumping_packet = (rand()%10==0); //easy
-               //dumping_packet = (rand()%4==0); // hard
+               dumping_packet = (myrand()%10==0); //easy
+               //dumping_packet = (myrand()%4==0); // hard
 
        if(DP){
                /*dstream<<DPS<<"UDPSocket("<<(int)m_handle
@@ -205,7 +216,7 @@ void UDPSocket::Send(const Address & destination, const void * data, int size)
                destination.print();
                dstream<<", size="<<size<<", data=";
                for(int i=0; i<size && i<20; i++){
-                       if(i%2==0) printf(" ");
+                       if(i%2==0) DEBUGPRINT(" ");
                        DEBUGPRINT("%.2X", ((int)((const char*)data)[i])&0xff);
                }
                if(size>20)
@@ -267,7 +278,7 @@ int UDPSocket::Receive(Address & sender, void * data, int size)
                //dstream<<", received="<<received<<std::endl;
                dstream<<", size="<<received<<", data=";
                for(int i=0; i<received && i<20; i++){
-                       if(i%2==0) printf(" ");
+                       if(i%2==0) DEBUGPRINT(" ");
                        DEBUGPRINT("%.2X", ((int)((const char*)data)[i])&0xff);
                }
                if(received>20)