Exemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override async void LoadContent()
        {
            base.LoadContent();

            IO      = new IOComponent(this);
            Plugins = new PluginComponent(this);
            Network = new NetworkManager(this);

            await IO.Init();

            await IO.LoadConfig();

            await Network.Init();

            Content       = new ContentManager();
            TextureLoader = new TextureLoader(Graphics.GraphicsDevice);
            Content.LoadTextures(Path.Combine(IO.Directories["Content"], "Textures"), this);

            if (IO.Config.Client.Resolution.X == 0 && IO.Config.Client.Resolution.Y == 0)
            {
                Graphics.PreferredBackBufferWidth  = (int)(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width * .9);
                Graphics.PreferredBackBufferHeight =
                    (int)(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height * .8);
                Graphics.ApplyChanges();
                base.Window.Position =
                    new Point(
                        (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - Graphics.PreferredBackBufferWidth) /
                        2,
                        (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - Graphics.PreferredBackBufferHeight) /
                        2);
            }
            else
            {
                Graphics.PreferredBackBufferWidth  = IO.Config.Client.Resolution.X;
                Graphics.PreferredBackBufferHeight = IO.Config.Client.Resolution.Y;
                Graphics.ApplyChanges();
            }

            // Initialize MonoForce after loading skins.
            UI.Initialize();
            SpriteBatch = UI.Renderer.SpriteBatch; // Set the spritebatch to the Neoforce managed one


            // Create the main window for all content to be added to.
            Window = new MainWindow(UI, this);
            Window.Init();
            UI.Add(Window);
            Window.SendToBack();

            // Unlike the server, the clientside plugins must be loaded last.
            await Plugins.Init();

            // Now that all the textures have been loaded, set the block textures
            foreach (var block in BlockType.Blocks.Where(x => x.IsRenderable))
            {
                var str = "blocks." + (block.Category != null ? block.Category + "." : string.Empty) + block.Name;
                block.Texture = Content[str];
            }
        }
Exemplo n.º 2
0
        internal async Task Start()
        {
            Logger.Server = this;
            Events        = new EventManager();
            Players       = new List <Player>();
            Levels        = new List <Level>();

            // Setup server
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Clear();
            start = DateTime.Now;
            input = string.Empty;
            clear = new string(' ', Console.WindowWidth);
            var stopwatch = Stopwatch.StartNew();

            Logger.WriteLine($"{Constants.Strings.ServerTitle}");
            Logger.WriteLine($"Server is starting now, on {DateTime.Now.ToString("U", new CultureInfo("en-US"))}");

            // Initialize Properties
            Commands = CommandParser.CreateNew().UsePrefix(string.Empty).OnError(OnParseError);
            RegisterCommands();

            // Initialize Components
            IO       = new IOComponent(this);
            Plugins  = new PluginComponent(this);
            Database = new DatabaseComponent(this);
            Net      = new NetworkComponent(this);

            await IO.Init();

            await Plugins.Init();

            await Database.Init();

            await Net.Init();

            // Create save timer
            saveTimer          = new Timer(IO.Config.Server.AutoSaveTime * 1000 * 60);
            saveTimer.Elapsed += async(sender, args) => await SaveAll();

            saveTimer.Start();

            stopwatch.Stop();
            Logger.WriteBreak();
            Logger.WriteLine("Ready. ({0}s) Type /help for commands.", Math.Round(stopwatch.Elapsed.TotalSeconds, 2));
            Logger.WriteBreak();

            WriteHeader();

            while (true) // Parse commands now that messaging has been handed off to another thread
            {
                input = string.Empty;
                WriteCommandCursor();

                // Read input and parse commands
                while (true)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Backspace)
                    {
                        if (input.Length - 1 >= 0)
                        {
                            input = input.Substring(0, input.Length - 1);
                            Console.CursorLeft = 3 + input.Length - 1;
                            Console.Write(' ');
                            Console.CursorLeft = 3 + input.Length - 1;
                        }
                        continue;
                    }
                    if (key.Key == ConsoleKey.Enter)
                    {
                        Console.WriteLine("");
                        break;
                    }
                    input += key.KeyChar;
                    Console.Write(key.KeyChar);
                }

                Commands.Parse(input.Trim());

                WriteHeader();
            }
            // ReSharper disable once FunctionNeverReturns
        }