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!"); }
public override void SetupConfig() { base.SetupConfig(); var netOrchPrefabPrefab = new GameObject("TILER2NetConfigOrchestratorPrefabPrefab"); netOrchPrefabPrefab.AddComponent <NetworkIdentity>(); NetConfig.netOrchPrefab = netOrchPrefabPrefab.InstantiateClone("TILER2NetConfigOrchestratorPrefab", true); NetConfig.netOrchPrefab.AddComponent <NetConfigOrchestrator>(); On.RoR2.Networking.GameNetworkManager.OnServerAddPlayerInternal += (orig, self, conn, pcid, extraMsg) => { orig(self, conn, pcid, extraMsg); if (!enableCheck || Util.ConnectionIsLocal(conn) || NetConfigOrchestrator.checkedConnections.Contains(conn)) { return; } NetConfigOrchestrator.checkedConnections.Add(conn); NetConfig.EnsureOrchestrator(); NetConfigOrchestrator.AICSyncAllToOne(conn); }; /*On.RoR2.Run.EndStage += (orig, self) => { * orig(self); * AutoItemConfig.CleanupDirty(false); * };*/ LanguageAPI.Add("TILER2_KICKREASON_NCCRITMISMATCH", "TILER2 NetConfig: unable to resolve some config mismatches.\nSome settings must be synced, but cannot be changed while the game is running. Please check your console window for details."); LanguageAPI.Add("TILER2_KICKREASON_NCTIMEOUT", "TILER2 NetConfig: mismatch check timed out.\nThis may be caused by a mod version mismatch, a network outage, or an error while applying changes.\nIf seeking support for this issue, please make sure to have FULL CONSOLE LOGS from BOTH CLIENT AND SERVER ready to post."); LanguageAPI.Add("TILER2_KICKREASON_NCMISSINGENTRY", "TILER2 NetConfig: mismatch check found missing config entries.\nYou are likely using a different version of a mod than the server."); LanguageAPI.Add("TILER2_DISABLED_ARTIFACT", "This artifact is <color=#ff7777>force-disabled</color>; it will have no effect ingame."); }
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); }
/// <summary>Internal handler for ConfigEntryChanged event.</summary> internal void OnConfigChanged(AutoConfigUpdateActionEventArgs e) { ConfigEntryChanged?.Invoke(this, e); TILER2Plugin._logger.LogDebug(e.target.modName + "/" + e.target.configEntry.Definition.Section + "/" + e.target.configEntry.Definition.Key + ": " + e.oldValue.ToString() + " > " + e.newValue.ToString()); if (!(Run.instance != null && Run.instance.isActiveAndEnabled)) { return; } if ((e.flags & AutoConfigUpdateActionTypes.InvalidateStats) == AutoConfigUpdateActionTypes.InvalidateStats) { AutoConfigModule.globalStatsDirty = true; } if ((e.flags & AutoConfigUpdateActionTypes.InvalidateDropTable) == AutoConfigUpdateActionTypes.InvalidateDropTable) { AutoConfigModule.globalDropsDirty = true; } if (!e.silent && (e.flags & AutoConfigUpdateActionTypes.AnnounceToRun) == AutoConfigUpdateActionTypes.AnnounceToRun && NetworkServer.active) { NetConfigOrchestrator.ServerSendGlobalChatMsg("The setting <color=#ffffaa>" + e.target.modName + "/" + e.target.configEntry.Definition.Section + "/" + e.target.configEntry.Definition.Key + "</color> has been changed from <color=#ffaaaa>" + e.oldValue.ToString() + "</color> to <color=#aaffaa>" + e.newValue.ToString() + "</color>."); } }
private void Awake() { instance = this; }