private List <BasePlayer> GetClanMembers(ulong playerUID)
        {
            var membersList = new List <BasePlayer>();

            var clanName = Clans?.Call <string>("GetClanOf", playerUID);

            if (!string.IsNullOrEmpty(clanName))
            {
                var clan = Clans?.Call <JObject>("GetClan", clanName);

                if (clan != null && clan is JObject)
                {
                    var members = (clan as JObject).GetValue("members");

                    if (members != null && members is JArray)
                    {
                        foreach (var member in (JArray)members)
                        {
                            ulong clanMemberUID;

                            if (!ulong.TryParse(member.ToString(), out clanMemberUID))
                            {
                                continue;
                            }

                            var clanMember = RustCore.FindPlayerById(clanMemberUID);

                            membersList.Add(clanMember);
                        }
                    }
                }
            }
            return(membersList);
        }
Пример #2
0
        private bool DisableGodmode(string playerID)
        {
            if (string.IsNullOrEmpty(playerID))
            {
                return(false);
            }
            var player = RustCore.FindPlayerById(ulong.Parse(playerID));

            if (player == null)
            {
                return(false);
            }
            if (IsGod(player.UserIDString))
            {
                storedData.godPlayers.Remove(player.UserIDString);
            }
            if (configData.showNamePrefix)
            {
                Rename(player, false);
            }

            ModifyMetabolism(player, false);
            CheckOnlineGods();
            return(true);
        }
Пример #3
0
        private void GodsCommand(IPlayer iPlayer, string command, string[] args)
        {
            if (!iPlayer.HasPermission(permAdmin))
            {
                Print(iPlayer, Lang("NotAllowed", iPlayer.Id, command));
                return;
            }
            if (storedData.godPlayers.Count == 0)
            {
                Print(iPlayer, Lang("NoGods", iPlayer.Id));
                return;
            }
            string result = string.Empty;

            foreach (var god in storedData.godPlayers)
            {
                BasePlayer player = RustCore.FindPlayerByIdString(god);
                if (player == null)
                {
                    continue;
                }
                result += $"\n[{god}] {player.displayName}";
            }
            Print(iPlayer, result);
        }
Пример #4
0
        private void GodCommand(IPlayer iPlayer, string command, string[] args)
        {
            if ((args.Length > 0 && !iPlayer.HasPermission(permAdmin)) || !iPlayer.HasPermission(permToggle))
            {
                Print(iPlayer, Lang("NotAllowed", iPlayer.Id, command));
                return;
            }
            if (args.Length == 0 && iPlayer.Id == "server_console")
            {
                Print(iPlayer, $"The server console cannot use {command}");
                return;
            }
            var target = args.Length > 0 ? RustCore.FindPlayer(args[0]) : iPlayer.Object as BasePlayer;

            if (args.Length > 0 && target == null)
            {
                Print(iPlayer, Lang("PlayerNotFound", iPlayer.Id, args[0]));
                return;
            }
            object obj = ToggleGodmode(target, iPlayer.Object as BasePlayer);

            if (iPlayer.Id == "server_console" && args.Length > 0 && obj is bool)
            {
                if ((bool)obj)
                {
                    Print(iPlayer, $"'{target.displayName}' have enabled godmode");
                }
                else
                {
                    Print(iPlayer, $"'{target.displayName}' have disabled godmode");
                }
            }
        }
Пример #5
0
        static bool CanAuthorize(BuildingPrivlidge cupboard)
        {
            var owner       = cupboard.authorizedPlayers[0];
            var ownerPlayer = RustCore.FindPlayerById(owner.userid);

            return(ownerPlayer?.isConnected ?? true);
        }
Пример #6
0
 string GetName(string id)
 {
     if (id == "0")
     {
         return("[SERVERSPAWN]");
     }
     return(RustCore.FindPlayer(id) ? RustCore.FindPlayer(id).displayName : covalence.Players.FindPlayer(id)?.Name);
 }
        private bool InTeam(ulong playerUID)
        {
            var player = RustCore.FindPlayerById(playerUID);

            var playersCurrentTeam = RelationshipManager.Instance.FindTeam(player.currentTeam);

            return(playersCurrentTeam != null);
        }
Пример #8
0
        private List <BasePlayer> GetFriends(ulong userID)
        {
            var result = Friends?.Call("GetFriends", userID);

            if (result == null)
            {
                return(null);
            }

            return((result as ulong[]).Select(x => RustCore.FindPlayerById(x)).ToList());
        }
        private List <BasePlayer> GetFriends(ulong playerUID)
        {
            var friendsList = new List <BasePlayer>();

            var friends = Friends.Call <ulong[]>("GetFriends", playerUID);

            foreach (var friendUID in friends)
            {
                var friend = RustCore.FindPlayerById(friendUID);

                friendsList.Add(friend);
            }

            return(friendsList);
        }
Пример #10
0
        private PlayerData GetPlayerData(ulong playerId)
        {
            var        player = RustCore.FindPlayerById(playerId);
            PlayerData playerData;

            if (!FriendsData.TryGetValue(playerId, out playerData))
            {
                FriendsData[playerId] = playerData = new PlayerData();
            }
            if (player != null)
            {
                playerData.Name = player.displayName;
            }
            return(playerData);
        }
Пример #11
0
        void OnEntityEnter(TriggerBase trigger, BaseEntity entity)
        {
            var player   = entity as BasePlayer;
            var cupboard = trigger as BuildPrivilegeTrigger;

            if (player == null || cupboard == null)
            {
                return;
            }

            var owner       = cupboard.privlidgeEntity.authorizedPlayers[0];
            var ownerPlayer = RustCore.FindPlayerById(owner.userid);

            if (ownerPlayer != null && ownerPlayer.isConnected)
            {
                timer.Once(0.1f, () => player.SetPlayerFlag(BasePlayer.PlayerFlags.HasBuildingPrivilege, true));
            }
        }
        private List <BasePlayer> GetTeamMembers(ulong playerUID)
        {
            var membersList = new List <BasePlayer>();

            var player = RustCore.FindPlayerById(playerUID);

            var playersCurrentTeam = RelationshipManager.Instance.FindTeam(player.currentTeam);

            var teamMembers = playersCurrentTeam.members;

            foreach (var teamMemberUID in teamMembers)
            {
                var teamMember = RustCore.FindPlayerById(teamMemberUID);

                membersList.Add(teamMember);
            }

            return(membersList);
        }
Пример #13
0
        private void cmdFriend(BasePlayer player, string command, string[] args)
        {
            if (args == null || args.Length <= 0 || args.Length == 1 && !args[0].Equals("list", StringComparison.OrdinalIgnoreCase))
            {
                PrintMessage(player, "Syntax");
                return;
            }
            switch (args[0].ToLower())
            {
            case "list":
                var friendList = GetFriendList(player.userID);
                if (friendList.Length > 0)
                {
                    PrintMessage(player, "List", $"{friendList.Length}/{configData.MaxFriends}", string.Join(", ", friendList));
                }
                else
                {
                    PrintMessage(player, "NoFriends");
                }
                return;

            case "add":
            case "+":
                var friendPlayer = RustCore.FindPlayer(args[1]);
                if (friendPlayer == null)
                {
                    PrintMessage(player, "PlayerNotFound", args[1]);
                    return;
                }
                if (player == friendPlayer)
                {
                    PrintMessage(player, "CantAddSelf");
                    return;
                }
                var playerData = GetPlayerData(player.userID);
                if (playerData.Friends.Count >= configData.MaxFriends)
                {
                    PrintMessage(player, "FriendlistFull");
                    return;
                }
                if (playerData.Friends.Contains(friendPlayer.userID))
                {
                    PrintMessage(player, "AlreadyOnList", friendPlayer.displayName);
                    return;
                }
                AddFriend(player.userID, friendPlayer.userID);
                PrintMessage(player, "FriendAdded", friendPlayer.displayName);
                return;

            case "remove":
            case "-":
                var friend = FindFriend(args[1]);
                if (friend <= 0)
                {
                    PrintMessage(player, "NotOnFriendlist", args[1]);
                    return;
                }
                var removed = RemoveFriend(player.userID, friend);
                PrintMessage(player, removed ? "FriendRemoved" : "NotOnFriendlist", args[1]);
                return;
            }
        }
Пример #14
0
        private void HandleTimer(ulong horseid, ulong userid, bool start = false)
        {
            if (htimer.ContainsKey(horseid))
            {
                if (start)
                {
                    htimer[horseid].timer = timer.Once(htimer[horseid].countdown, () => HandleTimer(horseid, userid, false));
                    if (configData.Options.debug)
                    {
                        Puts($"Started release timer for horse {horseid.ToString()} owned by {userid.ToString()}");
                    }
                }
                else
                {
                    if (htimer.ContainsKey(horseid))
                    {
                        htimer[horseid].timer.Destroy();
                        htimer.Remove(horseid);
                    }

                    try
                    {
                        BaseNetworkable horse   = BaseNetworkable.serverEntities.Find((uint)horseid);
                        BasePlayer      player  = RustCore.FindPlayerByIdString(userid.ToString());
                        RidableHorse    mounted = player.GetMounted().GetComponentInParent <RidableHorse>();

                        if (mounted.net.ID == horseid && configData.Options.ReleaseOwnerOnHorse)
                        {
                            // Player is on this horse and we allow ownership to be removed while on the horse
                            mounted.OwnerID = 0;
                            horses.Remove(horseid);
                            if (configData.Options.debug)
                            {
                                Puts($"Released horse {horseid.ToString()} owned by {userid.ToString()}");
                            }
                        }
                        else if (mounted.net.ID == horseid && !configData.Options.ReleaseOwnerOnHorse)
                        {
                            // Player is on this horse and we DO NOT allow ownership to be removed while on the horse
                            // Reset the timer...
                            htimer.Add(horseid, new HTimer()
                            {
                                start = Time.realtimeSinceStartup, countdown = configData.Options.ReleaseTime, userid = userid
                            });
                            htimer[horseid].timer = timer.Once(configData.Options.ReleaseTime, () => HandleTimer(horseid, userid));
                            if (configData.Options.debug)
                            {
                                Puts($"Reset ownership timer for horse {horseid.ToString()} owned by {userid.ToString()}");
                            }
                        }
                        else
                        {
                            // Player is NOT mounted on this horse...
                            BaseEntity bhorse = horse as BaseEntity;
                            bhorse.OwnerID = 0;
                            horses.Remove(horseid);
                            if (configData.Options.debug)
                            {
                                Puts($"Released horse {horseid.ToString()} owned by {userid}");
                            }
                        }
                        SaveData();
                    }
                    catch
                    {
                        BaseNetworkable horse  = BaseNetworkable.serverEntities.Find((uint)horseid);
                        BaseEntity      bhorse = horse as BaseEntity;
                        bhorse.OwnerID = 0;
                        horses.Remove(horseid);
                        SaveData();
                        if (configData.Options.debug)
                        {
                            Puts($"Released horse {horseid.ToString()} owned by {userid}");
                        }
                    }
                }
            }
        }
Пример #15
0
        private void BgConsoleCommand(ConsoleSystem.Arg arg)
        {
            string userIdString = arg.Connection?.userid.ToString();

            if (arg.Connection != null)
            {
                if (!arg.IsAdmin && !IsAdmin(arg.Connection.userid.ToString()))
                {
                    SendReply(arg, Lang("NoPermission", userIdString));
                    return;
                }
            }

            if (arg.Args == null || arg.Args.Length == 0)
            {
                SendReply(arg, Lang("InvalidArgsConsole", userIdString));
                return;
            }

            if (arg.Args.Length >= 0)
            {
                switch (arg.Args[0].ToLower())
                {
                case "unlocked":
                    if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null || target.blueprints == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        String replyString = Lang("BlueprintsUnlocked", userIdString, target.displayName);
                        foreach (String a in GetPlayerBlueprints(target))
                        {
                            replyString += a + ", ";
                        }

                        SendReply(arg, replyString);
                    }
                    return;

                case "save":
                    if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }
                        if (_targetNeedsPermission && !IsAdmin(target) && !IsUser(target.UserIDString))
                        {
                            SendReply(arg, Lang("NoPermTarget", userIdString, target.displayName));
                            return;
                        }
                        SaveBlueprints(target);
                        SendReply(arg, Lang("BlueprintsSavedTarget", userIdString, target.displayName));
                    }
                    return;

                case "restore":
                    if (!_isActivated)
                    {
                        SendReply(arg, Lang("PluginNotActivated", userIdString));
                        return;
                    }
                    if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        if (_targetNeedsPermission && !IsAdmin(target) && !IsUser(target.UserIDString))
                        {
                            SendReply(arg, Lang("NoPermTarget", userIdString, target.displayName));
                            return;
                        }

                        if (!_cachedPlayerInfo.ContainsKey(target.userID))
                        {
                            SendReply(arg, Lang("NoSavedDataFound", userIdString, target.displayName));
                            return;
                        }

                        if (arg.Connection != null)
                        {
                            SendReply(arg, RestoreBlueprints(target));
                        }
                    }
                    return;

                case "unlock":
                    if (arg.Args.Length == 3)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        ItemDefinition itemDefinition = ItemManager.FindItemDefinition(arg.Args[2]);

                        if (itemDefinition == null)
                        {
                            SendReply(arg, Lang("NoItemFound", userIdString));
                            return;
                        }

                        if (!_configData.DisableAllLogging)
                        {
                            Puts($"{arg.Connection?.username ?? "Server Console"} unlocked blueprint {itemDefinition.displayName} for [{target.displayName}/{target.userID}]");
                        }
                        target.blueprints?.Unlock(itemDefinition);
                    }

                    return;

                case "unlockall":
                    if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        if (_targetNeedsPermission && !IsAdmin(target) && !IsUser(target.UserIDString))
                        {
                            SendReply(arg, Lang("NoPermTarget", userIdString, target.displayName));
                            return;
                        }

                        var blueprints = target.blueprints;
                        if (blueprints == null)
                        {
                            return;
                        }

                        blueprints.UnlockAll();
                        SendReply(arg, Lang("AllBlueprintsUnlocked", userIdString, target.displayName));
                        if (!_configData.DisableAllLogging)
                        {
                            Puts(Lang("AllBlueprintsUnlocked", userIdString, target.displayName));
                        }
                    }
                    return;

                case "reset":
                    if (arg.Args.Length == 3)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        if (arg.Args[2].ToLower() == "confirm")
                        {
                            if (_targetNeedsPermission && !IsAdmin(target) && !IsUser(target.UserIDString))
                            {
                                SendReply(arg, Lang("NoPermTarget", userIdString, target.displayName));
                                return;
                            }

                            var blueprints = target.blueprints;
                            if (blueprints == null)
                            {
                                return;
                            }

                            //Use buildin Rust function to reset blueprints
                            blueprints.Reset();

                            //Check if blueprints are present in data and if so clear it
                            PlayerInfo playerInfo;
                            if (_cachedPlayerInfo.TryGetValue(target.userID, out playerInfo))
                            {
                                playerInfo.UnlockedBlueprints.Clear();
                            }

                            if (!_configData.DisableAllLogging)
                            {
                                Puts(Lang("BlueprintsReset", null, target.displayName));
                            }
                            if (arg.Connection != null)
                            {
                                SendReply(arg, Lang("BlueprintsReset", userIdString, target.displayName));
                            }
                        }
                        else
                        {
                            SendReply(arg, Lang("ConfirmReset", userIdString, target.displayName, arg.Args[2]));
                        }
                    }
                    else if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        SendReply(arg, Lang("ConfirmReset", userIdString, target.displayName, arg.Args[1]));
                    }
                    else
                    {
                        SendReply(arg, Lang("InvalidArgsConsole", userIdString));
                    }
                    return;

                case "toggle":
                    _isActivated = !_isActivated;
                    SaveConfigData();
                    SendReply(arg, _isActivated ? Lang("Activated", userIdString) : Lang("Deactivated", userIdString));
                    return;

                case "autorestore":
                    _autoRestore = !_autoRestore;
                    SaveConfigData();
                    SendReply(arg, _isActivated ? Lang("AutoRestoreActivated", userIdString) : Lang("AutoRestoreDeactivated", userIdString));
                    return;

                case "testautorestore":
                    _isNewSave = true;
                    SendReply(arg, $"isNewSave: {_isNewSave}");
                    CheckProtocol();
                    return;

                case "delsaved":
                    if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        if (!RemoveSavedBlueprints(target))
                        {
                            SendReply(arg, Lang("NoSavedDataFound", userIdString, target.displayName));
                        }
                        return;
                    }
                    else
                    {
                        SendReply(arg, Lang("InvalidArgs", userIdString));
                    }
                    return;

                case "listsaved":
                    if (arg.Args.Length == 1)
                    {
                        StringBuilder sb = new StringBuilder(Lang("SavedDataPlayerList", userIdString));
                        foreach (ulong userId in _cachedPlayerInfo.Keys)
                        {
                            BasePlayer target = RustCore.FindPlayerById(userId);
                            sb.Append($"{userId} : {target?.displayName} \n");
                        }

                        SendReply(arg, sb.ToString());
                    }
                    if (arg.Args.Length == 2)
                    {
                        BasePlayer target = RustCore.FindPlayer(arg.Args[1]);
                        if (target == null)
                        {
                            SendReply(arg, Lang("NoPlayerFoundWith", userIdString, arg.Args[1]));
                            return;
                        }

                        if (!_cachedPlayerInfo.ContainsKey(target.userID))
                        {
                            SendReply(arg, Lang("NoSavedDataFor", userIdString, target.displayName));
                            return;
                        }

                        HashSet <String> blueprints = _cachedPlayerInfo[target.userID].UnlockedBlueprints;
                        if (blueprints == null)
                        {
                            return;
                        }
                        SendReply(arg, Lang("BlueprintsSaved", userIdString, target.displayName) + String.Join(", ", blueprints));
                    }

                    return;

                case "default":
                case "help":
                    StringBuilder _sb = new StringBuilder(Lang("AvailableCommands", userIdString));
                    _sb.Append(Lang("HelpConsoleSave", userIdString));
                    _sb.Append(Lang("HelpConsoleRestore", userIdString));
                    _sb.Append(Lang("HelpConsoleDelSaved", userIdString));
                    _sb.Append(Lang("HelpConsoleUnlocked", userIdString));
                    _sb.Append(Lang("HelpConsoleUnlockAll", userIdString));
                    _sb.Append(Lang("HelpConsoleReset", userIdString));
                    _sb.Append(Lang("HelpConsoleList", userIdString));
                    _sb.Append(Lang("HelpListPlayerSaved", userIdString));
                    _sb.Append(Lang("HelpConsoleToggle", userIdString));

                    SendReply(arg,
                              arg.Connection == null ? Regex.Replace(_sb.ToString(), "<[^>]*>", "") : _sb.ToString());
                    return;
                }
            }
        }
Пример #16
0
 public BasePlayer FindPlayerByIdString(string id) => RustCore.FindPlayerByIdString(id);
Пример #17
0
 public BasePlayer FindPlayerById(ulong id) => RustCore.FindPlayerById(id);
Пример #18
0
 public BasePlayer FindPlayerByName(string name) => RustCore.FindPlayerByName(name);
Пример #19
0
 public BasePlayer FindPlayer(string nameOrIdOrIp) => RustCore.FindPlayer(nameOrIdOrIp);