X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fsocket.cpp;h=6d48178f963504c24075e270bc945da31ef3a25f;hb=347216d654e6f284119d9473db03e3393002b286;hp=88ba78c6ad0c601dde7ca195e1a9494161e0e9b2;hpb=c707e00195f1035ae535f3fc8697af42e73190c0;p=oweals%2Fminetest.git diff --git a/src/socket.cpp b/src/socket.cpp index 88ba78c6a..6d48178f9 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -1,12 +1,34 @@ +/* +Minetest-c55 +Copyright (C) 2010 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + #include "socket.h" #include "debug.h" #include #include #include #include +#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; @@ -31,6 +53,8 @@ void sockets_cleanup() Address::Address() { + m_address = 0; + m_port = 0; } Address::Address(unsigned int address, unsigned short port) @@ -73,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; @@ -88,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; @@ -175,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<20) @@ -248,7 +288,7 @@ int UDPSocket::Receive(Address & sender, void * data, int size) //dstream<<", received="<20) @@ -297,7 +337,13 @@ bool UDPSocket::WaitData(int timeout_ms) dstream<<(int)m_handle<<": Select failed: "<