/// <summary>
 /// Register this event
 /// </summary>
 /// <param name="method">This is the delegate that will get called when this event occurs</param>
 /// <param name="priority">The priority (imporantce) of this call</param>
 /// <param name="plugin">The plugin object that is registering the event</param>
 public static void Register(Server.OnConsoleCommand method, Priority priority, Plugin plugin)
 {
     if (Find(plugin) != null)
         throw new Exception("The user tried to register 2 of the same event!");
     events.Add(new OnConsoleCommandEvent(method, priority, plugin));
     Organize();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Register this event
 /// </summary>
 /// <param name="method">This is the delegate that will get called when this event occurs</param>
 /// <param name="priority">The priority (imporantce) of this call</param>
 /// <param name="plugin">The plugin object that is registering the event</param>
 /// <param name="bypass">Register more than one of the same event</param>
 public static void Register(Server.OnServerError method, Priority priority, Plugin plugin, bool bypass = false)
 {
     if (Find(plugin) != null)
                 if (!bypass)
                 throw new Exception("The user tried to register 2 of the same event!");
             events.Add(new OnServerErrorEvent(method, priority, plugin));
             Organize();
 }
Exemplo n.º 3
0
        static System.Timers.Timer messageTimer = new System.Timers.Timer(60000 * 5); //Every 5 mins

        #endregion Fields

        #region Constructors

        public Server()
        {
            ml = new MainLoop("server");
            Server.s = this;
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            startTime = DateTime.Now;
            if (Process.GetProcessesByName("MCForge").Length != 1)
            {
                foreach (Process pr in Process.GetProcessesByName("MCForge"))
                {
                    if (pr.MainModule.BaseAddress == Process.GetCurrentProcess().MainModule.BaseAddress)
                        if (pr.Id != Process.GetCurrentProcess().Id)
                            pr.Kill();
                }
            }
            PidgeonLogger.Init();
            AppDomain.CurrentDomain.UnhandledException += GlobalExHandler;
            Application.ThreadException += ThreadExHandler;
            bool skip = false;
            remake:
            try
            {
                if (!File.Exists("Viewmode.cfg") || skip)
                {
                    StreamWriter SW = new StreamWriter(File.Create("Viewmode.cfg"));
                    SW.WriteLine("#This file controls how the console window is shown to the server host");
                    SW.WriteLine("#cli: True or False (Determines whether a CLI interface is used) (Set True if on Mono)");
                    SW.WriteLine("#high-quality: True or false (Determines whether the GUI interface uses higher quality objects)");
                    SW.WriteLine();
                    SW.WriteLine("cli = false");
                    SW.WriteLine("high-quality = true");
                    SW.Flush();
                    SW.Close();
                    SW.Dispose();
                }

                if (File.ReadAllText("Viewmode.cfg") == "") { skip = true; goto remake; }

                string[] foundView = File.ReadAllLines("Viewmode.cfg");
                if (foundView[0][0] != '#') { skip = true; goto remake; }

                if (foundView[4].Split(' ')[2].ToLower() == "true")
                {
                    Server s = new Server();
                    s.OnLog += WriteToConsole;
                    s.OnCommand += WriteToConsole;
                    s.OnSystem += WriteToConsole;
                    s.Start();

                    Console.Title = Server.name + " - MCForge " + Server.Version;
                    usingConsole = true;
                    handleComm();

                    //Application.Run();
                }
                else
                {

                    IntPtr hConsole = GetConsoleWindow();
                    if (IntPtr.Zero != hConsole)
                    {
                        ShowWindow(hConsole, 0);
                    }
                    UpdateCheck(true);
                    if (foundView[5].Split(' ')[2].ToLower() == "true")
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                    }

                    updateTimer.Elapsed += delegate { UpdateCheck(); }; updateTimer.Start();
                    Application.Run(new MCForge.Gui.Window());
                }
                WriteToConsole("Completed in " + (DateTime.Now - startTime).Milliseconds + "ms");
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Exemplo n.º 5
0
        private void Window_Load(object sender, EventArgs e)
        {
            btnProperties.Enabled = false;
            thisWindow = this;
            MaximizeBox = false;
            this.Text = "Starting MCForge...";
            //this.Icon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MCLawl.Lawl.ico"));

            this.Show();
            this.BringToFront();
            WindowState = FormWindowState.Normal;
            new Thread(() => {
            s = new Server();
            s.OnLog += WriteLine;
            s.OnCommand += newCommand;
            s.OnError += newError;
            s.OnSystem += newSystem;
            s.OnAdmin += WriteAdmin;
            s.OnOp += WriteOp;

            /*foreach (TabPage tP in tabControl1.TabPages)
                tabControl1.SelectTab(tP);
            tabControl1.SelectTab(tabControl1.TabPages[0]);*/

            s.HeartBeatFail += HeartBeatFail;
            s.OnURLChange += UpdateUrl;
            s.OnPlayerListChange += UpdateClientList;
            s.OnSettingsUpdate += SettingsUpdate;
            s.Start();
            //btnProperties.Enabled = true;
            if (btnProperties.InvokeRequired)
            {
                VoidDelegate d = btnPropertiesenable;
                Invoke(d);
            }
            else
            {
                btnProperties.Enabled = true;
            }
            }).Start();
            notifyIcon1.Text = ("MCForge Server: " + Server.name).Truncate(64);

            this.notifyIcon1.ContextMenuStrip = this.iconContext;
            this.notifyIcon1.Icon = this.Icon;
            this.notifyIcon1.Visible = true;
            this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);

            //if (File.Exists(Logger.ErrorLogPath))
            //txtErrors.Lines = File.ReadAllLines(Logger.ErrorLogPath);
            if (File.Exists("Changelog.txt"))
            {
                txtChangelog.Text = "Changelog for " + Server.Version + ":";
                foreach (string line in File.ReadAllLines(("Changelog.txt")))
                {
                    txtChangelog.AppendText("\r\n           " + line);
                }
            }

            // Bind player list
            dgvPlayers.DataSource = pc;
            dgvPlayers.Font = new Font("Calibri", 8.25f);

            dgvMaps.DataSource = new LevelCollection(new LevelListView());
            dgvMaps.Font = new Font("Calibri", 8.25f);

            dgvMapsTab.DataSource = new LevelCollection(new LevelListViewForTab());
            dgvMapsTab.Font = new Font("Calibri", 8.25f);

            /*using (System.Timers.Timer UpdateListTimer = new System.Timers.Timer(10000))
            {
                UpdateListTimer.Elapsed += delegate
                {
                    UpdateClientList(Player.players);
                    UpdateMapList("'");
                    Server.s.Log("Lists updated!");
                }; UpdateListTimer.Start();
            }*/

            UpdateListTimer.Elapsed += delegate
            {
                try {
                    UpdateClientList(Player.players);
                    UpdateMapList("'");
                } catch {} // needed for slower computers
                //Server.s.Log("Lists updated!");
            }; UpdateListTimer.Start();
        }
 internal OnConsoleCommandEvent(Server.OnConsoleCommand method, Priority priority, Plugin plugin)
 {
     this.plugin = plugin; this.priority = priority; this.method = method;
 }
Exemplo n.º 7
0
 internal OnServerErrorEvent(Server.OnServerError method, Priority priority, Plugin plugin)
 {
     this.plugin = plugin; this.priority = priority; this.method = method;
 }
Exemplo n.º 8
0
        private void Window_Load(object sender, EventArgs e)
        {
            thisWindow = this;
            MaximizeBox = false;
            this.Text = "<server name here>";
            //this.Icon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MCLawl.Lawl.ico"));

            this.Show();
            this.BringToFront();
            WindowState = FormWindowState.Normal;

            s = new Server();
            s.OnLog += WriteLine;
            s.OnCommand += newCommand;
            s.OnError += newError;
            s.OnSystem += newSystem;

            foreach (TabPage tP in tabControl1.TabPages)
                tabControl1.SelectTab(tP);
            tabControl1.SelectTab(tabControl1.TabPages[0]);

            s.HeartBeatFail += HeartBeatFail;
            s.OnURLChange += UpdateUrl;
            s.OnPlayerListChange += UpdateClientList;
            s.OnSettingsUpdate += SettingsUpdate;
            s.Start();
            notifyIcon1.Text = ("MCForge Server: " + Server.name).Truncate(64);

            this.notifyIcon1.ContextMenuStrip = this.iconContext;
            this.notifyIcon1.Icon = this.Icon;
            this.notifyIcon1.Visible = true;
            this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);

            //if (File.Exists(Logger.ErrorLogPath))
                //txtErrors.Lines = File.ReadAllLines(Logger.ErrorLogPath);
            if (File.Exists("Changelog.txt"))
            {
                txtChangelog.Text = "Changelog for " + Server.Version + ":";
                foreach (string line in File.ReadAllLines(("Changelog.txt")))
                {
                    txtChangelog.AppendText("\r\n           " + line);
                }
            }

            // Bind player list
            dgvPlayers.DataSource = pc;
            dgvPlayers.Font = new Font("Calibri", 8.25f);

            dgvMaps.DataSource = new LevelCollection(new LevelListView());
            dgvMaps.Font = new Font("Calibri", 8.25f);

            System.Timers.Timer UpdateListTimer = new System.Timers.Timer(10000);
            UpdateListTimer.Elapsed += delegate
            {
                UpdateClientList(Player.players);
                UpdateMapList("'");
            }; UpdateListTimer.Start();
        }
Exemplo n.º 9
0
        public bool GenerateMap(Level Lvl, string type, int seed = 0, bool useSeed = false)
        {
            DateTime startTime = DateTime.Now;

            Server.s.Log("Attempting map gen");
            if (Inuse)
            {
                Server.s.Log("Generator in use"); return(false);
            }
            Random rand = useSeed ? new System.Random(seed) : new System.Random();

            try
            {
                Inuse   = true;
                terrain = new float[Lvl.width * Lvl.height];  //hmm
                overlay = new float[Lvl.width * Lvl.height];

                if (!type.Equals("ocean"))
                {
                    overlay2 = new float[Lvl.width * Lvl.height];
                }

                //float dispAux, pd;
                ushort WaterLevel = (ushort)(Lvl.depth / 2 + 2);
                ushort LavaLevel  = 5;

                if (type.Equals("ocean"))
                {
                    WaterLevel = (ushort)(Lvl.depth * 0.85f);
                }
                //Generate the level
                GenerateFault(terrain, Lvl, type, rand);

                //APPLY FILTER to terrain
                FilterAverage(Lvl);

                //CREATE OVERLAY
                //GenerateFault(overlay, Lvl, "overlay", rand);
                Server.s.Log("Creating overlay");
                GeneratePerlinNoise(overlay, Lvl, "", rand);

                if (!type.Equals("ocean") && type != "desert")
                {
                    Server.s.Log("Planning trees");
                    GeneratePerlinNoise(overlay2, Lvl, "", rand);
                }

                Server.s.Log("Converting height map");
                Server.s.Log("And applying overlays");
                float RangeLow  = 0.2f;
                float RangeHigh = 0.8f;
                float TreeDens  = 0.35f;
                short TreeDist  = 3;
                //changes the terrain range based on type, also tree threshold
                switch (type)
                {
                case "hell":
                    RangeLow  = .3f;
                    RangeHigh = 1.3f;
                    break;

                case "island":
                    RangeLow  = 0.4f;
                    RangeHigh = 0.75f;
                    break;

                case "forest":
                    RangeLow  = 0.45f;
                    RangeHigh = 0.8f;
                    TreeDens  = 0.7f;
                    TreeDist  = 2;
                    break;

                case "mountains":
                    RangeLow  = 0.3f;
                    RangeHigh = 0.9f;
                    TreeDist  = 4;
                    break;

                case "ocean":
                    RangeLow  = 0.1f;
                    RangeHigh = 0.6f;
                    break;

                case "desert":
                    RangeLow   = 0.5f;
                    RangeHigh  = 0.85f;
                    WaterLevel = 0;
                    TreeDist   = 24;
                    break;

                default:
                    break;
                }

                //loops though evey X/Z coordinate
                for (int bb = 0; bb < terrain.Length; bb++)
                {
                    ushort x = (ushort)(bb % Lvl.width);
                    ushort y = (ushort)(bb / Lvl.width);
                    ushort z;
                    if (type.Equals("island"))
                    {
                        z = Evaluate(Lvl, Range(terrain[bb], RangeLow - NegateEdge(x, y, Lvl), RangeHigh - NegateEdge(x, y, Lvl)));
                    }
                    else
                    {
                        z = Evaluate(Lvl, Range(terrain[bb], RangeLow, RangeHigh));
                    }
                    if (type != "hell")
                    {
                        #region nonLavaWorld
                        if (z > WaterLevel)
                        {
                            for (ushort zz = 0; z - zz >= 0; zz++)
                            {
                                if (type == "desert")
                                {
                                    Lvl.skipChange(x, (ushort)(z - zz), y, Block.sand);
                                }
                                else if (overlay[bb] < 0.72f)    //If not zoned for rocks or gravel
                                {
                                    if (type.Equals("island"))   //increase sand height for island
                                    {
                                        if (z > WaterLevel + 2)
                                        {
                                            if (zz == 0)
                                            {
                                                Lvl.skipChange(x, (ushort)(z - zz), y, Block.grass);
                                            }                                                                          //top layer
                                            else if (zz < 3)
                                            {
                                                Lvl.skipChange(x, (ushort)(z - zz), y, Block.dirt);
                                            }                                                                          //next few
                                            else
                                            {
                                                Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);
                                            }                                                                          //ten rock it
                                        }
                                        else
                                        {
                                            Lvl.skipChange(x, (ushort)(z - zz), y, Block.sand);                        //SAAAND extra for islands
                                        }
                                    }
                                    else if (type == "desert")
                                    {
                                        Lvl.skipChange(x, (ushort)(z - zz), y, Block.sand);
                                    }
                                    else
                                    {
                                        if (zz == 0)
                                        {
                                            Lvl.skipChange(x, (ushort)(z - zz), y, Block.grass);
                                        }
                                        else if (zz < 3)
                                        {
                                            Lvl.skipChange(x, (ushort)(z - zz), y, Block.dirt);
                                        }
                                        else
                                        {
                                            Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);
                                        }
                                    }
                                }
                                else
                                {
                                    Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);
                                }
                            }

                            if (overlay[bb] < 0.25f && type != "desert")    //Zoned for flowers
                            {
                                switch (rand.Next(12))
                                {
                                case 10:
                                    Lvl.skipChange(x, (ushort)(z + 1), y, Block.redflower);
                                    break;

                                case 11:
                                    Lvl.skipChange(x, (ushort)(z + 1), y, Block.yellowflower);
                                    break;

                                default:
                                    break;
                                }
                            }



                            if (!type.Equals("ocean"))
                            {
                                if (overlay[bb] < 0.65f && overlay2[bb] < TreeDens)
                                {
                                    if (Lvl.GetTile(x, (ushort)(z + 1), y) == Block.air)
                                    {
                                        if (Lvl.GetTile(x, z, y) == Block.grass || type == "desert")
                                        {
                                            if (rand.Next(13) == 0)
                                            {
                                                if (!TreeCheck(Lvl, x, z, y, TreeDist))
                                                {
                                                    if (type == "desert")
                                                    {
                                                        AddCactus(Lvl, x, (ushort)(z + 1), y, rand);
                                                    }
                                                    else
                                                    {
                                                        AddTree(Lvl, x, (ushort)(z + 1), y, rand);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else    //Must be on/under the water line then
                        {
                            for (ushort zz = 0; WaterLevel - zz >= 0; zz++)
                            {
                                if (WaterLevel - zz > z)
                                {
                                    Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.water);
                                }                                                                    //better fill the water aboce me
                                else if (WaterLevel - zz > z - 3)
                                {
                                    if (overlay[bb] < 0.75f)
                                    {
                                        Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.sand);   //sand top
                                    }
                                    else
                                    {
                                        Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.gravel);  //zoned for gravel
                                    }
                                }
                                else
                                {
                                    Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.rock);
                                }
                            }
                        }
                        #endregion
                    }
                    else //all of lava world generation
                    {
                        if (z > LavaLevel)
                        {
                            for (ushort zz = 0; z - zz >= 0; zz++)
                            {
                                if (z > (LavaLevel - 1))
                                {
                                    if (zz == 0)
                                    {
                                        Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);
                                    }                                                                         //top layer
                                    else if (zz < 3)
                                    {
                                        Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);
                                    }
                                    else if (zz < 2)
                                    {
                                        Lvl.skipChange(x, (ushort)(z - zz), y, Block.lava);
                                    }                                                                       //next few
                                    else
                                    {
                                        Lvl.skipChange(x, (ushort)(z - zz), y, Block.obsidian);
                                    }
                                }
                                else
                                {
                                    Lvl.skipChange(x, (ushort)(z - zz), y, Block.lava);
                                }
                                if (overlay[bb] < 0.3f)
                                {
                                    switch (rand.Next(13))
                                    {
                                    case 9:
                                    case 10:
                                    case 11:
                                    case 12:
                                        Lvl.skipChange(x, (ushort)(z + 1), y, Block.lava);     //change to lava when time
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                // if (zz == z) Lvl.skipChange(x, (ushort)(z - zz), y, Block.opsidian);
                                Lvl.skipChange(x, (ushort)(z), y, (rand.Next(100) % 3 == 1 ? Block.darkgrey : Block.obsidian));
                            }
                        }

                        else
                        {
                            for (ushort zz = 0; LavaLevel - zz >= 0; zz++)
                            {
                                if (LavaLevel - zz > z - 1)
                                { /*if (Lvl.GetTile(x, z, y) == Block.air)*/
                                    Lvl.skipChange(x, (ushort)(LavaLevel - zz), y, Block.lava);
                                } //better fill the water aboce me
                                else if (LavaLevel - zz > z - 3)
                                {
                                    if (overlay[bb] < .9f)
                                    {
                                        if (zz < z)
                                        {
                                            Lvl.skipChange(x, (ushort)(z - zz), (ushort)(y), Block.lava);
                                        }
                                        else
                                        {
                                            Lvl.skipChange(x, (ushort)(z - zz), y, Block.rock);
                                        }
                                    }
                                    else
                                    {
                                        Lvl.skipChange(x, (ushort)(LavaLevel - zz), (ushort)(y - 5), Block.lava);  //killer lava
                                    }
                                }
                                else
                                {
                                    Lvl.skipChange(x, (ushort)(LavaLevel - zz), y, Block.stone); //and just make the rest cobblestone
                                }
                            }
                        }
                    }
                }
                Server.s.Log("Total time was " + (DateTime.Now - startTime).TotalSeconds.ToString() + " seconds.");
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
                Server.s.Log("Gen Fail");
                Inuse = false;
                return(false);
            }

            terrain  = new float[0]; //Derp
            overlay  = new float[0]; //Derp
            overlay2 = new float[0]; //Derp

            Inuse = false;

            return(true);
        }
Exemplo n.º 10
0
        //public static Window thisWindow;
        private void Window_Load(object sender, EventArgs e)
        {
            btnProperties.Enabled = false;
            //thisWindow = this;
            MaximizeBox = false;
            this.Text = "Starting MCForge...";
            //this.Icon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MCLawl.Lawl.ico"));

            this.Show();
            this.BringToFront();
            WindowState = FormWindowState.Normal;
            new Thread(() =>
            {
                s = new Server();
                s.OnLog += WriteLine;
                s.OnCommand += newCommand;
                s.OnError += newError;
                s.OnSystem += newSystem;
                s.OnAdmin += WriteAdmin;
                s.OnOp += WriteOp;

                s.HeartBeatFail += HeartBeatFail;
                s.OnURLChange += UpdateUrl;
                s.OnPlayerListChange += UpdateClientList;
                s.OnSettingsUpdate += SettingsUpdate;
                s.Start();

                Player.PlayerConnect += new Player.OnPlayerConnect(Player_PlayerConnect);
                Player.PlayerDisconnect += new Player.OnPlayerDisconnect(Player_PlayerDisconnect);

                Level.LevelLoaded += new Level.OnLevelLoaded(Level_LevelLoaded);
                Level.LevelUnload += new Level.OnLevelUnload(Level_LevelUnload);

                GlobalChatBot.OnNewRecieveGlobalMessage += new GlobalChatBot.RecieveChat(GlobalChatRecieve);
                GlobalChatBot.OnNewSayGlobalMessage += new GlobalChatBot.SendChat(GlobalChatSay);

                RunOnUiThread(delegate { btnProperties.Enabled = true; });

            }).Start();

            notifyIcon1.Text = ("MCForge Server: " + Server.name).Truncate(64);

            this.notifyIcon1.ContextMenuStrip = this.iconContext;
            this.notifyIcon1.Icon = this.Icon;
            this.notifyIcon1.Visible = true;
            this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);

            if (File.Exists("Changelog.txt"))
            {
                txtChangelog.Text = "Changelog for " + Server.Version + ":";
                foreach (string line in File.ReadAllLines(("Changelog.txt")))
                {
                    txtChangelog.AppendText("\r\n           " + line);
                }
            }

            // Bind player list
            dgvPlayers.DataSource = pc;
            dgvPlayers.Font = new Font("Calibri", 8.25f);

            dgvMaps.DataSource = new LevelCollection(new LevelListView());
            dgvMaps.Font = new Font("Calibri", 8.25f);

            dgvMapsTab.DataSource = new LevelCollection(new LevelListViewForTab());
            dgvMapsTab.Font = new Font("Calibri", 8.25f);

            /*using (System.Timers.Timer UpdateListTimer = new System.Timers.Timer(10000))
            {
                UpdateListTimer.Elapsed += delegate
                {
                    UpdateClientList(Player.players);
                    UpdateMapList("'");
                    Server.s.Log("Lists updated!");
                }; UpdateListTimer.Start();
            }*/

            UpdateListTimer.Elapsed += delegate
            {
                try
                {
                    UpdateClientList(Player.players);
                    UpdateMapList();
                }
                catch { } // needed for slower computers
                //Server.s.Log("Lists updated!");
            }; UpdateListTimer.Start();
        }