예제 #1
0
        public static void CreateCharacter(KBEngine.Packet packet)
        {
            var inpb = packet.protoBody as CGCreateCharacter;
            var au   = GCCreateCharacter.CreateBuilder();
            var role = RolesInfo.CreateBuilder();

            role.Name     = inpb.PlayerName;
            role.PlayerId = 100;
            //playerId++;
            role.Level = 1;
            role.Job   = inpb.Job;

            var msg = role.Build();

            ServerData.Instance.playerInfo.Roles = RolesInfo.CreateBuilder(msg).Build();

            var dress = new int[]
            {
                97, 68, 69, 70, 71, 72,
            };
            int id    = 1;
            var pinfo = ServerData.Instance.playerInfo;

            foreach (var d in dress)
            {
                var pkinfo  = PackInfo.CreateBuilder();
                var pkEntry = PackEntry.CreateBuilder();
                pkEntry.Id        = id++;
                pkEntry.BaseId    = d;
                pkEntry.GoodsType = 1;
                pkEntry.Level     = 1;
                pkinfo.PackEntry  = pkEntry.Build();
                pinfo.AddDressInfo(pkinfo);
            }

            var cinfo = GCCopyInfo.CreateBuilder();
            var cin   = CopyInfo.CreateBuilder();

            cin.Id     = 209;
            cin.IsPass = true;
            cinfo.AddCopyInfo(cin);
            var msg2 = cinfo.Build();

            pinfo.CopyInfos = msg2;

            au.AddRolesInfos(msg);
            ServerBundle.SendImmediate(au, packet.flowId);

            //投掷 跳跃
            pinfo.Roles.Level = 10;
            AddSkillPoint(10);
            LevelUpSkill(3);
            LevelUpSkill(4);
        }
예제 #2
0
        /// <summary>
        /// First Chapter Lev
        /// </summary>
        /// <param name="openLev">Open lev.</param>
        public static void PassLev(int chapter, int openLev)
        {
            var pinfo = ServerData.Instance.playerInfo;

            if (!pinfo.HasCopyInfos)
            {
                var au  = GCCopyInfo.CreateBuilder();
                var cin = CopyInfo.CreateBuilder();
                cin.Id     = 101;
                cin.IsPass = false;
                au.AddCopyInfo(cin);
                var msg = au.Build();
                pinfo.CopyInfos = msg;
            }
            int levId = chapter * 100 + openLev;
            //int levId = -1;
            //int count = -1;
            bool find = false;

            foreach (var c in pinfo.CopyInfos.CopyInfoList)
            {
                if (c.Id == levId)
                {
                    c.IsPass = true;
                    find     = true;
                    break;
                }
            }
            if (!find)
            {
                var cinfo = CopyInfo.CreateBuilder();
                cinfo.Id     = levId;
                cinfo.IsPass = true;
                pinfo.CopyInfos.CopyInfoList.Add(cinfo.Build());
            }
            foreach (var c in pinfo.CopyInfos.CopyInfoList)
            {
                if (c.Id < levId)
                {
                    c.IsPass = true;
                }
            }

            var open = GCPushLevelOpen.CreateBuilder();

            open.Chapter = chapter;
            open.Level   = openLev;
            ServerBundle.SendImmediatePush(open);

            Log.Net("PassLevelData " + pinfo.Build().ToString());
        }
예제 #3
0
        public void InitNewPlayerInfo()
        {
            playerInfo      = PlayerInfo.CreateBuilder();
            playerInfo.Exp  = 0;
            playerInfo.Gold = 0;
            var role = RolesInfo.CreateBuilder();

            role.Name        = "test";
            role.PlayerId    = 100;
            role.Level       = 1;
            role.Job         = Job.WARRIOR;
            playerInfo.Roles = role.Build();

            var cinfo = GCCopyInfo.CreateBuilder();
            var cin   = CopyInfo.CreateBuilder();

            cin.Id     = 209;
            cin.IsPass = true;
            cinfo.AddCopyInfo(cin);
            playerInfo.CopyInfos = cinfo.Build();

            WindowMng.windowMng.ShowNotifyLog("初始化新的数据");
        }
예제 #4
0
        void handleMsg(KBEngine.Packet packet)
        {
            var receivePkg = packet.protoBody.GetType().FullName;

            Debug.Log("Server Receive " + receivePkg);
            var          className   = receivePkg.Split(char.Parse(".")) [1];
            IBuilderLite retPb       = null;
            uint         flowId      = packet.flowId;
            bool         findHandler = false;

            if (className == "CGAutoRegisterAccount")
            {
                var au = GCAutoRegisterAccount.CreateBuilder();
                au.Username = "******";
                retPb       = au;
            }
            else if (className == "CGRegisterAccount")
            {
                var au = GCRegisterAccount.CreateBuilder();
                retPb = au;
            }
            else if (className == "CGLoginAccount")
            {
                var au         = GCLoginAccount.CreateBuilder();
                var playerInfo = ServerData.Instance.playerInfo;
                if (playerInfo.HasRoles)
                {
                    var role = RolesInfo.CreateBuilder().MergeFrom(playerInfo.Roles);
                    au.AddRolesInfos(role);
                }

                retPb = au;
            }
            else if (className == "CGSelectCharacter")
            {
                var inpb = packet.protoBody as CGSelectCharacter;
                if (inpb.PlayerId == 101)
                {
                    selectPlayerJob = 4;
                }
                else if (inpb.PlayerId == 102)
                {
                    selectPlayerJob = 2;
                }
                else
                {
                    selectPlayerJob = 1;
                }
                var au = GCSelectCharacter.CreateBuilder();
                au.TokenId = "12345";
                retPb      = au;
            }
            else if (className == "CGBindingSession")
            {
                var au = GCBindingSession.CreateBuilder();
                au.X             = 22;
                au.Y             = 1;
                au.Z             = 17;
                au.Direction     = 10;
                au.MapId         = 0;
                au.DungeonBaseId = 0;
                au.DungeonId     = 0;
                retPb            = au;
            }
            else if (className == "CGEnterScene")
            {
                var inpb = packet.protoBody as CGEnterScene;
                var au   = GCEnterScene.CreateBuilder();
                au.Id = inpb.Id;
                retPb = au;
            }
            else if (className == "CGListBranchinges")
            {
                var au   = GCListBranchinges.CreateBuilder();
                var bran = Branching.CreateBuilder();
                bran.Line        = 1;
                bran.PlayerCount = 2;
                au.AddBranching(bran);
                retPb = au;
            }
            else if (className == "CGHeartBeat")
            {
            }
            else if (className == "CGCopyInfo")
            {
                var pinfo = ServerData.Instance.playerInfo;
                if (pinfo.HasCopyInfos)
                {
                    retPb = GCCopyInfo.CreateBuilder().MergeFrom(pinfo.CopyInfos);
                }
                else
                {
                    //First Fetch Login Info
                    var au  = GCCopyInfo.CreateBuilder();
                    var cin = CopyInfo.CreateBuilder();
                    cin.Id     = 101;
                    cin.IsPass = false;
                    au.AddCopyInfo(cin);
                    var msg = au.Build();
                    pinfo.CopyInfos = msg;
                    retPb           = GCCopyInfo.CreateBuilder().MergeFrom(msg);
                }
            }


            else if (className == "CGUserDressEquip")
            {
                PlayerData.UserDressEquip(packet);
                findHandler = true;
            }
            else if (className == "CGAutoRegisterAccount")
            {
                var au = GCAutoRegisterAccount.CreateBuilder();
                au.Username = "******" + random.Next();
                retPb       = au;
            }
            else if (className == "CGRegisterAccount")
            {
                var inpb = packet.protoBody as CGRegisterAccount;
                ServerData.Instance.playerInfo.Username = inpb.Username;

                var au = GCRegisterAccount.CreateBuilder();
                retPb = au;
            }
            else if (className == "CGPlayerMove")
            {
                var au = GCPlayerMove.CreateBuilder();
                retPb = au;
            }
            else
            {
                var fullName    = packet.protoBody.GetType().FullName;
                var handlerName = fullName.Replace("MyLib", "ServerPacketHandler");

                var tp = Type.GetType(handlerName);
                if (tp == null)
                {
                    if (ServerPacketHandler.HoldCode.staticTypeMap.ContainsKey(handlerName))
                    {
                        tp = ServerPacketHandler.HoldCode.staticTypeMap [handlerName];
                    }
                }

                if (tp == null)
                {
                    Debug.LogError("PushMessage noHandler " + handlerName);
                }
                else
                {
                    findHandler = true;
                    var ph = (ServerPacketHandler.IPacketHandler)Activator.CreateInstance(tp);
                    ph.HandlePacket(packet);
                }
            }


            if (retPb != null)
            {
                SendPacket(retPb, flowId);
            }
            else
            {
                if (className != "CGHeartBeat" && !findHandler)
                {
                    Debug.LogError("DemoServer::not Handle Message " + className);
                }
            }
        }
예제 #5
0
        void handleMsg(KBEngine.Packet packet)
        {
            var receivePkg = packet.protoBody.GetType().FullName;

            Debug.Log("Server Receive " + receivePkg);
            var          className   = receivePkg.Split(char.Parse(".")) [1];
            IBuilderLite retPb       = null;
            uint         flowId      = packet.flowId;
            bool         findHandler = false;

            if (className == "CGAutoRegisterAccount")
            {
                var au = GCAutoRegisterAccount.CreateBuilder();
                au.Username = "******";
                retPb       = au;
            }
            else if (className == "CGRegisterAccount")
            {
                var au = GCRegisterAccount.CreateBuilder();
                retPb = au;
            }
            else if (className == "CGLoginAccount")
            {
                var au         = GCLoginAccount.CreateBuilder();
                var playerInfo = ServerData.Instance.playerInfo;
                if (playerInfo.HasRoles)
                {
                    var role = RolesInfo.CreateBuilder().MergeFrom(playerInfo.Roles);
                    au.AddRolesInfos(role);
                }

                retPb = au;
            }
            else if (className == "CGSelectCharacter")
            {
                var inpb = packet.protoBody as CGSelectCharacter;
                if (inpb.PlayerId == 101)
                {
                    selectPlayerJob = 4;
                }
                else if (inpb.PlayerId == 102)
                {
                    selectPlayerJob = 2;
                }
                else
                {
                    selectPlayerJob = 1;
                }
                var au = GCSelectCharacter.CreateBuilder();
                au.TokenId = "12345";
                retPb      = au;
            }
            else if (className == "CGBindingSession")
            {
                var au = GCBindingSession.CreateBuilder();
                au.X             = 22;
                au.Y             = 1;
                au.Z             = 17;
                au.Direction     = 10;
                au.MapId         = 0;
                au.DungeonBaseId = 0;
                au.DungeonId     = 0;
                retPb            = au;
            }
            else if (className == "CGEnterScene")
            {
                var inpb = packet.protoBody as CGEnterScene;
                var au   = GCEnterScene.CreateBuilder();
                au.Id = inpb.Id;
                retPb = au;
            }
            else if (className == "CGListBranchinges")
            {
                var au   = GCListBranchinges.CreateBuilder();
                var bran = Branching.CreateBuilder();
                bran.Line        = 1;
                bran.PlayerCount = 2;
                au.AddBranching(bran);
                retPb = au;
            }
            else if (className == "CGHeartBeat")
            {
            }
            else if (className == "CGLoadSaleItems")
            {
                var au = GCLoadSaleItems.CreateBuilder();
                retPb = au;
            }
            else if (className == "CGListAllTeams")
            {
                var au = GCListAllTeams.CreateBuilder();
                retPb = au;
            }
            else if (className == "CGCopyInfo")
            {
                var pinfo = ServerData.Instance.playerInfo;
                if (pinfo.HasCopyInfos)
                {
                    retPb = GCCopyInfo.CreateBuilder().MergeFrom(pinfo.CopyInfos);
                }
                else
                {
                    //First Fetch Login Info
                    var au  = GCCopyInfo.CreateBuilder();
                    var cin = CopyInfo.CreateBuilder();
                    cin.Id     = 101;
                    cin.IsPass = false;
                    au.AddCopyInfo(cin);
                    var msg = au.Build();
                    pinfo.CopyInfos = msg;
                    retPb           = GCCopyInfo.CreateBuilder().MergeFrom(msg);
                }
            }
            else if (className == "CGLoadVipLevelGiftReceiveInfo")
            {
                var au  = GCLoadVipLevelGiftReceiveInfo.CreateBuilder();
                var vip = ReceviedReward.CreateBuilder();
                vip.RewardId = 1;
                au.AddReceviedLevelRewards(vip);

                vip          = ReceviedReward.CreateBuilder();
                vip.RewardId = 2;
                au.AddReceviedLevelRewards(vip);

                vip          = ReceviedReward.CreateBuilder();
                vip.RewardId = 3;
                au.AddReceviedLevelRewards(vip);

                retPb = au;
            }
            else if (className == "CGLoadVipInfo")
            {
                var au = GCLoadVipInfo.CreateBuilder();
                au.VipType       = VipType.NONE_VIP;
                au.VipRemainTime = 0;
                au.VipLevel      = 4;
                au.VipExp        = 0;
                retPb            = au;
            }
            else if (className == "CGLoadTaskList")
            {
                var au   = GCLoadTaskList.CreateBuilder();
                var task = PlayerTask.CreateBuilder();
                task.TaskId       = 1;
                task.PlayerTaskId = 1;
                task.PlayerId     = 2;
                task.TaskState    = 5;
                task.Chain        = 6;
                au.AddPlayerTask(task);

                task              = PlayerTask.CreateBuilder();
                task.TaskId       = 2;
                task.PlayerTaskId = 1;
                task.PlayerId     = 2;
                task.TaskState    = 5;
                task.Chain        = 6;
                au.AddPlayerTask(task);

                task              = PlayerTask.CreateBuilder();
                task.TaskId       = 3;
                task.PlayerTaskId = 1;
                task.PlayerId     = 2;
                task.TaskState    = 5;
                task.Chain        = 6;
                au.AddPlayerTask(task);

                retPb = au;
            }
            else if (className == "CGLoadAchievements")
            {
                var au = GCLoadAchievements.CreateBuilder();
                var ac = Achievement.CreateBuilder();
                ac.AchievementId = 1000;
                au.AddAchievements(ac);

                ac = Achievement.CreateBuilder();
                ac.AchievementId = 1001;
                au.AddAchievements(ac);

                ac = Achievement.CreateBuilder();
                ac.AchievementId = 1002;
                au.AddAchievements(ac);

                ac = Achievement.CreateBuilder();
                ac.AchievementId = 1003;
                au.AddAchievements(ac);

                ac = Achievement.CreateBuilder();
                ac.AchievementId = 1004;
                au.AddAchievements(ac);
                retPb = au;
            }
            else if (className == "CGAuctionInfo")
            {
                var au = GCAuctionInfo.CreateBuilder();
                au.MaxSize  = 1;
                au.PageSize = 6;
                var item = AuctionItem.CreateBuilder();
                item.Id         = 11;
                item.BaseId     = 14;
                item.Type       = 1;
                item.SellCount  = 2;
                item.RemainTime = 60;
                item.TotalCost  = 88;
                au.AddAuctionItems(item);

                item            = AuctionItem.CreateBuilder();
                item.Id         = 119;
                item.BaseId     = 15;
                item.Type       = 1;
                item.SellCount  = 2;
                item.RemainTime = 609;
                item.TotalCost  = 889;
                au.AddAuctionItems(item);

                item            = AuctionItem.CreateBuilder();
                item.Id         = 118;
                item.BaseId     = 16;
                item.Type       = 1;
                item.SellCount  = 2;
                item.RemainTime = 608;
                item.TotalCost  = 888;
                au.AddAuctionItems(item);

                item            = AuctionItem.CreateBuilder();
                item.Id         = 117;
                item.BaseId     = 23;
                item.Type       = 1;
                item.SellCount  = 2;
                item.RemainTime = 607;
                item.TotalCost  = 887;
                au.AddAuctionItems(item);

                item            = AuctionItem.CreateBuilder();
                item.Id         = 116;
                item.BaseId     = 24;
                item.Type       = 1;
                item.SellCount  = 2;
                item.RemainTime = 605;
                item.TotalCost  = 886;
                au.AddAuctionItems(item);

                item            = AuctionItem.CreateBuilder();
                item.Id         = 115;
                item.BaseId     = 25;
                item.Type       = 1;
                item.SellCount  = 2;
                item.RemainTime = 605;
                item.TotalCost  = 88;
                au.AddAuctionItems(item);
                retPb = au;
            }
            else if (className == "CGUserDressEquip")
            {
                PlayerData.UserDressEquip(packet);
                findHandler = true;
            }
            else if (className == "CGAutoRegisterAccount")
            {
                var au = GCAutoRegisterAccount.CreateBuilder();
                au.Username = "******" + random.Next();
                retPb       = au;
            }
            else if (className == "CGRegisterAccount")
            {
                var inpb = packet.protoBody as CGRegisterAccount;
                ServerData.Instance.playerInfo.Username = inpb.Username;

                var au = GCRegisterAccount.CreateBuilder();
                retPb = au;
            }
            else if (className == "CGPlayerMove")
            {
                var au = GCPlayerMove.CreateBuilder();
                retPb = au;
            }
            else
            {
                var fullName    = packet.protoBody.GetType().FullName;
                var handlerName = fullName.Replace("ChuMeng", "ServerPacketHandler");

                var tp = Type.GetType(handlerName);
                if (tp == null)
                {
                    if (ServerPacketHandler.HoldCode.staticTypeMap.ContainsKey(handlerName))
                    {
                        tp = ServerPacketHandler.HoldCode.staticTypeMap [handlerName];
                    }
                }

                if (tp == null)
                {
                    Debug.LogError("PushMessage noHandler " + handlerName);
                }
                else
                {
                    findHandler = true;
                    var ph = (ServerPacketHandler.IPacketHandler)Activator.CreateInstance(tp);
                    ph.HandlePacket(packet);
                }
            }


            if (retPb != null)
            {
                SendPacket(retPb, flowId);
            }
            else
            {
                if (className != "CGHeartBeat" && !findHandler)
                {
                    Debug.LogError("DemoServer::not Handle Message " + className);
                }
            }
        }