public static string InsertRandomTypo(string s) { List <char> list = s.ToList <char>(); if (LexiconClass.rand.Next(0, 5) == 0 && list.Count > 0) { int index = LexiconClass.rand.Next(0, s.Length); switch (LexiconClass.rand.Next(0, 3)) { case 0: list.RemoveAt(index); break; case 1: list.Insert(index, LexiconClass.RandChar()); s = new string(list.ToArray()); break; case 2: list[index] = LexiconClass.RandChar(); s = new string(list.ToArray()); break; } } return(new string(list.ToArray())); }
private void OnChat(ServerChatEventArgs e) { TSPlayer tSPlayer = TShock.Players[e.Who]; if (!e.Text.StartsWith(TShock.Config.CommandSpecifier) && !tSPlayer.mute) { bool flag = false; for (int i = 0; i < LexiconPlugin.config.LexiconedGroups.Length; i++) { if (LexiconPlugin.config.LexiconedGroups[i] == tSPlayer.Group.Name) { flag = true; } } if ((tSPlayer.Group.HasPermission("wordreplacement.permalexiconify") && !tSPlayer.Group.HasPermission("*")) || LexiconPlugin.BeingLexiconed[tSPlayer.Index] || flag) { e.Handled = true; string text = LexiconClass.Lexiconify(e.Text); if (!TShock.Config.EnableChatAboveHeads) { string text2 = string.Format(TShock.Config.ChatFormat, new object[] { tSPlayer.Group.Name, tSPlayer.Group.Prefix, tSPlayer.Name, tSPlayer.Group.Suffix, text }); TShock.Utils.Broadcast(text2, tSPlayer.Group.R, tSPlayer.Group.G, tSPlayer.Group.B); } else { Player player = Main.player[e.Who]; string name = player.name; player.name = string.Format(TShock.Config.ChatAboveHeadsFormat, new object[] { tSPlayer.Group.Name, tSPlayer.Group.Prefix, tSPlayer.Name, tSPlayer.Group.Suffix }); NetMessage.SendData(4, -1, -1, player.name, e.Who, 0f, 0f, 0f, 0); player.name = name; string text2 = text; NetMessage.SendData(25, -1, e.Who, text2, e.Who, (float)tSPlayer.Group.R, (float)tSPlayer.Group.G, (float)tSPlayer.Group.B, 0); NetMessage.SendData(4, -1, -1, name, e.Who, 0f, 0f, 0f, 0); string text3 = string.Format("<{0}> {1}", string.Format(TShock.Config.ChatAboveHeadsFormat, new object[] { tSPlayer.Group.Name, tSPlayer.Group.Prefix, tSPlayer.Name, tSPlayer.Group.Suffix }), text2); tSPlayer.SendMessage(text3, tSPlayer.Group.R, tSPlayer.Group.G, tSPlayer.Group.B); TSPlayer.Server.SendMessage(text3, tSPlayer.Group.R, tSPlayer.Group.G, tSPlayer.Group.B); Log.Info(string.Format("Broadcast: {0}", text3)); } } } }
public static string Lexiconify(string msg) { char[] array = new char[0]; string[] array2 = msg.Split(new char[] { ' ' }); string result; if (LexiconClass.rand.Next(0, 100) <= LexiconPlugin.config.HurrDurrChancePercentage && LexiconPlugin.config.ReplaceWithHurrDurr) { result = LexiconClass.ReplaceWithHurrDurr(msg); } else if (LexiconClass.rand.Next(0, 100) <= LexiconPlugin.config.RandomPhrasesChancePercentage && LexiconPlugin.config.SayRandomPhrases) { result = LexiconClass.SayRandomBullshit(); } else { for (int i = 0; i < array2.Length; i++) { string key = array2[i].ToLower(); if (LexiconPlugin.config.LexiconWords.ContainsKey(key)) { array = LexiconPlugin.config.LexiconWords[key].ToArray <char>(); for (int j = 0; j < array.Length; j++) { if (j < array2[i].Length) { if (char.IsUpper(array2[i][j])) { array[j] = char.ToUpper(array[j]); } } } array2[i] = new string(array); } } string text = string.Join(" ", array2); if (LexiconClass.rand.Next(0, 100) <= LexiconPlugin.config.TypoChancePercentage && LexiconPlugin.config.InsertRandomTypos) { text = LexiconClass.InsertRandomTypo(string.Join(" ", array2)); } result = text; } return(result); }