Exemplo n.º 1
0
        public void Start()
        {
            shuttingDown = false;
            Log("Starting Your Server");

            if (!Directory.Exists("properties"))
            {
                Directory.CreateDirectory("properties");
            }
            if (!Directory.Exists("bots"))
            {
                Directory.CreateDirectory("bots");
            }
            if (!Directory.Exists("text"))
            {
                Directory.CreateDirectory("text");
            }

            if (!Directory.Exists("extra"))
            {
                Directory.CreateDirectory("extra");
            }
            if (!Directory.Exists("extra/undo"))
            {
                Directory.CreateDirectory("extra/undo");
            }
            if (!Directory.Exists("extra/undoPrevious"))
            {
                Directory.CreateDirectory("extra/undoPrevious");
            }
            if (!Directory.Exists("extra/copy/"))
            {
                Directory.CreateDirectory("extra/copy/");
            }
            if (!Directory.Exists("extra/copyBackup/"))
            {
                Directory.CreateDirectory("extra/copyBackup/");
            }

            try
            {
                if (File.Exists("server.properties"))
                {
                    File.Move("server.properties", "properties/server.properties");
                }
                if (File.Exists("rules.txt"))
                {
                    File.Move("rules.txt", "text/rules.txt");
                }
                if (File.Exists("welcome.txt"))
                {
                    File.Move("welcome.txt", "text/welcome.txt");
                }
                if (File.Exists("messages.txt"))
                {
                    File.Move("messages.txt", "text/messages.txt");
                }
                if (File.Exists("externalurl.txt"))
                {
                    File.Move("externalurl.txt", "text/externalurl.txt");
                }
                if (File.Exists("autoload.txt"))
                {
                    File.Move("autoload.txt", "text/autoload.txt");
                }
                if (File.Exists("IRC_Controllers.txt"))
                {
                    File.Move("IRC_Controllers.txt", "ranks/IRC_Controllers.txt");
                }
                if (Server.useWhitelist)
                {
                    if (File.Exists("whitelist.txt"))
                    {
                        File.Move("whitelist.txt", "ranks/whitelist.txt");
                    }
                }
            } catch { }

            Properties.Load("properties/server.properties");
            Updater.Load("properties/update.properties");

            Group.InitAll();
            Command.InitAll();
            GrpCommands.fillRanks();
            Block.SetBlocks();
            Awards.Load();

            if (File.Exists("text/emotelist.txt"))
            {
                foreach (string s in File.ReadAllLines("text/emotelist.txt"))
                {
                    Player.emoteList.Add(s);
                }
            }
            else
            {
                File.Create("text/emotelist.txt");
            }

            timeOnline = DateTime.Now;

            try
            {
                MySQL.executeQuery("CREATE DATABASE if not exists `" + MySQLDatabaseName + "`", true);
            }
            catch (Exception e)
            {
                Server.s.Log("MySQL password has not been set! Please reference the MySQL_Setup.txt file on setting up MySQL!");
                Server.ErrorLog(e);
                //process.Kill();
                return;
            }

            MySQL.executeQuery("CREATE TABLE if not exists Players (ID MEDIUMINT not null auto_increment, Name VARCHAR(20), IP CHAR(15), FirstLogin DATETIME, LastLogin DATETIME, totalLogin MEDIUMINT, Title CHAR(20), TotalDeaths SMALLINT, Money MEDIUMINT UNSIGNED, totalBlocks BIGINT, totalKicked MEDIUMINT, color VARCHAR(6), title_color VARCHAR(6), PRIMARY KEY (ID));");

            // Check if the color column exists.
            DataTable colorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='color'");

            if (colorExists.Rows.Count == 0)
            {
                MySQL.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
            }
            colorExists.Dispose();

            // Check if the title color column exists.
            DataTable tcolorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='title_color'");

            if (tcolorExists.Rows.Count == 0)
            {
                MySQL.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
            }
            tcolorExists.Dispose();

            if (levels != null)
            {
                foreach (Level l in levels)
                {
                    l.Unload();
                }
            }
            ml.Queue(delegate
            {
                try
                {
                    levels = new List <Level>(Server.maps);
                    MapGen = new MapGenerator();

                    Random random = new Random();

                    if (File.Exists("levels/" + Server.level + ".lvl"))
                    {
                        mainLevel        = Level.Load(Server.level);
                        mainLevel.unload = false;
                        if (mainLevel == null)
                        {
                            if (File.Exists("levels/" + Server.level + ".lvl.backup"))
                            {
                                Log("Attempting to load backup.");
                                File.Copy("levels/" + Server.level + ".lvl.backup", "levels/" + Server.level + ".lvl", true);
                                mainLevel = Level.Load(Server.level);
                                if (mainLevel == null)
                                {
                                    Log("BACKUP FAILED!");
                                    Console.ReadLine(); return;
                                }
                            }
                            else
                            {
                                Log("Your main level was not found");
                                mainLevel = new Level(Server.level, 128, 128, 128, "flat");

                                mainLevel.permissionvisit = LevelPermission.Guest;
                                mainLevel.permissionbuild = LevelPermission.Guest;
                                mainLevel.Save();
                            }
                        }
                    }
                    else
                    {
                        Log("You need a main level, creating one for you now");
                        mainLevel = new Level(Server.level, 128, 128, 128, "flat");

                        mainLevel.permissionvisit = LevelPermission.Guest;
                        mainLevel.permissionbuild = LevelPermission.Guest;
                        mainLevel.Save();
                    }
                    addLevel(mainLevel);
                    mainLevel.physThread.Start();
                } catch (Exception e) { Server.ErrorLog(e); }
            });

            ml.Queue(delegate
            {
                bannedIP       = PlayerList.Load("banned-ip.txt", null);
                ircControllers = PlayerList.Load("IRC_Controllers.txt", null);

                foreach (Group grp in Group.GroupList)
                {
                    grp.playerList = PlayerList.Load(grp.fileName, grp);
                }
                if (Server.useWhitelist)
                {
                    whiteList = PlayerList.Load("whitelist.txt", null);
                }
            });

            ml.Queue(delegate
            {
                if (File.Exists("text/autoload.txt"))
                {
                    try
                    {
                        string[] lines = File.ReadAllLines("text/autoload.txt");
                        foreach (string line in lines)
                        {
                            //int temp = 0;
                            string _line = line.Trim();
                            try
                            {
                                if (_line == "")
                                {
                                    continue;
                                }
                                if (_line[0] == '#')
                                {
                                    continue;
                                }
                                int index = _line.IndexOf("=");

                                string key = _line.Split('=')[0].Trim();
                                string value;
                                try
                                {
                                    value = _line.Split('=')[1].Trim();
                                }
                                catch
                                {
                                    value = "0";
                                }

                                if (!key.Equals(mainLevel.name))
                                {
                                    Command.all.Find("load").Use(null, key + " " + value);
                                    Level l = Level.FindExact(key);
                                }
                                else
                                {
                                    try
                                    {
                                        int temp = int.Parse(value);
                                        if (temp >= 0 && temp <= 3)
                                        {
                                            mainLevel.setPhysics(temp);
                                        }
                                    }
                                    catch
                                    {
                                        Server.s.Log("Physics variable invalid");
                                    }
                                }
                            }
                            catch
                            {
                                Server.s.Log(_line + " failed.");
                            }
                        }
                    }
                    catch
                    {
                        Server.s.Log("autoload.txt error");
                    }
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                else
                {
                    Log("autoload.txt does not exist");
                }
            });

            ml.Queue(delegate
            {
                Log("Creating listening socket on port " + Server.port + "... ");
                if (Setup())
                {
                    s.Log("Done.");
                }
                else
                {
                    s.Log("Could not create socket connection.  Shutting down.");
                    return;
                }
            });

            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                    Player.GlobalUpdate();
                    PlayerBot.GlobalUpdatePosition();
                };

                updateTimer.Start();
            });


            // Heartbeat code here:

            ml.Queue(delegate
            {
                try
                {
                    Heartbeat.Init();
                }
                catch (Exception e)
                {
                    Server.ErrorLog(e);
                }
            });

            // END Heartbeat code

            /*
             * Thread processThread = new Thread(new ThreadStart(delegate
             * {
             *  try
             *  {
             *      PCCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
             *      ProcessCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);
             *      PCCounter.BeginInit();
             *      ProcessCounter.BeginInit();
             *      PCCounter.NextValue();
             *      ProcessCounter.NextValue();
             *  }
             *  catch { }
             * }));
             * processThread.Start();
             */

            ml.Queue(delegate
            {
                messageTimer.Elapsed += delegate
                {
                    RandomMessage();
                };
                messageTimer.Start();

                process = System.Diagnostics.Process.GetCurrentProcess();

                if (File.Exists("text/messages.txt"))
                {
                    StreamReader r = File.OpenText("text/messages.txt");
                    while (!r.EndOfStream)
                    {
                        messages.Add(r.ReadLine());
                    }
                    r.Dispose();
                }
                else
                {
                    File.Create("text/messages.txt").Close();
                }

                if (Server.irc)
                {
                    new IRCBot();
                }


                //      string CheckName = "FROSTEDBUTTS";

                //       if (Server.name.IndexOf(CheckName.ToLower())!= -1){ Server.s.Log("FROSTEDBUTTS DETECTED");}
                new AutoSaver(Server.backupInterval);     //2 and a half mins

                blockThread = new Thread(new ThreadStart(delegate
                {
                    while (true)
                    {
                        Thread.Sleep(blockInterval * 1000);
                        foreach (Level l in levels)
                        {
                            l.saveChanges();
                        }
                    }
                }));
                blockThread.Start();

                locationChecker = new Thread(new ThreadStart(delegate
                {
                    while (true)
                    {
                        Thread.Sleep(3);
                        for (int i = 0; i < Player.players.Count; i++)
                        {
                            try
                            {
                                Player p = Player.players[i];

                                if (p.frozen)
                                {
                                    unchecked { p.SendPos((byte)-1, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); } continue;
                                }
                                else if (p.following != "")
                                {
                                    Player who = Player.Find(p.following);
                                    if (who == null || who.level != p.level)
                                    {
                                        p.following = "";
                                        if (!p.canBuild)
                                        {
                                            p.canBuild = true;
                                        }
                                        if (who != null && who.possess == p.name)
                                        {
                                            who.possess = "";
                                        }
                                        continue;
                                    }
                                    if (p.canBuild)
                                    {
                                        unchecked { p.SendPos((byte)-1, who.pos[0], (ushort)(who.pos[1] - 16), who.pos[2], who.rot[0], who.rot[1]); }
                                    }
                                    else
                                    {
                                        unchecked { p.SendPos((byte)-1, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]); }
                                    }
                                }
                                else if (p.possess != "")
                                {
                                    Player who = Player.Find(p.possess);
                                    if (who == null || who.level != p.level)
                                    {
                                        p.possess = "";
                                    }
                                }

                                ushort x = (ushort)(p.pos[0] / 32);
                                ushort y = (ushort)(p.pos[1] / 32);
                                ushort z = (ushort)(p.pos[2] / 32);

                                if (p.level.Death)
                                {
                                    p.RealDeath(x, y, z);
                                }
                                p.CheckBlock(x, y, z);

                                p.oldBlock = (ushort)(x + y + z);
                            } catch (Exception e) { Server.ErrorLog(e); }
                        }
                    }
                }));

                locationChecker.Start();

                Log("Finished setting up " + Server.name + ".");
            });
        }
Exemplo n.º 2
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                if (p != null)
                {
                    message = p.level.name + " 30";
                }
                else
                {
                    message = Server.mainLevel + " 30";
                }
            }
            int foundNum = 0; Level foundLevel;

            if (message.IndexOf(' ') == -1)
            {
                try
                {
                    foundNum = int.Parse(message);
                    if (p != null)
                    {
                        foundLevel = p.level;
                    }
                    else
                    {
                        foundLevel = Server.mainLevel;
                    }
                }
                catch
                {
                    foundNum   = 30;
                    foundLevel = Level.Find(message);
                }
            }
            else
            {
                try
                {
                    foundNum   = int.Parse(message.Split(' ')[1]);
                    foundLevel = Level.Find(message.Split(' ')[0]);
                }
                catch
                {
                    Player.SendMessage(p, "Invalid input");
                    return;
                }
            }

            if (foundLevel == null)
            {
                Player.SendMessage(p, "Could not find entered level.");
                return;
            }

            try
            {
                if (foundLevel.physPause)
                {
                    foundLevel.physThread.Resume();
                    foundLevel.physResume = DateTime.Now;
                    foundLevel.physPause  = false;
                    Player.GlobalMessage("Physics on " + foundLevel.name + " were re-enabled.");
                }
                else
                {
                    foundLevel.physThread.Suspend();
                    foundLevel.physResume = DateTime.Now.AddSeconds(foundNum);
                    foundLevel.physPause  = true;
                    Player.GlobalMessage("Physics on " + foundLevel.name + " were temporarily disabled.");

                    foundLevel.physTimer.Elapsed += delegate
                    {
                        if (DateTime.Now > foundLevel.physResume)
                        {
                            foundLevel.physPause = false;
                            try
                            {
                                foundLevel.physThread.Resume();
                            }
                            catch (Exception e) { Server.ErrorLog(e); }
                            Player.GlobalMessage("Physics on " + foundLevel.name + " were re-enabled.");
                            foundLevel.physTimer.Stop();
                            foundLevel.physTimer.Dispose();
                        }
                    };
                    foundLevel.physTimer.Start();
                }
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
            }
        }
Exemplo n.º 3
0
        public override void Use(Player p, string message)
        {
            try
            {
                List <string> levels = new List <string>(Server.levels.Count);

                string unloadedLevels = ""; int currentNum = 0; int maxMaps = 0;

                if (message != "")
                {
                    try { maxMaps = int.Parse(message) * 50; currentNum = maxMaps - 50; }
                    catch { Help(p); return; }
                }

                DirectoryInfo di = new DirectoryInfo("levels/");
                FileInfo[]    fi = di.GetFiles("*.lvl");
                foreach (Level l in Server.levels)
                {
                    levels.Add(l.name.ToLower());
                }

                if (maxMaps == 0)
                {
                    foreach (FileInfo file in fi)
                    {
                        if (!levels.Contains(file.Name.Replace(".lvl", "").ToLower()))
                        {
                            unloadedLevels += ", " + file.Name.Replace(".lvl", "");
                        }
                    }
                    if (unloadedLevels != "")
                    {
                        Player.SendMessage(p, "Unloaded levels: ");
                        Player.SendMessage(p, "&4" + unloadedLevels.Remove(0, 2));
                        if (fi.Length > 50)
                        {
                            Player.SendMessage(p, "For a more structured list, use /unloaded <1/2/3/..>");
                        }
                    }
                    else
                    {
                        Player.SendMessage(p, "No maps are unloaded");
                    }
                }
                else
                {
                    if (maxMaps > fi.Length)
                    {
                        maxMaps = fi.Length;
                    }
                    if (currentNum > fi.Length)
                    {
                        Player.SendMessage(p, "No maps beyond number " + fi.Length); return;
                    }

                    Player.SendMessage(p, "Unloaded levels (" + currentNum + " to " + maxMaps + "):");
                    for (int i = currentNum; i < maxMaps; i++)
                    {
                        if (!levels.Contains(fi[i].Name.Replace(".lvl", "").ToLower()))
                        {
                            unloadedLevels += ", " + fi[i].Name.Replace(".lvl", "");
                        }
                    }

                    if (unloadedLevels != "")
                    {
                        Player.SendMessage(p, "&4" + unloadedLevels.Remove(0, 2));
                    }
                    else
                    {
                        Player.SendMessage(p, "No maps are unloaded");
                    }
                }
            }
            catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "An error occured"); }
            //Exception catching since it needs to be tested on Ocean Flatgrass
        }
Exemplo n.º 4
0
        public override void Use(Player p, string message)
        {
            byte b; Int64 seconds; Player who; Player.UndoPos Pos; int CurrentPos = 0;

            if (p != null)
            {
                p.RedoBuffer.Clear();
            }

            if (message == "")
            {
                message = p.name + " 30";
            }

            if (message.Split(' ').Length == 2)
            {
                if (message.Split(' ')[1].ToLower() == "all" && p.group.Permission > LevelPermission.Operator)
                {
                    seconds = 500000;
                }
                else
                {
                    try
                    {
                        seconds = Int64.Parse(message.Split(' ')[1]);
                    }
                    catch
                    {
                        Player.SendMessage(p, "Invalid seconds.");
                        return;
                    }
                }
            }
            else
            {
                try
                {
                    seconds = int.Parse(message);
                    if (p != null)
                    {
                        message = p.name + " " + message;
                    }
                }
                catch
                {
                    seconds = 30;
                    message = message + " 30";
                }
            }

            //if (message.Split(' ').Length == 1) if (char.IsDigit(message, 0)) { message = p.name + " " + message; } else { message = message + " 30"; }

            //try { seconds = Convert.ToInt16(message.Split(' ')[1]); } catch { seconds = 2; }
            if (seconds == 0)
            {
                seconds = 5400;
            }

            who = Player.Find(message.Split(' ')[0]);
            if (who != null)
            {
                if (p != null)
                {
                    if (who.group.Permission > p.group.Permission && who != p)
                    {
                        Player.SendMessage(p, "Cannot undo a user of higher or equal rank"); return;
                    }
                    if (who != p && p.group.Permission < LevelPermission.Operator)
                    {
                        Player.SendMessage(p, "Only an OP+ may undo other people's actions"); return;
                    }

                    if (p.group.Permission < LevelPermission.Builder && seconds > 120)
                    {
                        Player.SendMessage(p, "Guests may only undo 2 minutes."); return;
                    }
                    else if (p.group.Permission < LevelPermission.AdvBuilder && seconds > 300)
                    {
                        Player.SendMessage(p, "Builders may only undo 300 seconds."); return;
                    }
                    else if (p.group.Permission < LevelPermission.Operator && seconds > 1200)
                    {
                        Player.SendMessage(p, "AdvBuilders may only undo 600 seconds."); return;
                    }
                    else if (p.group.Permission == LevelPermission.Operator && seconds > 5400)
                    {
                        Player.SendMessage(p, "Operators may only undo 5400 seconds."); return;
                    }
                }

                for (CurrentPos = who.UndoBuffer.Count - 1; CurrentPos >= 0; --CurrentPos)
                {
                    try
                    {
                        Pos = who.UndoBuffer[CurrentPos];
                        Level foundLevel = Level.FindExact(Pos.mapName);
                        b = foundLevel.GetTile(Pos.x, Pos.y, Pos.z);
                        if (Pos.timePlaced.AddSeconds(seconds) >= DateTime.Now)
                        {
                            if (b == Pos.newtype || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava)
                            {
                                foundLevel.Blockchange(Pos.x, Pos.y, Pos.z, Pos.type, true);

                                Pos.newtype = Pos.type; Pos.type = b;
                                if (p != null)
                                {
                                    p.RedoBuffer.Add(Pos);
                                }
                                who.UndoBuffer.RemoveAt(CurrentPos);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch { }
                }

                if (p != who)
                {
                    Player.GlobalChat(p, who.color + who.name + Server.DefaultColor + "'s actions for the past &b" + seconds + " seconds were undone.", false);
                }
                else
                {
                    Player.SendMessage(p, "Undid your actions for the past &b" + seconds + Server.DefaultColor + " seconds.");
                }
                return;
            }
            else if (message.Split(' ')[0].ToLower() == "physics")
            {
                if (p.group.Permission < LevelPermission.AdvBuilder)
                {
                    Player.SendMessage(p, "Reserved for Adv+"); return;
                }
                else if (p.group.Permission < LevelPermission.Operator && seconds > 1200)
                {
                    Player.SendMessage(p, "AdvBuilders may only undo 1200 seconds."); return;
                }
                else if (p.group.Permission == LevelPermission.Operator && seconds > 5400)
                {
                    Player.SendMessage(p, "Operators may only undo 5400 seconds."); return;
                }

                Command.all.Find("pause").Use(p, "120");
                Level.UndoPos uP;
                ushort        x, y, z;

                if (p.level.UndoBuffer.Count != Server.physUndo)
                {
                    for (CurrentPos = p.level.currentUndo; CurrentPos >= 0; CurrentPos--)
                    {
                        try
                        {
                            uP = p.level.UndoBuffer[CurrentPos];
                            b  = p.level.GetTile(uP.location);
                            if (uP.timePerformed.AddSeconds(seconds) >= DateTime.Now)
                            {
                                if (b == uP.newType || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava)
                                {
                                    p.level.IntToPos(uP.location, out x, out y, out z);
                                    p.level.Blockchange(p, x, y, z, uP.oldType, true);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch { }
                    }
                }
                else
                {
                    for (CurrentPos = p.level.currentUndo; CurrentPos != p.level.currentUndo + 1; CurrentPos--)
                    {
                        try
                        {
                            if (CurrentPos < 0)
                            {
                                CurrentPos = p.level.UndoBuffer.Count - 1;
                            }
                            uP = p.level.UndoBuffer[CurrentPos];
                            b  = p.level.GetTile(uP.location);
                            if (uP.timePerformed.AddSeconds(seconds) >= DateTime.Now)
                            {
                                if (b == uP.newType || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava)
                                {
                                    p.level.IntToPos(uP.location, out x, out y, out z);
                                    p.level.Blockchange(p, x, y, z, uP.oldType, true);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch { }
                    }
                }

                Command.all.Find("pause").Use(p, "");
                Player.GlobalMessage("Physics were undone &b" + seconds + Server.DefaultColor + " seconds");
            }
            else
            {
                if (p != null)
                {
                    if (p.group.Permission < LevelPermission.Operator)
                    {
                        Player.SendMessage(p, "Reserved for OP+"); return;
                    }
                    if (seconds > 5400 && p.group.Permission == LevelPermission.Operator)
                    {
                        Player.SendMessage(p, "Only SuperOPs may undo more than 90 minutes."); return;
                    }
                }

                bool FoundUser = false;

                try
                {
                    DirectoryInfo di;
                    string[]      fileContent;

                    p.RedoBuffer.Clear();

                    if (Directory.Exists("extra/undo/" + message.Split(' ')[0]))
                    {
                        di = new DirectoryInfo("extra/undo/" + message.Split(' ')[0]);

                        for (int i = di.GetFiles("*.undo").Length - 1; i >= 0; i--)
                        {
                            fileContent = File.ReadAllText("extra/undo/" + message.Split(' ')[0] + "/" + i + ".undo").Split(' ');
                            if (!undoBlah(fileContent, seconds, p))
                            {
                                break;
                            }
                        }
                        FoundUser = true;
                    }

                    if (Directory.Exists("extra/undoPrevious/" + message.Split(' ')[0]))
                    {
                        di = new DirectoryInfo("extra/undoPrevious/" + message.Split(' ')[0]);

                        for (int i = di.GetFiles("*.undo").Length - 1; i >= 0; i--)
                        {
                            fileContent = File.ReadAllText("extra/undoPrevious/" + message.Split(' ')[0] + "/" + i + ".undo").Split(' ');
                            if (!undoBlah(fileContent, seconds, p))
                            {
                                break;
                            }
                        }
                        FoundUser = true;
                    }

                    if (FoundUser)
                    {
                        Player.GlobalChat(p, Server.FindColor(message.Split(' ')[0]) + message.Split(' ')[0] + Server.DefaultColor + "'s actions for the past &b" + seconds + Server.DefaultColor + " seconds were undone.", false);
                    }
                    else
                    {
                        Player.SendMessage(p, "Could not find player specified.");
                    }
                }
                catch (Exception e)
                {
                    Server.ErrorLog(e);
                }
            }
        }
Exemplo n.º 5
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }
            if (message[0] == '@')
            {
                message = message.Remove(0, 1).Trim();
                Player who = Player.Find(message);
                if (who == null)
                {
                    DataTable ip;
                    int       tryCounter = 0;
                    rerun : try
                    {
                        ip = MySQL.fillData("SELECT IP FROM Players WHERE Name = '" + message + "'");
                    }
                    catch (Exception e)
                    {
                        tryCounter++;
                        if (tryCounter < 10)
                        {
                            goto rerun;
                        }
                        else
                        {
                            Server.ErrorLog(e);
                            Player.SendMessage(p, "There was a database error fetching the IP address.  It has been logged.");
                            return;
                        }
                    }
                    if (ip.Rows.Count > 0)
                    {
                        message = ip.Rows[0]["IP"].ToString();
                    }
                    else
                    {
                        Player.SendMessage(p, "Unable to find an IP address for that user.");
                        return;
                    }
                    ip.Dispose();
                }
                else
                {
                    message = who.ip;
                }
            }

            if (!regex.IsMatch(message))
            {
                Player.SendMessage(p, "Not a valid ip!"); return;
            }
            if (p != null)
            {
                if (p.ip == message)
                {
                    Player.SendMessage(p, "You shouldn't be able to use this command..."); return;
                }
            }
            if (!Server.bannedIP.Contains(message))
            {
                Player.SendMessage(p, message + " doesn't seem to be banned..."); return;
            }
            Player.GlobalMessage(message + " got &8unip-banned" + Server.DefaultColor + "!");
            Server.bannedIP.Remove(message); Server.bannedIP.Save("banned-ip.txt", false);
            Server.s.Log("IP-UNBANNED: " + message.ToLower());
        }
Exemplo n.º 6
0
        public override void Use(Player p, string message)
        {
            string path;

            if (message.Split(' ').Length == 1)
            {
                path = "levels/" + message + ".lvl";
            }
            else if (message.Split(' ').Length == 2)
            {
                try { path = @Server.backupLocation + "/" + message.Split(' ')[0] + "/" + int.Parse(message.Split(' ')[1]) + "/" + message.Split(' ')[0] + ".lvl"; }
                catch { Help(p); return; }
            }
            else
            {
                Help(p); return;
            }

            if (File.Exists(path))
            {
                FileStream fs = File.OpenRead(path);
                try
                {
                    GZipStream gs  = new GZipStream(fs, CompressionMode.Decompress);
                    byte[]     ver = new byte[2];
                    gs.Read(ver, 0, ver.Length);
                    ushort version = BitConverter.ToUInt16(ver, 0);
                    Level  level;
                    if (version == 1874)
                    {
                        byte[] header = new byte[16]; gs.Read(header, 0, header.Length);
                        ushort width  = BitConverter.ToUInt16(header, 0);
                        ushort height = BitConverter.ToUInt16(header, 2);
                        ushort depth  = BitConverter.ToUInt16(header, 4);
                        level        = new Level(name, width, depth, height, "empty");
                        level.spawnx = BitConverter.ToUInt16(header, 6);
                        level.spawnz = BitConverter.ToUInt16(header, 8);
                        level.spawny = BitConverter.ToUInt16(header, 10);
                        level.rotx   = header[12]; level.roty = header[13];
                    }
                    else
                    {
                        byte[] header = new byte[12]; gs.Read(header, 0, header.Length);
                        ushort width  = version;
                        ushort height = BitConverter.ToUInt16(header, 0);
                        ushort depth  = BitConverter.ToUInt16(header, 2);
                        level        = new Level(name, width, depth, height, "grass");
                        level.spawnx = BitConverter.ToUInt16(header, 4);
                        level.spawnz = BitConverter.ToUInt16(header, 6);
                        level.spawny = BitConverter.ToUInt16(header, 8);
                        level.rotx   = header[10]; level.roty = header[11];
                    }

                    level.setPhysics(0);

                    byte[] blocks = new byte[level.width * level.height * level.depth];
                    gs.Read(blocks, 0, blocks.Length);
                    level.blocks = blocks;
                    gs.Close();

                    level.backedup        = true;
                    level.permissionbuild = LevelPermission.Admin;

                    level.jailx    = (ushort)(level.spawnx * 32); level.jaily = (ushort)(level.spawny * 32); level.jailz = (ushort)(level.spawnz * 32);
                    level.jailrotx = level.rotx; level.jailroty = level.roty;

                    p.Loading = true;
                    foreach (Player pl in Player.players)
                    {
                        if (p.level == pl.level && p != pl)
                        {
                            p.SendDie(pl.id);
                        }
                    }
                    foreach (PlayerBot b in PlayerBot.playerbots)
                    {
                        if (p.level == b.level)
                        {
                            p.SendDie(b.id);
                        }
                    }

                    Player.GlobalDie(p, true);

                    p.level = level;
                    p.SendMotd();

                    p.SendRaw(2);
                    byte[] buffer = new byte[level.blocks.Length + 4];
                    BitConverter.GetBytes(IPAddress.HostToNetworkOrder(level.blocks.Length)).CopyTo(buffer, 0);
                    //ushort xx; ushort yy; ushort zz;

                    for (int i = 0; i < level.blocks.Length; ++i)
                    {
                        buffer[4 + i] = Block.Convert(level.blocks[i]);
                    }

                    buffer = Player.GZip(buffer);
                    int number = (int)Math.Ceiling(((double)buffer.Length) / 1024);
                    for (int i = 1; buffer.Length > 0; ++i)
                    {
                        short  length = (short)Math.Min(buffer.Length, 1024);
                        byte[] send   = new byte[1027];
                        Player.HTNO(length).CopyTo(send, 0);
                        Buffer.BlockCopy(buffer, 0, send, 2, length);
                        byte[] tempbuffer = new byte[buffer.Length - length];
                        Buffer.BlockCopy(buffer, length, tempbuffer, 0, buffer.Length - length);
                        buffer     = tempbuffer;
                        send[1026] = (byte)(i * 100 / number);
                        p.SendRaw(3, send);
                        Thread.Sleep(10);
                    }
                    buffer = new byte[6];
                    Player.HTNO((short)level.width).CopyTo(buffer, 0);
                    Player.HTNO((short)level.depth).CopyTo(buffer, 2);
                    Player.HTNO((short)level.height).CopyTo(buffer, 4);
                    p.SendRaw(4, buffer);

                    ushort x = (ushort)((0.5 + level.spawnx) * 32);
                    ushort y = (ushort)((1 + level.spawny) * 32);
                    ushort z = (ushort)((0.5 + level.spawnz) * 32);

                    p.aiming = false;
                    Player.GlobalSpawn(p, x, y, z, level.rotx, level.roty, true);
                    p.ClearBlockchange();
                    p.Loading = false;

                    if (message.IndexOf(' ') == -1)
                    {
                        level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + ")";
                    }
                    else
                    {
                        level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + " " + message.Split(' ')[1] + ")";
                    }

                    if (!p.hidden)
                    {
                        Player.GlobalChat(null, p.color + p.prefix + p.name + Server.DefaultColor + " went to the " + level.name, false);
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch (Exception ex) { Player.SendMessage(p, "Error loading level."); Server.ErrorLog(ex); return; }
                finally { fs.Close(); }
            }
            else
            {
                Player.SendMessage(p, "Level or backup could not be found."); return;
            }
        }
Exemplo n.º 7
0
 public override void Use(Player p, string message)
 {
     if (message.Split(' ').Length > 2)
     {
         Help(p); return;
     }
     if (p == null)
     {
         Player.SendMessage(p, "Console possession?  Nope.avi."); return;
     }
     try
     {
         string skin = (message.Split(' ').Length == 2) ? message.Split(' ')[1] : "";
         message = message.Split(' ')[0];
         if (message == "")
         {
             if (p.possess == "")
             {
                 Help(p);
                 return;
             }
             else
             {
                 Player who = Player.Find(p.possess);
                 if (who == null)
                 {
                     p.possess = "";
                     Player.SendMessage(p, "Possession disabled.");
                     return;
                 }
                 who.following = "";
                 who.canBuild  = true;
                 p.possess     = "";
                 if (!who.MarkPossessed())
                 {
                     return;
                 }
                 p.invincible = false;
                 Command.all.Find("hide").Use(p, "");
                 Player.SendMessage(p, "Stopped possessing " + who.color + who.name + Server.DefaultColor + ".");
                 return;
             }
         }
         else if (message == p.possess)
         {
             Player who = Player.Find(p.possess);
             if (who == null)
             {
                 p.possess = "";
                 Player.SendMessage(p, "Possession disabled.");
                 return;
             }
             if (who == p)
             {
                 Player.SendMessage(p, "Cannot possess yourself!");
                 return;
             }
             who.following = "";
             who.canBuild  = true;
             p.possess     = "";
             if (!who.MarkPossessed())
             {
                 return;
             }
             p.invincible = false;
             Command.all.Find("hide").Use(p, "");
             Player.SendMessage(p, "Stopped possessing " + who.color + who.name + Server.DefaultColor + ".");
             return;
         }
         else
         {
             Player who = Player.Find(message);
             if (who == null)
             {
                 Player.SendMessage(p, "Could not find player.");
                 return;
             }
             if (who.group.Permission >= p.group.Permission)
             {
                 Player.SendMessage(p, "Cannot possess someone of equal or greater rank.");
                 return;
             }
             if (who.possess != "")
             {
                 Player.SendMessage(p, "That player is currently possessing someone!");
                 return;
             }
             if (who.following != "")
             {
                 Player.SendMessage(p, "That player is either following someone or already possessed.");
                 return;
             }
             if (p.possess != "")
             {
                 Player oldwho = Player.Find(p.possess);
                 if (oldwho != null)
                 {
                     oldwho.following = "";
                     oldwho.canBuild  = true;
                     if (!oldwho.MarkPossessed())
                     {
                         return;
                     }
                     //p.SendSpawn(oldwho.id, oldwho.color + oldwho.name, oldwho.pos[0], oldwho.pos[1], oldwho.pos[2], oldwho.rot[0], oldwho.rot[1]);
                 }
             }
             Command.all.Find("tp").Use(p, who.name);
             if (!p.hidden)
             {
                 Command.all.Find("hide").Use(p, "");
             }
             p.possess     = who.name;
             who.following = p.name;
             if (!p.invincible)
             {
                 p.invincible = true;
             }
             bool result = (skin == "#") ? who.MarkPossessed() : who.MarkPossessed(p.name);
             if (!result)
             {
                 return;
             }
             p.SendDie(who.id);
             who.canBuild = false;
             Player.SendMessage(p, "Successfully possessed " + who.color + who.name + Server.DefaultColor + ".");
         }
     }
     catch (Exception e)
     {
         Server.ErrorLog(e);
         Player.SendMessage(p, "There was an error.");
     }
 }
Exemplo n.º 8
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }

            try
            {
                Level foundLevel = Level.Find(message);
                if (foundLevel != null)
                {
                    Level startLevel = p.level;

                    GC.Collect();

                    if (p.level == foundLevel)
                    {
                        Player.SendMessage(p, "You are already in \"" + foundLevel.name + "\"."); return;
                    }
                    if (!p.ignorePermission)
                    {
                        if (p.group.Permission < foundLevel.permissionvisit)
                        {
                            Player.SendMessage(p, "You're not allowed to go to " + foundLevel.name + "."); return;
                        }
                    }

                    p.Loading = true;
                    foreach (Player pl in Player.players)
                    {
                        if (p.level == pl.level && p != pl)
                        {
                            p.SendDie(pl.id);
                        }
                    }
                    foreach (PlayerBot b in PlayerBot.playerbots)
                    {
                        if (p.level == b.level)
                        {
                            p.SendDie(b.id);
                        }
                    }

                    Player.GlobalDie(p, true);
                    p.level = foundLevel; p.SendUserMOTD(); p.SendMap();

                    GC.Collect();

                    ushort x = (ushort)((0.5 + foundLevel.spawnx) * 32);
                    ushort y = (ushort)((1 + foundLevel.spawny) * 32);
                    ushort z = (ushort)((0.5 + foundLevel.spawnz) * 32);

                    if (!p.hidden)
                    {
                        Player.GlobalSpawn(p, x, y, z, foundLevel.rotx, foundLevel.roty, true);
                    }
                    else
                    {
                        unchecked { p.SendPos((byte)-1, x, y, z, foundLevel.rotx, foundLevel.roty); }
                    }

                    foreach (Player pl in Player.players)
                    {
                        if (pl.level == p.level && p != pl && !pl.hidden)
                        {
                            p.SendSpawn(pl.id, pl.color + pl.name, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1]);
                        }
                    }

                    foreach (PlayerBot b in PlayerBot.playerbots)
                    {
                        if (b.level == p.level)
                        {
                            p.SendSpawn(b.id, b.color + b.name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
                        }
                    }

                    if (!p.hidden)
                    {
                        Player.GlobalChat(p, p.color + "*" + p.name + Server.DefaultColor + " went to &b" + foundLevel.name, false);
                    }

                    p.Loading = false;

                    bool skipUnload = false;
                    if (startLevel.unload && !startLevel.name.Contains("&cMuseum "))
                    {
                        foreach (Player pl in Player.players)
                        {
                            if (pl.level == startLevel)
                            {
                                skipUnload = true;
                            }
                        }
                        if (!skipUnload && Server.AutoLoad)
                        {
                            startLevel.Unload();
                        }
                    }
                }
                else if (Server.AutoLoad)
                {
                    Command.all.Find("load").Use(p, message);
                    foundLevel = Level.Find(message);
                    if (foundLevel != null)
                    {
                        Use(p, message);
                    }
                }
                else
                {
                    Player.SendMessage(p, "There is no level \"" + message + "\" loaded.");
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Exemplo n.º 9
0
        public override void Use(Player p, string message)
        {
            if (message.Split(' ').Length < 2)
            {
                Help(p); return;
            }

            string foundPath = message.Split(' ')[1].ToLower();

            if (!Player.ValidName(foundPath))
            {
                Player.SendMessage(p, "Invalid AI name!"); return;
            }
            if (foundPath == "hunt" || foundPath == "kill")
            {
                Player.SendMessage(p, "Reserved for special AI."); return;
            }

            try
            {
                switch (message.Split(' ')[0])
                {
                case "add":
                    if (message.Split(' ').Length == 2)
                    {
                        addPoint(p, foundPath);
                    }
                    else if (message.Split(' ').Length == 3)
                    {
                        addPoint(p, foundPath, message.Split(' ')[2]);
                    }
                    else if (message.Split(' ').Length == 4)
                    {
                        addPoint(p, foundPath, message.Split(' ')[2], message.Split(' ')[3]);
                    }
                    else
                    {
                        addPoint(p, foundPath, message.Split(' ')[2], message.Split(' ')[3], message.Split(' ')[4]);
                    }
                    break;

                case "del":
                    if (!Directory.Exists("bots/deleted"))
                    {
                        Directory.CreateDirectory("bots/deleted");
                    }

                    int currentTry = 0;
                    if (File.Exists("bots/" + foundPath))
                    {
                        retry : try
                        {
                            if (message.Split(' ').Length == 2)
                            {
                                if (currentTry == 0)
                                {
                                    File.Move("bots/" + foundPath, "bots/deleted/" + foundPath);
                                }
                                else
                                {
                                    File.Move("bots/" + foundPath, "bots/deleted/" + foundPath + currentTry);
                                }
                            }
                            else
                            {
                                if (message.Split(' ')[2].ToLower() == "last")
                                {
                                    string[] Lines    = File.ReadAllLines("bots/" + foundPath);
                                    string[] outLines = new string[Lines.Length - 1];
                                    for (int i = 0; i < Lines.Length - 1; i++)
                                    {
                                        outLines[i] = Lines[i];
                                    }

                                    File.WriteAllLines("bots/" + foundPath, outLines);
                                    Player.SendMessage(p, "Deleted the last waypoint from " + foundPath);
                                    return;
                                }
                                else
                                {
                                    Help(p); return;
                                }
                            }
                        }
                        catch (IOException) { currentTry++; goto retry; }
                        Player.SendMessage(p, "Deleted &b" + foundPath);
                    }
                    else
                    {
                        Player.SendMessage(p, "Could not find specified AI.");
                    }
                    break;

                default: Help(p); return;
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Exemplo n.º 10
0
        public void FloodFill(Player p, ushort x, ushort y, ushort z, byte b, byte oldType, int fillType, ref byte[] blocks, ref List <Pos> buffer)
        {
            try
            {
                Pos pos;
                pos.x = x; pos.y = y; pos.z = z;

                if (deep > 4000)
                {
                    fromWhere.Add(pos);
                    return;
                }

                blocks[x + p.level.width * z + p.level.width * p.level.height * y] = b;
                buffer.Add(pos);

                //x
                if (fillType != 4)
                {
                    if (GetTile((ushort)(x + 1), y, z, p.level, blocks) == oldType)
                    {
                        deep++;
                        FloodFill(p, (ushort)(x + 1), y, z, b, oldType, fillType, ref blocks, ref buffer);
                        deep--;
                    }

                    if (x - 1 > 0)
                    {
                        if (GetTile((ushort)(x - 1), y, z, p.level, blocks) == oldType)
                        {
                            deep++;
                            FloodFill(p, (ushort)(x - 1), y, z, b, oldType, fillType, ref blocks, ref buffer);
                            deep--;
                        }
                    }
                }

                //z
                if (fillType != 5)
                {
                    if (GetTile(x, y, (ushort)(z + 1), p.level, blocks) == oldType)
                    {
                        deep++;
                        FloodFill(p, x, y, (ushort)(z + 1), b, oldType, fillType, ref blocks, ref buffer);
                        deep--;
                    }

                    if (z - 1 > 0)
                    {
                        if (GetTile(x, y, (ushort)(z - 1), p.level, blocks) == oldType)
                        {
                            deep++;
                            FloodFill(p, x, y, (ushort)(z - 1), b, oldType, fillType, ref blocks, ref buffer);
                            deep--;
                        }
                    }
                }

                //y
                if (fillType == 0 || fillType == 1 || fillType > 3)
                {
                    if (GetTile(x, (ushort)(y + 1), z, p.level, blocks) == oldType)
                    {
                        deep++;
                        FloodFill(p, x, (ushort)(y + 1), z, b, oldType, fillType, ref blocks, ref buffer);
                        deep--;
                    }
                }

                if (fillType == 0 || fillType == 2 || fillType > 3)
                {
                    if (y - 1 > 0)
                    {
                        if (GetTile(x, (ushort)(y - 1), z, p.level, blocks) == oldType)
                        {
                            deep++;
                            FloodFill(p, x, (ushort)(y - 1), z, b, oldType, fillType, ref blocks, ref buffer);
                            deep--;
                        }
                    }
                }
            } catch (Exception e) { Server.ErrorLog(e); }
        }
Exemplo n.º 11
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (!File.Exists("extra/copy/index.copydb"))
                {
                    Player.SendMessage(p, "No copy index found! Save something before trying to retrieve it!"); return;
                }
                if (message == "")
                {
                    Help(p); return;
                }
                if (message.Split(' ')[0] == "info")
                {
                    if (message.IndexOf(' ') != -1)
                    {
                        message = message.Split(' ')[1];
                        if (File.Exists("extra/copy/" + message + ".copy"))
                        {
                            StreamReader sR       = new StreamReader(File.OpenRead("extra/copy/" + message + ".copy"));
                            string       infoline = sR.ReadLine();
                            sR.Close();
                            sR.Dispose();
                            Player.SendMessage(p, infoline);
                            return;
                        }
                    }
                    else
                    {
                        Help(p);
                        return;
                    }
                }
                if (message.Split(' ')[0] == "find")
                {
                    message = message.Replace("find", "");
                    string storedcopies = ""; int maxCopies = 0; int findnum = 0; int currentnum = 0;
                    bool   isint = int.TryParse(message, out findnum);
                    if (message == "")
                    {
                        goto retrieve;
                    }
                    if (!isint)
                    {
                        message = message.Trim();
                        list.Clear();
                        foreach (string s in File.ReadAllLines("extra/copy/index.copydb"))
                        {
                            CopyOwner cO = new CopyOwner();
                            cO.file = s.Split(' ')[0];
                            cO.name = s.Split(' ')[1];
                            list.Add(cO);
                        }
                        List <CopyOwner> results = new List <CopyOwner>();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].name.ToLower() == message.ToLower())
                            {
                                storedcopies += ", " + list[i].file;
                            }
                        }
                        if (storedcopies == "")
                        {
                            Player.SendMessage(p, "No saves found for player: " + message);
                        }
                        else
                        {
                            Player.SendMessage(p, "Saved copy files: ");
                            Player.SendMessage(p, "&f " + storedcopies.Remove(0, 2));
                        }
                        return;
                    }

                    // SEARCH BASED ON NAME STUFF ABOVE HERE
                    if (isint)
                    {
                        maxCopies = findnum * 50; currentnum = maxCopies - 50;
                    }
                    retrieve :   DirectoryInfo di = new DirectoryInfo("extra/copy/");
                    FileInfo[] fi = di.GetFiles("*.copy");

                    if (maxCopies == 0)
                    {
                        foreach (FileInfo file in fi)
                        {
                            storedcopies += ", " + file.Name.Replace(".copy", "");
                        }
                        if (storedcopies != "")
                        {
                            Player.SendMessage(p, "Saved copy files: ");
                            Player.SendMessage(p, "&f " + storedcopies.Remove(0, 2));
                            if (fi.Length > 50)
                            {
                                Player.SendMessage(p, "For a more structured list, use /retrieve find <1/2/3/...>");
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "There are no saved copies.");
                        }
                    }
                    else
                    {
                        if (maxCopies > fi.Length)
                        {
                            maxCopies = fi.Length;
                        }
                        if (currentnum > fi.Length)
                        {
                            Player.SendMessage(p, "No saved copies beyond number " + fi.Length); return;
                        }

                        Player.SendMessage(p, "Saved copies (" + currentnum + " to " + maxCopies + "):");
                        for (int i = currentnum; i < maxCopies; i++)
                        {
                            storedcopies += ", " + fi[i].Name.Replace(".copy", "");
                        }
                        if (storedcopies != "")
                        {
                            Player.SendMessage(p, "&f" + storedcopies.Remove(0, 2));
                        }
                        else
                        {
                            Player.SendMessage(p, "There are no saved copies.");
                        }
                    }
                }
                else
                {
                    if (message.IndexOf(' ') == -1)
                    {
                        message = message.Split(' ')[0];
                        if (File.Exists("extra/copy/" + message + ".copy"))
                        {
                            p.CopyBuffer.Clear();
                            bool readFirst = false;
                            foreach (string s in File.ReadAllLines("extra/copy/" + message + ".copy"))
                            {
                                if (readFirst)
                                {
                                    Player.CopyPos cP;
                                    cP.x    = Convert.ToUInt16(s.Split(' ')[0]);
                                    cP.y    = Convert.ToUInt16(s.Split(' ')[1]);
                                    cP.z    = Convert.ToUInt16(s.Split(' ')[2]);
                                    cP.type = Convert.ToByte(s.Split(' ')[3]);
                                    p.CopyBuffer.Add(cP);
                                }
                                else
                                {
                                    readFirst = true;
                                }
                            }
                            Player.SendMessage(p, "&f" + message + Server.DefaultColor + " has been placed copybuffer.  Paste away!");
                        }
                        else
                        {
                            Player.SendMessage(p, "Could not find copy specified");
                            return;
                        }
                    }
                    else
                    {
                        Help(p);
                        return;
                    }
                }
            }
            catch (Exception e) { Player.SendMessage(p, "An error occured"); Server.ErrorLog(e); }
        }
Exemplo n.º 12
0
        public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
        {
            try
            {
                p.ClearBlockchange();
                CatchPos cpos = (CatchPos)p.blockchangeObject;
                if (cpos.type == Block.Zero)
                {
                    cpos.type = p.bindings[type];
                }

                byte oldType = p.level.GetTile(x, y, z);
                p.SendBlockchange(x, y, z, oldType);

                if (cpos.type == oldType)
                {
                    Player.SendMessage(p, "Cannot fill the same time"); return;
                }
                if (!Block.canPlace(p, oldType) && !Block.BuildIn(oldType))
                {
                    Player.SendMessage(p, "Cannot fill that."); return;
                }

                byte[]     mapBlocks = new byte[p.level.blocks.Length];
                List <Pos> buffer    = new List <Pos>();
                p.level.blocks.CopyTo(mapBlocks, 0);

                fromWhere.Clear();
                deep = 0;
                FloodFill(p, x, y, z, cpos.type, oldType, cpos.FillType, ref mapBlocks, ref buffer);

                int totalFill = fromWhere.Count;
                for (int i = 0; i < totalFill; i++)
                {
                    totalFill = fromWhere.Count;
                    Pos pos = fromWhere[i];
                    deep = 0;
                    FloodFill(p, pos.x, pos.y, pos.z, cpos.type, oldType, cpos.FillType, ref mapBlocks, ref buffer);
                    totalFill = fromWhere.Count;
                }
                fromWhere.Clear();

                if (buffer.Count > p.group.maxBlocks)
                {
                    Player.SendMessage(p, "You tried to fill " + buffer.Count + " blocks.");
                    Player.SendMessage(p, "You cannot fill more than " + p.group.maxBlocks + ".");
                    return;
                }

                foreach (Pos pos in buffer)
                {
                    p.level.Blockchange(p, pos.x, pos.y, pos.z, cpos.type);
                }

                Player.SendMessage(p, "Filled " + buffer.Count + " blocks.");
                buffer.Clear();

                if (p.staticCommands)
                {
                    p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
                }
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
            }
        }
Exemplo n.º 13
0
        public override void Use(Player p, string message)
        {
            try
            {
                List <groups> playerList = new List <groups>();

                foreach (Group grp in Group.GroupList)
                {
                    if (grp.name != "nobody")
                    {
                        groups groups;
                        groups.group   = grp;
                        groups.players = new List <string>();
                        playerList.Add(groups);
                    }
                }

                string devs         = "";
                int    totalPlayers = 0;
                foreach (Player pl in Player.players)
                {
                    if (!pl.hidden || p.group.Permission > LevelPermission.AdvBuilder || Server.devs.Contains(p.name.ToLower()))
                    {
                        totalPlayers++;
                        string foundName = pl.name;

                        if (Server.afkset.Contains(pl.name))
                        {
                            foundName = pl.name + "-afk";
                        }

                        if (Server.devs.Contains(pl.name.ToLower()))
                        {
                            if (pl.voice)
                            {
                                devs += " " + "&f+" + Server.DefaultColor + foundName + " (" + pl.level.name + "),";
                            }
                            else
                            {
                                devs += " " + foundName + " (" + pl.level.name + "),";
                            }
                        }
                        else
                        {
                            if (pl.voice)
                            {
                                playerList.Find(grp => grp.group == pl.group).players.Add("&f+" + Server.DefaultColor + foundName + " (" + pl.level.name + ")");
                            }
                            else
                            {
                                playerList.Find(grp => grp.group == pl.group).players.Add(foundName + " (" + pl.level.name + ")");
                            }
                        }
                    }
                }
                Player.SendMessage(p, "There are " + totalPlayers + " players online.");
                if (devs.Length > 0)
                {
                    Player.SendMessage(p, ":&9Developers:" + Server.DefaultColor + devs.Trim(','));
                }

                for (int i = playerList.Count - 1; i >= 0; i--)
                {
                    groups groups       = playerList[i];
                    string appendString = "";

                    foreach (string player in groups.players)
                    {
                        appendString += ", " + player;
                    }

                    if (appendString != "")
                    {
                        appendString = appendString.Remove(0, 2);
                    }
                    appendString = ":" + groups.group.color + getPlural(groups.group.trueName) + ": " + appendString;

                    Player.SendMessage(p, appendString);
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Exemplo n.º 14
0
 public override void Use(Player p, string message)
 { // TODO
     try
     {
         if (message != "")
         {
             Help(p); return;
         }
         message = "";
         string message2 = "";
         bool   Once     = false;
         Server.levels.ForEach(delegate(Level level)
         {
             if (level.permissionvisit <= p.group.Permission)
             {
                 if (Group.findPerm(level.permissionbuild) != null)
                 {
                     message += ", " + Group.findPerm(level.permissionbuild).color + level.name + " &b[" + level.physics + "]";
                 }
                 else
                 {
                     message += ", " + level.name + " &b[" + level.physics + "]";
                 }
             }
             else
             {
                 if (!Once)
                 {
                     Once = true;
                     if (Group.findPerm(level.permissionvisit) != null)
                     {
                         message2 += Group.findPerm(level.permissionvisit).color + level.name + " &b[" + level.physics + "]";
                     }
                     else
                     {
                         message2 += level.name + " &b[" + level.physics + "]";
                     }
                 }
                 else
                 {
                     if (Group.findPerm(level.permissionvisit) != null)
                     {
                         message2 += ", " + Group.findPerm(level.permissionvisit).color + level.name + " &b[" + level.physics + "]";
                     }
                     else
                     {
                         message2 += ", " + level.name + " &b[" + level.physics + "]";
                     }
                 }
             }
         });
         Player.SendMessage(p, "Loaded: " + message.Remove(0, 2));
         if (message2 != "")
         {
             Player.SendMessage(p, "Can't Goto: " + message2);
         }
         Player.SendMessage(p, "Use &4/unloaded for unloaded levels.");
     }
     catch (Exception e)
     {
         Server.ErrorLog(e);
     }
 }
Exemplo n.º 15
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }
            if (message[0] == '@')
            {
                message = message.Remove(0, 1).Trim();
                Player who = Player.Find(message);
                if (who == null)
                {
                    DataTable ip;
                    int       tryCounter = 0;
                    rerun :  try
                    {
                        ip = MySQL.fillData("SELECT IP FROM Players WHERE Name = '" + message + "'");
                    }
                    catch (Exception e)
                    {
                        tryCounter++;
                        if (tryCounter < 10)
                        {
                            goto rerun;
                        }
                        else
                        {
                            Server.ErrorLog(e);
                            return;
                        }
                    }
                    if (ip.Rows.Count > 0)
                    {
                        message = ip.Rows[0]["IP"].ToString();
                    }
                    else
                    {
                        Player.SendMessage(p, "Unable to find an IP address for that user.");
                        return;
                    }
                    ip.Dispose();
                }
                else
                {
                    message = who.ip;
                }
            }
            else
            {
                Player who = Player.Find(message);
                if (who != null)
                {
                    message = who.ip;
                }
            }

            if (message.Equals("127.0.0.1"))
            {
                Player.SendMessage(p, "You can't ip-ban the server!"); return;
            }
            if (message.IndexOf('.') == -1)
            {
                Player.SendMessage(p, "Invalid IP!"); return;
            }
            if (message.Split('.').Length != 4)
            {
                Player.SendMessage(p, "Invalid IP!"); return;
            }
            if (p != null)
            {
                if (p.ip == message)
                {
                    Player.SendMessage(p, "You can't ip-ban yourself.!"); return;
                }
            }
            if (Server.bannedIP.Contains(message))
            {
                Player.SendMessage(p, message + " is already ip-banned."); return;
            }
            Player.GlobalMessage(message + " got &8ip-banned!");
            if (p != null)
            {
                IRCBot.Say("IP-BANNED: " + message.ToLower() + " by " + p.name);
            }
            else
            {
                IRCBot.Say("IP-BANNED: " + message.ToLower() + " by console");
            }
            Server.bannedIP.Add(message);
            Server.bannedIP.Save("banned-ip.txt", false);
            Server.s.Log("IP-BANNED: " + message.ToLower());

            /*
             * foreach (Player pl in Player.players) {
             *  if (message == pl.ip) { pl.Kick("Kicked by ipban"); }
             * }*/
        }
Exemplo n.º 16
0
        public override void Use(Player p, string message)
        {
            if (!Directory.Exists("extra/text/"))
            {
                Directory.CreateDirectory("extra/text");
            }
            if (message == "")
            {
                DirectoryInfo di       = new DirectoryInfo("extra/text/");
                string        allFiles = "";
                foreach (FileInfo fi in di.GetFiles("*.txt"))
                {
                    try
                    {
                        string firstLine = File.ReadAllLines("extra/text/" + fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length) + ".txt")[0];
                        if (firstLine[0] == '#')
                        {
                            if (Group.Find(firstLine.Substring(1)).Permission <= p.group.Permission)
                            {
                                allFiles += ", " + fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);
                            }
                        }
                        else
                        {
                            allFiles += ", " + fi.Name;
                        }
                    } catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "Error"); }
                }

                if (allFiles == "")
                {
                    Player.SendMessage(p, "No files are viewable by you");
                }
                else
                {
                    Player.SendMessage(p, "Available files:");
                    Player.SendMessage(p, allFiles.Remove(0, 2));
                }
            }
            else
            {
                Player who = null;
                if (message.IndexOf(' ') != -1)
                {
                    who = Player.Find(message.Split(' ')[message.Split(' ').Length - 1]);
                    if (who != null)
                    {
                        message = message.Substring(0, message.LastIndexOf(' '));
                    }
                }
                if (who == null)
                {
                    who = p;
                }

                if (File.Exists("extra/text/" + message + ".txt"))
                {
                    try
                    {
                        string[] allLines = File.ReadAllLines("extra/text/" + message + ".txt");
                        if (allLines[0][0] == '#')
                        {
                            if (Group.Find(allLines[0].Substring(1)).Permission <= p.group.Permission)
                            {
                                for (int i = 1; i < allLines.Length; i++)
                                {
                                    Player.SendMessage(who, allLines[i]);
                                }
                            }
                            else
                            {
                                Player.SendMessage(p, "You cannot view this file");
                            }
                        }
                        else
                        {
                            for (int i = 1; i < allLines.Length; i++)
                            {
                                Player.SendMessage(who, allLines[i]);
                            }
                        }
                    } catch { Player.SendMessage(p, "An error occurred when retrieving the file"); }
                }
                else
                {
                    Player.SendMessage(p, "File specified doesn't exist");
                }
            }
        }
Exemplo n.º 17
0
        public override void Use(Player p, string message)
        {
            try
            {
                message.ToLower();
                switch (message)
                {
                case "":
                    if (Server.oldHelp)
                    {
                        goto case "old";
                    }
                    else
                    {
                        Player.SendMessage(p, "Use &b/help ranks" + Server.DefaultColor + " for a list of ranks.");
                        Player.SendMessage(p, "Use &b/help build" + Server.DefaultColor + " for a list of building commands.");
                        Player.SendMessage(p, "Use &b/help mod" + Server.DefaultColor + " for a list of moderation commands.");
                        Player.SendMessage(p, "Use &b/help information" + Server.DefaultColor + " for a list of information commands.");
                        Player.SendMessage(p, "Use &b/help other" + Server.DefaultColor + " for a list of other commands.");
                        Player.SendMessage(p, "Use &b/help short" + Server.DefaultColor + " for a list of shortcuts.");
                        Player.SendMessage(p, "Use &b/help old" + Server.DefaultColor + " to view the Old help menu.");
                        Player.SendMessage(p, "Use &b/help [command] or /help [block] " + Server.DefaultColor + "to view more info.");
                    } break;

                case "ranks":
                    message = "";
                    foreach (Group grp in Group.GroupList)
                    {
                        if (grp.name != "nobody")
                        {
                            Player.SendMessage(p, grp.color + grp.name + " - &bCommand limit: " + grp.maxBlocks + " - &cPermission: " + (int)grp.Permission);
                        }
                    }
                    break;

                case "build":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("build"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Building commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "mod":
                case "moderation":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("mod"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Moderation commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "information":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("info"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Information commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "other":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("other"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Other commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "short":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.shortcut != "")
                            {
                                message += ", &b" + comm.shortcut + " " + Server.DefaultColor + "[" + comm.name + "]";
                            }
                        }
                    }
                    Player.SendMessage(p, "Available shortcuts:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "old":
                    string commandsFound = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            try { commandsFound += ", " + comm.name; } catch { }
                        }
                    }
                    Player.SendMessage(p, "Available commands:");
                    Player.SendMessage(p, commandsFound.Remove(0, 2));
                    Player.SendMessage(p, "Type \"/help <command>\" for more help.");
                    Player.SendMessage(p, "Type \"/help shortcuts\" for shortcuts.");
                    break;

                default:
                    Command cmd = Command.all.Find(message);
                    if (cmd != null)
                    {
                        cmd.Help(p);
                        string foundRank = Level.PermissionToName(GrpCommands.allowedCommands.Find(grpComm => grpComm.commandName == cmd.name).lowestRank);
                        Player.SendMessage(p, "Rank needed: " + getColor(cmd.name) + foundRank);
                        return;
                    }
                    byte b = Block.Byte(message);
                    if (b != Block.Zero)
                    {
                        Player.SendMessage(p, "Block \"" + message + "\" appears as &b" + Block.Name(Block.Convert(b)));
                        string foundRank = Level.PermissionToName(Block.BlockList.Find(bs => bs.type == b).lowestRank);
                        Player.SendMessage(p, "Rank needed: " + foundRank);
                        return;
                    }
                    Player.SendMessage(p, "Could not find command or block specified.");
                    break;
                }
            }
            catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "An error occured"); }
        }
Exemplo n.º 18
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Player.SendMessage(p, "Basic blocks: ");
                    for (byte i = 0; i < 50; i++)
                    {
                        message += ", " + Block.Name(i);
                    }
                    Player.SendMessage(p, message.Remove(0, 2));
                    Player.SendMessage(p, "&d/blocks all <0/1/2/3/4> " + Server.DefaultColor + "will show the rest.");
                }
                else if (message.ToLower() == "all")
                {
                    Player.SendMessage(p, "Complex blocks: ");
                    for (byte i = 50; i < 255; i++)
                    {
                        if (Block.Name(i).ToLower() != "unknown")
                        {
                            message += ", " + Block.Name(i);
                        }
                    }
                    Player.SendMessage(p, message.Remove(0, 2));
                    Player.SendMessage(p, "Use &d/blocks all <0/1/2/3/4> " + Server.DefaultColor + "for a readable list.");
                }
                else if (message.ToLower().IndexOf(' ') != -1 && message.Split(' ')[0] == "all")
                {
                    int foundRange = 0;
                    try { foundRange = int.Parse(message.Split(' ')[1]); }
                    catch { Player.SendMessage(p, "Incorrect syntax"); return; }

                    if (foundRange >= 5 || foundRange < 0)
                    {
                        Player.SendMessage(p, "Number must be between 0 and 4"); return;
                    }

                    message = "";
                    Player.SendMessage(p, "Blocks between " + foundRange * 51 + " and " + (foundRange + 1) * 51);
                    for (byte i = (byte)(foundRange * 51); i < (byte)((foundRange + 1) * 51); i++)
                    {
                        if (Block.Name(i).ToLower() != "unknown")
                        {
                            message += ", " + Block.Name(i);
                        }
                    }
                    Player.SendMessage(p, message.Remove(0, 2));
                }
                else
                {
                    string printMessage = ">>>&b";

                    if (Block.Byte(message) != Block.Zero)
                    {
                        byte b = Block.Byte(message);
                        if (b < 51)
                        {
                            for (byte i = 51; i < 255; i++)
                            {
                                if (Block.Convert(i) == b)
                                {
                                    printMessage += Block.Name(i) + ", ";
                                }
                            }

                            if (printMessage != ">>>&b")
                            {
                                Player.SendMessage(p, "Blocks which look like \"" + message + "\":");
                                Player.SendMessage(p, printMessage.Remove(printMessage.Length - 2));
                            }
                            else
                            {
                                Player.SendMessage(p, "No Complex Blocks look like \"" + message + "\"");
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "&bComplex information for \"" + message + "\":");
                            Player.SendMessage(p, "&cBlock will appear as a \"" + Block.Name(Block.Convert(b)) + "\" block");

                            if (Block.LightPass(b))
                            {
                                Player.SendMessage(p, "Block will allow light through");
                            }
                            if (Block.Physics(b))
                            {
                                Player.SendMessage(p, "Block effects physics in some way");
                            }
                            else
                            {
                                Player.SendMessage(p, "Block will not effect physics in any way");
                            }
                            if (Block.NeedRestart(b))
                            {
                                Player.SendMessage(p, "The block's physics will auto-start");
                            }

                            if (Block.OPBlocks(b))
                            {
                                Player.SendMessage(p, "Block is unaffected by explosions");
                            }

                            if (Block.AllowBreak(b))
                            {
                                Player.SendMessage(p, "Anybody can activate the block");
                            }
                            if (Block.Walkthrough(b))
                            {
                                Player.SendMessage(p, "Block can be walked through");
                            }
                            if (Block.Death(b))
                            {
                                Player.SendMessage(p, "Walking through block will kill you");
                            }

                            if (Block.DoorAirs(b) != (byte)0)
                            {
                                Player.SendMessage(p, "Block is an ordinary door");
                            }
                            if (Block.tDoor(b))
                            {
                                Player.SendMessage(p, "Block is a tdoor, which allows other blocks through when open");
                            }
                            if (Block.odoor(b) != Block.Zero)
                            {
                                Player.SendMessage(p, "Block is an odoor, which toggles (GLITCHY)");
                            }

                            if (Block.Mover(b))
                            {
                                Player.SendMessage(p, "Block can be activated by walking through it");
                            }
                        }
                    }
                    else if (Group.Find(message) != null)
                    {
                        LevelPermission Perm = Group.Find(message).Permission;
                        foreach (Block.Blocks bL in Block.BlockList)
                        {
                            if (Block.canPlace(Perm, bL.type) && Block.Name(bL.type).ToLower() != "unknown")
                            {
                                printMessage += Block.Name(bL.type) + ", ";
                            }
                        }

                        if (printMessage != ">>>&b")
                        {
                            Player.SendMessage(p, "Blocks which " + Group.Find(message).color + Group.Find(message).name + Server.DefaultColor + " can place: ");
                            Player.SendMessage(p, printMessage.Remove(printMessage.Length - 2));
                        }
                        else
                        {
                            Player.SendMessage(p, "No blocks are specific to this rank");
                        }
                    }
                    else if (message.IndexOf(' ') == -1)
                    {
                        if (message.ToLower() == "count")
                        {
                            Player.SendMessage(p, "Blocks in this map: " + p.level.blocks.Length);
                        }
                        else
                        {
                            Help(p);
                        }
                    }
                    else if (message.Split(' ')[0].ToLower() == "count")
                    {
                        int foundNum = 0; byte foundBlock = Block.Byte(message.Split(' ')[1]);
                        if (foundBlock == Block.Zero)
                        {
                            Player.SendMessage(p, "Could not find block specified"); return;
                        }

                        for (int i = 0; i < p.level.blocks.Length; i++)
                        {
                            if (foundBlock == p.level.blocks[i])
                            {
                                foundNum++;
                            }
                        }

                        if (foundNum == 0)
                        {
                            Player.SendMessage(p, "No blocks were of type \"" + message.Split(' ')[1] + "\"");
                        }
                        else if (foundNum == 1)
                        {
                            Player.SendMessage(p, "1 block was of type \"" + message.Split(' ')[1] + "\"");
                        }
                        else
                        {
                            Player.SendMessage(p, foundNum.ToString() + " blocks were of type \"" + message.Split(' ')[1] + "\"");
                        }
                    }
                    else
                    {
                        Player.SendMessage(p, "Unable to find block or rank");
                    }
                }
            }
            catch (Exception e) { Server.ErrorLog(e); Help(p); }
        }