internal static async Task Broadcast(string PreNSuf, string Message, byte r, byte g, byte b, TSPlayer tsplr, ServerChatEventArgs args) { args.Handled = true; string OriginalMessage = $"{PreNSuf}{Message}"; TShock.Log.Info(string.Format("Broadcast: {0}", OriginalMessage)); string text = String.Format(PConfig.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, args.Text); bool[] PlayerLangOn = new bool[3]; //0 = EN | 1 = PT | 2 = ES string[] TrMessage = new string[3]; //0 = EN | 1 = PT | 2 = ES if (!PConfig.Enabled) { Color c = new Color(r, g, b); TShockB.AllSendMessage(OriginalMessage, c); Logger.WriteLine($"[{Logger.DateTimeNow}] [CHAT] {System.Text.RegularExpressions.Regex.Replace(OriginalMessage, @"\[c\/[a-f0-9]{6}:([^\]]+)]", @"$1")}", ConsoleColor.DarkGreen); PlayerHooks.OnPlayerChat(tsplr, args.Text, ref text); return; } TSPlayerB.SendMessage(tsplr.Index, OriginalMessage, r, g, b); if (!PConfig.ConsoleChatTranslate) { Logger.WriteLine($"[{Logger.DateTimeNow}] [CHAT] {System.Text.RegularExpressions.Regex.Replace(OriginalMessage, @"\[c\/[a-f0-9]{6}:([^\]]+)]", @"$1")}", ConsoleColor.DarkGreen); } foreach (var plr in TShockB.Players.Where(p => p != null && p.Active)) { PlayerLangOn[(int)Enum.Parse(typeof(TSPlayerB.Language), Base.Config.DefaultHydraLanguage)] = true; if (PlayerLangOn[0] && PlayerLangOn[1] && PlayerLangOn[2]) { break; } switch (TSPlayerB.PlayerLanguage[plr.Index]) { case TSPlayerB.Language.English: PlayerLangOn[0] = true; break; case TSPlayerB.Language.Portuguese: PlayerLangOn[1] = true; break; case TSPlayerB.Language.Spanish: PlayerLangOn[2] = true; break; } } try { if (!string.IsNullOrWhiteSpace(Message)) { foreach (var Data in PConfig.WordsReplaces) { Message = System.Text.RegularExpressions.Regex.Replace(Message, $@"\b{Data.From}\b", Data.To); } var translator = new GoogleTranslateFreeApi.GoogleTranslator(); GoogleTranslateFreeApi.Language from = GoogleTranslateFreeApi.Language.Auto; for (int i = 0; i < PlayerLangOn.Count(); i++) { if (i == (int)TSPlayerB.PlayerLanguage[tsplr.Index]) { TrMessage[i] = $"{OriginalMessage}{SuccessTag()}"; continue; } if (PlayerLangOn[i]) { GoogleTranslateFreeApi.Language to = GoogleTranslateFreeApi.Language.English; switch (i) { case 1: to = GoogleTranslateFreeApi.Language.Portuguese; break; case 2: to = GoogleTranslateFreeApi.Language.Spanish; break; } var result = await translator.TranslateLiteAsync(Message, from, to); TrMessage[i] = $"{PreNSuf}{result.MergedTranslation}{SuccessTag()}"; } } if (PConfig.ConsoleChatTranslate) { Logger.WriteLine($"[{Logger.DateTimeNow}] [CHAT] {System.Text.RegularExpressions.Regex.Replace(TrMessage[(int)Enum.Parse(typeof(TSPlayerB.Language), Base.Config.DefaultHydraLanguage)], @"\[c\/[a-f0-9]{6}:([^\]]+)]", @"$1")}", ConsoleColor.DarkGreen); } } else { return; } } catch (Exception ex) { for (int i = 0; i < PlayerLangOn.Count(); i++) { if (PlayerLangOn[i]) { TrMessage[i] = $"{OriginalMessage}{ErrorTag()}"; } } if (PConfig.ConsoleChatTranslate) { Logger.WriteLine($"[{Logger.DateTimeNow}] [CHAT] {System.Text.RegularExpressions.Regex.Replace(TrMessage[(int)Enum.Parse(typeof(TSPlayerB.Language), Base.Config.DefaultHydraLanguage)], @"\[c\/[a-f0-9]{6}:([^\]]+)]", @"$1")}", ConsoleColor.DarkRed); } Logger.doLog($"[Hydra.ChatTranslator] {ex.Message}", Hydra.Config.DebugLevel.Error, _name); } Parallel.ForEach(TShock.Players.Where(p => p != null && p != tsplr /*&& p.Active*/), fchplr => { if (DisableTr[fchplr.Index]) { TSPlayerB.SendMessage(fchplr.Index, OriginalMessage, r, g, b); } else if (TSPlayerB.PlayerLanguage[tsplr.Index] == TSPlayerB.PlayerLanguage[fchplr.Index]) { TSPlayerB.SendMessage(fchplr.Index, $"{OriginalMessage}{(TrMessage[(int)TSPlayerB.PlayerLanguage[fchplr.Index]].Contains("[c/ff0000:(X)])") ? "[c/ff0000:(X)])" : "")}" /*TrMessage[(int)TSPlayerB.PlayerLanguage[fchplr.Index]]*/, r, g, b); } else if (TSPlayerB.PlayerLanguage[tsplr.Index] != TSPlayerB.PlayerLanguage[fchplr.Index]) { TSPlayerB.SendMessage(fchplr.Index, TrMessage[(int)TSPlayerB.PlayerLanguage[fchplr.Index]], r, g, b); } }); PlayerHooks.OnPlayerChat(tsplr, args.Text, ref text); }
public static void OnGreetPlayer(GreetPlayerEventArgs args) { var player = TShockB.Players[args.Who]; if (player == null) { args.Handled = true; return; } string playername = $"[c/4747BF:{player.Name}]"; if (!Main.player[player.Index].Male) { playername = $"[c/800080:{player.Name}]"; } string via = "[c/ff4500:(via PC)]"; if (TSPlayerB.isMobile[player.Index]) { via = "[c/ff198d:(via Mobile)]"; } string country = $" ({player.Country})"; if (country.Contains("N/A") || !TShock.Config.EnableGeoIP) { country = string.Empty; } if (!player.SilentJoinInProgress) { TShockB.AllSendMessage(DefaultMessage: $"{playername}{country} has joined the server {via}!", Color.White, PortugueseMessage: $"{playername}{country} entrou no servidor {via}!", SpanishMessage: $"{playername}{country} entró al servidor {(via.Contains("(via PC)") ? "[c/ff4500:(a través de PC)]" : "[c/ff198d:(vía teléfono móvil)]")}!", ignore: player); } Logger.doLog($"{player.Name}{country} has joined the server {(TSPlayerB.isMobile[player.Index] ? "(via Mobile)" : "(via PC)")}!", Config.DebugLevel.Info); if (TShock.Config.DisplayIPToAdmins) { TShock.Utils.SendLogs(string.Format("{0} IP => {1}", player.Name, player.IP), Color.Blue); } TSPlayerB.SendFileTextAsMessage(player.Index, FileToolsB.MotdPath); string pvpMode = TShock.Config.PvPMode.ToLowerInvariant(); if (pvpMode == "always") { player.TPlayer.hostile = true; player.SendData(PacketTypes.TogglePvp, "", player.Index); TSPlayer.All.SendData(PacketTypes.TogglePvp, "", player.Index); } if (!player.IsLoggedIn) { if (Main.ServerSideCharacter) { TSPlayerB.IsDisabledForSSC[player.Index] = true; TSPlayerB.SendErrorMessage(player.Index, DefaultMessage: String.Format("Server side characters is enabled!\nPlease [c/ffd700:{0}register] or [c/ffd700:{0}login] to play!", TShockAPI.Commands.Specifier), PortugueseMessage: "SSC está ativo neste servidor.\nEfetue [c/ffd700:{TShockAPI.Commands.Specifier}registro] ou [c/ffd700:{TShockAPI.Commands.Specifier}login] para jogar.", SpanishMessage: $"SSC está activo en este servidor.\nInicia [c/ffd700:{TShockAPI.Commands.Specifier}sesión] o [c/ffd700:{TShockAPI.Commands.Specifier}registrarse] para jugar"); player.LoginHarassed = true; } else if (TShock.Config.RequireLogin) { TSPlayerB.SendErrorMessage(player.Index, DefaultMessage: $"Please [c/ffd700:{TShockAPI.Commands.Specifier}register] or [c/ffd700:{TShockAPI.Commands.Specifier}login] to play!", PortugueseMessage: $"Efetue [c/ffd700:{TShockAPI.Commands.Specifier}registro] ou [c/ffd700:{TShockAPI.Commands.Specifier}login] para jogar.", SpanishMessage: $"Inicia [c/ffd700:{TShockAPI.Commands.Specifier}sesión] o [c/ffd700:{TShockAPI.Commands.Specifier}registrarse] para jugar"); player.LoginHarassed = true; } } player.LastNetPosition = new Vector2(Main.spawnTileX * 16f, Main.spawnTileY * 16f); if (TShock.Config.RememberLeavePos && (TShock.RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero) && !player.LoginHarassed) { player.RPPending = 1; TSPlayerB.SendInfoMessage(player.Index, DefaultMessage: "You will be teleported to your last known location...", PortugueseMessage: "Você será teleportado para sua última localização...", SpanishMessage: "Serás teletransportado a tu última ubicación..."); } args.Handled = true; }