Пример #1
0
        public static bool ParseModFile(string modFileData)
        {
            if (SystemsContainer.Get <ModSystem>().ModControl == ModControlMode.Disabled)
            {
                return(true);
            }

            SystemsContainer.Get <ModSystem>().LastModFileData = modFileData; //Save mod file so we can recheck it.

            StringBuilder = new StringBuilder();
            ParseRequired.Clear();
            ParseOptional.Clear();
            WhiteList.Clear();
            BlackList.Clear();
            PartsList.Clear();

            SaveCurrentModConfigurationFile();

            ReadModConfigurationFile(modFileData);

            CheckFiles();

            if (!ModCheckOk)
            {
                SystemsContainer.Get <ModSystem>().FailText = StringBuilder.ToString();
                WindowsContainer.Get <ModWindow>().Display  = true;
                return(false);
            }

            SystemsContainer.Get <ModSystem>().AllowedParts = PartsList;
            LunaLog.Log("[LMP]: Mod check passed!");
            return(true);
        }
Пример #2
0
        public static bool ParseModFile(string modFileData)
        {
            if (ModSystem.Singleton.ModControl == ModControlMode.DISABLED)
            {
                return(true);
            }

            ModSystem.Singleton.LastModFileData = modFileData; //Save mod file so we can recheck it.

            StringBuilder = new StringBuilder();
            ParseRequired.Clear();
            ParseOptional.Clear();
            WhiteList.Clear();
            BlackList.Clear();
            PartsList.Clear();

            SaveCurrentModConfigurationFile();

            ReadModConfigurationFile(modFileData);

            CheckFiles();

            if (!ModCheckOk)
            {
                ModSystem.Singleton.FailText = StringBuilder.ToString();
                ModWindow.Singleton.Display  = true;
                return(false);
            }

            ModSystem.Singleton.AllowedParts = PartsList;
            Debug.Log("[LMP]: Mod check passed!");
            return(true);
        }
Пример #3
0
        /// <inheritdoc />
        public void Execute(ICommandSender commandSender, string[] args)
        {
            if (args.Length < 2)
            {
                SendUsage(commandSender);
                return;
            }

            var action = args[1].ToLower();

            if (action == "on")
            {
                if (_whiteList.IsEnabled)
                {
                    commandSender.SendMessage("Whitelist was already enabled");
                    return;
                }

                _whiteList.IsEnabled = true;
                commandSender.SendMessage("Whitelist has been enabled");
            }
            else if (action == "off")
            {
                if (!_whiteList.IsEnabled)
                {
                    commandSender.SendMessage("Whitelist was already disabled");
                    return;
                }

                _whiteList.IsEnabled = false;
                commandSender.SendMessage("Whitelist has been disabled");
            }
            else if (action == "add" || action == "remove")
            {
                if (args.Length < 3)
                {
                    commandSender.SendMessage($"Invalid usage: {Trigger} <add|remove> <auth key|username>");
                    return;
                }

                // Store whether the action is to add or whether to remove
                var addAction = action == "add";

                var identifier = args[2];
                if (AuthUtil.IsValidAuthKey(identifier))
                {
                    if (addAction)
                    {
                        _whiteList.Add(identifier);
                        commandSender.SendMessage("Auth key has been added to whitelist");
                    }
                    else
                    {
                        _whiteList.Remove(identifier);
                        commandSender.SendMessage("Auth key has been removed from whitelist");
                    }
                }
                else
                {
                    // Since the given argument was not a valid auth key, we try player names instead
                    if (!CommandUtil.TryGetPlayerByName(_serverManager.Players, identifier, out var player))
                    {
                        if (addAction)
                        {
                            _whiteList.AddPreList(identifier);
                            commandSender.SendMessage(
                                $"Added player name '{identifier}' to pre-list. The next player that logs in with that name will be whitelisted.");
                        }
                        else
                        {
                            _whiteList.RemovePreList(identifier);
                            commandSender.SendMessage(
                                $"Removed player name '{identifier}' from pre-list. The next player that logs in with that name will no longer be whitelisted.");
                        }

                        return;
                    }

                    var playerData = (ServerPlayerData)player;

                    if (addAction)
                    {
                        _whiteList.Add(playerData.AuthKey);
                        commandSender.SendMessage(
                            $"Auth key of player '{player.Username}' has been added to whitelist");
                    }
                    else
                    {
                        _whiteList.Remove(playerData.AuthKey);
                        commandSender.SendMessage(
                            $"Auth key of player '{player.Username}' has been removed from whitelist");
                    }
                }
            }
            else if (action == "prelist")
            {
                commandSender.SendMessage($"Pre-listed player names: {_whiteList.GetPreListed()}");
            }
            else if (action == "clear")
            {
                if (args.Length < 3)
                {
                    _whiteList.Clear();
                    commandSender.SendMessage("Cleared whitelist");
                    return;
                }

                if (args[2] == "prelist")
                {
                    _whiteList.ClearPreList();
                    commandSender.SendMessage("Clear pre-list of whitelist");
                }
                else
                {
                    commandSender.SendMessage($"Invalid usage: '{Trigger} clear prelist' to clear pre-list");
                }
            }
            else
            {
                SendUsage(commandSender);
            }
        }