Exemple #1
0
        /// <summary>
        /// UDP_Init
        /// </summary>
        public Boolean Initialise( )
        {
            _IsInitialised = false;

            if (CommandLine.HasParam("-noudp"))
            {
                return(false);
            }

            try
            {
                MachineName = Dns.GetHostName();
            }
            catch (SocketException se)
            {
                ConsoleWrapper.DPrint("Cannot get host name: {0}\n", se.Message);
                return(false);
            }

            // if the quake hostname isn't set, set it to the machine name
            if (HostName == "UNNAMED")
            {
                IPAddress addr;
                if (!IPAddress.TryParse(MachineName, out addr))
                {
                    var i = MachineName.IndexOf('.');
                    if (i != -1)
                    {
                        HostName = MachineName.Substring(0, i);
                    }
                    else
                    {
                        HostName = MachineName;
                    }
                }
                //CVar.Set( "hostname", MachineName );
            }

            var i2 = CommandLine.CheckParm("-ip");

            if (i2 > 0)
            {
                if (i2 < CommandLine.Argc - 1)
                {
                    var ipaddr = CommandLine.Argv(i2 + 1);
                    if (!IPAddress.TryParse(ipaddr, out _MyAddress))
                    {
                        Utilities.Error("{0} is not a valid IP address!", ipaddr);
                    }
                    HostAddress = ipaddr;
                }
                else
                {
                    Utilities.Error("Net.Init: you must specify an IP address after -ip");
                }
            }
            else
            {
                _MyAddress  = IPAddress.Any;
                HostAddress = "INADDR_ANY";
                //Host.Network.MyTcpIpAddress = "INADDR_ANY";
            }

            _ControlSocket = OpenSocket(0);

            if (_ControlSocket == null)
            {
                ConsoleWrapper.Print("TCP/IP: Unable to open control socket\n");
                return(false);
            }

            _BroadcastAddress = new IPEndPoint(IPAddress.Broadcast, HostPort);

            _IsInitialised = true;
            ConsoleWrapper.Print("TCP/IP Initialized\n");
            return(true);
        }