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

@ -2036,7 +2036,7 @@ namespace Server.Items
return;
}
from.NetState?.SendDisplayEquipmentInfo(Serial, number, m_Crafter?.RawName, false, attrs);
from.NetState.SendDisplayEquipmentInfo(Serial, number, m_Crafter?.RawName, false, attrs);
}
[Flags]

View file

@ -880,7 +880,7 @@ namespace Server.Items
return;
}
from.NetState?.SendDisplayEquipmentInfo(Serial, number, m_Crafter?.RawName, false, attrs);
from.NetState.SendDisplayEquipmentInfo(Serial, number, m_Crafter?.RawName, false, attrs);
}
public virtual void AddEquipInfoAttributes(Mobile from, List<EquipInfoAttribute> attrs)

View file

@ -279,7 +279,7 @@ namespace Server.Items
inaccessible = true;
}
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", ""));
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number);
}
return inaccessible;

View file

@ -51,7 +51,7 @@ namespace Server.Items
return;
}
to.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, hue, 3, number, "", ""));
to.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Regular, hue, 3, number);
}
private void SendMessageTo(Mobile to, string text, int hue)
@ -61,7 +61,7 @@ namespace Server.Items
return;
}
to.Send(new UnicodeMessage(Serial, ItemID, MessageType.Regular, hue, 3, "ENU", "", text));
to.NetState.SendMessage(Serial, ItemID, MessageType.Regular, hue, 3, false, "ENU", "", text);
}
public virtual bool ExecuteTrap(Mobile from)

View file

@ -276,17 +276,13 @@ namespace Server.Items
}
else if (from.AccessLevel < AccessLevel.GameMaster && !Guild.IsMember(from))
{
from.Send(
new MessageLocalized(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
501158,
"",
""
)
from.NetState.SendMessageLocalized(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
501158
); // You are not a member ...
}
else

View file

@ -519,7 +519,7 @@ namespace Server.Items
if (m_Completed)
{
list.Add(1041507, m_CompletedBy == null ? "someone" : m_CompletedBy.Name); // completed by ~1_val~
list.Add(1041507, m_CompletedBy?.RawName ?? "someone"); // completed by ~1_val~
}
}
@ -527,19 +527,16 @@ namespace Server.Items
{
if (m_Completed)
{
from.Send(
new MessageLocalizedAffix(
Serial,
ItemID,
MessageType.Label,
0x3B2,
3,
1048030,
"",
AffixType.Append,
$" completed by {(m_CompletedBy == null ? "someone" : m_CompletedBy.Name)}",
""
)
from.NetState.SendMessageLocalizedAffix(
Serial,
ItemID,
MessageType.Label,
0x3B2,
3,
1048030,
"",
AffixType.Append,
$" completed by {m_CompletedBy?.RawName ?? "someone"}"
);
}
else if (m_Decoder != null)

View file

@ -153,19 +153,16 @@ namespace Server.Items
public override void OnSingleClick(Mobile from)
{
from.Send(
new MessageLocalizedAffix(
Serial,
ItemID,
MessageType.Label,
0x3B2,
3,
1041361,
"",
AffixType.Append,
$" {m_Worth}",
""
)
from.NetState.SendMessageLocalizedAffix(
Serial,
ItemID,
MessageType.Label,
0x3B2,
3,
1041361,
"",
AffixType.Append,
$" {m_Worth}"
); // A bank check:
}

View file

@ -1168,7 +1168,7 @@ namespace Server.Items
if (opl.Header > 0)
{
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs));
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs);
}
}
@ -1180,16 +1180,16 @@ namespace Server.Items
{
if (m_CorpseName != null)
{
from.Send(new AsciiMessage(Serial, ItemID, MessageType.Label, hue, 3, "", m_CorpseName));
from.NetState.SendMessage(Serial, ItemID, MessageType.Label, hue, 3, true, null, "", m_CorpseName);
}
else
{
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name));
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name);
}
}
else // Bone form
{
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name));
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name);
}
}

View file

@ -249,14 +249,14 @@ namespace Server.Items
{
desc = "(blank)";
}
else if ((desc = m_Description) == null || (desc = desc.Trim()).Length <= 0)
else
{
desc = "";
desc = m_Description?.Trim() ?? "";
}
if (desc.Length > 0)
{
from.Send(new UnicodeMessage(Serial, ItemID, MessageType.Regular, 0x3B2, 3, "ENU", "", desc));
from.NetState.SendMessage(Serial, ItemID, MessageType.Regular, 0x3B2, 3, false, "ENU", "", desc);
}
}

View file

@ -216,18 +216,18 @@ namespace Server.Items
public void DoDamage(Mobile to)
{
to.Send(
new UnicodeMessage(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
"",
"",
"The generator shoots an arc of electricity at you!"
)
to.NetState.SendMessage(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
false,
"ENU",
"",
"The generator shoots an arc of electricity at you!"
);
to.BoltEffect(0);
to.LocalOverheadMessage(MessageType.Regular, 0xC9, true, "* Your body convulses from electric shock *");
to.NonlocalOverheadMessage(MessageType.Regular, 0xC9, true, $"* {to.Name} spasms from electric shock *");

View file

@ -429,32 +429,28 @@ namespace Server.Items
{
if (m_MessageString != null)
{
m.Send(
new UnicodeMessage(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
"ENU",
null,
m_MessageString
)
m.NetState.SendMessage(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
false,
"ENU",
null,
m_MessageString
);
}
else if (m_MessageNumber != 0)
{
m.Send(
new MessageLocalized(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
m_MessageNumber,
null,
""
)
m.NetState.SendMessageLocalized(
Serial,
ItemID,
MessageType.Regular,
0x3B2,
3,
m_MessageNumber,
null
);
}

View file

@ -61,10 +61,8 @@ namespace Server.Items
public override void OnSingleClick(Mobile from)
{
var number = Amount == 1 ? 1049122 : 1049121;
from.Send(
new MessageLocalized(Serial, ItemID, MessageType.Label, 0x3B2, 3, number, "", (Amount * 50).ToString())
);
var amount = (Amount * 50).ToString();
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Label, 0x3B2, 3, number, "", amount);
}
}
}

View file

@ -62,7 +62,7 @@ namespace Server.Items
{
var number = Amount == 1 ? 1049124 : 1049123;
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", Amount.ToString()));
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", Amount.ToString());
}
}
}

View file

@ -62,7 +62,7 @@ namespace Server.Items
{
var number = Amount == 1 ? 1049124 : 1049123;
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", Amount.ToString()));
from.NetState.SendMessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", Amount.ToString());
}
}
}

View file

@ -696,7 +696,7 @@ namespace Server.Items
else if (Parent is Mobile)
{
// What will happen if the client doesn't know about our parent?
to.NetState?.SendEquipUpdate(this);
to.NetState.SendEquipUpdate(this);
}
if (ns.HighSeas)

View file

@ -469,7 +469,7 @@ namespace Server.Items
return;
}
from.NetState?.SendDisplayEquipmentInfo(Serial, number, m_Crafter?.RawName, false, attrs);
from.NetState.SendDisplayEquipmentInfo(Serial, number, m_Crafter?.RawName, false, attrs);
}
public override void Serialize(IGenericWriter writer)

View file

@ -22,33 +22,28 @@ namespace Server.Items
1008155
); // You peer into the heavens, seeking the moons...
from.Send(
new MessageLocalizedAffix(
from.Serial,
from.Body,
MessageType.Regular,
0x3B2,
3,
1008146 + (int)Clock.GetMoonPhase(Map.Trammel, from.X, from.Y),
"",
AffixType.Prepend,
"Trammel : ",
""
)
from.NetState.SendMessageLocalizedAffix(
from.Serial,
from.Body,
MessageType.Regular,
0x3B2,
3,
1008146 + (int)Clock.GetMoonPhase(Map.Trammel, from.X, from.Y),
"",
AffixType.Prepend,
"Trammel : "
);
from.Send(
new MessageLocalizedAffix(
from.Serial,
from.Body,
MessageType.Regular,
0x3B2,
3,
1008146 + (int)Clock.GetMoonPhase(Map.Felucca, from.X, from.Y),
"",
AffixType.Prepend,
"Felucca : ",
""
)
from.NetState.SendMessageLocalizedAffix(
from.Serial,
from.Body,
MessageType.Regular,
0x3B2,
3,
1008146 + (int)Clock.GetMoonPhase(Map.Felucca, from.X, from.Y),
"",
AffixType.Prepend,
"Felucca : "
);
if (from is PlayerMobile player)

View file

@ -260,16 +260,16 @@ namespace Server.Items
}
else if (item is BagOfSending || item is Container)
{
from.Send(
new AsciiMessage(
m_Bag.Serial,
m_Bag.ItemID,
MessageType.Regular,
0x3B2,
3,
"",
"You cannot send a container through the bag of sending."
)
from.NetState.SendMessage(
m_Bag.Serial,
m_Bag.ItemID,
MessageType.Regular,
0x3B2,
3,
true,
null,
"",
"You cannot send a container through the bag of sending."
);
}
else if (item.LootType == LootType.Cursed)

View file

@ -226,16 +226,16 @@ namespace Server.Items
else if (from.Map == Map.Ilshenar || from.Region.IsPartOf<DungeonRegion>() ||
from.Region.IsPartOf<JailRegion>() || from.Region.IsPartOf<SafeZone>())
{
from.Send(
new AsciiMessage(
Serial,
ItemID,
MessageType.Regular,
0x22,
3,
"",
"You cannot summon your pet to this location."
)
from.NetState.SendMessage(
Serial,
ItemID,
MessageType.Regular,
0x22,
3,
true,
null,
"",
"You cannot summon your pet to this location."
);
}
else if (Core.ML && from is PlayerMobile mobile && DateTime.UtcNow < mobile.LastPetBallTime.AddSeconds(15.0))

View file

@ -11,12 +11,12 @@ namespace Server
public static void SendLocalizedMessageTo(Item from, Mobile to, int number, string args, int hue)
{
to.Send(new MessageLocalized(from.Serial, from.ItemID, MessageType.Regular, hue, 3, number, "", args));
to.NetState.SendMessageLocalized(from.Serial, from.ItemID, MessageType.Regular, hue, 3, number, "", args);
}
public static void SendMessageTo(Item from, Mobile to, string text, int hue)
{
to.Send(new UnicodeMessage(from.Serial, from.ItemID, MessageType.Regular, hue, 3, "ENU", "", text));
to.NetState.SendMessage(from.Serial, from.ItemID, MessageType.Regular, hue, 3, false, "ENU", "", text);
}
}
}

View file

@ -268,7 +268,7 @@ namespace Server.Items
return;
}
from.NetState?.SendDisplayEquipmentInfo(Serial, number, Crafter?.RawName, false, attrs);
from.NetState.SendDisplayEquipmentInfo(Serial, number, Crafter?.RawName, false, attrs);
}
public void Cast(Spell spell)

View file

@ -83,7 +83,7 @@ namespace Server.Items
if (canSwing && attacker.HarmfulCheck(defender))
{
attacker.DisruptiveAction();
attacker.NetState?.SendSwing(attacker.Serial, defender.Serial);
attacker.NetState.SendSwing(attacker.Serial, defender.Serial);
if (OnFired(attacker, defender))
{