Inheritance: IServer
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static void ExecuteCommand(Server server, MinecraftClient user, string text)
        {
            string name = text.Substring(1);
            if (string.IsNullOrEmpty(name))
                return;
            var groups = (List<string>)user.Tags["PartyCraft.UserGroups"];
            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;
            }

            bool allowed = false;
            foreach (var group in groups)
            {
                if (command.AllowedGroups.Contains(group))
                    allowed = true;
            }
            if (!allowed)
            {
                user.SendChat(ChatColors.Red + "You do not have permission to use that command.");
                return;
            }
            command.Execute(server, user, userText, parameters);
        }
Ejemplo n.º 3
0
 public static bool MayUseCommand(Command command, RemoteClient user, Server server)
 {
     if (user is ConsoleClient)
         return true;
     var groups = server.GetUserGroups(user.Username);
     foreach (var group in groups)
     {
         if (command.AllowedGroups.Contains(group))
             return true;
     }
     return false;
 }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            CheckEnvironment();
            // TODO: Load certain plugins earlier
            if (PreStartup != null)
                PreStartup(null, null);
            if (SettingsProvider == null)
            {
                // Select a settings provider based on the enviornment
                if (File.Exists("server.properties"))
                    SettingsProvider = new VanillaSettingsProvider("server.properties");
                else
                {
                    // TODO: Create a better settings provider than vanilla
                    SettingsProvider = new VanillaSettingsProvider("server.properties");
                    SetUpDefaultPermissions(SettingsProvider);
                }
            }

            var server = new Server(SettingsProvider);
            LoadPlugins(server);
            Command.LoadCommands(server);
            // TODO
            //var consoleLog = new ConsoleLogWriter(LogImportance.Medium);
            //LogProvider.RegisterProvider(consoleLog);

            server.Start();

            Console.WriteLine("Use /stop to kill the server.");
            ConsoleClient = new ConsoleClient(server.MinecraftServer);
            while (true)
            {
                var command = Console.ReadLine();
                try
                {
                    if (!String.IsNullOrWhiteSpace(command))
                        Command.ExecuteCommand(server, ConsoleClient, command);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }

            server.Stop();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            CheckEnviornment();
            // TODO: Load plugins
            if (PreStartup != null)
                PreStartup(null, null);
            if (SettingsProvider == null)
            {
                // Select a settings provider based on the enviornment
                if (File.Exists("server.properties"))
                {
                    SettingsProvider = new VanillaSettingsProvider();
                    (SettingsProvider as VanillaSettingsProvider).Load(
                        File.Open("server.properties", FileMode.Open));
                }
                else
                {
                    // TODO: Create a better settings provider than vanilla
                    SettingsProvider = new VanillaSettingsProvider();
                    SetUpDefaultPermissions(SettingsProvider);
                }
            }

            var server = new Server(SettingsProvider);
            Command.LoadCommands(server);
            // TODO: Better logging
            var consoleLog = new ConsoleLogWriter(LogImportance.Medium);
            LogProvider.RegisterProvider(consoleLog);

            server.Start();

            Console.WriteLine("Press 'q' to quit.");
            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.KeyChar == 'q')
                    break;
            }

            server.Stop();
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            if (PreStartup != null)
                PreStartup(null, null);
            if (SettingsProvider == null)
                SettingsProvider = new VanillaSettingsProvider();

            Server server = new Server(SettingsProvider);
            // TODO: Better logging
            ConsoleLogWriter consoleLog = new ConsoleLogWriter(LogImportance.High);
            server.MinecraftServer.AddLogProvider(consoleLog);

            server.Start();

            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.KeyChar == 'q')
                    break;
            }

            server.Stop();
        }
Ejemplo n.º 7
0
 internal static void LoadCommands(Server server)
 {
     Commands = new List<Command>();
     var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()
         .Where(t => !t.IsAbstract && typeof(Command).IsAssignableFrom(t)));
     foreach (var type in types)
     {
         var command = (Command)Activator.CreateInstance(type);
         command.Aliases = new List<string>();
         if (server.SettingsProvider.ContainsKey("command." + command.DefaultCommand + ".aliases"))
         {
             command.Aliases = server.SettingsProvider.Get<List<string>>(
                 "command." + command.DefaultCommand + ".aliases");
         }
         command.AllowedGroups = new List<string>();
         if (server.SettingsProvider.ContainsKey("command." + command.DefaultCommand + ".groups"))
         {
             command.AllowedGroups = server.SettingsProvider.Get<List<string>>(
                 "command." + command.DefaultCommand + ".groups");
         }
         else
             command.AllowedGroups.Add("all");
         Commands.Add(command);
     }
 }
Ejemplo n.º 8
0
 // TODO: CommandContext class
 public abstract void Execute(Server server, MinecraftClient user, string text, params string[] parameters);
Ejemplo n.º 9
0
 // TODO: CommandContext class
 public abstract void Execute(Server server, RemoteClient user, string text, params string[] parameters);
Ejemplo n.º 10
0
 public virtual bool TabComplete(Server server, string text, out string[] matches)
 {
     matches = new string[0];
     return false;
 }
Ejemplo n.º 11
0
 public virtual bool TabComplete(Server server, string text, out string[] matches)
 {
     matches = new string[0];
     return false;
 }
Ejemplo n.º 12
0
 // TODO: CommandContext class
 public abstract void Execute(Server server, RemoteClient user, string text, params string[] parameters);
Ejemplo n.º 13
0
 private static void LoadPlugins(Server server)
 {
     // TODO: Make this better
     // Dynamic plugins
     var eval = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter()));
     eval.ReferenceAssembly(typeof(Plugin).Assembly);
     eval.ReferenceAssembly(typeof(Command).Assembly);
     eval.ReferenceAssembly(typeof(MinecraftServer).Assembly);
     eval.InteractiveBaseClass = typeof(ScriptPluginBase);
     ScriptPluginBase.Server = server;
     foreach (var plugin in Directory.GetFiles(Path.Combine("plugins", "scripts"), "*.csx"))
         eval.Run(File.ReadAllText(plugin));
     foreach (var plugin in Directory.GetFiles(Path.Combine("plugins", "scripts"), "*.csc")) // TODO: Upgrade Mono.CSharp to Mono 3.0 to support Roslyn-style inline classes in csx files
         eval.Compile(File.ReadAllText(plugin));
     // Load plugins
     var types = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetTypes())
             .Aggregate((a, b) => a.Concat(b).ToArray()).Where(t => !t.IsAbstract && typeof(Plugin).IsAssignableFrom(t));
     foreach (var type in types)
     {
         var plugin = (Plugin)Activator.CreateInstance(type);
         plugin.OnInitialize(server);
     }
 }