Beispiel #1
0
        private static int Main(string[] args)
        {
            if (!File.Exists("config.json"))
            {
                File.WriteAllText("config.json", JsonConvert.SerializeObject(new Config
                {
                    TwitterInfo = new TwitterInfo()
                },
                                                                             Formatting.Indented));
                Log.Error("config.json not found, generated file.");
                return(1);
            }
            Config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json"));
            Twitter.TwitterInfo = Config.TwitterInfo;
            Twitter.Login();
            _lastUpdate = DateTime.UtcNow.AddSeconds(-601);
            FlatFile.Initialize();
            MobileExport.Initialize();

            ParserDictionary.Add(Platform.Pc, new WorldStateParser(Platform.Pc));
            ParserDictionary.Add(Platform.PS4, new WorldStateParser(Platform.PS4));
            ParserDictionary.Add(Platform.Xbox, new WorldStateParser(Platform.Xbox));
            //ParserDictionary.Add(Platform.PcChina, new WorldStateParser(Platform.PcChina));

            //FlatFile.SerializeAlerts(Platform.Pc);
            //FlatFile.SerializeAlerts(Platform.PS4);
            //FlatFile.SerializeInvasion(Platform.Pc);
            //FlatFile.SerializeInvasion(Platform.PS4);
            (new Thread(Update)).Start(args.Length == 0);
            while (true)
            {
                try
                {
                    var word = Console.ReadLine();
                    if (word == null)
                    {
                        continue;
                    }
                    var parts   = word.Split(new[] { ' ' }, 2);
                    var command = parts[0];
                    switch (command)
                    {
                    case "reload":
                        Config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json"));
                        break;

                    case "names":
                    {
                        /*FlatFile.PlanetNames =
                         *  JsonConvert.DeserializeObject<Dictionary<string, string>>(
                         *      File.ReadAllText("planetnames.json"));
                         * Log.Info("Loaded " + FlatFile.PlanetNames.Count + " planet names from file.");*/
                        FlatFile.PlanetRegionNames =
                            JsonConvert.DeserializeObject <Dictionary <string, string> >(
                                File.ReadAllText("planetnamesregion.json"));
                        Log.Info("Loaded " + FlatFile.PlanetRegionNames.Count +
                                 " planet names with region from file.");
                        FlatFile.ItemNames =
                            JsonConvert.DeserializeObject <Dictionary <string, string> >(
                                File.ReadAllText("names.json"));
                        Log.Info("Loaded " + FlatFile.ItemNames.Count + " item names from file.");
                        FlatFile.LanguageStrings =
                            JsonConvert.DeserializeObject <Dictionary <string, string> >(
                                File.ReadAllText("strings.json"));
                        Log.Info("Loaded " + FlatFile.LanguageStrings.Count + " language strings from file.");
                        break;
                    }

                    case "currenttick":
                    {
                        Log.InfoFormat("Current tick: {0}", _updateCount);
                        break;
                    }

                    case "settick":
                    {
                        long newcount = 0;
                        if (long.TryParse(parts[1], out newcount))
                        {
                            _updateCount = newcount;
                        }
                        else
                        {
                            Log.Warn("Could not parse the param into an int.");
                        }
                        break;
                    }

                    case "exit":
                    case "quit":
                        Log.InfoFormat("Current count: {0}", _updateCount);
                        _exiting = true;
                        _scheduler.Shutdown();
                        return(0);

                    case "forcequit":
                    case "forceexit":
                        Log.InfoFormat("Current count: {0}", _updateCount);
                        Environment.Exit(0);
                        return(0);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Exception thrown when executing command.");
                    Log.Error(e.ToString());
                }
            }
        }