Updates Message Packets (#321)

### API Breaking Change
Combined `AsciiMessage` and `UnicodeMessage` into a single function that takes two arguments, `bool ascii` and `string lang`. Lang can be null (or anything) if ascii is true. 

- [X] Changes message packets
- [X] Cleans up some code
- [X] Uses benchmarks to determine if the spanwriter + copyfrom
This commit is contained in:
Kamron Batman 2020-11-20 21:50:13 -08:00 • committed by GitHub
parent 10d884fe30
commit b6cd408623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1160 additions and 1025 deletions

View file

@ -343,38 +343,31 @@ namespace Server.Guilds
public void AllianceChat(Mobile from, int hue, string text)
{
Packet p = null;
Span<byte> buffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(text)];
var length = OutgoingMessagePackets.CreateMessage(
ref buffer,
from.Serial,
from.Body,
MessageType.Alliance,
hue,
3,
false,
from.Language,
from.Name,
text
);
buffer = buffer.Slice(0, length); // Adjust to the actual size
for (var i = 0; i < m_Members.Count; i++)
{
var g = m_Members[i];
for (var j = 0; j < g.Members.Count; j++)
{
var m = g.Members[j];
var state = m.NetState;
if (state != null)
{
p ??= Packet.Acquire(
new UnicodeMessage(
from.Serial,
from.Body,
MessageType.Alliance,
hue,
3,
from.Language,
from.Name,
text
)
);
state.Send(p);
}
g.Members[j].NetState?.Send(buffer);
}
}
Packet.Release(p);
}
public void AllianceChat(Mobile from, string text)
@ -1512,24 +1505,18 @@ namespace Server.Guilds
public void GuildChat(Mobile from, int hue, string text)
{
Packet p = null;
Span<byte> buffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(text)];
var length = OutgoingMessagePackets.CreateMessage(
ref buffer,
from.Serial, from.Body, MessageType.Guild, hue, 3, false, from.Language, from.Name, text
);
buffer = buffer.Slice(0, length); // Adjust to the actual size
for (var i = 0; i < Members.Count; i++)
{
var m = Members[i];
var state = m.NetState;
if (state != null)
{
p ??= Packet.Acquire(
new UnicodeMessage(from.Serial, from.Body, MessageType.Guild, hue, 3, from.Language, from.Name, text)
);
state.Send(p);
}
Members[i].NetState?.Send(buffer);
}
Packet.Release(p);
}
public void GuildChat(Mobile from, string text)