Пример #1
0
        static void Main(string[] args)
        {
            InitAllController();

            #region 1、日志,配置,建立Socket,监听端口
            BaseProgram.PubMain1(ServerType, m_Port);
            #endregion

            #region 2、连接事件
            Thread mThread = new Thread(ListenClientCallBack);
            mThread.Start();
            #endregion

            #region 主循环
            while (true)
            {
                Thread.CurrentThread.Join(10);
                try
                {
                    ServerHeartbeat.Heartbeat();
                }
                catch (Exception ex)
                {
                    Loger.Error($"服务器错误{ex}");
                }
            }
            #endregion
        }
Пример #2
0
        /// <summary>
        /// 主程序
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            BaseProgram.PubMain1(args, EServerType.游戏);

            #region 启动服务器后执行服务器数据初始化

            OnServerStart();

            #endregion 启动服务器后执行服务器数据初始化


            #region  务器事件

            //新连接事件
            BaseServerInfo.AppServer.NewSessionConnected += new SessionHandler <LunarSession>(Dispatcher.OnSessionConnected);

            //连接断开事件
            BaseServerInfo.AppServer.SessionClosed += new SessionHandler <LunarSession, CloseReason>(Dispatcher.OnSessionClosed);

            //收到消息事件
            BaseServerInfo.AppServer.NewRequestReceived += new RequestHandler <LunarSession, LunarRequestInfo>(BaseDispatch.OnDispatch);

            #endregion  务器事件

            BaseProgram.PubMain2();

            BaseProgram.PubMain3();


            #region 连接到其他服务器

            if (!GameServerLinkManager.Start())
            {
                loger.Fatal("连接到其他服务器失败");
            }

            #endregion 连接到其他服务器

            #region 添加读取指令的线程

            BaseServerInfo.threadDriverCmds = new Thread(new ThreadStart(DriverCmds.ThreadDriverCmds));
            BaseServerInfo.threadDriverCmds.Start();
            Thread.Sleep(1000);

            #endregion 添加读取指令的线程

            #region 添加发送消息线程

            BaseServerInfo.threadSend = new Thread(new ThreadStart(BaseDispatch.ThreadSendMain));
            BaseServerInfo.threadSend.Start();
            Thread.Sleep(1000);

            BaseServerInfo.threadSend = new Thread(new ThreadStart(BaseDispatch.ThreadSendMergeMain));
            BaseServerInfo.threadSend.Start();
            Thread.Sleep(1000);

            #endregion

            BaseProgram.StartThreadDbMysqlSecond();

            #region 进入主循环


            while (true)
            {
                System.Threading.Thread.CurrentThread.Join(BaseServerInfo.ServerHeartbeat);
                try
                {
                    ServerHeartbeat.Heartbeat();
                }
                catch (Exception ex)
                {
                    loger.Fatal("服务器错误", ex);
                }
            }

            #endregion 进入主循环
        }