Ejemplo n.º 1
0
        void SendSoundEvent(ViewServer sender, Vector3 pos, float radius)
        {
            if (sender == null)
            {
                return;
            }

            var p    = WorldToBitmap(pos);
            var data = new Viewer.WorldEventSound();

            data.x = p.x;
            data.y = p.y;
            // FIXME: This is only remapped in one direction.

            var worldSize = Utils.Distance(_worldMins.x, _worldMaxs.x);
            var rescaled  = (radius / worldSize) * 512.0f;

            data.distance = (int)rescaled;

            Logger.Info("Distance {0}, Scaled: {1}", radius, data.distance);

            sender.Broadcast(Viewer.DataType.WorldEventSound, data);
        }
Ejemplo n.º 2
0
        private void ProcessBuffer(ref Client client)
        {
            var header = client.header;

            var buffer = client.buffer;

            buffer.Seek(0, SeekOrigin.Begin);

            try
            {
                // Read header.
                header.Deserialize(buffer);
                if (header.len > buffer.Length - buffer.Position)
                {
                    return;
                }

                if (_worldState == null)
                {
                    _worldState = new State();
                }

                Viewer.DataType messageType = (Viewer.DataType)header.type;
                switch (messageType)
                {
                case Viewer.DataType.Info:
                    _worldState.worldInfo.Deserialize(buffer);
                    Console.WriteLine("Received WorldInfo");
                    break;

                case Viewer.DataType.WorldZones:
                    _worldState.worldZones.Deserialize(buffer);
                    Console.WriteLine("Received WorldZones");
                    break;

                case Viewer.DataType.POIZones:
                    _worldState.poiZones.Deserialize(buffer);
                    Console.WriteLine("Received POIZones");
                    break;

                case Viewer.DataType.PlayerZones:
                    _worldState.playerZones.Deserialize(buffer);
                    break;

                case Viewer.DataType.ActiveZombies:
                    _worldState.active.Deserialize(buffer);
                    break;

                case Viewer.DataType.InactiveZombies:
                    _worldState.inactive.Deserialize(buffer);
                    break;

                case Viewer.DataType.WorldEventSound:
                    var ev = new Viewer.WorldEventSound();
                    ev.Deserialize(buffer);

                    var snd = new SoundEvent();
                    snd.x      = ev.x;
                    snd.y      = ev.y;
                    snd.radius = ev.distance;
                    snd.watch.Restart();

                    _worldState.sounds.Add(snd);

                    break;

                default:
                    break;
                }

                // Discard current packet.
                MemoryStream newBuffer = new MemoryStream();
                newBuffer.Write(buffer.GetBuffer(), (int)buffer.Position, (int)(buffer.Length - buffer.Position));

                // Set buffer.
                client.buffer = newBuffer;
            }
            catch (Exception)
            {
            }
        }