public async Task CheckPassword(CommandRequest request) { string checkUsername = (request.Arguments[2] ?? "").Trim(); string checkPassword = (request.Arguments[3] ?? "").Trim(); if (checkUsername.Length == 0) { await request.WriteLine("Error: No username specified!"); return; } if (checkPassword.Length == 0) { await request.WriteLine("Error: No password specified!"); return; } User checkUser = server.AccountManager.GetByName(checkUsername); if (checkUser == null) { await request.WriteLine($"Error: User '{checkUsername}' was not found."); return; } if (!checkUser.CheckPassword(checkPassword)) { await request.WriteLine("Error: That password was incorrect."); return; } await request.WriteLine("Password check ok!"); }
public async Task Handle(CommandRequest request) { OutputMode outputMode = CommandParser.ParseOutputMode(request.GetArg(1, "text")); if (outputMode == OutputMode.CSV) { await request.WriteLine("Id,Name,Remote Endpoint,Current Plane,Viewport"); } foreach (NibriClient client in server.AppServer.NibriClients) { object[] lineParams = new object[] { client.Id, client.Name, client.RemoteEndpoint, client.CurrentPlane.Name, client.CurrentViewPort }; string outputLine = string.Format("{0}: {1} from {1}, on {3} looking at {4}", lineParams); if (outputMode == OutputMode.CSV) { outputLine = string.Join(",", lineParams); } await request.WriteLine(outputLine); } await request.WriteLine(); if (outputMode == OutputMode.Text) { await request.WriteLine($"Total {server.AppServer.ClientCount} clients"); } }
public async Task SetPassword(CommandRequest request) { string setPasswordUsername = (request.Arguments[2] ?? "").Trim(); string setPasswordPass = (request.Arguments[3] ?? "").Trim(); if (setPasswordUsername.Length == 0) { await request.WriteLine("Error: No username specified."); return; } if (setPasswordPass.Length == 0) { await request.WriteLine("Error: No password specified."); } User setPasswordUser = server.AccountManager.GetByName(setPasswordUsername); if (setPasswordUser == null) { await request.WriteLine($"Error: User '{setPasswordUsername}' wasn't found."); return; } setPasswordUser.SetPassword(setPasswordPass); await server.SaveUserData(); await request.WriteLine($"Ok: Updated password for {setPasswordUser.Username} successfully."); }
public async Task Create(CommandRequest request) { if (request.Arguments.Length < 3) { await request.WriteLine("Error: No name specified for the new plane!"); return; } string newPlaneName = request.Arguments[2]; int chunkSize = server.PlaneManager.DefaultChunkSize; if (request.Arguments.Length >= 4) { chunkSize = int.Parse(request.Arguments[3]); } // Create the plane and save it to disk Plane createdPlane = server.PlaneManager.CreatePlane(new PlaneInfo( newPlaneName, chunkSize )); await createdPlane.Save(PlaneSavingMode.MetadataOnly); await request.WriteLine($"Ok: Created plane with name {newPlaneName} and chunk size {chunkSize}."); }
public async Task Handle(CommandRequest request) { await request.WriteLine( "Nibriboard Server {0}, built on {1}", NibriboardServer.Version, NibriboardServer.BuildDate.ToString("R") ); await request.WriteLine("By Starbeamrainbowlabs, licensed under MPL-2.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."); }
public async Task Get(CommandRequest request) { if (request.Arguments.Length < 4) { await request.WriteLine("Error: No username specified!"); return; } if (request.Arguments.Length < 3) { await request.WriteLine("Error: No plane name specified!"); return; } string planeName = request.Arguments[2]; string username = request.Arguments[3]; 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; } string role = "None"; if (targetPlane.Creators.Contains(username)) { role = "Creator"; } else if (targetPlane.Members.Contains(username)) { role = "Member"; } await request.WriteLine(role); }
public async Task List(CommandRequest request) { await request.WriteLine( string.Join("\n", server.AccountManager.Users.Select( (User user) => $"{user.CreationTime}\t{user.Username}\t{string.Join(", ", user.Roles.Select((RbacRole role) => role.Name))}" )) ); }
public async Task ListUser(CommandRequest request) { string username = request.GetArg(2, ""); OutputMode outputMode = CommandParser.ParseOutputMode(request.GetArg(3, "text")); if (username.Length == 0) { await request.WriteLine("Error: no username specified."); return; } // FUTURE: We need to be able to distinguish between viewing & editing here, amongst other places bool canViewAny = server.AccountManager.GetByName(username).HasPermission(server.AccountManager.ResolvePermission("view-any-plane")); IEnumerable <Plane> planes = server.PlaneManager.Planes.Where((Plane nextPlane) => canViewAny || nextPlane.HasMember(username)); if (outputMode == OutputMode.CSV) { await request.WriteLine("Plane Name,Role"); } foreach (Plane nextPlane in planes) { object[] formatArgs = new object[] { nextPlane.Name, (nextPlane.HasCreator(username) || canViewAny ? "Creator" : "Member") }; switch (outputMode) { case OutputMode.Text: await request.WriteLine("{0} as {1}", formatArgs); break; case OutputMode.CSV: await request.WriteLine(string.Join(",", formatArgs.Select((object arg) => arg.ToString()))); break; } } //await request.Write(generatePlaneList(server.PlaneManager.Planes, outputMode)); }
public async Task ListPerms(CommandRequest request) { foreach (RbacPermission perm in server.AccountManager.Permissions) { await request.WriteLine( request.GetArg(2, "text") == "csv"? $"{perm.Name},{perm.Description}" : $"{perm.Name}: {perm.Description}" ); } }
public async Task Add(CommandRequest request) { string newUsername = (request.Arguments[2] ?? "").Trim(); string password = (request.Arguments[3] ?? "").Trim(); if (newUsername.Length == 0) { await request.WriteLine("Error: No username specified!"); return; } if (password.Length == 0) { await request.WriteLine("Error: No password specified!"); return; } server.AccountManager.AddUser(newUsername, password); await server.SaveUserData(); await request.WriteLine($"Ok: Added user with name {newUsername} successfully."); }
public async Task Handle(CommandRequest request) { // Save the ripplespace CommandSave saver = new CommandSave(); saver.Setup(server); await saver.Handle(request); // Stop the listeners server.AppServer.Stop(request.GetArg(1, "This server is shutting down.")); server.PlaneManager.StopMaintenanceMonkey(); server.CommandServer.Stop(); await request.WriteLine("Stopping Nibriboard Server."); }
public async Task Handle(CommandRequest request) { await request.WriteLine($"Version: {NibriboardServer.Version}"); await request.WriteLine($"Build date: {NibriboardServer.BuildDate.ToString("R")}"); using (Process process = Process.GetCurrentProcess()) { await request.WriteLine($"PID: {process.Id}"); await request.WriteLine($"Private memory usage: {Formatters.HumanSize(process.PrivateMemorySize64)}"); } await request.WriteLine($"Connected clients: {server.AppServer.NibriClients.Count}"); await request.WriteLine($"Planes: {server.PlaneManager.Planes.Count}"); await request.WriteLine($"Total chunks: {server.PlaneManager.Planes.Sum((Plane nextPlane) => nextPlane.TotalSavedChunks)}"); await request.WriteLine($"...of which loaded: {server.PlaneManager.Planes.Sum((Plane nextPlane) => nextPlane.LoadedChunks)}"); }
public async Task Set(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; } targetPlane.Creators.Remove(username); targetPlane.Members.Remove(username); // The grant command handler should be able to handle it from here await Grant(request); }
public async Task Revoke(CommandRequest request) { string roleName = (request.Arguments[2] ?? "").Trim(); string recievingUsername = (request.Arguments[3] ?? "").Trim(); if (roleName.Length == 0) { await request.WriteLine("Error: No role name specified!"); return; } if (recievingUsername.Length == 0) { await request.WriteLine("Error: No username specified!"); return; } User user = server.AccountManager.GetByName(recievingUsername); RbacRole roleToGrant = server.AccountManager.ResolveRole(roleName); if (user == null) { await request.WriteLine($"Error: No user with the the name {recievingUsername} could be found."); return; } if (roleToGrant == null) { await request.WriteLine($"Error: No role with the the name {roleName} could be found."); return; } if (!user.HasRole(roleToGrant)) { await request.WriteLine($"Error: {recievingUsername} doesn't have the role {roleToGrant.Name}."); return; } user.Roles.Remove(roleToGrant); await server.SaveUserData(); await request.WriteLine($"Ok: Role {roleToGrant.Name} removed from {user.Username} successfully."); }
public async Task Grant(CommandRequest request) { string roleName = (request.Arguments[2] ?? "").Trim(); string targetUsername = (request.Arguments[3] ?? "").Trim(); if (roleName.Length == 0) { await request.WriteLine("Error: No role name specified!"); return; } if (targetUsername.Length == 0) { await request.WriteLine("Error: No username specified!"); return; } User user = server.AccountManager.GetByName(targetUsername); RbacRole roleToGrant = server.AccountManager.ResolveRole(roleName); if (user == null) { await request.WriteLine($"Error: No user with the the name {targetUsername} could be found."); return; } if (roleToGrant == null) { await request.WriteLine($"Error: No role with the the name {roleName} could be found."); return; } if (user.HasRole(roleToGrant)) { await request.WriteLine($"Error: {targetUsername} already has the role {roleToGrant.Name}."); return; } user.Roles.Add(roleToGrant); await server.SaveUserData(); await request.WriteLine($"Ok: Role {roleToGrant.Name} added to {user.Username} successfully."); }
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."); }
public async Task Handle(CommandRequest request) { if (request.Arguments.Length < 2) { await request.WriteLine("Nibriboard Server Command Console: perms"); await request.WriteLine("----------------------------------------"); await request.WriteLine(Description.ToLongString()); await request.WriteLine(); await request.WriteLine("Subcommands:"); await request.WriteLine(" grant {{{{perm:Creator|Member}}}} {{{{plane-name}}}} {{{{username}}}}"); await request.WriteLine(" Grant permission on plane-name to username"); await request.WriteLine(" revoke {{{{perm:Creator|Member}}}} {{{{plane-name}}}} {{{{username}}}}"); await request.WriteLine(" Revoke username's role permission plane-name"); await request.WriteLine(" get {{{{plane-name}}}} {{{{username}}}}"); await request.WriteLine(" Get a username's permission on the specified plane. Note that a user's role needs to be consulted too to determine whether they can or cannot perform an action."); await request.WriteLine(" set {{{{perm:Creator|Member}}}} {{{{plane-name}}}} {{{{username}}}}"); await request.WriteLine(" Set username's perm on plane-name to a specific value, removing all other permissions"); return; } await CommandParser.ExecuteSubcommand(this, request.Arguments[1], request); }
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."); }
public async Task Status(CommandRequest request) { if (request.Arguments.Length < 3) { await request.WriteLine("Error: No plane name specified!"); return; } string targetPlaneName = request.Arguments[2]; Plane targetPlane = server.PlaneManager.GetByName(targetPlaneName); if (targetPlane == null) { await request.WriteLine($"Error: A plane with the name {targetPlaneName} doesn't exist."); return; } await request.WriteLine($"Name: {targetPlane.Name}"); await request.WriteLine($"Chunk size: {targetPlane.ChunkSize}"); await request.WriteLine($"Loaded chunks: {targetPlane.LoadedChunks}"); // BUG: This isn't technically correct, as we can have phantom chunks loaded in the primary chunk area that haven't been drawn to, and so aren't on disk. await request.WriteLine($"Unloaded chunks: {targetPlane.TotalSavedChunks - targetPlane.LoadedChunks}"); await request.WriteLine($"Total saved chunks: {targetPlane.TotalSavedChunks}"); await request.WriteLine($"Primary chunk area size: {targetPlane.PrimaryChunkAreaSize}"); await request.WriteLine($"Min unloadeable chunks: {targetPlane.MinUnloadeableChunks}"); await request.WriteLine($"Soft loaded chunk limit: {targetPlane.SoftLoadedChunkLimit}"); await request.WriteLine($"Creators: {string.Join(", ", targetPlane.Creators)}"); await request.WriteLine($"Members: {string.Join(", ", targetPlane.Members)}"); }
public async Task Handle(CommandRequest request) { if (request.Arguments.Length < 2) { await request.WriteLine("Nibriboard Server Command Console: users"); await request.WriteLine("----------------------------------------"); await request.WriteLine(Description.ToLongString()); await request.WriteLine(); await request.WriteLine("Subcommands:"); await request.WriteLine(" list"); await request.WriteLine(" Lists all users."); await request.WriteLine(" add {{{{username}}}} {{{{password}}}}"); await request.WriteLine(" Adds a new user"); await request.WriteLine(" checkpassword {{{{username}}}} {{{{password}}}}"); await request.WriteLine(" Checks a user's password"); await request.WriteLine(" setpassword {{{{username}}}} {{{{password}}}}"); await request.WriteLine(" Resets a user's password"); return; } await CommandParser.ExecuteSubcommand(this, request.Arguments[1], request); }
public async Task Handle(CommandRequest request) { if (request.Arguments.Length < 2) { await request.WriteLine("Nibriboard Server Command Console: planes"); await request.WriteLine("-----------------------------------------"); await request.WriteLine(Description.ToLongString()); await request.WriteLine(); await request.WriteLine("Subcommands:"); await request.WriteLine(" list {{{{output_mode:text|csv}}"); await request.WriteLine(" List all the currently loaded planes"); await request.WriteLine(" listuser {{{{username}}}} {{{{output_mode:text|csv}}"); await request.WriteLine(" List all the planes the specified username has access to"); await request.WriteLine(" create {{new-plane-name}} [{{chunkSize}}]"); await request.WriteLine(" Create a new named plane, optionally with the specified chunk size"); await request.WriteLine(" status {{plane-name}}"); await request.WriteLine(" Show the statistics of the specified plane"); await request.WriteLine(); return; } await CommandParser.ExecuteSubcommand(this, request.Arguments[1], request); }
public async Task Handle(CommandRequest request) { if (request.Arguments.Length < 2) { await request.WriteLine("Nibriboard Server Command Console: roles"); await request.WriteLine("----------------------------------------"); await request.WriteLine(Description.ToLongString()); await request.WriteLine(); await request.WriteLine("Subcommands:"); await request.WriteLine(" list"); await request.WriteLine(" Lists all roles"); await request.WriteLine(" listperms [{{{{format:text|csv]}}}}]"); await request.WriteLine(" List all possible permissions that can be assigned to a role. Not to be confused with plane permissions."); await request.WriteLine(" grant {{{{role-name}}}} {{{{username}}}}"); await request.WriteLine(" Adds a role to a user"); await request.WriteLine(" revoke {{{{role-name}}}} {{{{username}}}}"); await request.WriteLine(" Removes a role from a user"); return; } await CommandParser.ExecuteSubcommand(this, request.Arguments[1], request); }
public async Task List(CommandRequest request) { await request.WriteLine(string.Join("\n", server.AccountManager.Roles.Select( (RbacRole role) => role.ToString() ))); }