Esempio n. 1
0
    //主线程执行
    private void HandleMsg(KBEngine.Packet packet)
    {
        var gc = packet.protoBody as GCPlayerCmd;

        if (gc.Result == "TestKCP" && !IsClose)
        {
            Connected = true;
        }
        else
        {
            networkScene.MsgHandler(packet);
        }
    }
Esempio n. 2
0
        /// <summary>
        /// 当消息处理器已经退出场景则关闭网络连接
        /// </summary>
        /// <param name="packet">Packet.</param>
        void HandleMsg(KBEngine.Packet packet)
        {
            //Debug.LogError("HandlerMsg "+packet.protoBody);
            Log.Net("HandlerMsg " + packet.protoBody);

            if (msgHandler != null)
            {
                msgHandler(packet);
            }
            else
            {
                Close();
            }
        }
Esempio n. 3
0
    public void MsgHandler(KBEngine.Packet packet)
    {
        var pb   = packet.protoBody;
        var cmd  = pb as GCPlayerCmd;
        var cmds = cmd.Result.Split(' ');

        switch (cmds[0])
        {
        case "Init":
            Log.Net("Init:" + myId);
            myId = Convert.ToInt32(cmds[1]);
            break;

        case "GameStart":
            state = GameState.InGame;
            //Logic.Instance.GameStart();
            MobaLogic.Instance.MatchSuc();
            break;

        case "NewTurn":
            //Logic.Instance.NewTurn(cmds);
            //MobaLogic.Instance.SyncState(cmd);
            MobaLogic.Instance.SyncPos(cmds);
            break;

        case "Bullet":
            MobaLogic.Instance.SyncBullet(cmds);
            break;

        case "MakeMove":
            //Logic.Instance.UpdateMove(cmds);
            break;

        default:
            break;
        }
    }
Esempio n. 4
0
        void MsgHandler(KBEngine.Packet packet)
        {
            var proto = packet.protoBody as GCPlayerCmd;

            Log.Net("ReceiveMsg: " + proto + " pid " + packet.flowId);
            var cmds = proto.Result.Split(' ');
            var c0   = cmds [0];

            if (c0 == "Add")
            {
                roomInfo.PlayersList.Add(proto.AvatarInfo);
                Util.ShowMsg("玩家:" + proto.AvatarInfo.Name + " 加入游戏,当前人数:" + matchRoom.GetPlayerNum());
            }
            else if (c0 == "Update")
            {
                foreach (var p in roomInfo.PlayersList)
                {
                    if (p.Id == proto.AvatarInfo.Id)
                    {
                        matchRoom.SyncAvatarInfo(proto.AvatarInfo, p);
                        break;
                    }
                }
            }
            else if (c0 == "Remove")
            {
                foreach (var p in roomInfo.PlayersList)
                {
                    if (p.Id == proto.AvatarInfo.Id)
                    {
                        roomInfo.PlayersList.Remove(p);
                        break;
                    }
                }
                Util.ShowMsg("玩家:" + proto.AvatarInfo.Name + " 离开游戏,当前人数:" + matchRoom.GetPlayerNum());
            }
            else if (c0 == "StartGame")
            {
                //进入Map5场景开始游戏
                //将网络状态数据保留
                //等待所有玩家进入场景成功
                //EnterSuc
                //然后将所有玩家状态重新刷新一遍
                Util.ShowMsg("玩家足够开始游戏:" + matchRoom.GetPlayerNum());
                Log.Net("StartGame");
                if (roomState != RoomState.InGame)
                {
                    roomState = RoomState.InGame;
                    WorldManager.worldManager.WorldChangeScene((int)LevelDefine.Battle, false);
                    GameObject.Destroy(GetComponent <NetworkLatency>());
                    var js = new JSONClass();
                    js.Add("total", new JSONData(1));
                    RecordData.UpdateRecord(js);
                }
            }
            else if (c0 == "SelectHero")
            {
                Util.ShowMsg("开始选择英雄");
                if (roomState == RoomState.InMatch)
                {
                    roomState = RoomState.SelectHero;
                    WorldManager.worldManager.WorldChangeScene((int)LevelDefine.SelectHero, false);
                    GameObject.Destroy(GetComponent <NetworkLatency>());
                }
            }
        }
Esempio n. 5
0
        public void MsgHandler(KBEngine.Packet packet)
        {
            var proto = packet.protoBody as GCPlayerCmd;

            Log.Net("Map4Receive: " + proto);
            var cmds = proto.Result.Split(' ');
            var cmd0 = cmds[0];

            if (cmds [0] == "Add")
            {
                ObjectManager.objectManager.CreateOtherPlayer(proto.AvatarInfo);
                //PlayerDataInterface.DressEquip(proto.AvatarInfo);
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();

                    if (!proto.AvatarInfo.HasScore)
                    {
                        proto.AvatarInfo.Score = 0;
                    }
                    if (sync != null)
                    {
                        var ainfo = NetMatchScene.Instance.matchRoom.GetPlayerInfo(proto.AvatarInfo.Id);
                        sync.InitSync(ainfo);
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "Remove")
            {
                ObjectManager.objectManager.DestroyPlayer(proto.AvatarInfo.Id);
            }
            else if (cmds [0] == "Update")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "Damage")
            {
                var dinfo = proto.DamageInfo;
                var enemy = ObjectManager.objectManager.GetPlayer(dinfo.Enemy);
                if (enemy != null)
                {
                    var sync = enemy.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
            }
            else if (cmds [0] == "Skill")
            {
                var sk     = proto.SkillAction;
                var player = ObjectManager.objectManager.GetPlayer(sk.Who);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkAttack(proto);
                    }
                }
            }
            else if (cmds [0] == "Buff")
            {
                var target = proto.BuffInfo.Target;
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkBuff(proto);
                    }
                }

                /*
                 * var target = proto.BuffInfo.Target;
                 * var sync = NetDateInterface.GetPlayer(target);
                 * var player = ObjectManager.objectManager.GetPlayer(target);
                 * if (sync != null)
                 * {
                 *  sync.NetworkBuff(proto);
                 * }
                 * else if(player != null)
                 * {
                 *  var sync2 = player.GetComponent<MySelfAttributeSync>();
                 *  if (sync2 != null)
                 *  {
                 *      sync2.NetworkBuff(proto);
                 *  }
                 * }
                 * if (player != null && !NetworkUtil.IsNetMaster())
                 * {
                 *  var monSync = player.GetComponent<MonsterSync>();
                 *  if (monSync != null)
                 *  {
                 *      monSync.NetworkBuff(proto);
                 *  }
                 * }
                 */
            }
            else if (cmds[0] == "RemoveBuff")
            {
                var target = proto.BuffInfo.Target;
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkRemoveBuff(proto);
                    }
                }
            }
            else if (cmds [0] == "AddEntity")
            {
                var ety = proto.EntityInfo;
                if (ety.EType == EntityType.CHEST)
                {
                    WaitZoneInit(ety);
                }
                else if (ety.EType == EntityType.DROP)
                {
                    var itemData = Util.GetItemData((int)ItemData.GoodsType.Props, (int)ety.ItemId);
                    var itemNum  = ety.ItemNum;
                    var pos      = NetworkUtil.FloatPos(ety.X, ety.Y, ety.Z);
                    DropItemStatic.MakeDropItemFromNet(itemData, pos, itemNum, ety);
                }
            }
            else if (cmds [0] == "UpdateEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                Log.Net("UpdateEntityHP: " + ety.Id + " hp " + ety.HasHP + " h " + ety.HP + ":" + ety + ":" + mon);
                //if (!NetworkUtil.IsMaster() && mon != null)
                if (mon != null)
                {
                    var sync = mon.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "RemoveEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                //if (!NetworkUtil.IsMaster() && mon != null)
                if (mon != null)
                {
                    var netView = mon.GetComponent <KBEngine.KBNetworkView>();
                    if (netView != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(netView.GetLocalId());
                    }
                }
            }
            else if (cmds [0] == "Pick")
            {
                //if (!NetworkUtil.IsMaster())
                {
                    var action = proto.PickAction;
                    var ety    = ObjectManager.objectManager.GetPlayer(action.Id);
                    var who    = ObjectManager.objectManager.GetPlayer(action.Who);
                    if (ety != null)
                    {
                        var item = ety.GetComponent <DropItemStatic>();
                        if (item != null)
                        {
                            item.PickItemFromNetwork(who);
                        }
                    }
                }
            }
            else if (cmds [0] == "Revive")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.Revive(proto);
                    }
                }
            }
            else if (cmd0 == "DeadActor")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.ActorId);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.Dead(proto);
                    }
                }
            }
            else if (cmds [0] == "Dead")
            {
                //ScoreManager.Instance.NetAddScore(dinfo.Attacker, dinfo.Enemy);
                ScoreManager.Instance.Dead(proto);
            }
            else if (cmds [0] == "SyncTime")
            {
                //if (!NetworkUtil.IsNetMaster())
                ScoreManager.Instance.NetSyncTime(proto.LeftTime);
            }
            else if (cmds [0] == "GameOver")
            {
                //if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetworkGameOver();
                }
            }
            else if (cmds [0] == "AllReady")
            {
                Util.ShowMsg("所有客户端准备完成");
                //当所有客户端准备好之后 服务器推送Entity给所有客户端
                NetMatchScene.Instance.SetAllReady();
            }
            else if (cmds[0] == "News")
            {
                var con = proto.News;
                Util.ShowMsg(con);
            }
            else if (cmds[0] == "UDPLost")
            {
                Util.ShowMsg("Server Side UDPLost!");
                UDPLost();
            }
            else if (cmd0 == "SyncFrame")
            {
                SyncFrame(proto);
            }
        }
Esempio n. 6
0
 void MsgHandler(KBEngine.Packet packet)
 {
 }