|
1 | | -extern alias References; |
| 1 | +extern alias References; |
2 | 2 |
|
3 | 3 | using References::Newtonsoft.Json; |
4 | 4 | using System.Collections; |
5 | 5 | using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Net; |
6 | 8 |
|
7 | 9 | namespace Oxide.Core.Configuration |
8 | 10 | { |
@@ -145,9 +147,93 @@ public class OxideRcon |
145 | 147 | /// </summary> |
146 | 148 | public OxideConfig(string filename) : base(filename) |
147 | 149 | { |
148 | | - Options = new OxideOptions { Modded = true, PluginWatchers = true, DefaultGroups = new DefaultGroups { Administrators = "admin", Players = "default" }, WebRequestIP = "0.0.0.0" }; |
149 | | - Console = new OxideConsole { Enabled = true, MinimalistMode = true, ShowStatusBar = true }; |
150 | | - Rcon = new OxideRcon { Enabled = false, ChatPrefix = "[Server Console]", Port = 25580, Password = string.Empty }; |
| 150 | + InitializeDefaultValues(); |
| 151 | + } |
| 152 | + |
| 153 | + public override void Load(string filename = null) |
| 154 | + { |
| 155 | + base.Load(filename); |
| 156 | + |
| 157 | + if (InitializeDefaultValues()) |
| 158 | + { |
| 159 | + Save(); |
| 160 | + } |
| 161 | + |
| 162 | + if (Compiler.PreprocessorDirectives.Count > 0) |
| 163 | + { |
| 164 | + Compiler.PreprocessorDirectives = Compiler.PreprocessorDirectives |
| 165 | + .Select(s => s.ToUpperInvariant().Replace(" ", "_")) |
| 166 | + .Distinct() |
| 167 | + .ToList(); |
| 168 | + } |
| 169 | + |
| 170 | + Commands.ChatPrefix = Commands.ChatPrefix.Distinct().ToList(); |
| 171 | + } |
| 172 | + |
| 173 | + private bool InitializeDefaultValues() |
| 174 | + { |
| 175 | + bool changed = false; |
| 176 | + if (Options == null) |
| 177 | + { |
| 178 | + Options = new OxideOptions(); |
| 179 | + changed = true; |
| 180 | + } |
| 181 | + |
| 182 | + if (Commands == null) |
| 183 | + { |
| 184 | + Commands = new CommandOptions(); |
| 185 | + changed = true; |
| 186 | + } |
| 187 | + |
| 188 | + if (Commands.ChatPrefix == null) |
| 189 | + { |
| 190 | + Commands.ChatPrefix = new List<string>() { "/" }; |
| 191 | + changed = true; |
| 192 | + } |
| 193 | + |
| 194 | + if (Commands.ChatPrefix.Count == 0) |
| 195 | + { |
| 196 | + Commands.ChatPrefix.Add("/"); |
| 197 | + changed = true; |
| 198 | + } |
| 199 | + |
| 200 | + if (Options.DefaultGroups == null) |
| 201 | + { |
| 202 | + Options.DefaultGroups = new DefaultGroups(); |
| 203 | + changed = true; |
| 204 | + } |
| 205 | + |
| 206 | + if (string.IsNullOrEmpty(Options.WebRequestIP) || !IPAddress.TryParse(Options.WebRequestIP, out IPAddress address)) |
| 207 | + { |
| 208 | + Options.WebRequestIP = "0.0.0.0"; |
| 209 | + changed = true; |
| 210 | + } |
| 211 | + |
| 212 | + if (Console == null) |
| 213 | + { |
| 214 | + Console = new OxideConsole(); |
| 215 | + changed = true; |
| 216 | + } |
| 217 | + |
| 218 | + if (Rcon == null) |
| 219 | + { |
| 220 | + Rcon = new OxideRcon(); |
| 221 | + changed = true; |
| 222 | + } |
| 223 | + |
| 224 | + if (Compiler == null) |
| 225 | + { |
| 226 | + Compiler = new CompilerOptions(); |
| 227 | + changed = true; |
| 228 | + } |
| 229 | + |
| 230 | + if (Compiler.PreprocessorDirectives == null) |
| 231 | + { |
| 232 | + Compiler.PreprocessorDirectives = new List<string>(); |
| 233 | + changed = true; |
| 234 | + } |
| 235 | + |
| 236 | + return changed; |
151 | 237 | } |
152 | 238 | } |
153 | 239 | } |
0 commit comments