Exemple #1
0
        internal Response(Api.Response dgraphResponse)
        {
            DgraphResponse = dgraphResponse;

            _Uids = new Lazy <Dictionary <string, string> >(
                () => new Dictionary <string, string>(DgraphResponse.Uids));
        }
Exemple #2
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;
            }
        }
Exemple #3
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);
 }
Exemple #4
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);
     }
 }
Exemple #5
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);
 }
 public override void Process(Request request, Response response)
 {
     base.Process(request, response);
     Console.WriteLine(response.Info);
 }
Exemple #7
0
 /// <summary>
 /// Process the response.
 /// </summary>
 /// <param name="request">Initial request.</param>
 /// <param name="response">Processed response.</param>
 /// <summary>It will not be called, if response is null or empty</summary>
 public virtual void Process(Request request, Response response)
 {
 }
Exemple #8
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;
 }
Exemple #9
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);
 }
Exemple #10
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);
            }
        }
Exemple #11
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);
     }
 }