/** ** Cleanup network. */ void ExitNetwork1() { if (!IsNetworkGame()) { // No network running return; } #ifdef DEBUG printStatistic(NetworkFildes.getStatistic()); NetworkFildes.clearStatistic(); NetworkStat.print(); #endif NetworkFildes.Close(); NetExit(); // machine dependent setup NetworkInSync = true; NetPlayers = 0; HostsCount = 0; }
/** ** Initialize network port. */ void InitNetwork1() { CNetworkParameter::Instance.FixValues(); NetInit(); // machine dependent setup // Our communication port const int port = CNetworkParameter::Instance.localPort; const char *NetworkAddr = NULL; // FIXME : bad use const CHost host(NetworkAddr, port); NetworkFildes.Open(host); if (NetworkFildes.IsValid() == false) { fprintf(stderr, "NETWORK: No free port %d available, aborting\n", port); NetExit(); // machine dependent network exit return; } #ifdef DEBUG const std::string hostStr = host.toString(); DebugPrint("My host:port %s\n" _C_ hostStr.c_str()); #endif #if 0 // FIXME: need a working interface check unsigned long ips[10]; int networkNumInterfaces = NetSocketAddr(NetworkFildes, ips, 10); if (networkNumInterfaces) { DebugPrint("Num IP: %d\n" _C_ networkNumInterfaces); for (int i = 0; i < networkNumInterfaces; ++i) { DebugPrint("IP: %d.%d.%d.%d\n" _C_ NIPQUAD(ntohl(ips[i]))); } } else { fprintf(stderr, "NETWORK: Not connected to any external IPV4-network, aborting\n"); ExitNetwork1(); return; } #endif }
NetCenter::~NetCenter() { NetExit(); }