当前位置: 首页>>代码示例>>C#>>正文


C# IScene.AddCommandHandler方法代码示例

本文整理汇总了C#中IScene.AddCommandHandler方法的典型用法代码示例。如果您正苦于以下问题:C# IScene.AddCommandHandler方法的具体用法?C# IScene.AddCommandHandler怎么用?C# IScene.AddCommandHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IScene的用法示例。


在下文中一共展示了IScene.AddCommandHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        public void Start(IScene scene)
        {
            IPAddress bindAddress = IPAddress.Any;
            int port = DEFAULT_UDP_PORT;
            bool allowAlternatePort = true;

            IConfig config = scene.Config.Configs["LindenRegion"];
            if (config != null)
            {
                port = config.GetInt("Port", DEFAULT_UDP_PORT);
                allowAlternatePort = config.GetBoolean("AllowAlternatePort", true);
            }

            config = scene.Config.Configs["LLUDP"];
            if (config != null)
            {
                IPAddress.TryParse(config.GetString("BindAddress", "0.0.0.0"), out bindAddress);
                IPAddress.TryParse(config.GetString("MasqueradeAddress", String.Empty), out m_masqAddress);
            }

            if (bindAddress.Equals(IPAddress.Any))
                bindAddress = Util.GetLocalInterface();

            IScheduler scheduler = scene.Simian.GetAppModule<IScheduler>();
            if (scheduler == null)
            {
                m_log.Error("Cannot start LLUDP server without an IScheduler");
                throw new InvalidOperationException();
            }

            if (allowAlternatePort && m_nextUnusedPort != 0)
                port = m_nextUnusedPort;

            m_udpServer = new LLUDPServer(this, scene, bindAddress, port, scene.Config, scheduler);

            // Loop until we successfully bind to a port or run out of options
            while (true)
            {
                //m_log.Debug("Trying to bind LLUDP server to " + bindAddress + ":" + port);

                try
                {
                    m_udpServer.Address = bindAddress;
                    m_udpServer.Port = port;
                    m_udpServer.Start();

                    m_log.Info("Bound LLUDP server to " + bindAddress + ":" + port);

                    m_nextUnusedPort = port + 1;
                    IPAddress address = m_masqAddress == null ? bindAddress : m_masqAddress;

                    scene.ExtraData["ExternalAddress"] = OSD.FromString(address.ToString());
                    scene.ExtraData["ExternalPort"] = OSD.FromInteger(port);

                    break;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    if (allowAlternatePort)
                    {
                        ++port;
                    }
                    else
                    {
                        m_log.Error("Failed to bind LLUDP server to port " + port);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("Failed to bind LLUDP server to any port: " + ex.Message);
                    break;
                }
            }

            scene.AddCommandHandler("packetlog", PacketLogCommandHandler);
        }
开发者ID:thoys,项目名称:simian,代码行数:77,代码来源:LLUDPServer.cs


注:本文中的IScene.AddCommandHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。