Example #1
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;
        }
Example #2
0
        public int HandlePacket(ClientBase client, GamePacket packet)
        {
            uint clientID = packet.ReadUnsignedInt();

            string account = packet.ReadUTF();

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

            return 0;
        }
Example #3
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(ServerConnector connector, GamePacket packet)
        {
            string ip = packet.ReadUTF();

            int port = packet.ReadInt();

            if (GatewayGlobal.CacheServer == null || GatewayGlobal.CacheServer.Socket.Connected == false)
            {
                GatewayGlobal.CacheServer = new CacheServerConnector(ip, port);
            }

            return 0;
        }
        public int HandlePacket(ServerConnector connector, GamePacket packet)
        {
            uint id = packet.ReadUnsignedInt();

            if (GatewayGlobal.ContainsBattleServer(id))
            {
                return 0;
            }

            string ip = packet.ReadUTF();

            int port = packet.ReadInt();

            new BattleServerConnector(id, ip, port);

            return 0;
        }
Example #6
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;
        }
        public int HandlePacket(ServerConnector connector, GamePacket packet)
        {
            int id = packet.ReadInt();

            if (GatewayGlobal.BattleServerMgr.Contains(id) ||
                GatewayGlobal.LogicConnectingMgr.Contains(id))
            {
                return 0;
            }

            string ip = packet.ReadUTF();

            int port = packet.ReadInt();

            LogicServerConnector conn = new LogicServerConnector(id);

            conn.Connect(ip, port);

            return 0;
        }
Example #8
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;
        }
        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;
        }