Beispiel #1
0
        static void PrintSlist()
        {
            int i;

            for (i = _SlistLastShown; i < HostCacheCount; i++)
            {
                hostcache_t hc = _HostCache[i];
                if (hc.maxusers != 0)
                {
                    Con.Print("{0,-15} {1,-15}\n {2,2}/{3,2}\n", Common.Copy(hc.name, 15), Common.Copy(hc.map, 15), hc.users, hc.maxusers);
                }
                else
                {
                    Con.Print("{0,-15} {1,-15}\n", Common.Copy(hc.name, 15), Common.Copy(hc.map, 15));
                }
            }
            _SlistLastShown = i;
        }
Beispiel #2
0
        // NET_Init (void)
        public static void Init()
        {
            for (int i2 = 0; i2 < _HostCache.Length; i2++)
            {
                _HostCache[i2] = new hostcache_t();
            }

            if (_Drivers == null)
            {
                if (Common.HasParam("-playback"))
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetVcr()
                    };
                }
                else
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetLoop(),
                        NetDatagram.Instance
                    };
                }
            }

            if (_LanDrivers == null)
            {
                _LanDrivers = new INetLanDriver[]
                {
                    NetTcpIp.Instance
                };
            }

            if (Common.HasParam("-record"))
            {
                _IsRecording = true;
            }

            int i = Common.CheckParm("-port");

            if (i == 0)
            {
                i = Common.CheckParm("-udpport");
            }
            if (i == 0)
            {
                i = Common.CheckParm("-ipxport");
            }

            if (i > 0)
            {
                if (i < Common.Argc - 1)
                {
                    _DefHostPort = Common.atoi(Common.Argv(i + 1));
                }
                else
                {
                    Sys.Error("Net.Init: you must specify a number after -port!");
                }
            }
            HostPort = _DefHostPort;

            if (Common.HasParam("-listen") || Client.cls.state == cactive_t.ca_dedicated)
            {
                _IsListening = true;
            }
            int numsockets = Server.svs.maxclientslimit;

            if (Client.cls.state != cactive_t.ca_dedicated)
            {
                numsockets++;
            }

            _FreeSockets   = new List <qsocket_t>(numsockets);
            _ActiveSockets = new List <qsocket_t>(numsockets);

            for (i = 0; i < numsockets; i++)
            {
                _FreeSockets.Add(new qsocket_t());
            }

            SetNetTime();

            // allocate space for network message buffer
            Message = new MsgWriter(NET_MAXMESSAGE); // SZ_Alloc (&net_message, NET_MAXMESSAGE);
            Reader  = new MsgReader(Net.Message);

            if (_MessageTimeout == null)
            {
                _MessageTimeout = new Cvar("net_messagetimeout", "300");
                _HostName       = new Cvar("hostname", "UNNAMED");
            }

            Cmd.Add("slist", Slist_f);
            Cmd.Add("listen", Listen_f);
            Cmd.Add("maxplayers", MaxPlayers_f);
            Cmd.Add("port", Port_f);

            // initialize all the drivers
            _DriverLevel = 0;
            foreach (INetDriver driver in _Drivers)
            {
                driver.Init();
                if (driver.IsInitialized && _IsListening)
                {
                    driver.Listen(true);
                }
                _DriverLevel++;
            }

            //if (*my_ipx_address)
            //    Con_DPrintf("IPX address %s\n", my_ipx_address);
            if (!String.IsNullOrEmpty(_MyTcpIpAddress))
            {
                Con.DPrint("TCP/IP address {0}\n", _MyTcpIpAddress);
            }
        }
Beispiel #3
0
        /// <summary>
        /// _Datagram_SearchForHosts
        /// </summary>
        void InternalSearchForHosts(bool xmit)
        {
            EndPoint myaddr = Net.LanDriver.ControlSocket.LocalEndPoint;

            if (xmit)
            {
                Net.Message.Clear();
                // save space for the header, filled in later
                Net.Message.WriteLong(0);
                Net.Message.WriteByte(CCReq.CCREQ_SERVER_INFO);
                Net.Message.WriteString("QUAKE");
                Net.Message.WriteByte(Net.NET_PROTOCOL_VERSION);
                Common.WriteInt(Net.Message.Data, 0, Common.BigLong(NetFlags.NETFLAG_CTL |
                                                                    (Net.Message.Length & NetFlags.NETFLAG_LENGTH_MASK)));
                Net.LanDriver.Broadcast(Net.LanDriver.ControlSocket, Net.Message.Data, Net.Message.Length);
                Net.Message.Clear();
            }

            EndPoint readaddr = new IPEndPoint(IPAddress.Any, 0);

            while (true)
            {
                Net.Message.FillFrom(Net.LanDriver.ControlSocket, ref readaddr);
                if (Net.Message.IsEmpty)
                {
                    break;
                }
                if (Net.Message.Length < sizeof(int))
                {
                    continue;
                }

                // don't answer our own query
                if (Net.LanDriver.AddrCompare(readaddr, myaddr) >= 0)
                {
                    continue;
                }

                // is the cache full?
                if (Net.HostCacheCount == Net.HOSTCACHESIZE)
                {
                    continue;
                }

                Net.Reader.Reset();
                int control = Common.BigLong(Net.Reader.ReadLong());// BigLong(*((int *)net_message.data));
                //MSG_ReadLong();
                if (control == -1)
                {
                    continue;
                }
                if ((control & (~NetFlags.NETFLAG_LENGTH_MASK)) != NetFlags.NETFLAG_CTL)
                {
                    continue;
                }
                if ((control & NetFlags.NETFLAG_LENGTH_MASK) != Net.Message.Length)
                {
                    continue;
                }

                if (Net.Reader.ReadByte() != CCRep.CCREP_SERVER_INFO)
                {
                    continue;
                }

                readaddr = Net.LanDriver.GetAddrFromName(Net.Reader.ReadString());
                int n;
                // search the cache for this server
                for (n = 0; n < Net.HostCacheCount; n++)
                {
                    if (Net.LanDriver.AddrCompare(readaddr, Net.HostCache[n].addr) == 0)
                    {
                        break;
                    }
                }

                // is it already there?
                if (n < Net.HostCacheCount)
                {
                    continue;
                }

                // add it
                Net.HostCacheCount++;
                hostcache_t hc = Net.HostCache[n];
                hc.name     = Net.Reader.ReadString();
                hc.map      = Net.Reader.ReadString();
                hc.users    = Net.Reader.ReadByte();
                hc.maxusers = Net.Reader.ReadByte();
                if (Net.Reader.ReadByte() != Net.NET_PROTOCOL_VERSION)
                {
                    hc.cname = hc.name;
                    hc.name  = "*" + hc.name;
                }
                IPEndPoint ep = (IPEndPoint)readaddr;
                hc.addr    = new IPEndPoint(ep.Address, ep.Port);
                hc.driver  = Net.DriverLevel;
                hc.ldriver = Net.LanDriverLevel;
                hc.cname   = readaddr.ToString();

                // check for a name conflict
                for (int i = 0; i < Net.HostCacheCount; i++)
                {
                    if (i == n)
                    {
                        continue;
                    }
                    hostcache_t hc2 = Net.HostCache[i];
                    if (hc.name == hc2.name)
                    {
                        i = hc.name.Length;
                        if (i < 15 && hc.name[i - 1] > '8')
                        {
                            hc.name = hc.name.Substring(0, i) + '0';
                        }
                        else
                        {
                            hc.name = hc.name.Substring(0, i - 1) + (char)(hc.name[i - 1] + 1);
                        }
                        i = 0;// -1;
                    }
                }
            }
        }