コード例 #1
0
ファイル: Auth.cs プロジェクト: zaitsevyan/Theseus
        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;
            }
        }
コード例 #2
0
ファイル: Minecraft.cs プロジェクト: zaitsevyan/Theseus
 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);
     }
 }
コード例 #3
0
ファイル: Minecraft.cs プロジェクト: zaitsevyan/Theseus
        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);
            }
        }
コード例 #4
0
ファイル: Minecraft.cs プロジェクト: zaitsevyan/Theseus
 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);
     }
 }