Exemplo n.º 1
0
        public async Task<Response> Login(Sender sender, String[] args){
            if (args.Length != 2) {
                var response = new Response(Channel.Private);
                response.SetError(AuthStrings.Login_ArgsError);
                return response;
            }

            var username = args[0];
            var password = args[1];
            Account account = await Manager.GetCore().GetAccountsDB().GetAccount(username, password);
            if (account != null) {
                if (account.Role <= sender.Role) {
                    var response = new Response(Channel.Private);
                    response.SetMessage(AuthStrings.Login_BetterRoleWarning);
                    return response;
                }
                else {
                    sender.Account = account;
                    var response = new Response(Channel.Private);
                    response.SetMessage(AuthStrings.Login_Ok, account.Role);
                    return response;
                }
            }
            else {
                var response = new Response(Channel.Private);
                response.SetError(AuthStrings.Login_InvalidLoginPass);
                return response;
            }
        }
Exemplo n.º 2
0
 public Task<Response> Help(Sender sender, String[] args)
 {
     List<CommandAttribute> commands;
     if (args.Length == 0)
         commands = Manager.GetAllowedCommands(sender);
     else
         commands = (from name in args
                                 select Manager.GetCommandInfo(name)).ToList();
     StringBuilder sb = new StringBuilder();
     if (commands.Count > 1) {
         sb.AppendLine(TheseusControlStrings.Help_PrintTitle);
     }
     foreach (var command in commands) {
         PrintCommandInfo(command, sb);
     }
     var response = new Response(Channel.Same);
     response.SetMessage(sb.ToString());
     return Task.FromResult<Response>(response);
 }
Exemplo n.º 3
0
 public Task<Response> Reboot(Sender sender, String[] args){
     if (args.Length != 1) {
         var error = new Response(Channel.Private);
         error.SetError(MinecraftStrings.Reboot_ArgsError);
         return Task.FromResult(error);
     }
     var serverName = args[0];
     if (!GetServersList().Contains(serverName)) {
         var error = new Response(Channel.Private);
         error.SetError(MinecraftStrings.Reboot_ArgsError);
         return Task.FromResult(error);
     }
     var server = (Config["servers"] as Dictionary<String, Object>)[serverName] as Dictionary<String, Object>;
     if (!server.ContainsKey("reboot-exec")) {
         var error = new Response(Channel.Private);
         error.SetError(MinecraftStrings.Reboot_ConfigError);
         return Task.FromResult(error);
     }
     var command = server["reboot-exec"] as String;
     try {
         // Start the child process.
         Process p = new Process();
         // Redirect the output stream of the child process.
         p.StartInfo.UseShellExecute = false;
         p.StartInfo.RedirectStandardOutput = true;
         p.StartInfo.FileName = "/bin/bash";
         p.StartInfo.Arguments = command;
         p.Start();
         // Do not wait for the child process to exit before
         // reading to the end of its redirected stream.
         // p.WaitForExit();
         // Read the output stream first and then wait.
         string output = p.StandardOutput.ReadToEnd();
         p.WaitForExit();
         var response = new Response(Channel.Same);
         response.SetMessage(output);
         return Task.FromResult(response);
     } catch (Exception) {
         var error = new Response(Channel.Private);
         error.SetError(MinecraftStrings.Reboot_Exception);
         return Task.FromResult(error);
     }
 }
Exemplo n.º 4
0
 public Task<Response> WhoAmI(Sender sender, String[] args){
     var response = new Response(Channel.Same);
     response.SetMessage("You are {0} with {1} role", sender.Account, sender.Role);
     return Task.FromResult(response);
 }
Exemplo n.º 5
0
 public async Task<Response> Players(Sender sender, String[] args){
     var sb = new StringBuilder();
     var prefix = "";
     List<String> servers;
     if (args.Length == 0) {
         servers = GetServersList();
     }
     else {
         servers = new List<string>(args);
     }
     if (servers.Count > 1) {
         sb.AppendLine(MinecraftStrings.Players_PrintTitle);
         prefix = "    ";
     }
     var tasks = new List<Task<String>>();
     foreach (var serverName in servers) {
         var server = (Config["servers"] as Dictionary<String, Object>)[serverName] as Dictionary<String, Object>;
         if (server == null)
             continue;
         var task = PingServer(server, serverName, prefix);
         tasks.Add(task);
     }
     await Task.WhenAll(tasks);
     foreach (var task in tasks) {
         sb.Append(task.Result);
     }
     var response = new Response(Channel.Same);
     response.SetMessage(sb.ToString());
     return response;
 }
Exemplo n.º 6
0
 public Task<Response> Servers(Sender sender, String[] args){
     var response = new Response(Channel.Same);
     response.SetMessage("{1}: {0}", String.Join(", ", GetServersList()), MinecraftStrings.Servers_PrintTitle);
     return Task.FromResult(response);
 }
Exemplo n.º 7
0
        public Task<Response> Ban(Sender sender, String[] args){
            SetupBanArguments();
            try {
                var options = banArguments.Parse(args);

                var plain = new List<String>(options.GetPlainArguments<String>());
                if (plain.Count != 1) {
                    var response = new Response(Channel.Private);
                    response.SetError(MinecraftStrings.PlayerNameMissing);
                    return Task.FromResult(response);
                }
                else {
                    var player = plain[0];
                    var time = Time.Forever;
                    if (options.IsOptionSet("time")) {
                        time = options.GetOptionValue<Time>("time");
                    }
                    var response = new Response(Channel.Same);
                    response.SetMessage(MinecraftStrings.Ban_Ok, player, time);
                    return Task.FromResult(response);
                }
            }
            catch (ArgumentsException e) {
                Logger.Trace(e);
                var response = new Response(Channel.Private);
                response.SetError(MinecraftStrings.OptionsParseError);
                return Task.FromResult(response);
            }
        }
Exemplo n.º 8
0
 public Task<Response> Unban(Sender sender, String[] args){
     if (args.Length != 1) {
         var response = new Response(Channel.Private);
         response.SetError(MinecraftStrings.PlayerNameMissing);
         return Task.FromResult(response);
     }
     else {
         var response = new Response(Channel.Same);
         response.SetMessage(MinecraftStrings.Unban_Ok, args[0]);
         return Task.FromResult(response);
     }
 }