Ejemplo n.º 1
0
 private void OnShipAdded(Packet<IScenePeer> obj)
 {
     //Console.WriteLine("ship.add received");
     if (_simulation != null && _isReady)
     {
         var shipsToAdd = obj.ReadObject<ShipCreatedDto[]>();
         //while (obj.Stream.Position != obj.Stream.Length)
         for (var i = 0; i < shipsToAdd.Length; i++)
         {
             var shipInfos = shipsToAdd[i];
             if (shipInfos.id != this.id && !_simulation.Environment.VisibleShips.ContainsKey(shipInfos.id))
             {
                 var ship = new Ship { Id = shipInfos.id, Team = shipInfos.team, X = shipInfos.x, Status = shipInfos.status, Y = shipInfos.y, Rot = shipInfos.rot, Weapons = shipInfos.weapons };
                 //Console.WriteLine("[" + _name + "] Ship {0} added ", shipInfos.id);
                 lock (_simulation.Environment)
                 {
                     _simulation.Environment.AddShip(ship);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void OnShipRemoved(Packet<IScenePeer> obj)
 {
     if (_simulation != null)
     {
         var id = obj.ReadObject<ushort>();
         //Console.WriteLine("[" + _name + "] Ship {0} removed ", id);
         lock (_simulation.Environment)
         {
             _simulation.Environment.RemoveShip(id);
         }
     }
 }
Ejemplo n.º 3
0
        private void OnShipStatusChanged(Packet<IScenePeer> obj)
        {
            if (!_isReady)
            {
                return;
            }
            var statusChangedArgs = obj.ReadObject<StatusChangedMsg>();
            if (statusChangedArgs.shipId != this.id)
            {
                if (_simulation.Environment.VisibleShips.ContainsKey(statusChangedArgs.shipId))
                {


                    _simulation.Environment.VisibleShips[statusChangedArgs.shipId].Status = (ShipStatus)statusChangedArgs.status;
                }
            }
            else
            {
                if (_simulation.Boid.Status != ShipStatus.InGame && statusChangedArgs.status == ShipStatus.InGame)
                {
                    _simulation.Reset();
                }
                _simulation.Boid.Status = statusChangedArgs.status;


            }

        }
Ejemplo n.º 4
0
        private void OnGetMyShipInfos(Packet<IScenePeer> obj)
        {
            var dtos = obj.ReadObject<ShipCreatedDto[]>();
            if (dtos.Length != 1)
            {
                throw new InvalidDataException("Invalid number of dtos");
            }

            var dto = dtos[0];
            Console.WriteLine("[" + _name + "] Ship infos received : {0}", dto.id);
            id = dto.id;
            _simulation.Boid.Id = id;
            _simulation.Boid.X = dto.x;
            _simulation.Boid.Y = dto.y;
            _simulation.Boid.Rot = dto.rot;//= new Simulation(dto.x, dto.y, dto.rot);
            _simulation.Boid.Weapons = dto.weapons.Select(w => new WeaponViewModel { Weapon = w }).ToList();
            _isReady = true;
        }
Ejemplo n.º 5
0
        private void OnPositionUpdate(Packet<IScenePeer> obj)
        {
            if (!_isReady)
            {
                return;
            }
            if (_simulation != null)
            {
                using (var reader = new BinaryReader(obj.Stream))
                {

                    while (reader.BaseStream.Length - reader.BaseStream.Position >= POSITION_UPDATE_FRAME_LENGTH)
                    {
                        var id = reader.ReadUInt16();
                        var x = reader.ReadSingle();
                        var y = reader.ReadSingle();
                        var rot = reader.ReadSingle();
                        var time = reader.ReadInt64();

                        if (id != this.id)
                        {
                            _simulation.Environment.UpdateShipLocation(id, x, y, rot);
                        }
                        else if (_simulation.Boid.Status != ShipStatus.InGame)
                        {
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 private void OnShipUsedSkill(Packet<IScenePeer> obj)
 {
     //We don't care
 }
Ejemplo n.º 7
0
        private void OnForcePositionUpdate(Packet<IScenePeer> obj)
        {
            using (var reader = new BinaryReader(obj.Stream))
            {
                var id = reader.ReadUInt16();
                var x = reader.ReadSingle();
                var y = reader.ReadSingle();
                var rot = reader.ReadSingle();
                var time = reader.ReadInt64();

                if (id == this.id)
                {
                    _simulation.Boid.X = x;
                    _simulation.Boid.Y = y;
                    _simulation.Boid.Rot = rot;
                }
            }

        }
Ejemplo n.º 8
0
 private void OnGameStatusChanged(Packet<IScenePeer> obj)
 {
     using (var reader = new BinaryReader(obj.Stream))
     {
         var status = (GameStatus)reader.ReadByte();
         if(status == GameStatus.Complete)
         {
             _gameCompleteTcs.SetResult(true);
         }
     }
 }
Ejemplo n.º 9
0
 private void waitForData(Socket socket)
 {
     Packet packet = new Packet();
       packet.socket = socket;
       packet.socket.BeginReceive(packet.buffer, 0, packet.buffer.Length, SocketFlags.None, new AsyncCallback(dataReceived), packet);
 }
Ejemplo n.º 10
0
        private void OnPositionUpdate(Packet<IScenePeerClient> packet)
        {
            unchecked
            {
                using (var reader = new BinaryReader(packet.Stream))
                {
                    
                    var shipId = reader.ReadUInt16();
                    var x = reader.ReadSingle();
                    var y = reader.ReadSingle();
                    var rot = reader.ReadSingle();
                    //var timestamp = reader.ReadInt64();
                    var timestamp = _scene.GetComponent<IEnvironment>().Clock;
                    var ls = _scene.GetComponent<Server.Leaderboards.ILeaderboardsService>();

                    Ship ship;
                    if (_ships.TryGetValue(shipId, out ship))
                    {
                        ship.PositionUpdatedOn = timestamp;
                        ship.x = x;
                        ship.y = y;
                        ship.rot = rot;

                    }

                    //this._boidsLastIndex.AddOrUpdate(shipId, packetIndex, (_, previousIndex) =>
                    //{
                    //    if (previousIndex < (packetIndex - 1))
                    //    {
                    //        Interlocked.Add(ref this._lostPackets, (int)(packetIndex - previousIndex - 1));
                    //    }
                    //    return packetIndex;
                    //});
                }

                //packet.Connection.Send("position.update", s =>
                //_scene.Broadcast("position.update", s =>
                //{
                //    using (var binWriter = new BinaryWriter(s, Encoding.UTF8, true))
                //    {
                //        binWriter.Write((byte)0xc0);
                //        binWriter.Write((uint)time);
                //        s.Write(bytes, 0, bytes.Length);
                //    }
                //}, PacketPriority.MEDIUM_PRIORITY, PacketReliability.UNRELIABLE_SEQUENCED);
            }
        }
Ejemplo n.º 11
0
 protected override byte[] BuildPacket(Packet packet)
 {
     return packet.Build();
 }