Skip to content

Commit

Permalink
Merge pull request #606 from starfi5h/pr-translation
Browse files Browse the repository at this point in the history
Add Translate() method
  • Loading branch information
starfi5h authored Jul 9, 2023
2 parents e12cc76 + 69d2c04 commit 8e6748a
Show file tree
Hide file tree
Showing 32 changed files with 249 additions and 156 deletions.
32 changes: 16 additions & 16 deletions NebulaNetwork/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
if (e.Code == (ushort)DisconnectionReason.ModIsMissing)
{
InGamePopup.ShowWarning(
"Mod Mismatch",
$"You are missing mod {e.Reason}",
"Mod Mismatch".Translate(),
string.Format("You are missing mod {0}".Translate(), e.Reason),
"OK".Translate(),
Multiplayer.LeaveGame);
return;
Expand All @@ -267,8 +267,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
if (e.Code == (ushort)DisconnectionReason.ModIsMissingOnServer)
{
InGamePopup.ShowWarning(
"Mod Mismatch",
$"Server is missing mod {e.Reason}",
"Mod Mismatch".Translate(),
string.Format("Server is missing mod {0}".Translate(), e.Reason),
"OK".Translate(),
Multiplayer.LeaveGame);
return;
Expand All @@ -278,8 +278,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
{
string[] versions = e.Reason.Split(';');
InGamePopup.ShowWarning(
"Mod Version Mismatch",
$"Your mod {versions[0]} version is not the same as the Host version.\nYou:{versions[1]} - Remote:{versions[2]}",
"Mod Version Mismatch".Translate(),
string.Format("Your mod {0} version is not the same as the Host version.\nYou:{1} - Remote:{2}".Translate(), versions[0], versions[1], versions[2]),
"OK".Translate(),
Multiplayer.LeaveGame);
return;
Expand All @@ -289,8 +289,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
{
string[] versions = e.Reason.Split(';');
InGamePopup.ShowWarning(
"Game Version Mismatch",
$"Your version of the game is not the same as the one used by the Host.\nYou:{versions[0]} - Remote:{versions[1]}",
"Game Version Mismatch".Translate(),
string.Format("Your version of the game is not the same as the one used by the Host.\nYou:{0} - Remote:{1}".Translate(), versions[0], versions[1]),
"OK".Translate(),
Multiplayer.LeaveGame);
return;
Expand All @@ -299,8 +299,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
if (e.Code == (ushort)DisconnectionReason.ProtocolError && websocketAuthenticationFailure)
{
InGamePopup.AskInput(
"Server Requires Password",
"Server is protected. Please enter the correct password:",
"Server Requires Password".Translate(),
"Server is protected. Please enter the correct password:".Translate(),
InputField.ContentType.Password,
serverPassword,
(password) =>
Expand All @@ -318,8 +318,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
if (e.Code == (ushort)DisconnectionReason.HostStillLoading)
{
InGamePopup.ShowWarning(
"Server Busy",
"Server is not ready to join. Please try again later.",
"Server Busy".Translate(),
"Server is not ready to join. Please try again later.".Translate(),
"OK".Translate(),
Multiplayer.LeaveGame);
return;
Expand All @@ -328,8 +328,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
if (Multiplayer.Session.IsGameLoaded || Multiplayer.Session.IsInLobby)
{
InGamePopup.ShowWarning(
"Connection Lost",
$"You have been disconnected from the server.\n{e.Reason}",
"Connection Lost".Translate(),
"You have been disconnected from the server.".Translate() + "\n" + e.Reason,
"Quit",
Multiplayer.LeaveGame);
if (Multiplayer.Session.IsInLobby)
Expand All @@ -343,8 +343,8 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e)
{
Log.Warn("Disconnect code: " + e.Code + ", reason:" + e.Reason);
InGamePopup.ShowWarning(
"Server Unavailable",
$"Could not reach the server, please try again later.",
"Server Unavailable".Translate(),
"Could not reach the server, please try again later.".Translate(),
"OK".Translate(),
Multiplayer.LeaveGame);
}
Expand Down
24 changes: 12 additions & 12 deletions NebulaNetwork/Ngrok/NgrokManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public NgrokManager(int port, string authtoken = null, string region = null)

if (string.IsNullOrEmpty(_authtoken))
{
NebulaModel.Logger.Log.WarnInform("Ngrok support was enabled, however no Authtoken was provided");
NebulaModel.Logger.Log.WarnInform("Ngrok support was enabled, however no Authtoken was provided".Translate());
return;
}

// Validate the Ngrok region
string[] availableRegions = { "us", "eu", "au", "ap", "sa", "jp", "in" };
if (!string.IsNullOrEmpty(_region) && !availableRegions.Any(_region.Contains))
{
NebulaModel.Logger.Log.WarnInform("Unsupported Ngrok region was provided, defaulting to autodetection");
NebulaModel.Logger.Log.WarnInform("Unsupported Ngrok region was provided, defaulting to autodetection".Translate());
_region = null;
}

Expand All @@ -67,10 +67,10 @@ public NgrokManager(int port, string authtoken = null, string region = null)
UnityDispatchQueue.RunOnMainThread(() =>
{
InGamePopup.ShowWarning(
"Ngrok download and installation confirmation",
"Ngrok support is enabled, however it has not been downloaded and installed yet, do you want to automatically download and install Ngrok?",
"Accept",
"Reject",
"Ngrok download and installation confirmation".Translate(),
"Ngrok support is enabled, however it has not been downloaded and installed yet, do you want to automatically download and install Ngrok?".Translate(),
"Accept".Translate(),
"Reject".Translate(),
() => downloadAndInstallConfirmationSource.TrySetResult(true),
() => downloadAndInstallConfirmationSource.TrySetResult(false)
);
Expand All @@ -79,7 +79,7 @@ public NgrokManager(int port, string authtoken = null, string region = null)
var hasDownloadAndInstallBeenConfirmed = await downloadAndInstallConfirmationSource.Task;
if (!hasDownloadAndInstallBeenConfirmed)
{
NebulaModel.Logger.Log.Warn("Failed to download or install Ngrok, because user rejected Ngrok download and install confirmation!");
NebulaModel.Logger.Log.Warn("Failed to download or install Ngrok, because user rejected Ngrok download and install confirmation!".Translate());
return;
}

Expand All @@ -89,21 +89,21 @@ public NgrokManager(int port, string authtoken = null, string region = null)
}
catch
{
NebulaModel.Logger.Log.WarnInform("Failed to download or install Ngrok!");
NebulaModel.Logger.Log.WarnInform("Failed to download or install Ngrok!".Translate());
throw;
}

}

if (!StartNgrok())
{
NebulaModel.Logger.Log.WarnInform($"Failed to start Ngrok tunnel! LastErrorCode: {NgrokLastErrorCode}");
NebulaModel.Logger.Log.WarnInform(string.Format("Failed to start Ngrok tunnel! LastErrorCode: {0}".Translate(), NgrokLastErrorCode));
return;
}

if (!IsNgrokActive())
{
NebulaModel.Logger.Log.WarnInform($"Ngrok tunnel has exited prematurely! LastErrorCode: {NgrokLastErrorCode}");
NebulaModel.Logger.Log.WarnInform(string.Format("Ngrok tunnel has exited prematurely! LastErrorCode: {0}".Translate(), NgrokLastErrorCode));
return;
}

Expand All @@ -130,7 +130,7 @@ private async Task DownloadAndInstallNgrok()

File.WriteAllLines(_ngrokConfigPath, new string[] { "version: 2" });

NebulaModel.Logger.Log.WarnInform("Ngrok install completed in the plugin folder");
NebulaModel.Logger.Log.WarnInform("Ngrok install completed in the plugin folder".Translate());
}

private bool IsNgrokInstalled()
Expand Down Expand Up @@ -217,7 +217,7 @@ private void ErrorDataReceivedEventHandler(object sender, DataReceivedEventArgs
if (errorCodeMatches.Count > 0)
{
NgrokLastErrorCode = errorCodeMatches[errorCodeMatches.Count - 1].Value;
NebulaModel.Logger.Log.WarnInform($"Ngrok Error! Code: {NgrokLastErrorCode}");
NebulaModel.Logger.Log.WarnInform(string.Format("Ngrok Error! Code: {0}".Translate(), NgrokLastErrorCode));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void ProcessPacket(ChatCommandWhisperPacket packet, NebulaConnec
{
Log.Warn($"Recipient not found {packet.RecipientUsername}");
INebulaPlayer sender = Multiplayer.Session.Network.PlayerManager.GetPlayer(conn);
sender.SendPacket(new ChatCommandWhisperPacket("SYSTEM", packet.SenderUsername, $"User not found {packet.RecipientUsername}"));
sender.SendPacket(new ChatCommandWhisperPacket("SYSTEM".Translate(), packet.SenderUsername, string.Format("User not found {0}".Translate(), packet.RecipientUsername)));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ internal class RemoteServerCommmandProcessor : PacketProcessor<RemoteServerComma

public override void ProcessPacket(RemoteServerCommandPacket packet, NebulaConnection conn)
{
string respond = "Unknown command";
string respond = "Unknown command".Translate();

// Don't run remote save command if it is not available
if (!Config.Options.RemoteAccessEnabled || !Multiplayer.IsDedicated || !IsHost)
{
respond = "Remote server access is not enabled";
respond = "Remote server access is not enabled".Translate();
conn.SendPacket(new NewChatMessagePacket(ChatMessageType.SystemWarnMessage, respond, DateTime.Now, ""));
return;
}
Expand All @@ -39,7 +39,7 @@ public override void ProcessPacket(RemoteServerCommandPacket packet, NebulaConne
{
if (!string.IsNullOrWhiteSpace(Config.Options.RemoteAccessPassword))
{
respond = "You need to login first!";
respond = "You need to login first!".Translate();
conn.SendPacket(new NewChatMessagePacket(ChatMessageType.SystemWarnMessage, respond, DateTime.Now, ""));
return;
}
Expand Down Expand Up @@ -83,26 +83,26 @@ private string Login(NebulaConnection conn, string passwordHash)
{
if (allowedConnections.Contains(conn))
{
return "You have already logged in";
return "You have already logged in".Translate();
}
if (!string.IsNullOrWhiteSpace(Config.Options.RemoteAccessPassword))
{
int cdtime = SERVERLOGIN_COOLDOWN - (int)(DateTime.Now - LastLoginTime).TotalSeconds;
if (cdtime > 0)
{
return $"Cooldown: {cdtime}s";
return string.Format("Cooldown: {0}s".Translate(), cdtime);
}
LastLoginTime = DateTime.Now;
IPlayerData playerData = Multiplayer.Session.Network.PlayerManager.GetPlayer(conn)?.Data;
string salt = playerData != null ? playerData.Username + playerData.PlayerId : "";
string hash = CryptoUtils.Hash(Config.Options.RemoteAccessPassword + salt);
if (hash != passwordHash)
{
return "Password incorrect!";
return "Password incorrect!".Translate();
}
}
allowedConnections.Add(conn);
return "Login success!";
return "Login success!".Translate();
}

private static string List(string numString)
Expand All @@ -126,7 +126,7 @@ private static string List(string numString)

Array.Sort(dates, names);
StringBuilder sb = new();
sb.AppendLine($"Save list on server: ({num}/{files.Length})");
sb.AppendLine(string.Format("Save list on server: ({0}/{1})".Translate(), num, files.Length));
for (int i = files.Length - num; i < files.Length; i++)
{
sb.AppendLine($"{dates[i]} {names[i]}");
Expand All @@ -142,19 +142,19 @@ private string Save(string saveName)
// Save game and report result to the client
LastSaveTime = DateTime.Now;
saveName = string.IsNullOrEmpty(saveName) ? GameSave.LastExit : saveName;
return $"Save {saveName} : " + (GameSave.SaveCurrentGame(saveName) ? "Success" : "Fail");
return string.Format("Save {0} : {1}".Translate(), saveName, GameSave.SaveCurrentGame(saveName) ? "Success".Translate() : "Fail".Translate());
}
else
{
return $"Cooldown: {countDown}s";
return string.Format("Cooldown: {0}s".Translate(), countDown);
}
}

private static string Load(string saveName)
{
if (!GameSave.SaveExist(saveName))
{
return $"{saveName} doesn't exist";
return string.Format("{0} doesn't exist".Translate(), saveName);
}

Log.Info($"Received command to load {saveName}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void ProcessPacket(BuildEntityRequest packet, NebulaConnection c
GameMain.gpuiManager.specifyPlanet = GameMain.galaxy.PlanetById(packet.PlanetId);
if (packet.EntityId != -1 && packet.EntityId != NebulaWorld.Factory.FactoryManager.GetNextEntityId(planet.factory))
{
string warningText = $"(Desync) EntityId mismatch {packet.EntityId} != {NebulaWorld.Factory.FactoryManager.GetNextEntityId(planet.factory)} on planet {planet.id}. Clients should reconnect!";
string warningText = string.Format("(Desync) EntityId mismatch {0} != {1} on planet {2}. Clients should reconnect!".Translate(), packet.EntityId, NebulaWorld.Factory.FactoryManager.GetNextEntityId(planet.factory), planet.displayName);
Log.WarnInform(warningText);
NebulaWorld.Warning.WarningManager.DisplayTemporaryWarning(warningText, 5000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override void ProcessPacket(HandshakeResponse packet, NebulaConnection co
gameDesc.isSandboxMode = packet.IsSandboxMode;
DSPGame.StartGameSkipPrologue(gameDesc);

InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
InGamePopup.ShowInfo("Loading".Translate(), "Loading state from server, please wait".Translate(), null);

Multiplayer.Session.NumPlayers = packet.NumPlayers;
DiscordManager.UpdateRichPresence(partyId: packet.DiscordPartyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public override void ProcessPacket(StartGameMessage packet, NebulaConnection con

DSPGame.StartGameSkipPrologue(UIRoot.instance.galaxySelect.gameDesc);

InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
InGamePopup.ShowInfo("Loading".Translate(), "Loading state from server, please wait".Translate(), null);
}
else
{
InGamePopup.ShowInfo("Please Wait", "The host is not ready to let you in, please wait!", "Okay");
InGamePopup.ShowInfo("Unavailable".Translate(), "The host is not ready to let you in, please wait!".Translate(), "OK".Translate());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions NebulaNetwork/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public override void Start()
}
catch (NatDeviceNotFoundException)
{
Log.WarnInform("No UPnp or Pmp compatible/enabled NAT device found");
Log.WarnInform("No UPnp or Pmp compatible/enabled NAT device found".Translate());
}
catch (MappingException)
{
Log.WarnInform("Could not create UPnp or Pmp port mapping");
Log.WarnInform("Could not create UPnp or Pmp port mapping".Translate());
}
});
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public override void Start()
socket.Start();
}catch(System.InvalidOperationException e)
{
InGamePopup.ShowError("Error", "An error occurred while hosting the game: " + e.Message, "Close");
InGamePopup.ShowError("Error", "An error occurred while hosting the game: ".Translate() + e.Message, "Close".Translate());
Stop();
Multiplayer.LeaveGame();
return;
Expand Down Expand Up @@ -301,7 +301,7 @@ protected override void OnOpen()
if (Multiplayer.Session.IsGameLoaded == false && Multiplayer.Session.IsInLobby == false)
{
// Reject any connection that occurs while the host's game is loading.
Context.WebSocket.Close((ushort)DisconnectionReason.HostStillLoading, "Host still loading, please try again later.");
Context.WebSocket.Close((ushort)DisconnectionReason.HostStillLoading, "Host still loading, please try again later.".Translate());
return;
}

Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/DESelection_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static bool SetViewStar_Prefix(DESelection __instance, ref StarData starD
}
else
{
InGamePopup.ShowInfo("Loading", $"Loading Dyson sphere {starData.displayName}, please wait...", null);
InGamePopup.ShowInfo("Loading".Translate(), string.Format("Loading Dyson sphere {0}, please wait".Translate(), starData.displayName), null);
}
// Restore comboBox back to original star
UIComboBox dysonBox = UIRoot.instance.uiGame.dysonEditor.controlPanel.topFunction.dysonBox;
Expand Down
Loading

0 comments on commit 8e6748a

Please sign in to comment.