コード例 #1
0
        public void ChangePlayerBlipAlpha(Client target, int newAlpha)
        {
            if (NetEntityHandler.ToDict().ContainsKey(target.handle.Value))
            {
                ((PlayerProperties)NetEntityHandler.ToDict()[target.handle.Value]).BlipAlpha = (byte)newAlpha;
            }

            var obj = new SyncEvent
            {
                EventType = (byte)ServerEventType.PlayerBlipAlphaChange,
                Arguments = ParseNativeArguments(target.handle.Value, newAlpha)
            };

            SendToAll(obj, PacketType.ServerEvent, true, ConnectionChannel.EntityBackend);
        }
コード例 #2
0
        //Vehicle Packet
        internal void ResendPacket(VehicleData fullPacket, Client exception, bool pure)
        {
            byte[] full;
            var    basic = new byte[0];

            if (pure)
            {
                full = PacketOptimization.WritePureSync(fullPacket);
                if (fullPacket.Flag != null && PacketOptimization.CheckBit(fullPacket.Flag.Value, VehicleDataFlags.Driver))
                {
                    if (fullPacket.NetHandle != null)
                    {
                        basic = PacketOptimization.WriteBasicSync(fullPacket.NetHandle.Value, fullPacket.Position);
                    }
                }
                else if (!exception.CurrentVehicle.IsNull)
                {
                    var carPos = NetEntityHandler.ToDict()[exception.CurrentVehicle.Value].Position;
                    if (fullPacket.NetHandle != null)
                    {
                        basic = PacketOptimization.WriteBasicSync(fullPacket.NetHandle.Value, carPos);
                    }
                }
            }
            else
            {
                full = PacketOptimization.WriteLightSync(fullPacket);
            }

            var msg = Server.CreateMessage();

            if (pure)
            {
                //if (client.Position.DistanceToSquared(fullPacket.Position) > 40000f) // 1 km
                //{
                //    var lastUpdateReceived = client.LastPacketReceived.Get(exception.handle.Value);

                //    if (lastUpdateReceived != 0 && Program.GetTicks() - lastUpdateReceived <= 1000) continue;
                //    msg.Write((byte)PacketType.BasicSync);
                //    msg.Write(basic.Length);
                //    msg.Write(basic);
                //    Server.SendMessage(msg, client.NetConnection, NetDeliveryMethod.UnreliableSequenced, (int)ConnectionChannel.BasicSync);

                //    client.LastPacketReceived.Set(exception.handle.Value, Program.GetTicks());
                //}
                //else
                //{
                msg.Write((byte)PacketType.VehiclePureSync);
                msg.Write(full.Length);
                msg.Write(full);
                //}
            }
            else
            {
                msg.Write((byte)PacketType.VehicleLightSync);
                msg.Write(full.Length);
                msg.Write(full);
            }

            List <NetConnection> connectionsNear = new List <NetConnection>();

            foreach (var client in exception.Streamer.GetNearClients())
            {
                if (client.NetConnection.Status == NetConnectionStatus.Disconnected)
                {
                    continue;
                }
                if (!client.ConnectionConfirmed)
                {
                    continue;
                }
                if (client.NetConnection.RemoteUniqueIdentifier == exception.NetConnection.RemoteUniqueIdentifier)
                {
                    continue;
                }

                if (pure)
                {
                    if (client.Position == null)
                    {
                        continue;
                    }

                    connectionsNear.Add(client.NetConnection);
                }
                else
                {
                    connectionsNear.Add(client.NetConnection);
                }
            }

            if (pure)
            {
                Server.SendMessage(msg, connectionsNear, NetDeliveryMethod.UnreliableSequenced, (int)ConnectionChannel.PureSync);
            }
            else
            {
                Server.SendMessage(msg, connectionsNear, NetDeliveryMethod.ReliableSequenced, (int)ConnectionChannel.LightSync);
            }

            if (pure)
            {
                var msgBasic = Server.CreateMessage();
                msgBasic.Write((byte)PacketType.BasicSync);
                msgBasic.Write(basic.Length);
                msgBasic.Write(basic);

                long ticks = Program.GetTicks();
                List <NetConnection> connectionsFar = new List <NetConnection>();

                foreach (var client in exception.Streamer.GetFarClients())
                {
                    if (client.NetConnection.Status == NetConnectionStatus.Disconnected)
                    {
                        continue;
                    }
                    if (!client.ConnectionConfirmed)
                    {
                        continue;
                    }
                    if (client.NetConnection.RemoteUniqueIdentifier == exception.NetConnection.RemoteUniqueIdentifier)
                    {
                        continue;
                    }

                    var lastUpdateReceived = client.LastPacketReceived.Get(exception.handle.Value);

                    if (lastUpdateReceived != 0 && ticks - lastUpdateReceived <= 1000)
                    {
                        continue;
                    }
                    connectionsFar.Add(client.NetConnection);

                    client.LastPacketReceived.Set(exception.handle.Value, ticks);
                }

                Server.SendMessage(msgBasic, connectionsFar, NetDeliveryMethod.UnreliableSequenced, (int)ConnectionChannel.BasicSync);
            }
        }