public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase pPacket, ref Peer pPlayer)
        {
            GCEnterScene Packet = (GCEnterScene)pPacket;

            LogManager.Log("RECV GCEnterScene : result=" + Packet.Result);
            //允许进入
            if (Packet.Result == 0)
            {
                //----------------------------------------------   --------------------
                //保存自身数据
                GameProcedure.s_pVariableSystem.SetAs_Int("MySelf_ID", Packet.ObjectID);

                GameProcedure.s_pVariableSystem.SetAs_Vector2("MySelf_Pos", Packet.Position.m_fX, Packet.Position.m_fZ);


                //------------------------------------------------------------------
                //设置要进入的场景
                // 增加一个资源ID,暂时resid和id相同 [10/24/2011 Sun]
                if (Packet.City == 1)
                {
                    //CGameProcedure::s_pProcEnter->SetSceneID(nCitySceneID, nCityLevel);
                    GameProcedure.s_ProcEnter.SetSceneID(Packet.SceneID, Packet.ResID, Packet.CityLevel);
                }
                else
                {
                    //普通场景,第二个参数(城市等级)必须为-1
                    //CGameProcedure::s_pProcEnter->SetSceneID(pPacket->getSceneID(), -1);
                    GameProcedure.s_ProcEnter.SetSceneID(Packet.SceneID, Packet.ResID, -1);
                }
                //设置登录流程状态,使之进入下一个状态
                GameProcedure.s_ProcEnter.SetStatus(GamePro_Enter.ENTER_STATUS.ENTERSCENE_OK);
                //进入场景
                GameProcedure.s_ProcEnter.EnterScene();
            }
            else
            {
                //不允许进入
                GameProcedure.s_ProcEnter.SetStatus(GamePro_Enter.ENTER_STATUS.ENTERSCENE_FAILED);
                //CGameProcedure::s_pEventSystem->PushEvent( GE_GAMELOGIN_SHOW_SYSTEM_INFO_CLOSE_NET, "进入场景的请求被服务器拒绝");
            }

            return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE);
        }
示例#2
0
        //执行进入场景的代码逻辑
        IEnumerator EnterScene(GCEnterScene sceneData)
        {
            Log.Sys("EnterNextScene is " + nextSceneId);

            var sdata = CopyController.copyController.GetLevelInfo(nextSceneId);

            //删除旧的场景中的玩家数据
            if (activeScene != null)
            {
                activeScene.LeaveScene();
                GameObject.Destroy(activeScene.gameObject);
            }
            activeScene = CScene.CreateScene(sdata);
            activeScene.Init();
            activeScene.EnterScene();

            //Init Camera
            NetDebug.netDebug.AddConsole("初始化照相机需要等待一frame");


            NetDebug.netDebug.AddConsole("Load Scene Name is " + sdata.SceneName);
            //等待加载静态场景资源
            AsyncOperation async = Application.LoadLevelAsync(sdata.SceneName);

            loadUI.async = async;
            loadUI.ShowLoad(sdata.SceneName);
            while (!async.isDone)
            {
                yield return(null);
            }
            //InitCamera After Load Scene
            //Scene Load Finish Then Load MainCamera
            if (CameraController.cameraController == null)
            {
                Log.Sys("CreateMainCamera");
                var mc = Resources.Load <GameObject> ("levelPublic/MainCamera");
                //var m =
                Instantiate(mc); //  as GameObject;
                //var lightMapCamera = Instantiate (Resources.Load<GameObject> ("levelPublic/lightMapCamera")) as GameObject;
                //var lightMapCamera =
                Instantiate(Resources.Load <GameObject> ("LightCamera"));// as GameObject;
            }
            if (BattleManager.battleManager == null)
            {
                var g = new GameObject("BattleManager");
                g.AddComponent <BattleManager>();
            }
            {
                var g = new GameObject("NpcManager");
                g.AddComponent <NpcManager>();
            }
            activeScene.ManagerInitOver();

            Log.Sys("Cameramain " + Camera.main);

            MyEventSystem.myEventSystem.PushEvent(MyEvent.EventType.EnterScene);
            //正在进入一个场景
            yield return(null);

            var g1     = new GameObject("StreamLoadLevel");
            var loader = g1.AddComponent <StreamLoadLevel>();
            var water  = g1.AddComponent <WaterEnvLoader>();

            yield return(StartCoroutine(loader.LoadFirstRoom()));

            var start = GameObject.Find("PlayerStart");

            CameraController.cameraController.TracePositon(start.transform.position);


            NetDebug.netDebug.AddConsole("LoadScene Finish start Init UI");

            CreateUI();

            NetDebug.netDebug.AddConsole("CreateMyPlayer");
            //场景传送点
            CreateMyPlayer();
            //load Success
            //loadUI.Hide (null);
            NetDebug.netDebug.AddConsole("Init Player Over Next");
            station = WorldStation.Enter;

            //场景其它初始化交给LevelInit
            NetDebug.netDebug.AddConsole("WorldManager:: InitLevel");
            CreateLevelInit();
            //初始化缓存的场景玩家
            ObjectManager.objectManager.InitCache();
            NetDebug.netDebug.AddConsole("Init World Finish");

            StartCoroutine(loader.LoadRoomNeibor());
        }
示例#3
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);
                }
            }
        }
示例#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 == "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);
                }
            }
        }