예제 #1
0
        public static LogicServerConnector GetFreeLogicServer(GatewayClient client)
        {
            LogicServerConnector connector = LogicServerMgr[m_freeID];

            if (connector != null && connector.Fulled == false)
            {
                return(connector);
            }

            LogicServerConnector connect = LogicServerMgr.SelectSingle(conn => conn.Fulled == false);

            if (connect != null)
            {
                m_freeID = connect.ID;

                connector = connect;

                return(connect);
            }
            else if (connector == null)
            {
                //TODO: 通知客户端逻辑服务器已满 稍候登陆

                ClientMsgPacket pkg = new ClientMsgPacket();

                pkg.MsgFlag = MsgFlag.NoneLogic;

                client.SendTcp(pkg);

                log.Warn("所有逻辑服务器满载 请增开新的逻辑服务器");
            }

            return(connector);
        }
예제 #2
0
        public GatewayPlayer(LoginInfo info, GatewayClient client)
            : base(info, client)
        {
            Client = client;

            Client.PlayerID = PlayerID;

            Client.Player = this;
        }
예제 #3
0
        public GatewayPlayer(LoginInfo info, GatewayClient client)
            : base(info, client)
        {
            Client = client;

            Client.PlayerID = PlayerID;

            Client.Player = this;
        }
예제 #4
0
        protected override ClientBase CreateClient(Socket socket)
        {
            GatewayClient client = new GatewayClient();

            client.Accept(socket);

            lock (m_locker)
            {
                GatewayGlobal.ClientCount++;

                client.SetClientID(GatewayGlobal.ClientCount);
            }

            return(client);
        }
예제 #5
0
        protected override ClientBase CreateClient(Socket socket)
        {
            GatewayClient client = new GatewayClient();

            client.Accept(socket);

            lock (m_locker)
            {
                GatewayGlobal.ClientCount++;

                client.ClientID = GatewayGlobal.ClientCount;
            }

            return client;
        }
예제 #6
0
        public static void CheckMaxClientCount(GatewayClient client)
        {
            lock (m_syncRoot)
            {
                if (Fulled)
                {
                    //TODO: 服务器已满 请求中心服务器更换网关

                    ChangeGatewayPacket pkg = new ChangeGatewayPacket();

                    pkg.ClientID = client.ClientID;

                    GatewayGlobal.Send2Center(pkg, client);

                    return;
                }
            }

            if (ClientMgr.Instance.ClientCount >= GatewayServerConfig.Configuration.MaxClients)
            {
                lock (m_syncRoot)
                {
                    Fulled = true;

                    //TODO: 通知中心服务器此网关已满 并N分钟后重置为未满

                    UpdateServerFullPacket pkg = new UpdateServerFullPacket();

                    pkg.ClientID = client.ClientID;

                    GatewayGlobal.Send2Center(pkg, client);

                    m_timer.Interval  = 300 * 1000;
                    m_timer.Elapsed  += new ElapsedEventHandler(m_timer_Elapsed);
                    m_timer.AutoReset = true;
                    m_timer.Start();
                }
            }
            else
            {
                //TODO: 通知客户端登陆

                NoticeLoginPacket pkg = new NoticeLoginPacket();

                client.SendTcp(pkg);
            }
        }
예제 #7
0
        public static void CheckMaxClientCount(GatewayClient client)
        {
            lock (m_syncRoot)
            {
                if (Fulled)
                {
                    //TODO: 服务器已满 请求中心服务器更换网关

                    ChangeGatewayPacket pkg = new ChangeGatewayPacket();

                    pkg.ClientID = client.ClientID;

                    GatewayGlobal.Send2Center(pkg, client);

                    return;
                }
            }

            if (ClientMgr.Instance.ClientCount >= GatewayServerConfig.Configuration.MaxClients)
            {
                lock (m_syncRoot)
                {
                    Fulled = true;

                    //TODO: 通知中心服务器此网关已满 并N分钟后重置为未满

                    UpdateServerFullPacket pkg = new UpdateServerFullPacket();

                    pkg.ClientID = client.ClientID;

                    GatewayGlobal.Send2Center(pkg, client);

                    m_timer.Interval = 300 * 1000;
                    m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed);
                    m_timer.AutoReset = true;
                    m_timer.Start();
                }
            }
            else
            {
                //TODO: 通知客户端登陆

                NoticeLoginPacket pkg = new NoticeLoginPacket();

                client.SendTcp(pkg);
            }
        }
예제 #8
0
        protected override void SaveClient(ClientBase client)
        {
            base.SaveClient(client);

            GatewayClient c = (GatewayClient)client;

            GatewayGlobal.PlayerClientMgr.Add(c.ClientID, c);

            if (Fulled)
            {
                ConnectOtherGatewayPacket pkg = new ConnectOtherGatewayPacket();
                pkg.GatewayID = GatewayGlobal.GatewayID;
                pkg.ClientID  = ((GatewayClient)client).ClientID;
                GatewayGlobal.CenterServer.SendTCP(pkg);

                return;
            }
            else if (GatewayGlobal.PlayerClientMgr.Count > GatewayServerConfig.Configuration.MaxClients)
            {
                UpdateServerFullPacket pkg = new UpdateServerFullPacket();

                pkg.GatewayID = GatewayGlobal.GatewayID;
                pkg.ClientID  = ((GatewayClient)client).ClientID;

                GatewayGlobal.CenterServer.SendTCP(pkg);

                Fulled = true;

                m_timer          = new System.Timers.Timer(GatewayServerConfig.Configuration.FullInterval * 1000);
                m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);
                m_timer.Start();
            }
            else
            {
                NoticeLoginPacket pkg = new NoticeLoginPacket();

                client.SendTcp(pkg);
            }
        }
예제 #9
0
 public GatewayPlayer(PlayerInfo info, GatewayClient client)
     : base(info, client)
 {
     //GClient = client;
 }
예제 #10
0
 public GatewayPlayer(PlayerInfo info, GatewayClient client)
     : base(info, client)
 {
     //GClient = client;
 }
예제 #11
0
        public static LogicServerConnector GetFreeLogicServer(GatewayClient client)
        {
            LogicServerConnector connector = LogicServerMgr[m_freeID];

            if (connector != null && connector.Fulled == false)
            {
                return connector;
            }

            LogicServerConnector connect = LogicServerMgr.SelectSingle(conn => conn.Fulled == false);

            if (connect != null)
            {
                m_freeID = connect.ID;

                connector = connect;

                return connect;
            }
            else if(connector == null)
            {
                //TODO: 通知客户端逻辑服务器已满 稍候登陆

                ClientMsgPacket pkg = new ClientMsgPacket();

                pkg.MsgFlag = MsgFlag.NoneLogic;

                client.SendTcp(pkg);

                log.Warn("所有逻辑服务器满载 请增开新的逻辑服务器");
            }

            return connector;
        }