public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            if (parameters.Length != 1)
            {
                user.SendChat(ChatColors.Red + "Incorrect usage. Use /help difficulty for more information.");
                return;
            }
            Difficulty value;
            int        num;

            if (int.TryParse(text, out num))
            {
                if (num < 0 || num > 3)
                {
                    user.SendChat(ChatColors.Red + "Invalid difficulty specified.");
                    return;
                }
                value = (Difficulty)num;
            }
            else
            {
                if (!Enum.TryParse <Difficulty>(text, true, out value))
                {
                    user.SendChat(ChatColors.Red + "Invalid difficulty specified.");
                    return;
                }
            }
            //user.World.Difficulty = value; // TODO
            server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " sets difficulty of " + user.World.Name + " to " + value.ToString());
        }
示例#2
0
        public static void Handshake(RemoteClient client, Proxy proxy, IPacket _packet)
        {
            var packet = (HandshakePacket)_packet;

            client.SendChat(ChatColors.Yellow + "Logged into " + packet.PartyName);
            client.SendChat(ChatColors.Yellow + "Message of the Day: " + packet.KeyOrMOTD);
        }
示例#3
0
        public static void ExecuteCommand(Server server, RemoteClient user, string text)
        {
            string name = text.Substring(1);
            if (string.IsNullOrEmpty(name))
                return;
            var parameters = new string[0];
            var userText = "";
            if (name.Contains(" "))
            {
                name = name.Remove(name.IndexOf(' '));
                userText = text.Substring(text.IndexOf(' ') + 1);
                parameters = userText.Split(' ');
            }
            var command = GetCommand(name);

            if (command == null)
            {
                user.SendChat(ChatColors.Red + "That command was not found.");
                return;
            }

            if (!MayUseCommand(command, user, server))
            {
                user.SendChat(ChatColors.Red + "You do not have permission to use that command.");
                return;
            }
            command.Execute(server, user, userText, parameters);
        }
示例#4
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            if (parameters.Length < 2)
            {
                user.SendChat(ChatColors.Red + "Insufficient parameters. Use \"/help tell\" for more information.");
                return;
            }
            var client = server.MinecraftServer.GetClient(parameters[0]);

            if (client == null)
            {
                user.SendChat(parameters[0] + " is not online.");
                return;
            }
            var format = server.SettingsProvider.Get <string>("chat.private.format");

            client.SendChat(string.Format(format, user.Username, client.Username, text));
        }
示例#5
0
 public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
 {
     if (parameters.Length != 1)
     {
         user.SendChat(ChatColors.Red + "Invalid parameters. Use /help op for more information.");
         return;
     }
     // TODO
 }
示例#6
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            if (parameters.Length != 1)
            {
                user.SendChat(ChatColors.Red + "Invalid parameters. Use /help op for more information.");
                return;
            }
            var groups = server.GetUserGroups(parameters[0]);

            if (groups.Contains("server.op"))
            {
                user.SendChat(ChatColors.Red + "User is already an op.");
                return;
            }
            groups.Add("server.op");
            server.SetUserGroups(parameters[0], groups);
            server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " adds " + parameters[0] + " to server.op group.");
        }
示例#7
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            string   player = user.Username;
            GameMode gameMode;

            if (parameters.Length == 0 || parameters.Length > 2)
            {
                user.SendChat(ChatColors.Red + "Incorrect usage. Use /help gamemode for more information.");
                return;
            }
            int value;

            if (int.TryParse(parameters[0], out value))
            {
                if (value < 0 || value > 2)
                {
                    user.SendChat(ChatColors.Red + "Incorrect usage. Use /help gamemode for more information.");
                    return;
                }
                gameMode = (GameMode)value;
            }
            else
            {
                if (!Enum.TryParse <GameMode>(parameters[0], true, out gameMode))
                {
                    user.SendChat(ChatColors.Red + "Incorrect usage. Use /help gamemode for more information.");
                    return;
                }
            }
            if (parameters.Length == 2)
            {
                player = parameters[1];
            }
            var client = server.MinecraftServer.GetClient(player);

            if (client == null)
            {
                user.SendChat(ChatColors.Red + player + " is not online."); // TODO: Set it anyway
                return;
            }
            client.GameMode = gameMode;
            server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " sets " + player + " to " + gameMode + " mode.");
        }
示例#8
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            if (parameters.Length > 2 || parameters.Length == 0)
            {
                user.SendChat(ChatColors.Red + "Incorrect usage. Use /help speed for more information.");
                return;
            }
            if (parameters[0].ToLower() == "reset")
            {
                user.Entity.Abilities.WalkingSpeed = 12;
                user.Entity.Abilities.FlyingSpeed  = 24;
                return;
            }
            string player = user.Username;
            int    speed;

            if (parameters.Length == 2)
            {
                player = parameters[0];
                if (!int.TryParse(parameters[1], out speed))
                {
                    user.SendChat(ChatColors.Red + "Incorrect usage. Use /help speed for more information.");
                    return;
                }
            }
            else
            {
                if (!int.TryParse(parameters[0], out speed))
                {
                    user.SendChat(ChatColors.Red + "Incorrect usage. Use /help speed for more information.");
                    return;
                }
            }
            var client = server.MinecraftServer.GetClient(player);

            if (client == null)
            {
                user.SendChat(ChatColors.Red + player + " is not online.");
                return;
            }
            client.Entity.Abilities.WalkingSpeed = (byte)speed;
            client.Entity.Abilities.FlyingSpeed  = (byte)(speed * 2);
        }
示例#9
0
 public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
 {
     Server = server;
     if (parameters.Length != 0)
     {
         user.SendChat(ChatColors.Red + "Invalid parameters. Use /help repl for more information.");
         return;
     }
     if (ReplContext.Self != null)
     {
         user.SendChat(ChatColors.Red + ReplContext.Self.Username + " is currently in REPL mode. Only one user may be in REPL mode at a time.");
         // TODO: Upgrade Mono.CSharp to Mono 3.0 and support several REPLs at once
         return;
     }
     server.ChatMessage -= HandleChatMessage;
     server.ChatMessage += HandleChatMessage;
     server.MinecraftServer.PlayerLoggedOut += (s, e) =>
     {
         if (Evaluators.ContainsKey(e.Username))
         {
             Evaluators.Remove(e.Username);
         }
         ReplContext.Self = null;
     };
     Evaluators[user.Username] = new Evaluator(new CompilerContext(new CompilerSettings(), new MinecraftReportPrinter(user)));
     Evaluators[user.Username].ReferenceAssembly(typeof(Server).Assembly);
     Evaluators[user.Username].ReferenceAssembly(typeof(MinecraftServer).Assembly);
     Evaluators[user.Username].ReferenceAssembly(typeof(Craft.Net.Networking.IPacket).Assembly);
     Evaluators[user.Username].ReferenceAssembly(typeof(World).Assembly);
     Evaluators[user.Username].ReferenceAssembly(typeof(IServer).Assembly);
     Evaluators[user.Username].InteractiveBaseClass = typeof(ReplContext);
     Evaluators[user.Username].Run("using Craft.Net");
     Evaluators[user.Username].Run("using Craft.Net.Data");
     Evaluators[user.Username].Run("using Craft.Net.Data.Blocks");
     Evaluators[user.Username].Run("using Craft.Net.Data.Items");
     Evaluators[user.Username].Run("using Craft.Net.Server");
     Evaluators[user.Username].Run("using PartyCraft");
     ReplContext.Self   = user;
     ReplContext.Server = server;
     user.SendChat(ChatColors.Blue + "Entering C# Interactive Mode");
     user.SendChat(ChatColors.Blue + "Use `Exit()` to exit REPL mode.");
 }
示例#10
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            string player = user.Username;
            int    x      = (int)user.Entity.Position.X;
            int    y      = (int)user.Entity.Position.Y;
            int    z      = (int)user.Entity.Position.Z;

            if (parameters.Length == 1)
            {
                player = parameters[0];
            }
            else if (parameters.Length == 3)
            {
                if (!int.TryParse(parameters[0], out x) &&
                    !int.TryParse(parameters[1], out y) &&
                    !int.TryParse(parameters[2], out z))
                {
                    user.SendChat(ChatColors.Red + "Incorrect usage. Use /help spawnpoint for more information.");
                    return;
                }
            }
            else if (parameters.Length == 4)
            {
                player = parameters[0];
                if (!int.TryParse(parameters[1], out x) &&
                    !int.TryParse(parameters[2], out y) &&
                    !int.TryParse(parameters[3], out z))
                {
                    user.SendChat(ChatColors.Red + "Incorrect usage. Use /help spawnpoint for more information.");
                    return;
                }
            }
            var client = server.MinecraftServer.GetClient(player);

            if (player == null)
            {
                user.SendChat(ChatColors.Red + player + " is not online."); // TODO: Set it anyway
                return;
            }
            client.Entity.SpawnPoint = new Vector3(x, y, z);
            server.SendChatToGroup("server.op", user.Username + " set " + player + " spawn point to " + client.Entity.SpawnPoint);
        }
示例#11
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            if (parameters.Length == 0)
            {
                user.SendChat(ChatColors.Red + "Incorrect usage. Use /help say for more information.");
                return;
            }
            var format = server.SettingsProvider.Get <string>("chat.broadcast.format");

            server.MinecraftServer.SendChat(string.Format(format, text));
        }
示例#12
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            int page = -1;

            if (parameters.Length == 0)
            {
                page = 1;
            }
            if (parameters.Length > 1)
            {
                user.SendChat(ChatColors.Red + "Incorrect usage. Use \"/help\" for more information.");
                return;
            }
            if (page != -1 || int.TryParse(parameters[0], out page))
            {
                page--;
                int pages = Commands.Count / CommandsPerPage;
                if (page >= pages)
                {
                    user.SendChat(ChatColors.Red + "No further commands. Use \"/help\" for more information.");
                    return;
                }
                user.SendChat(ChatColors.DarkGreen + "Command List (page " + (page + 1) + " of " + pages + ")");
                foreach (var c in Commands.Skip(page * CommandsPerPage).Take(CommandsPerPage))
                {
                    user.SendChat(ChatColors.DarkCyan + "/" + c.DefaultCommand);
                }
                return;
            }
            var command = GetCommand(parameters[0]);

            if (command == null)
            {
                user.SendChat(ChatColors.Red + "Command not found.");
                return;
            }
            string[] lines = command.Documentation.Split('\n');
            user.SendChat(ChatColors.DarkGreen + "Documentation for /" + command.DefaultCommand + ":");
            foreach (var line in lines)
            {
                user.SendChat(ChatColors.DarkCyan + line);
            }
            if (!MayUseCommand(command, user, server))
            {
                user.SendChat(ChatColors.Red + "You are not permitted to use this command.");
            }
        }
示例#13
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            string  player = user.Username;
            Vector3 target;

            if (parameters.Length < 1 || parameters.Length > 4)
            {
                user.SendChat(ChatColors.Red + "Incorrect usage. Use /help tp for more information.");
                return;
            }
            if (parameters.Length == 1)
            {
                var client = server.MinecraftServer.GetClient(parameters[0]);
            }
        }
示例#14
0
        public static void ClientStatus(RemoteClient client, Proxy proxy, IPacket _packet)
        {
            var packet = (ClientStatusPacket)_packet;

            if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn)
            {
                // Throw them into an empty world and inform them that we'll be connecting them shortly.
                client.SendPacket(new LoginRequestPacket(1, "FLAT", GameMode.Creative, Dimension.Overworld, Difficulty.Normal, 100));
                client.SendPacket(new PlayerAbilitiesPacket(0, 0.05f, 0.1f));
                client.SendPacket(new EntityPropertiesPacket(1, new[] { new EntityProperty("generic.movementSpeed", 0.05f) }));
                client.SendPacket(new PlayerPositionAndLookPacket(0, 1.72, 0, 0.1, 0, 0, false));
                client.SendChat(ChatColors.Yellow + "Connecting to the classic server, please wait.");
                proxy.Connect(client);
            }
            else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn)
            {
                // TODO
            }
        }
示例#15
0
        public static void ChatMessage(RemoteClient client, Proxy proxy, IPacket _packet)
        {
            var packet = (ChatMessagePacket)_packet;

            client.SendChat(packet.Message);
        }
示例#16
0
 public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
 {
     user.SendChat(server.MinecraftServer.Level.RandomSeed.ToString()); // TODO: Maybe add some stuff in Craft.Net to make this less cumbersome
 }
示例#17
0
        public override void Execute(Server server, RemoteClient user, string text, params string[] parameters)
        {
            bool add     = false;
            var  current = server.MinecraftServer.Level.Time;
            long?time    = null;

            if (parameters.Length == 0)
            {
                user.SendChat("The current time is " + current + ", or " + LongToTimeString(current));
                return;
            }
            if (parameters[0].ToLower() == "day")
            {
                time = 0;
            }
            else if (parameters[0].ToLower() == "night")
            {
                time = 12000;
            }
            else if (parameters[0].ToLower() == "noon")
            {
                time = 6000;
            }
            else if (parameters[0].ToLower() == "midnight")
            {
                time = 18000;
            }
            else
            {
                string timeString;
                if (parameters[0].ToLower() == "set" && parameters.Length > 1)
                {
                    timeString = parameters[1];
                }
                else if (parameters[0].ToLower() == "add" && parameters.Length > 1)
                {
                    timeString = parameters[1];
                    add        = true;
                }
                else
                {
                    timeString = parameters[0];
                }
                if (timeString.Contains(":"))
                {
                    try
                    {
                        time = TimeStringToLong(timeString);
                    }
                    catch { }
                }
                else
                {
                    long _time;
                    if (long.TryParse(timeString, out _time))
                    {
                        time = _time;
                    }
                }
                if (add)
                {
                    time += current;
                }
            }

            if (time == null)
            {
                user.SendChat(ChatColors.Red + "Invalid time specified.");
                return;
            }

            time = time.Value % 24000;

            server.MinecraftServer.Level.Time = time.Value; // TODO: Add event listener in Craft.Net
            server.SendChatToGroup("server.op", ChatColors.Gray + user.Username + " set the time in " + user.World.Name +
                                   " to " + time.Value + ", or " + LongToTimeString(time.Value));
        }