Пример #1
0
        public static ObservingEntitiesResponse FromBytes(byte[] bytes)
        {
            long responseLength = bytes.Length;

            Log.Info("Creating new stream of length " + responseLength, "FromBytes");
            VRage.ByteStream          stream   = new VRage.ByteStream(bytes, bytes.Length);
            ObservingEntitiesResponse response = new ObservingEntitiesResponse();

            response.LoadFromByteStream(stream);

            Log.Info("Base pos " + stream.Position, "FromBytes");
            ushort count = stream.getUShort();

            Log.Info("With count pos " + stream.Position, "FromBytes");
            for (int i = 0; i < count; i++)
            {
                Log.Info("Beginning get entity at pos " + stream.Position + " / " + stream.Length, "FromBytes");
                EntityType entityType = (EntityType)stream.getUShort();

                switch (entityType)
                {
                case EntityType.Character:
                    response.ObservingEntities.Add(new Character(stream));
                    break;

                case EntityType.Grid:
                    response.ObservingEntities.Add(new RevealedGrid(stream));
                    break;
                }
            }

            Log.Info("Finished getting entity at final pos " + stream.Position, "FromBytes");
            return(response);
        }
        public static ObservingEntitiesResponse FromBytes(byte[] bytes)
        {
            long responseLength = bytes.Length;
            Log.Info("Creating new stream of length " + responseLength, "FromBytes");
            VRage.ByteStream stream = new VRage.ByteStream(bytes, bytes.Length);
            ObservingEntitiesResponse response = new ObservingEntitiesResponse();
            response.LoadFromByteStream(stream);

            Log.Info("Base pos " + stream.Position, "FromBytes");
            ushort count = stream.getUShort();
            Log.Info("With count pos " + stream.Position, "FromBytes");
            for (int i = 0; i < count; i++) {
                Log.Info("Beginning get entity at pos " + stream.Position + " / " + stream.Length, "FromBytes");
                EntityType entityType = (EntityType)stream.getUShort();

                switch (entityType) {
                    case EntityType.Character:
                        response.ObservingEntities.Add(new Character(stream));
                        break;
                    case EntityType.Grid:
                        response.ObservingEntities.Add(new RevealedGrid(stream));
                        break;
                }

            }

            Log.Info("Finished getting entity at final pos " + stream.Position, "FromBytes");
            return response;
        }
        private void ReceiveObservingEntitiesRequest(byte[] body, ulong senderId)
        {
            Log.Trace("Receiving Observing Entities Request",
                "ReceiveObservingEntitiesRequest");

            // nothing to read, but doing this anyway to test
            ObservingEntitiesRequest request = ObservingEntitiesRequest.FromBytes(body);

            // Convert them to just observing form
            ObservingEntitiesResponse response = new ObservingEntitiesResponse() {
                ObservingEntities = Session.Manager.Revealed.ObservingEntitiesList()
            };

            response.SendToPlayer(senderId);
        }