示例#1
0
    public static void SendStartMsg(WorldBase world)
    {
        //获取所有的Player组件,并派发
        List <EntityBase> list = world.GetEntiyList(s_playerFilter);

        StartSyncMsg startMsg = CreateStartMsg(world);

        SyncEntityMsg playerInfo = new SyncEntityMsg();

        playerInfo.frame = world.FrameCount;
        playerInfo.infos = new List <EntityInfo>();

        for (int i = 0; i < list.Count; i++)
        {
            playerInfo.infos.Add(CreatePlayerComponentInfo(list[i]));
        }

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cc          = list[i].GetComp <ConnectionComponent>();
            SyncEntityMsg       serviceInfo = CreateServiceMsg(world, cc.m_session);

            ProtocolAnalysisService.SendMsg(cc.m_session, playerInfo);
            ProtocolAnalysisService.SendMsg(cc.m_session, serviceInfo);
            ProtocolAnalysisService.SendMsg(cc.m_session, startMsg);
        }
    }
    static void BroadcastSameCommand(WorldBase world, ConnectionComponent connectComp, SameCommand cmd, bool includeSelf)
    {
        cmd.time = ServiceTime.GetServiceTime();

        List <EntityBase> list = world.GetEntiyList(new string[] { "ConnectionComponent" });

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cp = list[i].GetComp <ConnectionComponent>();
            ProtocolAnalysisService.SendMsg(cp.m_session, cmd);
        }
    }
    static void BroadcastCommand(WorldBase world, ConnectionComponent connectComp, T cmd, bool includeSelf)
    {
        //TODO 与预测一致不广播节约带宽
        List <EntityBase> list = world.GetEntiyList(new string[] { "ConnectionComponent" });

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cp = list[i].GetComp <ConnectionComponent>();
            if (!(includeSelf && cp != connectComp))
            {
                ProtocolAnalysisService.SendMsg(cp.m_session, cmd);
            }
        }
    }
        static void ReceviceSyncMsg(SyncSession session, T msg)
        {
            ConnectionComponent commandComp = session.m_connect;
            WorldBase           world       = session.m_connect.Entity.World;

            if (commandComp != null)
            {
                PlayerCommandBase comp = msg;
                comp.frame = msg.frame;

                if (msg.frame > world.FrameCount)
                {
                    commandComp.m_commandList.Add(comp);
                    //TODO 与预测一致不广播节约带宽
                    List <EntityBase> list = world.GetEntiyList(new string[] { "ConnectionComponent" });

                    for (int i = 0; i < list.Count; i++)
                    {
                        ConnectionComponent cp = list[i].GetComp <ConnectionComponent>();
                        if (cp != commandComp)
                        {
                            ProtocolAnalysisService.SendMsg(cp.m_session, msg);
                        }
                    }
                }
                else
                {
                    //潜在的不同步威胁

                    Debug.Log("帧数落后 丢弃玩家操作 world.FrameCount: " + world.FrameCount + " msg frame:" + msg.frame);

                    //发送给玩家自己 服务器给他预测的操作,
                    for (int i = 0; i < commandComp.m_forecastList.Count; i++)
                    {
                        ProtocolAnalysisService.SendMsg(session, commandComp.m_forecastList[i]);
                    }
                    commandComp.m_forecastList.Clear();

                    //并且让这个玩家提前
                    commandComp.m_lastInputCache = comp;

                    PursueMsg pmsg = new PursueMsg();
                    pmsg.frame        = world.FrameCount;
                    pmsg.advanceCount = 1;

                    ProtocolAnalysisService.SendMsg(session, pmsg);
                }
            }
        }
    public void OnGameFinsih(params object[] objs)
    {
        WorldBase world = (WorldBase)objs[0];

        List <EntityBase> list = world.GetEntiyList(new string[] { "ConnectionComponent" });

        //移除所有的重连信息
        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cc = list[i].GetComp <ConnectionComponent>();
            m_disConnectDict.Remove(cc.m_playerID);

            RemoveRecord(cc.m_playerID);
        }
    }
示例#6
0
    public static SyncEntityMsg CreateServiceMsg(WorldBase world, SyncSession session)
    {
        SyncEntityMsg serviceInfo = new SyncEntityMsg();

        serviceInfo.frame = world.FrameCount;
        serviceInfo.infos = new List <EntityInfo>();

        List <EntityBase> list = world.GetEntiyList(s_playerFilter);

        for (int i = 0; i < list.Count; i++)
        {
            serviceInfo.infos.Add(CreateServiceComponentInfo(list[i], session));
        }

        return(serviceInfo);
    }