예제 #1
0
        private static void AICSet(ConCommandArgs args, bool isTemporary)
        {
            var targetCmd = isTemporary ? "aic_settemp" : "aic_set";

            var errorPre  = "ConCmd " + targetCmd + " failed (";
            var usagePost = ").\nUsage: " + targetCmd + " \"path1\" \"optional path2\" \"optional path3\" newValue. Path matches mod name, config category, and config name, in that order.";

            if (args.Count < 2)
            {
                NetConfigOrchestrator.SendConMsg(args.sender, errorPre + "not enough arguments" + usagePost, LogLevel.Warning);
                return;
            }
            if (args.Count > 4)
            {
                NetConfigOrchestrator.SendConMsg(args.sender, errorPre + "too many arguments" + usagePost, LogLevel.Warning);
                return;
            }

            var(matches, errmsg) = GetAICFromPath(args[0], (args.Count > 2) ? args[1] : null, (args.Count > 3) ? args[2] : null);

            if (errmsg != null)
            {
                errmsg += ").";
                if (matches != null)
                {
                    errmsg += "\nThe following config settings have a matching path: " + String.Join(", ", matches.Select(x => "\"" + x.readablePath + "\""));
                }
                NetConfigOrchestrator.SendConMsg(args.sender, errorPre + errmsg, LogLevel.Warning);
                return;
            }

            var convStr = args[args.Count - 1];

            object convObj;

            try {
                convObj = TomlTypeConverter.ConvertToValue(convStr, matches[0].propType);
            } catch {
                NetConfigOrchestrator.SendConMsg(args.sender, errorPre + "(can't convert argument 2 'newValue' to the target config type, " + matches[0].propType.Name + ").", LogLevel.Warning);
                return;
            }

            if (!isTemporary)
            {
                matches[0].configEntry.BoxedValue = convObj;
                if (!matches[0].configEntry.ConfigFile.SaveOnConfigSet)
                {
                    matches[0].configEntry.ConfigFile.Save();
                }
            }
            else
            {
                matches[0].OverrideProperty(convObj);
            }
            if (args.sender && !args.sender.hasAuthority)
            {
                TILER2Plugin._logger.LogMessage("ConCmd " + targetCmd + " from client " + args.sender.userName + " passed. Changed config setting " + matches[0].readablePath + " to " + convObj.ToString());
            }
            NetConfigOrchestrator.SendConMsg(args.sender, "ConCmd " + targetCmd + " successfully updated config entry!");
        }
예제 #2
0
        public static void ConCmdAICSetTemp(ConCommandArgs args)
        {
            EnsureOrchestrator();

#if !DEBUG
            if ((!args.sender.hasAuthority) && !allowClientAICSet.value)
            {
                TILER2Plugin._logger.LogWarning("Client " + args.sender.userName + " tried to use ConCmd aic_settemp, but ConVar aic_allowclientset is set to false. DO NOT change this convar to true, unless you trust everyone who is in or may later join the server; doing so will allow them to temporarily change some config settings.");
                NetConfigOrchestrator.SendConMsg(args.sender, "ConCmd aic_settemp cannot be used on this server by anyone other than the host.", LogLevel.Warning);
                return;
            }
#endif

            AICSet(args, true);
        }