/// <summary> /// Deletes the account /// </summary> /// <param name="query"></param> /// <returns></returns> public override RestResponse OnDelete(Query query) { //Make sure we have permission to edit admin accounts if (Account.IsAdmin && AuthenticationLevel < AuthLevel.SuperBot) { return(new RestResponse(RestStatus.Forbidden, msg: "Only SuperBots or above may delete admin accounts")); } //Reload the server var task = Task.Run(async() => { if (!await Starbound.Configurator.RemoveAccountAsync(Account)) { return(false); } return(await Starbound.SaveConfigurationAsync(true)); }); if (query.GetBool(Query.AsyncKey, false)) { return(RestResponse.Async); } return(new RestResponse(RestStatus.OK, res: task.Result)); }
public WhitelistManager GetWhitelistManager() { var monitors = Starbound.GetMonitors <WhitelistManager>(); if (monitors.Length == 0) { return(null); } return(monitors[0]); }
public RestoreMonitor GetRestoreMonitor() { var monitors = Starbound.GetMonitors <RestoreMonitor>(); if (monitors.Length == 0) { return(null); } return(monitors[0]); }
public void Render(Starbound.UI.Controls.Control control, SpriteBatch spriteBatch) { if (this.spriteBatch == null) { this.spriteBatch = new SpriteBatchWrapper(spriteBatch); } foreach (Primitive primitive in control.Template.Primitives) { Render(primitive); } }
/// <summary> /// Creates an account. /// </summary> /// <param name="query"></param> /// <param name="payloadObject"></param> /// <returns></returns> public override RestResponse OnPost(Query query, object payloadObject) { #if !SKIP_SSL_ENFORCE //Server must be in SSL mode if (!Handler.ApiHandler.IsSecure) { return(new RestResponse(RestStatus.Forbidden, msg: "Cannot set passwords if the server is not SSL")); } #endif //Validate the account AccountPatch account = (AccountPatch)payloadObject; if (string.IsNullOrWhiteSpace(account.Name)) { return(new RestResponse(RestStatus.BadRequest, msg: "Account name cannot be empty")); } if (string.IsNullOrWhiteSpace(account.Password)) { return(new RestResponse(RestStatus.BadRequest, msg: "Password cannot be empty")); } //Only SuperBot and SuperUsers can create admin if (account.IsAdmin.GetValueOrDefault(false) && AuthenticationLevel < AuthLevel.SuperBot) { return(new RestResponse(RestStatus.Forbidden, "Only SuperBot or above may create admin accounts.")); } var task = Task.Run(async() => { //Make sure the name isnt a duplicate if (await Starbound.Configurator.GetAccountAsync(account.Name) != null) { return(new RestResponse(RestStatus.BadRequest, $"The username {account.Name} already exists.")); } //Post it await Starbound.Configurator.SetAccountAsync(account.ToAccount()); //Save the settings await Starbound.SaveConfigurationAsync(true); return(new RestResponse(RestStatus.OK, msg: $"Saved: " + account.Name, res: account)); }); if (query.GetBool(Query.AsyncKey, false)) { return(RestResponse.Async); } return(task.Result); }
/// <summary> /// Deletes a ban /// </summary> public override RestResponse OnDelete(Query query) { //Failed to remove the ban if (!Starbound.Configurator.ExpireBanAsync(Ban).Result) { return(new RestResponse(RestStatus.OK, res: false)); } //Save the settings and reload var task = Starbound.SaveConfigurationAsync(true); if (query.GetBool(Query.AsyncKey, false)) { return(RestResponse.Async); } return(new RestResponse(RestStatus.OK, res: task.Result)); }
public override RestResponse OnDelete(Query query) { if (Player == null) { return(RestResponse.ResourceNotFound); } string reason; int duration = 0; bool async = query.GetBool(Query.AsyncKey, false); if (Starbound.Rcon == null) { return(new RestResponse(RestStatus.BadRequest, "Rcon not enabled.")); } //Get the reason if (!query.TryGetString("reason", out reason)) { return(new RestResponse(RestStatus.BadRequest, msg: "Cannot delete user without a reason")); } //Prepare the task Task <RconResponse> task; //If we have a duration then kick for the duration if (query.TryGetInt("duration", out duration)) { task = Starbound.Kick(Player, reason, duration); } else { task = Starbound.Kick(Player, reason); } //If we are async then return asap, otherwise get the result if (async) { return(RestResponse.Async); } return(new RestResponse(RestStatus.OK, res: task.Result)); }
/// <summary> /// Updates the account /// </summary> /// <param name="query"></param> /// <param name="payloadObject"></param> /// <returns></returns> public override RestResponse OnPatch(Query query, object payloadObject) { AccountPatch oa = (AccountPatch)payloadObject; if (oa.IsAdmin.HasValue && AuthenticationLevel < AuthLevel.SuperBot) { return(new RestResponse(RestStatus.Forbidden, msg: "Only SuperBots or above may patch admin accounts")); } #if !SKIP_SSL_ENFORCE if (oa.Password != null && !Handler.ApiHandler.IsSecure) { return(new RestResponse(RestStatus.Forbidden, msg: "Cannot set passwords if the server is not SSL")); } #endif string username = oa.Name ?? Account.Name; string password = oa.Password ?? Account.Password; bool isAdmin = oa.IsAdmin ?? Account.IsAdmin; bool isActive = oa.IsActive ?? Account.IsActive; //Prepare the task var task = Task.Run(async() => { if (username != Account.Name) { //Make sure the name isnt a duplicate if (Starbound.Configurator.GetAccountAsync(username) != null) { return(new RestResponse(RestStatus.BadRequest, "The username " + username + " already exists.")); } //Remove the old account await Starbound.Configurator.RemoveAccountAsync(Account); //Create the new account Account = new Account(username) { IsAdmin = isAdmin, Password = password, IsActive = isActive }; } else { //Edit the individual parts of the account Account.Password = password; Account.IsAdmin = isAdmin; Account.IsActive = isActive; } //Set the account await Starbound.Configurator.SetAccountAsync(Account); //Terminate any connections var auth = this.Handler.ApiHandler.GetAuthentication(Account.Name); this.Handler.ApiHandler.DisconnectAuthentication(auth, reason: "Authentication change"); //Logout anyone that previously connected foreach (var player in Starbound?.Connections?.GetCopiedPlayersEnumerable().Where(p => p != null && p.AccountName != null && p.AccountName.Equals(Account.Name))) { await player.Kick("Account details changed."); } //Apply the settings await Starbound.SaveConfigurationAsync(true); return(OnGet(query)); }); //If we are async, abort asap, otherwise wait for it to finish. if (query.GetBool(Query.AsyncKey, false)) { return(RestResponse.Async); } return(task.Result); }
///// <summary> ///// Gets the last ban ///// </summary> //public override RestResponse OnGet(Query query) //{ // return new RestResponse(RestStatus.OK, res: Starbound.Settings.CurrentBanTicket); //} /// <summary> /// Creates a new ban /// </summary> public override RestResponse OnPost(Query query, object payloadObject) { //Prepare some values Ban ban = (Ban)payloadObject; Player player = null; //Validate the ban exists if (ban.Ticket.HasValue) { return(new RestResponse(RestStatus.BadRequest, msg: "Bans cannot have their tickets preset!")); } //If we have a connection ID then we will fill the rest with the connection information. // otherwise we will just ban the player as usual. if (query.ContainsKey("cid")) { //We are banning a specific connection id. int connection = 0; if (!query.TryGetInt("cid", out connection)) { return(new RestResponse(RestStatus.BadRequest, msg: $"Cannot convert '{query["cid"]}' to a int32!")); } //Get the connection player = Starbound.Connections.GetPlayer(connection); //Make sure the player is upto date if (player != null && player.UUID == null) { Starbound.Connections.RefreshListing().Wait(); player = Starbound.Connections.GetPlayer(connection); } } //If we have a player, update the ban information if (player != null) { //Update the results (if nessary) if (string.IsNullOrEmpty(ban.IP) || query.GetBool("copy_details", false)) { ban.IP = player.IP; } if (string.IsNullOrEmpty(ban.UUID) || query.GetBool("copy_details", false)) { ban.UUID = player.UUID; } } //Make sure we have a IP or UUID if (ban.BanType == BanType.Invalid) { return(new RestResponse(RestStatus.BadRequest, "Invalid ban type. IP and/or UUID must be set!")); } //Update the moderator if required if (string.IsNullOrEmpty(ban.Moderator)) { ban.Moderator = Authentication.Name; } //Apply the correct date time ban.CreatedDate = DateTime.UtcNow; //Perform the ban and get the ban result var task = Starbound.Ban(ban); ban = Starbound.Configurator.GetBanAsync(task.Result).Result; //Kick the player if nessary, waiting for it to finish. if (player != null) { Starbound.Kick(player.Connection, ban.Reason).Wait(); } //Return the ban return(new RestResponse(RestStatus.OK, res: ban)); }