Example #1
0
        public static void ConnectOtherGatewayServer(ClientBase client, int gatewayID, int clientID)
        {
            GatewayInfo info = CenterGlobal.GetFreeGateway(gatewayID);

            if (info != null)
            {
                ReConnectGatewayPacket pkg = new ReConnectGatewayPacket();

                pkg.ClientID = clientID;
                pkg.IP = info.IP;
                pkg.Port = info.Port;

                client.SendTcp(pkg);
            }
            else
            {
                //TODO: 通知客户端服务器繁忙

                log.Warn("所有网关服务器满载 请增开新的网关服务器");

                ClientMsgPacket pkg = new ClientMsgPacket();

                pkg.MsgFlag = MsgFlag.NoneGateway;

                //ServerBusiesPacket pkg = new ServerBusiesPacket();

                //pkg.ClientID = clientID;

                client.SendTcp(pkg);
            }
        }
Example #2
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            int clientID = packet.ReadInt();
            string account = packet.ReadUTF();
            string nickName = packet.ReadUTF();

            int playerID = 0;

            using (PlayerBussiness pb = new PlayerBussiness())
            {
                playerID = pb.Registe(account, nickName);
            }

            if (playerID != 0)
            {
                ValidateLoginHandler.SendLoginPacket(client, clientID, account, playerID);
            }
            else
            {
                //TODO: 发送创建角色失败给客户端

                RegisteResultPacket pkg = new RegisteResultPacket();

                pkg.ClientID = clientID;

                client.SendTcp(pkg);
            }

            return 0;
        }
        public static void ConnectOtherGatewayServer(ClientBase client, uint gatewayID, uint clientID)
        {
            GatewayInfo info = CenterGlobal.GetNormalGateway(gatewayID);

            if (info != null)
            {
                ReConnectGatewayPacket pkg = new ReConnectGatewayPacket();

                pkg.ClientID = clientID;
                pkg.IP = info.IP;
                pkg.Port = info.Port;

                client.SendTcp(pkg);
            }
            else
            {
                //TODO: 通知客户端服务器繁忙
                ServerBusiesPacket pkg = new ServerBusiesPacket();

                pkg.ClientID = clientID;

                client.SendTcp(pkg);
            }
        }
Example #4
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);
            }
        }
Example #5
0
        public static void Send2Center(GamePacket pkg, ClientBase client)
        {
            if (CenterServer.Socket.Connected)
            {
                CenterServer.SendTCP(pkg);
            }
            else
            {
                //TODO: 通知客户端无可用中心服务器

                if (client != null)
                {
                    ClientMsgPacket p = new ClientMsgPacket();

                    p.MsgFlag = MsgFlag.NoneCenter;

                    client.SendTcp(p);
                }
            }
        }