Fixes a Non-SSC chat over heads bug. Should solve #1436

This commit is contained in:
White 2017-05-03 21:49:19 +09:30
parent 7dcfa17ac2
commit 528d9c642b

View file

@ -1502,23 +1502,31 @@ namespace TShockAPI
Player ply = Main.player[args.Who];
string name = ply.name;
ply.name = String.Format(Config.ChatAboveHeadsFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix);
//Update the player's name to format text nicely. This needs to be done because Terraria automatically formats messages against our will
NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(ply.name), args.Who, 0, 0, 0, 0);
ply.name = name;
Hooks.PlayerHooks.OnPlayerChat(tsplr, args.Text, ref text);
//Give that poor player their name back :'c
ply.name = name;
PlayerHooks.OnPlayerChat(tsplr, args.Text, ref text);
//This netpacket is used to send chat text from the server to clients, in this case on behalf of a client
Terraria.Net.NetPacket packet = Terraria.GameContent.NetModules.NetTextModule.SerializeServerMessage(
NetworkText.FromLiteral(text), new Color(tsplr.Group.R, tsplr.Group.G, tsplr.Group.B), (byte)args.Who
);
Terraria.Net.NetManager.Instance.Broadcast(packet);
//Broadcast to everyone except the player who sent the message.
//This is so that we can send them the same nicely formatted message that everyone else gets
Terraria.Net.NetManager.Instance.Broadcast(packet, args.Who);
//Reset their name
NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(name), args.Who, 0, 0, 0, 0);
string msg = String.Format("<{0}> {1}",
String.Format(Config.ChatAboveHeadsFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix),
text);
//tsplr.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
text
);
//Send the original sender their nicely formatted message, and do all the loggy things
tsplr.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
TSPlayer.Server.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
Log.Info("Broadcast: {0}", msg);
args.Handled = true;