コード例 #1
0
        public static void TeleportHere(Sender sender, string[] commands)
        {
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }

                // /tp <player> <toplayer>
                if (commands.Length > 1 && commands[1] != null && commands[1].Trim().Length > 0)
                {
                    Player toplayer = Program.server.GetPlayerByName(commands[1].Trim());

                    if (toplayer == null)
                    {
                        sender.sendMessage("Could not find a Player on the Server");
                        return;
                    }

                    toplayer.teleportTo(player);

                    Program.server.notifyOps("Teleported " + toplayer.Name + " to " +
                        player.Name + " {" + sender.getName() + "}", true);

                    return;
                }
            }
            else
            {
                goto ERROR;
            }

            ERROR:
            sender.sendMessage("Command Error!");
        }
コード例 #2
0
        public static void Time(Sender sender, string[] commands)
        {
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (commands != null && commands.Length > 1)
            {
                if (commands[1] != null && commands[1].Length > 0)
                {
                    string caseType = commands[1].Trim().ToLower();

                    switch (caseType)
                    {
                        case "set":
                            {
                                if (commands.Length > 2 && commands[2] != null && commands[2].Length > 0)
                                {
                                    try
                                    {
                                    Program.server.getWorld().setTime(Double.Parse(commands[2]), true);
                                    } catch(Exception) {
                                        goto ERROR;
                                    }
                                }
                                else
                                {
                                    goto ERROR;
                                }
                                break;
                            }
                        case "day":
                            {
                                Program.server.getWorld().setTime(13500.0);
                                break;
                            }
                        case "dawn":
                            {
                                Program.server.getWorld().setTime(0);
                                break;
                            }
                        case "dusk":
                            {
                                Program.server.getWorld().setTime(0, false, false);
                                break;
                            }
                        case "noon":
                            {
                                Program.server.getWorld().setTime(27000.0);
                                break;
                            }
                        case "night":
                            {
                                Program.server.getWorld().setTime(16200.0, false, false);
                                break;
                            }
                        case "now":
                            {
                                string AP = "AM";
                                double time = Main.time;
                                if (!Main.dayTime)
                                {
                                    time += 54000.0;
                                }
                                time = time / 86400.0 * 24.0;
                                double num2 = 7.5; //stuffs me at this stage
                                time = time - num2 - 12.0;
                                if (time < 0.0)
                                {
                                    time += 24.0;
                                }
                                if (time >= 12.0)
                                {
                                    AP = "PM";
                                }
                                int Hours = (int)time;
                                double Minutes = time - (double)Hours;
                                string MinuteString = (Minutes * 60.0).ToString();
                                if (Minutes < 10.0)
                                {
                                    MinuteString = "0" + MinuteString;
                                }
                                if (Hours > 12)
                                {
                                    Hours -= 12;
                                }
                                if (Hours == 0)
                                {
                                    Hours = 12;
                                }
                                if (MinuteString.Length > 2)
                                {
                                    MinuteString = MinuteString.Substring(0, 2);
                                }
                                sender.sendMessage("Current Time: " + Hours + ":" + MinuteString + " " + AP);
                                return;
                            }
                        default:
                            {
                                goto ERROR;
                            }
                    }
                    NetMessage.SendData((int)Packet.WORLD_DATA); //Update Data
                    Program.server.notifyAll("Time set to " + Server.time.ToString() + " by " + sender.getName());
                    return;
                }
            }

            ERROR:
            sender.sendMessage("Command Error!");
        }
コード例 #3
0
        public static void OP(Sender sender, string[] commands, bool deop = false)
        {
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (((deop && commands.Length > 1) || (!deop && commands.Length > 2))
                && commands[1] != null
                && (deop || commands[2] != null)
                && commands[1].Trim().Length > 0
                && (deop || commands[2].Trim().Length > 0))
            {
                string player_OP = commands[1].Trim().ToLower();

                if (deop)
                {
                    Program.server.notifyOps("De-Opping " + player_OP + " {" + sender.getName() + "}", true);

                    if (Player.isInOpList(player_OP, Program.server))
                    {
                        Program.server.OpList.removeException(player_OP + ":" + Player.getPassword(player_OP, Program.server));
                    }
                }
                else
                {
                    string player_Password = commands[2].Trim().ToLower();
                    Program.server.notifyOps("Opping " + player_OP + " {" + sender.getName() + "}", true);
                    Program.server.OpList.addException(player_OP + ":" + player_Password);
                }

                if (!Program.server.OpList.Save())
                {
                    Program.server.notifyOps("OpList Failed to Save due to " + sender.getName() + "'s command", true);
                }
                return;
            }
            else
            {
                goto ERROR;
            }

            ERROR:
            sender.sendMessage("Command Error!");
        }
コード例 #4
0
        public static void OPLoginOut(Sender sender, string[] commands, bool logout = false)
        {
            if (sender is Player)
            {
                if (logout)
                {
                    if (sender.Op)
                    {
                        sender.Op = false;
                        sender.sendMessage("Successfully Logged Out.");
                    }
                    return;
                }

                if (commands.Length > 1 && commands[1] != null && commands[1].Trim().Length > 0)
                {
                    string player_Password = commands[1].Trim().ToLower();

                    if (Player.isInOpList(sender.getName(), Program.server))
                    {
                        if (((Player)sender).getPassword().Trim().ToLower() == player_Password)
                        {
                            sender.Op = true;
                            sender.sendMessage("Successfully Logged in as OP.");
                        }
                        else
                        {
                            sender.sendMessage("Incorrect OP Password.");
                            return;
                        }
                    }
                    else
                    {
                        sender.sendMessage("You need to be Assiged OP Privledges.");
                        return;
                    }
                    return;
                }
                else
                {
                    goto ERROR;
                }
            ERROR:
                sender.sendMessage("Command Error!");
            }
        }
コード例 #5
0
        public static void Kick(Sender sender, string[] commands)
        {
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (commands != null && commands.Length > 1)
            {
                if (commands[0] != null && commands[0].Length > 0)
                {
                    Player banee = Program.server.GetPlayerByName(commands[1]);

                    if (banee != null)
                    {
                        banee.Kick("You have been kicked from this Server.");
                    }
                    else
                    {
                        sender.sendMessage("Cannot find player online!.");
                    }
                    Program.server.notifyOps(sender.getName() + " has kicked " + commands[1], true);
                    return;
                }
            }
            sender.sendMessage("Command Error!");
        }
コード例 #6
0
        public static void Give(Sender sender, string[] commands)
        {
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }
            // /give <player> <stack> <name>
            if (commands.Length > 3 && commands[1] != null && commands[2] != null && commands[3] != null &&
                commands[1].Trim().Length > 0 && commands[2].Trim().Length > 0 && commands[3].Trim().Length > 0)
            {
                string playerName = commands[1].Trim();
                string itemName = MergeStringArray(commands);
                itemName = itemName.Remove(0, itemName.IndexOf(" " + commands[3]));

                Player player = Program.server.GetPlayerByName(playerName);
                if (player != null)
                {
                    Item[] items = new Item[Main.maxItemTypes];
                    for (int i = 0; i < Main.maxItemTypes; i++)
                    {
                        items[i] = new Item();
                        items[i].SetDefaults(i);
                    }

                    Item item = null;
                    itemName = itemName.Replace(" ", "").ToLower();
                    for (int i = 0; i < Main.maxItemTypes; i++)
                    {
                        if (items[i].Name != null)
                        {
                            string genItemName = items[i].Name.Replace(" ", "").Trim().ToLower();
                            if (genItemName == itemName)
                            {
                                item = items[i];
                            }
                        }
                    }

                    int itemType = -1;
                    bool assumed = false;
                    if (item != null)
                    {
                        itemType = item.Type;
                    }
                    else
                    {
                        int assumedItem;
                        try
                        {
                            assumedItem = Int32.Parse(itemName);
                        }
                        catch (Exception)
                        {
                            sender.sendMessage("Item '" + itemName + "' not found!");
                            return;
                        }

                        for (int i = 0; i < Main.maxItemTypes; i++)
                        {
                            if (items[i].Type == assumedItem)
                            {
                                itemType = items[i].Type;
                                assumed = true;
                                break;
                            }
                        }

                        if (!assumed)
                        {
                            sender.sendMessage("Item '" + itemName + "' not found!");
                            return;
                        }
                    }

                    //Clear Data
                    for (int i = 0; i < Main.maxItemTypes; i++)
                    {
                        items[i] = null;
                    }
                    items = null;

                    if (itemType != -1)
                    {

                        int stackSize;
                        try
                        {
                            stackSize = Int32.Parse(commands[2]);
                        }
                        catch (Exception)
                        {
                            stackSize = 1;
                        }

                        Item.NewItem((int)player.Position.X, (int)player.Position.Y, player.width, player.height, itemType, stackSize, false);

                        Program.server.notifyOps("Giving " + player.Name + " some " + itemType.ToString() + " {" + sender.getName() + "}", true);

                        return;
                    }
                }
                else
                {
                    sender.sendMessage("Player '" + playerName + "' not found!");
                    return;
                }
            }
            else
            {
                goto ERROR;
            }

            ERROR:
            sender.sendMessage("Command Error!");
        }
コード例 #7
0
        public static void BanList(Sender sender, string[] commands)
        {
            // /ban  <player>
            // /unban <player>

            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (commands != null && commands.Length > 1)
            {
                if (commands[0] != null && commands[0].Length > 0)
                {
                    int caseType = -1;

                    if (commands[0].Trim().ToLower().Equals("ban"))
                    {
                        caseType = 0;
                    }
                    else if (commands[0].Trim().ToLower().Equals("unban"))
                    {
                        caseType = 1;
                    }

                    switch (caseType)
                    {
                        case 0:
                            {
                                //We now should check to make sure they are off the server...
                                Player banee = Program.server.GetPlayerByName(commands[1]);

                                if (banee == null)
                                {
                                    foreach (Player player in Program.server.getPlayerList())
                                    {
                                        if (Netplay.serverSock[player.whoAmi].tcpClient.Client.RemoteEndPoint != null)
                                        {
                                            if (Netplay.serverSock[player.whoAmi].tcpClient.Client.RemoteEndPoint.ToString()
                                            .Split(':')[0].Equals(commands[1]))
                                            {
                                                banee = player;
                                            }
                                        }
                                    }
                                }

                                Program.server.BanList.addException(commands[1]);

                                if (banee != null)
                                {
                                    banee.Kick("You have been banned from this Server.");
                                    Program.server.BanList.addException(Netplay.serverSock[banee.whoAmi].
                                        tcpClient.Client.RemoteEndPoint.ToString().Split(':')[0]);
                                }
                                break;
                            }
                        case 1:
                            {
                                Program.server.BanList.removeException(commands[1]);
                                break;
                            }
                        default:
                            {
                                goto ERROR;
                            }

                    }

                    Program.server.notifyOps(sender.getName() + " used Ban command case " + caseType + " for: " + commands[1], true);

                    if (!Program.server.BanList.Save())
                    {
                        Program.server.notifyOps("BanList Failed to Save due to " + sender.getName() + "'s command", true);
                    }
                    return;
                }
            }

            ERROR:
            sender.sendMessage("Command Error!");
        }
コード例 #8
0
        public static void WhiteList(Sender sender, string[] commands)
        {
            // /whitelist <add:remove> <player>
            // arg  0         1           2
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.Op)
                {
                    player.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (commands != null && commands.Length > 2)
            {
                if (commands[1] != null && commands[2] != null && commands[1].Length > 0 && commands[2].Length > 0)
                {
                    string caseType = "ADD";

                    switch (commands[1].Trim().ToUpper())
                    {
                        case "ADD":
                            {
                                Program.server.WhiteList.addException(commands[2]);
                                break;
                            }
                        case "REMOVE":
                            {
                                Program.server.WhiteList.removeException(commands[2]);
                                caseType = "REMOVE";
                                break;
                            }
                        default:
                            {
                                goto ERROR;
                            }

                    }

                    Program.server.notifyOps(sender.getName() + " used WhiteList command " + caseType + " for: " + commands[2], true);

                    if (!Program.server.WhiteList.Save())
                    {
                        Program.server.notifyOps("WhiteList Failed to Save due to " + sender.getName() + "'s command", true);
                    }
                    return;
                }
            }
            ERROR:
            sender.sendMessage("Command args Error!");
        }
コード例 #9
0
        /*public static void ConCmd_setgroup(string input)
        {
            string[] split = input.Split(' ');
            if (split.Length < 2)
            {
                Console.WriteLine("USAGE: setgroup [player] [group]");
                return;
            }
            PlayerPermissions perm = Players.Find(item => item.Name == split[1]);
            if (perm == null) Players.Add(new PlayerPermissions(split[1], split[2], "", new List<string>()));
            else
            {
                int index = Players.IndexOf(perm);
                perm.Group = split[2];
                Players[index] = perm;
            }
            Console.WriteLine("Reloading permissions...");
            SavePermissions();
            LoadPermissions();
            Console.WriteLine("Permissions reloaded!");
        }
        public static void ConCmd_reloadpermissions(string input)
        {
            Console.WriteLine("Reloading permissions...");
            LoadPermissions();
            Console.WriteLine("Permissions reloaded!");
        }
        public static void ConCmd_savepermissions(string input)
        {
            Console.WriteLine("Saving permissions...");
            SavePermissions();
            Console.WriteLine("Permissions saved!");
        }

        public static void ConCmd_addpermission(string input)
        {
            string[] split = input.Split(' ');
            if (split.Length < 2)
            {
                Console.WriteLine("USAGE: addpermission [player] [node]");
                return;
            }
            PlayerPermissions perm = Players.Find(item => item.Name == split[1]);
            if (perm == null) Players.Add(new PlayerPermissions(split[1], "", "", new List<string>(new[] { split[2] })));
            else
            {
                int index = Players.IndexOf(perm);
                perm.Nodes.Add(split[2]);
                Players[index] = perm;
            }
            Console.WriteLine("Reloading permissions...");
            SavePermissions();
            LoadPermissions();
            Console.WriteLine("Permissions reloaded!");
        }
        public static void ConCmd_haspermission(string input)
        {
            string[] split = input.Split(' ');
            if (split.Length < 2)
            {
                Console.WriteLine("USAGE: haspermission [player] [node]");
                return;
            }
            Console.WriteLine(split[1] + (HasPermission(split[1], split[2]) ? " has" : " doesn't have") + " permissions for " + split[2]);
        }*/
        public static bool HasPermission(Sender sender, string node)
        {
            return sender.getName() == "CONSOLE" || Players.Find(item => item.Name == sender.getName()).HasPermission(node);
        }