Example #1
0
 public Player(LoginInfo info, ClientBase client)
 {
     PlayerID = info.PlayerID;
     Account = info.Account;
     NickName = info.NickName;
     Client = client;
 }
Example #2
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 #3
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 int HandlePacket(ClientBase client, GamePacket packet)
        {
            bool logined = packet.ReadBoolean();

            uint clientID = packet.ReadUnsignedInt();

            return 0;
        }
Example #5
0
 public Player(PlayerInfo info, ClientBase client)
 {
     PlayerID = info.PlayerID;
     Account = info.Account;
     NickName = info.NickName;
     Client = client;
     Client.Player = this;
 }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            if (packet.Code > 1000)
            {
                client.HandlePacket(packet.Code, packet);
            }

            return 0;
        }
Example #7
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            int gatewayID = packet.ReadInt();
            int clientID = packet.ReadInt();

            ConnectOtherGatewayServer(client, gatewayID, clientID);

            return 0;
        }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            uint gatewayID = packet.ReadUnsignedInt();

            GatewayInfo info = GameGlobal.GatewayMgr.FindTemplate(gatewayID);

            info.Fulled = false;

            return 0;
        }
Example #9
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            uint clientID = packet.ReadUnsignedInt();

            string account = packet.ReadUTF();

            //TODO: 从数据库验证帐号,成功时记录到CacheGlobal中的LoginPlayerMgr和CachePlayerMgr中.

            return 0;
        }
Example #10
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            Player player = CacheGlobal.CachePlayerMgr.Remove(packet.PlayerID);

            if (player != null)
            {
                CacheGlobal.LoginPlayerMgr.RemovePlayer(player);
            }

            return 0;
        }
Example #11
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            string account = packet.ReadUTF();

            ValidateLoginPacket pkg = new ValidateLoginPacket();

            pkg.ClientID = ((GatewayClient)client).ClientID;
            pkg.Account = account;

            GatewayGlobal.Send2CacheServer(pkg);

            return 0;
        }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            int clientID = packet.ReadInt();

            CenterPlayer player = CenterGlobal.PlayerMgr[packet.PlayerID];

            if (player != null && player.Client == client && player.ClientID == clientID)
            {
                CenterGlobal.PlayerMgr.Remove(player.PlayerID);
            }

            return 0;
        }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            uint gatewayID = packet.ReadUnsignedInt();

            uint clientID = packet.ReadUnsignedInt();

            GatewayInfo info = GameGlobal.GatewayMgr.FindTemplate(gatewayID);

            info.Fulled = true;

            ConnectOtherGatewayHandler.ConnectOtherGatewayServer(client, gatewayID, clientID);

            return 0;
        }
Example #14
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            CenterPlayer player = CenterGlobal.PlayerMgr[packet.PlayerID];

            if (player != null)
            {
                ValidateLoginPacket pkg = new ValidateLoginPacket();
                pkg.PlayerID = player.PlayerID;
                pkg.ClientID = player.ClientID;
                player.SendTcp(pkg);
            }

            return 0;
        }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            int clientID = packet.ReadInt();

            GamePlayer player = GameGlobal.PlayerMgr[packet.PlayerID];

            if (player != null && player.Client == client && player.ClientID == clientID)
            {
                player.SaveToDatabase();

                GameGlobal.PlayerMgr.Remove(packet.PlayerID);
            }

            return 0;
        }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            if (packet == null || packet.Code <= 1000)
            {
                return 0;
            }

            GatewayPlayer c = GatewayGlobal.PlayerLoginMgr[packet.PlayerID];

            if (c != null && c.LogicServer != null)
            {
                c.LogicServer.SendTCP(packet);
            }

            return 0;
        }
Example #17
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            GatewayClient gc = client as GatewayClient;

            if (gc.Account.IsNullOrEmpty())
            {
                return 0;
            }

            RegisteServerPacket pkg = new RegisteServerPacket();

            pkg.ClientID = gc.ClientID;
            pkg.Account = gc.Account;
            pkg.NickName = packet.ReadUTF();

            GatewayGlobal.Send2Center(pkg, client);

            return 0;
        }
Example #18
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            int clientID = packet.ReadInt();

            LoginInfo info = new LoginInfo();

            info.PlayerID = packet.PlayerID;

            GamePlayer player = new GamePlayer(info, client as GameClient);

            player.ClientID = clientID;

            player.Logined();

            GameGlobal.PlayerMgr.Add(player.PlayerID, player);

            GameGlobal.CheckMaxClientCount();

            return 0;
        }
Example #19
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 #20
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            GamePlayer player = GameGlobal.PlayerMgr[packet.PlayerID];

            if (player != null)
            {
                player.SaveToDatabase();
                player.Logout();

                KitPlayerPacket p = new KitPlayerPacket(packet.PlayerID);
                player.SendTcp(p);
            }

            GameGlobal.PlayerMgr.Remove(packet.PlayerID);

            LoginAfterKitPacket pkg = new LoginAfterKitPacket();

            pkg.PlayerID = packet.PlayerID;

            GameGlobal.CenterServer.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 #22
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            GatewayClient gc = client as GatewayClient;

            gc.LogicServer = GatewayGlobal.GetFreeLogicServer(gc);

            if (gc.LogicServer == null)
            {
                return 0;
            }

            string account = packet.ReadUTF();

            gc.Account = account;

            ValidateLoginPacket pkg = new ValidateLoginPacket();

            pkg.ClientID = gc.ClientID;
            pkg.Account = account;

            GatewayGlobal.Send2Center(pkg, client);

            return 0;
        }
Example #23
0
        protected override void SaveClient(ClientBase client)
        {
            base.SaveClient(client);

            GatewayGlobal.CheckMaxClientCount(client as GatewayClient);
        }
Example #24
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            //LogicGlobal.LogicPlayerMgr.Remove(packet.PlayerID);

            return 0;
        }
Example #25
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);
                }
            }
        }
Example #26
0
 public Player(uint playerID, string account, ClientBase client)
 {
     PlayerID = playerID;
     Account = account;
     Client = client;
 }
Example #27
0
 public CenterPlayer(LoginInfo info, ClientBase client)
     : base(info, client)
 {
 }
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            CenterClient center = client as CenterClient;

            ServerType type = (ServerType)packet.ReadUnsignedByte();

            string ip = packet.ReadUTF();

            int port = packet.ReadInt();

            uint id = 0;

            switch (type)
            {
                //case ServerType.UnKnowServer:
                //    break;
                //case ServerType.CenterServer:
                //    break;
                case ServerType.CacheServer:
                    id = 1;
                    if (CenterServerConfig.Configuration.CacheIP == ip && CenterServerConfig.Configuration.CachePort == port)
                    {
                        CenterGlobal.CacheServer = center;

                        CenterGlobal.GatewayServerMgr.ForEach((c) =>
                        {
                            ConnectCacheServerPacket pkg = new ConnectCacheServerPacket();
                            pkg.IP = ip;
                            pkg.Port = port;
                            c.SendTcp(pkg);
                        });
                    }
                    break;
                case ServerType.LogicServer:
                    id = GameGlobal.GameLogicMgr.GetID(info => info.IP == ip && info.Port == port);
                    if (id > 0)
                    {
                        CenterGlobal.GameLogicServerMgr.Add(id, center);
                        CenterGlobal.GatewayServerMgr.ForEach((c) => {
                            ConnectLogicServerPacket pkg = new ConnectLogicServerPacket();
                            pkg.ID = id;
                            pkg.IP = ip;
                            pkg.Port = port;
                            c.SendTcp(pkg);
                        });
                    }
                    break;
                case ServerType.BattleServer:
                    id = GameGlobal.BattleMgr.GetID(info => info.IP == ip && info.Port == port);
                    if (id > 0)
                    {
                        CenterGlobal.BattleServerMgr.Add(id, center);
                        CenterGlobal.GatewayServerMgr.ForEach((c) =>
                        {
                            ConnectBattleServerPacket pkg = new ConnectBattleServerPacket();
                            pkg.ID = id;
                            pkg.IP = ip;
                            pkg.Port = port;
                            c.SendTcp(pkg);
                        });
                    }
                    break;
                case ServerType.GatewayServer:
                    id = GameGlobal.GatewayMgr.GetID(info => info.IP == ip && info.Port == port);

                    UpdateServerIDPacket pkt = new UpdateServerIDPacket();
                    pkt.ID = (byte)id;
                    center.SendTcp(pkt);

                    if (id > 0)
                    {
                        CenterGlobal.GatewayServerMgr.Add(id, center);

                        uint[] keys = CenterGlobal.GameLogicServerMgr.GetKeys();

                        foreach (uint key in keys)
                        {
                            GameLogicInfo info = GameGlobal.GameLogicMgr.FindTemplate(key);
                            ConnectLogicServerPacket pkg = new ConnectLogicServerPacket();
                            pkg.ID = key;
                            pkg.IP = info.IP;
                            pkg.Port = info.Port;
                            center.SendTcp(pkg);
                        }

                        keys = CenterGlobal.BattleServerMgr.GetKeys();
                        foreach (uint key in keys)
                        {
                            BattleInfo info = GameGlobal.BattleMgr.FindTemplate(key);
                            ConnectBattleServerPacket pkg = new ConnectBattleServerPacket();
                            pkg.ID = key;
                            pkg.IP = info.IP;
                            pkg.Port = info.Port;
                            center.SendTcp(pkg);
                        }

                        if (CenterGlobal.CacheServer != null && CenterGlobal.CacheServer.Connected)
                        {
                            ConnectCacheServerPacket cachePacket = new ConnectCacheServerPacket();
                            cachePacket.IP = CenterServerConfig.Configuration.CacheIP;
                            cachePacket.Port = CenterServerConfig.Configuration.CachePort;
                            center.SendTcp(cachePacket);
                        }
                    }
                    break;
                default:
                    center.Disconnect();
                    return 0;
            }

            if (id > 0)
            {
                center.ID = id;
                center.Type = type;
                center.Validated = true;
            }
            else
            {
                center.Disconnect();
            }

            return 0;
        }
Example #29
0
 protected virtual void SaveClient(ClientBase client)
 {
     ClientMgr.Instance.AddClient(client);
 }