Exemplo n.º 1
0
        public void Start(string[] args)
        {
            random = new Random(DateTime.Now.Second);
            if (args.Length == 0)
            {
                args = File.ReadAllLines("../Config/directory.config");
            }

            if (!int.TryParse(args[0], out mPort))
            {
                Logger.Warn(@"Gate server Start() Faild! args[1]={0}", args[1]);
                return;
            }

            try
            {
                mTimer = new TimeDispatcher("Directory");
                mTimer.Start();

                var settings = new SocketSettings(1000, 100, new IPEndPoint(IPAddress.Any, mPort));
                settings.Compress = true;
                mServer           = new SocketListener(settings);

                mServer.ClientConnected    += ClientConnected;
                mServer.ClientDisconnected += ClientDisconnected;

                mServer.StartListen();
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex, "Server start failed.");
            }

            try
            {
                mConnectionString = args[1];
                while (true)
                {
                    UpdateContent();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Connect to db {0} Failed.", args[1]);
            }
        }
Exemplo n.º 2
0
        //-----------------------------------------------------Base------------------------
        public void Start(string[] args)
        {
            if (!int.TryParse(args[0], out mId))
            {
                Logger.Warn(@"Gate server Start() Faild! args[0]={0}", args[0]);
                return;
            }

            if (!int.TryParse(args[1], out mPort))
            {
                Logger.Warn(@"Gate server Start() Faild! args[1]={0}", args[1]);
                return;
            }

            Utility.IsGate = true;

            dynamic User = Config.ApplyJson(args[3]);

            var list = new List <dynamic>();

            foreach (var name in GlobalVariable.ServerNames)
            {
                if (User.ContainsKey(name))
                {
                    list.Add(User[name]);
                }
            }

            AddFunctionNameActivity.AddFunctionName(mFromFunctionId2Name);
            AddFunctionNameChat.AddFunctionName(mFromFunctionId2Name);
            AddFunctionNameLogic.AddFunctionName(mFromFunctionId2Name);
            AddFunctionNameLogin.AddFunctionName(mFromFunctionId2Name);
            AddFunctionNameRank.AddFunctionName(mFromFunctionId2Name);
            AddFunctionNameScene.AddFunctionName(mFromFunctionId2Name);
            AddFunctionNameTeam.AddFunctionName(mFromFunctionId2Name);

            AddFunctionNameActivity.AddCSFunctionName(mCSFunctionId2Name);
            AddFunctionNameChat.AddCSFunctionName(mCSFunctionId2Name);
            AddFunctionNameLogic.AddCSFunctionName(mCSFunctionId2Name);
            AddFunctionNameLogin.AddCSFunctionName(mCSFunctionId2Name);
            AddFunctionNameRank.AddCSFunctionName(mCSFunctionId2Name);
            AddFunctionNameScene.AddCSFunctionName(mCSFunctionId2Name);
            AddFunctionNameTeam.AddCSFunctionName(mCSFunctionId2Name);

            mTimeDispatcher = new TimeDispatcher("GateServerTimer");
            mTimeDispatcher.Start();

            try
            {
                var settings = new SocketSettings(5000, 200, new IPEndPoint(IPAddress.Any, mPort));

                settings.Compress = true;
                mServer           = new SocketListener(settings);

                //mServer.ClientConnected += OnSocketListenerConnected;
                mServer.ClientConnected    += OnSocketListenerConnectedEx;
                mServer.ClientDisconnected += OnSocketListenerDisconnected;

                mServer.StartListen();
            }
            catch (Exception ex)
            {
                Logger.FatalException("Server start failed.", ex);
            }

            //Thread.Sleep(5000);

            ConnectToServer(Config.ApplyJson(args[5]));

            ConnectToBroker(list);

            Console.WriteLine("GateServer startOver.");
        }