static public HFTArgParser GetInstance() { if (s_parser == null) { s_parser = new HFTArgParser(); } return(s_parser); }
public void Awake() { HFTArgParser p = new HFTArgParser(); bool found = false; found |= p.Contains("show-instructions"); found |= p.TryGet <string>("instructions", ref instructions); found |= p.TryGetBool("bottom", ref bottom); if (found) { show = true; } }
public HFTArgsBase(string prefix) { HFTLog log = new HFTLog("HFTArgs"); HFTArgChecker checker = new HFTArgChecker(log, prefix); HFTArgParser p = HFTArgParser.GetInstance(); System.Reflection.FieldInfo[] fields = this.GetType().GetFields(); foreach (System.Reflection.FieldInfo info in fields) { object field = System.Activator.CreateInstance(info.FieldType); string dashName = checker.GetHFTDashName(info.Name); checker.AddArg(dashName); info.FieldType.GetMethod("Init").Invoke(field, new object[] { dashName, p }); info.SetValue(this, field); } checker.CheckArgs(); }
public static int Main(string[] args) { HFTRuntimeOptions m_options; HFTArgParser p = HFTArgParser.GetInstance(); string argStr = ""; if (p.TryGet <string> ("hft-args", ref argStr)) { Deserializer d = new Deserializer(); m_options = d.Deserialize <HFTRuntimeOptions>(argStr); } else { m_options = new HFTRuntimeOptions(); } if (!HFTArgsToFields.Apply("hft", m_options)) { System.Console.WriteLine("bad args!"); return(1); } HFTLog.debug = m_options.debug; //using (System.IO.StreamWriter writer = new System.IO.StreamWriter(System.IO.File.Open("/Users/gregg/temp/hft-server.log", System.IO.FileMode.Create))) //{ // writer.WriteLine(System.DateTime.Now.ToString()); // writer.WriteLine(Serializer.Serialize(m_options, false, true)); //} List <string> addresses = new List <string>(); addresses.Add("http://[::0]:" + m_options.serverPort); // addresses.Add("http://0.0.0.0:18679"); if (m_options.installationMode) { addresses.Add("http://[::0]:80"); // addresses.Add("http://0.0.0.0:80"); } // Do I want this option ever? // Good: Need from editor to test instalation mode in editor // Bad: If game is hacked and serve any folder. But if game // is hack you can probably own machine anyway. if (!String.IsNullOrEmpty(m_options.dataPath)) { HFTWebFileDB.GetInstance().DataPath = m_options.dataPath; } string ipv4Address = String.IsNullOrEmpty(m_options.ipv4DnsAddress) ? HFTIpUtils.GetLocalIPv4Address() : m_options.ipv4DnsAddress; string ipv6Address = String.IsNullOrEmpty(m_options.ipv6DnsAddress) ? HFTIpUtils.GetLocalIPv6Address() : m_options.ipv6DnsAddress; HFTWebServer webServer = new HFTWebServer(m_options, addresses.ToArray()); webServer.Start(); if (m_options.dns || m_options.installationMode) { HFTDnsRunner dnsRunner = new HFTDnsRunner(); dnsRunner.Start(ipv4Address, ipv6Address, 53); } // There's no HFTSite because were in installationMode which means there's no internet System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); return(0); }
public void Init(string name, HFTArgParser p) { isSet_ = p.TryGetBool(name, ref value_); }
public static bool Apply(string prefix, object obj) { HFTLog log = new HFTLog("HFTArgsDirect"); HFTArgChecker checker = new HFTArgChecker(log, prefix); HFTArgParser p = HFTArgParser.GetInstance(); System.Reflection.FieldInfo[] fields = obj.GetType().GetFields(); foreach (System.Reflection.FieldInfo info in fields) { //object field = System.Activator.CreateInstance(info.FieldType); object value = null; System.Type fieldType = info.FieldType; string dashName = checker.GetHFTDashName(info.Name); checker.AddArg(dashName); // Should do this with reflection but ... if (fieldType == typeof(string)) { string strValue = ""; if (p.TryGet <string>(dashName, ref strValue)) { value = strValue; } } else if (fieldType == typeof(int)) { int intValue = 0; if (p.TryGet <int>(dashName, ref intValue)) { value = intValue; } } else if (fieldType == typeof(bool)) { bool boolValue = false; if (p.TryGetBool(dashName, ref boolValue)) { value = boolValue; } } else if (fieldType == typeof(float)) { float floatValue = 0; if (p.TryGet <float>(dashName, ref floatValue)) { value = floatValue; } } else { throw new System.InvalidOperationException("no support for type: " + fieldType.Name); } if (value != null) { info.SetValue(obj, value); } } return(checker.CheckArgs()); }