Core/Grids: Move packet sending functionality out of MessageDistDeliverer and into separate, customizable class and unify LocalizedPacketDo, LocalizedPacketListDo as generic localizable action

Port From (https://github.com/TrinityCore/TrinityCore/commit/fb66575d38d2ba7ffc24c29824fa75d7019de549)
This commit is contained in:
hondacrx
2021-05-02 13:41:19 -04:00
parent 7c83501ba7
commit aaa3964d49
16 changed files with 188 additions and 198 deletions
+22 -7
View File
@@ -1472,7 +1472,7 @@ namespace Game
public void SendWorldText(CypherStrings string_id, params object[] args)
{
WorldWorldTextBuilder wt_builder = new((uint)string_id, args);
var wt_do = new LocalizedPacketListDo(wt_builder);
var wt_do = new LocalizedDo(wt_builder);
foreach (var session in m_sessions.Values)
{
if (session == null || !session.GetPlayer() || !session.GetPlayer().IsInWorld)
@@ -1486,7 +1486,7 @@ namespace Game
public void SendGMText(CypherStrings string_id, params object[] args)
{
var wt_builder = new WorldWorldTextBuilder((uint)string_id, args);
var wt_do = new LocalizedPacketListDo(wt_builder);
var wt_do = new LocalizedDo(wt_builder);
foreach (var session in m_sessions.Values)
{
// Session should have permissions to receive global gm messages
@@ -2512,32 +2512,47 @@ namespace Game
}
public class WorldWorldTextBuilder : MessageBuilder
{
{
public WorldWorldTextBuilder(uint textId, params object[] args)
{
i_textId = textId;
i_args = args;
}
public override void Invoke(List<ServerPacket> data_list, Locale loc_idx)
public override MultiplePacketSender Invoke(Locale locale)
{
string text = Global.ObjectMgr.GetCypherString(i_textId, loc_idx);
string text = Global.ObjectMgr.GetCypherString(i_textId, locale);
if (i_args != null)
text = string.Format(text, i_args);
ChatPkt messageChat = new();
MultiplePacketSender sender = new MultiplePacketSender();
var lines = new StringArray(text, "\n");
for (var i = 0; i < lines.Length; ++i)
{
ChatPkt messageChat = new();
messageChat.Initialize(ChatMsg.System, Language.Universal, null, null, lines[i]);
data_list.Add(messageChat);
messageChat.Write();
sender.Packets.Add(messageChat);
}
return sender;
}
uint i_textId;
object[] i_args;
public class MultiplePacketSender : IDoWork<Player>
{
public void Invoke(Player receiver)
{
foreach (var packet in Packets)
receiver.SendPacket(packet);
}
public List<ServerPacket> Packets = new();
}
}
struct Autobroadcast