示例#1
0
        public async Task Handle(CommandRequest request)
        {
            await request.Write("Saving ripple space - ");

            Stopwatch timer        = Stopwatch.StartNew();
            long      bytesWritten = await server.PlaneManager.Save();

            long msTaken = timer.ElapsedMilliseconds;

            await request.WriteLine("done.");

            await request.WriteLine($"{Formatters.HumanSize(bytesWritten)} written in {msTaken}ms.");

            await request.WriteLine($"Save is now {Formatters.HumanSize(server.PlaneManager.LastSaveSize)} in size.");
        }
示例#2
0
        public async Task Grant(CommandRequest request)
        {
            if (request.Arguments.Length < 5)
            {
                await request.WriteLine("Error: No username specified!");

                return;
            }
            if (request.Arguments.Length < 4)
            {
                await request.WriteLine("Error: No plane name specified!");

                return;
            }
            if (request.Arguments.Length < 3)
            {
                await request.WriteLine("Error: No role specified!");

                return;
            }
            string grantRoleName  = request.Arguments[2];
            string grantPlaneName = request.Arguments[3];
            string grantUsername  = request.Arguments[4];

            if (grantRoleName.ToLower() != "creator" && grantRoleName.ToLower() != "member")
            {
                await request.WriteLine($"Error: Invalid role {grantRoleName}. Valid values: Creator, Member. Is not case-sensitive.");

                return;
            }
            Plane grantPlane = server.PlaneManager.GetByName(grantPlaneName);

            if (grantPlane == null)
            {
                await request.WriteLine($"Error: The plane with the name {grantPlaneName} could not be found.");

                return;
            }
            if (server.AccountManager.GetByName(grantUsername) == null)
            {
                await request.WriteLine($"Error: No user could be found with the name {grantUsername}.");

                return;
            }

            switch (grantRoleName.ToLower())
            {
            case "creator":
                if (grantPlane.Creators.Contains(grantUsername))
                {
                    await request.WriteLine($"Error: {grantUsername} is already a creator on {grantPlaneName}.");

                    return;
                }
                grantPlane.Creators.Add(grantUsername);
                break;

            case "member":
                if (grantPlane.Members.Contains(grantUsername))
                {
                    await request.WriteLine($"Error: {grantUsername} is already a member on {grantPlaneName}.");

                    return;
                }
                grantPlane.Members.Add(grantUsername);
                break;
            }

            await request.WriteLine($"Ok: {grantUsername} has been granted {grantRoleName} on {grantPlaneName} successfully.");

            await request.Write("Saving - ");

            DateTime grantTimeStart = DateTime.Now;
            await grantPlane.Save(PlaneSavingMode.MetadataOnly);

            await request.WriteLine($"done in {(DateTime.Now - grantTimeStart).Milliseconds}ms.");
        }
示例#3
0
        public async Task List(CommandRequest request)
        {
            OutputMode outputMode = CommandParser.ParseOutputMode(request.GetArg(2, "text"));

            await request.Write(generatePlaneList(server.PlaneManager.Planes, outputMode));
        }
示例#4
0
        public async Task Revoke(CommandRequest request)
        {
            if (request.Arguments.Length < 5)
            {
                await request.WriteLine("Error: No username specified!");

                return;
            }
            if (request.Arguments.Length < 4)
            {
                await request.WriteLine("Error: No plane name specified!");

                return;
            }
            if (request.Arguments.Length < 3)
            {
                await request.WriteLine("Error: No role specified!");

                return;
            }
            string roleName  = request.Arguments[2];
            string planeName = request.Arguments[3];
            string username  = request.Arguments[4];

            if (roleName.ToLower() != "creator" && roleName.ToLower() != "member")
            {
                await request.WriteLine($"Error: Invalid role {roleName}. Valid values: Creator, Member. Is not case-sensitive.");

                return;
            }
            Plane targetPlane = server.PlaneManager.GetByName(planeName);

            if (targetPlane == null)
            {
                await request.WriteLine($"Error: The plane with the name {planeName} could not be found.");

                return;
            }
            if (server.AccountManager.GetByName(username) == null)
            {
                await request.WriteLine($"Error: No user could be found with the name {username}.");

                return;
            }

            switch (roleName.ToLower())
            {
            case "creator":
                targetPlane.Creators.Remove(username);
                break;

            case "member":
                targetPlane.Members.Remove(username);
                break;
            }

            await request.WriteLine($"Ok: {username} has been revoked {roleName} on {planeName} successfully.");

            await request.Write("Saving - ");

            DateTime timeStart = DateTime.Now;
            await targetPlane.Save(PlaneSavingMode.MetadataOnly);

            await request.WriteLine($"done in {(DateTime.Now - timeStart).Milliseconds}ms.");
        }