コード例 #1
0
        private NetDataWriter CreateRemovePlayerPacket(Entity playerEntity)
        {
            var em = MainWorld.GetOrCreateManager <EntityManager>();

            var msgManager = NetInstance.GetMessageManager();
            var dataWriter = msgManager.Create(m_MsgRemovePlayer);

            dataWriter.Put(playerEntity.Index);

            return(dataWriter);
        }
コード例 #2
0
        /// <summary>
        /// Create a packet who contains data about the player
        /// </summary>
        /// <param name="playerEntity"></param>
        /// <param name="owned"></param>
        /// <returns></returns>
        private NetDataWriter CreatePlayerDataPacket(Entity playerEntity, NetPeer peer)
        {
            var em         = MainWorld.GetOrCreateManager <EntityManager>();
            var peerLink   = em.GetSharedComponentData <PlayerPeerLink>(playerEntity);
            var userLink   = em.GetSharedComponentData <PlayerUserLink>(playerEntity);
            var masterLink = em.GetSharedComponentData <MasterServerPlayerId>(playerEntity);

            var msgManager = NetInstance.GetMessageManager();
            var dataWriter = msgManager.Create(m_MsgUpdatePlayer);

            // The index is used to determin the id of the entity in the server
            dataWriter.Put(StMath.DoubleIntToLong(playerEntity.Index, playerEntity.Version));
            dataWriter.Put(userLink.Target.Index);
            dataWriter.Put(masterLink.Id);
            dataWriter.Put(peerLink.Target == peer);

            return(dataWriter);
        }