コード例 #1
0
ファイル: CmdPause.cs プロジェクト: DireatClassicube/MCLawl
        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);
            }
        }
コード例 #2
0
        public void Start()
        {
            shuttingDown = false;
            Log("Starting 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 settings have 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("mainlevel not found");
                                mainLevel = new Level(Server.level, 128, 64, 128, "flat");

                                mainLevel.permissionvisit = LevelPermission.Guest;
                                mainLevel.permissionbuild = LevelPermission.Guest;
                                mainLevel.Save();
                            }
                        }
                    }
                    else
                    {
                        Log("mainlevel not found");
                        mainLevel = new Level(Server.level, 128, 64, 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");
            });
        }
コード例 #3
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!");
            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"); }
             * }*/
        }
コード例 #4
0
ファイル: CmdUnbanip.cs プロジェクト: DireatClassicube/MCLawl
        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());
        }
コード例 #5
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"); }
        }
コード例 #6
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); }
        }
コード例 #7
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;
            }
        }
コード例 #8
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); }
        }
コード例 #9
0
        public static Level Load(Stream lvlStream, string fileName)
        {
            byte[] temp = new byte[8];
            Level  lvl  = new Level(fileName, 0, 0, 0, "empty");

            byte[] data;
            int    length;

            try {
                lvlStream.Seek(-4, SeekOrigin.End);
                lvlStream.Read(temp, 0, sizeof(int));
                lvlStream.Seek(0, SeekOrigin.Begin);
                length = BitConverter.ToInt32(temp, 0);
                data   = new byte[length];
                using (GZipStream reader = new GZipStream(lvlStream, CompressionMode.Decompress, true)) {
                    reader.Read(data, 0, length);
                }

                for (int i = 0; i < length - 1; i++)
                {
                    if (data[i] == 0xAC && data[i + 1] == 0xED)
                    {
                        // bypassing the header crap
                        int pointer = i + 6;
                        Array.Copy(data, pointer, temp, 0, sizeof(short));
                        pointer += IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                        pointer += 13;

                        int headerEnd = 0;
                        // find the end of serialization listing
                        for (headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++)
                        {
                            if (data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70)
                            {
                                headerEnd += 2;
                                break;
                            }
                        }

                        // start parsing serialization listing
                        int offset = 0;
                        while (pointer < headerEnd)
                        {
                            if (data[pointer] == 'Z')
                            {
                                offset++;
                            }
                            else if (data[pointer] == 'I' || data[pointer] == 'F')
                            {
                                offset += 4;
                            }
                            else if (data[pointer] == 'J')
                            {
                                offset += 8;
                            }

                            pointer += 1;
                            Array.Copy(data, pointer, temp, 0, sizeof(short));
                            short skip = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                            pointer += 2;

                            // look for relevant variables
                            Array.Copy(data, headerEnd + offset - 4, temp, 0, sizeof(int));
                            if (MemCmp(data, pointer, "width"))
                            {
                                lvl.width = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                            }
                            else if (MemCmp(data, pointer, "depth"))
                            {
                                lvl.depth = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                            }
                            else if (MemCmp(data, pointer, "height"))
                            {
                                lvl.height = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                            }

                            pointer += skip;
                        }

                        lvl.spawnx = (ushort)(lvl.width / 1.3);
                        lvl.spawny = (ushort)(lvl.depth / 1.3);
                        lvl.spawnz = (ushort)(lvl.height / 1.3);

                        // find the start of the block array
                        bool foundBlockArray = false;
                        offset = Array.IndexOf <byte>(data, 0x00, headerEnd);
                        while (offset != -1 && offset < data.Length - 2)
                        {
                            if (data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70)
                            {
                                foundBlockArray = true;
                                pointer         = offset + 7;
                            }
                            offset = Array.IndexOf <byte>(data, 0x00, offset + 1);
                        }

                        // copy the block array... or fail
                        if (foundBlockArray)
                        {
                            lvl.CopyBlocks(data, pointer);
                            lvl.Save(true);
                        }
                        else
                        {
                            throw new Exception("Could not locate block array.");
                        }
                        break;
                    }
                }
            } catch (Exception ex) {
                Server.s.Log("Conversion failed");
                Server.ErrorLog(ex);
                return(null);
            }

            return(lvl);
        }
コード例 #10
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)
                {
#pragma warning disable CS0618 // 'Thread.Resume()" является устаревшим: 'Thread.Resume has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202'
                    foundLevel.physThread.Resume();
#pragma warning restore CS0618 // 'Thread.Resume()" является устаревшим: 'Thread.Resume has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202'
                    foundLevel.physResume = DateTime.Now;
                    foundLevel.physPause  = false;
                    Player.GlobalMessage("Physics on " + foundLevel.name + " were re-enabled.");
                }
                else
                {
#pragma warning disable CS0618 // 'Thread.Suspend()" является устаревшим: 'Thread.Suspend has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202'
                    foundLevel.physThread.Suspend();
#pragma warning restore CS0618 // 'Thread.Suspend()" является устаревшим: 'Thread.Suspend has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202'
                    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
                            {
#pragma warning disable CS0618 // 'Thread.Resume()" является устаревшим: 'Thread.Resume has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202'
                                foundLevel.physThread.Resume();
#pragma warning restore CS0618 // 'Thread.Resume()" является устаревшим: 'Thread.Resume has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202'
                            }
                            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);
            }
        }
コード例 #11
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Help(p); return;
                }

                bool stealth = false; bool totalBan = false;
                if (message[0] == '#')
                {
                    message = message.Remove(0, 1).Trim();
                    stealth = true;
                    Server.s.Log("Stealth Ban Attempted");
                }
                else if (message[0] == '@')
                {
                    totalBan = true;
                    message  = message.Remove(0, 1).Trim();
                }

                Player who = Player.Find(message);

                if (who == null)
                {
                    if (!Player.ValidName(message))
                    {
                        Player.SendMessage(p, "Invalid name \"" + message + "\".");
                        return;
                    }

                    Group foundGroup = Group.findPlayerGroup(message);

                    if (foundGroup.Permission >= LevelPermission.Operator)
                    {
                        Player.SendMessage(p, "You can't ban a " + foundGroup.name + "!");
                        return;
                    }
                    if (foundGroup.Permission == LevelPermission.Banned)
                    {
                        Player.SendMessage(p, message + " is already banned.");
                        return;
                    }

                    foundGroup.playerList.Remove(message);
                    foundGroup.playerList.Save();

                    Player.GlobalMessage(message + " &f(offline)" + Server.DefaultColor + " is now &8banned" + Server.DefaultColor + "!");
                    Group.findPerm(LevelPermission.Banned).playerList.Add(message);
                }
                else
                {
                    if (!Player.ValidName(who.name))
                    {
                        Player.SendMessage(p, "Invalid name \"" + who.name + "\".");
                        return;
                    }

                    if (who.group.Permission >= LevelPermission.Operator)
                    {
                        Player.SendMessage(p, "You can't ban a " + who.group.name + "!");
                        return;
                    }
                    if (who.group.Permission == LevelPermission.Banned)
                    {
                        Player.SendMessage(p, message + " is already banned.");
                        return;
                    }

                    who.group.playerList.Remove(message);
                    who.group.playerList.Save();

                    if (stealth)
                    {
                        Player.GlobalMessageOps(who.color + who.name + Server.DefaultColor + " is now STEALTH &8banned" + Server.DefaultColor + "!");
                    }
                    else
                    {
                        Player.GlobalChat(who, who.color + who.name + Server.DefaultColor + " is now &8banned" + Server.DefaultColor + "!", false);
                    }

                    who.group = Group.findPerm(LevelPermission.Banned);
                    who.color = who.group.color;
                    Player.GlobalDie(who, false);
                    Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false);
                    Group.findPerm(LevelPermission.Banned).playerList.Add(who.name);
                }
                Group.findPerm(LevelPermission.Banned).playerList.Save();

                IRCBot.Say(message + " was banned.");
                Server.s.Log("BANNED: " + message.ToLower());

                if (totalBan == true)
                {
                    Command.all.Find("undo").Use(p, message + " 0");
                    Command.all.Find("banip").Use(p, "@ " + message);
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
コード例 #12
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);
                }
            }
        }
コード例 #13
0
        public static void retrieveMapSettings(string str)
        {
            try
            {
                if (!File.Exists(configPath + str))
                {
                    Server.s.Log("Config file is empty!"); return;
                }

                foreach (string line in File.ReadAllLines(configPath + str))
                {
                    if (line != "" && line[0] != '#')
                    {
                        string key   = line.Split('=')[0].Trim();
                        string value = line.Split('=')[1].Trim();

                        switch (key.ToLower())
                        {
                            #region Blue flag spawn

                        case "blue.flag.x":
                            CTF.redTeam.flagSpawn[0] = ushort.Parse(value);
                            break;

                        case "blue.flag.y":
                            CTF.redTeam.flagSpawn[1] = ushort.Parse(value);
                            break;

                        case "blue.flag.z":
                            CTF.redTeam.flagSpawn[2] = ushort.Parse(value);
                            break;
                            #endregion

                            #region Blue team spawn
                        case "blue.team.x":
                            CTF.blueTeam.teamSpawn[0] = ushort.Parse(value);
                            break;

                        case "blue.team.y":
                            CTF.blueTeam.teamSpawn[1] = ushort.Parse(value);
                            break;

                        case "blue.team.z":
                            CTF.blueTeam.teamSpawn[2] = ushort.Parse(value);
                            break;


                            #endregion


                            #region Red flag spawn
                        case "red.flag.x":
                            CTF.redTeam.flagSpawn[0] = ushort.Parse(line);
                            break;

                        case "red.flag.y":
                            CTF.redTeam.flagSpawn[1] = ushort.Parse(line);
                            break;

                        case "red.flag.z":
                            CTF.redTeam.flagSpawn[2] = ushort.Parse(line);
                            break;
                            #endregion

                            #region Red team spawn
                        case "red.team.x":
                            CTF.redTeam.teamSpawn[0] = ushort.Parse(value);
                            break;

                        case "red.team.y":
                            CTF.redTeam.teamSpawn[1] = ushort.Parse(value);
                            break;

                        case "red.team.z":
                            CTF.redTeam.teamSpawn[2] = ushort.Parse(value);
                            break;


                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Server.ErrorLog(ex);
            }
        }
コード例 #14
0
        public override void Use(Player p, string message)
        {
            byte   b; Int64 seconds;
            Player who;

            Player.UndoPos Pos;
            int            CurrentPos = 0;
            bool           FoundUser  = false;

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

            if (message.Split(' ').Length == 2)
            {
                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 = 300;
                    message = message + " 300";
                }
            }

            if (seconds == 0)
            {
                seconds = 5400;
            }

            who = Player.Find(message.Split(' ')[0]);
            if (who != null)
            {
                message   = who.name + " " + seconds;
                FoundUser = true;
                for (CurrentPos = who.UndoBuffer.Count - 1; CurrentPos >= 0; --CurrentPos)
                {
                    try
                    {
                        Pos = who.UndoBuffer[CurrentPos];
                        Level foundLevel = Level.Find(Pos.mapName);
                        if (foundLevel == p.level)
                        {
                            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)
                                {
                                    if (b == Block.air || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava)
                                    {
                                        p.SendBlockchange(Pos.x, Pos.y, Pos.z, Block.red);
                                    }
                                    else
                                    {
                                        p.SendBlockchange(Pos.x, Pos.y, Pos.z, Block.green);
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch { }
                }
            }

            try
            {
                DirectoryInfo di;
                string[]      fileContent;

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

                    for (int i = 0; i < di.GetFiles("*.undo").Length; i++)
                    {
                        fileContent = File.ReadAllText("extra/undo/" + message.Split(' ')[0] + "/" + i + ".undo").Split(' ');
                        highlightStuff(fileContent, seconds, p);
                    }
                    FoundUser = true;
                }

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

                    for (int i = 0; i < di.GetFiles("*.undo").Length; i++)
                    {
                        fileContent = File.ReadAllText("extra/undoPrevious/" + message.Split(' ')[0] + "/" + i + ".undo").Split(' ');
                        highlightStuff(fileContent, seconds, p);
                    }
                    FoundUser = true;
                }

                if (FoundUser)
                {
                    Player.SendMessage(p, "Now highlighting &b" + seconds + Server.DefaultColor + " seconds for " + Server.FindColor(message.Split(' ')[0]) + message.Split(' ')[0]);
                    Player.SendMessage(p, "&cUse /reveal to un-highlight");
                }
                else
                {
                    Player.SendMessage(p, "Could not find player specified.");
                }
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
            }
        }
コード例 #15
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); }
        }
コード例 #16
0
ファイル: CmdLoad.cs プロジェクト: tyabus/MCLawl
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Help(p); return;
                }
                if (message.Split(' ').Length > 2)
                {
                    Help(p); return;
                }
                int    pos  = message.IndexOf(' ');
                string phys = "0";
                if (pos != -1)
                {
                    phys    = message.Substring(pos + 1);
                    message = message.Substring(0, pos).ToLower();
                }
                else
                {
                    message = message.ToLower();
                }

                foreach (Level l in Server.levels)
                {
                    if (l.name == message)
                    {
                        Player.SendMessage(p, message + " is already loaded!"); return;
                    }
                }

                if (Server.levels.Count == Server.levels.Capacity)
                {
                    if (Server.levels.Capacity == 1)
                    {
                        Player.SendMessage(p, "You can't load any levels!");
                    }
                    else
                    {
                        Command.all.Find("unload").Use(p, "empty");
                        if (Server.levels.Capacity == 1)
                        {
                            Player.SendMessage(p, "No maps are empty to unload. Cannot load map.");
                            return;
                        }
                    }
                }

                if (!File.Exists("levels/" + message + ".lvl"))
                {
                    Player.SendMessage(p, "Level \"" + message + "\" doesn't exist!"); return;
                }

                Level level = Level.Load(message);

                if (level == null)
                {
                    if (File.Exists("levels/" + message + ".lvl.backup"))
                    {
                        Server.s.Log("Attempting to load backup.");
                        File.Copy("levels/" + message + ".lvl.backup", "levels/" + message + ".lvl", true);
                        level = Level.Load(message);
                        if (level == null)
                        {
                            Player.SendMessage(p, "Backup of " + message + " failed.");
                            return;
                        }
                    }
                    else
                    {
                        Player.SendMessage(p, "Backup of " + message + " does not exist.");
                        return;
                    }
                }

                if (p != null)
                {
                    if (level.permissionvisit > p.group.Permission)
                    {
                        Player.SendMessage(p, "This map is for " + Level.PermissionToName(level.permissionvisit) + " only!");
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        return;
                    }
                }

                foreach (Level l in Server.levels)
                {
                    if (l.name == message)
                    {
                        Player.SendMessage(p, message + " is already loaded!");
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        return;
                    }
                }

                lock (Server.levels) {
                    Server.addLevel(level);
                }

                level.physThread.Start();
                Player.GlobalMessage("Level \"" + level.name + "\" loaded.");
                try
                {
                    int temp = int.Parse(phys);
                    if (temp >= 1 && temp <= 4)
                    {
                        level.setPhysics(temp);
                    }
                }
                catch
                {
                    Player.SendMessage(p, "Physics variable invalid");
                }
            }
            catch (Exception e)
            {
                Player.GlobalMessage("An error occured with /load");
                Server.ErrorLog(e);
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
コード例 #17
0
ファイル: CmdView.cs プロジェクト: tyabus/MCLawl
        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");
                }
            }
        }
コード例 #18
0
ファイル: CmdBotAI.cs プロジェクト: DireatClassicube/MCLawl
        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); }
        }
コード例 #19
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Help(p); return;
                }

                if (message.IndexOf(' ') == -1)
                {
                    if (File.Exists("extra/copy/" + message + ".copy"))
                    {
                        Player.SendMessage(p, "File: &f" + message + Server.DefaultColor + " already exists.  Delete first");
                        return;
                    }
                    else
                    {
                        Player.SendMessage(p, "Storing: " + message);
                        StreamWriter sW = new StreamWriter(File.Create("extra/copy/" + message + ".copy"));
                        sW.WriteLine("Saved by: " + p.name + " at " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss "));
                        for (int k = 0; k < p.CopyBuffer.Count; k++)
                        {
                            sW.WriteLine(p.CopyBuffer[k].x + " " + p.CopyBuffer[k].y + " " + p.CopyBuffer[k].z + " " + p.CopyBuffer[k].type);
                        }
                        sW.Flush();
                        sW.Close();

                        sW = File.AppendText("extra/copy/index.copydb");
                        sW.WriteLine(message + " " + p.name);
                        sW.Flush();
                        sW.Close();
                    }
                }
                else
                {
                    if (message.Split(' ')[0] == "delete")
                    {
                        message = message.Split(' ')[1];
                        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);
                        }
                        CopyOwner result = list.Find(
                            delegate(CopyOwner cO) {
                            return(cO.file == message);
                        }
                            );

                        if (p.group.Permission >= LevelPermission.Operator || result.name == p.name)
                        {
                            if (File.Exists("extra/copy/" + message + ".copy"))
                            {
                                try
                                {
                                    if (File.Exists("extra/copyBackup/" + message + ".copy"))
                                    {
                                        File.Delete("extra/copyBackup/" + message + ".copy");
                                    }
                                    File.Move("extra/copy/" + message + ".copy", "extra/copyBackup/" + message + ".copy");
                                }
                                catch { }
                                Player.SendMessage(p, "File &f" + message + Server.DefaultColor + " has been deleted.");
                                list.Remove(result);
                                File.Delete("extra/copy/index.copydb");
                                StreamWriter sW = new StreamWriter(File.Create("extra/copy/index.copydb"));
                                foreach (CopyOwner cO in list)
                                {
                                    sW.WriteLine(cO.file + " " + cO.name);
                                }
                                sW.Flush();
                                sW.Close();
                            }
                            else
                            {
                                Player.SendMessage(p, "File does not exist.");
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "You must be an operator or file owner to delete a save.");
                            return;
                        }
                    }
                    else
                    {
                        Help(p); return;
                    }
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
コード例 #20
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); }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
ファイル: MapGenerator.cs プロジェクト: dekema2/MCDek
        public bool GenerateMap(Level Lvl, string type)
        {
            Server.s.Log("Attempting map gen");
            if (Inuse)
            {
                Server.s.Log("Generator in use"); return(false);
            }
            Random rand = new System.Random();

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

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

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

                if (type.Equals("ocean"))
                {
                    WaterLevel = (ushort)(Lvl.depth * 0.85f);
                }

                //Generate the level
                GenerateFault(terrain, Lvl, type, rand);

                //APPLY FILTER to terrain
                FilterAverage(Lvl);

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

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

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

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

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

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

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

                default:
                    break;
                }

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

                        if (overlay[bb] < 0.25f && type != "desert")    //Zoned for flowers
                        {
                            int temprand = rand.Next(12);

                            switch (temprand)
                            {
                            case 10:
                                Lvl.skipChange(x, (ushort)(z + 1), y, Block.redflower);
                                break;

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

                            default:
                                break;
                            }
                        }

                        if (!type.Equals("ocean"))
                        {
                            if (overlay[bb] < 0.65f && overlay2[bb] < TreeDens)
                            {
                                if (Lvl.GetTile(x, (ushort)(z + 1), y) == Block.air)
                                {
                                    if (Lvl.GetTile(x, z, y) == Block.grass || type == "desert")
                                    {
                                        if (rand.Next(13) == 0)
                                        {
                                            if (!TreeCheck(Lvl, x, z, y, TreeDist))
                                            {
                                                if (type == "desert")
                                                {
                                                    AddCactus(Lvl, x, (ushort)(z + 1), y, rand);
                                                }
                                                else
                                                {
                                                    AddTree(Lvl, x, (ushort)(z + 1), y, rand);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else    //Must be on/under the water line then
                    {
                        for (ushort zz = 0; WaterLevel - zz >= 0; zz++)
                        {
                            if (WaterLevel - zz > z)
                            {
                                Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.water);
                            }                                                                    //better fill the water aboce me
                            else if (WaterLevel - zz > z - 3)
                            {
                                if (overlay[bb] < 0.75f)
                                {
                                    Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.sand);   //sand top
                                }
                                else
                                {
                                    Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.gravel);  //zoned for gravel
                                }
                            }
                            else
                            {
                                Lvl.skipChange(x, (ushort)(WaterLevel - zz), y, Block.rock);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
                Server.s.Log("Gen Fail");
                Inuse = false;
                return(false);
            }

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

            Inuse = false;

            return(true);
        }
コード例 #23
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); }
        }
コード例 #24
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
        }
コード例 #25
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(MCLawl.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);
     }
 }
コード例 #26
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.");
     }
 }
コード例 #27
0
        public override void Use(Player p, string message)
        {
            if (!p.canBuild)
            {
                Player.SendMessage(p, "You're currently being &4possessed" + Server.DefaultColor + "!");
                return;
            }
            try
            {
                bool stealth = false;

                if (message != "")
                {
                    if (message == "#")
                    {
                        if (p.following != "")
                        {
                            stealth = true;
                            message = "";
                        }
                        else
                        {
                            Help(p);
                            return;
                        }
                    }
                    else if (message.IndexOf(' ') != -1)
                    {
                        if (message.Split(' ')[0] == "#")
                        {
                            if (p.hidden)
                            {
                                stealth = true;
                            }
                            message = message.Split(' ')[1];
                        }
                    }
                }

                Player who = Player.Find(message);
                if (message == "" && p.following == "")
                {
                    Help(p);
                    return;
                }
                else if (message == "" && p.following != "" || message == p.following)
                {
                    who         = Player.Find(p.following);
                    p.following = "";
                    if (p.hidden)
                    {
                        if (who != null)
                        {
                            p.SendSpawn(who.id, who.color + who.name, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]);
                        }
                        if (!stealth)
                        {
                            Command.all.Find("hide").Use(p, "");
                        }
                        else
                        {
                            if (who != null)
                            {
                                Player.SendMessage(p, "You have stopped following " + who.color + who.name + Server.DefaultColor + " and remained hidden.");
                            }
                            else
                            {
                                Player.SendMessage(p, "Following stopped.");
                            }
                        }
                        return;
                    }
                }
                if (who == null)
                {
                    Player.SendMessage(p, "Could not find player."); return;
                }
                else if (who == p)
                {
                    Player.SendMessage(p, "Cannot follow yourself."); return;
                }
                else if (who.group.Permission >= p.group.Permission)
                {
                    Player.SendMessage(p, "Cannot follow someone of equal or greater rank."); return;
                }
                else if (who.following != "")
                {
                    Player.SendMessage(p, who.name + " is already following " + who.following); return;
                }

                if (!p.hidden)
                {
                    Command.all.Find("hide").Use(p, "");
                }

                if (p.level != who.level)
                {
                    Command.all.Find("tp").Use(p, who.name);
                }
                if (p.following != "")
                {
                    who = Player.Find(p.following);
                    p.SendSpawn(who.id, who.color + who.name, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]);
                }
                who         = Player.Find(message);
                p.following = who.name;
                Player.SendMessage(p, "Following " + who.name + ". Use \"/follow\" to stop.");
                p.SendDie(who.id);
            }
            catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "Error occured"); }
        }