ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An IRC bouncer. 00002 // 00003 //! @file Server.cc 00004 //! @brief This file contains the implementation of class Server. 00005 // 00006 // Copyright (C) 2005 - 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef USE_PCH 00017 #include "sys.h" 00018 #include "debug.h" 00019 #endif 00020 00021 #include "Server.h" 00022 #include "PersistXML.h" 00023 #include "Network.h" 00024 #include <libcw/timing.h> 00025 #include <boost/random/linear_congruential.hpp> 00026 #include <boost/random/uniform_smallint.hpp> 00027 00028 timeval Server::S_last_connection_event_init = { 0, 0 }; 00029 00030 //! @brief Serialize object to XML. 00031 void Server::serialize(PersistXML& xml) 00032 { 00033 xml.serialize("M_hostname", M_hostname); 00034 xml.serialize("M_irc_name", M_irc_name); 00035 xml.serialize("M_ports", M_ports); 00036 xml.serialize("M_default_port", M_default_port); 00037 xml.serialize("M_last_connection_event.tv_sec", M_last_connection_event.tv_sec); 00038 xml.serialize("M_last_connection_event.tv_usec", M_last_connection_event.tv_usec); 00039 xml.serialize("M_version", M_version); 00040 00041 if (xml.openmode() == PersistXML::load) 00042 M_next_port = random_port(); 00043 } 00044 00045 unsigned short Server::random_port(void) const 00046 { 00047 static uint64_t seed = (uint64_t)timerRequest.get_now().tv_sec << 32 + timerRequest.get_now().tv_usec; 00048 static boost::rand48 urng(seed); 00049 if (M_ports.empty()) 00050 return M_default_port; 00051 boost::uniform_smallint<int> rd(0, M_ports.size() - 1); 00052 return M_ports[rd(urng)]; 00053 }
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|