Reworked the inventory move handling code, hopefully fixed more problems than caused
[oweals/minetest.git] / src / socket.cpp
index f4b8f442943aaf78834569547ab376763a65aef0..6d48178f963504c24075e270bc945da31ef3a25f 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)
@@ -92,6 +97,16 @@ void Address::Resolve(const char *name)
        freeaddrinfo(resolved);
 }
 
+std::string Address::serializeString() const
+{
+       unsigned int a, b, c, d;
+       a = (m_address & 0xFF000000)>>24;
+       b = (m_address & 0x00FF0000)>>16;
+       c = (m_address & 0x0000FF00)>>8;
+       d = (m_address & 0x000000FF);
+       return itos(a)+"."+itos(b)+"."+itos(c)+"."+itos(d);
+}
+
 unsigned int Address::getAddress() const
 {
        return m_address;
@@ -107,6 +122,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 +215,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