public static bool InRangeUnobstructed(
            this IContainer origin,
            IEntity other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false)
        {
            var originEntity = origin.Owner;

            return(SharedInteractionSystem.InRangeUnobstructed(originEntity, other, range, collisionMask, predicate,
                                                               ignoreInsideBlocker));
        }
        /// <summary>
        ///     Checks that the user and target of a
        ///     <see cref="ITargetedInteractEventArgs"/> are within a certain
        ///     distance without any entity that matches the collision mask
        ///     obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the entity and component.
        /// </summary>
        /// <param name="args">The event args to use.</param>
        /// <param name="range">
        ///     Maximum distance between the two entity and set of map coordinates.
        /// </param>
        /// <param name="collisionMask">The mask to check for collisions.</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <param name="ignoreInsideBlocker">
        ///     If true and both the user and target are inside
        ///     the obstruction, ignores the obstruction and considers the interaction
        ///     unobstructed.
        ///     Therefore, setting this to true makes this check more permissive,
        ///     such as allowing an interaction to occur inside something impassable
        ///     (like a wall). The default, false, makes the check more restrictive.
        /// </param>
        /// <param name="popup">
        ///     Whether or not to popup a feedback message on the user entity for
        ///     it to see.
        /// </param>
        /// <returns>
        ///     True if the two points are within a given range without being obstructed.
        /// </returns>
        public bool InRangeUnobstructed(
            ITargetedInteractEventArgs args,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var origin = args.User;
            var other  = args.Target;

            return(InRangeUnobstructed(origin, other, range, collisionMask, predicate, ignoreInsideBlocker, popup));
        }
Пример #3
0
        public static bool InRangeUnobstructed(
            this MapCoordinates origin,
            GridCoordinates other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false)
        {
            var mapManager    = IoCManager.Resolve <IMapManager>();
            var otherPosition = other.ToMap(mapManager);

            return(SharedInteractionSystem.InRangeUnobstructed(origin, otherPosition, range, collisionMask, predicate,
                                                               ignoreInsideBlocker));
        }
Пример #4
0
        public void AddIgnored(ChatUser user)
        {
            if (IsIgnored(user))
            {
                SendMessage(22, user.Username); // You are already ignoring %1.
            }
            else
            {
                Ignored.Add(user);
                user.Ignoring.Add(this);

                SendMessage(23, user.Username); // You are now ignoring %1.
            }
        }
        public static bool InRangeUnobstructed(
            this LocalPlayer origin,
            IEntity other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var otherPosition = other.Transform.MapPosition;

            return(origin.InRangeUnobstructed(otherPosition, range, collisionMask, predicate, ignoreInsideBlocker,
                                              popup));
        }
Пример #6
0
        internal override XmlElement ToXml(XmlDocument doc, string baseDir)
        {
            var elem = base.ToXml(doc, baseDir);

            elem.SetAttribute("exceptionName", exceptionName);
            elem.SetAttribute("includeSubclasses", includeSubclasses.ToString());
            foreach (var item in Ignored.OrderBy(s => s))
            {
                var newChild = doc.CreateElement("Ignore");
                newChild.InnerText = item;
                elem.AppendChild(newChild);
            }
            return(elem);
        }
Пример #7
0
        /// <summary>
        /// Convert to specification in server format
        /// </summary>
        /// <returns></returns>
        override public String ToString()
        {
            String descStr = String.Empty;

            if (Description != null)
            {
                descStr = Description.Replace("\n", "\n\t");
            }

            String Type = _type.ToString(StringEnumCase.Lower);

            String ParentPath = String.Empty;

            if (Parent != null)
            {
                ParentPath = Parent.Path.ToString();
                if (ParentPath == "None")
                {
                    ParentPath = ParentPath.ToLower();
                }
            }

            String pathsView = String.Empty;

            if (Paths != null)
            {
                pathsView = Paths.ToString().Replace("\r\n", "\r\n\t").Trim();
            }

            String remappedView = String.Empty;

            if (Remapped != null)
            {
                remappedView = Remapped.ToString().Replace("\r\n", "\r\n\t").Trim();
            }

            String ignoredView = String.Empty;

            if (Ignored != null)
            {
                ignoredView = Ignored.ToString().Replace("\r\n", "\r\n\t").Trim();
            }

            String value = String.Format(StreamSpecFormat, Id,
                                         FormBase.FormatDateTime(Updated), FormBase.FormatDateTime(Accessed),
                                         OwnerName, Name, ParentPath, Type, descStr, _options.ToString(),
                                         pathsView, remappedView, ignoredView);

            return(value);
        }
        public static bool InRangeUnobstructed(
            this EntityCoordinates origin,
            IContainer other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false)
        {
            var entityManager  = IoCManager.Resolve <IEntityManager>();
            var originPosition = origin.ToMap(entityManager);
            var otherPosition  = other.Owner.Transform.MapPosition;

            return(SharedInteractionSystem.InRangeUnobstructed(originPosition, otherPosition, range, collisionMask,
                                                               predicate, ignoreInsideBlocker));
        }
        public static bool InRangeUnobstructed(
            this LocalPlayer origin,
            EntityCoordinates other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var entityManager = IoCManager.Resolve <IEntityManager>();
            var otherPosition = other.ToMap(entityManager);

            return(origin.InRangeUnobstructed(otherPosition, range, collisionMask, predicate, ignoreInsideBlocker,
                                              popup));
        }
Пример #10
0
        internal Catchpoint(XmlElement elem, string baseDir) : base(elem, baseDir)
        {
            exceptionName = elem.GetAttribute("exceptionName");

            var str = elem.GetAttribute("includeSubclasses");

            if (string.IsNullOrEmpty(str) || !bool.TryParse(str, out includeSubclasses))
            {
                // fall back to the old default behavior
                includeSubclasses = true;
            }
            foreach (var child in elem.ChildNodes.OfType <XmlElement>())
            {
                Ignored.Add(child.InnerText);
            }
        }
Пример #11
0
        /// <summary>
        ///     Checks that these coordinates are within a certain distance without any
        ///     entity that matches the collision mask obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the two sets
        ///     of coordinates.
        /// </summary>
        /// <param name="origin">Set of coordinates to use.</param>
        /// <param name="other">Other set of coordinates to use.</param>
        /// <param name="range">
        ///     Maximum distance between the two sets of coordinates.
        /// </param>
        /// <param name="collisionMask">The mask to check for collisions.</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <param name="ignoreInsideBlocker">
        ///     If true and <see cref="origin"/> or <see cref="other"/> are inside
        ///     the obstruction, ignores the obstruction and considers the interaction
        ///     unobstructed.
        ///     Therefore, setting this to true makes this check more permissive,
        ///     such as allowing an interaction to occur inside something impassable
        ///     (like a wall). The default, false, makes the check more restrictive.
        /// </param>
        /// <returns>
        ///     True if the two points are within a given range without being obstructed.
        /// </returns>
        public bool InRangeUnobstructed(
            MapCoordinates origin,
            MapCoordinates other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false)
        {
            if (!origin.InRange(other, range))
            {
                return(false);
            }

            var dir = other.Position - origin.Position;

            if (dir.LengthSquared.Equals(0f))
            {
                return(true);
            }
            if (range > 0f && !(dir.LengthSquared <= range * range))
            {
                return(false);
            }

            predicate ??= _ => false;

            var ray        = new CollisionRay(origin.Position, dir.Normalized, (int)collisionMask);
            var rayResults = _physicsManager.IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();

            if (rayResults.Count == 0)
            {
                return(true);
            }

            if (!ignoreInsideBlocker)
            {
                return(false);
            }

            if (rayResults.Count <= 0)
            {
                return(false);
            }

            return((rayResults[0].HitPos - other.Position).Length < 1f);
        }
Пример #12
0
        /// <inheritdoc />
        public override void Initialize(string root)
        {
            Ignored.Clear();

            var projectFiles = Directory.EnumerateFiles(root, "*.csproj", SearchOption.AllDirectories);
            var projects     = projectFiles.Select(GetEvaluationProject);

            foreach (var project in projects)
            {
                var bin = GetBinPath(project);
                var obj = GetObjPath(project)
                          + Path.DirectorySeparatorChar;

                Ignored.Add(new Uri(bin));
                Ignored.Add(new Uri(obj));
            }
        }
Пример #13
0
        public void RemoveIgnored(ChatUser user)
        {
            if (IsIgnored(user))
            {
                Ignored.Remove(user);
                user.Ignoring.Remove(this);

                SendMessage(24, user.Username); // You are no longer ignoring %1.

                if (Ignored.Count == 0)
                {
                    SendMessage(26); // You are no longer ignoring anyone.
                }
            }
            else
            {
                SendMessage(25, user.Username); // You are not ignoring %1.
            }
        }
        public static bool InRangeUnobstructed(
            this LocalPlayer origin,
            MapCoordinates other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var originEntity = origin.ControlledEntity;

            if (originEntity == null)
            {
                // TODO: Take into account the player's camera position?
                return(false);
            }

            return(SharedInteractionSystem.InRangeUnobstructed(originEntity, other, range, collisionMask, predicate,
                                                               ignoreInsideBlocker, popup));
        }
        /// <summary>
        ///     Checks that an entity and a set of map coordinates are within a certain
        ///     distance without any entity that matches the collision mask
        ///     obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the entity and component.
        /// </summary>
        /// <param name="origin">The entity to use.</param>
        /// <param name="other">The map coordinates to use.</param>
        /// <param name="range">
        ///     Maximum distance between the two entity and set of map coordinates.
        /// </param>
        /// <param name="collisionMask">The mask to check for collisions.</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <param name="popup">
        ///     Whether or not to popup a feedback message on the origin entity for
        ///     it to see.
        /// </param>
        /// <returns>
        ///     True if the two points are within a given range without being obstructed.
        /// </returns>
        public bool InRangeUnobstructed(
            EntityUid origin,
            MapCoordinates other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored?predicate            = null,
            bool popup = false)
        {
            Ignored combinedPredicatre = e => e == origin || (predicate?.Invoke(e) ?? false);
            var     originPosition     = Transform(origin).MapPosition;
            var     inRange            = InRangeUnobstructed(originPosition, other, range, collisionMask, combinedPredicatre);

            if (!inRange && popup && _gameTiming.IsFirstTimePredicted)
            {
                var message = Loc.GetString("interaction-system-user-interaction-cannot-reach");
                _popupSystem.PopupEntity(message, origin, Filter.Entities(origin));
            }

            return(inRange);
        }
        public bool InRangeUnobstructed(
            MapCoordinates origin,
            EntityUid target,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored?predicate            = null)
        {
            var transform = Transform(target);

            var(position, rotation) = transform.GetWorldPositionRotation();
            var mapPos = new MapCoordinates(position, transform.MapID);

            var     wallPredicate     = AddAnchoredPredicate(target, mapPos, rotation, origin);
            Ignored combinedPredicate = e =>
            {
                return(e == target ||
                       (predicate?.Invoke(e) ?? false) ||
                       (wallPredicate?.Invoke(e) ?? false));
            };

            return(InRangeUnobstructed(origin, mapPos, range, collisionMask, combinedPredicate));
        }
Пример #17
0
        public override void Update(float frameTime)
        {
            if (_examineTooltipOpen == null || !_examineTooltipOpen.Visible)
            {
                return;
            }
            if (_examinedEntity == null || _playerEntity == null)
            {
                return;
            }

            Ignored predicate = entity => entity == _playerEntity || entity == _examinedEntity;

            if (_playerEntity.TryGetContainer(out var container))
            {
                predicate += entity => entity == container.Owner;
            }

            if (!InRangeUnOccluded(_playerEntity, _examinedEntity, ExamineRange, predicate))
            {
                CloseTooltip();
            }
        }
Пример #18
0
        /// <summary>
        ///     Checks that an entity and a set of map coordinates are within a certain
        ///     distance without any entity that matches the collision mask
        ///     obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the entity and component.
        /// </summary>
        /// <param name="origin">The entity to use.</param>
        /// <param name="other">The map coordinates to use.</param>
        /// <param name="range">
        ///     Maximum distance between the two entity and set of map coordinates.
        /// </param>
        /// <param name="collisionMask">The mask to check for collisions.</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <param name="ignoreInsideBlocker">
        ///     If true and <see cref="origin"/> or <see cref="other"/> are inside
        ///     the obstruction, ignores the obstruction and considers the interaction
        ///     unobstructed.
        ///     Therefore, setting this to true makes this check more permissive,
        ///     such as allowing an interaction to occur inside something impassable
        ///     (like a wall). The default, false, makes the check more restrictive.
        /// </param>
        /// <param name="popup">
        ///     Whether or not to popup a feedback message on the origin entity for
        ///     it to see.
        /// </param>
        /// <returns>
        ///     True if the two points are within a given range without being obstructed.
        /// </returns>
        public bool InRangeUnobstructed(
            IEntity origin,
            MapCoordinates other,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var originPosition = origin.Transform.MapPosition;

            predicate ??= e => e == origin;

            var inRange = InRangeUnobstructed(originPosition, other, range, collisionMask, predicate, ignoreInsideBlocker);

            if (!inRange && popup)
            {
                var message = Loc.GetString("You can't reach there!");
                origin.PopupMessage(message);
            }

            return(inRange);
        }
Пример #19
0
        /// <summary>
        ///     Traces a ray from coords to otherCoords and returns the length
        ///     of the vector between coords and the ray's first hit.
        /// </summary>
        /// <param name="origin">Set of coordinates to use.</param>
        /// <param name="other">Other set of coordinates to use.</param>
        /// <param name="collisionMask">the mask to check for collisions</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <returns>Length of resulting ray.</returns>
        public float UnobstructedDistance(
            MapCoordinates origin,
            MapCoordinates other,
            int collisionMask = (int)CollisionGroup.Impassable,
            Ignored predicate = null)
        {
            var dir = other.Position - origin.Position;

            if (dir.LengthSquared.Equals(0f))
            {
                return(0f);
            }

            predicate ??= _ => false;
            var ray        = new CollisionRay(origin.Position, dir.Normalized, collisionMask);
            var rayResults = _physicsManager.IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();

            if (rayResults.Count == 0)
            {
                return(dir.Length);
            }
            return((rayResults[0].HitPos - origin.Position).Length);
        }
Пример #20
0
        /// <summary>
        ///     Checks that the user of a <see cref="DragDropEventArgs"/> is within a
        ///     certain distance of the target and dropped entities without any entity
        ///     that matches the collision mask obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the entity and component.
        /// </summary>
        /// <param name="args">The event args to use.</param>
        /// <param name="range">
        ///     Maximum distance between the two entity and set of map coordinates.
        /// </param>
        /// <param name="collisionMask">The mask to check for collisions.</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <param name="ignoreInsideBlocker">
        ///     If true and both the user and target are inside
        ///     the obstruction, ignores the obstruction and considers the interaction
        ///     unobstructed.
        ///     Therefore, setting this to true makes this check more permissive,
        ///     such as allowing an interaction to occur inside something impassable
        ///     (like a wall). The default, false, makes the check more restrictive.
        /// </param>
        /// <param name="popup">
        ///     Whether or not to popup a feedback message on the user entity for
        ///     it to see.
        /// </param>
        /// <returns>
        ///     True if the two points are within a given range without being obstructed.
        /// </returns>
        public bool InRangeUnobstructed(
            DragDropEventArgs args,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var user    = args.User;
            var dropped = args.Dropped;
            var target  = args.Target;

            if (!InRangeUnobstructed(user, target, range, collisionMask, predicate, ignoreInsideBlocker))
            {
                if (popup)
                {
                    var message = Loc.GetString("You can't reach there!");
                    target.PopupMessage(user, message);
                }

                return(false);
            }

            if (!InRangeUnobstructed(user, dropped, range, collisionMask, predicate, ignoreInsideBlocker))
            {
                if (popup)
                {
                    var message = Loc.GetString("You can't reach there!");
                    dropped.PopupMessage(user, message);
                }

                return(false);
            }

            return(true);
        }
        /// <inheritdoc />
        public override void Initialize(string root)
        {
            var projectFiles = Directory.EnumerateFiles(root, "*.vstemplate", SearchOption.AllDirectories);

            Ignored.AddRange(projectFiles.Select(d => new Uri(d, UriKind.Absolute)));
        }
Пример #22
0
 private static StackTrace InvokeIgnoredMethodWithException() => Ignored.MethodWithException();
Пример #23
0
 private static StackTrace InvokeIgnoredMethod() => Ignored.Method();
Пример #24
0
        public static bool InRangeUnOccluded(MapCoordinates origin, MapCoordinates other, float range, Ignored predicate, bool ignoreInsideBlocker = true)
        {
            var occluderSystem = Get <OccluderSystem>();

            if (!origin.InRange(other, range))
            {
                return(false);
            }

            var dir = other.Position - origin.Position;

            if (dir.LengthSquared.Equals(0f))
            {
                return(true);
            }
            if (range > 0f && !(dir.LengthSquared <= range * range))
            {
                return(false);
            }

            predicate ??= _ => false;

            var ray        = new Ray(origin.Position, dir.Normalized);
            var rayResults = occluderSystem
                             .IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();

            if (rayResults.Count == 0)
            {
                return(true);
            }

            if (!ignoreInsideBlocker)
            {
                return(false);
            }

            if (rayResults.Count <= 0)
            {
                return(false);
            }

            return((rayResults[0].HitPos - other.Position).Length < 1f);
        }
Пример #25
0
 public bool IsIgnored(ChatUser check) => Ignored.Contains(check);
 /// <inheritdoc />
 public override bool IsValid(string file)
 {
     return(!Ignored.Contains(new Uri(file, UriKind.Absolute)));
 }
Пример #27
0
 private void IgnoreClick(object sender, RoutedEventArgs e)
 {
     Ignored?.Invoke(this);
 }
Пример #28
0
 /// <summary>
 /// Declare that the specified property on the mapping destination should not have its value set during mapping
 /// </summary>
 /// <typeparam name="TPropertyType"></typeparam>
 /// <param name="property">The property to ignore</param>
 /// <returns></returns>
 public MappingConfig <TSrc, TDest> Ignore <TPropertyType>(Expression <Func <TDest, TPropertyType> > property)
 {
     Ignored.Add(GetPropertyName(property));
     return(this);
 }
Пример #29
0
        /// <summary>
        /// Packets handled in this function are 'internal' and cannot be overriden.
        /// </summary>
        internal bool HandlePacket(PacketEventArgs e)
        {
            if (IsCaptcha)
            {
                switch ((AresId)e.Packet.Id)
                {
                case AresId.MSG_CHAT_CLIENT_FASTPING:
                    FastPing = true;
                    return(true);

                case AresId.MSG_CHAT_CLIENT_DUMMY:
                    return(true);

                case AresId.MSG_CHAT_CLIENT_AUTOLOGIN:
                    AutoLogin login = (AutoLogin)e.Packet;
                    AresCommands.HandleAutoLogin(server, this, login.Sha1Password);
                    return(true);

                case AresId.MSG_CHAT_CLIENT_PUBLIC:
                    ClientPublic pub = (ClientPublic)e.Packet;
                    FinishCaptcha(pub.Message);
                    return(true);

                case AresId.MSG_CHAT_CLIENT_EMOTE:
                    ClientEmote emote = (ClientEmote)e.Packet;
                    FinishCaptcha(emote.Message);
                    return(true);

                case AresId.MSG_CHAT_CLIENT_ADDSHARE:
                    return(true);

                case AresId.MSG_CHAT_CLIENT_UPDATE_STATUS:
                    ClientUpdate update = (ClientUpdate)e.Packet;

                    LastUpdate = DateTime.Now;
                    NodeIp     = update.NodeIp;
                    NodePort   = update.NodePort;
                    return(true);

                default:
                    break;
                }
                return(false);
            }
            else if (LoggedIn)
            {
                switch ((AresId)e.Packet.Id)
                {
                case AresId.MSG_CHAT_CLIENT_FASTPING:
                    FastPing = true;
                    return(true);

                case AresId.MSG_CHAT_CLIENT_DUMMY:
                    return(true);

                case AresId.MSG_CHAT_CLIENT_PUBLIC:
                    ClientPublic pub = (ClientPublic)e.Packet;

                    if (AresCommands.HandlePreCommand(server, this, pub.Message))
                    {
                        return(true);
                    }

                    if (Muzzled)
                    {
                        server.SendAnnounce(this, Strings.AreMuzzled);
                        return(true);
                    }
                    break;

                case AresId.MSG_CHAT_CLIENT_EMOTE:
                    ClientEmote emote = (ClientEmote)e.Packet;

                    if (AresCommands.HandlePreCommand(server, this, emote.Message))
                    {
                        return(true);
                    }

                    if (Muzzled)
                    {
                        server.SendAnnounce(this, Strings.AreMuzzled);
                        return(true);
                    }
                    break;

                case AresId.MSG_CHAT_CLIENT_COMMAND:
                    Command cmd = (Command)e.Packet;
                    if (AresCommands.HandleCommand(server, this, cmd.Message))
                    {
                        return(true);
                    }
                    break;

                case AresId.MSG_CHAT_CLIENT_PVT:
                    Private pvt = (Private)e.Packet;

                    if (Muzzled && !server.Config.MuzzledPMs)
                    {
                        pvt.Message = "[" + Strings.AreMuzzled + "]";
                        SendPacket(pvt);

                        return(true);
                    }

                    break;

                case AresId.MSG_CHAT_CLIENT_AUTHREGISTER: {
                    AuthRegister reg = (AuthRegister)e.Packet;
                    AresCommands.HandleRegister(server, this, reg.Password);
                    return(true);
                }

                case AresId.MSG_CHAT_CLIENT_AUTHLOGIN: {
                    AuthLogin login = (AuthLogin)e.Packet;
                    AresCommands.HandleLogin(server, this, login.Password);
                    return(true);
                }

                case AresId.MSG_CHAT_CLIENT_AUTOLOGIN: {
                    AutoLogin login = (AutoLogin)e.Packet;
                    AresCommands.HandleAutoLogin(server, this, login.Sha1Password);
                    return(true);
                }

                case AresId.MSG_CHAT_CLIENT_ADDSHARE:
                    return(true);

                case AresId.MSG_CHAT_CLIENT_IGNORELIST:
                    Ignored ignore = (Ignored)e.Packet;
                    if (ignore.Ignore)
                    {
                        lock (Ignored) {
                            if (!Ignored.Contains(ignore.Username))
                            {
                                Ignored.Add(ignore.Username);
                                server.SendAnnounce(this, String.Format(Strings.Ignored, ignore.Username));
                            }
                        }
                    }
                    else
                    {
                        lock (Ignored) {
                            if (Ignored.Contains(ignore.Username))
                            {
                                Ignored.Remove(ignore.Username);
                                server.SendAnnounce(this, String.Format(Strings.Unignored, ignore.Username));
                            }
                        }
                    }
                    return(true);

                case AresId.MSG_CHAT_CLIENT_UPDATE_STATUS:
                    ClientUpdate update = (ClientUpdate)e.Packet;

                    LastUpdate = DateTime.Now;
                    NodeIp     = update.NodeIp;
                    NodePort   = update.NodePort;
                    server.SendPacket((s) =>
                                      s.Vroom == Vroom &&
                                      s.CanSee(this),
                                      new ServerUpdate(this));

                    return(true);

                case AresId.MSG_CHAT_CLIENT_DIRCHATPUSH:
                    ClientDirectPush push = (ClientDirectPush)e.Packet;

                    if (Encoding.UTF8.GetByteCount(push.Username) < 2)
                    {
                        SendPacket(new DirectPushError(4));
                        return(true);
                    }

                    if (push.TextSync.Length < 16)
                    {
                        SendPacket(new DirectPushError(3));
                        return(true);
                    }

                    IClient target = server.FindUser(s => s.Name == push.Username);

                    if (target == null)
                    {
                        SendPacket(new DirectPushError(1));
                        return(true);
                    }

                    if (target.Ignored.Contains(Name))
                    {
                        SendPacket(new DirectPushError(2));
                        return(true);
                    }

                    SendPacket(new DirectPushError(0));
                    server.SendPacket(target, new ServerDirectPush(this, push));

                    return(true);

                case AresId.MSG_CHAT_CLIENT_BROWSE:
                    SendPacket(new BrowseError(((Browse)e.Packet).BrowseId));
                    return(true);

                case AresId.MSG_CHAT_CLIENT_SEARCH:
                    SendPacket(new SearchEnd(((Search)e.Packet).SearchId));
                    return(true);

                case AresId.MSG_CHAT_CLIENTCOMPRESSED: {
                    Compressed packet  = (Compressed)e.Packet;
                    byte[]     payload = Zlib.Decompress(packet.Data);

                    var reader = new PacketReader(payload)
                    {
                        Position = 0L
                    };

                    while (reader.Remaining >= 3)
                    {
                        ushort count = reader.ReadUInt16();
                        byte   id    = reader.ReadByte();

                        IPacket msg = Socket.Formatter.Unformat(id, reader.ReadBytes(count));
                        OnPacketReceived(Socket, new PacketEventArgs(msg, WebSocketMessageType.Binary, 0));
                    }
                    break;
                }

                default:
                    break;
                }

                return(false);//wasn't handled
            }
            else
            {
                //not captcha, not logged, error?
                Logging.Info("AresClient", "Client {0} sent {1} before logging in.", this.ExternalIp, e.Packet.Id);
                return(true);
            }
        }
Пример #30
0
 private void ClearIgnoredUnits()
 {
     Ignored.Clear();
 }