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


C# MessageHandler.Start方法代码示例

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


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

示例1: Start

        public bool Start()
        {
            try
            {
                context = new ServerContext();
                context.ServerConfig = serverConfig;

                // Database connection check
                Logger.Output(this, "Checking database connection..");
                context.Css = Config.DatabaseConnectionString;

                using (MySqlConnection conn = new MySqlConnection(Config.DatabaseConnectionString))
                {
                    conn.Open();

                    if (conn.State == ConnectionState.Open)
                    {
                        Logger.Output(this, "Database connection verified..");

                        MySqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "SELECT * FROM settings";
                        MySqlDataReader dr = cmd.ExecuteReader();

                        // Load all world settings from the database.
                        while (dr.Read())
                        {
                            string name, value;
                            name = DatabaseHelper.GetString(dr, "name");
                            value = DatabaseHelper.GetString(dr, "value");
                            Logger.Record(this, "Config param: {0}\t= '{1}'", name, value);
                            serverConfig.Add(name, value);
                        }
                        dr.Close();
                    }
                    else
                    {
                        Logger.Output(this, "Database connection can't be opened!");
                        throw new InvalidOperationException("Database connection can't be opened.");
                    }
                }

                Logger.Output(this, "Creating server components..");

                Timer = new Stopwatch();
                Timer.Start();
                Logger.Output(this, "Hi res timer available: {0}, frequency: {1}.", Stopwatch.IsHighResolution, Stopwatch.Frequency);

                int result;
                int.TryParse(serverConfig["turn_duration"], out result);
                context.TurnDuration = result;

                int.TryParse(serverConfig["users_allowed"], out result);
                context.Mpt = new MasterPlayerTable(result, context);

                // Queues
                QueueManager qMngr = QueueManager.Singletone;
                qMngr.CreateQueues(result);

                // Load all WorldData.xml and Entities.xml data
                DataManager dMngr = DataManager.Singletone;

                // Create the zone manager.
                Logger.Output(this, "Creating zone manager..");
                context.ZoneManager = new ZoneManager(context);

                // Now load all static predefined entities.
                //Logger.Output(this, "Loading static entities..");
                //dMngr.LoadStaticEntities(context.ZoneManager);

                // Create the game processor for handling messages.
                Logger.Output(this, "Creating game processor..");
                context.GameProcessor = new GameProcessor(context);

                // Create the chat processor for handling chat and remote commands.
                Logger.Output(this, "Creating chat processor..");
                context.ChatProcessor = new ChatProcessor(context);

                // Network server
                Logger.Output(this, "Creating network server..");

                NetPeerConfiguration cfg = new NetPeerConfiguration("Asteria");
                int.TryParse(context.ServerConfig["client_port"], out result);
                cfg.Port = result;

                int.TryParse(context.ServerConfig["users_allowed"], out result);
                cfg.MaximumConnections = result;

                int.TryParse(context.ServerConfig["max_transmissionunit"], out result);
                cfg.MaximumTransmissionUnit = result;

                int.TryParse(context.ServerConfig["client_timeout_seconds"], out result);
                cfg.ConnectionTimeout = result;

                cfg.ReceiveBufferSize = 4095;
                cfg.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            #if DEBUG
                cfg.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
            #endif

                IPAddress clientAddress;
//.........这里部分代码省略.........
开发者ID:KtBkkr,项目名称:Asteria,代码行数:101,代码来源:WorldServer.cs


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