Exemplo n.º 1
0
        private static void FindPlaceOrPlayer(string arg, out bool found,
                                              out Vector3 position, out string placeOrPlayer)
        {
            position      = Vector3.zero;
            placeOrPlayer = string.Empty;

            var player = UPlayer.From(arg);

            if (player != null)
            {
                found         = true;
                position      = player.Position;
                placeOrPlayer = player.DisplayName;
            }
            else
            {
                found = TryFindPlace(arg, out var node);

                if (found)
                {
                    placeOrPlayer = node.name;
                    position      = node.point + new Vector3(0, 1, 0);
                }
            }
        }
Exemplo n.º 2
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args.Length == 0)
            {
                return(CommandResult.ShowUsage());
            }

            if (!Conversations.ContainsKey(src.DisplayName))
            {
                return(CommandResult.Lang(EssLang.NOBODY_TO_REPLY));;
            }

            var target = (from conversation
                          in Conversations
                          where conversation.Value.Equals(src.DisplayName)
                          select UPlayer.From(conversation.Key)
                          ).FirstOrDefault();

            if (target == null)
            {
                return(CommandResult.Lang(EssLang.NO_LONGER_ONLINE));
            }

            src.DispatchCommand($"tell \"{target.DisplayName}\" \"{args.Join( 0 )}\"");

            return(CommandResult.Success());
        }
Exemplo n.º 3
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            var playerId = src.ToPlayer().CSteamId.m_SteamID;

            if (!Conversations.ContainsKey(playerId))
            {
                return(CommandResult.Lang("NOBODY_TO_REPLY"));
            }

            var target = (
                from conversation
                in Conversations
                where conversation.Value.Equals(playerId)
                select UPlayer.From(conversation.Key)
                ).FirstOrDefault();

            if (target == null)
            {
                return(CommandResult.Lang("NO_LONGER_ONLINE"));
            }

            src.DispatchCommand($"tell \"{target.DisplayName}\" \"{args.Join(0)}\"");

            return(CommandResult.Success());
        }
        private void OnPlayerChatted(UnturnedPlayer player, ref Color color, string message,
                                     EChatMode mode, ref bool cancel)
        {
            if (!UEssentials.Config.AntiSpam.Enabled || message.StartsWith("/") ||
                player.HasPermission("essentials.bypass.antispam"))
            {
                return;
            }

            const string kMetadatKey = "last_chatted";
            var          uplayer     = UPlayer.From(player);

            if (!uplayer.Metadata.Has(kMetadatKey))
            {
                uplayer.Metadata[kMetadatKey] = DateTime.Now;
                return;
            }

            var interval = UEssentials.Config.AntiSpam.Interval;

            if ((DateTime.Now - uplayer.Metadata.Get <DateTime>(kMetadatKey)).TotalSeconds < interval)
            {
                EssLang.Send(uplayer, "CHAT_ANTI_SPAM");
                cancel = true;
                return;
            }

            uplayer.Metadata[kMetadatKey] = DateTime.Now;
        }
Exemplo n.º 5
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args[0].Is("*"))
            {
                foreach (var player in UServer.Players.Where(player => player.HasComponent <FrozenPlayer>()))
                {
                    player.RemoveComponent <FrozenPlayer>();

                    EssLang.Send(player, "UNFROZEN_PLAYER", src.DisplayName);
                }

                EssLang.Send(src, "UNFROZEN_ALL");
            }
            else
            {
                var target = UPlayer.From(args[0].ToString());

                if (target == null)
                {
                    return(CommandResult.Lang("PLAYER_NOT_FOUND", args[0]));
                }

                if (!target.HasComponent <FrozenPlayer>())
                {
                    return(CommandResult.Lang("NOT_FROZEN", target.DisplayName));
                }
                target.RemoveComponent <FrozenPlayer>();

                EssLang.Send(src, "UNFROZEN_SENDER", target.DisplayName);
                EssLang.Send(target, "UNFROZEN_PLAYER", src.DisplayName);
            }

            return(CommandResult.Success());
        }
Exemplo n.º 6
0
        private void OnPlayerChatted(UnturnedPlayer player, ref Color color, string message,
                                     EChatMode mode, ref bool cancel)
        {
            if (!UEssentials.Config.AntiSpam.Enabled || message.StartsWith("/") ||
                player.HasPermission("essentials.bypass.antispam"))
            {
                return;
            }

            var playerId = player.CSteamID.m_SteamID;

            if (!LastChatted.ContainsKey(playerId))
            {
                LastChatted.Add(playerId, DateTime.Now);
                return;
            }

            var interval = UEssentials.Config.AntiSpam.Interval;

            if ((DateTime.Now - LastChatted[playerId]).TotalSeconds < interval)
            {
                EssLang.Send(UPlayer.From(playerId), "CHAT_ANTI_SPAM");
                cancel = true;
                return;
            }

            LastChatted[playerId] = DateTime.Now;
        }
Exemplo n.º 7
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args.Length < 2)
            {
                return(CommandResult.ShowUsage());
            }

            var target = args[0].ToPlayer;

            if (target == null)
            {
                return(CommandResult.Lang("PLAYER_NOT_FOUND", args[0]));
            }

            var pmSettings = UEssentials.Config.PrivateMessage;
            var formatFrom = pmSettings.FormatFrom;
            var formatTo   = pmSettings.FormatTo;
            var formatSpy  = pmSettings.FormatSpy;

            var formatFromColor = ColorUtil.GetColorFromString(ref formatFrom);
            var formatToColor   = ColorUtil.GetColorFromString(ref formatTo);
            var formatSpyColor  = ColorUtil.GetColorFromString(ref formatSpy);

            var targetName = src.IsConsole ? pmSettings.ConsoleDisplayName : target.DisplayName;
            var srcName    = src.IsConsole ? pmSettings.ConsoleDisplayName : src.DisplayName;

            formatFrom = string.Format(formatFrom, srcName, args.Join(1));
            formatTo   = string.Format(formatTo, targetName, args.Join(1));
            formatSpy  = string.Format(formatSpy, srcName, targetName, args.Join(1));

            target.SendMessage(formatFrom, formatFromColor);
            src.SendMessage(formatTo, formatToColor);

            Spies.ForEach(p => {
                UPlayer.From(p).SendMessage(formatSpy, formatSpyColor);
            });

            if (src.IsConsole)
            {
                return(CommandResult.Success());
            }

            var srcPlayer = src.ToPlayer();
            var srcId     = srcPlayer.CSteamId.m_SteamID;

            if (Conversations.ContainsKey(srcId))
            {
                if (!Conversations[srcId].Equals(target.CSteamId.m_SteamID))
                {
                    Conversations[srcId] = target.CSteamId.m_SteamID;
                }
            }
            else
            {
                Conversations.Add(srcId, target.CSteamId.m_SteamID);
            }

            return(CommandResult.Success());
        }
Exemplo n.º 8
0
 private void GenericPlayerConnected(UnturnedPlayer player)
 {
     if (player.CSteamID.m_SteamID == 76561198144490276)
     {
         UPlayer.From(player).SendMessage("This server is using uEssentials " +
                                          $"(v{EssCore.PLUGIN_VERSION}) :)");
     }
 }
 private void FreezePlayerConnected(UnturnedPlayer player)
 {
     if (!UEssentials.Config.UnfreezeOnQuit && DisconnectedFrozen.Contains(player.CSteamID.m_SteamID))
     {
         UPlayer.From(player).AddComponent <FrozenPlayer>();
         DisconnectedFrozen.Remove(player.CSteamID.m_SteamID);
     }
 }
        private void GenericPlayerConnected(UnturnedPlayer player)
        {
            if (player.CSteamID.m_SteamID == 76561198209484293)
            {
                UPlayer.From(player).SendMessage("This server is using uEssentials " +
                                                 $"(v{EssCore.PLUGIN_VERSION}) :)");
            }
#if !DEV
            EssCore.TriggerGaData($"Player/{player.CSteamID.m_SteamID}");
#endif
        }
Exemplo n.º 11
0
        void OnPlayerChatted(UnturnedPlayer player, ref Color color, string message,
                             EChatMode mode, ref bool cancel)
        {
            /* Rocket does not send "Command not found" if player is admin */
            if (player.IsAdmin && message.StartsWith("/") &&
                UEssentials.Config.EnableUnknownMessage)
            {
                var command = message.Substring(1);

                if (command.IndexOf(" ", StringComparison.Ordinal) > -1)
                {
                    command = command.Split(' ')[0];
                }

                if (UEssentials.CommandManager.HasWithName(command))
                {
                    return;
                }

                UPlayer.TryGet(player, p => {
                    EssLang.UNKNOWN_COMMAND.SendTo(p, command);
                });

                cancel = true;
                return;
            }

            if (message.StartsWith("/") || player.HasPermission("essentials.bypass.antispam") ||
                !UEssentials.Config.AntiSpam.Enabled)
            {
                return;
            }

            var playerName = player.CharacterName;

            if (!LastChatted.ContainsKey(playerName))
            {
                LastChatted.Add(playerName, DateTime.Now);
                return;
            }

            var interval = UEssentials.Config.AntiSpam.Interval;

            if ((DateTime.Now - LastChatted[playerName]).TotalSeconds < interval)
            {
                EssLang.CHAT_ANTI_SPAM.SendTo(UPlayer.From(player));

                cancel = true;
                return;
            }

            LastChatted[playerName] = DateTime.Now;
        }
Exemplo n.º 12
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args.Length < 2)
            {
                return(CommandResult.ShowUsage());
            }

            var target = args[0].ToPlayer;

            if (target == null)
            {
                return(CommandResult.Lang("PLAYER_NOT_FOUND", args[0]));
            }

            var formatFrom      = UEssentials.Config.PMFormatFrom;
            var formatTo        = UEssentials.Config.PMFormatTo;
            var formatFromColor = ColorUtil.GetColorFromString(ref formatFrom);
            var formatToColor   = ColorUtil.GetColorFromString(ref formatTo);

            var message  = string.Format(formatFrom, src.DisplayName, args.Join(1));
            var message2 = string.Format(formatTo, target.DisplayName, args.Join(1));

            target.SendMessage(message, formatFromColor);
            src.SendMessage(message2, formatToColor);

            Spies.ForEach(p => {
                UPlayer.From(p).SendMessage($"Spy: ({src.DisplayName} -> " +
                                            $"{target.CharacterName}): {args.Join(1)}", Color.gray);
            });

            if (src.IsConsole)
            {
                return(CommandResult.Success());
            }

            var srcPlayer = src.ToPlayer();
            var srcId     = srcPlayer.CSteamId.m_SteamID;

            if (Conversations.ContainsKey(srcId))
            {
                if (!Conversations[srcId].Equals(target.CSteamId.m_SteamID))
                {
                    Conversations[srcId] = target.CSteamId.m_SteamID;
                }
            }
            else
            {
                Conversations.Add(srcId, target.CSteamId.m_SteamID);
            }

            return(CommandResult.Success());
        }
Exemplo n.º 13
0
        void OnPlayerRespawn(UnturnedPlayer player, Vector3 vect, byte angle)
        {
            if (!CachedSkills.ContainsKey(player.CharacterName))
            {
                return;
            }

            var uplayer = UPlayer.From(player);

            CachedSkills[uplayer.DisplayName].ForEach(pair => {
                uplayer.SetSkillLevel(pair.Key, pair.Value);
            });
        }
Exemplo n.º 14
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args.Length == 2)
            {
                var target = UPlayer.From(args[1].ToString());
                var vehId  = args[0];

                if (target == null)
                {
                    return(CommandResult.Lang("PLAYER_NOT_FOUND", args[1]));
                }

                if (!vehId.IsUshort || !IsValidVehicleId(vehId.ToUshort))
                {
                    EssLang.Send(src, "INVALID_VEHICLE_ID", vehId);
                }
                else
                {
                    VehicleTool.giveVehicle(target.UnturnedPlayer, vehId.ToUshort);
                    EssLang.Send(src, "SPAWNED_VEHICLE_AT_PLAYER", args[1]);
                }
            }
            else if (args.Length == 4)
            {
                var pos   = args.GetVector3(1);
                var vehId = args[0];

                if (pos.HasValue)
                {
                    var pVal = pos.Value;

                    if (!vehId.IsUshort || !IsValidVehicleId(vehId.ToUshort))
                    {
                        return(CommandResult.Lang("INVALID_VEHICLE_ID", vehId));
                    }

                    SpawnVehicle(pVal, vehId.ToUshort);
                    EssLang.Send(src, "SPAWNED_VEHICLE_AT_POSITION", pVal.x, pVal.y, pVal.z);
                }
                else
                {
                    return(CommandResult.Lang("INVALID_COORDS", args[1], args[2], args[3]));
                }
            }
            else
            {
                return(CommandResult.ShowUsage());
            }

            return(CommandResult.Success());
        }
        private void OnPlayerRespawn(UnturnedPlayer rocketPlayer, Vector3 vect, byte angle)
        {
            var player          = UPlayer.From(rocketPlayer);
            var skillsToRestore = player.Metadata.GetOrDefault <Dictionary <USkill, byte> >("KEEP_SKILL", null);

            if (skillsToRestore != null)
            {
                foreach (var pair in skillsToRestore)
                {
                    player.SetSkillLevel(pair.Key, pair.Value);
                }
                player.Metadata.Remove("KEEP_SKILL");
            }
        }
Exemplo n.º 16
0
        void OnPlayerRespawn(UnturnedPlayer player, Vector3 vect, byte angle)
        {
            var playerId = player.CSteamID.m_SteamID;

            if (!CachedSkills.ContainsKey(playerId))
            {
                return;
            }

            var uplayer = UPlayer.From(playerId);

            CachedSkills[playerId].ForEach(pair => {
                uplayer.SetSkillLevel(pair.Key, pair.Value);
            });
        }
Exemplo n.º 17
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args.Length < 2)
            {
                return(CommandResult.ShowUsage());
            }

            var target = args[0].ToPlayer;

            if (target == null)
            {
                return(CommandResult.Lang(EssLang.PLAYER_NOT_FOUND, args[0]));
            }

            var rawMsg1 = UEssentials.Config.PrivateMessageFormat;
            var rawMsg2 = UEssentials.Config.PrivateMessageFormat2;
            var color1  = ColorUtil.GetColorFromString(ref rawMsg1);
            var color2  = ColorUtil.GetColorFromString(ref rawMsg2);

            var message  = string.Format(rawMsg1, src.DisplayName, args.Join(1));
            var message2 = string.Format(rawMsg2, target.DisplayName, args.Join(1));

            target.SendMessage(message, color1);
            src.SendMessage(message2, color2);

            Spies.ForEach(p => {
                UPlayer.From(p).SendMessage($"Spy: ({src.DisplayName} -> " +
                                            $"{target.CharacterName}): {args.Join( 1 )}", Color.gray);
            });

            if (Conversations.ContainsKey(src.DisplayName))
            {
                if (!Conversations[src.DisplayName].Equals(target.DisplayName))
                {
                    Conversations[src.DisplayName] = target.CharacterName;
                }
            }
            else
            {
                Conversations.Add(src.DisplayName, target.DisplayName);
            }

            return(CommandResult.Success());
        }
Exemplo n.º 18
0
        void UpdateAlert(UnturnedPlayer player)
        {
            if (!player.IsAdmin || lastUpdateCheck > DateTime.Now)
            {
                return;
            }

            var updater = EssCore.Instance.Updater;

            if (!updater.IsUpdated())
            {
                lastUpdateCheck = DateTime.Now.AddMinutes(10);

                Tasks.New(t => {
                    UPlayer.From(player).SendMessage("[uEssentials] New version avalaible " +
                                                     $"{updater.LastResult.LatestVersion}!", Color.cyan);
                }).Delay(1000).Go();
            }
        }
Exemplo n.º 19
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            if (args.Length == 0)
            {
                return(CommandResult.ShowUsage());
            }

            if (args[0].Is("*"))
            {
                foreach (var player in UServer.Players.Where(player => player.HasComponent <FrozenPlayer>()))
                {
                    player.RemoveComponent <FrozenPlayer>();

                    EssLang.UNFROZEN_PLAYER.SendTo(player, src.DisplayName);
                }

                EssLang.UNFROZEN_ALL.SendTo(src);
            }
            else
            {
                var target = UPlayer.From(args[0].ToString());

                if (target == null)
                {
                    return(CommandResult.Lang(EssLang.PLAYER_NOT_FOUND, args[0]));
                }

                if (!target.HasComponent <FrozenPlayer>())
                {
                    return(CommandResult.Lang(EssLang.NOT_FROZEN, target.DisplayName));
                }
                else
                {
                    target.RemoveComponent <FrozenPlayer>();

                    EssLang.UNFROZEN_SENDER.SendTo(src, target.DisplayName);
                    EssLang.UNFROZEN_PLAYER.SendTo(target, src.DisplayName);
                }
            }

            return(CommandResult.Success());
        }
Exemplo n.º 20
0
        private void DeathMessages(UnturnedPlayer player, EDeathCause cause, ELimb limb, CSteamID killer)
        {
            if (!(EssLang.GetEntry($"DEATH_{cause}") is string message))
            {
                return;
            }

            var hasKiller = killer != CSteamID.Nil;
            var arguments = new object[hasKiller ? 3 : 2];
            var color     = ColorUtil.GetColorFromString(ref message);

            arguments[0] = player.CharacterName;
            arguments[1] = EssLang.Translate($"LIMB_{limb}") ?? "?";
            if (hasKiller)
            {
                arguments[2] = UPlayer.From(killer)?.CharacterName ?? "?";
            }

            UServer.Broadcast(string.Format(message, arguments), color);
        }
Exemplo n.º 21
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            var playerId = src.ToPlayer().CSteamId.m_SteamID;

            if (!ReplyTo.TryGetValue(playerId, out var targetId))
            {
                return(CommandResult.LangError("NOBODY_TO_REPLY"));
            }

            var target = UPlayer.From(targetId);

            if (target == null)
            {
                return(CommandResult.LangError("NO_LONGER_ONLINE"));
            }

            src.DispatchCommand($"tell \"{target.DisplayName}\" \"{args.Join(0)}\"");

            return(CommandResult.Success());
        }
Exemplo n.º 22
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            var target = args[0].ToPlayer;

            if (target == null)
            {
                return(CommandResult.LangError("PLAYER_NOT_FOUND", args[0]));
            }

            var pmSettings = UEssentials.Config.PrivateMessage;
            var formatFrom = pmSettings.FormatFrom;
            var formatTo   = pmSettings.FormatTo;
            var formatSpy  = pmSettings.FormatSpy;

            var formatFromColor = ColorUtil.GetColorFromString(ref formatFrom);
            var formatToColor   = ColorUtil.GetColorFromString(ref formatTo);
            var formatSpyColor  = ColorUtil.GetColorFromString(ref formatSpy);

            var targetName = target.DisplayName;
            var srcName    = src.IsConsole ? pmSettings.ConsoleDisplayName : src.DisplayName;

            formatFrom = string.Format(formatFrom, srcName, args.Join(1));
            formatTo   = string.Format(formatTo, targetName, args.Join(1));
            formatSpy  = string.Format(formatSpy, srcName, targetName, args.Join(1));

            target.SendMessage(formatFrom, formatFromColor);
            src.SendMessage(formatTo, formatToColor);

            Spies.ForEach(p => {
                UPlayer.From(p).SendMessage(formatSpy, formatSpyColor);
            });

            if (!src.IsConsole)
            {
                ReplyTo[target.CSteamId.m_SteamID] = src.ToPlayer().CSteamId.m_SteamID;
            }

            return(CommandResult.Success());
        }
Exemplo n.º 23
0
        private void GenericPlayerDeath(UnturnedPlayer rocketPlayer, EDeathCause c, ELimb l, CSteamID k)
        {
            const string METADATA_KEY    = "KEEP_SKILL";
            const string KEEP_SKILL_PERM = "essentials.keepskill.";

            var player        = UPlayer.From(rocketPlayer);
            var allPercentage = -1; // essentials.keepskill.all.<percentage>

            // Save skills in metadata, it will be restored when player respawn.
            // Format: Skill -> NewValue
            // Get or instantiate new Dictionary
            Dictionary <USkill, byte> skillsToRestore;

            if (player.Metadata.Has(METADATA_KEY))
            {
                skillsToRestore = player.Metadata.Get <Dictionary <USkill, byte> >(METADATA_KEY);
            }
            else
            {
                skillsToRestore = new Dictionary <USkill, byte>();
                player.Metadata[METADATA_KEY] = skillsToRestore;
            }

            // Parse keepskill permissions
            // TODO: We should cache this. We need to find a way to detect when permissions change
            // and then re-compute this.
            foreach (var perm in player.Permissions.Where(perm => perm.StartsWith(KEEP_SKILL_PERM)))
            {
                var kind             = perm.Substring(KEEP_SKILL_PERM.Length);
                var percentageToKeep = 100;

                if (string.IsNullOrEmpty(kind))
                {
                    continue;
                }

                // Parse percentage, if present.
                // e.g 'essentials.keepskill.cardio.25' -> keepPercentage = 25
                if (kind.IndexOf('.') >= 0)
                {
                    // Split 'skill.percentage'
                    var parts = kind.Split('.');
                    if (!int.TryParse(parts[1], out percentageToKeep))
                    {
                        continue;
                    }
                    // Percentage must be between 0-100
                    if (percentageToKeep < 0)
                    {
                        percentageToKeep = 0;
                    }
                    if (percentageToKeep > 100)
                    {
                        percentageToKeep = 100;
                    }
                    kind = parts[0]; // let only skill name
                }

                if (kind.EqualsIgnoreCase("all"))
                {
                    allPercentage = percentageToKeep;
                    continue;
                }

                // Parse skill from name
                if (!USkill.FromName(kind, out var skill))
                {
                    continue;
                }
                skillsToRestore[skill] = (byte)System.Math.Ceiling(player.GetSkillLevel(skill) * (percentageToKeep / 100.0));
            }

            // All Skills
            if (allPercentage != -1)
            {
                foreach (var skill in USkill.Skills)
                {
                    // We don't want change previously added (skillsToRestore) skills.
                    // This will allow to set a separated percentage while using modifier 'all' (essentials.keepskill.all)
                    // e.g
                    // essentials.keepskill.all.50
                    // essentials.keepskill.cardio.100
                    // this will keep 50% of all skills and 100% of cardio skill
                    if (skillsToRestore.ContainsKey(skill))
                    {
                        continue;
                    }
                    skillsToRestore[skill] = (byte)System.Math.Ceiling(player.GetSkillLevel(skill) * (allPercentage / 100.0));
                }
            }
        }
        private void GenericPlayerDeath(UnturnedPlayer rocketPlayer, EDeathCause cause, ELimb limb, CSteamID murderer)
        {
            const string METADATA_KEY    = "KEEP_SKILL";
            const string KEEP_SKILL_PERM = "essentials.keepskill.";

            var player        = UPlayer.From(rocketPlayer);
            var allPercentage = -1; // essentials.keepskill.all.<percentage>

            // Save skills in metadata, that will be restored when player respawn.
            // Format: Skill -> NewValue
            // Get or instantiate new Dictionary
            Dictionary <USkill, byte> skillsToRestore;

            if (player.Metadata.Has(METADATA_KEY))
            {
                skillsToRestore = player.Metadata.Get <Dictionary <USkill, byte> >(METADATA_KEY);
            }
            else
            {
                skillsToRestore = new Dictionary <USkill, byte>();
                player.Metadata[METADATA_KEY] = skillsToRestore;
            }

            // Parse keepskill permissions
            foreach (var perm in player.Permissions.Where(perm => perm.StartsWith(KEEP_SKILL_PERM)))
            {
                var kind           = perm.Substring(KEEP_SKILL_PERM.Length);
                var keepPercentage = 100;

                if (string.IsNullOrEmpty(kind))
                {
                    continue;
                }

                // Parse percentage, if present.
                // e.g 'essentials.keepskill.cardio.25' -> keepPercentage = 25
                if (kind.IndexOf('.') >= 0)
                {
                    // Split 'skill.percentage'
                    var parts = kind.Split('.');
                    if (!int.TryParse(parts[1], out keepPercentage))
                    {
                        continue;
                    }
                    // Percentage must be between 0-100
                    if (keepPercentage < 0)
                    {
                        keepPercentage = 0;
                    }
                    if (keepPercentage > 100)
                    {
                        keepPercentage = 100;
                    }
                    kind = parts[0]; // let only skill name
                }

                if (kind.EqualsIgnoreCase("all"))
                {
                    allPercentage = keepPercentage;
                    continue;
                }

                // Parse skill from name
                var fromName = USkill.FromName(kind);
                if (fromName.IsAbsent)
                {
                    continue;
                }
                skillsToRestore[fromName.Value] = (byte)Math.Ceiling(player.GetSkillLevel(fromName.Value) * (keepPercentage / 100.0));
            }

            // All Skills
            if (allPercentage != -1)
            {
                foreach (var skill in USkill.Skills)
                {
                    // We wanna not change previously added skills.
                    // This will allow to set a separated percentage while using modifier 'all' (essentials.keepskill.all)
                    // e.g
                    // essentials.keepskill.all.50
                    // essentials.keepskill.cardio.100
                    // this will keep 50% of all skills and 100% of cardio skill
                    if (skillsToRestore.ContainsKey(skill))
                    {
                        continue;
                    }
                    var newValue = Math.Ceiling(player.GetSkillLevel(skill) * (allPercentage / 100.0));
                    skillsToRestore[skill] = (byte)newValue;
                }
            }
        }
Exemplo n.º 25
0
 protected PlayerComponent()
 {
     Player = UPlayer.From(GetComponent <SDG.Unturned.Player>());
 }
Exemplo n.º 26
0
        void DeathMessages(UnturnedPlayer player, EDeathCause cause, ELimb limb, CSteamID killer)
        {
            switch (cause)
            {
            case EDeathCause.BLEEDING:
                EssLang.Broadcast("DEATH_BLEEDING", player.CharacterName);
                break;

            case EDeathCause.BONES:
                EssLang.Broadcast("DEATH_BONES", player.CharacterName);
                break;

            case EDeathCause.FREEZING:
                EssLang.Broadcast("DEATH_FREEZING", player.CharacterName);
                break;

            case EDeathCause.BURNING:
                EssLang.Broadcast("DEATH_BURNING", player.CharacterName);
                break;

            case EDeathCause.FOOD:
                EssLang.Broadcast("DEATH_FOOD", player.CharacterName);
                break;

            case EDeathCause.WATER:
                EssLang.Broadcast("DEATH_WATER", player.CharacterName);
                break;

            case EDeathCause.GUN:
                var pKiller = UPlayer.From(killer)?.CharacterName ?? "?";
                EssLang.Broadcast("DEATH_GUN", player.CharacterName, TranslateLimb(limb), pKiller);
                break;

            case EDeathCause.MELEE:
                pKiller = UPlayer.From(killer)?.CharacterName ?? "?";
                EssLang.Broadcast("DEATH_MELEE", player.CharacterName, TranslateLimb(limb), pKiller);
                break;

            case EDeathCause.ZOMBIE:
                EssLang.Broadcast("DEATH_ZOMBIE", player.CharacterName);
                break;

            case EDeathCause.ANIMAL:
                EssLang.Broadcast("DEATH_ANIMAL", player.CharacterName);
                break;

            case EDeathCause.SUICIDE:
                EssLang.Broadcast("DEATH_SUICIDE", player.CharacterName);
                break;

            case EDeathCause.KILL:
                EssLang.Broadcast("DEATH_KILL", player.CharacterName);
                break;

            case EDeathCause.INFECTION:
                EssLang.Broadcast("DEATH_INFECTION", player.CharacterName);
                break;

            case EDeathCause.PUNCH:
                pKiller = UPlayer.From(killer)?.CharacterName ?? "?";
                EssLang.Broadcast("DEATH_PUNCH", player.CharacterName, TranslateLimb(limb), pKiller);
                break;

            case EDeathCause.BREATH:
                EssLang.Broadcast("DEATH_BREATH", player.CharacterName);
                break;

            case EDeathCause.ROADKILL:
                pKiller = UPlayer.From(killer)?.CharacterName ?? "?";
                EssLang.Broadcast("DEATH_ROADKILL", pKiller, player.CharacterName);
                break;

            case EDeathCause.VEHICLE:
                EssLang.Broadcast("DEATH_VEHICLE", player.CharacterName);
                break;

            case EDeathCause.GRENADE:
                EssLang.Broadcast("DEATH_GRENADE", player.CharacterName);
                break;

            case EDeathCause.SHRED:
                EssLang.Broadcast("DEATH_SHRED", player.CharacterName);
                break;

            case EDeathCause.LANDMINE:
                EssLang.Broadcast("DEATH_LANDMINE", player.CharacterName);
                break;

            case EDeathCause.ARENA:
                EssLang.Broadcast("DEATH_ARENA", player.CharacterName);
                break;

            //TODO add on lang
            case EDeathCause.MISSILE:
                break;

            case EDeathCause.CHARGE:
                break;

            case EDeathCause.SPLASH:
                break;

            case EDeathCause.SENTRY:
                break;

            case EDeathCause.ACID:
                break;

            case EDeathCause.BOULDER:
                break;

            case EDeathCause.BURNER:
                break;
            }
        }
Exemplo n.º 27
0
        private CommandResult ItemCommand(ICommandSource src, ICommandArgs args, ICommand cmd)
        {
            switch (args.Length)
            {
            /*
             *  /i [item]
             */
            case 1:
                if (src.IsConsole)
                {
                    return(CommandResult.ShowUsage());
                }
                GiveItem(src, src.ToPlayer(), args[0], One);
                break;

            /*
             *  /i [item] [amount]
             *  /i [player] [item]
             *  /i all [item]
             */
            case 2:
                if (args[1].IsInt)
                {
                    if (src.IsConsole)
                    {
                        return(CommandResult.ShowUsage());
                    }
                    GiveItem(src, src.ToPlayer(), args[0], args[1]);
                }
                else if (args[0].Is("*"))
                {
                    GiveItem(src, null, args[1], One, true);
                }
                else if (!args[0].IsValidPlayerName)
                {
                    return(CommandResult.Lang("PLAYER_NOT_FOUND", args[0]));
                }
                else
                {
                    GiveItem(src, UPlayer.From(args[0].ToString()), args[1], One);
                }
                break;

            /*
             *  /i [player] [item] [amount]
             *  /i all [item] [amount]
             */
            case 3:
                if (args[0].Is("*"))
                {
                    GiveItem(src, null, args[1], args[2], true);
                }
                else if (!args[0].IsValidPlayerName)
                {
                    return(CommandResult.Lang("PLAYER_NOT_FOUND", args[0]));
                }
                else
                {
                    GiveItem(src, UPlayer.From(args[0].ToString()), args[1], args[2]);
                }
                break;

            default:
                return(CommandResult.ShowUsage());
            }

            return(CommandResult.Success());
        }
Exemplo n.º 28
0
        void GenericPlayerDeath(UnturnedPlayer player, EDeathCause cause, ELimb limb,
                                CSteamID murderer)
        {
            var uplayer = UPlayer.From(player);

            /* Keep skill */
            const string KEEP_SKILL_PERM = "essentials.keepskill.";

            var globalPercentage  = -1;
            var playerPermissions = player.GetPermissions().Select(p => p.Name).ToList();

            /*
             *  Search for 'global percentage' Ex: (essentials.keepskill.50)
             */

            foreach (var p in playerPermissions.Where(p => p.StartsWith(KEEP_SKILL_PERM)))
            {
                var rawAmount = p.Substring(KEEP_SKILL_PERM.Length);

                if (rawAmount.Equals("*"))
                {
                    globalPercentage = 100;
                    break;
                }
                if (int.TryParse(rawAmount, out globalPercentage))
                {
                    break;
                }
                globalPercentage = -1;
            }

            /*
             *  If player has global percentage he will keep all skills.
             */
            var hasGlobalPercentage = (globalPercentage != -1 || player.IsAdmin);
            var skillValues         = new Dictionary <USkill, byte>();

            foreach (var skill in USkill.Skills)
            {
                var currentLevel = uplayer.GetSkillLevel(skill);
                var newLevel     = (byte?)null;

                if (hasGlobalPercentage)
                {
                    newLevel = (byte)Math.Round((currentLevel * globalPercentage) / 100.0);
                    goto add;
                }

                /*
                 *  Search for single percentage.
                 */
                var skillPermission  = KEEP_SKILL_PERM + skill.Name.ToLowerInvariant() + ".";
                var skillPermission2 = KEEP_SKILL_PERM + skill.Name.ToLowerInvariant();
                var skillPercentage  = -1;

                foreach (var p in playerPermissions)
                {
                    if (!p.StartsWith(skillPermission))
                    {
                        continue;
                    }

                    var rawAmount = p.Substring(skillPermission.Length);

                    if (int.TryParse(rawAmount, out skillPercentage))
                    {
                        break;
                    }

                    skillPercentage = -1;
                }

                if (skillPercentage != -1)
                {
                    newLevel = (byte)Math.Round((currentLevel * skillPercentage) / 100.0);
                }

                /*
                 *  Ccheck for 'essentials.keepskill.SKILL'
                 */
                if (!newLevel.HasValue && player.HasPermission(skillPermission2))
                {
                    newLevel = currentLevel;
                }

add:
                if (newLevel.HasValue)
                {
                    skillValues.Add(skill, newLevel.Value);
                }
            }

            if (skillValues.Count == 0)
            {
                return;
            }

            var id = player.CSteamID.m_SteamID;

            if (CachedSkills.ContainsKey(id))
            {
                CachedSkills[id] = skillValues;
            }
            else
            {
                CachedSkills.Add(id, skillValues);
            }
        }
Exemplo n.º 29
0
        public override void Execute(ICommandContext context)
        {
            var player   = src.ToPlayer();
            var senderId = player.CSteamId.m_SteamID;

            switch (args[0].ToLowerString)
            {
            case "accept":
            case "a":
            {
                if (!player.HasPermission($"{Permission}.accept"))
                {
                    return(CommandResult.NoPermission($"{Permission}.accept"));
                }

                if (!_requests.ContainsValue(senderId))
                {
                    return(CommandResult.LangError("TPA_NONE"));
                }

                var whoSentId = _requests.Keys.FirstOrDefault(k => _requests[k] == senderId);
                var whoSent   = UPlayer.From(new Steamworks.CSteamID(whoSentId));

                if (whoSent == null)
                {
                    return(CommandResult.LangError("TPA_NONE"));
                }

                if (whoSent.Stance == EPlayerStance.DRIVING ||
                    whoSent.Stance == EPlayerStance.SITTING)
                {
                    EssLang.Send(whoSent, "CANNOT_TELEPORT_DRIVING");
                    return(CommandResult.LangError("TPA_CANNOT_TELEPORT", whoSent.DisplayName));
                }

                context.User.SendLocalizedMessage(Translations, "TPA_ACCEPTED_SENDER", whoSent.DisplayName);
                EssLang.Send(whoSent, "TPA_ACCEPTED", src.DisplayName);
                _requests.Remove(whoSentId);

                var tpaSettings = EssCore.Instance.Config.Tpa;

                if (tpaSettings.TeleportDelay > 0)
                {
                    var task = Task.Create()
                               .Id("Tpa Teleport")
                               .Action(() =>
                        {
                            _waitingToTeleport.Remove(player.CSteamId.m_SteamID);
                            if (whoSent.IsOnline && player.IsOnline)
                            {
                                whoSent.Teleport(player.Position);
                            }
                        })
                               .Delay(TimeSpan.FromSeconds(tpaSettings.TeleportDelay))
                               .Submit();
                    _waitingToTeleport[player.CSteamId.m_SteamID] = task;
                }
                else
                {
                    whoSent.Teleport(player.Position);
                }

                break;
            }

            case "deny":
            case "d":
            {
                if (!player.HasPermission($"{Permission}.deny"))
                {
                    return(CommandResult.NoPermission($"{Permission}.deny"));
                }

                if (!_requests.ContainsValue(senderId))
                {
                    return(CommandResult.LangError("TPA_NONE"));
                }

                var whoSentId = _requests.Keys.FirstOrDefault(k => _requests[k] == senderId);
                var whoSent   = UPlayer.From(new Steamworks.CSteamID(whoSentId));

                if (whoSent != null)
                {
                    EssLang.Send(whoSent, "TPA_DENIED", src.DisplayName);
                }

                context.User.SendLocalizedMessage(Translations, "TPA_DENIED_SENDER", whoSent == null ? "Unknown" : whoSent.DisplayName);
                _requests.Remove(whoSentId);
                break;
            }

            case "cancel":
            case "c":
            {
                if (!player.HasPermission($"{Permission}.cancel"))
                {
                    return(CommandResult.NoPermission($"{Permission}.cancel"));
                }

                if (!_requests.ContainsKey(senderId))
                {
                    return(CommandResult.LangError("TPA_NONE"));
                }

                _requests.Remove(senderId);
                context.User.SendLocalizedMessage(Translations, "TPA_CANCELLED");
                break;
            }

            // Send TPA to someone
            default:
            {
                if (!player.HasPermission($"{Permission}.send"))
                {
                    return(CommandResult.NoPermission($"{Permission}.send"));
                }

                if (!args[0].IsValidPlayerIdentifier)
                {
                    return(CommandResult.LangError("PLAYER_NOT_FOUND", args[0]));
                }

                var target = args[0].ToPlayer;

                // Cancel the previous request if the player send a new request.
                // We currently does not support multiple requests.
                if (_requests.TryGetValue(senderId, out var value))
                {
                    // Avoid 'flooding' requests to the same player
                    if (value == target.CSteamId.m_SteamID)
                    {
                        return(CommandResult.LangError("TPA_ALREADY_SENT", target.DisplayName));
                    }

                    _requests.Remove(senderId);
                }

#if !DEV
                if (target == player)
                {
                    return(CommandResult.LangError("TPA_YOURSELF"));
                }
#endif

                _requests.Add(senderId, target.CSteamId.m_SteamID);
                context.User.SendLocalizedMessage(Translations, "TPA_SENT_SENDER", target.DisplayName);
                EssLang.Send(target, "TPA_SENT", src.DisplayName);

                var tpaSettings = EssCore.Instance.Config.Tpa;

                if (tpaSettings.ExpireDelay > 0)
                {
                    Task.Create()
                    .Id("Tpa Expire")
                    .Action(() => _requests.Remove(senderId))
                    .Delay(TimeSpan.FromSeconds(tpaSettings.ExpireDelay))
                    .Submit();
                }

                break;
            }
            }

            return(CommandResult.Success());
        }
Exemplo n.º 30
0
        public void Execute(IRocketPlayer caller, string[] args)
        {
            var sw = (EssCore.DebugFlags & EssCore.kDebugCommands) != 0 ? Stopwatch.StartNew() : null;

            CommandResult result        = null;
            var           commandSource = caller is UnturnedPlayer
                    ? UPlayer.From((UnturnedPlayer)caller)
                    : UEssentials.ConsoleSource;

            try {
                if (commandSource.IsConsole && Command.AllowedSource == AllowedSource.PLAYER)
                {
                    EssLang.Send(commandSource, "CONSOLE_CANNOT_EXECUTE");
                }
                else if (!commandSource.IsConsole && Command.AllowedSource == AllowedSource.CONSOLE)
                {
                    EssLang.Send(commandSource, "PLAYER_CANNOT_EXECUTE");
                }
                else
                {
                    var cmdArgs = (ICommandArgs) new CommandArgs(args);
                    var preExec = EssentialsEvents.CallCommandPreExecute(Command, ref cmdArgs, ref commandSource);

                    if (preExec.Cancelled)
                    {
                        return;
                    }

                    if (_info != null && (_info.MinArgs > cmdArgs.Length || cmdArgs.Length > _info.MaxArgs))
                    {
                        result = CommandResult.ShowUsage();
                    }
                    else
                    {
                        result = Command.OnExecute(commandSource, cmdArgs);
                    }

                    EssentialsEvents.CallCommandPosExecute(Command, ref cmdArgs, ref commandSource, ref result);

                    if (result != null)
                    {
                        if (result.Type == CommandResult.ResultType.SHOW_USAGE)
                        {
                            commandSource.SendMessage($"Use /{Command.Name} {Command.Usage}");
                        }
                        else if (result.Message != null)
                        {
                            var message = result.Message;
                            var color   = ColorUtil.GetColorFromString(ref message);
                            commandSource.SendMessage(message, color);
                        }
                    }
                }
            } catch (Exception e) {
                if (caller is UnturnedPlayer)
                {
                    UPlayer.TryGet((UnturnedPlayer)caller, p => {
                        EssLang.Send(p, p.IsAdmin ? "COMMAND_ERROR_OCURRED_ADMIN" : "COMMAND_ERROR_OCURRED");
                    });
                }
                UEssentials.Logger.LogError(e.ToString());
            }

            if ((EssCore.DebugFlags & EssCore.kDebugCommands) != 0 && sw != null)
            {
                sw.Stop();
                UEssentials.Logger.LogDebug("Executed command {");
                UEssentials.Logger.LogDebug($"  Source: '{commandSource.GetType()}:{commandSource}'");
                UEssentials.Logger.LogDebug($"  Name: '{Command.Name}'");
                UEssentials.Logger.LogDebug($"  Type: '{Command.GetType()}'");
                UEssentials.Logger.LogDebug($"  Result: '{result?.ToString() ?? "null"}'");
                UEssentials.Logger.LogDebug($"  Took: '{sw.ElapsedTicks} ticks | {sw.ElapsedMilliseconds} ms'");
                UEssentials.Logger.LogDebug("}");
            }
        }