Some i18nifiying
This commit is contained in:
parent
39576e3180
commit
f63b26ac76
31 changed files with 538 additions and 455 deletions
|
|
@ -242,9 +242,9 @@ namespace Rests
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TShock.Log.Error("Fatal Startup Exception");
|
||||
TShock.Log.Error(GetString("Fatal Startup Exception"));
|
||||
TShock.Log.Error(ex.ToString());
|
||||
TShock.Log.ConsoleError("Invalid REST configuration: \nYou may already have a REST service bound to port {0}. \nPlease adjust your configuration and restart the server. \nPress any key to exit.", Port);
|
||||
TShock.Log.ConsoleError(GetString("Invalid REST configuration: \nYou may already have a REST service bound to port {0}. \nPlease adjust your configuration and restart the server. \nPress any key to exit.", Port));
|
||||
Console.ReadLine();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
|
@ -423,14 +423,14 @@ namespace Rests
|
|||
{
|
||||
return new RestObject("500")
|
||||
{
|
||||
{"error", "Internal server error."},
|
||||
{"error", GetString("Internal server error.") },
|
||||
{"errormsg", exception.Message},
|
||||
{"stacktrace", exception.StackTrace},
|
||||
};
|
||||
}
|
||||
return new RestObject("404")
|
||||
{
|
||||
{"error", "Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints."}
|
||||
{"error", GetString("Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints.") }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -448,7 +448,8 @@ namespace Rests
|
|||
object result = cmd.Execute(verbs, parms, request, context);
|
||||
if (cmd.DoLog && TShock.Config.Settings.LogRest)
|
||||
{
|
||||
TShock.Log.ConsoleInfo("Anonymous requested REST endpoint: " + BuildRequestUri(cmd, verbs, parms, false));
|
||||
var endpoint = BuildRequestUri(cmd, verbs, parms, false);
|
||||
TShock.Log.ConsoleInfo(GetString($"Anonymous requested REST endpoint: {endpoint}"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -479,7 +480,7 @@ namespace Rests
|
|||
requestBuilder.Append(param.Value);
|
||||
separator = '&';
|
||||
}
|
||||
|
||||
|
||||
return requestBuilder.ToString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,15 +92,15 @@ namespace Rests
|
|||
|
||||
public override object Execute(RestVerbs verbs, IParameterCollection parameters, IRequest request, IHttpContext context)
|
||||
{
|
||||
return new RestObject("401") { Error = "Not authorized. The specified API endpoint requires a token." };
|
||||
return new RestObject("401") { Error = GetString("Not authorized. The specified API endpoint requires a token.") };
|
||||
}
|
||||
|
||||
public object Execute(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData, IRequest request, IHttpContext context)
|
||||
{
|
||||
if (tokenData.Equals(SecureRest.TokenData.None))
|
||||
return new RestObject("401") { Error = "Not authorized. The specified API endpoint requires a token." };
|
||||
return new RestObject("401") { Error = GetString("Not authorized. The specified API endpoint requires a token.") };
|
||||
|
||||
return callback(new RestRequestArgs(verbs, parameters, request, tokenData, context));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Token"/>
|
||||
/// </summary>
|
||||
public Token() : base("token", true, "The REST authentication token.", typeof(String)) { }
|
||||
public Token() : base("token", true, GetString("The REST authentication token."), typeof(String)) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -665,10 +665,10 @@ namespace TShockAPI
|
|||
player.Kick(reason, true);
|
||||
}
|
||||
|
||||
return RestResponse($"Ban added. Ticket number: {banResult.Ban.TicketNumber}");
|
||||
return RestResponse(GetString($"Ban added. Ticket number: {banResult.Ban.TicketNumber}"));
|
||||
}
|
||||
|
||||
return RestError($"Failed to add ban. {banResult.Message}", status: "500");
|
||||
return RestError(GetString($"Failed to add ban. {banResult.Message}"), status: "500");
|
||||
}
|
||||
|
||||
[Description("Delete an existing ban entry.")]
|
||||
|
|
@ -692,10 +692,10 @@ namespace TShockAPI
|
|||
|
||||
if (TShock.Bans.RemoveBan(ticketNumber, fullDelete))
|
||||
{
|
||||
return RestResponse("Ban removed.");
|
||||
return RestResponse(GetString("Ban removed."));
|
||||
}
|
||||
|
||||
return RestError("Failed to remove ban.", status: "500");
|
||||
return RestError(GetString("Failed to remove ban."), status: "500");
|
||||
}
|
||||
|
||||
[Description("View the details of a specific ban.")]
|
||||
|
|
@ -718,7 +718,7 @@ namespace TShockAPI
|
|||
|
||||
if (ban == null)
|
||||
{
|
||||
return RestResponse("No matching bans found.");
|
||||
return RestResponse(GetString("No matching bans found."));
|
||||
}
|
||||
|
||||
return new RestObject
|
||||
|
|
@ -777,7 +777,7 @@ namespace TShockAPI
|
|||
return RestInvalidParam("state");
|
||||
TShock.Config.Settings.AutoSave = autoSave;
|
||||
|
||||
var resp = RestResponse("AutoSave has been set to " + autoSave);
|
||||
var resp = RestResponse($"AutoSave has been set to {autoSave}");
|
||||
resp.Add("upgrade", "/v3/world/autosave");
|
||||
return resp;
|
||||
}
|
||||
|
|
@ -791,11 +791,25 @@ namespace TShockAPI
|
|||
bool autoSave;
|
||||
if (!bool.TryParse(args.Parameters["state"], out autoSave))
|
||||
{
|
||||
return RestResponse($"Autosave is currently {(TShock.Config.Settings.AutoSave ? "enabled" : "disabled")}");
|
||||
if (TShock.Config.Settings.AutoSave)
|
||||
{
|
||||
return RestResponse(GetString($"Autosave is currently enabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return RestResponse(GetString($"Autosave is currently disabled"));
|
||||
}
|
||||
}
|
||||
TShock.Config.Settings.AutoSave = autoSave;
|
||||
|
||||
return RestResponse($"AutoSave has been {(TShock.Config.Settings.AutoSave ? "enabled" : "disabled")}");
|
||||
if (TShock.Config.Settings.AutoSave)
|
||||
{
|
||||
return RestResponse(GetString($"AutoSave has been enabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return RestResponse(GetString($"AutoSave has been disabled"));
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Save the world.")]
|
||||
|
|
@ -830,7 +844,7 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
return RestResponse(killcount + " NPCs have been killed");
|
||||
return RestResponse(GetPluralString($"{killcount} NPC has been killed.", "{killcount} NPCs have been killed.", killcount));
|
||||
}
|
||||
|
||||
[Description("Get information regarding the world.")]
|
||||
|
|
@ -857,7 +871,7 @@ namespace TShockAPI
|
|||
{
|
||||
WorldGen.spawnMeteor = false;
|
||||
WorldGen.dropMeteor();
|
||||
return RestResponse("Meteor has been spawned");
|
||||
return RestResponse(GetString("Meteor has been spawned"));
|
||||
}
|
||||
|
||||
[Description("Toggle the status of blood moon.")]
|
||||
|
|
@ -872,7 +886,7 @@ namespace TShockAPI
|
|||
return RestInvalidParam("bloodmoon");
|
||||
Main.bloodMoon = bloodmoon;
|
||||
|
||||
var resp = RestResponse("Blood Moon has been set to " + bloodmoon);
|
||||
var resp = RestResponse(GetString($"Blood Moon has been set to {bloodmoon}"));
|
||||
resp.Add("upgrade", "/v3/world/bloodmoon");
|
||||
return resp;
|
||||
}
|
||||
|
|
@ -887,11 +901,18 @@ namespace TShockAPI
|
|||
bool bloodmoon;
|
||||
if (!bool.TryParse(args.Verbs["state"], out bloodmoon))
|
||||
{
|
||||
return RestResponse($"Bloodmoon state: {(Main.bloodMoon ? "Enabled" : "Disabled")}");
|
||||
return RestResponse(GetString($"Bloodmoon state: {(Main.bloodMoon ? "Enabled" : "Disabled")}"));
|
||||
}
|
||||
Main.bloodMoon = bloodmoon;
|
||||
|
||||
return RestResponse($"Blood Moon has been {(Main.bloodMoon ? "enabled" : "disabled")}");
|
||||
if (Main.bloodMoon)
|
||||
{
|
||||
return RestResponse($"Blood Moon has been enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
return RestResponse($"Blood Moon has been disabled");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -1025,8 +1046,8 @@ namespace TShockAPI
|
|||
return ret;
|
||||
|
||||
TSPlayer player = (TSPlayer)ret;
|
||||
player.Kick(null == args.Parameters["reason"] ? "Kicked via web" : args.Parameters["reason"], false, true, null, true);
|
||||
return RestResponse("Player " + player.Name + " was kicked");
|
||||
player.Kick(null == args.Parameters["reason"] ? GetString("Kicked via web") : args.Parameters["reason"], false, true, null, true);
|
||||
return RestResponse($"Player {player.Name} was kicked");
|
||||
}
|
||||
|
||||
[Description("Kill a player.")]
|
||||
|
|
@ -1044,8 +1065,8 @@ namespace TShockAPI
|
|||
TSPlayer player = (TSPlayer)ret;
|
||||
player.DamagePlayer(999999);
|
||||
var from = string.IsNullOrWhiteSpace(args.Parameters["from"]) ? "Server Admin" : args.Parameters["from"];
|
||||
player.SendInfoMessage(string.Format("{0} just killed you!", from));
|
||||
return RestResponse("Player " + player.Name + " was killed");
|
||||
player.SendInfoMessage(GetString($"{from} just killed you!"));
|
||||
return RestResponse(GetString($"Player {player.Name} was killed"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -1109,7 +1130,7 @@ namespace TShockAPI
|
|||
return RestError(e.Message);
|
||||
}
|
||||
|
||||
return RestResponse("Group '" + group.Name + "' deleted successfully");
|
||||
return RestResponse(GetString($"Group {group.Name} deleted successfully"));
|
||||
}
|
||||
|
||||
[Description("Create a new group.")]
|
||||
|
|
@ -1134,7 +1155,7 @@ namespace TShockAPI
|
|||
return RestError(e.Message);
|
||||
}
|
||||
|
||||
return RestResponse("Group '" + name + "' created successfully");
|
||||
return RestResponse(GetString($"Group {name} created successfully"));
|
||||
}
|
||||
|
||||
[Route("/v2/groups/update")]
|
||||
|
|
@ -1163,13 +1184,14 @@ namespace TShockAPI
|
|||
return RestError(e.Message);
|
||||
}
|
||||
|
||||
return RestResponse("Group '" + group.Name + "' updated successfully");
|
||||
return RestResponse(GetString($"Group {group.Name} updated successfully"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility Methods
|
||||
|
||||
// TODO: figure out how to localise the route descriptions
|
||||
public static void DumpDescriptions()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
|
@ -1243,7 +1265,7 @@ namespace TShockAPI
|
|||
|
||||
private RestObject RestMissingParam(string var)
|
||||
{
|
||||
return RestError("Missing or empty " + var + " parameter");
|
||||
return RestError(GetString($"Missing or empty {var} parameter"));
|
||||
}
|
||||
|
||||
private RestObject RestMissingParam(params string[] vars)
|
||||
|
|
@ -1253,7 +1275,7 @@ namespace TShockAPI
|
|||
|
||||
private RestObject RestInvalidParam(string var)
|
||||
{
|
||||
return RestError("Missing or invalid " + var + " parameter");
|
||||
return RestError(GetString($"Missing or invalid {var} parameter"));
|
||||
}
|
||||
|
||||
private bool GetBool(string val, bool def)
|
||||
|
|
@ -1274,9 +1296,9 @@ namespace TShockAPI
|
|||
case 1:
|
||||
return found[0];
|
||||
case 0:
|
||||
return RestError("Player " + name + " was not found");
|
||||
return RestError(GetString($"Player {name} was not found"));
|
||||
default:
|
||||
return RestError("Player " + name + " matches " + found.Count + " players");
|
||||
return RestError(GetPluralString($"Player {name} matches {found.Count} player", $"Player {name} matches {found.Count} players", found.Count));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1301,7 +1323,7 @@ namespace TShockAPI
|
|||
account = TShock.UserAccounts.GetUserAccountByID(Convert.ToInt32(name));
|
||||
break;
|
||||
default:
|
||||
return RestError("Invalid Type: '" + type + "'");
|
||||
return RestError(GetString($"Invalid Type: '{type}'"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -1310,7 +1332,7 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
if (null == account)
|
||||
return RestError(String.Format("User {0} '{1}' doesn't exist", type, name));
|
||||
return RestError(GetString($"User {type} '{name}' doesn't exist"));
|
||||
|
||||
return account;
|
||||
}
|
||||
|
|
@ -1323,7 +1345,7 @@ namespace TShockAPI
|
|||
|
||||
var group = TShock.Groups.GetGroupByName(name);
|
||||
if (null == group)
|
||||
return RestError("Group '" + name + "' doesn't exist");
|
||||
return RestError(GetString($"Group {name} doesn't exist"));
|
||||
|
||||
return group;
|
||||
}
|
||||
|
|
@ -1360,9 +1382,16 @@ namespace TShockAPI
|
|||
|
||||
TSPlayer player = (TSPlayer)ret;
|
||||
player.mute = mute;
|
||||
var verb = mute ? "muted" : "unmuted";
|
||||
player.SendInfoMessage("You have been remotely " + verb);
|
||||
return RestResponse("Player " + player.Name + " was " + verb);
|
||||
if (mute)
|
||||
{
|
||||
player.SendInfoMessage(GetString("You have been remotely muted"));
|
||||
return RestResponse(GetString($"Player {player.Name} has been muted"));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendInfoMessage(GetString("You have been remotely unmmuted"));
|
||||
return RestResponse(GetString($"Player {player.Name} has been unmuted"));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -87,10 +87,10 @@ namespace Rests
|
|||
catch (Exception)
|
||||
{
|
||||
return new RestObject("400")
|
||||
{ Error = "The specified token queued for destruction failed to be deleted." };
|
||||
{ Error = GetString("The specified token queued for destruction failed to be deleted.") };
|
||||
}
|
||||
return new RestObject()
|
||||
{ Response = "Requested token was successfully destroyed." };
|
||||
{ Response = GetString("Requested token was successfully destroyed.") };
|
||||
}
|
||||
|
||||
private object DestroyAllTokens(RestRequestArgs args)
|
||||
|
|
@ -117,7 +117,7 @@ namespace Rests
|
|||
{
|
||||
if (tokens >= TShock.Config.Settings.RESTMaximumRequestsPerInterval)
|
||||
{
|
||||
TShock.Log.ConsoleError("A REST login from {0} was blocked as it currently has {1} rate-limit tokens and is at the RESTMaximumRequestsPerInterval threshold.", context.RemoteEndPoint.Address.ToString(), tokens);
|
||||
TShock.Log.ConsoleError(GetString("A REST login from {0} was blocked as it currently has {1} rate-limit tokens and is at the RESTMaximumRequestsPerInterval threshold.", context.RemoteEndPoint.Address.ToString(), tokens));
|
||||
tokenBucket[context.RemoteEndPoint.Address.ToString()] += 1; // Tokens over limit, increment by one and reject request
|
||||
return new RestObject("403")
|
||||
{
|
||||
|
|
@ -135,13 +135,13 @@ namespace Rests
|
|||
if (userAccount == null)
|
||||
{
|
||||
AddTokenToBucket(context.RemoteEndPoint.Address.ToString());
|
||||
return new RestObject("403") { Error = "Username or password may be incorrect or this account may not have sufficient privileges." };
|
||||
return new RestObject("403") { Error = GetString("Username or password may be incorrect or this account may not have sufficient privileges.") };
|
||||
}
|
||||
|
||||
if (!userAccount.VerifyPassword(password))
|
||||
{
|
||||
AddTokenToBucket(context.RemoteEndPoint.Address.ToString());
|
||||
return new RestObject("403") { Error = "Username or password may be incorrect or this account may not have sufficient privileges." };
|
||||
return new RestObject("403") { Error = GetString("Username or password may be incorrect or this account may not have sufficient privileges.") };
|
||||
}
|
||||
|
||||
Group userGroup = TShock.Groups.GetGroupByName(userAccount.Group);
|
||||
|
|
@ -149,7 +149,7 @@ namespace Rests
|
|||
{
|
||||
AddTokenToBucket(context.RemoteEndPoint.Address.ToString());
|
||||
return new RestObject("403")
|
||||
{ Error = "Username or password may be incorrect or this account may not have sufficient privileges." };
|
||||
{ Error = GetString("Username or password may be incorrect or this account may not have sufficient privileges.") };
|
||||
}
|
||||
|
||||
string tokenHash;
|
||||
|
|
@ -164,7 +164,7 @@ namespace Rests
|
|||
|
||||
AddTokenToBucket(context.RemoteEndPoint.Address.ToString());
|
||||
|
||||
RestObject response = new RestObject() { Response = "Successful login" };
|
||||
RestObject response = new RestObject() { Response = GetString("Successful login") };
|
||||
response["token"] = tokenHash;
|
||||
return response;
|
||||
}
|
||||
|
|
@ -177,13 +177,13 @@ namespace Rests
|
|||
var token = parms["token"];
|
||||
if (token == null)
|
||||
return new RestObject("401")
|
||||
{ Error = "Not authorized. The specified API endpoint requires a token." };
|
||||
{ Error = GetString("Not authorized. The specified API endpoint requires a token.") };
|
||||
|
||||
SecureRestCommand secureCmd = (SecureRestCommand)cmd;
|
||||
TokenData tokenData;
|
||||
if (!Tokens.TryGetValue(token, out tokenData) && !AppTokens.TryGetValue(token, out tokenData))
|
||||
return new RestObject("403")
|
||||
{ Error = "Not authorized. The specified API endpoint requires a token, but the provided token was not valid." };
|
||||
{ Error = GetString("Not authorized. The specified API endpoint requires a token, but the provided token was not valid.") };
|
||||
|
||||
Group userGroup = TShock.Groups.GetGroupByName(tokenData.UserGroupName);
|
||||
if (userGroup == null)
|
||||
|
|
@ -191,13 +191,13 @@ namespace Rests
|
|||
Tokens.Remove(token);
|
||||
|
||||
return new RestObject("403")
|
||||
{ Error = "Not authorized. The provided token became invalid due to group changes, please create a new token." };
|
||||
{ Error = GetString("Not authorized. The provided token became invalid due to group changes, please create a new token.") };
|
||||
}
|
||||
|
||||
if (secureCmd.Permissions.Length > 0 && secureCmd.Permissions.All(perm => !userGroup.HasPermission(perm)))
|
||||
{
|
||||
return new RestObject("403")
|
||||
{ Error = string.Format("Not authorized. User \"{0}\" has no access to use the specified API endpoint.", tokenData.Username) };
|
||||
{ Error = GetString("Not authorized. User \"{0}\" has no access to use the specified API endpoint.", tokenData.Username) };
|
||||
}
|
||||
|
||||
//Main.rand being null can cause issues in command execution.
|
||||
|
|
@ -209,7 +209,7 @@ namespace Rests
|
|||
|
||||
object result = secureCmd.Execute(verbs, parms, tokenData, request, context);
|
||||
if (cmd.DoLog && TShock.Config.Settings.LogRest)
|
||||
TShock.Utils.SendLogs(string.Format(
|
||||
TShock.Utils.SendLogs(GetString(
|
||||
"\"{0}\" requested REST endpoint: {1}", tokenData.Username, this.BuildRequestUri(cmd, verbs, parms, false)),
|
||||
Color.PaleVioletRed);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue