public static void OnGreetPlayer(GreetPlayerEventArgs args) { var player = TShock.Players[args.Who]; if (player == null || TShock.Users.GetUsers().Where(u => u != null && u.Name.ToLowerInvariant() == player.Name.ToLowerInvariant()).Count() >= 1 || !PConfig.EnableAutoRegister) { return; } Task.Run(() => { System.Threading.Thread.Sleep(2000); if (PConfig.AnnounceNewAccount) { foreach (TSPlayer tsplayer in TShockB.Players.Where(p => p != null && p != player)) { TSPlayerB.SendMessage(tsplayer.Index, DefaultMessage: tsplayer.TPlayer.Male ? $"yay! [c/FFD700:We have a new Terrarian with us! Be very welcome,] [c/00a0dd:{player.Name}]" : $"yay! [c/FFD700:We have a new Terrarian with us! Be very welcome,] [c/ed177a:{player.Name}]", Color.Magenta, PortugueseMessage: tsplayer.TPlayer.Male ? $"Oba! [c/FFD700:Temos um novo Terrariano conosco! Seja muito bem vindo,] [c/00a0dd:{player.Name}]" : $"Oba! [c/FFD700:Temos uma nova Terrariana conosco! Seja muito bem vinda,] [c/ed177a:{player.Name}]", SpanishMessage: tsplayer.TPlayer.Male ? $"Hurra! [c/FFD700:Tenemos un nuevo Terrario con nosotros! Sea muy bienvenido,] [c/00a0dd:{player.Name}]" : $"Hurra! [c/FFD700:Tenemos un nuevo Terrario con nosotros! Sea muy bienvenida,] [c/ed177a:{player.Name}]", EnglishMessageIfNotDefault: tsplayer.TPlayer.Male ? $"yay! [c/FFD700:We have a new Terrarian with us! Be very welcome,] [c/00a0dd:{player.Name}]" : $"yay! [c/FFD700:We have a new Terrarian with us! Be very welcome,] [c/ed177a:{player.Name}]"); } } string newPass = CreatePassword(6); Logger.doLogLang(DefaultMessage: $"Creating a new account for: {player.Name}", Hydra.Config.DebugLevel.Info, Base.CurrentHydraLanguage, _name, PortugueseMessage: $"Criando uma nova conta para: {player.Name}", SpanishMessage: $"Creando una nueva cuenta para el: {player.Name}", EnglishMessageIfNotDefault: $"Creating a new account for: {player.Name}"); try { TShock.Users.AddUser(new User( player.Name, BCrypt.Net.BCrypt.HashPassword(newPass.Trim()), player.UUID, PConfig.SelectRegisterGroupAccordingGender ? (player.TPlayer.Male ? PConfig.DefaultGroup : PConfig.FemaleDefaultGroup) : PConfig.DefaultGroup, DateTime.UtcNow.ToString("s"), DateTime.UtcNow.ToString("s"), "")); //auto login User user = TShock.Users.GetUserByName(player.Name); if (user.VerifyPassword(newPass)) { player.PlayerData = TShock.CharacterDB.GetPlayerData(player, user.ID); var group = TShock.Utils.GetGroup(user.Group); player.Group = group; player.tempGroup = null; player.User = user; player.IsLoggedIn = true; player.IgnoreActionsForInventory = "none"; if (Main.ServerSideCharacter) { if (player.HasPermission(TShockAPI.Permissions.bypassssc)) { player.PlayerData.CopyCharacter(player); TShock.CharacterDB.InsertPlayerData(player); } player.PlayerData.RestoreCharacter(player); } player.LoginFailsBySsi = false; if (player.HasPermission(TShockAPI.Permissions.ignorestackhackdetection)) { player.IgnoreActionsForCheating = "none"; } if (player.HasPermission(TShockAPI.Permissions.usebanneditem)) { player.IgnoreActionsForDisabledArmor = "none"; } player.LoginHarassed = false; TShock.Users.SetUserUUID(user, player.UUID); Logger.doLogLang(DefaultMessage: $"'{player.Name}' was automatically authenticated with the new registered account.", Hydra.Config.DebugLevel.Info, Base.CurrentHydraLanguage, _name, PortugueseMessage: $"'{player.Name}' foi autenticado automaticamente com a nova conta cadastrada.", SpanishMessage: $"'{player.Name}' se autenticó automáticamente con la nueva cuenta registrada.", EnglishMessageIfNotDefault: $"'{player.Name}' was automatically authenticated with the new registered account."); TSPlayerB.SendMessage(player.Index, DefaultMessage: "Hello! We saw that you are new so we already created your account!", Color.DeepPink, PortugueseMessage: $"Olá! Vimos que você é {(player.TPlayer.Male ? "novo" : "nova")} então já criamos a sua conta!", SpanishMessage: $"Hola! Vimos que eres {(player.TPlayer.Male ? "nuevo" : "nueva")}, así que ya creamos tu cuenta", EnglishMessageIfNotDefault: "Hello! We saw that you are new so we already created your account!"); TSPlayerB.SendMessage(player.Index, DefaultMessage: $"Your password is [c/ffa500:{newPass}], change it with [c/ffd700:/password].", Color.Red, PortugueseMessage: $"Sua senha é [c/ffa500:{newPass}], altere-a com [c/ffd700:/senha].", SpanishMessage: $"Tu contraseña es [c/ffa500:{newPass}], cambiarlo con [c/ffd700:contraseña].", EnglishMessageIfNotDefault: $"Your password is [c/ffa500:{newPass}], change it with [c/ffd700:/password]."); PlayerHooks.OnPlayerPostLogin(player); } } catch (Exception ex) { Logger.doLog(ex.ToString(), Hydra.Config.DebugLevel.Critical, _name); } }); }
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); }