Exemple #1
0
        static void Initialize()
        {
            //
            var serializerSettings = new JsonSerializerSettings()
            {
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            // Load settings
            if (File.Exists(CONFIG_FILE))
            {
                // Populate existing object
                JsonConvert.PopulateObject(File.ReadAllText(CONFIG_FILE), Settings, serializerSettings);
            }
            else
            {
                // Add empty patch to default config output
                // This helps a user understand the format
                if (Settings.Patches.Count == 0)
                {
                    Settings.Patches.Add(new Patch());
                }

                // Add empty game mode to default config output
                if (Settings.Gamemodes.Count == 0)
                {
                    Settings.Gamemodes.Add(new Gamemode());
                }

                // Save defaults
                File.WriteAllText(CONFIG_FILE, JsonConvert.SerializeObject(Settings, Formatting.Indented));
            }

            // Load account db
            if (File.Exists(DB_FILE))
            {
                // Populate existing object
                try { JsonConvert.PopulateObject(File.ReadAllText(DB_FILE), Database, serializerSettings); }
                catch (Exception e) { Console.WriteLine(e); }
            }

            // Save db
            Database.Save();

            // Determine server ip
            if (!String.IsNullOrEmpty(Settings.ServerIpOverride))
            {
                SERVER_IP = IPAddress.Parse(Settings.ServerIpOverride);
            }
            else
            {
                SERVER_IP = IPAddress.Parse(GetIPAddress());
            }

            // Initialize default channel
            Channels.Add(new Channel()
            {
                Id            = Settings.DefaultChannelId,
                ApplicationId = Program.Settings.ApplicationId,
                MaxPlayers    = 256,
                Name          = "Default",
                Type          = ChannelType.Lobby
            });

            // Load tick time into sleep ms for main loop
            sleepMS = TickMS;
        }